• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 #pragma once
18 
19 #include <android-base/logging.h>
20 #include <android_media_tuner_testing_configuration_V1_0.h>
21 #include <android_media_tuner_testing_configuration_V1_0_enums.h>
22 
23 #include <aidl/android/hardware/tv/tuner/DataFormat.h>
24 #include <aidl/android/hardware/tv/tuner/DemuxAlpFilterType.h>
25 #include <aidl/android/hardware/tv/tuner/DemuxFilterAvSettings.h>
26 #include <aidl/android/hardware/tv/tuner/DemuxFilterEvent.h>
27 #include <aidl/android/hardware/tv/tuner/DemuxFilterMainType.h>
28 #include <aidl/android/hardware/tv/tuner/DemuxFilterRecordSettings.h>
29 #include <aidl/android/hardware/tv/tuner/DemuxFilterSectionSettings.h>
30 #include <aidl/android/hardware/tv/tuner/DemuxFilterSettings.h>
31 #include <aidl/android/hardware/tv/tuner/DemuxFilterType.h>
32 #include <aidl/android/hardware/tv/tuner/DemuxIpAddress.h>
33 #include <aidl/android/hardware/tv/tuner/DemuxIpFilterSettings.h>
34 #include <aidl/android/hardware/tv/tuner/DemuxIpFilterType.h>
35 #include <aidl/android/hardware/tv/tuner/DemuxMmtpFilterType.h>
36 #include <aidl/android/hardware/tv/tuner/DemuxRecordScIndexType.h>
37 #include <aidl/android/hardware/tv/tuner/DemuxTlvFilterType.h>
38 #include <aidl/android/hardware/tv/tuner/DemuxTsFilterType.h>
39 #include <aidl/android/hardware/tv/tuner/DvrSettings.h>
40 #include <aidl/android/hardware/tv/tuner/DvrType.h>
41 #include <aidl/android/hardware/tv/tuner/FrontendDvbsSettings.h>
42 #include <aidl/android/hardware/tv/tuner/FrontendDvbtBandwidth.h>
43 #include <aidl/android/hardware/tv/tuner/FrontendDvbtCoderate.h>
44 #include <aidl/android/hardware/tv/tuner/FrontendDvbtConstellation.h>
45 #include <aidl/android/hardware/tv/tuner/FrontendDvbtGuardInterval.h>
46 #include <aidl/android/hardware/tv/tuner/FrontendDvbtHierarchy.h>
47 #include <aidl/android/hardware/tv/tuner/FrontendDvbtPlpMode.h>
48 #include <aidl/android/hardware/tv/tuner/FrontendDvbtSettings.h>
49 #include <aidl/android/hardware/tv/tuner/FrontendDvbtStandard.h>
50 #include <aidl/android/hardware/tv/tuner/FrontendDvbtTransmissionMode.h>
51 #include <aidl/android/hardware/tv/tuner/FrontendSettings.h>
52 #include <aidl/android/hardware/tv/tuner/FrontendStatus.h>
53 #include <aidl/android/hardware/tv/tuner/FrontendStatusType.h>
54 #include <aidl/android/hardware/tv/tuner/FrontendType.h>
55 #include <aidl/android/hardware/tv/tuner/LnbPosition.h>
56 #include <aidl/android/hardware/tv/tuner/LnbTone.h>
57 #include <aidl/android/hardware/tv/tuner/LnbVoltage.h>
58 #include <aidl/android/hardware/tv/tuner/PlaybackSettings.h>
59 #include <aidl/android/hardware/tv/tuner/RecordSettings.h>
60 
61 using namespace std;
62 using namespace aidl::android::hardware::tv::tuner;
63 using namespace android::media::tuner::testing::configuration::V1_0;
64 
65 const string emptyHardwareId = "";
66 
67 static string mConfigFilePath;
68 
69 #define PROVISION_STR                                      \
70     "{                                                   " \
71     "  \"id\": 21140844,                                 " \
72     "  \"name\": \"Test Title\",                         " \
73     "  \"lowercase_organization_name\": \"Android\",     " \
74     "  \"asset_key\": {                                  " \
75     "  \"encryption_key\": \"nezAr3CHFrmBR9R8Tedotw==\"  " \
76     "  },                                                " \
77     "  \"cas_type\": 1,                                  " \
78     "  \"track_types\": [ ]                              " \
79     "}                                                   "
80 
81 struct FrontendConfig {
82     bool isSoftwareFe;
83     FrontendType type;
84     bool canConnectToCiCam;
85     int32_t ciCamId;
86     int32_t removePid;
87     FrontendSettings settings;
88     vector<FrontendStatusType> tuneStatusTypes;
89     vector<FrontendStatus> expectTuneStatuses;
90 };
91 
92 struct FilterConfig {
93     int32_t bufferSize;
94     DemuxFilterType type;
95     DemuxFilterSettings settings;
96     bool getMqDesc;
97     AvStreamType streamType;
98     int32_t ipCid;
99     int32_t monitorEventTypes;
100     int timeDelayInMs = 0;
101     int dataDelayInBytes = 0;
102 
103     bool operator<(const FilterConfig& /*c*/) const { return false; }
104 };
105 
106 struct DvrConfig {
107     DvrType type;
108     int32_t bufferSize;
109     DvrSettings settings;
110     string playbackInputFile;
111 };
112 
113 struct LnbConfig {
114     string name;
115     LnbVoltage voltage;
116     LnbTone tone;
117     LnbPosition position;
118 };
119 
120 struct TimeFilterConfig {
121     int64_t timeStamp;
122 };
123 
124 struct DescramblerConfig {
125     int32_t casSystemId;
126     string provisionStr;
127     vector<uint8_t> hidlPvtData;
128 };
129 
130 struct LiveBroadcastHardwareConnections {
131     bool hasFrontendConnection;
132     string frontendId;
133     string dvrSoftwareFeId;
134     string audioFilterId;
135     string videoFilterId;
136     string sectionFilterId;
137     string ipFilterId;
138     string pcrFilterId;
139     /* list string of extra filters; */
140 };
141 
142 struct ScanHardwareConnections {
143     bool hasFrontendConnection;
144     string frontendId;
145 };
146 
147 struct DvrPlaybackHardwareConnections {
148     bool support;
149     string frontendId;
150     string dvrId;
151     string audioFilterId;
152     string videoFilterId;
153     string sectionFilterId;
154     /* list string of extra filters; */
155 };
156 
157 struct DvrRecordHardwareConnections {
158     bool support;
159     bool hasFrontendConnection;
160     string frontendId;
161     string dvrRecordId;
162     string dvrSoftwareFeId;
163     string recordFilterId;
164     string dvrSourceId;
165 };
166 
167 struct DescramblingHardwareConnections {
168     bool support;
169     bool hasFrontendConnection;
170     string frontendId;
171     string dvrSoftwareFeId;
172     string audioFilterId;
173     string videoFilterId;
174     string descramblerId;
175     string dvrSourceId;
176     /* list string of extra filters; */
177 };
178 
179 struct LnbLiveHardwareConnections {
180     bool support;
181     string frontendId;
182     string audioFilterId;
183     string videoFilterId;
184     string lnbId;
185     vector<string> diseqcMsgs;
186     /* list string of extra filters; */
187 };
188 
189 struct LnbRecordHardwareConnections {
190     bool support;
191     string frontendId;
192     string dvrRecordId;
193     string recordFilterId;
194     string lnbId;
195     vector<string> diseqcMsgs;
196     /* list string of extra filters; */
197 };
198 
199 struct TimeFilterHardwareConnections {
200     bool support;
201     string timeFilterId;
202 };
203 
204 struct TunerTestingConfigAidlReader1_0 {
205   public:
setConfigFilePathTunerTestingConfigAidlReader1_0206     static void setConfigFilePath(string path) { mConfigFilePath = path; }
207 
checkConfigFileExistsTunerTestingConfigAidlReader1_0208     static bool checkConfigFileExists() {
209         auto res = read(mConfigFilePath.c_str());
210         if (res == nullopt) {
211             ALOGW("[ConfigReader] Couldn't read %s."
212                   "Please check tuner_testing_dynamic_configuration.xsd"
213                   "and sample_tuner_vts_config.xml for more details on how to config Tune VTS.",
214                   mConfigFilePath.c_str());
215         }
216         return (res != nullopt);
217     }
218 
getTunerConfigTunerTestingConfigAidlReader1_0219     static TunerConfiguration getTunerConfig() { return *read(mConfigFilePath.c_str()); }
220 
getDataFlowConfigurationTunerTestingConfigAidlReader1_0221     static DataFlowConfiguration getDataFlowConfiguration() {
222         return *getTunerConfig().getFirstDataFlowConfiguration();
223     }
224 
getHardwareConfigTunerTestingConfigAidlReader1_0225     static HardwareConfiguration getHardwareConfig() {
226         return *getTunerConfig().getFirstHardwareConfiguration();
227     }
228 
readFrontendConfig1_0TunerTestingConfigAidlReader1_0229     static void readFrontendConfig1_0(map<string, FrontendConfig>& frontendMap) {
230         auto hardwareConfig = getHardwareConfig();
231         if (hardwareConfig.hasFrontends()) {
232             // TODO: b/182519645 complete the tune status config
233             vector<FrontendStatusType> types;
234             vector<FrontendStatus> statuses;
235 
236             types.push_back(FrontendStatusType::DEMOD_LOCK);
237             types.push_back(FrontendStatusType::UEC);
238             types.push_back(FrontendStatusType::IS_MISO);
239 
240             FrontendStatus status;
241             status.set<FrontendStatus::Tag::isDemodLocked>(true);
242             statuses.push_back(status);
243             status.set<FrontendStatus::Tag::uec>(4);
244             statuses.push_back(status);
245             status.set<FrontendStatus::Tag::isMiso>(true);
246             statuses.push_back(status);
247 
248             auto frontends = *hardwareConfig.getFirstFrontends();
249             for (auto feConfig : frontends.getFrontend()) {
250                 string id = feConfig.getId();
251                 if (id.compare(string("FE_DEFAULT")) == 0) {
252                     // overrid default
253                     frontendMap.erase(string("FE_DEFAULT"));
254                 }
255                 FrontendType type;
256                 switch (feConfig.getType()) {
257                     case FrontendTypeEnum::UNDEFINED:
258                         type = FrontendType::UNDEFINED;
259                         break;
260                     // TODO: b/182519645 finish all other frontend settings
261                     case FrontendTypeEnum::ANALOG:
262                         type = FrontendType::ANALOG;
263                         break;
264                     case FrontendTypeEnum::ATSC:
265                         type = FrontendType::ATSC;
266                         break;
267                     case FrontendTypeEnum::ATSC3:
268                         type = FrontendType::ATSC3;
269                         break;
270                     case FrontendTypeEnum::DVBC:
271                         type = FrontendType::DVBC;
272                         break;
273                     case FrontendTypeEnum::DVBS:
274                         type = FrontendType::DVBS;
275                         frontendMap[id].settings.set<FrontendSettings::Tag::dvbs>(
276                                 readDvbsFrontendSettings(feConfig));
277                         break;
278                     case FrontendTypeEnum::DVBT: {
279                         type = FrontendType::DVBT;
280                         frontendMap[id].settings.set<FrontendSettings::Tag::dvbt>(
281                                 readDvbtFrontendSettings(feConfig));
282                         break;
283                     }
284                     case FrontendTypeEnum::ISDBS:
285                         type = FrontendType::ISDBS;
286                         break;
287                     case FrontendTypeEnum::ISDBS3:
288                         type = FrontendType::ISDBS3;
289                         break;
290                     case FrontendTypeEnum::ISDBT:
291                         type = FrontendType::ISDBT;
292                         break;
293                     case FrontendTypeEnum::DTMB:
294                         type = FrontendType::DTMB;
295                         break;
296                     case FrontendTypeEnum::UNKNOWN:
297                         ALOGW("[ConfigReader] invalid frontend type");
298                         return;
299                     default:
300                         ALOGW("[ConfigReader] fe already handled in 1_0 reader.");
301                         break;
302                 }
303                 frontendMap[id].type = type;
304                 frontendMap[id].isSoftwareFe = feConfig.getIsSoftwareFrontend();
305                 // TODO: b/182519645 complete the tune status config
306                 frontendMap[id].tuneStatusTypes = types;
307                 frontendMap[id].expectTuneStatuses = statuses;
308                 getCiCamInfo(feConfig, frontendMap[id].canConnectToCiCam, frontendMap[id].ciCamId,
309                              frontendMap[id].removePid);
310             }
311         }
312     }
313 
readFilterConfig1_0TunerTestingConfigAidlReader1_0314     static void readFilterConfig1_0(map<string, FilterConfig>& filterMap) {
315         auto hardwareConfig = getHardwareConfig();
316         if (hardwareConfig.hasFilters()) {
317             auto filters = *hardwareConfig.getFirstFilters();
318             for (auto filterConfig : filters.getFilter()) {
319                 string id = filterConfig.getId();
320                 if (id.compare(string("FILTER_AUDIO_DEFAULT")) == 0) {
321                     // overrid default
322                     filterMap.erase(string("FILTER_AUDIO_DEFAULT"));
323                 }
324                 if (id.compare(string("FILTER_VIDEO_DEFAULT")) == 0) {
325                     // overrid default
326                     filterMap.erase(string("FILTER_VIDEO_DEFAULT"));
327                 }
328 
329                 DemuxFilterType type;
330                 DemuxFilterSettings settings;
331                 if (!readFilterTypeAndSettings(filterConfig, type, settings)) {
332                     ALOGW("[ConfigReader] invalid filter type");
333                     return;
334                 }
335                 filterMap[id].type = type;
336                 filterMap[id].bufferSize = filterConfig.getBufferSize();
337                 filterMap[id].getMqDesc = filterConfig.getUseFMQ();
338                 filterMap[id].settings = settings;
339 
340                 if (filterConfig.hasMonitorEventTypes()) {
341                     filterMap[id].monitorEventTypes = (int32_t)filterConfig.getMonitorEventTypes();
342                 }
343                 if (filterConfig.hasTimeDelayInMs()) {
344                     filterMap[id].timeDelayInMs = filterConfig.getTimeDelayInMs();
345                 }
346                 if (filterConfig.hasDataDelayInBytes()) {
347                     filterMap[id].dataDelayInBytes = filterConfig.getDataDelayInBytes();
348                 }
349                 if (filterConfig.hasAvFilterSettings_optional()) {
350                     auto av = filterConfig.getFirstAvFilterSettings_optional();
351                     if (av->hasAudioStreamType_optional()) {
352                         filterMap[id].streamType.set<AvStreamType::Tag::audio>(
353                                 static_cast<AudioStreamType>(av->getAudioStreamType_optional()));
354                     }
355                     if (av->hasVideoStreamType_optional()) {
356                         filterMap[id].streamType.set<AvStreamType::Tag::video>(
357                                 static_cast<VideoStreamType>(av->getVideoStreamType_optional()));
358                     }
359                 }
360                 if (filterConfig.hasIpFilterConfig_optional()) {
361                     auto ip = filterConfig.getFirstIpFilterConfig_optional();
362                     if (ip->hasIpCid()) {
363                         filterMap[id].ipCid = ip->getIpCid();
364                     }
365                 }
366             }
367         }
368     }
369 
readDvrConfig1_0TunerTestingConfigAidlReader1_0370     static void readDvrConfig1_0(map<string, DvrConfig>& dvrMap) {
371         auto hardwareConfig = getHardwareConfig();
372         if (hardwareConfig.hasDvrs()) {
373             auto dvrs = *hardwareConfig.getFirstDvrs();
374             for (auto dvrConfig : dvrs.getDvr()) {
375                 string id = dvrConfig.getId();
376                 DvrType type;
377                 switch (dvrConfig.getType()) {
378                     case DvrTypeEnum::PLAYBACK:
379                         type = DvrType::PLAYBACK;
380                         dvrMap[id].settings.set<DvrSettings::Tag::playback>(
381                                 readPlaybackSettings(dvrConfig));
382                         break;
383                     case DvrTypeEnum::RECORD:
384                         type = DvrType::RECORD;
385                         dvrMap[id].settings.set<DvrSettings::Tag::record>(
386                                 readRecordSettings(dvrConfig));
387                         break;
388                     case DvrTypeEnum::UNKNOWN:
389                         ALOGW("[ConfigReader] invalid DVR type");
390                         return;
391                 }
392                 dvrMap[id].type = type;
393                 dvrMap[id].bufferSize = static_cast<int32_t>(dvrConfig.getBufferSize());
394                 if (dvrConfig.hasInputFilePath()) {
395                     dvrMap[id].playbackInputFile = dvrConfig.getInputFilePath();
396                 }
397             }
398         }
399     }
400 
readLnbConfig1_0TunerTestingConfigAidlReader1_0401     static void readLnbConfig1_0(map<string, LnbConfig>& lnbMap) {
402         auto hardwareConfig = getHardwareConfig();
403         if (hardwareConfig.hasLnbs()) {
404             auto lnbs = *hardwareConfig.getFirstLnbs();
405             for (auto lnbConfig : lnbs.getLnb()) {
406                 string id = lnbConfig.getId();
407                 if (lnbConfig.hasName()) {
408                     lnbMap[id].name = lnbConfig.getName();
409                 } else {
410                     lnbMap[id].name = emptyHardwareId;
411                 }
412                 lnbMap[id].voltage = static_cast<LnbVoltage>(lnbConfig.getVoltage());
413                 lnbMap[id].tone = static_cast<LnbTone>(lnbConfig.getTone());
414                 lnbMap[id].position = static_cast<LnbPosition>(lnbConfig.getPosition());
415             }
416         }
417     }
418 
readDescramblerConfig1_0TunerTestingConfigAidlReader1_0419     static void readDescramblerConfig1_0(map<string, DescramblerConfig>& descramblerMap) {
420         auto hardwareConfig = getHardwareConfig();
421         if (hardwareConfig.hasDescramblers()) {
422             auto descramblers = *hardwareConfig.getFirstDescramblers();
423             for (auto descramblerConfig : descramblers.getDescrambler()) {
424                 string id = descramblerConfig.getId();
425                 descramblerMap[id].casSystemId =
426                         static_cast<int32_t>(descramblerConfig.getCasSystemId());
427                 if (descramblerConfig.hasProvisionStr()) {
428                     descramblerMap[id].provisionStr = descramblerConfig.getProvisionStr();
429                 } else {
430                     descramblerMap[id].provisionStr = PROVISION_STR;
431                 }
432                 if (descramblerConfig.hasSesstionPrivatData()) {
433                     auto privateData = descramblerConfig.getSesstionPrivatData();
434                     int size = privateData.size();
435                     descramblerMap[id].hidlPvtData.resize(size);
436                     memcpy(descramblerMap[id].hidlPvtData.data(), privateData.data(), size);
437                 } else {
438                     descramblerMap[id].hidlPvtData.resize(256);
439                 }
440             }
441         }
442     }
443 
readDiseqcMessagesTunerTestingConfigAidlReader1_0444     static void readDiseqcMessages(map<string, vector<uint8_t>>& diseqcMsgMap) {
445         auto hardwareConfig = getHardwareConfig();
446         if (hardwareConfig.hasDiseqcMessages()) {
447             auto msgs = *hardwareConfig.getFirstDiseqcMessages();
448             for (auto msgConfig : msgs.getDiseqcMessage()) {
449                 string name = msgConfig.getMsgName();
450                 for (uint8_t atom : msgConfig.getMsgBody()) {
451                     diseqcMsgMap[name].push_back(atom);
452                 }
453             }
454         }
455     }
456 
readTimeFilterConfig1_0TunerTestingConfigAidlReader1_0457     static void readTimeFilterConfig1_0(map<string, TimeFilterConfig>& timeFilterMap) {
458         auto hardwareConfig = getHardwareConfig();
459         if (hardwareConfig.hasTimeFilters()) {
460             auto timeFilters = *hardwareConfig.getFirstTimeFilters();
461             for (auto timeFilterConfig : timeFilters.getTimeFilter()) {
462                 string id = timeFilterConfig.getId();
463                 timeFilterMap[id].timeStamp = static_cast<int64_t>(timeFilterConfig.getTimeStamp());
464             }
465         }
466     }
467 
connectLiveBroadcastTunerTestingConfigAidlReader1_0468     static void connectLiveBroadcast(LiveBroadcastHardwareConnections& live) {
469         auto dataFlow = getDataFlowConfiguration();
470         if (dataFlow.hasClearLiveBroadcast()) {
471             live.hasFrontendConnection = true;
472         } else {
473             live.hasFrontendConnection = false;
474             return;
475         }
476         auto liveConfig = *dataFlow.getFirstClearLiveBroadcast();
477         live.frontendId = liveConfig.getFrontendConnection();
478 
479         live.audioFilterId = liveConfig.getAudioFilterConnection();
480         live.videoFilterId = liveConfig.getVideoFilterConnection();
481         if (liveConfig.hasPcrFilterConnection()) {
482             live.pcrFilterId = liveConfig.getPcrFilterConnection();
483         } else {
484             live.pcrFilterId = emptyHardwareId;
485         }
486         if (liveConfig.hasSectionFilterConnection()) {
487             live.sectionFilterId = liveConfig.getSectionFilterConnection();
488         } else {
489             live.sectionFilterId = emptyHardwareId;
490         }
491         if (liveConfig.hasDvrSoftwareFeConnection()) {
492             live.dvrSoftwareFeId = liveConfig.getDvrSoftwareFeConnection();
493         }
494         if (liveConfig.hasIpFilterConnection()) {
495             live.ipFilterId = liveConfig.getIpFilterConnection();
496         } else {
497             live.ipFilterId = emptyHardwareId;
498         }
499     }
500 
connectScanTunerTestingConfigAidlReader1_0501     static void connectScan(ScanHardwareConnections& scan) {
502         auto dataFlow = getDataFlowConfiguration();
503         if (dataFlow.hasScan()) {
504             scan.hasFrontendConnection = true;
505         } else {
506             scan.hasFrontendConnection = false;
507             return;
508         }
509         auto scanConfig = *dataFlow.getFirstScan();
510         scan.frontendId = scanConfig.getFrontendConnection();
511     }
512 
connectDvrPlaybackTunerTestingConfigAidlReader1_0513     static void connectDvrPlayback(DvrPlaybackHardwareConnections& playback) {
514         auto dataFlow = getDataFlowConfiguration();
515         if (dataFlow.hasDvrPlayback()) {
516             playback.support = true;
517         } else {
518             playback.support = false;
519             return;
520         }
521         auto playbackConfig = *dataFlow.getFirstDvrPlayback();
522         playback.dvrId = playbackConfig.getDvrConnection();
523         playback.audioFilterId = playbackConfig.getAudioFilterConnection();
524         playback.videoFilterId = playbackConfig.getVideoFilterConnection();
525         if (playbackConfig.hasSectionFilterConnection()) {
526             playback.sectionFilterId = playbackConfig.getSectionFilterConnection();
527         } else {
528             playback.sectionFilterId = emptyHardwareId;
529         }
530     }
531 
connectDvrRecordTunerTestingConfigAidlReader1_0532     static void connectDvrRecord(DvrRecordHardwareConnections& record) {
533         auto dataFlow = getDataFlowConfiguration();
534         if (dataFlow.hasDvrRecord()) {
535             record.support = true;
536         } else {
537             record.support = false;
538             return;
539         }
540         auto recordConfig = *dataFlow.getFirstDvrRecord();
541         record.recordFilterId = recordConfig.getRecordFilterConnection();
542         record.dvrRecordId = recordConfig.getDvrRecordConnection();
543         if (recordConfig.hasDvrSoftwareFeConnection()) {
544             record.dvrSoftwareFeId = recordConfig.getDvrSoftwareFeConnection();
545         }
546         if (recordConfig.getHasFrontendConnection()) {
547             record.hasFrontendConnection = true;
548             record.dvrSourceId = emptyHardwareId;
549             record.frontendId = recordConfig.getFrontendConnection();
550         } else {
551             record.hasFrontendConnection = false;
552             record.dvrSourceId = recordConfig.getDvrSourceConnection();
553         }
554     }
555 
connectDescramblingTunerTestingConfigAidlReader1_0556     static void connectDescrambling(DescramblingHardwareConnections& descrambling) {
557         auto dataFlow = getDataFlowConfiguration();
558         if (dataFlow.hasDescrambling()) {
559             descrambling.support = true;
560         } else {
561             descrambling.support = false;
562             return;
563         }
564         auto descConfig = *dataFlow.getFirstDescrambling();
565         descrambling.descramblerId = descConfig.getDescramblerConnection();
566         descrambling.audioFilterId = descConfig.getAudioFilterConnection();
567         descrambling.videoFilterId = descConfig.getVideoFilterConnection();
568         if (descConfig.hasDvrSoftwareFeConnection()) {
569             descrambling.dvrSoftwareFeId = descConfig.getDvrSoftwareFeConnection();
570         }
571         if (descConfig.getHasFrontendConnection()) {
572             descrambling.hasFrontendConnection = true;
573             descrambling.dvrSourceId = emptyHardwareId;
574             descrambling.frontendId = descConfig.getFrontendConnection();
575         } else {
576             descrambling.hasFrontendConnection = false;
577             descrambling.dvrSourceId = descConfig.getDvrSourceConnection();
578         }
579     }
580 
connectLnbLiveTunerTestingConfigAidlReader1_0581     static void connectLnbLive(LnbLiveHardwareConnections& lnbLive) {
582         auto dataFlow = getDataFlowConfiguration();
583         if (dataFlow.hasLnbLive()) {
584             lnbLive.support = true;
585         } else {
586             lnbLive.support = false;
587             return;
588         }
589         auto lnbLiveConfig = *dataFlow.getFirstLnbLive();
590         lnbLive.frontendId = lnbLiveConfig.getFrontendConnection();
591         lnbLive.audioFilterId = lnbLiveConfig.getAudioFilterConnection();
592         lnbLive.videoFilterId = lnbLiveConfig.getVideoFilterConnection();
593         lnbLive.lnbId = lnbLiveConfig.getLnbConnection();
594         if (lnbLiveConfig.hasDiseqcMsgSender()) {
595             for (auto msgName : lnbLiveConfig.getDiseqcMsgSender()) {
596                 lnbLive.diseqcMsgs.push_back(msgName);
597             }
598         }
599     }
600 
connectLnbRecordTunerTestingConfigAidlReader1_0601     static void connectLnbRecord(LnbRecordHardwareConnections& lnbRecord) {
602         auto dataFlow = getDataFlowConfiguration();
603         if (dataFlow.hasLnbRecord()) {
604             lnbRecord.support = true;
605         } else {
606             lnbRecord.support = false;
607             return;
608         }
609         auto lnbRecordConfig = *dataFlow.getFirstLnbRecord();
610         lnbRecord.frontendId = lnbRecordConfig.getFrontendConnection();
611         lnbRecord.recordFilterId = lnbRecordConfig.getRecordFilterConnection();
612         lnbRecord.dvrRecordId = lnbRecordConfig.getDvrRecordConnection();
613         lnbRecord.lnbId = lnbRecordConfig.getLnbConnection();
614         if (lnbRecordConfig.hasDiseqcMsgSender()) {
615             for (auto msgName : lnbRecordConfig.getDiseqcMsgSender()) {
616                 lnbRecord.diseqcMsgs.push_back(msgName);
617             }
618         }
619     }
620 
connectTimeFilterTunerTestingConfigAidlReader1_0621     static void connectTimeFilter(TimeFilterHardwareConnections& timeFilter) {
622         auto dataFlow = getDataFlowConfiguration();
623         if (dataFlow.hasTimeFilter()) {
624             timeFilter.support = true;
625         } else {
626             timeFilter.support = false;
627             return;
628         }
629         auto timeFilterConfig = *dataFlow.getFirstTimeFilter();
630         timeFilter.timeFilterId = timeFilterConfig.getTimeFilterConnection();
631     }
632 
633   private:
readDvbtFrontendSettingsTunerTestingConfigAidlReader1_0634     static FrontendDvbtSettings readDvbtFrontendSettings(Frontend feConfig) {
635         ALOGW("[ConfigReader] fe type is dvbt");
636         FrontendDvbtSettings dvbtSettings{
637                 .frequency = (int64_t)feConfig.getFrequency(),
638         };
639         if (feConfig.hasEndFrequency()) {
640             dvbtSettings.endFrequency = (int64_t)feConfig.getEndFrequency();
641         }
642         if (!feConfig.hasDvbtFrontendSettings_optional()) {
643             ALOGW("[ConfigReader] no more dvbt settings");
644             return dvbtSettings;
645         }
646         auto dvbt = feConfig.getFirstDvbtFrontendSettings_optional();
647         int32_t trans = static_cast<int32_t>(dvbt->getTransmissionMode());
648         dvbtSettings.transmissionMode = static_cast<FrontendDvbtTransmissionMode>(trans);
649         dvbtSettings.bandwidth = static_cast<FrontendDvbtBandwidth>(dvbt->getBandwidth());
650         dvbtSettings.isHighPriority = dvbt->getIsHighPriority();
651         dvbtSettings.hierarchy = static_cast<FrontendDvbtHierarchy>(dvbt->getHierarchy());
652         dvbtSettings.hpCoderate = static_cast<FrontendDvbtCoderate>(dvbt->getHpCoderate());
653         dvbtSettings.lpCoderate = static_cast<FrontendDvbtCoderate>(dvbt->getLpCoderate());
654         dvbtSettings.guardInterval =
655                 static_cast<FrontendDvbtGuardInterval>(dvbt->getGuardInterval());
656         dvbtSettings.standard = static_cast<FrontendDvbtStandard>(dvbt->getStandard());
657         dvbtSettings.isMiso = dvbt->getIsMiso();
658         dvbtSettings.plpMode = static_cast<FrontendDvbtPlpMode>(dvbt->getPlpMode());
659         dvbtSettings.plpId = dvbt->getPlpId();
660         dvbtSettings.plpGroupId = dvbt->getPlpGroupId();
661         if (dvbt->hasConstellation()) {
662             dvbtSettings.constellation =
663                     static_cast<FrontendDvbtConstellation>(dvbt->getConstellation());
664         }
665         return dvbtSettings;
666     }
667 
readDvbsFrontendSettingsTunerTestingConfigAidlReader1_0668     static FrontendDvbsSettings readDvbsFrontendSettings(Frontend feConfig) {
669         ALOGW("[ConfigReader] fe type is dvbs");
670         FrontendDvbsSettings dvbsSettings{
671                 .frequency = (int64_t)feConfig.getFrequency(),
672         };
673         if (feConfig.hasEndFrequency()) {
674             dvbsSettings.endFrequency = (int64_t)feConfig.getEndFrequency();
675         }
676         if (!feConfig.hasDvbsFrontendSettings_optional()) {
677             ALOGW("[ConfigReader] no more dvbs settings");
678             return dvbsSettings;
679         }
680         dvbsSettings.symbolRate = static_cast<int32_t>(
681                 feConfig.getFirstDvbsFrontendSettings_optional()->getSymbolRate());
682         dvbsSettings.inputStreamId = static_cast<int32_t>(
683                 feConfig.getFirstDvbsFrontendSettings_optional()->getInputStreamId());
684         auto dvbs = feConfig.getFirstDvbsFrontendSettings_optional();
685         if (dvbs->hasScanType()) {
686             dvbsSettings.scanType = static_cast<FrontendDvbsScanType>(dvbs->getScanType());
687         }
688         if (dvbs->hasIsDiseqcRxMessage()) {
689             dvbsSettings.isDiseqcRxMessage = dvbs->getIsDiseqcRxMessage();
690         }
691         return dvbsSettings;
692     }
693 
readFilterTypeAndSettingsTunerTestingConfigAidlReader1_0694     static bool readFilterTypeAndSettings(Filter filterConfig, DemuxFilterType& type,
695                                           DemuxFilterSettings& settings) {
696         auto mainType = filterConfig.getMainType();
697         auto subType = filterConfig.getSubType();
698 
699         switch (mainType) {
700             case FilterMainTypeEnum::TS: {
701                 ALOGW("[ConfigReader] filter main type is ts");
702                 type.mainType = DemuxFilterMainType::TS;
703                 DemuxTsFilterSettings ts;
704                 bool isTsSet = false;
705                 switch (subType) {
706                     case FilterSubTypeEnum::UNDEFINED:
707                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
708                                 DemuxTsFilterType::UNDEFINED);
709                         break;
710                     case FilterSubTypeEnum::SECTION:
711                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
712                                 DemuxTsFilterType::SECTION);
713                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::section>(
714                                 readSectionFilterSettings(filterConfig));
715                         isTsSet = true;
716                         break;
717                     case FilterSubTypeEnum::PES:
718                         // TODO: b/182519645 support all the filter settings
719                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
720                                 DemuxTsFilterType::PES);
721                         break;
722                     case FilterSubTypeEnum::TS:
723                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
724                                 DemuxTsFilterType::TS);
725                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::noinit>(
726                                 true);
727                         isTsSet = true;
728                         break;
729                     case FilterSubTypeEnum::PCR:
730                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
731                                 DemuxTsFilterType::PCR);
732                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::noinit>(
733                                 true);
734                         isTsSet = true;
735                         break;
736                     case FilterSubTypeEnum::TEMI:
737                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
738                                 DemuxTsFilterType::TEMI);
739                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::noinit>(
740                                 true);
741                         isTsSet = true;
742                         break;
743                     case FilterSubTypeEnum::AUDIO:
744                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
745                                 DemuxTsFilterType::AUDIO);
746                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(
747                                 readAvFilterSettings(filterConfig));
748                         isTsSet = true;
749                         break;
750                     case FilterSubTypeEnum::VIDEO:
751                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
752                                 DemuxTsFilterType::VIDEO);
753                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::av>(
754                                 readAvFilterSettings(filterConfig));
755                         isTsSet = true;
756                         break;
757                     case FilterSubTypeEnum::RECORD:
758                         type.subType.set<DemuxFilterSubType::Tag::tsFilterType>(
759                                 DemuxTsFilterType::RECORD);
760                         ts.filterSettings.set<DemuxTsFilterSettingsFilterSettings::Tag::record>(
761                                 readRecordFilterSettings(filterConfig));
762                         isTsSet = true;
763                         break;
764                     default:
765                         ALOGW("[ConfigReader] ts subtype is not supported");
766                         return false;
767                 }
768                 if (filterConfig.hasPid()) {
769                     ts.tpid = static_cast<int32_t>(filterConfig.getPid());
770                     isTsSet = true;
771                 }
772                 if (isTsSet) {
773                     settings.set<DemuxFilterSettings::Tag::ts>(ts);
774                 }
775                 break;
776             }
777             case FilterMainTypeEnum::MMTP: {
778                 ALOGW("[ConfigReader] filter main type is mmtp");
779                 type.mainType = DemuxFilterMainType::MMTP;
780                 DemuxMmtpFilterSettings mmtp;
781                 bool isMmtpSet = false;
782                 switch (subType) {
783                     case FilterSubTypeEnum::UNDEFINED:
784                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
785                                 DemuxMmtpFilterType::UNDEFINED);
786                         break;
787                     case FilterSubTypeEnum::SECTION:
788                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
789                                 DemuxMmtpFilterType::SECTION);
790                         mmtp.filterSettings
791                                 .set<DemuxMmtpFilterSettingsFilterSettings::Tag::section>(
792                                         readSectionFilterSettings(filterConfig));
793                         isMmtpSet = true;
794                         break;
795                     case FilterSubTypeEnum::PES:
796                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
797                                 DemuxMmtpFilterType::PES);
798                         // TODO: b/182519645 support all the filter settings
799                         break;
800                     case FilterSubTypeEnum::MMTP:
801                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
802                                 DemuxMmtpFilterType::MMTP);
803                         mmtp.filterSettings.set<DemuxMmtpFilterSettingsFilterSettings::Tag::noinit>(
804                                 true);
805                         isMmtpSet = true;
806                         break;
807                     case FilterSubTypeEnum::AUDIO:
808                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
809                                 DemuxMmtpFilterType::AUDIO);
810                         mmtp.filterSettings.set<DemuxMmtpFilterSettingsFilterSettings::Tag::av>(
811                                 readAvFilterSettings(filterConfig));
812                         isMmtpSet = true;
813                         break;
814                     case FilterSubTypeEnum::VIDEO:
815                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
816                                 DemuxMmtpFilterType::VIDEO);
817                         mmtp.filterSettings.set<DemuxMmtpFilterSettingsFilterSettings::Tag::av>(
818                                 readAvFilterSettings(filterConfig));
819                         isMmtpSet = true;
820                         break;
821                     case FilterSubTypeEnum::RECORD:
822                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
823                                 DemuxMmtpFilterType::RECORD);
824                         mmtp.filterSettings.set<DemuxMmtpFilterSettingsFilterSettings::Tag::record>(
825                                 readRecordFilterSettings(filterConfig));
826                         isMmtpSet = true;
827                         break;
828                     case FilterSubTypeEnum::DOWNLOAD:
829                         type.subType.set<DemuxFilterSubType::Tag::mmtpFilterType>(
830                                 DemuxMmtpFilterType::DOWNLOAD);
831                         // TODO: b/182519645 support all the filter settings
832                         break;
833                     default:
834                         ALOGW("[ConfigReader] mmtp subtype is not supported");
835                         return false;
836                 }
837                 if (filterConfig.hasPid()) {
838                     mmtp.mmtpPid = static_cast<int32_t>(filterConfig.getPid());
839                     isMmtpSet = true;
840                 }
841                 if (isMmtpSet) {
842                     settings.set<DemuxFilterSettings::Tag::mmtp>(mmtp);
843                 }
844                 break;
845             }
846             case FilterMainTypeEnum::IP: {
847                 ALOGW("[ConfigReader] filter main type is ip");
848                 type.mainType = DemuxFilterMainType::IP;
849                 DemuxIpFilterSettings ip;
850                 switch (subType) {
851                     case FilterSubTypeEnum::UNDEFINED:
852                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
853                                 DemuxIpFilterType::UNDEFINED);
854                         break;
855                     case FilterSubTypeEnum::SECTION:
856                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
857                                 DemuxIpFilterType::SECTION);
858                         ip.filterSettings.set<DemuxIpFilterSettingsFilterSettings::Tag::section>(
859                                 readSectionFilterSettings(filterConfig));
860                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
861                         break;
862                     case FilterSubTypeEnum::NTP:
863                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
864                                 DemuxIpFilterType::NTP);
865                         ip.filterSettings.set<DemuxIpFilterSettingsFilterSettings::Tag::noinit>(
866                                 true);
867                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
868                         break;
869                     case FilterSubTypeEnum::IP: {
870                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
871                                 DemuxIpFilterType::IP);
872                         ip.ipAddr = readIpAddress(filterConfig),
873                         ip.filterSettings
874                                 .set<DemuxIpFilterSettingsFilterSettings::Tag::bPassthrough>(
875                                         readPassthroughSettings(filterConfig));
876                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
877                         break;
878                     }
879                     case FilterSubTypeEnum::IP_PAYLOAD:
880                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
881                                 DemuxIpFilterType::IP_PAYLOAD);
882                         ip.filterSettings.set<DemuxIpFilterSettingsFilterSettings::Tag::noinit>(
883                                 true);
884                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
885                         break;
886                     case FilterSubTypeEnum::PAYLOAD_THROUGH:
887                         type.subType.set<DemuxFilterSubType::Tag::ipFilterType>(
888                                 DemuxIpFilterType::PAYLOAD_THROUGH);
889                         ip.filterSettings.set<DemuxIpFilterSettingsFilterSettings::Tag::noinit>(
890                                 true);
891                         settings.set<DemuxFilterSettings::Tag::ip>(ip);
892                         break;
893                     default:
894                         ALOGW("[ConfigReader] mmtp subtype is not supported");
895                         return false;
896                 }
897                 break;
898             }
899             default:
900                 // TODO: b/182519645 support all the filter configs
901                 ALOGW("[ConfigReader] filter main type is not supported in dynamic config");
902                 return false;
903         }
904         return true;
905     }
906 
readIpAddressTunerTestingConfigAidlReader1_0907     static DemuxIpAddress readIpAddress(Filter filterConfig) {
908         DemuxIpAddress ipAddress;
909         vector<uint8_t> data;
910         if (!filterConfig.hasIpFilterConfig_optional()) {
911             return ipAddress;
912         }
913         auto ipFilterConfig = filterConfig.getFirstIpFilterConfig_optional();
914         if (ipFilterConfig->hasSrcPort()) {
915             ipAddress.srcPort = ipFilterConfig->getSrcPort();
916         }
917         if (ipFilterConfig->hasDestPort()) {
918             ipAddress.dstPort = ipFilterConfig->getDestPort();
919         }
920         if (ipFilterConfig->getFirstSrcIpAddress()->getIsIpV4()) {
921             data.resize(4);
922             memcpy(data.data(), ipFilterConfig->getFirstSrcIpAddress()->getIp().data(), 4);
923             ipAddress.srcIpAddress.set<DemuxIpAddressIpAddress::Tag::v4>(data);
924         } else {
925             data.resize(6);
926             memcpy(data.data(), ipFilterConfig->getFirstSrcIpAddress()->getIp().data(), 6);
927             ipAddress.srcIpAddress.set<DemuxIpAddressIpAddress::Tag::v6>(data);
928         }
929         if (ipFilterConfig->getFirstDestIpAddress()->getIsIpV4()) {
930             data.resize(4);
931             memcpy(data.data(), ipFilterConfig->getFirstDestIpAddress()->getIp().data(), 4);
932             ipAddress.dstIpAddress.set<DemuxIpAddressIpAddress::Tag::v4>(data);
933         } else {
934             data.resize(6);
935             memcpy(data.data(), ipFilterConfig->getFirstDestIpAddress()->getIp().data(), 6);
936             ipAddress.dstIpAddress.set<DemuxIpAddressIpAddress::Tag::v6>(data);
937         }
938         return ipAddress;
939     }
940 
readPassthroughSettingsTunerTestingConfigAidlReader1_0941     static bool readPassthroughSettings(Filter filterConfig) {
942         if (!filterConfig.hasIpFilterConfig_optional()) {
943             return false;
944         }
945         auto ipFilterConfig = filterConfig.getFirstIpFilterConfig_optional();
946         if (ipFilterConfig->hasDataPassthrough()) {
947             return ipFilterConfig->getDataPassthrough();
948         }
949         return false;
950     }
951 
readSectionFilterSettingsTunerTestingConfigAidlReader1_0952     static DemuxFilterSectionSettings readSectionFilterSettings(Filter filterConfig) {
953         DemuxFilterSectionSettings settings;
954         if (!filterConfig.hasSectionFilterSettings_optional()) {
955             return settings;
956         }
957         auto section = filterConfig.getFirstSectionFilterSettings_optional();
958         settings.isCheckCrc = section->getIsCheckCrc();
959         settings.isRepeat = section->getIsRepeat();
960         settings.isRaw = section->getIsRaw();
961         settings.bitWidthOfLengthField = section->getBitWidthOfLengthField();
962         return settings;
963     }
964 
readAvFilterSettingsTunerTestingConfigAidlReader1_0965     static DemuxFilterAvSettings readAvFilterSettings(Filter filterConfig) {
966         DemuxFilterAvSettings settings;
967         if (!filterConfig.hasAvFilterSettings_optional()) {
968             return settings;
969         }
970         auto av = filterConfig.getFirstAvFilterSettings_optional();
971         settings.isPassthrough = av->getIsPassthrough();
972         settings.isSecureMemory = av->getIsSecureMemory();
973         return settings;
974     }
975 
readRecordFilterSettingsTunerTestingConfigAidlReader1_0976     static DemuxFilterRecordSettings readRecordFilterSettings(Filter filterConfig) {
977         DemuxFilterRecordSettings settings;
978         if (!filterConfig.hasRecordFilterSettings_optional()) {
979             return settings;
980         }
981         auto record = filterConfig.getFirstRecordFilterSettings_optional();
982         settings.tsIndexMask = record->getTsIndexMask();
983         settings.scIndexType = static_cast<DemuxRecordScIndexType>(record->getScIndexType());
984         return settings;
985     }
986 
readPlaybackSettingsTunerTestingConfigAidlReader1_0987     static PlaybackSettings readPlaybackSettings(Dvr dvrConfig) {
988         ALOGW("[ConfigReader] dvr type is playback");
989         PlaybackSettings playbackSettings{
990                 .statusMask = static_cast<int8_t>(dvrConfig.getStatusMask()),
991                 .lowThreshold = static_cast<int64_t>(dvrConfig.getLowThreshold()),
992                 .highThreshold = static_cast<int64_t>(dvrConfig.getHighThreshold()),
993                 .dataFormat = static_cast<DataFormat>(dvrConfig.getDataFormat()),
994                 .packetSize = static_cast<int64_t>(dvrConfig.getPacketSize()),
995         };
996         return playbackSettings;
997     }
998 
readRecordSettingsTunerTestingConfigAidlReader1_0999     static RecordSettings readRecordSettings(Dvr dvrConfig) {
1000         ALOGW("[ConfigReader] dvr type is record");
1001         RecordSettings recordSettings{
1002                 .statusMask = static_cast<int8_t>(dvrConfig.getStatusMask()),
1003                 .lowThreshold = static_cast<int64_t>(dvrConfig.getLowThreshold()),
1004                 .highThreshold = static_cast<int64_t>(dvrConfig.getHighThreshold()),
1005                 .dataFormat = static_cast<DataFormat>(dvrConfig.getDataFormat()),
1006                 .packetSize = static_cast<int64_t>(dvrConfig.getPacketSize()),
1007         };
1008         return recordSettings;
1009     }
1010 
getCiCamInfoTunerTestingConfigAidlReader1_01011     static void getCiCamInfo(Frontend feConfig, bool& canConnectToCiCam, int32_t& ciCamId,
1012                              int32_t& removePid) {
1013         if (!feConfig.hasConnectToCicamId()) {
1014             canConnectToCiCam = false;
1015             ciCamId = -1;
1016             removePid = -1;
1017             return;
1018         }
1019         canConnectToCiCam = true;
1020         ciCamId = static_cast<int32_t>(feConfig.getConnectToCicamId());
1021         removePid = static_cast<int32_t>(feConfig.getRemoveOutputPid());
1022     }
1023 };
1024