blob: ddc36a8c4005a5eb36cdcaf99e8432ff50b515a9 [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
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000134 * index 2 - optional section filters
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000135 */
136static inline vector<DvrPlaybackHardwareConnections> generatePlaybackCombinations() {
137 vector<DvrPlaybackHardwareConnections> combinations;
138 vector<string> sectionFilterIds_optional = sectionFilterIds;
139 sectionFilterIds_optional.push_back(emptyHardwareId);
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000140 vector<vector<string>> deviceIds{playbackDvrIds, audioFilterIds, sectionFilterIds_optional};
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000141
142 const int dvrIndex = 0;
143 const int audioFilterIndex = 1;
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000144 const int sectionFilterIndex = 2;
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000145
146 auto idCombinations = generateIdCombinations(deviceIds);
147 for (auto& combo : idCombinations) {
148 DvrPlaybackHardwareConnections mPlayback;
149 mPlayback.dvrId = combo[dvrIndex];
150 mPlayback.audioFilterId = combo[audioFilterIndex];
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000151 mPlayback.sectionFilterId = combo[sectionFilterIndex];
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000152 const int videoFilterIndex =
153 find(audioFilterIds.begin(), audioFilterIds.end(), mPlayback.audioFilterId) -
154 audioFilterIds.begin();
155 mPlayback.videoFilterId = videoFilterIds[videoFilterIndex];
Frankie Lizcanoa53f5542022-07-07 17:32:06 +0000156 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
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000179 * index 2 - lnbs
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000180 */
181static inline vector<LnbLiveHardwareConnections> generateLnbLiveCombinations() {
182 vector<LnbLiveHardwareConnections> combinations;
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000183 vector<vector<string>> deviceIds{frontendIds, audioFilterIds, lnbIds};
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000184
185 const int frontendIndex = 0;
186 const int audioFilterIndex = 1;
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000187 const int lnbIndex = 2;
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000188
189 // TODO: Find a better way to vary diseqcMsgs, if at all
190 auto idCombinations = generateIdCombinations(deviceIds);
191 for (auto& combo : idCombinations) {
192 const string feId = combo[frontendIndex];
193 auto type = frontendMap[feId].type;
194 if (type == FrontendType::DVBS || type == FrontendType::ISDBS ||
195 type == FrontendType::ISDBS3) {
196 LnbLiveHardwareConnections mLnbLive;
197 mLnbLive.frontendId = feId;
198 mLnbLive.audioFilterId = combo[audioFilterIndex];
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000199 const int videoFilterIndex =
200 find(audioFilterIds.begin(), audioFilterIds.end(), mLnbLive.audioFilterId) -
201 audioFilterIds.begin();
202 mLnbLive.videoFilterId = videoFilterIds[videoFilterIndex];
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000203 mLnbLive.lnbId = combo[lnbIndex];
204 mLnbLive.diseqcMsgs = diseqcMsgs;
205 combinations.push_back(mLnbLive);
206 }
207 }
208
209 return combinations;
210}
211
212static inline vector<LnbLiveHardwareConnections> generateLnbLiveConfigurations() {
213 vector<LnbLiveHardwareConnections> lnbLive_configs;
214 if (configuredLnbLive) {
215 ALOGD("Using LnbLive configuration provided.");
216 lnbLive_configs = {lnbLive};
217 } else {
218 ALOGD("LnbLive not provided. Generating possible combinations. Consider adding it to the "
219 "configuration file.");
220 lnbLive_configs = generateLnbLiveCombinations();
221 }
222
223 return lnbLive_configs;
224}
225
Frankie Lizcano3138d6b2022-07-11 22:06:45 +0000226static inline vector<ScanHardwareConnections> generateScanCombinations() {
227 vector<ScanHardwareConnections> combinations;
228
229 for (auto& id : frontendIds) {
230 ScanHardwareConnections mScan;
231 mScan.frontendId = id;
232 combinations.push_back(mScan);
233 }
234
235 return combinations;
236}
237
238static inline vector<ScanHardwareConnections> generateScanConfigurations() {
239 vector<ScanHardwareConnections> scan_configs;
240 if (configuredScan) {
241 ALOGD("Using scan configuration provided.");
242 scan_configs = {scan};
243 } else {
244 ALOGD("Scan not provided. Generating possible combinations. Consider adding it to "
245 "the configuration file.");
246 scan_configs = generateScanCombinations();
247 }
248
249 return scan_configs;
250}
251
Frankie Lizcanoecba02a2022-07-12 17:56:54 +0000252/*
253 * index 0 - frontends
254 * index 1 - record filter
255 * index 2 - Record Dvr
256 * index 3 - Lnb
257 */
258static inline vector<LnbRecordHardwareConnections> generateLnbRecordCombinations() {
259 vector<LnbRecordHardwareConnections> combinations;
260 vector<vector<string>> deviceIds{frontendIds, recordFilterIds, recordDvrIds, lnbIds};
261
262 const int frontendIndex = 0;
263 const int recordFilterIndex = 1;
264 const int dvrIndex = 2;
265 const int lnbIndex = 3;
266
267 auto idCombinations = generateIdCombinations(deviceIds);
268 // TODO : Find a better way to vary diseqcMsgs, if at all
269 for (auto& combo : idCombinations) {
270 const string feId = combo[frontendIndex];
271 auto type = frontendMap[feId].type;
272 if (type == FrontendType::DVBS || type == FrontendType::ISDBS ||
273 type == FrontendType::ISDBS3) {
274 LnbRecordHardwareConnections mLnbRecord;
275 mLnbRecord.frontendId = feId;
276 mLnbRecord.recordFilterId = combo[recordFilterIndex];
277 mLnbRecord.dvrRecordId = combo[dvrIndex];
278 mLnbRecord.lnbId = combo[lnbIndex];
279 mLnbRecord.diseqcMsgs = diseqcMsgs;
280 combinations.push_back(mLnbRecord);
281 }
282 }
283
284 return combinations;
285}
286
287static inline vector<LnbRecordHardwareConnections> generateLnbRecordConfigurations() {
288 vector<LnbRecordHardwareConnections> lnbRecord_configs;
289 if (configuredLnbRecord) {
290 ALOGD("Using LnbRecord configuration provided.");
291 lnbRecord_configs = {lnbRecord};
292 } else {
293 ALOGD("LnbRecord not provided. Generating possible combinations. Consider adding it to "
294 "the configuration file.");
295 lnbRecord_configs = generateLnbRecordCombinations();
296 }
297
298 return lnbRecord_configs;
299}
300
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000301/*
302 * index 0 - decramblers
303 * index 1 - frontends
304 * index 2 - audio filters
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000305 * index 3 - Dvr SW Fe Connections
306 * index 4 - DVR Source Connections
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000307 */
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;
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000323 const int dvrFeIdIndex = 3;
324 const int dvrSourceIdIndex = 4;
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000325
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000326 vector<vector<string>> deviceIds{descramblerIds, mfrontendIds, audioFilterIds,
327 mDvrFeConnectionIds, mDvrSourceConnectionIds};
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000328 auto idCombinations = generateIdCombinations(deviceIds);
329 for (auto& combo : idCombinations) {
330 DescramblingHardwareConnections mDescrambling;
331 const string feId = combo[frontendIndex];
332 const string dvrSwFeId = combo[dvrFeIdIndex];
333 const string dvrSourceId = combo[dvrSourceIdIndex];
334 mDescrambling.hasFrontendConnection = feId.compare(emptyHardwareId) == 0 ? false : true;
335 if (!mDescrambling.hasFrontendConnection) {
336 if (dvrSourceId.compare(emptyHardwareId) == 0) {
337 // If combination does not have a frontend or dvr source connection, do not include
338 // it
339 continue;
340 }
341 } else {
342 if (frontendMap[feId].isSoftwareFe && dvrSwFeId.compare(emptyHardwareId) == 0) {
343 // If combination has a software frontend and no dvr->software frontend connection,
344 // do not include it
345 continue;
346 }
347 }
348 if (dvrSwFeId.compare(dvrSourceId) == 0) {
349 // If dvr->software frontend connection is the same as dvr source input to tuner, do not
350 // include it.
351 continue;
352 }
353 mDescrambling.frontendId = feId;
354 mDescrambling.audioFilterId = combo[audioFilterIndex];
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000355 const int videoFilterIndex =
356 find(audioFilterIds.begin(), audioFilterIds.end(), mDescrambling.audioFilterId) -
357 audioFilterIds.begin();
358 mDescrambling.videoFilterId = videoFilterIds[videoFilterIndex];
Frankie Lizcanof4e07962022-07-13 20:54:34 +0000359 mDescrambling.dvrSoftwareFeId = dvrSwFeId;
360 mDescrambling.dvrSourceId = dvrSourceId;
361 mDescrambling.descramblerId = combo[descramblerIndex];
362 combinations.push_back(mDescrambling);
363 }
364
365 return combinations;
366}
367
368static inline vector<DescramblingHardwareConnections> generateDescramblingConfigurations() {
369 vector<DescramblingHardwareConnections> descrambling_configs;
370 if (configuredDescrambling) {
371 ALOGD("Using Descrambling configuration provided.");
372 descrambling_configs = {descrambling};
373 } else {
374 ALOGD("Descrambling not provided. Generating possible combinations. Consider adding it to "
375 "the "
376 "configuration file.");
377 descrambling_configs = generateDescramblingCombinations();
378 }
379
380 return descrambling_configs;
381}
382
Hongguang600a6ae2021-07-08 18:51:51 -0700383/** Config all the frontends that would be used in the tests */
384inline void initFrontendConfig() {
385 // The test will use the internal default fe when default fe is connected to any data flow
386 // without overriding in the xml config.
387 string defaultFeId = "FE_DEFAULT";
388 FrontendDvbtSettings dvbtSettings{
Gareth Fenn282fb372021-09-27 15:14:11 +0100389 .frequency = 578000000,
Hongguang600a6ae2021-07-08 18:51:51 -0700390 .transmissionMode = FrontendDvbtTransmissionMode::AUTO,
391 .bandwidth = FrontendDvbtBandwidth::BANDWIDTH_8MHZ,
392 .isHighPriority = true,
393 };
394 frontendMap[defaultFeId].type = FrontendType::DVBT;
395 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbtSettings);
396
397 vector<FrontendStatusType> types;
398 types.push_back(FrontendStatusType::UEC);
399 types.push_back(FrontendStatusType::IS_MISO);
400
401 vector<FrontendStatus> statuses;
402 FrontendStatus status;
403 status.set<FrontendStatus::Tag::uec>(4);
404 statuses.push_back(status);
405 status.set<FrontendStatus::Tag::isMiso>(true);
406 statuses.push_back(status);
407
408 frontendMap[defaultFeId].tuneStatusTypes = types;
409 frontendMap[defaultFeId].expectTuneStatuses = statuses;
410 frontendMap[defaultFeId].isSoftwareFe = true;
411 frontendMap[defaultFeId].canConnectToCiCam = true;
412 frontendMap[defaultFeId].ciCamId = 0;
413 FrontendDvbtSettings dvbt;
414 dvbt.transmissionMode = FrontendDvbtTransmissionMode::MODE_8K_E;
415 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbt);
416 // Read customized config
417 TunerTestingConfigAidlReader1_0::readFrontendConfig1_0(frontendMap);
418};
419
420inline void initFilterConfig() {
421 // The test will use the internal default filter when default filter is connected to any
422 // data flow without overriding in the xml config.
423 string defaultAudioFilterId = "FILTER_AUDIO_DEFAULT";
424 string defaultVideoFilterId = "FILTER_VIDEO_DEFAULT";
425
426 filterMap[defaultVideoFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700427 filterMap[defaultVideoFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
428 DemuxTsFilterType::VIDEO);
Hongguang600a6ae2021-07-08 18:51:51 -0700429 filterMap[defaultVideoFilterId].bufferSize = FMQ_SIZE_16M;
430 filterMap[defaultVideoFilterId].settings =
431 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
432 filterMap[defaultVideoFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
433 DemuxFilterAvSettings video;
434 video.isPassthrough = false;
435 filterMap[defaultVideoFilterId]
436 .settings.get<DemuxFilterSettings::Tag::ts>()
437 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(video);
438 filterMap[defaultVideoFilterId].monitorEventTypes =
439 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
440 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
441 filterMap[defaultVideoFilterId].streamType.set<AvStreamType::Tag::video>(
442 VideoStreamType::MPEG1);
443
444 filterMap[defaultAudioFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700445 filterMap[defaultAudioFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
446 DemuxTsFilterType::AUDIO);
Hongguang600a6ae2021-07-08 18:51:51 -0700447 filterMap[defaultAudioFilterId].bufferSize = FMQ_SIZE_16M;
448 filterMap[defaultAudioFilterId].settings =
449 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
450 filterMap[defaultAudioFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
451 DemuxFilterAvSettings audio;
452 audio.isPassthrough = false;
453 filterMap[defaultAudioFilterId]
454 .settings.get<DemuxFilterSettings::Tag::ts>()
455 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(audio);
456 filterMap[defaultAudioFilterId].monitorEventTypes =
457 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
458 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
459 filterMap[defaultAudioFilterId].streamType.set<AvStreamType::Tag::audio>(AudioStreamType::MP3);
460 // Read customized config
461 TunerTestingConfigAidlReader1_0::readFilterConfig1_0(filterMap);
462};
463
464/** Config all the dvrs that would be used in the tests */
465inline void initDvrConfig() {
466 // Read customized config
467 TunerTestingConfigAidlReader1_0::readDvrConfig1_0(dvrMap);
468};
469
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000470inline void initTimeFilterConfig() {
471 // Read customized config
472 TunerTestingConfigAidlReader1_0::readTimeFilterConfig1_0(timeFilterMap);
473};
474
Frankie Lizcanof5352122022-06-29 22:10:16 +0000475inline void initDescramblerConfig() {
476 // Read customized config
477 TunerTestingConfigAidlReader1_0::readDescramblerConfig1_0(descramblerMap);
478}
479
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000480inline void initLnbConfig() {
481 // Read customized config
482 TunerTestingConfigAidlReader1_0::readLnbConfig1_0(lnbMap);
483};
484
485inline void initDiseqcMsgsConfig() {
486 // Read customized config
487 TunerTestingConfigAidlReader1_0::readDiseqcMessages(diseqcMsgMap);
488};
489
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000490inline void determineScan() {
491 if (!frontendMap.empty()) {
492 scan.hasFrontendConnection = true;
493 ALOGD("Can support scan");
494 }
495}
496
497inline void determineTimeFilter() {
498 if (!timeFilterMap.empty()) {
499 timeFilter.support = true;
500 ALOGD("Can support time filter");
501 }
502}
503
504inline void determineDvrPlayback() {
505 if (!playbackDvrIds.empty() && !audioFilterIds.empty() && !videoFilterIds.empty()) {
506 playback.support = true;
507 ALOGD("Can support dvr playback");
508 }
509}
510
511inline void determineLnbLive() {
512 if (!audioFilterIds.empty() && !videoFilterIds.empty() && !frontendMap.empty() &&
513 !lnbMap.empty()) {
514 lnbLive.support = true;
515 ALOGD("Can support lnb live");
516 }
517}
518
519inline void determineLnbRecord() {
520 if (!frontendMap.empty() && !recordFilterIds.empty() && !recordDvrIds.empty() &&
521 !lnbMap.empty()) {
522 lnbRecord.support = true;
523 ALOGD("Can support lnb record");
524 }
525}
526
527inline void determineLive() {
528 if (videoFilterIds.empty() || audioFilterIds.empty() || frontendMap.empty()) {
529 return;
530 }
531 if (hasSwFe && !hasHwFe && dvrMap.empty()) {
532 ALOGD("Cannot configure Live. Only software frontends and no dvr connections");
533 return;
534 }
535 ALOGD("Can support live");
536 live.hasFrontendConnection = true;
537}
538
539inline void determineDescrambling() {
540 if (descramblerMap.empty() || audioFilterIds.empty() || videoFilterIds.empty()) {
541 return;
542 }
543 if (frontendMap.empty() && playbackDvrIds.empty()) {
544 ALOGD("Cannot configure descrambling. No frontends or playback dvr's");
545 return;
546 }
547 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
548 ALOGD("cannot configure descrambling. Only SW frontends and no playback dvr's");
549 return;
550 }
551 ALOGD("Can support descrambling");
552 descrambling.support = true;
553}
554
555inline void determineDvrRecord() {
556 if (recordDvrIds.empty() || recordFilterIds.empty()) {
557 return;
558 }
559 if (frontendMap.empty() && playbackDvrIds.empty()) {
Frankie Lizcanoecba02a2022-07-12 17:56:54 +0000560 ALOGD("Cannot support dvr record. No frontends and no playback dvr's");
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000561 return;
562 }
563 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
564 ALOGD("Cannot support dvr record. Only SW frontends and no playback dvr's");
565 return;
566 }
567 ALOGD("Can support dvr record.");
568 record.support = true;
569}
570
Hongguang600a6ae2021-07-08 18:51:51 -0700571/** Read the vendor configurations of which hardware to use for each test cases/data flows */
572inline void connectHardwaresToTestCases() {
573 TunerTestingConfigAidlReader1_0::connectLiveBroadcast(live);
574 TunerTestingConfigAidlReader1_0::connectScan(scan);
575 TunerTestingConfigAidlReader1_0::connectDvrRecord(record);
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000576 TunerTestingConfigAidlReader1_0::connectTimeFilter(timeFilter);
Frankie Lizcanof5352122022-06-29 22:10:16 +0000577 TunerTestingConfigAidlReader1_0::connectDescrambling(descrambling);
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000578 TunerTestingConfigAidlReader1_0::connectLnbLive(lnbLive);
Frankie Lizcano3138d6b2022-07-11 22:06:45 +0000579 TunerTestingConfigAidlReader1_0::connectLnbRecord(lnbRecord);
Frankie Lizcano50461932022-06-28 21:36:26 +0000580 TunerTestingConfigAidlReader1_0::connectDvrPlayback(playback);
Hongguang600a6ae2021-07-08 18:51:51 -0700581};
582
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000583inline void determineDataFlows() {
584 determineScan();
585 determineTimeFilter();
586 determineDvrPlayback();
587 determineLnbLive();
588 determineLnbRecord();
589 determineLive();
590 determineDescrambling();
591 determineDvrRecord();
592}
593
Hongguang600a6ae2021-07-08 18:51:51 -0700594inline bool validateConnections() {
595 if (record.support && !record.hasFrontendConnection &&
596 record.dvrSourceId.compare(emptyHardwareId) == 0) {
597 ALOGW("[vts config] Record must support either a DVR source or a Frontend source.");
598 return false;
599 }
Gareth Fenn9a808452022-03-31 08:40:00 +0100600 bool feIsValid = live.hasFrontendConnection
601 ? frontendMap.find(live.frontendId) != frontendMap.end()
602 : true;
603 feIsValid &= scan.hasFrontendConnection ? frontendMap.find(scan.frontendId) != frontendMap.end()
604 : true;
605 feIsValid &= record.support && record.hasFrontendConnection
606 ? frontendMap.find(record.frontendId) != frontendMap.end()
607 : true;
Frankie Lizcanof5352122022-06-29 22:10:16 +0000608 feIsValid &= descrambling.support && descrambling.hasFrontendConnection
609 ? frontendMap.find(descrambling.frontendId) != frontendMap.end()
610 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700611
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000612 feIsValid &= lnbLive.support ? frontendMap.find(lnbLive.frontendId) != frontendMap.end() : true;
613
614 feIsValid &=
615 lnbRecord.support ? frontendMap.find(lnbRecord.frontendId) != frontendMap.end() : true;
616
Hongguang600a6ae2021-07-08 18:51:51 -0700617 if (!feIsValid) {
618 ALOGW("[vts config] dynamic config fe connection is invalid.");
619 return false;
620 }
621
622 bool dvrIsValid = frontendMap[live.frontendId].isSoftwareFe
623 ? dvrMap.find(live.dvrSoftwareFeId) != dvrMap.end()
624 : true;
625
626 if (record.support) {
627 if (record.hasFrontendConnection) {
628 if (frontendMap[record.frontendId].isSoftwareFe) {
629 dvrIsValid &= dvrMap.find(record.dvrSoftwareFeId) != dvrMap.end();
630 }
631 } else {
632 dvrIsValid &= dvrMap.find(record.dvrSourceId) != dvrMap.end();
633 }
634 dvrIsValid &= dvrMap.find(record.dvrRecordId) != dvrMap.end();
635 }
636
Frankie Lizcanof5352122022-06-29 22:10:16 +0000637 if (descrambling.support) {
638 if (descrambling.hasFrontendConnection) {
639 if (frontendMap[descrambling.frontendId].isSoftwareFe) {
640 dvrIsValid &= dvrMap.find(descrambling.dvrSoftwareFeId) != dvrMap.end();
641 }
642 } else {
643 dvrIsValid &= dvrMap.find(descrambling.dvrSourceId) != dvrMap.end();
644 }
645 }
646
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000647 dvrIsValid &= lnbRecord.support ? dvrMap.find(lnbRecord.dvrRecordId) != dvrMap.end() : true;
648
Frankie Lizcano50461932022-06-28 21:36:26 +0000649 dvrIsValid &= playback.support ? dvrMap.find(playback.dvrId) != dvrMap.end() : true;
650
Hongguang600a6ae2021-07-08 18:51:51 -0700651 if (!dvrIsValid) {
652 ALOGW("[vts config] dynamic config dvr connection is invalid.");
653 return false;
654 }
655
Gareth Fenn9a808452022-03-31 08:40:00 +0100656 bool filterIsValid = (live.hasFrontendConnection)
657 ? filterMap.find(live.audioFilterId) != filterMap.end() &&
658 filterMap.find(live.videoFilterId) != filterMap.end()
659 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700660 filterIsValid &=
661 record.support ? filterMap.find(record.recordFilterId) != filterMap.end() : true;
662
Frankie Lizcanof5352122022-06-29 22:10:16 +0000663 filterIsValid &= descrambling.support
664 ? filterMap.find(descrambling.videoFilterId) != filterMap.end() &&
665 filterMap.find(descrambling.audioFilterId) != filterMap.end()
666 : true;
667
668 for (auto& filterId : descrambling.extraFilters) {
669 filterIsValid &= filterMap.find(filterId) != filterMap.end();
670 }
671
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000672 filterIsValid &= lnbLive.support
673 ? filterMap.find(lnbLive.audioFilterId) != filterMap.end() &&
674 filterMap.find(lnbLive.videoFilterId) != filterMap.end()
675 : true;
676
677 filterIsValid &=
678 lnbRecord.support ? filterMap.find(lnbRecord.recordFilterId) != filterMap.end() : true;
679
680 for (auto& filterId : lnbRecord.extraFilters) {
681 filterIsValid &= filterMap.find(filterId) != filterMap.end();
682 }
683
684 for (auto& filterId : lnbLive.extraFilters) {
685 filterIsValid &= filterMap.find(filterId) != filterMap.end();
686 }
687
Frankie Lizcano50461932022-06-28 21:36:26 +0000688 filterIsValid &= playback.support
689 ? filterMap.find(playback.audioFilterId) != filterMap.end() &&
690 filterMap.find(playback.videoFilterId) != filterMap.end()
691 : true;
692 filterIsValid &= playback.sectionFilterId.compare(emptyHardwareId) == 0
693 ? true
694 : filterMap.find(playback.sectionFilterId) != filterMap.end();
695
696 for (auto& filterId : playback.extraFilters) {
697 filterIsValid &=
698 playback.hasExtraFilters ? filterMap.find(filterId) != filterMap.end() : true;
699 }
700
Hongguang600a6ae2021-07-08 18:51:51 -0700701 if (!filterIsValid) {
702 ALOGW("[vts config] dynamic config filter connection is invalid.");
703 return false;
704 }
705
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000706 if (audioFilterIds.size() != videoFilterIds.size()) {
707 ALOGW("[vts config] the number of audio and video filters should be equal");
708 return false;
709 }
710
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000711 bool timeFilterIsValid =
712 timeFilter.support ? timeFilterMap.find(timeFilter.timeFilterId) != timeFilterMap.end()
713 : true;
714
715 if (!timeFilterIsValid) {
716 ALOGW("[vts config] dynamic config time filter connection is invalid.");
Frankie Lizcanof5352122022-06-29 22:10:16 +0000717 }
718
719 bool descramblerIsValid =
720 descrambling.support
721 ? descramblerMap.find(descrambling.descramblerId) != descramblerMap.end()
722 : true;
723
724 if (!descramblerIsValid) {
725 ALOGW("[vts config] dynamic config descrambler connection is invalid.");
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000726 return false;
727 }
728
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000729 bool lnbIsValid = lnbLive.support ? lnbMap.find(lnbLive.lnbId) != lnbMap.end() : true;
730
731 lnbIsValid &= lnbRecord.support ? lnbMap.find(lnbRecord.lnbId) != lnbMap.end() : true;
732
733 if (!lnbIsValid) {
734 ALOGW("[vts config] dynamic config lnb connection is invalid.");
735 return false;
736 }
737
738 bool diseqcMsgsIsValid = true;
739
740 for (auto& msg : lnbRecord.diseqcMsgs) {
741 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
742 }
743
744 for (auto& msg : lnbLive.diseqcMsgs) {
745 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
746 }
747
748 if (!diseqcMsgsIsValid) {
749 ALOGW("[vts config] dynamic config diseqcMsg is invalid.");
750 return false;
751 }
752
Hongguang600a6ae2021-07-08 18:51:51 -0700753 return true;
754}