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 "TunerTestingConfigReaderV1_0.h" 19 20 using android::hardware::tv::tuner::V1_1::AudioStreamType; 21 using android::hardware::tv::tuner::V1_1::AvStreamType; 22 using android::hardware::tv::tuner::V1_1::FrontendDvbsScanType; 23 using android::hardware::tv::tuner::V1_1::FrontendDvbsSettingsExt1_1; 24 using android::hardware::tv::tuner::V1_1::FrontendDvbtSettingsExt1_1; 25 using android::hardware::tv::tuner::V1_1::FrontendSettingsExt1_1; 26 using android::hardware::tv::tuner::V1_1::FrontendStatusExt1_1; 27 using android::hardware::tv::tuner::V1_1::FrontendStatusTypeExt1_1; 28 using android::hardware::tv::tuner::V1_1::VideoStreamType; 29 30 struct FrontendConfig1_1 { 31 FrontendConfig config1_0; 32 bool canConnectToCiCam; 33 uint32_t ciCamId; 34 FrontendSettingsExt1_1 settingsExt1_1; 35 vector<FrontendStatusTypeExt1_1> tuneStatusTypes; 36 vector<FrontendStatusExt1_1> expectTuneStatuses; 37 }; 38 39 struct FilterConfig1_1 { 40 FilterConfig config1_0; 41 AvStreamType streamType; 42 uint32_t ipCid; 43 uint32_t monitorEventTypes; 44 45 bool operator<(const FilterConfig& /*c*/) const { return false; } 46 }; 47 48 struct TunerTestingConfigReader1_1 { 49 public: readFrontendConfig1_1TunerTestingConfigReader1_150 static void readFrontendConfig1_1(map<string, FrontendConfig1_1>& frontendMap) { 51 map<string, FrontendConfig> frontendMap1_0; 52 TunerTestingConfigReader1_0::readFrontendConfig1_0(frontendMap1_0); 53 for (auto it = frontendMap1_0.begin(); it != frontendMap1_0.end(); it++) { 54 frontendMap[it->first].config1_0 = it->second; 55 } 56 57 auto hardwareConfig = TunerTestingConfigReader1_0::getHardwareConfig(); 58 if (hardwareConfig.hasFrontends()) { 59 // TODO: b/182519645 complete the tune status config 60 vector<FrontendStatusTypeExt1_1> types; 61 types.push_back(FrontendStatusTypeExt1_1::UEC); 62 types.push_back(FrontendStatusTypeExt1_1::IS_MISO); 63 vector<FrontendStatusExt1_1> statuses; 64 FrontendStatusExt1_1 status; 65 status.uec(4); 66 statuses.push_back(status); 67 status.isMiso(true); 68 statuses.push_back(status); 69 70 auto frontends = *hardwareConfig.getFirstFrontends(); 71 72 for (auto feConfig : frontends.getFrontend()) { 73 string id = feConfig.getId(); 74 switch (feConfig.getType()) { 75 case FrontendTypeEnum::DVBS: 76 frontendMap[id].settingsExt1_1.settingExt.dvbs( 77 readDvbsFrontendSettings1_1(feConfig)); 78 break; 79 case FrontendTypeEnum::DVBT: { 80 frontendMap[id].settingsExt1_1.settingExt.dvbt( 81 readDvbtFrontendSettings1_1(feConfig)); 82 break; 83 } 84 case FrontendTypeEnum::DTMB: 85 frontendMap[id].config1_0.type = static_cast<FrontendType>( 86 android::hardware::tv::tuner::V1_1::FrontendType::DTMB); 87 break; 88 case FrontendTypeEnum::UNKNOWN: 89 ALOGW("[ConfigReader] invalid frontend type"); 90 return; 91 default: 92 ALOGW("[ConfigReader] fe already handled in 1_0 reader."); 93 break; 94 } 95 if (feConfig.hasEndFrequency()) { 96 frontendMap[id].settingsExt1_1.endFrequency = 97 (uint32_t)feConfig.getEndFrequency(); 98 } 99 // TODO: b/182519645 complete the tune status config 100 frontendMap[id].tuneStatusTypes = types; 101 frontendMap[id].expectTuneStatuses = statuses; 102 getCiCamInfo(feConfig, frontendMap[id].canConnectToCiCam, frontendMap[id].ciCamId); 103 } 104 } 105 } 106 readFilterConfig1_1TunerTestingConfigReader1_1107 static void readFilterConfig1_1(map<string, FilterConfig1_1>& filterMap) { 108 map<string, FilterConfig> filterMap1_0; 109 TunerTestingConfigReader1_0::readFilterConfig1_0(filterMap1_0); 110 for (auto it = filterMap1_0.begin(); it != filterMap1_0.end(); it++) { 111 filterMap[it->first].config1_0 = it->second; 112 } 113 auto hardwareConfig = TunerTestingConfigReader1_0::getHardwareConfig(); 114 if (hardwareConfig.hasFilters()) { 115 auto filters = *hardwareConfig.getFirstFilters(); 116 for (auto filterConfig : filters.getFilter()) { 117 string id = filterConfig.getId(); 118 if (filterConfig.hasMonitorEventTypes()) { 119 filterMap[id].monitorEventTypes = (uint32_t)filterConfig.getMonitorEventTypes(); 120 } 121 if (filterConfig.hasAvFilterSettings_optional()) { 122 AvStreamType type; 123 auto av = filterConfig.getFirstAvFilterSettings_optional(); 124 if (av->hasAudioStreamType_optional()) { 125 type.audio(static_cast<AudioStreamType>(av->getAudioStreamType_optional())); 126 filterMap[id].streamType = type; 127 } 128 if (av->hasVideoStreamType_optional()) { 129 type.video(static_cast<VideoStreamType>(av->getVideoStreamType_optional())); 130 filterMap[id].streamType = type; 131 } 132 } 133 if (filterConfig.hasIpFilterConfig_optional()) { 134 auto ip = filterConfig.getFirstIpFilterConfig_optional(); 135 if (ip->hasIpCid()) { 136 filterMap[id].ipCid = ip->getIpCid(); 137 } 138 } 139 } 140 } 141 } 142 143 private: getCiCamInfoTunerTestingConfigReader1_1144 static void getCiCamInfo(Frontend feConfig, bool& canConnectToCiCam, uint32_t& ciCamId) { 145 if (!feConfig.hasConnectToCicamId()) { 146 canConnectToCiCam = false; 147 ciCamId = -1; 148 } 149 canConnectToCiCam = true; 150 ciCamId = static_cast<uint32_t>(feConfig.getConnectToCicamId()); 151 } 152 readDvbsFrontendSettings1_1TunerTestingConfigReader1_1153 static FrontendDvbsSettingsExt1_1 readDvbsFrontendSettings1_1(Frontend feConfig) { 154 FrontendDvbsSettingsExt1_1 dvbsSettings; 155 if (!feConfig.hasDvbsFrontendSettings_optional()) { 156 return dvbsSettings; 157 } 158 auto dvbs = feConfig.getFirstDvbsFrontendSettings_optional(); 159 if (dvbs->hasScanType()) { 160 dvbsSettings.scanType = static_cast<FrontendDvbsScanType>(dvbs->getScanType()); 161 } 162 if (dvbs->hasIsDiseqcRxMessage()) { 163 dvbsSettings.isDiseqcRxMessage = dvbs->getIsDiseqcRxMessage(); 164 } 165 return dvbsSettings; 166 } 167 readDvbtFrontendSettings1_1TunerTestingConfigReader1_1168 static FrontendDvbtSettingsExt1_1 readDvbtFrontendSettings1_1(Frontend feConfig) { 169 FrontendDvbtSettingsExt1_1 dvbtSettings; 170 if (!feConfig.hasDvbtFrontendSettings_optional()) { 171 return dvbtSettings; 172 } 173 auto dvbt = feConfig.getFirstDvbtFrontendSettings_optional(); 174 auto trans = dvbt->getTransmissionMode(); 175 dvbtSettings.transmissionMode = 176 static_cast<android::hardware::tv::tuner::V1_1::FrontendDvbtTransmissionMode>( 177 trans); 178 if (dvbt->hasConstellation()) { 179 dvbtSettings.constellation = 180 static_cast<android::hardware::tv::tuner::V1_1::FrontendDvbtConstellation>( 181 dvbt->getConstellation()); 182 } 183 return dvbtSettings; 184 } 185 };