blob: ca74ab04ab5d4e5991e75a517608be413902acc6 [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
Frankie Lizcano0c069532022-07-14 20:20:46 +0000383static inline vector<TimeFilterHardwareConnections> generateTimeFilterCombinations() {
384 vector<TimeFilterHardwareConnections> combinations;
385
386 for (auto& id : timeFilterIds) {
387 TimeFilterHardwareConnections mTimeFilter;
388 mTimeFilter.timeFilterId = id;
389 combinations.push_back(mTimeFilter);
390 }
391
392 return combinations;
393}
394
395static inline vector<TimeFilterHardwareConnections> generateTimeFilterConfigurations() {
396 vector<TimeFilterHardwareConnections> timeFilter_configs;
397 if (configuredTimeFilter) {
398 ALOGD("Using TimeFilter configuration provided.");
399 timeFilter_configs = {timeFilter};
400 } else {
401 ALOGD("TimeFilter not provided. Generating possible combinations. Consider adding it to "
402 "the "
403 "configuration file.");
404 timeFilter_configs = generateTimeFilterCombinations();
405 }
406
407 return timeFilter_configs;
408}
409
Hongguang600a6ae2021-07-08 18:51:51 -0700410/** Config all the frontends that would be used in the tests */
411inline void initFrontendConfig() {
412 // The test will use the internal default fe when default fe is connected to any data flow
413 // without overriding in the xml config.
414 string defaultFeId = "FE_DEFAULT";
415 FrontendDvbtSettings dvbtSettings{
Gareth Fenn282fb372021-09-27 15:14:11 +0100416 .frequency = 578000000,
Hongguang600a6ae2021-07-08 18:51:51 -0700417 .transmissionMode = FrontendDvbtTransmissionMode::AUTO,
418 .bandwidth = FrontendDvbtBandwidth::BANDWIDTH_8MHZ,
419 .isHighPriority = true,
420 };
421 frontendMap[defaultFeId].type = FrontendType::DVBT;
422 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbtSettings);
423
424 vector<FrontendStatusType> types;
425 types.push_back(FrontendStatusType::UEC);
426 types.push_back(FrontendStatusType::IS_MISO);
427
428 vector<FrontendStatus> statuses;
429 FrontendStatus status;
430 status.set<FrontendStatus::Tag::uec>(4);
431 statuses.push_back(status);
432 status.set<FrontendStatus::Tag::isMiso>(true);
433 statuses.push_back(status);
434
435 frontendMap[defaultFeId].tuneStatusTypes = types;
436 frontendMap[defaultFeId].expectTuneStatuses = statuses;
437 frontendMap[defaultFeId].isSoftwareFe = true;
438 frontendMap[defaultFeId].canConnectToCiCam = true;
439 frontendMap[defaultFeId].ciCamId = 0;
440 FrontendDvbtSettings dvbt;
441 dvbt.transmissionMode = FrontendDvbtTransmissionMode::MODE_8K_E;
442 frontendMap[defaultFeId].settings.set<FrontendSettings::Tag::dvbt>(dvbt);
443 // Read customized config
444 TunerTestingConfigAidlReader1_0::readFrontendConfig1_0(frontendMap);
445};
446
447inline void initFilterConfig() {
448 // The test will use the internal default filter when default filter is connected to any
449 // data flow without overriding in the xml config.
450 string defaultAudioFilterId = "FILTER_AUDIO_DEFAULT";
451 string defaultVideoFilterId = "FILTER_VIDEO_DEFAULT";
452
453 filterMap[defaultVideoFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700454 filterMap[defaultVideoFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
455 DemuxTsFilterType::VIDEO);
Hongguang600a6ae2021-07-08 18:51:51 -0700456 filterMap[defaultVideoFilterId].bufferSize = FMQ_SIZE_16M;
457 filterMap[defaultVideoFilterId].settings =
458 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
459 filterMap[defaultVideoFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
460 DemuxFilterAvSettings video;
461 video.isPassthrough = false;
462 filterMap[defaultVideoFilterId]
463 .settings.get<DemuxFilterSettings::Tag::ts>()
464 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(video);
465 filterMap[defaultVideoFilterId].monitorEventTypes =
466 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
467 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
468 filterMap[defaultVideoFilterId].streamType.set<AvStreamType::Tag::video>(
469 VideoStreamType::MPEG1);
470
471 filterMap[defaultAudioFilterId].type.mainType = DemuxFilterMainType::TS;
Hongguangce1e30d2021-08-02 21:55:44 -0700472 filterMap[defaultAudioFilterId].type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
473 DemuxTsFilterType::AUDIO);
Hongguang600a6ae2021-07-08 18:51:51 -0700474 filterMap[defaultAudioFilterId].bufferSize = FMQ_SIZE_16M;
475 filterMap[defaultAudioFilterId].settings =
476 DemuxFilterSettings::make<DemuxFilterSettings::Tag::ts>();
477 filterMap[defaultAudioFilterId].settings.get<DemuxFilterSettings::Tag::ts>().tpid = 256;
478 DemuxFilterAvSettings audio;
479 audio.isPassthrough = false;
480 filterMap[defaultAudioFilterId]
481 .settings.get<DemuxFilterSettings::Tag::ts>()
482 .filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(audio);
483 filterMap[defaultAudioFilterId].monitorEventTypes =
484 static_cast<int32_t>(DemuxFilterMonitorEventType::SCRAMBLING_STATUS) |
485 static_cast<int32_t>(DemuxFilterMonitorEventType::IP_CID_CHANGE);
486 filterMap[defaultAudioFilterId].streamType.set<AvStreamType::Tag::audio>(AudioStreamType::MP3);
487 // Read customized config
488 TunerTestingConfigAidlReader1_0::readFilterConfig1_0(filterMap);
489};
490
491/** Config all the dvrs that would be used in the tests */
492inline void initDvrConfig() {
493 // Read customized config
494 TunerTestingConfigAidlReader1_0::readDvrConfig1_0(dvrMap);
495};
496
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000497inline void initTimeFilterConfig() {
498 // Read customized config
499 TunerTestingConfigAidlReader1_0::readTimeFilterConfig1_0(timeFilterMap);
500};
501
Frankie Lizcanof5352122022-06-29 22:10:16 +0000502inline void initDescramblerConfig() {
503 // Read customized config
504 TunerTestingConfigAidlReader1_0::readDescramblerConfig1_0(descramblerMap);
505}
506
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000507inline void initLnbConfig() {
508 // Read customized config
509 TunerTestingConfigAidlReader1_0::readLnbConfig1_0(lnbMap);
510};
511
512inline void initDiseqcMsgsConfig() {
513 // Read customized config
514 TunerTestingConfigAidlReader1_0::readDiseqcMessages(diseqcMsgMap);
515};
516
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000517inline void determineScan() {
518 if (!frontendMap.empty()) {
519 scan.hasFrontendConnection = true;
520 ALOGD("Can support scan");
521 }
522}
523
524inline void determineTimeFilter() {
525 if (!timeFilterMap.empty()) {
526 timeFilter.support = true;
527 ALOGD("Can support time filter");
528 }
529}
530
531inline void determineDvrPlayback() {
532 if (!playbackDvrIds.empty() && !audioFilterIds.empty() && !videoFilterIds.empty()) {
533 playback.support = true;
534 ALOGD("Can support dvr playback");
535 }
536}
537
538inline void determineLnbLive() {
539 if (!audioFilterIds.empty() && !videoFilterIds.empty() && !frontendMap.empty() &&
540 !lnbMap.empty()) {
541 lnbLive.support = true;
542 ALOGD("Can support lnb live");
543 }
544}
545
546inline void determineLnbRecord() {
547 if (!frontendMap.empty() && !recordFilterIds.empty() && !recordDvrIds.empty() &&
548 !lnbMap.empty()) {
549 lnbRecord.support = true;
550 ALOGD("Can support lnb record");
551 }
552}
553
554inline void determineLive() {
555 if (videoFilterIds.empty() || audioFilterIds.empty() || frontendMap.empty()) {
556 return;
557 }
558 if (hasSwFe && !hasHwFe && dvrMap.empty()) {
559 ALOGD("Cannot configure Live. Only software frontends and no dvr connections");
560 return;
561 }
562 ALOGD("Can support live");
563 live.hasFrontendConnection = true;
564}
565
566inline void determineDescrambling() {
567 if (descramblerMap.empty() || audioFilterIds.empty() || videoFilterIds.empty()) {
568 return;
569 }
570 if (frontendMap.empty() && playbackDvrIds.empty()) {
571 ALOGD("Cannot configure descrambling. No frontends or playback dvr's");
572 return;
573 }
574 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
575 ALOGD("cannot configure descrambling. Only SW frontends and no playback dvr's");
576 return;
577 }
578 ALOGD("Can support descrambling");
579 descrambling.support = true;
580}
581
582inline void determineDvrRecord() {
583 if (recordDvrIds.empty() || recordFilterIds.empty()) {
584 return;
585 }
586 if (frontendMap.empty() && playbackDvrIds.empty()) {
Frankie Lizcanoecba02a2022-07-12 17:56:54 +0000587 ALOGD("Cannot support dvr record. No frontends and no playback dvr's");
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000588 return;
589 }
590 if (hasSwFe && !hasHwFe && playbackDvrIds.empty()) {
591 ALOGD("Cannot support dvr record. Only SW frontends and no playback dvr's");
592 return;
593 }
594 ALOGD("Can support dvr record.");
595 record.support = true;
596}
597
Hongguang600a6ae2021-07-08 18:51:51 -0700598/** Read the vendor configurations of which hardware to use for each test cases/data flows */
599inline void connectHardwaresToTestCases() {
600 TunerTestingConfigAidlReader1_0::connectLiveBroadcast(live);
601 TunerTestingConfigAidlReader1_0::connectScan(scan);
602 TunerTestingConfigAidlReader1_0::connectDvrRecord(record);
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000603 TunerTestingConfigAidlReader1_0::connectTimeFilter(timeFilter);
Frankie Lizcanof5352122022-06-29 22:10:16 +0000604 TunerTestingConfigAidlReader1_0::connectDescrambling(descrambling);
Frankie Lizcano1e283b32022-07-08 21:07:42 +0000605 TunerTestingConfigAidlReader1_0::connectLnbLive(lnbLive);
Frankie Lizcano3138d6b2022-07-11 22:06:45 +0000606 TunerTestingConfigAidlReader1_0::connectLnbRecord(lnbRecord);
Frankie Lizcano50461932022-06-28 21:36:26 +0000607 TunerTestingConfigAidlReader1_0::connectDvrPlayback(playback);
Hongguang600a6ae2021-07-08 18:51:51 -0700608};
609
Frankie Lizcano5b29f502022-07-06 22:09:42 +0000610inline void determineDataFlows() {
611 determineScan();
612 determineTimeFilter();
613 determineDvrPlayback();
614 determineLnbLive();
615 determineLnbRecord();
616 determineLive();
617 determineDescrambling();
618 determineDvrRecord();
619}
620
Hongguang600a6ae2021-07-08 18:51:51 -0700621inline bool validateConnections() {
622 if (record.support && !record.hasFrontendConnection &&
623 record.dvrSourceId.compare(emptyHardwareId) == 0) {
624 ALOGW("[vts config] Record must support either a DVR source or a Frontend source.");
625 return false;
626 }
Gareth Fenn9a808452022-03-31 08:40:00 +0100627 bool feIsValid = live.hasFrontendConnection
628 ? frontendMap.find(live.frontendId) != frontendMap.end()
629 : true;
630 feIsValid &= scan.hasFrontendConnection ? frontendMap.find(scan.frontendId) != frontendMap.end()
631 : true;
632 feIsValid &= record.support && record.hasFrontendConnection
633 ? frontendMap.find(record.frontendId) != frontendMap.end()
634 : true;
Frankie Lizcanof5352122022-06-29 22:10:16 +0000635 feIsValid &= descrambling.support && descrambling.hasFrontendConnection
636 ? frontendMap.find(descrambling.frontendId) != frontendMap.end()
637 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700638
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000639 feIsValid &= lnbLive.support ? frontendMap.find(lnbLive.frontendId) != frontendMap.end() : true;
640
641 feIsValid &=
642 lnbRecord.support ? frontendMap.find(lnbRecord.frontendId) != frontendMap.end() : true;
643
Hongguang600a6ae2021-07-08 18:51:51 -0700644 if (!feIsValid) {
645 ALOGW("[vts config] dynamic config fe connection is invalid.");
646 return false;
647 }
648
649 bool dvrIsValid = frontendMap[live.frontendId].isSoftwareFe
650 ? dvrMap.find(live.dvrSoftwareFeId) != dvrMap.end()
651 : true;
652
653 if (record.support) {
654 if (record.hasFrontendConnection) {
655 if (frontendMap[record.frontendId].isSoftwareFe) {
656 dvrIsValid &= dvrMap.find(record.dvrSoftwareFeId) != dvrMap.end();
657 }
658 } else {
659 dvrIsValid &= dvrMap.find(record.dvrSourceId) != dvrMap.end();
660 }
661 dvrIsValid &= dvrMap.find(record.dvrRecordId) != dvrMap.end();
662 }
663
Frankie Lizcanof5352122022-06-29 22:10:16 +0000664 if (descrambling.support) {
665 if (descrambling.hasFrontendConnection) {
666 if (frontendMap[descrambling.frontendId].isSoftwareFe) {
667 dvrIsValid &= dvrMap.find(descrambling.dvrSoftwareFeId) != dvrMap.end();
668 }
669 } else {
670 dvrIsValid &= dvrMap.find(descrambling.dvrSourceId) != dvrMap.end();
671 }
672 }
673
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000674 dvrIsValid &= lnbRecord.support ? dvrMap.find(lnbRecord.dvrRecordId) != dvrMap.end() : true;
675
Frankie Lizcano50461932022-06-28 21:36:26 +0000676 dvrIsValid &= playback.support ? dvrMap.find(playback.dvrId) != dvrMap.end() : true;
677
Hongguang600a6ae2021-07-08 18:51:51 -0700678 if (!dvrIsValid) {
679 ALOGW("[vts config] dynamic config dvr connection is invalid.");
680 return false;
681 }
682
Gareth Fenn9a808452022-03-31 08:40:00 +0100683 bool filterIsValid = (live.hasFrontendConnection)
684 ? filterMap.find(live.audioFilterId) != filterMap.end() &&
685 filterMap.find(live.videoFilterId) != filterMap.end()
686 : true;
Hongguang600a6ae2021-07-08 18:51:51 -0700687 filterIsValid &=
688 record.support ? filterMap.find(record.recordFilterId) != filterMap.end() : true;
689
Frankie Lizcanof5352122022-06-29 22:10:16 +0000690 filterIsValid &= descrambling.support
691 ? filterMap.find(descrambling.videoFilterId) != filterMap.end() &&
692 filterMap.find(descrambling.audioFilterId) != filterMap.end()
693 : true;
694
695 for (auto& filterId : descrambling.extraFilters) {
696 filterIsValid &= filterMap.find(filterId) != filterMap.end();
697 }
698
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000699 filterIsValid &= lnbLive.support
700 ? filterMap.find(lnbLive.audioFilterId) != filterMap.end() &&
701 filterMap.find(lnbLive.videoFilterId) != filterMap.end()
702 : true;
703
704 filterIsValid &=
705 lnbRecord.support ? filterMap.find(lnbRecord.recordFilterId) != filterMap.end() : true;
706
707 for (auto& filterId : lnbRecord.extraFilters) {
708 filterIsValid &= filterMap.find(filterId) != filterMap.end();
709 }
710
711 for (auto& filterId : lnbLive.extraFilters) {
712 filterIsValid &= filterMap.find(filterId) != filterMap.end();
713 }
714
Frankie Lizcano50461932022-06-28 21:36:26 +0000715 filterIsValid &= playback.support
716 ? filterMap.find(playback.audioFilterId) != filterMap.end() &&
717 filterMap.find(playback.videoFilterId) != filterMap.end()
718 : true;
719 filterIsValid &= playback.sectionFilterId.compare(emptyHardwareId) == 0
720 ? true
721 : filterMap.find(playback.sectionFilterId) != filterMap.end();
722
723 for (auto& filterId : playback.extraFilters) {
724 filterIsValid &=
725 playback.hasExtraFilters ? filterMap.find(filterId) != filterMap.end() : true;
726 }
727
Hongguang600a6ae2021-07-08 18:51:51 -0700728 if (!filterIsValid) {
729 ALOGW("[vts config] dynamic config filter connection is invalid.");
730 return false;
731 }
732
Frankie Lizcano14aa8482022-07-26 16:50:35 +0000733 if (audioFilterIds.size() != videoFilterIds.size()) {
734 ALOGW("[vts config] the number of audio and video filters should be equal");
735 return false;
736 }
737
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000738 bool timeFilterIsValid =
739 timeFilter.support ? timeFilterMap.find(timeFilter.timeFilterId) != timeFilterMap.end()
740 : true;
741
742 if (!timeFilterIsValid) {
743 ALOGW("[vts config] dynamic config time filter connection is invalid.");
Frankie Lizcanof5352122022-06-29 22:10:16 +0000744 }
745
746 bool descramblerIsValid =
747 descrambling.support
748 ? descramblerMap.find(descrambling.descramblerId) != descramblerMap.end()
749 : true;
750
751 if (!descramblerIsValid) {
752 ALOGW("[vts config] dynamic config descrambler connection is invalid.");
Frankie Lizcano1fd52972022-06-30 16:50:21 +0000753 return false;
754 }
755
Frankie Lizcano647d5aa2022-06-30 20:49:31 +0000756 bool lnbIsValid = lnbLive.support ? lnbMap.find(lnbLive.lnbId) != lnbMap.end() : true;
757
758 lnbIsValid &= lnbRecord.support ? lnbMap.find(lnbRecord.lnbId) != lnbMap.end() : true;
759
760 if (!lnbIsValid) {
761 ALOGW("[vts config] dynamic config lnb connection is invalid.");
762 return false;
763 }
764
765 bool diseqcMsgsIsValid = true;
766
767 for (auto& msg : lnbRecord.diseqcMsgs) {
768 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
769 }
770
771 for (auto& msg : lnbLive.diseqcMsgs) {
772 diseqcMsgsIsValid &= diseqcMsgMap.find(msg) != diseqcMsgMap.end();
773 }
774
775 if (!diseqcMsgsIsValid) {
776 ALOGW("[vts config] dynamic config diseqcMsg is invalid.");
777 return false;
778 }
779
Hongguang600a6ae2021-07-08 18:51:51 -0700780 return true;
781}