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