blob: fea5f838265e6e92b82135f62db856b72340128b [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
Frankie Lizcanobcf4ebb2022-08-01 18:06:00 +0000536static inline vector<LnbDescramblingHardwareConnections> generateLnbDescramblingCombinations() {
537 vector<LnbDescramblingHardwareConnections> combinations;
538 vector<vector<string>> deviceIds{frontendIds, audioFilterIds, lnbIds, descramblerIds};
539
540 const int frontendIdIndex = 0;
541 const int audioFilterIdIndex = 1;
542 const int lnbIdIndex = 2;
543 const int descramblerIdIndex = 3;
544
545 auto idCombinations = generateIdCombinations(deviceIds);
546 // TODO : Find a better way to vary diseqcMsgs, if at all
547 for (auto& combo : idCombinations) {
548 const string feId = combo[frontendIdIndex];
549 auto type = frontendMap[feId].type;
550 if (type == FrontendType::DVBS || type == FrontendType::ISDBS ||
551 type == FrontendType::ISDBS3) {
552 LnbDescramblingHardwareConnections mLnbDescrambling;
553 mLnbDescrambling.support = true;
554 mLnbDescrambling.frontendId = feId;
555 mLnbDescrambling.audioFilterId = combo[audioFilterIdIndex];
556 const int videoFilterIdIndex = find(audioFilterIds.begin(), audioFilterIds.end(),
557 mLnbDescrambling.audioFilterId) -
558 audioFilterIds.begin();
559 mLnbDescrambling.videoFilterId = videoFilterIds[videoFilterIdIndex];
560 mLnbDescrambling.lnbId = combo[lnbIdIndex];
561 mLnbDescrambling.descramblerId = combo[descramblerIdIndex];
562 mLnbDescrambling.diseqcMsgs = diseqcMsgs;
563 combinations.push_back(mLnbDescrambling);
564 }
565 }
566
567 return combinations;
568}
569
570static inline vector<LnbDescramblingHardwareConnections> generateLnbDescramblingConfigurations() {
571 vector<LnbDescramblingHardwareConnections> lnbDescrambling_configs;
572 if (configuredLnbDescrambling) {
573 ALOGD("Using LnbDescrambling configuration provided");
574 lnbDescrambling_configs = {lnbDescrambling};
575 } else {
576 ALOGD("LnbDescrambling not provided. Generating possible combinations. Consider adding it "
577 "to the configuration file.");
578 lnbDescrambling_configs = generateLnbDescramblingCombinations();
579 }
580
581 return lnbDescrambling_configs;
582}
583
Hongguang600a6ae2021-07-08 18:51:51 -0700584/** Config all the frontends that would be used in the tests */
585inline void initFrontendConfig() {
586 // The test will use the internal default fe when default fe is connected to any data flow
587 // without overriding in the xml config.
588 string defaultFeId = "FE_DEFAULT";
589 FrontendDvbtSettings dvbtSettings{
Gareth Fenn282fb372021-09-27 15:14:11 +0100590 .frequency = 578000000,
Hongguang600a6ae2021-07-08 18:51:51 -0700591 .transmissionMode = FrontendDvbtTransmissionMode::AUTO,
592 .bandwidth = FrontendDvbtBandwidth::BANDWIDTH_8MHZ,
593 .isHighPriority = true,
594 };
595 frontendMap[defaultFeId].type = FrontendType::DVBT;
596 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbtSettings);
597
598 vector<FrontendStatusType> types;
599 types.push_back(FrontendStatusType::UEC);
600 types.push_back(FrontendStatusType::IS_MISO);
601
602 vector<FrontendStatus> statuses;
603 FrontendStatus status;
604 status.set<FrontendStatus::Tag::uec>(4);
605 statuses.push_back(status);
606 status.set<FrontendStatus::Tag::isMiso>(true);
607 statuses.push_back(status);
608
609 frontendMap[defaultFeId].tuneStatusTypes = types;
610 frontendMap[defaultFeId].expectTuneStatuses = statuses;
611 frontendMap[defaultFeId].isSoftwareFe = true;
612 frontendMap[defaultFeId].canConnectToCiCam = true;
613 frontendMap[defaultFeId].ciCamId = 0;
614 FrontendDvbtSettings dvbt;
615 dvbt.transmissionMode = FrontendDvbtTransmissionMode::MODE_8K_E;
616 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbt);
617 // Read customized config
618 TunerTestingConfigAidlReader1_0::readFrontendConfig1_0(frontendMap);
619};
620
621inline void initFilterConfig() {
622 // The test will use the internal default filter when default filter is connected to any
623 // data flow without overriding in the xml config.
624 string defaultAudioFilterId = "FILTER_AUDIO_DEFAULT";
625 string defaultVideoFilterId = "FILTER_VIDEO_DEFAULT";
626
627 filterMap[defaultVideoFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700628 filterMap[defaultVideoFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
629 DemuxTsFilterType::VIDEO);
Hongguang600a6ae2021-07-08 18:51:51 -0700630 filterMap[defaultVideoFilterId].bufferSize = FMQ_SIZE_16M;
631 filterMap[defaultVideoFilterId].settings =
632 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
633 filterMap[defaultVideoFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
634 DemuxFilterAvSettings video;
635 video.isPassthrough = false;
636 filterMap[defaultVideoFilterId]
637 .settings.get<DemuxFilterSettings::Tag::ts>()
638 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(video);
639 filterMap[defaultVideoFilterId].monitorEventTypes =
640 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
641 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
642 filterMap[defaultVideoFilterId].streamType.set<AvStreamType::Tag::video>(
643 VideoStreamType::MPEG1);
644
645 filterMap[defaultAudioFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700646 filterMap[defaultAudioFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
647 DemuxTsFilterType::AUDIO);
Hongguang600a6ae2021-07-08 18:51:51 -0700648 filterMap[defaultAudioFilterId].bufferSize = FMQ_SIZE_16M;
649 filterMap[defaultAudioFilterId].settings =
650 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
651 filterMap[defaultAudioFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
652 DemuxFilterAvSettings audio;
653 audio.isPassthrough = false;
654 filterMap[defaultAudioFilterId]
655 .settings.get<DemuxFilterSettings::Tag::ts>()
656 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(audio);
657 filterMap[defaultAudioFilterId].monitorEventTypes =
658 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
659 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
660 filterMap[defaultAudioFilterId].streamType.set<AvStreamType::Tag::audio>(AudioStreamType::MP3);
661 // Read customized config
662 TunerTestingConfigAidlReader1_0::readFilterConfig1_0(filterMap);
663};
664
665/** Config all the dvrs that would be used in the tests */
666inline void initDvrConfig() {
667 // Read customized config
668 TunerTestingConfigAidlReader1_0::readDvrConfig1_0(dvrMap);
669};
670
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000671inline void initTimeFilterConfig() {
672 // Read customized config
673 TunerTestingConfigAidlReader1_0::readTimeFilterConfig1_0(timeFilterMap);
674};
675
Frankie Lizcanof5352122022-06-29 22:10:16 +0000676inline void initDescramblerConfig() {
677 // Read customized config
678 TunerTestingConfigAidlReader1_0::readDescramblerConfig1_0(descramblerMap);
679}
680
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000681inline void initLnbConfig() {
682 // Read customized config
683 TunerTestingConfigAidlReader1_0::readLnbConfig1_0(lnbMap);
684};
685
686inline void initDiseqcMsgsConfig() {
687 // Read customized config
688 TunerTestingConfigAidlReader1_0::readDiseqcMessages(diseqcMsgMap);
689};
690
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000691inline void determineScan() {
692 if (!frontendMap.empty()) {
693 scan.hasFrontendConnection = true;
694 ALOGD("Can support scan");
695 }
696}
697
698inline void determineTimeFilter() {
699 if (!timeFilterMap.empty()) {
700 timeFilter.support = true;
701 ALOGD("Can support time filter");
702 }
703}
704
705inline void determineDvrPlayback() {
706 if (!playbackDvrIds.empty() && !audioFilterIds.empty() && !videoFilterIds.empty()) {
707 playback.support = true;
708 ALOGD("Can support dvr playback");
709 }
710}
711
712inline void determineLnbLive() {
713 if (!audioFilterIds.empty() && !videoFilterIds.empty() && !frontendMap.empty() &&
714 !lnbMap.empty()) {
715 lnbLive.support = true;
716 ALOGD("Can support lnb live");
717 }
718}
719
720inline void determineLnbRecord() {
721 if (!frontendMap.empty() && !recordFilterIds.empty() && !recordDvrIds.empty() &&
722 !lnbMap.empty()) {
723 lnbRecord.support = true;
724 ALOGD("Can support lnb record");
725 }
726}
727
728inline void determineLive() {
729 if (videoFilterIds.empty() || audioFilterIds.empty() || frontendMap.empty()) {
730 return;
731 }
732 if (hasSwFe && !hasHwFe && dvrMap.empty()) {
733 ALOGD("Cannot configure Live. Only software frontends and no dvr connections");
734 return;
735 }
736 ALOGD("Can support live");
737 live.hasFrontendConnection = true;
738}
739
740inline void determineDescrambling() {
741 if (descramblerMap.empty() || audioFilterIds.empty() || videoFilterIds.empty()) {
742 return;
743 }
744 if (frontendMap.empty() && playbackDvrIds.empty()) {
745 ALOGD("Cannot configure descrambling. No frontends or playback dvr's");
746 return;
747 }
748 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
749 ALOGD("cannot configure descrambling. Only SW frontends and no playback dvr's");
750 return;
751 }
752 ALOGD("Can support descrambling");
753 descrambling.support = true;
754}
755
756inline void determineDvrRecord() {
757 if (recordDvrIds.empty() || recordFilterIds.empty()) {
758 return;
759 }
760 if (frontendMap.empty() && playbackDvrIds.empty()) {
Frankie Lizcanoecba02a2022-07-12 17:56:54 +0000761 ALOGD("Cannot support dvr record. No frontends and no playback dvr's");
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000762 return;
763 }
764 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
765 ALOGD("Cannot support dvr record. Only SW frontends and no playback dvr's");
766 return;
767 }
768 ALOGD("Can support dvr record.");
769 record.support = true;
770}
771
Frankie Lizcanobcf4ebb2022-08-01 18:06:00 +0000772inline void determineLnbDescrambling() {
773 if (frontendIds.empty() || audioFilterIds.empty() || videoFilterIds.empty() || lnbIds.empty() ||
774 descramblerIds.empty()) {
775 return;
776 }
777 ALOGD("Can support LnbDescrambling.");
778 lnbDescrambling.support = true;
779}
780
Hongguang600a6ae2021-07-08 18:51:51 -0700781/** Read the vendor configurations of which hardware to use for each test cases/data flows */
782inline void connectHardwaresToTestCases() {
783 TunerTestingConfigAidlReader1_0::connectLiveBroadcast(live);
784 TunerTestingConfigAidlReader1_0::connectScan(scan);
785 TunerTestingConfigAidlReader1_0::connectDvrRecord(record);
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000786 TunerTestingConfigAidlReader1_0::connectTimeFilter(timeFilter);
Frankie Lizcanof5352122022-06-29 22:10:16 +0000787 TunerTestingConfigAidlReader1_0::connectDescrambling(descrambling);
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000788 TunerTestingConfigAidlReader1_0::connectLnbLive(lnbLive);
Frankie Lizcano3138d6b2022-07-11 22:06:45 +0000789 TunerTestingConfigAidlReader1_0::connectLnbRecord(lnbRecord);
Frankie Lizcano50461932022-06-28 21:36:26 +0000790 TunerTestingConfigAidlReader1_0::connectDvrPlayback(playback);
Frankie Lizcano523e5452022-07-27 22:21:16 +0000791 TunerTestingConfigAidlReader1_0::connectLnbDescrambling(lnbDescrambling);
Hongguang600a6ae2021-07-08 18:51:51 -0700792};
793
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000794inline void determineDataFlows() {
795 determineScan();
796 determineTimeFilter();
797 determineDvrPlayback();
798 determineLnbLive();
799 determineLnbRecord();
800 determineLive();
801 determineDescrambling();
802 determineDvrRecord();
Frankie Lizcanobcf4ebb2022-08-01 18:06:00 +0000803 determineLnbDescrambling();
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000804}
805
Hongguang600a6ae2021-07-08 18:51:51 -0700806inline bool validateConnections() {
807 if (record.support && !record.hasFrontendConnection &&
808 record.dvrSourceId.compare(emptyHardwareId) == 0) {
809 ALOGW("[vts config] Record must support either a DVR source or a Frontend source.");
810 return false;
811 }
Gareth Fenn9a808452022-03-31 08:40:00 +0100812 bool feIsValid = live.hasFrontendConnection
813 ? frontendMap.find(live.frontendId) != frontendMap.end()
814 : true;
815 feIsValid &= scan.hasFrontendConnection ? frontendMap.find(scan.frontendId) != frontendMap.end()
816 : true;
817 feIsValid &= record.support && record.hasFrontendConnection
818 ? frontendMap.find(record.frontendId) != frontendMap.end()
819 : true;
Frankie Lizcanof5352122022-06-29 22:10:16 +0000820 feIsValid &= descrambling.support && descrambling.hasFrontendConnection
821 ? frontendMap.find(descrambling.frontendId) != frontendMap.end()
822 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700823
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000824 feIsValid &= lnbLive.support ? frontendMap.find(lnbLive.frontendId) != frontendMap.end() : true;
825
826 feIsValid &=
827 lnbRecord.support ? frontendMap.find(lnbRecord.frontendId) != frontendMap.end() : true;
828
Frankie Lizcano523e5452022-07-27 22:21:16 +0000829 feIsValid &= lnbDescrambling.support
830 ? frontendMap.find(lnbDescrambling.frontendId) != frontendMap.end()
831 : true;
832
Hongguang600a6ae2021-07-08 18:51:51 -0700833 if (!feIsValid) {
834 ALOGW("[vts config] dynamic config fe connection is invalid.");
835 return false;
836 }
837
838 bool dvrIsValid = frontendMap[live.frontendId].isSoftwareFe
839 ? dvrMap.find(live.dvrSoftwareFeId) != dvrMap.end()
840 : true;
841
842 if (record.support) {
843 if (record.hasFrontendConnection) {
844 if (frontendMap[record.frontendId].isSoftwareFe) {
845 dvrIsValid &= dvrMap.find(record.dvrSoftwareFeId) != dvrMap.end();
846 }
847 } else {
848 dvrIsValid &= dvrMap.find(record.dvrSourceId) != dvrMap.end();
849 }
850 dvrIsValid &= dvrMap.find(record.dvrRecordId) != dvrMap.end();
851 }
852
Frankie Lizcanof5352122022-06-29 22:10:16 +0000853 if (descrambling.support) {
854 if (descrambling.hasFrontendConnection) {
855 if (frontendMap[descrambling.frontendId].isSoftwareFe) {
856 dvrIsValid &= dvrMap.find(descrambling.dvrSoftwareFeId) != dvrMap.end();
857 }
858 } else {
859 dvrIsValid &= dvrMap.find(descrambling.dvrSourceId) != dvrMap.end();
860 }
861 }
862
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000863 dvrIsValid &= lnbRecord.support ? dvrMap.find(lnbRecord.dvrRecordId) != dvrMap.end() : true;
864
Frankie Lizcano50461932022-06-28 21:36:26 +0000865 dvrIsValid &= playback.support ? dvrMap.find(playback.dvrId) != dvrMap.end() : true;
866
Hongguang600a6ae2021-07-08 18:51:51 -0700867 if (!dvrIsValid) {
868 ALOGW("[vts config] dynamic config dvr connection is invalid.");
869 return false;
870 }
871
Gareth Fenn9a808452022-03-31 08:40:00 +0100872 bool filterIsValid = (live.hasFrontendConnection)
873 ? filterMap.find(live.audioFilterId) != filterMap.end() &&
874 filterMap.find(live.videoFilterId) != filterMap.end()
875 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700876 filterIsValid &=
877 record.support ? filterMap.find(record.recordFilterId) != filterMap.end() : true;
878
Frankie Lizcanof5352122022-06-29 22:10:16 +0000879 filterIsValid &= descrambling.support
880 ? filterMap.find(descrambling.videoFilterId) != filterMap.end() &&
881 filterMap.find(descrambling.audioFilterId) != filterMap.end()
882 : true;
883
884 for (auto& filterId : descrambling.extraFilters) {
885 filterIsValid &= filterMap.find(filterId) != filterMap.end();
886 }
887
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000888 filterIsValid &= lnbLive.support
889 ? filterMap.find(lnbLive.audioFilterId) != filterMap.end() &&
890 filterMap.find(lnbLive.videoFilterId) != filterMap.end()
891 : true;
892
893 filterIsValid &=
894 lnbRecord.support ? filterMap.find(lnbRecord.recordFilterId) != filterMap.end() : true;
895
896 for (auto& filterId : lnbRecord.extraFilters) {
897 filterIsValid &= filterMap.find(filterId) != filterMap.end();
898 }
899
900 for (auto& filterId : lnbLive.extraFilters) {
901 filterIsValid &= filterMap.find(filterId) != filterMap.end();
902 }
903
Frankie Lizcano50461932022-06-28 21:36:26 +0000904 filterIsValid &= playback.support
905 ? filterMap.find(playback.audioFilterId) != filterMap.end() &&
906 filterMap.find(playback.videoFilterId) != filterMap.end()
907 : true;
908 filterIsValid &= playback.sectionFilterId.compare(emptyHardwareId) == 0
909 ? true
910 : filterMap.find(playback.sectionFilterId) != filterMap.end();
911
912 for (auto& filterId : playback.extraFilters) {
913 filterIsValid &=
914 playback.hasExtraFilters ? filterMap.find(filterId) != filterMap.end() : true;
915 }
916
Frankie Lizcano523e5452022-07-27 22:21:16 +0000917 filterIsValid &=
918 lnbDescrambling.support
919 ? filterMap.find(lnbDescrambling.audioFilterId) != filterMap.end() &&
920 filterMap.find(lnbDescrambling.videoFilterId) != filterMap.end()
921 : true;
922
Hongguang600a6ae2021-07-08 18:51:51 -0700923 if (!filterIsValid) {
924 ALOGW("[vts config] dynamic config filter connection is invalid.");
925 return false;
926 }
927
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000928 if (audioFilterIds.size() != videoFilterIds.size()) {
929 ALOGW("[vts config] the number of audio and video filters should be equal");
930 return false;
931 }
932
Frankie Lizcano8b87f252022-07-19 21:51:54 +0000933 if (!pcrFilterIds.empty() && pcrFilterIds.size() != 1 &&
934 pcrFilterIds.size() != audioFilterIds.size()) {
935 ALOGW("[vts config] When more than 1 pcr filter is configured, the number of pcr filters "
936 "must equal the number of audio and video filters.");
937 return false;
938 }
939
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000940 bool timeFilterIsValid =
941 timeFilter.support ? timeFilterMap.find(timeFilter.timeFilterId) != timeFilterMap.end()
942 : true;
943
944 if (!timeFilterIsValid) {
945 ALOGW("[vts config] dynamic config time filter connection is invalid.");
Frankie Lizcanof5352122022-06-29 22:10:16 +0000946 }
947
948 bool descramblerIsValid =
949 descrambling.support
950 ? descramblerMap.find(descrambling.descramblerId) != descramblerMap.end()
951 : true;
952
Frankie Lizcano523e5452022-07-27 22:21:16 +0000953 descramblerIsValid &=
954 lnbDescrambling.support
955 ? descramblerMap.find(lnbDescrambling.descramblerId) != descramblerMap.end()
956 : true;
957
Frankie Lizcanof5352122022-06-29 22:10:16 +0000958 if (!descramblerIsValid) {
959 ALOGW("[vts config] dynamic config descrambler connection is invalid.");
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000960 return false;
961 }
962
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000963 bool lnbIsValid = lnbLive.support ? lnbMap.find(lnbLive.lnbId) != lnbMap.end() : true;
964
965 lnbIsValid &= lnbRecord.support ? lnbMap.find(lnbRecord.lnbId) != lnbMap.end() : true;
966
Frankie Lizcano523e5452022-07-27 22:21:16 +0000967 lnbIsValid &=
968 lnbDescrambling.support ? lnbMap.find(lnbDescrambling.lnbId) != lnbMap.end() : true;
969
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000970 if (!lnbIsValid) {
971 ALOGW("[vts config] dynamic config lnb connection is invalid.");
972 return false;
973 }
974
975 bool diseqcMsgsIsValid = true;
976
977 for (auto& msg : lnbRecord.diseqcMsgs) {
978 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
979 }
980
981 for (auto& msg : lnbLive.diseqcMsgs) {
982 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
983 }
984
Frankie Lizcano523e5452022-07-27 22:21:16 +0000985 for (auto& msg : lnbDescrambling.diseqcMsgs) {
986 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
987 }
988
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000989 if (!diseqcMsgsIsValid) {
990 ALOGW("[vts config] dynamic config diseqcMsg is invalid.");
991 return false;
992 }
993
Hongguang600a6ae2021-07-08 18:51:51 -0700994 return true;
995}