blob: c4b09629bf38897cea0d111e74d6b521f697fd78 [file] [log] [blame]
Hongguang600a6ae2021-07-08 18:51:51 -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 <binder/MemoryDealer.h>
18
19#include "../../../config/TunerTestingConfigAidlReaderV1_0.h"
20
21#include <aidl/android/hardware/tv/tuner/DataFormat.h>
22#include <aidl/android/hardware/tv/tuner/DemuxAlpFilterType.h>
23#include <aidl/android/hardware/tv/tuner/DemuxFilterMainType.h>
24#include <aidl/android/hardware/tv/tuner/DemuxFilterMonitorEventType.h>
25#include <aidl/android/hardware/tv/tuner/DemuxFilterSettings.h>
26#include <aidl/android/hardware/tv/tuner/DemuxFilterType.h>
27#include <aidl/android/hardware/tv/tuner/DemuxIpAddress.h>
28#include <aidl/android/hardware/tv/tuner/DemuxIpFilterSettings.h>
29#include <aidl/android/hardware/tv/tuner/DemuxIpFilterType.h>
30#include <aidl/android/hardware/tv/tuner/DemuxMmtpFilterType.h>
31#include <aidl/android/hardware/tv/tuner/DemuxRecordScIndexType.h>
32#include <aidl/android/hardware/tv/tuner/DemuxTsFilterType.h>
33#include <aidl/android/hardware/tv/tuner/DvrSettings.h>
34#include <aidl/android/hardware/tv/tuner/DvrType.h>
35#include <aidl/android/hardware/tv/tuner/FrontendDvbtBandwidth.h>
36#include <aidl/android/hardware/tv/tuner/FrontendDvbtCoderate.h>
37#include <aidl/android/hardware/tv/tuner/FrontendDvbtConstellation.h>
38#include <aidl/android/hardware/tv/tuner/FrontendDvbtGuardInterval.h>
39#include <aidl/android/hardware/tv/tuner/FrontendDvbtHierarchy.h>
40#include <aidl/android/hardware/tv/tuner/FrontendDvbtSettings.h>
41#include <aidl/android/hardware/tv/tuner/FrontendDvbtStandard.h>
42#include <aidl/android/hardware/tv/tuner/FrontendDvbtTransmissionMode.h>
43#include <aidl/android/hardware/tv/tuner/FrontendSettings.h>
44#include <aidl/android/hardware/tv/tuner/FrontendType.h>
45#include <aidl/android/hardware/tv/tuner/PlaybackSettings.h>
46#include <aidl/android/hardware/tv/tuner/RecordSettings.h>
47
48using namespace std;
49using namespace aidl::android::hardware::tv::tuner;
50using namespace android::media::tuner::testing::configuration::V1_0;
51
52const int32_t FMQ_SIZE_4M = 0x400000;
53const int32_t FMQ_SIZE_16M = 0x1000000;
54
Hongguang16dacc12021-11-01 15:51:52 -070055const string configFilePath = "/vendor/etc/tuner_vts_config_aidl_V1.xml";
Hongguang600a6ae2021-07-08 18:51:51 -070056
57#define FILTER_MAIN_TYPE_BIT_COUNT 5
58
59// Hardware configs
60static map<string, FrontendConfig> frontendMap;
61static map<string, FilterConfig> filterMap;
62static map<string, DvrConfig> dvrMap;
63static map<string, LnbConfig> lnbMap;
64static map<string, TimeFilterConfig> timeFilterMap;
65static map<string, vector<uint8_t>> diseqcMsgMap;
66static map<string, DescramblerConfig> descramblerMap;
67
68// Hardware and test cases connections
69static LiveBroadcastHardwareConnections live;
70static ScanHardwareConnections scan;
71static DvrPlaybackHardwareConnections playback;
72static DvrRecordHardwareConnections record;
73static DescramblingHardwareConnections descrambling;
74static LnbLiveHardwareConnections lnbLive;
75static LnbRecordHardwareConnections lnbRecord;
76static TimeFilterHardwareConnections timeFilter;
77
78/** Config all the frontends that would be used in the tests */
79inline void initFrontendConfig() {
80 // The test will use the internal default fe when default fe is connected to any data flow
81 // without overriding in the xml config.
82 string defaultFeId = "FE_DEFAULT";
83 FrontendDvbtSettings dvbtSettings{
Gareth Fenn282fb372021-09-27 15:14:11 +010084 .frequency = 578000000,
Hongguang600a6ae2021-07-08 18:51:51 -070085 .transmissionMode = FrontendDvbtTransmissionMode::AUTO,
86 .bandwidth = FrontendDvbtBandwidth::BANDWIDTH_8MHZ,
87 .isHighPriority = true,
88 };
89 frontendMap[defaultFeId].type = FrontendType::DVBT;
90 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbtSettings);
91
92 vector<FrontendStatusType> types;
93 types.push_back(FrontendStatusType::UEC);
94 types.push_back(FrontendStatusType::IS_MISO);
95
96 vector<FrontendStatus> statuses;
97 FrontendStatus status;
98 status.set<FrontendStatus::Tag::uec>(4);
99 statuses.push_back(status);
100 status.set<FrontendStatus::Tag::isMiso>(true);
101 statuses.push_back(status);
102
103 frontendMap[defaultFeId].tuneStatusTypes = types;
104 frontendMap[defaultFeId].expectTuneStatuses = statuses;
105 frontendMap[defaultFeId].isSoftwareFe = true;
106 frontendMap[defaultFeId].canConnectToCiCam = true;
107 frontendMap[defaultFeId].ciCamId = 0;
108 FrontendDvbtSettings dvbt;
109 dvbt.transmissionMode = FrontendDvbtTransmissionMode::MODE_8K_E;
110 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbt);
111 // Read customized config
112 TunerTestingConfigAidlReader1_0::readFrontendConfig1_0(frontendMap);
113};
114
115inline void initFilterConfig() {
116 // The test will use the internal default filter when default filter is connected to any
117 // data flow without overriding in the xml config.
118 string defaultAudioFilterId = "FILTER_AUDIO_DEFAULT";
119 string defaultVideoFilterId = "FILTER_VIDEO_DEFAULT";
120
121 filterMap[defaultVideoFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700122 filterMap[defaultVideoFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
123 DemuxTsFilterType::VIDEO);
Hongguang600a6ae2021-07-08 18:51:51 -0700124 filterMap[defaultVideoFilterId].bufferSize = FMQ_SIZE_16M;
125 filterMap[defaultVideoFilterId].settings =
126 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
127 filterMap[defaultVideoFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
128 DemuxFilterAvSettings video;
129 video.isPassthrough = false;
130 filterMap[defaultVideoFilterId]
131 .settings.get<DemuxFilterSettings::Tag::ts>()
132 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(video);
133 filterMap[defaultVideoFilterId].monitorEventTypes =
134 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
135 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
136 filterMap[defaultVideoFilterId].streamType.set<AvStreamType::Tag::video>(
137 VideoStreamType::MPEG1);
138
139 filterMap[defaultAudioFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700140 filterMap[defaultAudioFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
141 DemuxTsFilterType::AUDIO);
Hongguang600a6ae2021-07-08 18:51:51 -0700142 filterMap[defaultAudioFilterId].bufferSize = FMQ_SIZE_16M;
143 filterMap[defaultAudioFilterId].settings =
144 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
145 filterMap[defaultAudioFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
146 DemuxFilterAvSettings audio;
147 audio.isPassthrough = false;
148 filterMap[defaultAudioFilterId]
149 .settings.get<DemuxFilterSettings::Tag::ts>()
150 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(audio);
151 filterMap[defaultAudioFilterId].monitorEventTypes =
152 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
153 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
154 filterMap[defaultAudioFilterId].streamType.set<AvStreamType::Tag::audio>(AudioStreamType::MP3);
155 // Read customized config
156 TunerTestingConfigAidlReader1_0::readFilterConfig1_0(filterMap);
157};
158
159/** Config all the dvrs that would be used in the tests */
160inline void initDvrConfig() {
161 // Read customized config
162 TunerTestingConfigAidlReader1_0::readDvrConfig1_0(dvrMap);
163};
164
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000165inline void initTimeFilterConfig() {
166 // Read customized config
167 TunerTestingConfigAidlReader1_0::readTimeFilterConfig1_0(timeFilterMap);
168};
169
Frankie Lizcanof5352122022-06-29 22:10:16 +0000170inline void initDescramblerConfig() {
171 // Read customized config
172 TunerTestingConfigAidlReader1_0::readDescramblerConfig1_0(descramblerMap);
173}
174
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000175inline void initLnbConfig() {
176 // Read customized config
177 TunerTestingConfigAidlReader1_0::readLnbConfig1_0(lnbMap);
178};
179
180inline void initDiseqcMsgsConfig() {
181 // Read customized config
182 TunerTestingConfigAidlReader1_0::readDiseqcMessages(diseqcMsgMap);
183};
184
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000185inline void determineScan() {
186 if (!frontendMap.empty()) {
187 scan.hasFrontendConnection = true;
188 ALOGD("Can support scan");
189 }
190}
191
192inline void determineTimeFilter() {
193 if (!timeFilterMap.empty()) {
194 timeFilter.support = true;
195 ALOGD("Can support time filter");
196 }
197}
198
199inline void determineDvrPlayback() {
200 if (!playbackDvrIds.empty() && !audioFilterIds.empty() && !videoFilterIds.empty()) {
201 playback.support = true;
202 ALOGD("Can support dvr playback");
203 }
204}
205
206inline void determineLnbLive() {
207 if (!audioFilterIds.empty() && !videoFilterIds.empty() && !frontendMap.empty() &&
208 !lnbMap.empty()) {
209 lnbLive.support = true;
210 ALOGD("Can support lnb live");
211 }
212}
213
214inline void determineLnbRecord() {
215 if (!frontendMap.empty() && !recordFilterIds.empty() && !recordDvrIds.empty() &&
216 !lnbMap.empty()) {
217 lnbRecord.support = true;
218 ALOGD("Can support lnb record");
219 }
220}
221
222inline void determineLive() {
223 if (videoFilterIds.empty() || audioFilterIds.empty() || frontendMap.empty()) {
224 return;
225 }
226 if (hasSwFe && !hasHwFe && dvrMap.empty()) {
227 ALOGD("Cannot configure Live. Only software frontends and no dvr connections");
228 return;
229 }
230 ALOGD("Can support live");
231 live.hasFrontendConnection = true;
232}
233
234inline void determineDescrambling() {
235 if (descramblerMap.empty() || audioFilterIds.empty() || videoFilterIds.empty()) {
236 return;
237 }
238 if (frontendMap.empty() && playbackDvrIds.empty()) {
239 ALOGD("Cannot configure descrambling. No frontends or playback dvr's");
240 return;
241 }
242 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
243 ALOGD("cannot configure descrambling. Only SW frontends and no playback dvr's");
244 return;
245 }
246 ALOGD("Can support descrambling");
247 descrambling.support = true;
248}
249
250inline void determineDvrRecord() {
251 if (recordDvrIds.empty() || recordFilterIds.empty()) {
252 return;
253 }
254 if (frontendMap.empty() && playbackDvrIds.empty()) {
255 ALOGD("Cannot support dvr record. No frontends and no playback dvr's");
256 return;
257 }
258 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
259 ALOGD("Cannot support dvr record. Only SW frontends and no playback dvr's");
260 return;
261 }
262 ALOGD("Can support dvr record.");
263 record.support = true;
264}
265
Hongguang600a6ae2021-07-08 18:51:51 -0700266/** Read the vendor configurations of which hardware to use for each test cases/data flows */
267inline void connectHardwaresToTestCases() {
268 TunerTestingConfigAidlReader1_0::connectLiveBroadcast(live);
269 TunerTestingConfigAidlReader1_0::connectScan(scan);
270 TunerTestingConfigAidlReader1_0::connectDvrRecord(record);
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000271 TunerTestingConfigAidlReader1_0::connectTimeFilter(timeFilter);
Frankie Lizcanof5352122022-06-29 22:10:16 +0000272 TunerTestingConfigAidlReader1_0::connectDescrambling(descrambling);
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000273 TunerTestingConfigAidlReader1_0::connectLnbLive(lnbLive);
274 TunerTestingConfigAidlReader1_0::connectLnbRecord(lnbRecord);
Frankie Lizcano50461932022-06-28 21:36:26 +0000275 TunerTestingConfigAidlReader1_0::connectDvrPlayback(playback);
Hongguang600a6ae2021-07-08 18:51:51 -0700276};
277
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000278inline void determineDataFlows() {
279 determineScan();
280 determineTimeFilter();
281 determineDvrPlayback();
282 determineLnbLive();
283 determineLnbRecord();
284 determineLive();
285 determineDescrambling();
286 determineDvrRecord();
287}
288
Hongguang600a6ae2021-07-08 18:51:51 -0700289inline bool validateConnections() {
290 if (record.support && !record.hasFrontendConnection &&
291 record.dvrSourceId.compare(emptyHardwareId) == 0) {
292 ALOGW("[vts config] Record must support either a DVR source or a Frontend source.");
293 return false;
294 }
Gareth Fenn9a808452022-03-31 08:40:00 +0100295 bool feIsValid = live.hasFrontendConnection
296 ? frontendMap.find(live.frontendId) != frontendMap.end()
297 : true;
298 feIsValid &= scan.hasFrontendConnection ? frontendMap.find(scan.frontendId) != frontendMap.end()
299 : true;
300 feIsValid &= record.support && record.hasFrontendConnection
301 ? frontendMap.find(record.frontendId) != frontendMap.end()
302 : true;
Frankie Lizcanof5352122022-06-29 22:10:16 +0000303 feIsValid &= descrambling.support && descrambling.hasFrontendConnection
304 ? frontendMap.find(descrambling.frontendId) != frontendMap.end()
305 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700306
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000307 feIsValid &= lnbLive.support ? frontendMap.find(lnbLive.frontendId) != frontendMap.end() : true;
308
309 feIsValid &=
310 lnbRecord.support ? frontendMap.find(lnbRecord.frontendId) != frontendMap.end() : true;
311
Hongguang600a6ae2021-07-08 18:51:51 -0700312 if (!feIsValid) {
313 ALOGW("[vts config] dynamic config fe connection is invalid.");
314 return false;
315 }
316
317 bool dvrIsValid = frontendMap[live.frontendId].isSoftwareFe
318 ? dvrMap.find(live.dvrSoftwareFeId) != dvrMap.end()
319 : true;
320
321 if (record.support) {
322 if (record.hasFrontendConnection) {
323 if (frontendMap[record.frontendId].isSoftwareFe) {
324 dvrIsValid &= dvrMap.find(record.dvrSoftwareFeId) != dvrMap.end();
325 }
326 } else {
327 dvrIsValid &= dvrMap.find(record.dvrSourceId) != dvrMap.end();
328 }
329 dvrIsValid &= dvrMap.find(record.dvrRecordId) != dvrMap.end();
330 }
331
Frankie Lizcanof5352122022-06-29 22:10:16 +0000332 if (descrambling.support) {
333 if (descrambling.hasFrontendConnection) {
334 if (frontendMap[descrambling.frontendId].isSoftwareFe) {
335 dvrIsValid &= dvrMap.find(descrambling.dvrSoftwareFeId) != dvrMap.end();
336 }
337 } else {
338 dvrIsValid &= dvrMap.find(descrambling.dvrSourceId) != dvrMap.end();
339 }
340 }
341
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000342 dvrIsValid &= lnbRecord.support ? dvrMap.find(lnbRecord.dvrRecordId) != dvrMap.end() : true;
343
Frankie Lizcano50461932022-06-28 21:36:26 +0000344 dvrIsValid &= playback.support ? dvrMap.find(playback.dvrId) != dvrMap.end() : true;
345
Hongguang600a6ae2021-07-08 18:51:51 -0700346 if (!dvrIsValid) {
347 ALOGW("[vts config] dynamic config dvr connection is invalid.");
348 return false;
349 }
350
Gareth Fenn9a808452022-03-31 08:40:00 +0100351 bool filterIsValid = (live.hasFrontendConnection)
352 ? filterMap.find(live.audioFilterId) != filterMap.end() &&
353 filterMap.find(live.videoFilterId) != filterMap.end()
354 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700355 filterIsValid &=
356 record.support ? filterMap.find(record.recordFilterId) != filterMap.end() : true;
357
Frankie Lizcanof5352122022-06-29 22:10:16 +0000358 filterIsValid &= descrambling.support
359 ? filterMap.find(descrambling.videoFilterId) != filterMap.end() &&
360 filterMap.find(descrambling.audioFilterId) != filterMap.end()
361 : true;
362
363 for (auto& filterId : descrambling.extraFilters) {
364 filterIsValid &= filterMap.find(filterId) != filterMap.end();
365 }
366
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000367 filterIsValid &= lnbLive.support
368 ? filterMap.find(lnbLive.audioFilterId) != filterMap.end() &&
369 filterMap.find(lnbLive.videoFilterId) != filterMap.end()
370 : true;
371
372 filterIsValid &=
373 lnbRecord.support ? filterMap.find(lnbRecord.recordFilterId) != filterMap.end() : true;
374
375 for (auto& filterId : lnbRecord.extraFilters) {
376 filterIsValid &= filterMap.find(filterId) != filterMap.end();
377 }
378
379 for (auto& filterId : lnbLive.extraFilters) {
380 filterIsValid &= filterMap.find(filterId) != filterMap.end();
381 }
382
Frankie Lizcano50461932022-06-28 21:36:26 +0000383 filterIsValid &= playback.support
384 ? filterMap.find(playback.audioFilterId) != filterMap.end() &&
385 filterMap.find(playback.videoFilterId) != filterMap.end()
386 : true;
387 filterIsValid &= playback.sectionFilterId.compare(emptyHardwareId) == 0
388 ? true
389 : filterMap.find(playback.sectionFilterId) != filterMap.end();
390
391 for (auto& filterId : playback.extraFilters) {
392 filterIsValid &=
393 playback.hasExtraFilters ? filterMap.find(filterId) != filterMap.end() : true;
394 }
395
Hongguang600a6ae2021-07-08 18:51:51 -0700396 if (!filterIsValid) {
397 ALOGW("[vts config] dynamic config filter connection is invalid.");
398 return false;
399 }
400
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000401 bool timeFilterIsValid =
402 timeFilter.support ? timeFilterMap.find(timeFilter.timeFilterId) != timeFilterMap.end()
403 : true;
404
405 if (!timeFilterIsValid) {
406 ALOGW("[vts config] dynamic config time filter connection is invalid.");
Frankie Lizcanof5352122022-06-29 22:10:16 +0000407 }
408
409 bool descramblerIsValid =
410 descrambling.support
411 ? descramblerMap.find(descrambling.descramblerId) != descramblerMap.end()
412 : true;
413
414 if (!descramblerIsValid) {
415 ALOGW("[vts config] dynamic config descrambler connection is invalid.");
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000416 return false;
417 }
418
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000419 bool lnbIsValid = lnbLive.support ? lnbMap.find(lnbLive.lnbId) != lnbMap.end() : true;
420
421 lnbIsValid &= lnbRecord.support ? lnbMap.find(lnbRecord.lnbId) != lnbMap.end() : true;
422
423 if (!lnbIsValid) {
424 ALOGW("[vts config] dynamic config lnb connection is invalid.");
425 return false;
426 }
427
428 bool diseqcMsgsIsValid = true;
429
430 for (auto& msg : lnbRecord.diseqcMsgs) {
431 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
432 }
433
434 for (auto& msg : lnbLive.diseqcMsgs) {
435 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
436 }
437
438 if (!diseqcMsgsIsValid) {
439 ALOGW("[vts config] dynamic config diseqcMsg is invalid.");
440 return false;
441 }
442
Hongguang600a6ae2021-07-08 18:51:51 -0700443 return true;
444}