blob: de12dc0efa14e54d58c0940a8d926bd8468760a8 [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
Frankie Lizcanoa53f5542022-07-07 17:32:06 +000078/*
79 * This function takes in a 2d vector of device Id's
80 * The n vectors correlate to the ids for n different devices (eg frontends, filters)
81 * The resultant 2d vector is every combination of id's with 1 id from each vector
82 */
83inline vector<vector<string>> generateIdCombinations(vector<vector<string>>& ids) {
84 vector<vector<string>> combinations;
85
86 // The index of each vector in ids that will be used in the next combination
87 // EG {0, 2} means combo {ids[0][0] ids[1][2]} will be next
88 const int size = static_cast<int>(ids.size());
89 vector<int> indexes_used_in_combination(size, 0);
90
91 // The vector number from ids whose elements we will cycle through to make combinations.
92 // First, start at the right most vector
93 int cycled_vector = size - 1;
94
95 while (cycled_vector >= 0) {
96 // Make a combination (one at a time)
97 vector<string> combo;
98 for (size_t i = 0; i < indexes_used_in_combination.size(); ++i) {
99 const int combo_index = indexes_used_in_combination[i];
100 combo.push_back(ids[i][combo_index]);
101 }
102 combinations.push_back(combo);
103
104 // Find the right most vector that still has space [elements left] to cycle through and
105 // create a combination
106 while (cycled_vector >= 0 &&
107 indexes_used_in_combination[cycled_vector] == ids[cycled_vector].size() - 1) {
108 cycled_vector--;
109 }
110
111 // Use this check to avoid segmentation faults
112 if (cycled_vector >= 0) {
113 // Once found, we have a vector we can cycle through, so increase to its next element
114 indexes_used_in_combination[cycled_vector]++;
115
116 // Reset the other vectors to the right to their first element so we can cycle through
117 // them again with the new element from cycled vector
118 for (size_t i = cycled_vector + 1; i < indexes_used_in_combination.size(); ++i) {
119 indexes_used_in_combination[i] = 0;
120 }
121
122 // all the vectors to the right were reset, so we can cycle through them again
123 // Start at the furthest right vector
124 cycled_vector = size - 1;
125 }
126 }
127
128 return combinations;
129}
130
131/*
132 * index 0 - playback dvr
133 * index 1 - audio filters
134 * index 2 - video filters
135 * index 3 - optional section filters
136 */
137static inline vector<DvrPlaybackHardwareConnections> generatePlaybackCombinations() {
138 vector<DvrPlaybackHardwareConnections> combinations;
139 vector<string> sectionFilterIds_optional = sectionFilterIds;
140 sectionFilterIds_optional.push_back(emptyHardwareId);
141 vector<vector<string>> deviceIds{playbackDvrIds, audioFilterIds, videoFilterIds,
142 sectionFilterIds_optional};
143
144 const int dvrIndex = 0;
145 const int audioFilterIndex = 1;
146 const int videoFilterIndex = 2;
147 const int sectionFilterIndex = 3;
148
149 auto idCombinations = generateIdCombinations(deviceIds);
150 for (auto& combo : idCombinations) {
151 DvrPlaybackHardwareConnections mPlayback;
152 mPlayback.dvrId = combo[dvrIndex];
153 mPlayback.audioFilterId = combo[audioFilterIndex];
154 mPlayback.videoFilterId = combo[videoFilterIndex];
155 mPlayback.sectionFilterId = combo[sectionFilterIndex];
156 combinations.push_back(mPlayback);
157 }
158
159 return combinations;
160}
161
162static inline vector<DvrPlaybackHardwareConnections> generatePlaybackConfigs() {
163 vector<DvrPlaybackHardwareConnections> playback_configs;
164 if (configuredPlayback) {
165 ALOGD("Using DVR playback configuration provided.");
166 playback_configs = {playback};
167 } else {
168 ALOGD("Dvr playback not provided. Generating possible combinations. Consider adding it to "
169 "the configuration file.");
170 playback_configs = generatePlaybackCombinations();
171 }
172
173 return playback_configs;
174}
175
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000176/*
177 * index 0 - frontends
178 * index 1 - audio filters
179 * index 2 - video filters
180 * index 3 - lnbs
181 */
182static inline vector<LnbLiveHardwareConnections> generateLnbLiveCombinations() {
183 vector<LnbLiveHardwareConnections> combinations;
184 vector<vector<string>> deviceIds{frontendIds, audioFilterIds, videoFilterIds, lnbIds};
185
186 const int frontendIndex = 0;
187 const int audioFilterIndex = 1;
188 const int videoFilterIndex = 2;
189 const int lnbIndex = 3;
190
191 // TODO: Find a better way to vary diseqcMsgs, if at all
192 auto idCombinations = generateIdCombinations(deviceIds);
193 for (auto& combo : idCombinations) {
194 const string feId = combo[frontendIndex];
195 auto type = frontendMap[feId].type;
196 if (type == FrontendType::DVBS || type == FrontendType::ISDBS ||
197 type == FrontendType::ISDBS3) {
198 LnbLiveHardwareConnections mLnbLive;
199 mLnbLive.frontendId = feId;
200 mLnbLive.audioFilterId = combo[audioFilterIndex];
201 mLnbLive.videoFilterId = combo[videoFilterIndex];
202 mLnbLive.lnbId = combo[lnbIndex];
203 mLnbLive.diseqcMsgs = diseqcMsgs;
204 combinations.push_back(mLnbLive);
205 }
206 }
207
208 return combinations;
209}
210
211static inline vector<LnbLiveHardwareConnections> generateLnbLiveConfigurations() {
212 vector<LnbLiveHardwareConnections> lnbLive_configs;
213 if (configuredLnbLive) {
214 ALOGD("Using LnbLive configuration provided.");
215 lnbLive_configs = {lnbLive};
216 } else {
217 ALOGD("LnbLive not provided. Generating possible combinations. Consider adding it to the "
218 "configuration file.");
219 lnbLive_configs = generateLnbLiveCombinations();
220 }
221
222 return lnbLive_configs;
223}
224
Frankie Lizcano3138d6b2022-07-11 22:06:45 +0000225static inline vector<ScanHardwareConnections> generateScanCombinations() {
226 vector<ScanHardwareConnections> combinations;
227
228 for (auto& id : frontendIds) {
229 ScanHardwareConnections mScan;
230 mScan.frontendId = id;
231 combinations.push_back(mScan);
232 }
233
234 return combinations;
235}
236
237static inline vector<ScanHardwareConnections> generateScanConfigurations() {
238 vector<ScanHardwareConnections> scan_configs;
239 if (configuredScan) {
240 ALOGD("Using scan configuration provided.");
241 scan_configs = {scan};
242 } else {
243 ALOGD("Scan not provided. Generating possible combinations. Consider adding it to "
244 "the configuration file.");
245 scan_configs = generateScanCombinations();
246 }
247
248 return scan_configs;
249}
250
Frankie Lizcanoecba02a2022-07-12 17:56:54 +0000251/*
252 * index 0 - frontends
253 * index 1 - record filter
254 * index 2 - Record Dvr
255 * index 3 - Lnb
256 */
257static inline vector<LnbRecordHardwareConnections> generateLnbRecordCombinations() {
258 vector<LnbRecordHardwareConnections> combinations;
259 vector<vector<string>> deviceIds{frontendIds, recordFilterIds, recordDvrIds, lnbIds};
260
261 const int frontendIndex = 0;
262 const int recordFilterIndex = 1;
263 const int dvrIndex = 2;
264 const int lnbIndex = 3;
265
266 auto idCombinations = generateIdCombinations(deviceIds);
267 // TODO : Find a better way to vary diseqcMsgs, if at all
268 for (auto& combo : idCombinations) {
269 const string feId = combo[frontendIndex];
270 auto type = frontendMap[feId].type;
271 if (type == FrontendType::DVBS || type == FrontendType::ISDBS ||
272 type == FrontendType::ISDBS3) {
273 LnbRecordHardwareConnections mLnbRecord;
274 mLnbRecord.frontendId = feId;
275 mLnbRecord.recordFilterId = combo[recordFilterIndex];
276 mLnbRecord.dvrRecordId = combo[dvrIndex];
277 mLnbRecord.lnbId = combo[lnbIndex];
278 mLnbRecord.diseqcMsgs = diseqcMsgs;
279 combinations.push_back(mLnbRecord);
280 }
281 }
282
283 return combinations;
284}
285
286static inline vector<LnbRecordHardwareConnections> generateLnbRecordConfigurations() {
287 vector<LnbRecordHardwareConnections> lnbRecord_configs;
288 if (configuredLnbRecord) {
289 ALOGD("Using LnbRecord configuration provided.");
290 lnbRecord_configs = {lnbRecord};
291 } else {
292 ALOGD("LnbRecord not provided. Generating possible combinations. Consider adding it to "
293 "the configuration file.");
294 lnbRecord_configs = generateLnbRecordCombinations();
295 }
296
297 return lnbRecord_configs;
298}
299
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000300/*
301 * index 0 - decramblers
302 * index 1 - frontends
303 * index 2 - audio filters
304 * index 3 - video filters
305 * index 4 - Dvr SW Fe Connections
306 * index 5 - DVR Source Connections
307 */
308static inline vector<DescramblingHardwareConnections> generateDescramblingCombinations() {
309 vector<DescramblingHardwareConnections> combinations;
310 vector<string> mfrontendIds = frontendIds;
311 vector<string> mDvrFeConnectionIds = playbackDvrIds;
312 vector<string> mDvrSourceConnectionIds = playbackDvrIds;
313
314 // Add the empty hardware id to each vector to include combinations where these 3 fields might
315 // be optional
316 mfrontendIds.push_back(emptyHardwareId);
317 mDvrFeConnectionIds.push_back(emptyHardwareId);
318 mDvrSourceConnectionIds.push_back(emptyHardwareId);
319
320 const int descramblerIndex = 0;
321 const int frontendIndex = 1;
322 const int audioFilterIndex = 2;
323 const int videoFilterIndex = 3;
324 const int dvrFeIdIndex = 4;
325 const int dvrSourceIdIndex = 5;
326
327 vector<vector<string>> deviceIds{descramblerIds, mfrontendIds, audioFilterIds,
328 videoFilterIds, mDvrFeConnectionIds, mDvrSourceConnectionIds};
329 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];
356 mDescrambling.videoFilterId = combo[videoFilterIndex];
357 mDescrambling.dvrSoftwareFeId = dvrSwFeId;
358 mDescrambling.dvrSourceId = dvrSourceId;
359 mDescrambling.descramblerId = combo[descramblerIndex];
360 combinations.push_back(mDescrambling);
361 }
362
363 return combinations;
364}
365
366static inline vector<DescramblingHardwareConnections> generateDescramblingConfigurations() {
367 vector<DescramblingHardwareConnections> descrambling_configs;
368 if (configuredDescrambling) {
369 ALOGD("Using Descrambling configuration provided.");
370 descrambling_configs = {descrambling};
371 } else {
372 ALOGD("Descrambling not provided. Generating possible combinations. Consider adding it to "
373 "the "
374 "configuration file.");
375 descrambling_configs = generateDescramblingCombinations();
376 }
377
378 return descrambling_configs;
379}
380
Hongguang600a6ae2021-07-08 18:51:51 -0700381/** Config all the frontends that would be used in the tests */
382inline void initFrontendConfig() {
383 // The test will use the internal default fe when default fe is connected to any data flow
384 // without overriding in the xml config.
385 string defaultFeId = "FE_DEFAULT";
386 FrontendDvbtSettings dvbtSettings{
Gareth Fenn282fb372021-09-27 15:14:11 +0100387 .frequency = 578000000,
Hongguang600a6ae2021-07-08 18:51:51 -0700388 .transmissionMode = FrontendDvbtTransmissionMode::AUTO,
389 .bandwidth = FrontendDvbtBandwidth::BANDWIDTH_8MHZ,
390 .isHighPriority = true,
391 };
392 frontendMap[defaultFeId].type = FrontendType::DVBT;
393 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbtSettings);
394
395 vector<FrontendStatusType> types;
396 types.push_back(FrontendStatusType::UEC);
397 types.push_back(FrontendStatusType::IS_MISO);
398
399 vector<FrontendStatus> statuses;
400 FrontendStatus status;
401 status.set<FrontendStatus::Tag::uec>(4);
402 statuses.push_back(status);
403 status.set<FrontendStatus::Tag::isMiso>(true);
404 statuses.push_back(status);
405
406 frontendMap[defaultFeId].tuneStatusTypes = types;
407 frontendMap[defaultFeId].expectTuneStatuses = statuses;
408 frontendMap[defaultFeId].isSoftwareFe = true;
409 frontendMap[defaultFeId].canConnectToCiCam = true;
410 frontendMap[defaultFeId].ciCamId = 0;
411 FrontendDvbtSettings dvbt;
412 dvbt.transmissionMode = FrontendDvbtTransmissionMode::MODE_8K_E;
413 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbt);
414 // Read customized config
415 TunerTestingConfigAidlReader1_0::readFrontendConfig1_0(frontendMap);
416};
417
418inline void initFilterConfig() {
419 // The test will use the internal default filter when default filter is connected to any
420 // data flow without overriding in the xml config.
421 string defaultAudioFilterId = "FILTER_AUDIO_DEFAULT";
422 string defaultVideoFilterId = "FILTER_VIDEO_DEFAULT";
423
424 filterMap[defaultVideoFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700425 filterMap[defaultVideoFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
426 DemuxTsFilterType::VIDEO);
Hongguang600a6ae2021-07-08 18:51:51 -0700427 filterMap[defaultVideoFilterId].bufferSize = FMQ_SIZE_16M;
428 filterMap[defaultVideoFilterId].settings =
429 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
430 filterMap[defaultVideoFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
431 DemuxFilterAvSettings video;
432 video.isPassthrough = false;
433 filterMap[defaultVideoFilterId]
434 .settings.get<DemuxFilterSettings::Tag::ts>()
435 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(video);
436 filterMap[defaultVideoFilterId].monitorEventTypes =
437 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
438 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
439 filterMap[defaultVideoFilterId].streamType.set<AvStreamType::Tag::video>(
440 VideoStreamType::MPEG1);
441
442 filterMap[defaultAudioFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700443 filterMap[defaultAudioFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
444 DemuxTsFilterType::AUDIO);
Hongguang600a6ae2021-07-08 18:51:51 -0700445 filterMap[defaultAudioFilterId].bufferSize = FMQ_SIZE_16M;
446 filterMap[defaultAudioFilterId].settings =
447 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
448 filterMap[defaultAudioFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
449 DemuxFilterAvSettings audio;
450 audio.isPassthrough = false;
451 filterMap[defaultAudioFilterId]
452 .settings.get<DemuxFilterSettings::Tag::ts>()
453 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(audio);
454 filterMap[defaultAudioFilterId].monitorEventTypes =
455 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
456 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
457 filterMap[defaultAudioFilterId].streamType.set<AvStreamType::Tag::audio>(AudioStreamType::MP3);
458 // Read customized config
459 TunerTestingConfigAidlReader1_0::readFilterConfig1_0(filterMap);
460};
461
462/** Config all the dvrs that would be used in the tests */
463inline void initDvrConfig() {
464 // Read customized config
465 TunerTestingConfigAidlReader1_0::readDvrConfig1_0(dvrMap);
466};
467
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000468inline void initTimeFilterConfig() {
469 // Read customized config
470 TunerTestingConfigAidlReader1_0::readTimeFilterConfig1_0(timeFilterMap);
471};
472
Frankie Lizcanof5352122022-06-29 22:10:16 +0000473inline void initDescramblerConfig() {
474 // Read customized config
475 TunerTestingConfigAidlReader1_0::readDescramblerConfig1_0(descramblerMap);
476}
477
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000478inline void initLnbConfig() {
479 // Read customized config
480 TunerTestingConfigAidlReader1_0::readLnbConfig1_0(lnbMap);
481};
482
483inline void initDiseqcMsgsConfig() {
484 // Read customized config
485 TunerTestingConfigAidlReader1_0::readDiseqcMessages(diseqcMsgMap);
486};
487
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000488inline void determineScan() {
489 if (!frontendMap.empty()) {
490 scan.hasFrontendConnection = true;
491 ALOGD("Can support scan");
492 }
493}
494
495inline void determineTimeFilter() {
496 if (!timeFilterMap.empty()) {
497 timeFilter.support = true;
498 ALOGD("Can support time filter");
499 }
500}
501
502inline void determineDvrPlayback() {
503 if (!playbackDvrIds.empty() && !audioFilterIds.empty() && !videoFilterIds.empty()) {
504 playback.support = true;
505 ALOGD("Can support dvr playback");
506 }
507}
508
509inline void determineLnbLive() {
510 if (!audioFilterIds.empty() && !videoFilterIds.empty() && !frontendMap.empty() &&
511 !lnbMap.empty()) {
512 lnbLive.support = true;
513 ALOGD("Can support lnb live");
514 }
515}
516
517inline void determineLnbRecord() {
518 if (!frontendMap.empty() && !recordFilterIds.empty() && !recordDvrIds.empty() &&
519 !lnbMap.empty()) {
520 lnbRecord.support = true;
521 ALOGD("Can support lnb record");
522 }
523}
524
525inline void determineLive() {
526 if (videoFilterIds.empty() || audioFilterIds.empty() || frontendMap.empty()) {
527 return;
528 }
529 if (hasSwFe && !hasHwFe && dvrMap.empty()) {
530 ALOGD("Cannot configure Live. Only software frontends and no dvr connections");
531 return;
532 }
533 ALOGD("Can support live");
534 live.hasFrontendConnection = true;
535}
536
537inline void determineDescrambling() {
538 if (descramblerMap.empty() || audioFilterIds.empty() || videoFilterIds.empty()) {
539 return;
540 }
541 if (frontendMap.empty() && playbackDvrIds.empty()) {
542 ALOGD("Cannot configure descrambling. No frontends or playback dvr's");
543 return;
544 }
545 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
546 ALOGD("cannot configure descrambling. Only SW frontends and no playback dvr's");
547 return;
548 }
549 ALOGD("Can support descrambling");
550 descrambling.support = true;
551}
552
553inline void determineDvrRecord() {
554 if (recordDvrIds.empty() || recordFilterIds.empty()) {
555 return;
556 }
557 if (frontendMap.empty() && playbackDvrIds.empty()) {
Frankie Lizcanoecba02a2022-07-12 17:56:54 +0000558 ALOGD("Cannot support dvr record. No frontends and no playback dvr's");
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000559 return;
560 }
561 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
562 ALOGD("Cannot support dvr record. Only SW frontends and no playback dvr's");
563 return;
564 }
565 ALOGD("Can support dvr record.");
566 record.support = true;
567}
568
Hongguang600a6ae2021-07-08 18:51:51 -0700569/** Read the vendor configurations of which hardware to use for each test cases/data flows */
570inline void connectHardwaresToTestCases() {
571 TunerTestingConfigAidlReader1_0::connectLiveBroadcast(live);
572 TunerTestingConfigAidlReader1_0::connectScan(scan);
573 TunerTestingConfigAidlReader1_0::connectDvrRecord(record);
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000574 TunerTestingConfigAidlReader1_0::connectTimeFilter(timeFilter);
Frankie Lizcanof5352122022-06-29 22:10:16 +0000575 TunerTestingConfigAidlReader1_0::connectDescrambling(descrambling);
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000576 TunerTestingConfigAidlReader1_0::connectLnbLive(lnbLive);
Frankie Lizcano3138d6b2022-07-11 22:06:45 +0000577 TunerTestingConfigAidlReader1_0::connectLnbRecord(lnbRecord);
Frankie Lizcano50461932022-06-28 21:36:26 +0000578 TunerTestingConfigAidlReader1_0::connectDvrPlayback(playback);
Hongguang600a6ae2021-07-08 18:51:51 -0700579};
580
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000581inline void determineDataFlows() {
582 determineScan();
583 determineTimeFilter();
584 determineDvrPlayback();
585 determineLnbLive();
586 determineLnbRecord();
587 determineLive();
588 determineDescrambling();
589 determineDvrRecord();
590}
591
Hongguang600a6ae2021-07-08 18:51:51 -0700592inline bool validateConnections() {
593 if (record.support && !record.hasFrontendConnection &&
594 record.dvrSourceId.compare(emptyHardwareId) == 0) {
595 ALOGW("[vts config] Record must support either a DVR source or a Frontend source.");
596 return false;
597 }
Gareth Fenn9a808452022-03-31 08:40:00 +0100598 bool feIsValid = live.hasFrontendConnection
599 ? frontendMap.find(live.frontendId) != frontendMap.end()
600 : true;
601 feIsValid &= scan.hasFrontendConnection ? frontendMap.find(scan.frontendId) != frontendMap.end()
602 : true;
603 feIsValid &= record.support && record.hasFrontendConnection
604 ? frontendMap.find(record.frontendId) != frontendMap.end()
605 : true;
Frankie Lizcanof5352122022-06-29 22:10:16 +0000606 feIsValid &= descrambling.support && descrambling.hasFrontendConnection
607 ? frontendMap.find(descrambling.frontendId) != frontendMap.end()
608 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700609
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000610 feIsValid &= lnbLive.support ? frontendMap.find(lnbLive.frontendId) != frontendMap.end() : true;
611
612 feIsValid &=
613 lnbRecord.support ? frontendMap.find(lnbRecord.frontendId) != frontendMap.end() : true;
614
Hongguang600a6ae2021-07-08 18:51:51 -0700615 if (!feIsValid) {
616 ALOGW("[vts config] dynamic config fe connection is invalid.");
617 return false;
618 }
619
620 bool dvrIsValid = frontendMap[live.frontendId].isSoftwareFe
621 ? dvrMap.find(live.dvrSoftwareFeId) != dvrMap.end()
622 : true;
623
624 if (record.support) {
625 if (record.hasFrontendConnection) {
626 if (frontendMap[record.frontendId].isSoftwareFe) {
627 dvrIsValid &= dvrMap.find(record.dvrSoftwareFeId) != dvrMap.end();
628 }
629 } else {
630 dvrIsValid &= dvrMap.find(record.dvrSourceId) != dvrMap.end();
631 }
632 dvrIsValid &= dvrMap.find(record.dvrRecordId) != dvrMap.end();
633 }
634
Frankie Lizcanof5352122022-06-29 22:10:16 +0000635 if (descrambling.support) {
636 if (descrambling.hasFrontendConnection) {
637 if (frontendMap[descrambling.frontendId].isSoftwareFe) {
638 dvrIsValid &= dvrMap.find(descrambling.dvrSoftwareFeId) != dvrMap.end();
639 }
640 } else {
641 dvrIsValid &= dvrMap.find(descrambling.dvrSourceId) != dvrMap.end();
642 }
643 }
644
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000645 dvrIsValid &= lnbRecord.support ? dvrMap.find(lnbRecord.dvrRecordId) != dvrMap.end() : true;
646
Frankie Lizcano50461932022-06-28 21:36:26 +0000647 dvrIsValid &= playback.support ? dvrMap.find(playback.dvrId) != dvrMap.end() : true;
648
Hongguang600a6ae2021-07-08 18:51:51 -0700649 if (!dvrIsValid) {
650 ALOGW("[vts config] dynamic config dvr connection is invalid.");
651 return false;
652 }
653
Gareth Fenn9a808452022-03-31 08:40:00 +0100654 bool filterIsValid = (live.hasFrontendConnection)
655 ? filterMap.find(live.audioFilterId) != filterMap.end() &&
656 filterMap.find(live.videoFilterId) != filterMap.end()
657 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700658 filterIsValid &=
659 record.support ? filterMap.find(record.recordFilterId) != filterMap.end() : true;
660
Frankie Lizcanof5352122022-06-29 22:10:16 +0000661 filterIsValid &= descrambling.support
662 ? filterMap.find(descrambling.videoFilterId) != filterMap.end() &&
663 filterMap.find(descrambling.audioFilterId) != filterMap.end()
664 : true;
665
666 for (auto& filterId : descrambling.extraFilters) {
667 filterIsValid &= filterMap.find(filterId) != filterMap.end();
668 }
669
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000670 filterIsValid &= lnbLive.support
671 ? filterMap.find(lnbLive.audioFilterId) != filterMap.end() &&
672 filterMap.find(lnbLive.videoFilterId) != filterMap.end()
673 : true;
674
675 filterIsValid &=
676 lnbRecord.support ? filterMap.find(lnbRecord.recordFilterId) != filterMap.end() : true;
677
678 for (auto& filterId : lnbRecord.extraFilters) {
679 filterIsValid &= filterMap.find(filterId) != filterMap.end();
680 }
681
682 for (auto& filterId : lnbLive.extraFilters) {
683 filterIsValid &= filterMap.find(filterId) != filterMap.end();
684 }
685
Frankie Lizcano50461932022-06-28 21:36:26 +0000686 filterIsValid &= playback.support
687 ? filterMap.find(playback.audioFilterId) != filterMap.end() &&
688 filterMap.find(playback.videoFilterId) != filterMap.end()
689 : true;
690 filterIsValid &= playback.sectionFilterId.compare(emptyHardwareId) == 0
691 ? true
692 : filterMap.find(playback.sectionFilterId) != filterMap.end();
693
694 for (auto& filterId : playback.extraFilters) {
695 filterIsValid &=
696 playback.hasExtraFilters ? filterMap.find(filterId) != filterMap.end() : true;
697 }
698
Hongguang600a6ae2021-07-08 18:51:51 -0700699 if (!filterIsValid) {
700 ALOGW("[vts config] dynamic config filter connection is invalid.");
701 return false;
702 }
703
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000704 bool timeFilterIsValid =
705 timeFilter.support ? timeFilterMap.find(timeFilter.timeFilterId) != timeFilterMap.end()
706 : true;
707
708 if (!timeFilterIsValid) {
709 ALOGW("[vts config] dynamic config time filter connection is invalid.");
Frankie Lizcanof5352122022-06-29 22:10:16 +0000710 }
711
712 bool descramblerIsValid =
713 descrambling.support
714 ? descramblerMap.find(descrambling.descramblerId) != descramblerMap.end()
715 : true;
716
717 if (!descramblerIsValid) {
718 ALOGW("[vts config] dynamic config descrambler connection is invalid.");
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000719 return false;
720 }
721
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000722 bool lnbIsValid = lnbLive.support ? lnbMap.find(lnbLive.lnbId) != lnbMap.end() : true;
723
724 lnbIsValid &= lnbRecord.support ? lnbMap.find(lnbRecord.lnbId) != lnbMap.end() : true;
725
726 if (!lnbIsValid) {
727 ALOGW("[vts config] dynamic config lnb connection is invalid.");
728 return false;
729 }
730
731 bool diseqcMsgsIsValid = true;
732
733 for (auto& msg : lnbRecord.diseqcMsgs) {
734 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
735 }
736
737 for (auto& msg : lnbLive.diseqcMsgs) {
738 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
739 }
740
741 if (!diseqcMsgsIsValid) {
742 ALOGW("[vts config] dynamic config diseqcMsg is invalid.");
743 return false;
744 }
745
Hongguang600a6ae2021-07-08 18:51:51 -0700746 return true;
747}