blob: 2132994a38d74d11d2d89811663a3974e05215ea [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;
Frankie Lizcano523e5452022-07-27 22:21:16 +000077static LnbDescramblingHardwareConnections lnbDescrambling;
Hongguang600a6ae2021-07-08 18:51:51 -070078
Frankie Lizcanoa53f5542022-07-07 17:32:06 +000079/*
80 * This function takes in a 2d vector of device Id's
81 * The n vectors correlate to the ids for n different devices (eg frontends, filters)
82 * The resultant 2d vector is every combination of id's with 1 id from each vector
83 */
84inline vector<vector<string>> generateIdCombinations(vector<vector<string>>& ids) {
85 vector<vector<string>> combinations;
86
87 // The index of each vector in ids that will be used in the next combination
88 // EG {0, 2} means combo {ids[0][0] ids[1][2]} will be next
89 const int size = static_cast<int>(ids.size());
90 vector<int> indexes_used_in_combination(size, 0);
91
92 // The vector number from ids whose elements we will cycle through to make combinations.
93 // First, start at the right most vector
94 int cycled_vector = size - 1;
95
96 while (cycled_vector >= 0) {
97 // Make a combination (one at a time)
98 vector<string> combo;
99 for (size_t i = 0; i < indexes_used_in_combination.size(); ++i) {
100 const int combo_index = indexes_used_in_combination[i];
101 combo.push_back(ids[i][combo_index]);
102 }
103 combinations.push_back(combo);
104
105 // Find the right most vector that still has space [elements left] to cycle through and
106 // create a combination
107 while (cycled_vector >= 0 &&
108 indexes_used_in_combination[cycled_vector] == ids[cycled_vector].size() - 1) {
109 cycled_vector--;
110 }
111
112 // Use this check to avoid segmentation faults
113 if (cycled_vector >= 0) {
114 // Once found, we have a vector we can cycle through, so increase to its next element
115 indexes_used_in_combination[cycled_vector]++;
116
117 // Reset the other vectors to the right to their first element so we can cycle through
118 // them again with the new element from cycled vector
119 for (size_t i = cycled_vector + 1; i < indexes_used_in_combination.size(); ++i) {
120 indexes_used_in_combination[i] = 0;
121 }
122
123 // all the vectors to the right were reset, so we can cycle through them again
124 // Start at the furthest right vector
125 cycled_vector = size - 1;
126 }
127 }
128
129 return combinations;
130}
131
132/*
133 * index 0 - playback dvr
134 * index 1 - audio filters
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000135 * index 2 - optional section filters
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000136 */
137static inline vector<DvrPlaybackHardwareConnections> generatePlaybackCombinations() {
138 vector<DvrPlaybackHardwareConnections> combinations;
139 vector<string> sectionFilterIds_optional = sectionFilterIds;
140 sectionFilterIds_optional.push_back(emptyHardwareId);
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000141 vector<vector<string>> deviceIds{playbackDvrIds, audioFilterIds, sectionFilterIds_optional};
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000142
143 const int dvrIndex = 0;
144 const int audioFilterIndex = 1;
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000145 const int sectionFilterIndex = 2;
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000146
147 auto idCombinations = generateIdCombinations(deviceIds);
148 for (auto& combo : idCombinations) {
149 DvrPlaybackHardwareConnections mPlayback;
150 mPlayback.dvrId = combo[dvrIndex];
151 mPlayback.audioFilterId = combo[audioFilterIndex];
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000152 mPlayback.sectionFilterId = combo[sectionFilterIndex];
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000153 const int videoFilterIndex =
154 find(audioFilterIds.begin(), audioFilterIds.end(), mPlayback.audioFilterId) -
155 audioFilterIds.begin();
156 mPlayback.videoFilterId = videoFilterIds[videoFilterIndex];
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000157 combinations.push_back(mPlayback);
158 }
159
160 return combinations;
161}
162
163static inline vector<DvrPlaybackHardwareConnections> generatePlaybackConfigs() {
164 vector<DvrPlaybackHardwareConnections> playback_configs;
165 if (configuredPlayback) {
166 ALOGD("Using DVR playback configuration provided.");
167 playback_configs = {playback};
168 } else {
169 ALOGD("Dvr playback not provided. Generating possible combinations. Consider adding it to "
170 "the configuration file.");
171 playback_configs = generatePlaybackCombinations();
172 }
173
174 return playback_configs;
175}
176
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000177/*
178 * index 0 - frontends
179 * index 1 - audio filters
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000180 * index 2 - lnbs
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000181 */
182static inline vector<LnbLiveHardwareConnections> generateLnbLiveCombinations() {
183 vector<LnbLiveHardwareConnections> combinations;
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000184 vector<vector<string>> deviceIds{frontendIds, audioFilterIds, lnbIds};
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000185
186 const int frontendIndex = 0;
187 const int audioFilterIndex = 1;
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000188 const int lnbIndex = 2;
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000189
190 // TODO: Find a better way to vary diseqcMsgs, if at all
191 auto idCombinations = generateIdCombinations(deviceIds);
192 for (auto& combo : idCombinations) {
193 const string feId = combo[frontendIndex];
194 auto type = frontendMap[feId].type;
195 if (type == FrontendType::DVBS || type == FrontendType::ISDBS ||
196 type == FrontendType::ISDBS3) {
197 LnbLiveHardwareConnections mLnbLive;
198 mLnbLive.frontendId = feId;
199 mLnbLive.audioFilterId = combo[audioFilterIndex];
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000200 const int videoFilterIndex =
201 find(audioFilterIds.begin(), audioFilterIds.end(), mLnbLive.audioFilterId) -
202 audioFilterIds.begin();
203 mLnbLive.videoFilterId = videoFilterIds[videoFilterIndex];
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000204 mLnbLive.lnbId = combo[lnbIndex];
205 mLnbLive.diseqcMsgs = diseqcMsgs;
206 combinations.push_back(mLnbLive);
207 }
208 }
209
210 return combinations;
211}
212
213static inline vector<LnbLiveHardwareConnections> generateLnbLiveConfigurations() {
214 vector<LnbLiveHardwareConnections> lnbLive_configs;
215 if (configuredLnbLive) {
216 ALOGD("Using LnbLive configuration provided.");
217 lnbLive_configs = {lnbLive};
218 } else {
219 ALOGD("LnbLive not provided. Generating possible combinations. Consider adding it to the "
220 "configuration file.");
221 lnbLive_configs = generateLnbLiveCombinations();
222 }
223
224 return lnbLive_configs;
225}
226
Frankie Lizcano3138d6b2022-07-11 22:06:45 +0000227static inline vector<ScanHardwareConnections> generateScanCombinations() {
228 vector<ScanHardwareConnections> combinations;
229
230 for (auto& id : frontendIds) {
231 ScanHardwareConnections mScan;
232 mScan.frontendId = id;
233 combinations.push_back(mScan);
234 }
235
236 return combinations;
237}
238
239static inline vector<ScanHardwareConnections> generateScanConfigurations() {
240 vector<ScanHardwareConnections> scan_configs;
241 if (configuredScan) {
242 ALOGD("Using scan configuration provided.");
243 scan_configs = {scan};
244 } else {
245 ALOGD("Scan not provided. Generating possible combinations. Consider adding it to "
246 "the configuration file.");
247 scan_configs = generateScanCombinations();
248 }
249
250 return scan_configs;
251}
252
Frankie Lizcanoecba02a2022-07-12 17:56:54 +0000253/*
254 * index 0 - frontends
255 * index 1 - record filter
256 * index 2 - Record Dvr
257 * index 3 - Lnb
258 */
259static inline vector<LnbRecordHardwareConnections> generateLnbRecordCombinations() {
260 vector<LnbRecordHardwareConnections> combinations;
261 vector<vector<string>> deviceIds{frontendIds, recordFilterIds, recordDvrIds, lnbIds};
262
263 const int frontendIndex = 0;
264 const int recordFilterIndex = 1;
265 const int dvrIndex = 2;
266 const int lnbIndex = 3;
267
268 auto idCombinations = generateIdCombinations(deviceIds);
269 // TODO : Find a better way to vary diseqcMsgs, if at all
270 for (auto& combo : idCombinations) {
271 const string feId = combo[frontendIndex];
272 auto type = frontendMap[feId].type;
273 if (type == FrontendType::DVBS || type == FrontendType::ISDBS ||
274 type == FrontendType::ISDBS3) {
275 LnbRecordHardwareConnections mLnbRecord;
276 mLnbRecord.frontendId = feId;
277 mLnbRecord.recordFilterId = combo[recordFilterIndex];
278 mLnbRecord.dvrRecordId = combo[dvrIndex];
279 mLnbRecord.lnbId = combo[lnbIndex];
280 mLnbRecord.diseqcMsgs = diseqcMsgs;
281 combinations.push_back(mLnbRecord);
282 }
283 }
284
285 return combinations;
286}
287
288static inline vector<LnbRecordHardwareConnections> generateLnbRecordConfigurations() {
289 vector<LnbRecordHardwareConnections> lnbRecord_configs;
290 if (configuredLnbRecord) {
291 ALOGD("Using LnbRecord configuration provided.");
292 lnbRecord_configs = {lnbRecord};
293 } else {
294 ALOGD("LnbRecord not provided. Generating possible combinations. Consider adding it to "
295 "the configuration file.");
296 lnbRecord_configs = generateLnbRecordCombinations();
297 }
298
299 return lnbRecord_configs;
300}
301
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000302/*
303 * index 0 - decramblers
304 * index 1 - frontends
305 * index 2 - audio filters
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000306 * index 3 - Dvr SW Fe Connections
307 * index 4 - DVR Source Connections
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000308 */
309static inline vector<DescramblingHardwareConnections> generateDescramblingCombinations() {
310 vector<DescramblingHardwareConnections> combinations;
311 vector<string> mfrontendIds = frontendIds;
312 vector<string> mDvrFeConnectionIds = playbackDvrIds;
313 vector<string> mDvrSourceConnectionIds = playbackDvrIds;
314
315 // Add the empty hardware id to each vector to include combinations where these 3 fields might
316 // be optional
317 mfrontendIds.push_back(emptyHardwareId);
318 mDvrFeConnectionIds.push_back(emptyHardwareId);
319 mDvrSourceConnectionIds.push_back(emptyHardwareId);
320
321 const int descramblerIndex = 0;
322 const int frontendIndex = 1;
323 const int audioFilterIndex = 2;
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000324 const int dvrFeIdIndex = 3;
325 const int dvrSourceIdIndex = 4;
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000326
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000327 vector<vector<string>> deviceIds{descramblerIds, mfrontendIds, audioFilterIds,
328 mDvrFeConnectionIds, mDvrSourceConnectionIds};
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000329 auto idCombinations = generateIdCombinations(deviceIds);
330 for (auto& combo : idCombinations) {
331 DescramblingHardwareConnections mDescrambling;
332 const string feId = combo[frontendIndex];
333 const string dvrSwFeId = combo[dvrFeIdIndex];
334 const string dvrSourceId = combo[dvrSourceIdIndex];
335 mDescrambling.hasFrontendConnection = feId.compare(emptyHardwareId) == 0 ? false : true;
336 if (!mDescrambling.hasFrontendConnection) {
337 if (dvrSourceId.compare(emptyHardwareId) == 0) {
338 // If combination does not have a frontend or dvr source connection, do not include
339 // it
340 continue;
341 }
342 } else {
343 if (frontendMap[feId].isSoftwareFe && dvrSwFeId.compare(emptyHardwareId) == 0) {
344 // If combination has a software frontend and no dvr->software frontend connection,
345 // do not include it
346 continue;
347 }
348 }
349 if (dvrSwFeId.compare(dvrSourceId) == 0) {
350 // If dvr->software frontend connection is the same as dvr source input to tuner, do not
351 // include it.
352 continue;
353 }
354 mDescrambling.frontendId = feId;
355 mDescrambling.audioFilterId = combo[audioFilterIndex];
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000356 const int videoFilterIndex =
357 find(audioFilterIds.begin(), audioFilterIds.end(), mDescrambling.audioFilterId) -
358 audioFilterIds.begin();
359 mDescrambling.videoFilterId = videoFilterIds[videoFilterIndex];
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000360 mDescrambling.dvrSoftwareFeId = dvrSwFeId;
361 mDescrambling.dvrSourceId = dvrSourceId;
362 mDescrambling.descramblerId = combo[descramblerIndex];
363 combinations.push_back(mDescrambling);
364 }
365
366 return combinations;
367}
368
369static inline vector<DescramblingHardwareConnections> generateDescramblingConfigurations() {
370 vector<DescramblingHardwareConnections> descrambling_configs;
371 if (configuredDescrambling) {
372 ALOGD("Using Descrambling configuration provided.");
373 descrambling_configs = {descrambling};
374 } else {
375 ALOGD("Descrambling not provided. Generating possible combinations. Consider adding it to "
376 "the "
377 "configuration file.");
378 descrambling_configs = generateDescramblingCombinations();
379 }
380
381 return descrambling_configs;
382}
383
Frankie Lizcano0c069532022-07-14 20:20:46 +0000384static inline vector<TimeFilterHardwareConnections> generateTimeFilterCombinations() {
385 vector<TimeFilterHardwareConnections> combinations;
386
387 for (auto& id : timeFilterIds) {
388 TimeFilterHardwareConnections mTimeFilter;
389 mTimeFilter.timeFilterId = id;
390 combinations.push_back(mTimeFilter);
391 }
392
393 return combinations;
394}
395
396static inline vector<TimeFilterHardwareConnections> generateTimeFilterConfigurations() {
397 vector<TimeFilterHardwareConnections> timeFilter_configs;
398 if (configuredTimeFilter) {
399 ALOGD("Using TimeFilter configuration provided.");
400 timeFilter_configs = {timeFilter};
401 } else {
402 ALOGD("TimeFilter not provided. Generating possible combinations. Consider adding it to "
403 "the "
404 "configuration file.");
405 timeFilter_configs = generateTimeFilterCombinations();
406 }
407
408 return timeFilter_configs;
409}
410
Frankie Lizcano9c464f72022-07-18 17:56:52 +0000411/*
412 * index 0 - frontends
413 * index 1 - record dvrs
414 * index 2 - record filters
415 */
416static inline vector<DvrRecordHardwareConnections> generateRecordCombinations() {
417 vector<DvrRecordHardwareConnections> combinations;
418
419 const int frontendIdIndex = 0;
420 const int recordDvrIndex = 1;
421 const int recordFilterIndex = 2;
422
423 vector<vector<string>> deviceIds{frontendIds, recordDvrIds, recordFilterIds};
424
425 auto idCombinations = generateIdCombinations(deviceIds);
426 for (auto& combo : idCombinations) {
427 DvrRecordHardwareConnections mRecord;
428 const string feId = combo[frontendIdIndex];
429 mRecord.hasFrontendConnection = true;
430 if (frontendMap[feId].isSoftwareFe) {
431 // If we have a software frontend, do not include configuration for testing.
432 continue;
433 }
434 mRecord.frontendId = feId;
435 mRecord.support = true;
436 mRecord.dvrSourceId = emptyHardwareId;
437 mRecord.dvrSoftwareFeId = emptyHardwareId;
438 mRecord.recordFilterId = combo[recordFilterIndex];
439 mRecord.dvrRecordId = combo[recordDvrIndex];
440 combinations.push_back(mRecord);
441 }
442
443 return combinations;
444}
445
446static inline vector<DvrRecordHardwareConnections> generateRecordConfigurations() {
447 vector<DvrRecordHardwareConnections> record_configs;
448 if (configuredRecord) {
449 ALOGD("Using Record configuration provided.");
450 record_configs = {record};
451 } else {
452 ALOGD("Record not provided. Generating possible combinations. Consider adding it to "
453 "the "
454 "configuration file.");
455 record_configs = generateRecordCombinations();
456 }
457
458 return record_configs;
459}
460
Frankie Lizcano8b87f252022-07-19 21:51:54 +0000461/*
462 * index 0 - frontends
463 * index 1 - audio filters
464 * index 2 - playback dvrs
465 * index 3 - section Filters
466 */
467static inline vector<LiveBroadcastHardwareConnections> generateLiveCombinations() {
468 vector<LiveBroadcastHardwareConnections> combinations;
469 vector<string> mSectionFilterIds = sectionFilterIds;
470 vector<string> mDvrSwConnectionIds = playbackDvrIds;
471
472 // Adding the empty hardware id to cover cases where fields are optional
473 mSectionFilterIds.push_back(emptyHardwareId);
474 mDvrSwConnectionIds.push_back(emptyHardwareId);
475
476 const int frontendIdIndex = 0;
477 const int audioFilterIdIndex = 1;
478 const int dvrSwConnectionIdIndex = 2;
479 const int sectionFilterIdIndex = 3;
480
481 vector<vector<string>> deviceIds{frontendIds, audioFilterIds, mDvrSwConnectionIds,
482 mSectionFilterIds};
483
484 auto idCombinations = generateIdCombinations(deviceIds);
485 for (auto& combo : idCombinations) {
486 LiveBroadcastHardwareConnections mLive;
487 const string feId = combo[frontendIdIndex];
488 const string dvrSwConnectionId = combo[dvrSwConnectionIdIndex];
489 mLive.hasFrontendConnection = true;
490
491 if (frontendMap[feId].isSoftwareFe && dvrSwConnectionId.compare(emptyHardwareId) == 0) {
492 // If the frontend is a software frontend and there is no dvr playback connected, do not
493 // include configuration
494 continue;
495 }
496 mLive.frontendId = feId;
497 mLive.dvrSoftwareFeId = dvrSwConnectionId;
498 mLive.audioFilterId = combo[audioFilterIdIndex];
499 const int videoFilterIdIndex =
500 find(audioFilterIds.begin(), audioFilterIds.end(), mLive.audioFilterId) -
501 audioFilterIds.begin();
502 mLive.videoFilterId = videoFilterIds[videoFilterIdIndex];
503 mLive.sectionFilterId = combo[sectionFilterIdIndex];
504
505 if (pcrFilterIds.empty()) {
506 // If pcr Filters have not been provided, set it to empty hardware id
507 mLive.pcrFilterId = emptyHardwareId;
508 } else {
509 // If pcr Filters have been provided, use the first index if there is only 1, or choose
510 // the filter that corresponds to the correct audio and video filter pair
511 const int pcrFilterIdIndex = pcrFilterIds.size() == 1 ? 0 : videoFilterIdIndex;
512 mLive.pcrFilterId = pcrFilterIds[pcrFilterIdIndex];
513 }
514
515 combinations.push_back(mLive);
516 }
517
518 return combinations;
519}
520
521static inline vector<LiveBroadcastHardwareConnections> generateLiveConfigurations() {
522 vector<LiveBroadcastHardwareConnections> live_configs;
523 if (configuredLive) {
524 ALOGD("Using Live configuration provided.");
525 live_configs = {live};
526 } else {
527 ALOGD("Live not provided. Generating possible combinations. Consider adding it to "
528 "the "
529 "configuration file.");
530 live_configs = generateLiveCombinations();
531 }
532
533 return live_configs;
534}
535
Hongguang600a6ae2021-07-08 18:51:51 -0700536/** Config all the frontends that would be used in the tests */
537inline void initFrontendConfig() {
538 // The test will use the internal default fe when default fe is connected to any data flow
539 // without overriding in the xml config.
540 string defaultFeId = "FE_DEFAULT";
541 FrontendDvbtSettings dvbtSettings{
Gareth Fenn282fb372021-09-27 15:14:11 +0100542 .frequency = 578000000,
Hongguang600a6ae2021-07-08 18:51:51 -0700543 .transmissionMode = FrontendDvbtTransmissionMode::AUTO,
544 .bandwidth = FrontendDvbtBandwidth::BANDWIDTH_8MHZ,
545 .isHighPriority = true,
546 };
547 frontendMap[defaultFeId].type = FrontendType::DVBT;
548 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbtSettings);
549
550 vector<FrontendStatusType> types;
551 types.push_back(FrontendStatusType::UEC);
552 types.push_back(FrontendStatusType::IS_MISO);
553
554 vector<FrontendStatus> statuses;
555 FrontendStatus status;
556 status.set<FrontendStatus::Tag::uec>(4);
557 statuses.push_back(status);
558 status.set<FrontendStatus::Tag::isMiso>(true);
559 statuses.push_back(status);
560
561 frontendMap[defaultFeId].tuneStatusTypes = types;
562 frontendMap[defaultFeId].expectTuneStatuses = statuses;
563 frontendMap[defaultFeId].isSoftwareFe = true;
564 frontendMap[defaultFeId].canConnectToCiCam = true;
565 frontendMap[defaultFeId].ciCamId = 0;
566 FrontendDvbtSettings dvbt;
567 dvbt.transmissionMode = FrontendDvbtTransmissionMode::MODE_8K_E;
568 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbt);
569 // Read customized config
570 TunerTestingConfigAidlReader1_0::readFrontendConfig1_0(frontendMap);
571};
572
573inline void initFilterConfig() {
574 // The test will use the internal default filter when default filter is connected to any
575 // data flow without overriding in the xml config.
576 string defaultAudioFilterId = "FILTER_AUDIO_DEFAULT";
577 string defaultVideoFilterId = "FILTER_VIDEO_DEFAULT";
578
579 filterMap[defaultVideoFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700580 filterMap[defaultVideoFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
581 DemuxTsFilterType::VIDEO);
Hongguang600a6ae2021-07-08 18:51:51 -0700582 filterMap[defaultVideoFilterId].bufferSize = FMQ_SIZE_16M;
583 filterMap[defaultVideoFilterId].settings =
584 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
585 filterMap[defaultVideoFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
586 DemuxFilterAvSettings video;
587 video.isPassthrough = false;
588 filterMap[defaultVideoFilterId]
589 .settings.get<DemuxFilterSettings::Tag::ts>()
590 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(video);
591 filterMap[defaultVideoFilterId].monitorEventTypes =
592 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
593 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
594 filterMap[defaultVideoFilterId].streamType.set<AvStreamType::Tag::video>(
595 VideoStreamType::MPEG1);
596
597 filterMap[defaultAudioFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700598 filterMap[defaultAudioFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
599 DemuxTsFilterType::AUDIO);
Hongguang600a6ae2021-07-08 18:51:51 -0700600 filterMap[defaultAudioFilterId].bufferSize = FMQ_SIZE_16M;
601 filterMap[defaultAudioFilterId].settings =
602 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
603 filterMap[defaultAudioFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
604 DemuxFilterAvSettings audio;
605 audio.isPassthrough = false;
606 filterMap[defaultAudioFilterId]
607 .settings.get<DemuxFilterSettings::Tag::ts>()
608 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(audio);
609 filterMap[defaultAudioFilterId].monitorEventTypes =
610 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
611 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
612 filterMap[defaultAudioFilterId].streamType.set<AvStreamType::Tag::audio>(AudioStreamType::MP3);
613 // Read customized config
614 TunerTestingConfigAidlReader1_0::readFilterConfig1_0(filterMap);
615};
616
617/** Config all the dvrs that would be used in the tests */
618inline void initDvrConfig() {
619 // Read customized config
620 TunerTestingConfigAidlReader1_0::readDvrConfig1_0(dvrMap);
621};
622
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000623inline void initTimeFilterConfig() {
624 // Read customized config
625 TunerTestingConfigAidlReader1_0::readTimeFilterConfig1_0(timeFilterMap);
626};
627
Frankie Lizcanof5352122022-06-29 22:10:16 +0000628inline void initDescramblerConfig() {
629 // Read customized config
630 TunerTestingConfigAidlReader1_0::readDescramblerConfig1_0(descramblerMap);
631}
632
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000633inline void initLnbConfig() {
634 // Read customized config
635 TunerTestingConfigAidlReader1_0::readLnbConfig1_0(lnbMap);
636};
637
638inline void initDiseqcMsgsConfig() {
639 // Read customized config
640 TunerTestingConfigAidlReader1_0::readDiseqcMessages(diseqcMsgMap);
641};
642
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000643inline void determineScan() {
644 if (!frontendMap.empty()) {
645 scan.hasFrontendConnection = true;
646 ALOGD("Can support scan");
647 }
648}
649
650inline void determineTimeFilter() {
651 if (!timeFilterMap.empty()) {
652 timeFilter.support = true;
653 ALOGD("Can support time filter");
654 }
655}
656
657inline void determineDvrPlayback() {
658 if (!playbackDvrIds.empty() && !audioFilterIds.empty() && !videoFilterIds.empty()) {
659 playback.support = true;
660 ALOGD("Can support dvr playback");
661 }
662}
663
664inline void determineLnbLive() {
665 if (!audioFilterIds.empty() && !videoFilterIds.empty() && !frontendMap.empty() &&
666 !lnbMap.empty()) {
667 lnbLive.support = true;
668 ALOGD("Can support lnb live");
669 }
670}
671
672inline void determineLnbRecord() {
673 if (!frontendMap.empty() && !recordFilterIds.empty() && !recordDvrIds.empty() &&
674 !lnbMap.empty()) {
675 lnbRecord.support = true;
676 ALOGD("Can support lnb record");
677 }
678}
679
680inline void determineLive() {
681 if (videoFilterIds.empty() || audioFilterIds.empty() || frontendMap.empty()) {
682 return;
683 }
684 if (hasSwFe && !hasHwFe && dvrMap.empty()) {
685 ALOGD("Cannot configure Live. Only software frontends and no dvr connections");
686 return;
687 }
688 ALOGD("Can support live");
689 live.hasFrontendConnection = true;
690}
691
692inline void determineDescrambling() {
693 if (descramblerMap.empty() || audioFilterIds.empty() || videoFilterIds.empty()) {
694 return;
695 }
696 if (frontendMap.empty() && playbackDvrIds.empty()) {
697 ALOGD("Cannot configure descrambling. No frontends or playback dvr's");
698 return;
699 }
700 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
701 ALOGD("cannot configure descrambling. Only SW frontends and no playback dvr's");
702 return;
703 }
704 ALOGD("Can support descrambling");
705 descrambling.support = true;
706}
707
708inline void determineDvrRecord() {
709 if (recordDvrIds.empty() || recordFilterIds.empty()) {
710 return;
711 }
712 if (frontendMap.empty() && playbackDvrIds.empty()) {
Frankie Lizcanoecba02a2022-07-12 17:56:54 +0000713 ALOGD("Cannot support dvr record. No frontends and no playback dvr's");
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000714 return;
715 }
716 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
717 ALOGD("Cannot support dvr record. Only SW frontends and no playback dvr's");
718 return;
719 }
720 ALOGD("Can support dvr record.");
721 record.support = true;
722}
723
Hongguang600a6ae2021-07-08 18:51:51 -0700724/** Read the vendor configurations of which hardware to use for each test cases/data flows */
725inline void connectHardwaresToTestCases() {
726 TunerTestingConfigAidlReader1_0::connectLiveBroadcast(live);
727 TunerTestingConfigAidlReader1_0::connectScan(scan);
728 TunerTestingConfigAidlReader1_0::connectDvrRecord(record);
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000729 TunerTestingConfigAidlReader1_0::connectTimeFilter(timeFilter);
Frankie Lizcanof5352122022-06-29 22:10:16 +0000730 TunerTestingConfigAidlReader1_0::connectDescrambling(descrambling);
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000731 TunerTestingConfigAidlReader1_0::connectLnbLive(lnbLive);
Frankie Lizcano3138d6b2022-07-11 22:06:45 +0000732 TunerTestingConfigAidlReader1_0::connectLnbRecord(lnbRecord);
Frankie Lizcano50461932022-06-28 21:36:26 +0000733 TunerTestingConfigAidlReader1_0::connectDvrPlayback(playback);
Frankie Lizcano523e5452022-07-27 22:21:16 +0000734 TunerTestingConfigAidlReader1_0::connectLnbDescrambling(lnbDescrambling);
Hongguang600a6ae2021-07-08 18:51:51 -0700735};
736
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000737inline void determineDataFlows() {
738 determineScan();
739 determineTimeFilter();
740 determineDvrPlayback();
741 determineLnbLive();
742 determineLnbRecord();
743 determineLive();
744 determineDescrambling();
745 determineDvrRecord();
746}
747
Hongguang600a6ae2021-07-08 18:51:51 -0700748inline bool validateConnections() {
749 if (record.support && !record.hasFrontendConnection &&
750 record.dvrSourceId.compare(emptyHardwareId) == 0) {
751 ALOGW("[vts config] Record must support either a DVR source or a Frontend source.");
752 return false;
753 }
Gareth Fenn9a808452022-03-31 08:40:00 +0100754 bool feIsValid = live.hasFrontendConnection
755 ? frontendMap.find(live.frontendId) != frontendMap.end()
756 : true;
757 feIsValid &= scan.hasFrontendConnection ? frontendMap.find(scan.frontendId) != frontendMap.end()
758 : true;
759 feIsValid &= record.support && record.hasFrontendConnection
760 ? frontendMap.find(record.frontendId) != frontendMap.end()
761 : true;
Frankie Lizcanof5352122022-06-29 22:10:16 +0000762 feIsValid &= descrambling.support && descrambling.hasFrontendConnection
763 ? frontendMap.find(descrambling.frontendId) != frontendMap.end()
764 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700765
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000766 feIsValid &= lnbLive.support ? frontendMap.find(lnbLive.frontendId) != frontendMap.end() : true;
767
768 feIsValid &=
769 lnbRecord.support ? frontendMap.find(lnbRecord.frontendId) != frontendMap.end() : true;
770
Frankie Lizcano523e5452022-07-27 22:21:16 +0000771 feIsValid &= lnbDescrambling.support
772 ? frontendMap.find(lnbDescrambling.frontendId) != frontendMap.end()
773 : true;
774
Hongguang600a6ae2021-07-08 18:51:51 -0700775 if (!feIsValid) {
776 ALOGW("[vts config] dynamic config fe connection is invalid.");
777 return false;
778 }
779
780 bool dvrIsValid = frontendMap[live.frontendId].isSoftwareFe
781 ? dvrMap.find(live.dvrSoftwareFeId) != dvrMap.end()
782 : true;
783
784 if (record.support) {
785 if (record.hasFrontendConnection) {
786 if (frontendMap[record.frontendId].isSoftwareFe) {
787 dvrIsValid &= dvrMap.find(record.dvrSoftwareFeId) != dvrMap.end();
788 }
789 } else {
790 dvrIsValid &= dvrMap.find(record.dvrSourceId) != dvrMap.end();
791 }
792 dvrIsValid &= dvrMap.find(record.dvrRecordId) != dvrMap.end();
793 }
794
Frankie Lizcanof5352122022-06-29 22:10:16 +0000795 if (descrambling.support) {
796 if (descrambling.hasFrontendConnection) {
797 if (frontendMap[descrambling.frontendId].isSoftwareFe) {
798 dvrIsValid &= dvrMap.find(descrambling.dvrSoftwareFeId) != dvrMap.end();
799 }
800 } else {
801 dvrIsValid &= dvrMap.find(descrambling.dvrSourceId) != dvrMap.end();
802 }
803 }
804
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000805 dvrIsValid &= lnbRecord.support ? dvrMap.find(lnbRecord.dvrRecordId) != dvrMap.end() : true;
806
Frankie Lizcano50461932022-06-28 21:36:26 +0000807 dvrIsValid &= playback.support ? dvrMap.find(playback.dvrId) != dvrMap.end() : true;
808
Hongguang600a6ae2021-07-08 18:51:51 -0700809 if (!dvrIsValid) {
810 ALOGW("[vts config] dynamic config dvr connection is invalid.");
811 return false;
812 }
813
Gareth Fenn9a808452022-03-31 08:40:00 +0100814 bool filterIsValid = (live.hasFrontendConnection)
815 ? filterMap.find(live.audioFilterId) != filterMap.end() &&
816 filterMap.find(live.videoFilterId) != filterMap.end()
817 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700818 filterIsValid &=
819 record.support ? filterMap.find(record.recordFilterId) != filterMap.end() : true;
820
Frankie Lizcanof5352122022-06-29 22:10:16 +0000821 filterIsValid &= descrambling.support
822 ? filterMap.find(descrambling.videoFilterId) != filterMap.end() &&
823 filterMap.find(descrambling.audioFilterId) != filterMap.end()
824 : true;
825
826 for (auto& filterId : descrambling.extraFilters) {
827 filterIsValid &= filterMap.find(filterId) != filterMap.end();
828 }
829
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000830 filterIsValid &= lnbLive.support
831 ? filterMap.find(lnbLive.audioFilterId) != filterMap.end() &&
832 filterMap.find(lnbLive.videoFilterId) != filterMap.end()
833 : true;
834
835 filterIsValid &=
836 lnbRecord.support ? filterMap.find(lnbRecord.recordFilterId) != filterMap.end() : true;
837
838 for (auto& filterId : lnbRecord.extraFilters) {
839 filterIsValid &= filterMap.find(filterId) != filterMap.end();
840 }
841
842 for (auto& filterId : lnbLive.extraFilters) {
843 filterIsValid &= filterMap.find(filterId) != filterMap.end();
844 }
845
Frankie Lizcano50461932022-06-28 21:36:26 +0000846 filterIsValid &= playback.support
847 ? filterMap.find(playback.audioFilterId) != filterMap.end() &&
848 filterMap.find(playback.videoFilterId) != filterMap.end()
849 : true;
850 filterIsValid &= playback.sectionFilterId.compare(emptyHardwareId) == 0
851 ? true
852 : filterMap.find(playback.sectionFilterId) != filterMap.end();
853
854 for (auto& filterId : playback.extraFilters) {
855 filterIsValid &=
856 playback.hasExtraFilters ? filterMap.find(filterId) != filterMap.end() : true;
857 }
858
Frankie Lizcano523e5452022-07-27 22:21:16 +0000859 filterIsValid &=
860 lnbDescrambling.support
861 ? filterMap.find(lnbDescrambling.audioFilterId) != filterMap.end() &&
862 filterMap.find(lnbDescrambling.videoFilterId) != filterMap.end()
863 : true;
864
Hongguang600a6ae2021-07-08 18:51:51 -0700865 if (!filterIsValid) {
866 ALOGW("[vts config] dynamic config filter connection is invalid.");
867 return false;
868 }
869
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000870 if (audioFilterIds.size() != videoFilterIds.size()) {
871 ALOGW("[vts config] the number of audio and video filters should be equal");
872 return false;
873 }
874
Frankie Lizcano8b87f252022-07-19 21:51:54 +0000875 if (!pcrFilterIds.empty() && pcrFilterIds.size() != 1 &&
876 pcrFilterIds.size() != audioFilterIds.size()) {
877 ALOGW("[vts config] When more than 1 pcr filter is configured, the number of pcr filters "
878 "must equal the number of audio and video filters.");
879 return false;
880 }
881
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000882 bool timeFilterIsValid =
883 timeFilter.support ? timeFilterMap.find(timeFilter.timeFilterId) != timeFilterMap.end()
884 : true;
885
886 if (!timeFilterIsValid) {
887 ALOGW("[vts config] dynamic config time filter connection is invalid.");
Frankie Lizcanof5352122022-06-29 22:10:16 +0000888 }
889
890 bool descramblerIsValid =
891 descrambling.support
892 ? descramblerMap.find(descrambling.descramblerId) != descramblerMap.end()
893 : true;
894
Frankie Lizcano523e5452022-07-27 22:21:16 +0000895 descramblerIsValid &=
896 lnbDescrambling.support
897 ? descramblerMap.find(lnbDescrambling.descramblerId) != descramblerMap.end()
898 : true;
899
Frankie Lizcanof5352122022-06-29 22:10:16 +0000900 if (!descramblerIsValid) {
901 ALOGW("[vts config] dynamic config descrambler connection is invalid.");
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000902 return false;
903 }
904
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000905 bool lnbIsValid = lnbLive.support ? lnbMap.find(lnbLive.lnbId) != lnbMap.end() : true;
906
907 lnbIsValid &= lnbRecord.support ? lnbMap.find(lnbRecord.lnbId) != lnbMap.end() : true;
908
Frankie Lizcano523e5452022-07-27 22:21:16 +0000909 lnbIsValid &=
910 lnbDescrambling.support ? lnbMap.find(lnbDescrambling.lnbId) != lnbMap.end() : true;
911
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000912 if (!lnbIsValid) {
913 ALOGW("[vts config] dynamic config lnb connection is invalid.");
914 return false;
915 }
916
917 bool diseqcMsgsIsValid = true;
918
919 for (auto& msg : lnbRecord.diseqcMsgs) {
920 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
921 }
922
923 for (auto& msg : lnbLive.diseqcMsgs) {
924 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
925 }
926
Frankie Lizcano523e5452022-07-27 22:21:16 +0000927 for (auto& msg : lnbDescrambling.diseqcMsgs) {
928 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
929 }
930
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000931 if (!diseqcMsgsIsValid) {
932 ALOGW("[vts config] dynamic config diseqcMsg is invalid.");
933 return false;
934 }
935
Hongguang600a6ae2021-07-08 18:51:51 -0700936 return true;
937}