blob: aa2b75c1def4b563c25148d09b180cdad69ef786 [file] [log] [blame]
Amy Zhange6915052021-03-30 13:44:43 -07001/*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <android-base/logging.h>
18#include <android/hardware/tv/tuner/1.0/types.h>
19#include <android_media_tuner_testing_configuration_V1_0.h>
20#include <android_media_tuner_testing_configuration_V1_0_enums.h>
21#include <binder/MemoryDealer.h>
22#include <hidl/HidlSupport.h>
23#include <hidl/HidlTransportSupport.h>
24#include <hidl/Status.h>
25#include <hidlmemory/FrameworkUtils.h>
26
27using namespace std;
28using namespace android::media::tuner::testing::configuration::V1_0;
29
30using android::hardware::tv::tuner::V1_0::DataFormat;
31using android::hardware::tv::tuner::V1_0::DemuxAlpFilterType;
32using android::hardware::tv::tuner::V1_0::DemuxFilterEvent;
33using android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
34using android::hardware::tv::tuner::V1_0::DemuxFilterSettings;
35using android::hardware::tv::tuner::V1_0::DemuxFilterType;
36using android::hardware::tv::tuner::V1_0::DemuxIpFilterType;
37using android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType;
38using android::hardware::tv::tuner::V1_0::DemuxRecordScIndexType;
39using android::hardware::tv::tuner::V1_0::DemuxTlvFilterType;
40using android::hardware::tv::tuner::V1_0::DemuxTpid;
41using android::hardware::tv::tuner::V1_0::DemuxTsFilterType;
42using android::hardware::tv::tuner::V1_0::DvrSettings;
43using android::hardware::tv::tuner::V1_0::DvrType;
44using android::hardware::tv::tuner::V1_0::FrontendDvbsSettings;
45using android::hardware::tv::tuner::V1_0::FrontendDvbtBandwidth;
46using android::hardware::tv::tuner::V1_0::FrontendDvbtCoderate;
47using android::hardware::tv::tuner::V1_0::FrontendDvbtConstellation;
48using android::hardware::tv::tuner::V1_0::FrontendDvbtGuardInterval;
49using android::hardware::tv::tuner::V1_0::FrontendDvbtHierarchy;
50using android::hardware::tv::tuner::V1_0::FrontendDvbtSettings;
51using android::hardware::tv::tuner::V1_0::FrontendDvbtStandard;
52using android::hardware::tv::tuner::V1_0::FrontendDvbtTransmissionMode;
53using android::hardware::tv::tuner::V1_0::FrontendSettings;
54using android::hardware::tv::tuner::V1_0::FrontendStatus;
55using android::hardware::tv::tuner::V1_0::FrontendStatusType;
56using android::hardware::tv::tuner::V1_0::FrontendType;
57using android::hardware::tv::tuner::V1_0::LnbPosition;
58using android::hardware::tv::tuner::V1_0::LnbTone;
59using android::hardware::tv::tuner::V1_0::LnbVoltage;
60using android::hardware::tv::tuner::V1_0::PlaybackSettings;
61using android::hardware::tv::tuner::V1_0::RecordSettings;
62
63const string configFilePath = "/vendor/etc/tuner_vts_config.xml";
64
65struct FrontendConfig {
66 bool isSoftwareFe;
67 FrontendType type;
68 FrontendSettings settings;
69 vector<FrontendStatusType> tuneStatusTypes;
70 vector<FrontendStatus> expectTuneStatuses;
71};
72
Amy Zhange50f08d2021-03-30 15:56:02 -070073struct DvrConfig {
74 DvrType type;
75 uint32_t bufferSize;
76 DvrSettings settings;
77 string playbackInputFile;
78};
79
Amy Zhange6915052021-03-30 13:44:43 -070080struct LiveBroadcastHardwareConnections {
81 string frontendId;
Amy Zhange50f08d2021-03-30 15:56:02 -070082 string dvrSoftwareFeId;
Amy Zhange6915052021-03-30 13:44:43 -070083 /* string audioFilterId;
84 string videoFilterId;
85 list string of extra filters; */
86};
87
88struct ScanHardwareConnections {
89 string frontendId;
90};
91
Amy Zhange50f08d2021-03-30 15:56:02 -070092struct DvrPlaybackHardwareConnections {
93 bool support;
94 string frontendId;
95 string dvrId;
96 /* string audioFilterId;
97 string videoFilterId;
98 list string of extra filters; */
99};
100
Amy Zhange6915052021-03-30 13:44:43 -0700101struct DvrRecordHardwareConnections {
102 bool support;
103 string frontendId;
Amy Zhange50f08d2021-03-30 15:56:02 -0700104 string dvrRecordId;
105 string dvrSoftwareFeId;
Amy Zhange6915052021-03-30 13:44:43 -0700106 /* string recordFilterId;
107 string dvrId; */
108};
109
110struct DescramblingHardwareConnections {
111 bool support;
112 string frontendId;
Amy Zhange50f08d2021-03-30 15:56:02 -0700113 string dvrSoftwareFeId;
Amy Zhange6915052021-03-30 13:44:43 -0700114 /* string descramblerId;
115 string audioFilterId;
116 string videoFilterId;
117 list string of extra filters; */
118};
119
120struct LnbLiveHardwareConnections {
121 bool support;
122 string frontendId;
123 /* string audioFilterId;
124 string videoFilterId;
125 list string of extra filters;
126 string lnbId; */
127};
128
129struct LnbRecordHardwareConnections {
130 bool support;
131 string frontendId;
132 /* string recordFilterId;
133 list string of extra filters;
134 string lnbId; */
135};
136
137struct TunerTestingConfigReader {
138 public:
139 static bool checkConfigFileExists() {
140 auto res = read(configFilePath.c_str());
141 if (res == nullopt) {
142 ALOGW("[ConfigReader] Couldn't read /vendor/etc/tuner_vts_config.xml."
143 "Please check tuner_testing_dynamic_configuration.xsd"
144 "and sample_tuner_vts_config.xml for more details on how to config Tune VTS.");
145 }
146 return (res != nullopt);
147 }
148
149 static void readFrontendConfig1_0(map<string, FrontendConfig>& frontendMap) {
150 auto hardwareConfig = getHardwareConfig();
151 if (hardwareConfig.hasFrontends()) {
152 // TODO: complete the tune status config
153 vector<FrontendStatusType> types;
154 types.push_back(FrontendStatusType::DEMOD_LOCK);
155 FrontendStatus status;
156 status.isDemodLocked(true);
157 vector<FrontendStatus> statuses;
158 statuses.push_back(status);
159
160 auto frontends = *hardwareConfig.getFirstFrontends();
161 for (auto feConfig : frontends.getFrontend()) {
162 string id = feConfig.getId();
163 if (id.compare(string("FE_DEFAULT")) == 0) {
164 // overrid default
165 frontendMap.erase(string("FE_DEFAULT"));
166 }
167 FrontendType type;
168 switch (feConfig.getType()) {
169 case FrontendTypeEnum::UNDEFINED:
170 type = FrontendType::UNDEFINED;
171 break;
172 // TODO: finish all other frontend settings
173 case FrontendTypeEnum::ANALOG:
174 type = FrontendType::ANALOG;
175 break;
176 case FrontendTypeEnum::ATSC:
177 type = FrontendType::ATSC;
178 break;
179 case FrontendTypeEnum::ATSC3:
180 type = FrontendType::ATSC3;
181 break;
182 case FrontendTypeEnum::DVBC:
183 type = FrontendType::DVBC;
184 break;
185 case FrontendTypeEnum::DVBS:
186 type = FrontendType::DVBS;
187 frontendMap[id].settings.dvbs(readDvbsFrontendSettings(feConfig));
188 break;
189 case FrontendTypeEnum::DVBT: {
190 type = FrontendType::DVBT;
191 frontendMap[id].settings.dvbt(readDvbtFrontendSettings(feConfig));
192 break;
193 }
194 case FrontendTypeEnum::ISDBS:
195 type = FrontendType::ISDBS;
196 break;
197 case FrontendTypeEnum::ISDBS3:
198 type = FrontendType::ISDBS3;
199 break;
200 case FrontendTypeEnum::ISDBT:
201 type = FrontendType::ISDBT;
202 break;
203 case FrontendTypeEnum::DTMB:
204 // dtmb will be handled in readFrontendConfig1_1;
205 continue;
206 case FrontendTypeEnum::UNKNOWN:
207 ALOGW("[ConfigReader] invalid frontend type");
208 return;
209 }
210 frontendMap[id].type = type;
211 frontendMap[id].isSoftwareFe = feConfig.getIsSoftwareFrontend();
212 // TODO: complete the tune status config
213 frontendMap[id].tuneStatusTypes = types;
214 frontendMap[id].expectTuneStatuses = statuses;
215 }
216 }
217 }
218
Amy Zhange50f08d2021-03-30 15:56:02 -0700219 static void readDvrConfig1_0(map<string, DvrConfig>& dvrMap) {
220 auto hardwareConfig = getHardwareConfig();
221 if (hardwareConfig.hasDvrs()) {
222 auto dvrs = *hardwareConfig.getFirstDvrs();
223 for (auto dvrConfig : dvrs.getDvr()) {
224 string id = dvrConfig.getId();
225 DvrType type;
226 switch (dvrConfig.getType()) {
227 case DvrTypeEnum::PLAYBACK:
228 type = DvrType::PLAYBACK;
229 dvrMap[id].settings.playback(readPlaybackSettings(dvrConfig));
230 break;
231 case DvrTypeEnum::RECORD:
232 type = DvrType::RECORD;
233 dvrMap[id].settings.record(readRecordSettings(dvrConfig));
234 break;
235 case DvrTypeEnum::UNKNOWN:
236 ALOGW("[ConfigReader] invalid DVR type");
237 return;
238 }
239 dvrMap[id].type = type;
240 dvrMap[id].bufferSize = static_cast<uint32_t>(dvrConfig.getBufferSize());
241 if (dvrConfig.hasInputFilePath()) {
242 dvrMap[id].playbackInputFile = dvrConfig.getInputFilePath();
243 }
244 }
245 }
246 }
247
Amy Zhange6915052021-03-30 13:44:43 -0700248 static void connectLiveBroadcast(LiveBroadcastHardwareConnections& live) {
249 auto liveConfig = getDataFlowConfiguration().getFirstClearLiveBroadcast();
250 live.frontendId = liveConfig->getFrontendConnection();
Amy Zhange50f08d2021-03-30 15:56:02 -0700251 if (liveConfig->hasDvrSoftwareFeConnection()) {
252 live.dvrSoftwareFeId = liveConfig->getDvrSoftwareFeConnection();
253 }
Amy Zhange6915052021-03-30 13:44:43 -0700254 }
255
256 static void connectScan(ScanHardwareConnections& scan) {
257 auto scanConfig = getDataFlowConfiguration().getFirstScan();
258 scan.frontendId = scanConfig->getFrontendConnection();
259 }
260
Amy Zhange50f08d2021-03-30 15:56:02 -0700261 static void connectDvrPlayback(DvrPlaybackHardwareConnections& playback) {
262 auto dataFlow = getDataFlowConfiguration();
263 if (!dataFlow.hasDvrPlayback()) {
264 playback.support = false;
265 return;
266 }
267 auto playbackConfig = dataFlow.getFirstDvrPlayback();
268 playback.dvrId = playbackConfig->getDvrConnection();
269 }
270
Amy Zhange6915052021-03-30 13:44:43 -0700271 static void connectDvrRecord(DvrRecordHardwareConnections& record) {
272 auto dataFlow = getDataFlowConfiguration();
273 if (!dataFlow.hasDvrRecord()) {
274 record.support = false;
275 return;
276 }
277 auto recordConfig = dataFlow.getFirstDvrRecord();
278 record.frontendId = recordConfig->getFrontendConnection();
Amy Zhange50f08d2021-03-30 15:56:02 -0700279 record.dvrRecordId = recordConfig->getDvrRecordConnection();
280 if (recordConfig->hasDvrSoftwareFeConnection()) {
281 record.dvrSoftwareFeId = recordConfig->getDvrSoftwareFeConnection();
282 }
Amy Zhange6915052021-03-30 13:44:43 -0700283 }
284
285 static void connectDescrambling(DescramblingHardwareConnections& descrambling) {
286 auto dataFlow = getDataFlowConfiguration();
287 if (!dataFlow.hasDescrambling()) {
288 descrambling.support = false;
289 return;
290 }
291 auto descConfig = dataFlow.getFirstDescrambling();
292 descrambling.frontendId = descConfig->getFrontendConnection();
Amy Zhange50f08d2021-03-30 15:56:02 -0700293 if (descConfig->hasDvrSoftwareFeConnection()) {
294 descrambling.dvrSoftwareFeId = descConfig->getDvrSoftwareFeConnection();
295 }
Amy Zhange6915052021-03-30 13:44:43 -0700296 }
297
298 static void connectLnbLive(LnbLiveHardwareConnections& lnbLive) {
299 auto dataFlow = getDataFlowConfiguration();
300 if (!dataFlow.hasLnbLive()) {
301 lnbLive.support = false;
302 return;
303 }
304 auto lnbLiveConfig = dataFlow.getFirstLnbLive();
305 lnbLive.frontendId = lnbLiveConfig->getFrontendConnection();
306 }
307
308 static void connectLnbRecord(LnbRecordHardwareConnections& lnbRecord) {
309 auto dataFlow = getDataFlowConfiguration();
310 if (!dataFlow.hasLnbRecord()) {
311 lnbRecord.support = false;
312 return;
313 }
314 auto lnbRecordConfig = dataFlow.getFirstLnbRecord();
315 lnbRecord.frontendId = lnbRecordConfig->getFrontendConnection();
316 }
317
318 private:
319 static FrontendDvbtSettings readDvbtFrontendSettings(Frontend feConfig) {
Amy Zhange50f08d2021-03-30 15:56:02 -0700320 ALOGW("[ConfigReader] fe type is dvbt");
Amy Zhange6915052021-03-30 13:44:43 -0700321 FrontendDvbtSettings dvbtSettings{
322 .frequency = (uint32_t)feConfig.getFrequency(),
323 };
324 if (!feConfig.hasDvbtFrontendSettings_optional()) {
325 ALOGW("[ConfigReader] no more dvbt settings");
326 return dvbtSettings;
327 }
328 dvbtSettings.transmissionMode = static_cast<FrontendDvbtTransmissionMode>(
329 feConfig.getFirstDvbtFrontendSettings_optional()->getTransmissionMode());
330 dvbtSettings.bandwidth = static_cast<FrontendDvbtBandwidth>(
331 feConfig.getFirstDvbtFrontendSettings_optional()->getBandwidth());
332 dvbtSettings.isHighPriority =
333 feConfig.getFirstDvbtFrontendSettings_optional()->getIsHighPriority();
334 return dvbtSettings;
335 }
336
337 static FrontendDvbsSettings readDvbsFrontendSettings(Frontend feConfig) {
Amy Zhange50f08d2021-03-30 15:56:02 -0700338 ALOGW("[ConfigReader] fe type is dvbs");
Amy Zhange6915052021-03-30 13:44:43 -0700339 FrontendDvbsSettings dvbsSettings{
340 .frequency = (uint32_t)feConfig.getFrequency(),
341 };
342 if (!feConfig.hasDvbsFrontendSettings_optional()) {
343 ALOGW("[ConfigReader] no more dvbs settings");
344 return dvbsSettings;
345 }
346 dvbsSettings.symbolRate = static_cast<uint32_t>(
347 feConfig.getFirstDvbsFrontendSettings_optional()->getSymbolRate());
348 dvbsSettings.inputStreamId = static_cast<uint32_t>(
349 feConfig.getFirstDvbsFrontendSettings_optional()->getInputStreamId());
350 return dvbsSettings;
351 }
352
Amy Zhange50f08d2021-03-30 15:56:02 -0700353 static PlaybackSettings readPlaybackSettings(Dvr dvrConfig) {
354 ALOGW("[ConfigReader] dvr type is playback");
355 PlaybackSettings playbackSettings{
356 .statusMask = static_cast<uint8_t>(dvrConfig.getStatusMask()),
357 .lowThreshold = static_cast<uint32_t>(dvrConfig.getLowThreshold()),
358 .highThreshold = static_cast<uint32_t>(dvrConfig.getHighThreshold()),
359 .dataFormat = static_cast<DataFormat>(dvrConfig.getDataFormat()),
360 .packetSize = static_cast<uint8_t>(dvrConfig.getPacketSize()),
361 };
362 return playbackSettings;
363 }
364
365 static RecordSettings readRecordSettings(Dvr dvrConfig) {
366 ALOGW("[ConfigReader] dvr type is record");
367 RecordSettings recordSettings{
368 .statusMask = static_cast<uint8_t>(dvrConfig.getStatusMask()),
369 .lowThreshold = static_cast<uint32_t>(dvrConfig.getLowThreshold()),
370 .highThreshold = static_cast<uint32_t>(dvrConfig.getHighThreshold()),
371 .dataFormat = static_cast<DataFormat>(dvrConfig.getDataFormat()),
372 .packetSize = static_cast<uint8_t>(dvrConfig.getPacketSize()),
373 };
374 return recordSettings;
375 }
376
Amy Zhange6915052021-03-30 13:44:43 -0700377 static TunerConfiguration getTunerConfig() { return *read(configFilePath.c_str()); }
378
379 static HardwareConfiguration getHardwareConfig() {
380 return *getTunerConfig().getFirstHardwareConfiguration();
381 }
382
383 static DataFlowConfiguration getDataFlowConfiguration() {
384 return *getTunerConfig().getFirstDataFlowConfiguration();
385 }
386};