blob: 5c7f5648d33c419f9ad8f7267dd639d892ce7f56 [file] [log] [blame]
Amy Zhange6915052021-03-30 13:44:43 -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 <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
27using namespace std;
28using namespace android::media::tuner::testing::configuration::V1_0;
29
30using android::hardware::tv::tuner::V1_0::DataFormat;
31using android::hardware::tv::tuner::V1_0::DemuxAlpFilterType;
32using android::hardware::tv::tuner::V1_0::DemuxFilterEvent;
33using android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
34using android::hardware::tv::tuner::V1_0::DemuxFilterSettings;
35using android::hardware::tv::tuner::V1_0::DemuxFilterType;
36using android::hardware::tv::tuner::V1_0::DemuxIpFilterType;
37using android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType;
38using android::hardware::tv::tuner::V1_0::DemuxRecordScIndexType;
39using android::hardware::tv::tuner::V1_0::DemuxTlvFilterType;
40using android::hardware::tv::tuner::V1_0::DemuxTpid;
41using android::hardware::tv::tuner::V1_0::DemuxTsFilterType;
42using android::hardware::tv::tuner::V1_0::DvrSettings;
43using android::hardware::tv::tuner::V1_0::DvrType;
44using android::hardware::tv::tuner::V1_0::FrontendDvbsSettings;
45using android::hardware::tv::tuner::V1_0::FrontendDvbtBandwidth;
46using android::hardware::tv::tuner::V1_0::FrontendDvbtCoderate;
47using android::hardware::tv::tuner::V1_0::FrontendDvbtConstellation;
48using android::hardware::tv::tuner::V1_0::FrontendDvbtGuardInterval;
49using android::hardware::tv::tuner::V1_0::FrontendDvbtHierarchy;
50using android::hardware::tv::tuner::V1_0::FrontendDvbtSettings;
51using android::hardware::tv::tuner::V1_0::FrontendDvbtStandard;
52using android::hardware::tv::tuner::V1_0::FrontendDvbtTransmissionMode;
53using android::hardware::tv::tuner::V1_0::FrontendSettings;
54using android::hardware::tv::tuner::V1_0::FrontendStatus;
55using android::hardware::tv::tuner::V1_0::FrontendStatusType;
56using android::hardware::tv::tuner::V1_0::FrontendType;
57using android::hardware::tv::tuner::V1_0::LnbPosition;
58using android::hardware::tv::tuner::V1_0::LnbTone;
59using android::hardware::tv::tuner::V1_0::LnbVoltage;
60using android::hardware::tv::tuner::V1_0::PlaybackSettings;
61using android::hardware::tv::tuner::V1_0::RecordSettings;
62
63const string configFilePath = "/vendor/etc/tuner_vts_config.xml";
64
65struct FrontendConfig {
66 bool isSoftwareFe;
67 FrontendType type;
68 FrontendSettings settings;
69 vector<FrontendStatusType> tuneStatusTypes;
70 vector<FrontendStatus> expectTuneStatuses;
71};
72
73struct LiveBroadcastHardwareConnections {
74 string frontendId;
75 /* string audioFilterId;
76 string videoFilterId;
77 list string of extra filters; */
78};
79
80struct ScanHardwareConnections {
81 string frontendId;
82};
83
84struct DvrRecordHardwareConnections {
85 bool support;
86 string frontendId;
87 /* string recordFilterId;
88 string dvrId; */
89};
90
91struct DescramblingHardwareConnections {
92 bool support;
93 string frontendId;
94 /* string descramblerId;
95 string audioFilterId;
96 string videoFilterId;
97 list string of extra filters; */
98};
99
100struct LnbLiveHardwareConnections {
101 bool support;
102 string frontendId;
103 /* string audioFilterId;
104 string videoFilterId;
105 list string of extra filters;
106 string lnbId; */
107};
108
109struct LnbRecordHardwareConnections {
110 bool support;
111 string frontendId;
112 /* string recordFilterId;
113 list string of extra filters;
114 string lnbId; */
115};
116
117struct TunerTestingConfigReader {
118 public:
119 static bool checkConfigFileExists() {
120 auto res = read(configFilePath.c_str());
121 if (res == nullopt) {
122 ALOGW("[ConfigReader] Couldn't read /vendor/etc/tuner_vts_config.xml."
123 "Please check tuner_testing_dynamic_configuration.xsd"
124 "and sample_tuner_vts_config.xml for more details on how to config Tune VTS.");
125 }
126 return (res != nullopt);
127 }
128
129 static void readFrontendConfig1_0(map<string, FrontendConfig>& frontendMap) {
130 auto hardwareConfig = getHardwareConfig();
131 if (hardwareConfig.hasFrontends()) {
132 // TODO: complete the tune status config
133 vector<FrontendStatusType> types;
134 types.push_back(FrontendStatusType::DEMOD_LOCK);
135 FrontendStatus status;
136 status.isDemodLocked(true);
137 vector<FrontendStatus> statuses;
138 statuses.push_back(status);
139
140 auto frontends = *hardwareConfig.getFirstFrontends();
141 for (auto feConfig : frontends.getFrontend()) {
142 string id = feConfig.getId();
143 if (id.compare(string("FE_DEFAULT")) == 0) {
144 // overrid default
145 frontendMap.erase(string("FE_DEFAULT"));
146 }
147 FrontendType type;
148 switch (feConfig.getType()) {
149 case FrontendTypeEnum::UNDEFINED:
150 type = FrontendType::UNDEFINED;
151 break;
152 // TODO: finish all other frontend settings
153 case FrontendTypeEnum::ANALOG:
154 type = FrontendType::ANALOG;
155 break;
156 case FrontendTypeEnum::ATSC:
157 type = FrontendType::ATSC;
158 break;
159 case FrontendTypeEnum::ATSC3:
160 type = FrontendType::ATSC3;
161 break;
162 case FrontendTypeEnum::DVBC:
163 type = FrontendType::DVBC;
164 break;
165 case FrontendTypeEnum::DVBS:
166 type = FrontendType::DVBS;
167 frontendMap[id].settings.dvbs(readDvbsFrontendSettings(feConfig));
168 break;
169 case FrontendTypeEnum::DVBT: {
170 type = FrontendType::DVBT;
171 frontendMap[id].settings.dvbt(readDvbtFrontendSettings(feConfig));
172 break;
173 }
174 case FrontendTypeEnum::ISDBS:
175 type = FrontendType::ISDBS;
176 break;
177 case FrontendTypeEnum::ISDBS3:
178 type = FrontendType::ISDBS3;
179 break;
180 case FrontendTypeEnum::ISDBT:
181 type = FrontendType::ISDBT;
182 break;
183 case FrontendTypeEnum::DTMB:
184 // dtmb will be handled in readFrontendConfig1_1;
185 continue;
186 case FrontendTypeEnum::UNKNOWN:
187 ALOGW("[ConfigReader] invalid frontend type");
188 return;
189 }
190 frontendMap[id].type = type;
191 frontendMap[id].isSoftwareFe = feConfig.getIsSoftwareFrontend();
192 // TODO: complete the tune status config
193 frontendMap[id].tuneStatusTypes = types;
194 frontendMap[id].expectTuneStatuses = statuses;
195 }
196 }
197 }
198
199 static void connectLiveBroadcast(LiveBroadcastHardwareConnections& live) {
200 auto liveConfig = getDataFlowConfiguration().getFirstClearLiveBroadcast();
201 live.frontendId = liveConfig->getFrontendConnection();
202 }
203
204 static void connectScan(ScanHardwareConnections& scan) {
205 auto scanConfig = getDataFlowConfiguration().getFirstScan();
206 scan.frontendId = scanConfig->getFrontendConnection();
207 }
208
209 static void connectDvrRecord(DvrRecordHardwareConnections& record) {
210 auto dataFlow = getDataFlowConfiguration();
211 if (!dataFlow.hasDvrRecord()) {
212 record.support = false;
213 return;
214 }
215 auto recordConfig = dataFlow.getFirstDvrRecord();
216 record.frontendId = recordConfig->getFrontendConnection();
217 }
218
219 static void connectDescrambling(DescramblingHardwareConnections& descrambling) {
220 auto dataFlow = getDataFlowConfiguration();
221 if (!dataFlow.hasDescrambling()) {
222 descrambling.support = false;
223 return;
224 }
225 auto descConfig = dataFlow.getFirstDescrambling();
226 descrambling.frontendId = descConfig->getFrontendConnection();
227 }
228
229 static void connectLnbLive(LnbLiveHardwareConnections& lnbLive) {
230 auto dataFlow = getDataFlowConfiguration();
231 if (!dataFlow.hasLnbLive()) {
232 lnbLive.support = false;
233 return;
234 }
235 auto lnbLiveConfig = dataFlow.getFirstLnbLive();
236 lnbLive.frontendId = lnbLiveConfig->getFrontendConnection();
237 }
238
239 static void connectLnbRecord(LnbRecordHardwareConnections& lnbRecord) {
240 auto dataFlow = getDataFlowConfiguration();
241 if (!dataFlow.hasLnbRecord()) {
242 lnbRecord.support = false;
243 return;
244 }
245 auto lnbRecordConfig = dataFlow.getFirstLnbRecord();
246 lnbRecord.frontendId = lnbRecordConfig->getFrontendConnection();
247 }
248
249 private:
250 static FrontendDvbtSettings readDvbtFrontendSettings(Frontend feConfig) {
251 ALOGW("[ConfigReader] type is dvbt");
252 FrontendDvbtSettings dvbtSettings{
253 .frequency = (uint32_t)feConfig.getFrequency(),
254 };
255 if (!feConfig.hasDvbtFrontendSettings_optional()) {
256 ALOGW("[ConfigReader] no more dvbt settings");
257 return dvbtSettings;
258 }
259 dvbtSettings.transmissionMode = static_cast<FrontendDvbtTransmissionMode>(
260 feConfig.getFirstDvbtFrontendSettings_optional()->getTransmissionMode());
261 dvbtSettings.bandwidth = static_cast<FrontendDvbtBandwidth>(
262 feConfig.getFirstDvbtFrontendSettings_optional()->getBandwidth());
263 dvbtSettings.isHighPriority =
264 feConfig.getFirstDvbtFrontendSettings_optional()->getIsHighPriority();
265 return dvbtSettings;
266 }
267
268 static FrontendDvbsSettings readDvbsFrontendSettings(Frontend feConfig) {
269 ALOGW("[ConfigReader] type is dvbs");
270 FrontendDvbsSettings dvbsSettings{
271 .frequency = (uint32_t)feConfig.getFrequency(),
272 };
273 if (!feConfig.hasDvbsFrontendSettings_optional()) {
274 ALOGW("[ConfigReader] no more dvbs settings");
275 return dvbsSettings;
276 }
277 dvbsSettings.symbolRate = static_cast<uint32_t>(
278 feConfig.getFirstDvbsFrontendSettings_optional()->getSymbolRate());
279 dvbsSettings.inputStreamId = static_cast<uint32_t>(
280 feConfig.getFirstDvbsFrontendSettings_optional()->getInputStreamId());
281 return dvbsSettings;
282 }
283
284 static TunerConfiguration getTunerConfig() { return *read(configFilePath.c_str()); }
285
286 static HardwareConfiguration getHardwareConfig() {
287 return *getTunerConfig().getFirstHardwareConfiguration();
288 }
289
290 static DataFlowConfiguration getDataFlowConfiguration() {
291 return *getTunerConfig().getFirstDataFlowConfiguration();
292 }
293};