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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "TunerHidlFrontend"
19
20 #include "TunerHidlFrontend.h"
21
22 #include <aidl/android/hardware/tv/tuner/Result.h>
23
24 #include "TunerHidlLnb.h"
25 #include "TunerHidlService.h"
26
27 using ::aidl::android::hardware::tv::tuner::FrontendAnalogSettings;
28 using ::aidl::android::hardware::tv::tuner::FrontendAnalogSifStandard;
29 using ::aidl::android::hardware::tv::tuner::FrontendAnalogType;
30 using ::aidl::android::hardware::tv::tuner::FrontendAtsc3Bandwidth;
31 using ::aidl::android::hardware::tv::tuner::FrontendAtsc3CodeRate;
32 using ::aidl::android::hardware::tv::tuner::FrontendAtsc3Fec;
33 using ::aidl::android::hardware::tv::tuner::FrontendAtsc3Modulation;
34 using ::aidl::android::hardware::tv::tuner::FrontendAtsc3PlpSettings;
35 using ::aidl::android::hardware::tv::tuner::FrontendAtsc3Settings;
36 using ::aidl::android::hardware::tv::tuner::FrontendAtsc3TimeInterleaveMode;
37 using ::aidl::android::hardware::tv::tuner::FrontendAtscModulation;
38 using ::aidl::android::hardware::tv::tuner::FrontendAtscSettings;
39 using ::aidl::android::hardware::tv::tuner::FrontendBandwidth;
40 using ::aidl::android::hardware::tv::tuner::FrontendCableTimeInterleaveMode;
41 using ::aidl::android::hardware::tv::tuner::FrontendDtmbBandwidth;
42 using ::aidl::android::hardware::tv::tuner::FrontendDtmbGuardInterval;
43 using ::aidl::android::hardware::tv::tuner::FrontendDtmbModulation;
44 using ::aidl::android::hardware::tv::tuner::FrontendDtmbSettings;
45 using ::aidl::android::hardware::tv::tuner::FrontendDtmbTimeInterleaveMode;
46 using ::aidl::android::hardware::tv::tuner::FrontendDtmbTransmissionMode;
47 using ::aidl::android::hardware::tv::tuner::FrontendDvbcAnnex;
48 using ::aidl::android::hardware::tv::tuner::FrontendDvbcBandwidth;
49 using ::aidl::android::hardware::tv::tuner::FrontendDvbcModulation;
50 using ::aidl::android::hardware::tv::tuner::FrontendDvbcSettings;
51 using ::aidl::android::hardware::tv::tuner::FrontendDvbsModulation;
52 using ::aidl::android::hardware::tv::tuner::FrontendDvbsRolloff;
53 using ::aidl::android::hardware::tv::tuner::FrontendDvbsSettings;
54 using ::aidl::android::hardware::tv::tuner::FrontendDvbsStandard;
55 using ::aidl::android::hardware::tv::tuner::FrontendDvbtBandwidth;
56 using ::aidl::android::hardware::tv::tuner::FrontendDvbtConstellation;
57 using ::aidl::android::hardware::tv::tuner::FrontendDvbtGuardInterval;
58 using ::aidl::android::hardware::tv::tuner::FrontendDvbtHierarchy;
59 using ::aidl::android::hardware::tv::tuner::FrontendDvbtSettings;
60 using ::aidl::android::hardware::tv::tuner::FrontendDvbtStandard;
61 using ::aidl::android::hardware::tv::tuner::FrontendDvbtTransmissionMode;
62 using ::aidl::android::hardware::tv::tuner::FrontendGuardInterval;
63 using ::aidl::android::hardware::tv::tuner::FrontendInnerFec;
64 using ::aidl::android::hardware::tv::tuner::FrontendInterleaveMode;
65 using ::aidl::android::hardware::tv::tuner::FrontendIsdbs3Modulation;
66 using ::aidl::android::hardware::tv::tuner::FrontendIsdbs3Rolloff;
67 using ::aidl::android::hardware::tv::tuner::FrontendIsdbs3Settings;
68 using ::aidl::android::hardware::tv::tuner::FrontendIsdbsModulation;
69 using ::aidl::android::hardware::tv::tuner::FrontendIsdbsRolloff;
70 using ::aidl::android::hardware::tv::tuner::FrontendIsdbsSettings;
71 using ::aidl::android::hardware::tv::tuner::FrontendIsdbtBandwidth;
72 using ::aidl::android::hardware::tv::tuner::FrontendIsdbtCoderate;
73 using ::aidl::android::hardware::tv::tuner::FrontendIsdbtGuardInterval;
74 using ::aidl::android::hardware::tv::tuner::FrontendIsdbtMode;
75 using ::aidl::android::hardware::tv::tuner::FrontendIsdbtModulation;
76 using ::aidl::android::hardware::tv::tuner::FrontendIsdbtSettings;
77 using ::aidl::android::hardware::tv::tuner::FrontendModulation;
78 using ::aidl::android::hardware::tv::tuner::FrontendModulationStatus;
79 using ::aidl::android::hardware::tv::tuner::FrontendRollOff;
80 using ::aidl::android::hardware::tv::tuner::FrontendScanAtsc3PlpInfo;
81 using ::aidl::android::hardware::tv::tuner::FrontendScanMessageStandard;
82 using ::aidl::android::hardware::tv::tuner::FrontendSpectralInversion;
83 using ::aidl::android::hardware::tv::tuner::FrontendStatusAtsc3PlpInfo;
84 using ::aidl::android::hardware::tv::tuner::FrontendTransmissionMode;
85 using ::aidl::android::hardware::tv::tuner::Result;
86
87 using HidlFrontendStatusAtsc3PlpInfo =
88 ::aidl::android::hardware::tv::tuner::FrontendStatusAtsc3PlpInfo;
89 using HidlFrontendAnalogSifStandard =
90 ::android::hardware::tv::tuner::V1_0::FrontendAnalogSifStandard;
91 using HidlFrontendAnalogType = ::android::hardware::tv::tuner::V1_0::FrontendAnalogType;
92 using HidlFrontendAtscModulation = ::android::hardware::tv::tuner::V1_0::FrontendAtscModulation;
93 using HidlFrontendAtsc3Bandwidth = ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Bandwidth;
94 using HidlFrontendAtsc3CodeRate = ::android::hardware::tv::tuner::V1_0::FrontendAtsc3CodeRate;
95 using HidlFrontendAtsc3DemodOutputFormat =
96 ::android::hardware::tv::tuner::V1_0::FrontendAtsc3DemodOutputFormat;
97 using HidlFrontendAtsc3Fec = ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Fec;
98 using HidlFrontendAtsc3Modulation = ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Modulation;
99 using HidlFrontendAtsc3TimeInterleaveMode =
100 ::android::hardware::tv::tuner::V1_0::FrontendAtsc3TimeInterleaveMode;
101 using HidlFrontendDvbcAnnex = ::android::hardware::tv::tuner::V1_0::FrontendDvbcAnnex;
102 using HidlFrontendDvbcModulation = ::android::hardware::tv::tuner::V1_0::FrontendDvbcModulation;
103 using HidlFrontendDvbcOuterFec = ::android::hardware::tv::tuner::V1_0::FrontendDvbcOuterFec;
104 using HidlFrontendDvbcSpectralInversion =
105 ::android::hardware::tv::tuner::V1_0::FrontendDvbcSpectralInversion;
106 using HidlFrontendDvbsModulation = ::android::hardware::tv::tuner::V1_0::FrontendDvbsModulation;
107 using HidlFrontendDvbsPilot = ::android::hardware::tv::tuner::V1_0::FrontendDvbsPilot;
108 using HidlFrontendDvbsRolloff = ::android::hardware::tv::tuner::V1_0::FrontendDvbsRolloff;
109 using HidlFrontendDvbsSettings = ::android::hardware::tv::tuner::V1_0::FrontendDvbsSettings;
110 using HidlFrontendDvbsStandard = ::android::hardware::tv::tuner::V1_0::FrontendDvbsStandard;
111 using HidlFrontendDvbsVcmMode = ::android::hardware::tv::tuner::V1_0::FrontendDvbsVcmMode;
112 using HidlFrontendDvbtBandwidth = ::android::hardware::tv::tuner::V1_0::FrontendDvbtBandwidth;
113 using HidlFrontendDvbtCoderate = ::android::hardware::tv::tuner::V1_0::FrontendDvbtCoderate;
114 using HidlFrontendDvbtConstellation =
115 ::android::hardware::tv::tuner::V1_0::FrontendDvbtConstellation;
116 using HidlFrontendDvbtGuardInterval =
117 ::android::hardware::tv::tuner::V1_0::FrontendDvbtGuardInterval;
118 using HidlFrontendDvbtHierarchy = ::android::hardware::tv::tuner::V1_0::FrontendDvbtHierarchy;
119 using HidlFrontendDvbtPlpMode = ::android::hardware::tv::tuner::V1_0::FrontendDvbtPlpMode;
120 using HidlFrontendDvbtSettings = ::android::hardware::tv::tuner::V1_0::FrontendDvbtSettings;
121 using HidlFrontendDvbtStandard = ::android::hardware::tv::tuner::V1_0::FrontendDvbtStandard;
122 using HidlFrontendDvbtTransmissionMode =
123 ::android::hardware::tv::tuner::V1_0::FrontendDvbtTransmissionMode;
124 using HidlFrontendInnerFec = ::android::hardware::tv::tuner::V1_0::FrontendInnerFec;
125 using HidlFrontendIsdbs3Coderate = ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Coderate;
126 using HidlFrontendIsdbs3Modulation = ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Modulation;
127 using HidlFrontendIsdbs3Rolloff = ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Rolloff;
128 using HidlFrontendIsdbs3Settings = ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Settings;
129 using HidlFrontendIsdbsCoderate = ::android::hardware::tv::tuner::V1_0::FrontendIsdbsCoderate;
130 using HidlFrontendIsdbsModulation = ::android::hardware::tv::tuner::V1_0::FrontendIsdbsModulation;
131 using HidlFrontendIsdbsRolloff = ::android::hardware::tv::tuner::V1_0::FrontendIsdbsRolloff;
132 using HidlFrontendIsdbsSettings = ::android::hardware::tv::tuner::V1_0::FrontendIsdbsSettings;
133 using HidlFrontendIsdbsStreamIdType =
134 ::android::hardware::tv::tuner::V1_0::FrontendIsdbsStreamIdType;
135 using HidlFrontendIsdbtBandwidth = ::android::hardware::tv::tuner::V1_0::FrontendIsdbtBandwidth;
136 using HidlFrontendIsdbtCoderate = ::android::hardware::tv::tuner::V1_0::FrontendIsdbtCoderate;
137 using HidlFrontendIsdbtGuardInterval =
138 ::android::hardware::tv::tuner::V1_0::FrontendIsdbtGuardInterval;
139 using HidlFrontendIsdbtMode = ::android::hardware::tv::tuner::V1_0::FrontendIsdbtMode;
140 using HidlFrontendIsdbtModulation = ::android::hardware::tv::tuner::V1_0::FrontendIsdbtModulation;
141 using HidlFrontendIsdbtSettings = ::android::hardware::tv::tuner::V1_0::FrontendIsdbtSettings;
142 using HidlFrontendModulationStatus = ::android::hardware::tv::tuner::V1_0::FrontendModulationStatus;
143 using HidlFrontendScanAtsc3PlpInfo = ::android::hardware::tv::tuner::V1_0::FrontendScanAtsc3PlpInfo;
144 using HidlFrontendScanType = ::android::hardware::tv::tuner::V1_0::FrontendScanType;
145 using HidlFrontendStatusType = ::android::hardware::tv::tuner::V1_0::FrontendStatusType;
146 using HidlResult = ::android::hardware::tv::tuner::V1_0::Result;
147 using HidlFrontendAnalogAftFlag = ::android::hardware::tv::tuner::V1_1::FrontendAnalogAftFlag;
148 using HidlFrontendBandwidth = ::android::hardware::tv::tuner::V1_1::FrontendBandwidth;
149 using HidlFrontendCableTimeInterleaveMode =
150 ::android::hardware::tv::tuner::V1_1::FrontendCableTimeInterleaveMode;
151 using HidlFrontendDvbcBandwidth = ::android::hardware::tv::tuner::V1_1::FrontendDvbcBandwidth;
152 using HidlFrontendDtmbBandwidth = ::android::hardware::tv::tuner::V1_1::FrontendDtmbBandwidth;
153 using HidlFrontendDtmbCodeRate = ::android::hardware::tv::tuner::V1_1::FrontendDtmbCodeRate;
154 using HidlFrontendDtmbGuardInterval =
155 ::android::hardware::tv::tuner::V1_1::FrontendDtmbGuardInterval;
156 using HidlFrontendDtmbModulation = ::android::hardware::tv::tuner::V1_1::FrontendDtmbModulation;
157 using HidlFrontendDtmbTimeInterleaveMode =
158 ::android::hardware::tv::tuner::V1_1::FrontendDtmbTimeInterleaveMode;
159 using HidlFrontendDtmbTransmissionMode =
160 ::android::hardware::tv::tuner::V1_1::FrontendDtmbTransmissionMode;
161 using HidlFrontendDvbsScanType = ::android::hardware::tv::tuner::V1_1::FrontendDvbsScanType;
162 using HidlFrontendGuardInterval = ::android::hardware::tv::tuner::V1_1::FrontendGuardInterval;
163 using HidlFrontendInterleaveMode = ::android::hardware::tv::tuner::V1_1::FrontendInterleaveMode;
164 using HidlFrontendModulation = ::android::hardware::tv::tuner::V1_1::FrontendModulation;
165 using HidlFrontendRollOff = ::android::hardware::tv::tuner::V1_1::FrontendRollOff;
166 using HidlFrontendTransmissionMode = ::android::hardware::tv::tuner::V1_1::FrontendTransmissionMode;
167 using HidlFrontendSpectralInversion =
168 ::android::hardware::tv::tuner::V1_1::FrontendSpectralInversion;
169 using HidlFrontendStatusTypeExt1_1 = ::android::hardware::tv::tuner::V1_1::FrontendStatusTypeExt1_1;
170
171 using namespace std;
172
173 namespace aidl {
174 namespace android {
175 namespace media {
176 namespace tv {
177 namespace tuner {
178
TunerHidlFrontend(sp<HidlIFrontend> frontend,int id)179 TunerHidlFrontend::TunerHidlFrontend(sp<HidlIFrontend> frontend, int id) {
180 mFrontend = frontend;
181 mFrontend_1_1 = ::android::hardware::tv::tuner::V1_1::IFrontend::castFrom(mFrontend);
182 mId = id;
183 }
184
~TunerHidlFrontend()185 TunerHidlFrontend::~TunerHidlFrontend() {
186 mFrontend = nullptr;
187 mFrontend_1_1 = nullptr;
188 mId = -1;
189 }
190
setCallback(const shared_ptr<ITunerFrontendCallback> & tunerFrontendCallback)191 ::ndk::ScopedAStatus TunerHidlFrontend::setCallback(
192 const shared_ptr<ITunerFrontendCallback>& tunerFrontendCallback) {
193 if (mFrontend == nullptr) {
194 ALOGE("IFrontend is not initialized");
195 return ::ndk::ScopedAStatus::fromServiceSpecificError(
196 static_cast<int32_t>(Result::UNAVAILABLE));
197 }
198
199 if (tunerFrontendCallback == nullptr) {
200 return ::ndk::ScopedAStatus::fromServiceSpecificError(
201 static_cast<int32_t>(Result::INVALID_ARGUMENT));
202 }
203
204 sp<HidlIFrontendCallback> frontendCallback = new FrontendCallback(tunerFrontendCallback);
205 HidlResult status = mFrontend->setCallback(frontendCallback);
206 if (status == HidlResult::SUCCESS) {
207 return ::ndk::ScopedAStatus::ok();
208 }
209
210 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
211 }
212
tune(const FrontendSettings & settings)213 ::ndk::ScopedAStatus TunerHidlFrontend::tune(const FrontendSettings& settings) {
214 if (mFrontend == nullptr) {
215 ALOGE("IFrontend is not initialized");
216 return ::ndk::ScopedAStatus::fromServiceSpecificError(
217 static_cast<int32_t>(Result::UNAVAILABLE));
218 }
219
220 HidlResult status;
221 HidlFrontendSettings frontendSettings;
222 HidlFrontendSettingsExt1_1 frontendSettingsExt;
223 getHidlFrontendSettings(settings, frontendSettings, frontendSettingsExt);
224 if (mFrontend_1_1 != nullptr) {
225 status = mFrontend_1_1->tune_1_1(frontendSettings, frontendSettingsExt);
226 } else {
227 status = mFrontend->tune(frontendSettings);
228 }
229 if (status == HidlResult::SUCCESS) {
230 return ::ndk::ScopedAStatus::ok();
231 }
232
233 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
234 }
235
stopTune()236 ::ndk::ScopedAStatus TunerHidlFrontend::stopTune() {
237 if (mFrontend == nullptr) {
238 ALOGD("IFrontend is not initialized");
239 return ::ndk::ScopedAStatus::fromServiceSpecificError(
240 static_cast<int32_t>(Result::UNAVAILABLE));
241 }
242
243 HidlResult status = mFrontend->stopTune();
244 if (status == HidlResult::SUCCESS) {
245 return ::ndk::ScopedAStatus::ok();
246 }
247
248 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
249 }
250
scan(const FrontendSettings & settings,FrontendScanType frontendScanType)251 ::ndk::ScopedAStatus TunerHidlFrontend::scan(const FrontendSettings& settings,
252 FrontendScanType frontendScanType) {
253 if (mFrontend == nullptr) {
254 ALOGD("IFrontend is not initialized");
255 return ::ndk::ScopedAStatus::fromServiceSpecificError(
256 static_cast<int32_t>(Result::UNAVAILABLE));
257 }
258
259 HidlResult status;
260 HidlFrontendSettings frontendSettings;
261 HidlFrontendSettingsExt1_1 frontendSettingsExt;
262 getHidlFrontendSettings(settings, frontendSettings, frontendSettingsExt);
263 if (mFrontend_1_1 != nullptr) {
264 status = mFrontend_1_1->scan_1_1(frontendSettings,
265 static_cast<HidlFrontendScanType>(frontendScanType),
266 frontendSettingsExt);
267 } else {
268 status = mFrontend->scan(frontendSettings,
269 static_cast<HidlFrontendScanType>(frontendScanType));
270 }
271 if (status == HidlResult::SUCCESS) {
272 return ::ndk::ScopedAStatus::ok();
273 }
274
275 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
276 }
277
stopScan()278 ::ndk::ScopedAStatus TunerHidlFrontend::stopScan() {
279 if (mFrontend == nullptr) {
280 ALOGD("IFrontend is not initialized");
281 return ::ndk::ScopedAStatus::fromServiceSpecificError(
282 static_cast<int32_t>(Result::UNAVAILABLE));
283 }
284
285 HidlResult status = mFrontend->stopScan();
286 if (status == HidlResult::SUCCESS) {
287 return ::ndk::ScopedAStatus::ok();
288 }
289
290 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
291 }
292
setLnb(const shared_ptr<ITunerLnb> & lnb)293 ::ndk::ScopedAStatus TunerHidlFrontend::setLnb(const shared_ptr<ITunerLnb>& lnb) {
294 if (mFrontend == nullptr) {
295 ALOGD("IFrontend is not initialized");
296 return ::ndk::ScopedAStatus::fromServiceSpecificError(
297 static_cast<int32_t>(Result::UNAVAILABLE));
298 }
299
300 if (lnb == nullptr) {
301 return ::ndk::ScopedAStatus::fromServiceSpecificError(
302 static_cast<int32_t>(Result::INVALID_ARGUMENT));
303 }
304
305 HidlResult status = mFrontend->setLnb(static_cast<TunerHidlLnb*>(lnb.get())->getId());
306 if (status == HidlResult::SUCCESS) {
307 return ::ndk::ScopedAStatus::ok();
308 }
309
310 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
311 }
312
linkCiCamToFrontend(int32_t ciCamId,int32_t * _aidl_return)313 ::ndk::ScopedAStatus TunerHidlFrontend::linkCiCamToFrontend(int32_t ciCamId,
314 int32_t* _aidl_return) {
315 if (mFrontend_1_1 == nullptr) {
316 ALOGD("IFrontend_1_1 is not initialized");
317 return ::ndk::ScopedAStatus::fromServiceSpecificError(
318 static_cast<int32_t>(Result::UNAVAILABLE));
319 }
320
321 int ltsId;
322 HidlResult status;
323 mFrontend_1_1->linkCiCam(static_cast<uint32_t>(ciCamId), [&](HidlResult r, uint32_t id) {
324 status = r;
325 ltsId = id;
326 });
327
328 if (status == HidlResult::SUCCESS) {
329 *_aidl_return = ltsId;
330 return ::ndk::ScopedAStatus::ok();
331 }
332
333 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
334 }
335
unlinkCiCamToFrontend(int32_t ciCamId)336 ::ndk::ScopedAStatus TunerHidlFrontend::unlinkCiCamToFrontend(int32_t ciCamId) {
337 if (mFrontend_1_1 == nullptr) {
338 ALOGD("IFrontend_1_1 is not initialized");
339 return ::ndk::ScopedAStatus::fromServiceSpecificError(
340 static_cast<int32_t>(Result::UNAVAILABLE));
341 }
342
343 HidlResult status = mFrontend_1_1->unlinkCiCam(ciCamId);
344 if (status == HidlResult::SUCCESS) {
345 return ::ndk::ScopedAStatus::ok();
346 }
347
348 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
349 }
350
close()351 ::ndk::ScopedAStatus TunerHidlFrontend::close() {
352 if (mFrontend == nullptr) {
353 ALOGD("IFrontend is not initialized");
354 return ::ndk::ScopedAStatus::fromServiceSpecificError(
355 static_cast<int32_t>(Result::UNAVAILABLE));
356 }
357
358 TunerHidlService::getTunerService()->removeFrontend(this->ref<TunerHidlFrontend>());
359
360 HidlResult status = mFrontend->close();
361 mFrontend = nullptr;
362 mFrontend_1_1 = nullptr;
363
364 if (status != HidlResult::SUCCESS) {
365 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
366 }
367
368 return ::ndk::ScopedAStatus::ok();
369 }
370
getStatus(const vector<FrontendStatusType> & in_statusTypes,vector<FrontendStatus> * _aidl_return)371 ::ndk::ScopedAStatus TunerHidlFrontend::getStatus(const vector<FrontendStatusType>& in_statusTypes,
372 vector<FrontendStatus>* _aidl_return) {
373 if (mFrontend == nullptr) {
374 ALOGD("IFrontend is not initialized");
375 return ::ndk::ScopedAStatus::fromServiceSpecificError(
376 static_cast<int32_t>(Result::UNAVAILABLE));
377 }
378
379 HidlResult res;
380 vector<HidlFrontendStatus> status;
381 vector<HidlFrontendStatusExt1_1> statusExt;
382 vector<HidlFrontendStatusType> types;
383 vector<HidlFrontendStatusTypeExt1_1> typesExt;
384 for (auto s : in_statusTypes) {
385 if (static_cast<int32_t>(s) <=
386 static_cast<int32_t>(HidlFrontendStatusType::ATSC3_PLP_INFO)) {
387 types.push_back(static_cast<HidlFrontendStatusType>(s));
388 } else {
389 typesExt.push_back(static_cast<HidlFrontendStatusTypeExt1_1>(s));
390 }
391 }
392
393 mFrontend->getStatus(types, [&](HidlResult r, const hidl_vec<HidlFrontendStatus>& ss) {
394 res = r;
395 for (auto s : ss) {
396 status.push_back(s);
397 }
398 });
399 if (res != HidlResult::SUCCESS) {
400 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
401 }
402
403 if (mFrontend_1_1 != nullptr) {
404 mFrontend_1_1->getStatusExt1_1(
405 typesExt, [&](HidlResult r, const hidl_vec<HidlFrontendStatusExt1_1>& ss) {
406 res = r;
407 for (auto s : ss) {
408 statusExt.push_back(s);
409 }
410 });
411 if (res != HidlResult::SUCCESS) {
412 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
413 }
414 }
415
416 getAidlFrontendStatus(status, statusExt, *_aidl_return);
417 return ::ndk::ScopedAStatus::ok();
418 }
419
getFrontendId(int32_t * _aidl_return)420 ::ndk::ScopedAStatus TunerHidlFrontend::getFrontendId(int32_t* _aidl_return) {
421 *_aidl_return = mId;
422 return ::ndk::ScopedAStatus::ok();
423 }
424
getHardwareInfo(std::string * _aidl_return)425 ::ndk::ScopedAStatus TunerHidlFrontend::getHardwareInfo(std::string* _aidl_return) {
426 _aidl_return->clear();
427 return ::ndk::ScopedAStatus::fromServiceSpecificError(
428 static_cast<int32_t>(Result::UNAVAILABLE));
429 }
430
removeOutputPid(int32_t)431 ::ndk::ScopedAStatus TunerHidlFrontend::removeOutputPid(int32_t /* in_pid */) {
432 return ::ndk::ScopedAStatus::fromServiceSpecificError(
433 static_cast<int32_t>(Result::UNAVAILABLE));
434 }
435
getFrontendStatusReadiness(const std::vector<FrontendStatusType> &,std::vector<FrontendStatusReadiness> * _aidl_return)436 ::ndk::ScopedAStatus TunerHidlFrontend::getFrontendStatusReadiness(
437 const std::vector<FrontendStatusType>& /* in_statusTypes */,
438 std::vector<FrontendStatusReadiness>* _aidl_return) {
439 _aidl_return->clear();
440 return ::ndk::ScopedAStatus::fromServiceSpecificError(
441 static_cast<int32_t>(Result::UNAVAILABLE));
442 }
443
setLna(bool bEnable)444 void TunerHidlFrontend::setLna(bool bEnable) {
445 if (mFrontend == nullptr) {
446 ALOGD("IFrontend is not initialized");
447 return;
448 }
449
450 mFrontend->setLna(bEnable);
451 }
452
453 /////////////// FrontendCallback ///////////////////////
onEvent(HidlFrontendEventType frontendEventType)454 Return<void> TunerHidlFrontend::FrontendCallback::onEvent(HidlFrontendEventType frontendEventType) {
455 ALOGV("FrontendCallback::onEvent, type=%d", frontendEventType);
456 mTunerFrontendCallback->onEvent(static_cast<FrontendEventType>(frontendEventType));
457 return Void();
458 }
459
onScanMessage(HidlFrontendScanMessageType type,const HidlFrontendScanMessage & message)460 Return<void> TunerHidlFrontend::FrontendCallback::onScanMessage(
461 HidlFrontendScanMessageType type, const HidlFrontendScanMessage& message) {
462 ALOGV("FrontendCallback::onScanMessage, type=%d", type);
463 FrontendScanMessage scanMessage;
464 switch (type) {
465 case HidlFrontendScanMessageType::LOCKED: {
466 scanMessage.set<FrontendScanMessage::isLocked>(message.isLocked());
467 break;
468 }
469 case HidlFrontendScanMessageType::END: {
470 scanMessage.set<FrontendScanMessage::isEnd>(message.isEnd());
471 break;
472 }
473 case HidlFrontendScanMessageType::PROGRESS_PERCENT: {
474 scanMessage.set<FrontendScanMessage::progressPercent>(message.progressPercent());
475 break;
476 }
477 case HidlFrontendScanMessageType::FREQUENCY: {
478 const vector<uint32_t>& f = message.frequencies();
479 vector<int64_t> lf(begin(f), end(f));
480 scanMessage.set<FrontendScanMessage::frequencies>(lf);
481 break;
482 }
483 case HidlFrontendScanMessageType::SYMBOL_RATE: {
484 const vector<uint32_t>& s = message.symbolRates();
485 vector<int32_t> symbolRates(begin(s), end(s));
486 scanMessage.set<FrontendScanMessage::symbolRates>(symbolRates);
487 break;
488 }
489 case HidlFrontendScanMessageType::HIERARCHY: {
490 scanMessage.set<FrontendScanMessage::hierarchy>(
491 static_cast<FrontendDvbtHierarchy>(message.hierarchy()));
492 break;
493 }
494 case HidlFrontendScanMessageType::ANALOG_TYPE: {
495 scanMessage.set<FrontendScanMessage::analogType>(
496 static_cast<FrontendAnalogType>(message.analogType()));
497 break;
498 }
499 case HidlFrontendScanMessageType::PLP_IDS: {
500 const vector<uint8_t>& p = message.plpIds();
501 vector<int32_t> plpIds(begin(p), end(p));
502 scanMessage.set<FrontendScanMessage::plpIds>(plpIds);
503 break;
504 }
505 case HidlFrontendScanMessageType::GROUP_IDS: {
506 const vector<uint8_t>& g = message.groupIds();
507 vector<int32_t> groupIds(begin(g), end(g));
508 scanMessage.set<FrontendScanMessage::groupIds>(groupIds);
509 break;
510 }
511 case HidlFrontendScanMessageType::INPUT_STREAM_IDS: {
512 const vector<uint16_t>& i = message.inputStreamIds();
513 vector<int32_t> streamIds(begin(i), end(i));
514 scanMessage.set<FrontendScanMessage::inputStreamIds>(streamIds);
515 break;
516 }
517 case HidlFrontendScanMessageType::STANDARD: {
518 const HidlFrontendScanMessage::Standard& std = message.std();
519 FrontendScanMessageStandard standard;
520 if (std.getDiscriminator() == HidlFrontendScanMessage::Standard::hidl_discriminator::sStd) {
521 standard.set<FrontendScanMessageStandard::sStd>(
522 static_cast<FrontendDvbsStandard>(std.sStd()));
523 } else if (std.getDiscriminator() ==
524 HidlFrontendScanMessage::Standard::hidl_discriminator::tStd) {
525 standard.set<FrontendScanMessageStandard::tStd>(
526 static_cast<FrontendDvbtStandard>(std.tStd()));
527 } else if (std.getDiscriminator() ==
528 HidlFrontendScanMessage::Standard::hidl_discriminator::sifStd) {
529 standard.set<FrontendScanMessageStandard::sifStd>(
530 static_cast<FrontendAnalogSifStandard>(std.sifStd()));
531 }
532 scanMessage.set<FrontendScanMessage::std>(standard);
533 break;
534 }
535 case HidlFrontendScanMessageType::ATSC3_PLP_INFO: {
536 const vector<HidlFrontendScanAtsc3PlpInfo>& plpInfos = message.atsc3PlpInfos();
537 vector<FrontendScanAtsc3PlpInfo> tunerPlpInfos;
538 for (int i = 0; i < plpInfos.size(); i++) {
539 FrontendScanAtsc3PlpInfo plpInfo{
540 .plpId = static_cast<int32_t>(plpInfos[i].plpId),
541 .bLlsFlag = plpInfos[i].bLlsFlag,
542 };
543 tunerPlpInfos.push_back(plpInfo);
544 }
545 scanMessage.set<FrontendScanMessage::atsc3PlpInfos>(tunerPlpInfos);
546 break;
547 }
548 default:
549 break;
550 }
551 mTunerFrontendCallback->onScanMessage(static_cast<FrontendScanMessageType>(type), scanMessage);
552 return Void();
553 }
554
onScanMessageExt1_1(HidlFrontendScanMessageTypeExt1_1 type,const HidlFrontendScanMessageExt1_1 & message)555 Return<void> TunerHidlFrontend::FrontendCallback::onScanMessageExt1_1(
556 HidlFrontendScanMessageTypeExt1_1 type, const HidlFrontendScanMessageExt1_1& message) {
557 ALOGV("onScanMessageExt1_1::onScanMessage, type=%d", type);
558 FrontendScanMessage scanMessage;
559 switch (type) {
560 case HidlFrontendScanMessageTypeExt1_1::MODULATION: {
561 HidlFrontendModulation m = message.modulation();
562 FrontendModulation modulation;
563 switch (m.getDiscriminator()) {
564 case HidlFrontendModulation::hidl_discriminator::dvbc: {
565 modulation.set<FrontendModulation::dvbc>(static_cast<FrontendDvbcModulation>(m.dvbc()));
566 break;
567 }
568 case HidlFrontendModulation::hidl_discriminator::dvbt: {
569 modulation.set<FrontendModulation::dvbt>(
570 static_cast<FrontendDvbtConstellation>(m.dvbt()));
571 break;
572 }
573 case HidlFrontendModulation::hidl_discriminator::dvbs: {
574 modulation.set<FrontendModulation::dvbs>(static_cast<FrontendDvbsModulation>(m.dvbs()));
575 break;
576 }
577 case HidlFrontendModulation::hidl_discriminator::isdbs: {
578 modulation.set<FrontendModulation::isdbs>(
579 static_cast<FrontendIsdbsModulation>(m.isdbs()));
580 break;
581 }
582 case HidlFrontendModulation::hidl_discriminator::isdbs3: {
583 modulation.set<FrontendModulation::isdbs3>(
584 static_cast<FrontendIsdbs3Modulation>(m.isdbs3()));
585 break;
586 }
587 case HidlFrontendModulation::hidl_discriminator::isdbt: {
588 modulation.set<FrontendModulation::isdbt>(
589 static_cast<FrontendIsdbtModulation>(m.isdbt()));
590 break;
591 }
592 case HidlFrontendModulation::hidl_discriminator::atsc: {
593 modulation.set<FrontendModulation::atsc>(static_cast<FrontendAtscModulation>(m.atsc()));
594 break;
595 }
596 case HidlFrontendModulation::hidl_discriminator::atsc3: {
597 modulation.set<FrontendModulation::atsc3>(
598 static_cast<FrontendAtsc3Modulation>(m.atsc3()));
599 break;
600 }
601 case HidlFrontendModulation::hidl_discriminator::dtmb: {
602 modulation.set<FrontendModulation::dtmb>(static_cast<FrontendDtmbModulation>(m.dtmb()));
603 break;
604 }
605 }
606 scanMessage.set<FrontendScanMessage::modulation>(modulation);
607 break;
608 }
609 case HidlFrontendScanMessageTypeExt1_1::DVBC_ANNEX: {
610 scanMessage.set<FrontendScanMessage::annex>(
611 static_cast<FrontendDvbcAnnex>(message.annex()));
612 break;
613 }
614 case HidlFrontendScanMessageTypeExt1_1::HIGH_PRIORITY: {
615 scanMessage.set<FrontendScanMessage::isHighPriority>(message.isHighPriority());
616 break;
617 }
618 default: {
619 break;
620 }
621 }
622 mTunerFrontendCallback->onScanMessage(static_cast<FrontendScanMessageType>(type), scanMessage);
623 return Void();
624 }
625
626 /////////////// TunerHidlFrontend Helper Methods ///////////////////////
getAidlFrontendStatus(const vector<HidlFrontendStatus> & hidlStatus,const vector<HidlFrontendStatusExt1_1> & hidlStatusExt,vector<FrontendStatus> & aidlStatus)627 void TunerHidlFrontend::getAidlFrontendStatus(const vector<HidlFrontendStatus>& hidlStatus,
628 const vector<HidlFrontendStatusExt1_1>& hidlStatusExt,
629 vector<FrontendStatus>& aidlStatus) {
630 for (HidlFrontendStatus s : hidlStatus) {
631 FrontendStatus status;
632 switch (s.getDiscriminator()) {
633 case HidlFrontendStatus::hidl_discriminator::isDemodLocked: {
634 status.set<FrontendStatus::isDemodLocked>(s.isDemodLocked());
635 aidlStatus.push_back(status);
636 break;
637 }
638 case HidlFrontendStatus::hidl_discriminator::snr: {
639 status.set<FrontendStatus::snr>((int)s.snr());
640 aidlStatus.push_back(status);
641 break;
642 }
643 case HidlFrontendStatus::hidl_discriminator::ber: {
644 status.set<FrontendStatus::ber>((int)s.ber());
645 aidlStatus.push_back(status);
646 break;
647 }
648 case HidlFrontendStatus::hidl_discriminator::per: {
649 status.set<FrontendStatus::per>((int)s.per());
650 aidlStatus.push_back(status);
651 break;
652 }
653 case HidlFrontendStatus::hidl_discriminator::preBer: {
654 status.set<FrontendStatus::preBer>((int)s.preBer());
655 aidlStatus.push_back(status);
656 break;
657 }
658 case HidlFrontendStatus::hidl_discriminator::signalQuality: {
659 status.set<FrontendStatus::signalQuality>((int)s.signalQuality());
660 aidlStatus.push_back(status);
661 break;
662 }
663 case HidlFrontendStatus::hidl_discriminator::signalStrength: {
664 status.set<FrontendStatus::signalStrength>((int)s.signalStrength());
665 aidlStatus.push_back(status);
666 break;
667 }
668 case HidlFrontendStatus::hidl_discriminator::symbolRate: {
669 status.set<FrontendStatus::symbolRate>((int)s.symbolRate());
670 aidlStatus.push_back(status);
671 break;
672 }
673 case HidlFrontendStatus::hidl_discriminator::innerFec: {
674 status.set<FrontendStatus::innerFec>(static_cast<FrontendInnerFec>(s.innerFec()));
675 aidlStatus.push_back(status);
676 break;
677 }
678 case HidlFrontendStatus::hidl_discriminator::modulation: {
679 FrontendModulationStatus modulationStatus;
680 switch (s.modulation().getDiscriminator()) {
681 case HidlFrontendModulationStatus::hidl_discriminator::dvbc:
682 modulationStatus.set<FrontendModulationStatus::dvbc>(
683 static_cast<FrontendDvbcModulation>(s.modulation().dvbc()));
684 break;
685 case HidlFrontendModulationStatus::hidl_discriminator::dvbs:
686 modulationStatus.set<FrontendModulationStatus::dvbs>(
687 static_cast<FrontendDvbsModulation>(s.modulation().dvbs()));
688 break;
689 case HidlFrontendModulationStatus::hidl_discriminator::isdbs:
690 modulationStatus.set<FrontendModulationStatus::isdbs>(
691 static_cast<FrontendIsdbsModulation>(s.modulation().isdbs()));
692 break;
693 case HidlFrontendModulationStatus::hidl_discriminator::isdbs3:
694 modulationStatus.set<FrontendModulationStatus::isdbs3>(
695 static_cast<FrontendIsdbs3Modulation>(s.modulation().isdbs3()));
696 break;
697 case HidlFrontendModulationStatus::hidl_discriminator::isdbt:
698 modulationStatus.set<FrontendModulationStatus::isdbt>(
699 static_cast<FrontendIsdbtModulation>(s.modulation().isdbt()));
700 break;
701 }
702 status.set<FrontendStatus::modulationStatus>(modulationStatus);
703 aidlStatus.push_back(status);
704 break;
705 }
706 case HidlFrontendStatus::hidl_discriminator::inversion: {
707 status.set<FrontendStatus::inversion>(
708 static_cast<FrontendSpectralInversion>(s.inversion()));
709 aidlStatus.push_back(status);
710 break;
711 }
712 case HidlFrontendStatus::hidl_discriminator::lnbVoltage: {
713 status.set<FrontendStatus::lnbVoltage>(static_cast<LnbVoltage>(s.lnbVoltage()));
714 aidlStatus.push_back(status);
715 break;
716 }
717 case HidlFrontendStatus::hidl_discriminator::plpId: {
718 status.set<FrontendStatus::plpId>((int32_t)s.plpId());
719 aidlStatus.push_back(status);
720 break;
721 }
722 case HidlFrontendStatus::hidl_discriminator::isEWBS: {
723 status.set<FrontendStatus::isEWBS>(s.isEWBS());
724 aidlStatus.push_back(status);
725 break;
726 }
727 case HidlFrontendStatus::hidl_discriminator::agc: {
728 status.set<FrontendStatus::agc>((int32_t)s.agc());
729 aidlStatus.push_back(status);
730 break;
731 }
732 case HidlFrontendStatus::hidl_discriminator::isLnaOn: {
733 status.set<FrontendStatus::isLnaOn>(s.isLnaOn());
734 aidlStatus.push_back(status);
735 break;
736 }
737 case HidlFrontendStatus::hidl_discriminator::isLayerError: {
738 vector<bool> e(s.isLayerError().begin(), s.isLayerError().end());
739 status.set<FrontendStatus::isLayerError>(e);
740 aidlStatus.push_back(status);
741 break;
742 }
743 case HidlFrontendStatus::hidl_discriminator::mer: {
744 status.set<FrontendStatus::mer>(static_cast<int32_t>(s.mer()));
745 aidlStatus.push_back(status);
746 break;
747 }
748 case HidlFrontendStatus::hidl_discriminator::freqOffset: {
749 status.set<FrontendStatus::freqOffset>(static_cast<int64_t>(s.freqOffset()));
750 aidlStatus.push_back(status);
751 break;
752 }
753 case HidlFrontendStatus::hidl_discriminator::hierarchy: {
754 status.set<FrontendStatus::hierarchy>(
755 static_cast<FrontendDvbtHierarchy>(s.hierarchy()));
756 aidlStatus.push_back(status);
757 break;
758 }
759 case HidlFrontendStatus::hidl_discriminator::isRfLocked: {
760 status.set<FrontendStatus::isRfLocked>(s.isRfLocked());
761 aidlStatus.push_back(status);
762 break;
763 }
764 case HidlFrontendStatus::hidl_discriminator::plpInfo: {
765 vector<FrontendStatusAtsc3PlpInfo> info;
766 for (auto i : s.plpInfo()) {
767 info.push_back({
768 .plpId = static_cast<int32_t>(i.plpId),
769 .isLocked = i.isLocked,
770 .uec = static_cast<int32_t>(i.uec),
771 });
772 }
773 status.set<FrontendStatus::plpInfo>(info);
774 aidlStatus.push_back(status);
775 break;
776 }
777 }
778 }
779
780 for (HidlFrontendStatusExt1_1 s : hidlStatusExt) {
781 FrontendStatus status;
782 switch (s.getDiscriminator()) {
783 case HidlFrontendStatusExt1_1::hidl_discriminator::modulations: {
784 vector<FrontendModulation> aidlMod;
785 for (auto m : s.modulations()) {
786 switch (m.getDiscriminator()) {
787 case HidlFrontendModulation::hidl_discriminator::dvbc:
788 aidlMod.push_back(static_cast<FrontendDvbcModulation>(m.dvbc()));
789 break;
790 case HidlFrontendModulation::hidl_discriminator::dvbs:
791 aidlMod.push_back(static_cast<FrontendDvbsModulation>(m.dvbs()));
792 break;
793 case HidlFrontendModulation::hidl_discriminator::dvbt:
794 aidlMod.push_back(static_cast<FrontendDvbtConstellation>(m.dvbt()));
795 break;
796 case HidlFrontendModulation::hidl_discriminator::isdbs:
797 aidlMod.push_back(static_cast<FrontendIsdbsModulation>(m.isdbs()));
798 break;
799 case HidlFrontendModulation::hidl_discriminator::isdbs3:
800 aidlMod.push_back(static_cast<FrontendIsdbs3Modulation>(m.isdbs3()));
801 break;
802 case HidlFrontendModulation::hidl_discriminator::isdbt:
803 aidlMod.push_back(static_cast<FrontendIsdbtModulation>(m.isdbt()));
804 break;
805 case HidlFrontendModulation::hidl_discriminator::atsc:
806 aidlMod.push_back(static_cast<FrontendAtscModulation>(m.atsc()));
807 break;
808 case HidlFrontendModulation::hidl_discriminator::atsc3:
809 aidlMod.push_back(static_cast<FrontendAtsc3Modulation>(m.atsc3()));
810 break;
811 case HidlFrontendModulation::hidl_discriminator::dtmb:
812 aidlMod.push_back(static_cast<FrontendDtmbModulation>(m.dtmb()));
813 break;
814 }
815 }
816 status.set<FrontendStatus::modulations>(aidlMod);
817 aidlStatus.push_back(status);
818 break;
819 }
820 case HidlFrontendStatusExt1_1::hidl_discriminator::bers: {
821 vector<int> b(s.bers().begin(), s.bers().end());
822 status.set<FrontendStatus::bers>(b);
823 aidlStatus.push_back(status);
824 break;
825 }
826 case HidlFrontendStatusExt1_1::hidl_discriminator::codeRates: {
827 vector<FrontendInnerFec> codeRates;
828 for (auto c : s.codeRates()) {
829 codeRates.push_back(static_cast<FrontendInnerFec>(c));
830 }
831 status.set<FrontendStatus::codeRates>(codeRates);
832 aidlStatus.push_back(status);
833 break;
834 }
835 case HidlFrontendStatusExt1_1::hidl_discriminator::bandwidth: {
836 FrontendBandwidth bandwidth;
837 switch (s.bandwidth().getDiscriminator()) {
838 case HidlFrontendBandwidth::hidl_discriminator::atsc3:
839 bandwidth.set<FrontendBandwidth::atsc3>(
840 static_cast<FrontendAtsc3Bandwidth>(s.bandwidth().atsc3()));
841 break;
842 case HidlFrontendBandwidth::hidl_discriminator::dvbc:
843 bandwidth.set<FrontendBandwidth::dvbc>(
844 static_cast<FrontendDvbcBandwidth>(s.bandwidth().dvbc()));
845 break;
846 case HidlFrontendBandwidth::hidl_discriminator::dvbt:
847 bandwidth.set<FrontendBandwidth::dvbt>(
848 static_cast<FrontendDvbtBandwidth>(s.bandwidth().dvbt()));
849 break;
850 case HidlFrontendBandwidth::hidl_discriminator::isdbt:
851 bandwidth.set<FrontendBandwidth::isdbt>(
852 static_cast<FrontendIsdbtBandwidth>(s.bandwidth().isdbt()));
853 break;
854 case HidlFrontendBandwidth::hidl_discriminator::dtmb:
855 bandwidth.set<FrontendBandwidth::dtmb>(
856 static_cast<FrontendDtmbBandwidth>(s.bandwidth().dtmb()));
857 break;
858 }
859 status.set<FrontendStatus::bandwidth>(bandwidth);
860 aidlStatus.push_back(status);
861 break;
862 }
863 case HidlFrontendStatusExt1_1::hidl_discriminator::interval: {
864 FrontendGuardInterval interval;
865 switch (s.interval().getDiscriminator()) {
866 case HidlFrontendGuardInterval::hidl_discriminator::dvbt:
867 interval.set<FrontendGuardInterval::dvbt>(
868 static_cast<FrontendDvbtGuardInterval>(s.interval().dvbt()));
869 break;
870 case HidlFrontendGuardInterval::hidl_discriminator::isdbt:
871 interval.set<FrontendGuardInterval::isdbt>(
872 static_cast<FrontendIsdbtGuardInterval>(s.interval().isdbt()));
873 break;
874 case HidlFrontendGuardInterval::hidl_discriminator::dtmb:
875 interval.set<FrontendGuardInterval::dtmb>(
876 static_cast<FrontendDtmbGuardInterval>(s.interval().dtmb()));
877 break;
878 }
879 status.set<FrontendStatus::interval>(interval);
880 aidlStatus.push_back(status);
881 break;
882 }
883 case HidlFrontendStatusExt1_1::hidl_discriminator::transmissionMode: {
884 FrontendTransmissionMode transmissionMode;
885 switch (s.transmissionMode().getDiscriminator()) {
886 case HidlFrontendTransmissionMode::hidl_discriminator::dvbt:
887 transmissionMode.set<FrontendTransmissionMode::dvbt>(
888 static_cast<FrontendDvbtTransmissionMode>(s.transmissionMode().dvbt()));
889 break;
890 case HidlFrontendTransmissionMode::hidl_discriminator::isdbt:
891 transmissionMode.set<FrontendTransmissionMode::isdbt>(
892 static_cast<FrontendIsdbtMode>(s.transmissionMode().isdbt()));
893 break;
894 case HidlFrontendTransmissionMode::hidl_discriminator::dtmb:
895 transmissionMode.set<FrontendTransmissionMode::dtmb>(
896 static_cast<FrontendDtmbTransmissionMode>(s.transmissionMode().dtmb()));
897 break;
898 }
899 status.set<FrontendStatus::transmissionMode>(transmissionMode);
900 aidlStatus.push_back(status);
901 break;
902 }
903 case HidlFrontendStatusExt1_1::hidl_discriminator::uec: {
904 status.set<FrontendStatus::uec>(static_cast<int32_t>(s.uec()));
905 aidlStatus.push_back(status);
906 break;
907 }
908 case HidlFrontendStatusExt1_1::hidl_discriminator::systemId: {
909 status.set<FrontendStatus::systemId>(static_cast<int32_t>(s.systemId()));
910 aidlStatus.push_back(status);
911 break;
912 }
913 case HidlFrontendStatusExt1_1::hidl_discriminator::interleaving: {
914 vector<FrontendInterleaveMode> aidlInter;
915 for (auto i : s.interleaving()) {
916 FrontendInterleaveMode leaveMode;
917 switch (i.getDiscriminator()) {
918 case HidlFrontendInterleaveMode::hidl_discriminator::atsc3:
919 leaveMode.set<FrontendInterleaveMode::atsc3>(
920 static_cast<FrontendAtsc3TimeInterleaveMode>(i.atsc3()));
921 break;
922 case HidlFrontendInterleaveMode::hidl_discriminator::dvbc:
923 leaveMode.set<FrontendInterleaveMode::dvbc>(
924 static_cast<FrontendCableTimeInterleaveMode>(i.dvbc()));
925 break;
926 case HidlFrontendInterleaveMode::hidl_discriminator::dtmb:
927 leaveMode.set<FrontendInterleaveMode::dtmb>(
928 static_cast<FrontendDtmbTimeInterleaveMode>(i.dtmb()));
929 break;
930 }
931 aidlInter.push_back(leaveMode);
932 }
933 status.set<FrontendStatus::interleaving>(aidlInter);
934 aidlStatus.push_back(status);
935 break;
936 }
937 case HidlFrontendStatusExt1_1::hidl_discriminator::isdbtSegment: {
938 const vector<uint8_t>& seg = s.isdbtSegment();
939 vector<int32_t> i(seg.begin(), seg.end());
940 status.set<FrontendStatus::isdbtSegment>(i);
941 aidlStatus.push_back(status);
942 break;
943 }
944 case HidlFrontendStatusExt1_1::hidl_discriminator::tsDataRate: {
945 vector<int32_t> ts(s.tsDataRate().begin(), s.tsDataRate().end());
946 status.set<FrontendStatus::tsDataRate>(ts);
947 aidlStatus.push_back(status);
948 break;
949 }
950 case HidlFrontendStatusExt1_1::hidl_discriminator::rollOff: {
951 FrontendRollOff rollOff;
952 switch (s.rollOff().getDiscriminator()) {
953 case HidlFrontendRollOff::hidl_discriminator::dvbs:
954 rollOff.set<FrontendRollOff::dvbs>(
955 static_cast<FrontendDvbsRolloff>(s.rollOff().dvbs()));
956 break;
957 case HidlFrontendRollOff::hidl_discriminator::isdbs:
958 rollOff.set<FrontendRollOff::isdbs>(
959 static_cast<FrontendIsdbsRolloff>(s.rollOff().isdbs()));
960 break;
961 case HidlFrontendRollOff::hidl_discriminator::isdbs3:
962 rollOff.set<FrontendRollOff::isdbs3>(
963 static_cast<FrontendIsdbs3Rolloff>(s.rollOff().isdbs3()));
964 break;
965 }
966 status.set<FrontendStatus::rollOff>(rollOff);
967 aidlStatus.push_back(status);
968 break;
969 }
970 case HidlFrontendStatusExt1_1::hidl_discriminator::isMiso: {
971 status.set<FrontendStatus::isMiso>(s.isMiso());
972 aidlStatus.push_back(status);
973 break;
974 }
975 case HidlFrontendStatusExt1_1::hidl_discriminator::isLinear: {
976 status.set<FrontendStatus::isLinear>(s.isLinear());
977 aidlStatus.push_back(status);
978 break;
979 }
980 case HidlFrontendStatusExt1_1::hidl_discriminator::isShortFrames: {
981 status.set<FrontendStatus::isShortFrames>(s.isShortFrames());
982 aidlStatus.push_back(status);
983 break;
984 }
985 }
986 }
987 }
988
getAtsc3PlpSettings(const FrontendAtsc3Settings & settings)989 hidl_vec<HidlFrontendAtsc3PlpSettings> TunerHidlFrontend::getAtsc3PlpSettings(
990 const FrontendAtsc3Settings& settings) {
991 int len = settings.plpSettings.size();
992 hidl_vec<HidlFrontendAtsc3PlpSettings> plps = hidl_vec<HidlFrontendAtsc3PlpSettings>(len);
993 // parse PLP settings
994 for (int i = 0; i < len; i++) {
995 uint8_t plpId = static_cast<uint8_t>(settings.plpSettings[i].plpId);
996 HidlFrontendAtsc3Modulation modulation =
997 static_cast<HidlFrontendAtsc3Modulation>(settings.plpSettings[i].modulation);
998 HidlFrontendAtsc3TimeInterleaveMode interleaveMode =
999 static_cast<HidlFrontendAtsc3TimeInterleaveMode>(
1000 settings.plpSettings[i].interleaveMode);
1001 HidlFrontendAtsc3CodeRate codeRate =
1002 static_cast<HidlFrontendAtsc3CodeRate>(settings.plpSettings[i].codeRate);
1003 HidlFrontendAtsc3Fec fec = static_cast<HidlFrontendAtsc3Fec>(settings.plpSettings[i].fec);
1004 HidlFrontendAtsc3PlpSettings frontendAtsc3PlpSettings{
1005 .plpId = plpId,
1006 .modulation = modulation,
1007 .interleaveMode = interleaveMode,
1008 .codeRate = codeRate,
1009 .fec = fec,
1010 };
1011 plps[i] = frontendAtsc3PlpSettings;
1012 }
1013 return plps;
1014 }
1015
getDvbsCodeRate(const FrontendDvbsCodeRate & codeRate)1016 HidlFrontendDvbsCodeRate TunerHidlFrontend::getDvbsCodeRate(const FrontendDvbsCodeRate& codeRate) {
1017 HidlFrontendInnerFec innerFec = static_cast<HidlFrontendInnerFec>(codeRate.fec);
1018 bool isLinear = codeRate.isLinear;
1019 bool isShortFrames = codeRate.isShortFrames;
1020 uint32_t bitsPer1000Symbol = static_cast<uint32_t>(codeRate.bitsPer1000Symbol);
1021 HidlFrontendDvbsCodeRate coderate{
1022 .fec = innerFec,
1023 .isLinear = isLinear,
1024 .isShortFrames = isShortFrames,
1025 .bitsPer1000Symbol = bitsPer1000Symbol,
1026 };
1027 return coderate;
1028 }
1029
getHidlFrontendSettings(const FrontendSettings & aidlSettings,HidlFrontendSettings & settings,HidlFrontendSettingsExt1_1 & settingsExt)1030 void TunerHidlFrontend::getHidlFrontendSettings(const FrontendSettings& aidlSettings,
1031 HidlFrontendSettings& settings,
1032 HidlFrontendSettingsExt1_1& settingsExt) {
1033 switch (aidlSettings.getTag()) {
1034 case FrontendSettings::analog: {
1035 const FrontendAnalogSettings& analog = aidlSettings.get<FrontendSettings::analog>();
1036 settings.analog({
1037 .frequency = static_cast<uint32_t>(analog.frequency),
1038 .type = static_cast<HidlFrontendAnalogType>(analog.type),
1039 .sifStandard = static_cast<HidlFrontendAnalogSifStandard>(analog.sifStandard),
1040 });
1041 settingsExt.settingExt.analog({
1042 .aftFlag = static_cast<HidlFrontendAnalogAftFlag>(analog.aftFlag),
1043 });
1044 settingsExt.endFrequency = static_cast<uint32_t>(analog.endFrequency);
1045 settingsExt.inversion = static_cast<HidlFrontendSpectralInversion>(analog.inversion);
1046 break;
1047 }
1048 case FrontendSettings::atsc: {
1049 const FrontendAtscSettings& atsc = aidlSettings.get<FrontendSettings::atsc>();
1050 settings.atsc({
1051 .frequency = static_cast<uint32_t>(atsc.frequency),
1052 .modulation = static_cast<HidlFrontendAtscModulation>(atsc.modulation),
1053 });
1054 settingsExt.endFrequency = static_cast<uint32_t>(atsc.endFrequency);
1055 settingsExt.inversion = static_cast<HidlFrontendSpectralInversion>(atsc.inversion);
1056 settingsExt.settingExt.noinit();
1057 break;
1058 }
1059 case FrontendSettings::atsc3: {
1060 const FrontendAtsc3Settings& atsc3 = aidlSettings.get<FrontendSettings::atsc3>();
1061 settings.atsc3({
1062 .frequency = static_cast<uint32_t>(atsc3.frequency),
1063 .bandwidth = static_cast<HidlFrontendAtsc3Bandwidth>(atsc3.bandwidth),
1064 .demodOutputFormat =
1065 static_cast<HidlFrontendAtsc3DemodOutputFormat>(atsc3.demodOutputFormat),
1066 .plpSettings = getAtsc3PlpSettings(atsc3),
1067 });
1068 settingsExt.endFrequency = static_cast<uint32_t>(atsc3.endFrequency);
1069 settingsExt.inversion = static_cast<HidlFrontendSpectralInversion>(atsc3.inversion);
1070 settingsExt.settingExt.noinit();
1071 break;
1072 }
1073 case FrontendSettings::dvbc: {
1074 const FrontendDvbcSettings& dvbc = aidlSettings.get<FrontendSettings::dvbc>();
1075 settings.dvbc({
1076 .frequency = static_cast<uint32_t>(dvbc.frequency),
1077 .modulation = static_cast<HidlFrontendDvbcModulation>(dvbc.modulation),
1078 .fec = static_cast<HidlFrontendInnerFec>(dvbc.fec),
1079 .symbolRate = static_cast<uint32_t>(dvbc.symbolRate),
1080 .outerFec = static_cast<HidlFrontendDvbcOuterFec>(dvbc.outerFec),
1081 .annex = static_cast<HidlFrontendDvbcAnnex>(dvbc.annex),
1082 .spectralInversion = static_cast<HidlFrontendDvbcSpectralInversion>(dvbc.inversion),
1083 });
1084 settingsExt.settingExt.dvbc({
1085 .interleaveMode =
1086 static_cast<HidlFrontendCableTimeInterleaveMode>(dvbc.interleaveMode),
1087 .bandwidth = static_cast<HidlFrontendDvbcBandwidth>(dvbc.bandwidth),
1088 });
1089 settingsExt.endFrequency = static_cast<uint32_t>(dvbc.endFrequency);
1090 settingsExt.inversion = static_cast<HidlFrontendSpectralInversion>(dvbc.inversion);
1091 break;
1092 }
1093 case FrontendSettings::dvbs: {
1094 const FrontendDvbsSettings& dvbs = aidlSettings.get<FrontendSettings::dvbs>();
1095 settings.dvbs({
1096 .frequency = static_cast<uint32_t>(dvbs.frequency),
1097 .modulation = static_cast<HidlFrontendDvbsModulation>(dvbs.modulation),
1098 .coderate = getDvbsCodeRate(dvbs.coderate),
1099 .symbolRate = static_cast<uint32_t>(dvbs.symbolRate),
1100 .rolloff = static_cast<HidlFrontendDvbsRolloff>(dvbs.rolloff),
1101 .pilot = static_cast<HidlFrontendDvbsPilot>(dvbs.pilot),
1102 .inputStreamId = static_cast<uint32_t>(dvbs.inputStreamId),
1103 .standard = static_cast<HidlFrontendDvbsStandard>(dvbs.standard),
1104 .vcmMode = static_cast<HidlFrontendDvbsVcmMode>(dvbs.vcmMode),
1105 });
1106 settingsExt.settingExt.dvbs({
1107 .scanType = static_cast<HidlFrontendDvbsScanType>(dvbs.scanType),
1108 .isDiseqcRxMessage = dvbs.isDiseqcRxMessage,
1109 });
1110 settingsExt.endFrequency = static_cast<uint32_t>(dvbs.endFrequency);
1111 settingsExt.inversion = static_cast<HidlFrontendSpectralInversion>(dvbs.inversion);
1112 break;
1113 }
1114 case FrontendSettings::dvbt: {
1115 const FrontendDvbtSettings& dvbt = aidlSettings.get<FrontendSettings::dvbt>();
1116 settings.dvbt({
1117 .frequency = static_cast<uint32_t>(dvbt.frequency),
1118 .transmissionMode =
1119 static_cast<HidlFrontendDvbtTransmissionMode>(dvbt.transmissionMode),
1120 .bandwidth = static_cast<HidlFrontendDvbtBandwidth>(dvbt.bandwidth),
1121 .constellation = static_cast<HidlFrontendDvbtConstellation>(dvbt.constellation),
1122 .hierarchy = static_cast<HidlFrontendDvbtHierarchy>(dvbt.hierarchy),
1123 .hpCoderate = static_cast<HidlFrontendDvbtCoderate>(dvbt.hpCoderate),
1124 .lpCoderate = static_cast<HidlFrontendDvbtCoderate>(dvbt.lpCoderate),
1125 .guardInterval = static_cast<HidlFrontendDvbtGuardInterval>(dvbt.guardInterval),
1126 .isHighPriority = dvbt.isHighPriority,
1127 .standard = static_cast<HidlFrontendDvbtStandard>(dvbt.standard),
1128 .isMiso = dvbt.isMiso,
1129 .plpMode = static_cast<HidlFrontendDvbtPlpMode>(dvbt.plpMode),
1130 .plpId = static_cast<uint8_t>(dvbt.plpId),
1131 .plpGroupId = static_cast<uint8_t>(dvbt.plpGroupId),
1132 });
1133 settingsExt.settingExt.dvbt({
1134 .constellation = static_cast<
1135 ::android::hardware::tv::tuner::V1_1::FrontendDvbtConstellation>(
1136 dvbt.constellation),
1137 .transmissionMode = static_cast<
1138 ::android::hardware::tv::tuner::V1_1::FrontendDvbtTransmissionMode>(
1139 dvbt.transmissionMode),
1140 });
1141 settingsExt.endFrequency = static_cast<uint32_t>(dvbt.endFrequency);
1142 settingsExt.inversion = static_cast<HidlFrontendSpectralInversion>(dvbt.inversion);
1143 break;
1144 }
1145 case FrontendSettings::isdbs: {
1146 const FrontendIsdbsSettings& isdbs = aidlSettings.get<FrontendSettings::isdbs>();
1147 settings.isdbs({
1148 .frequency = static_cast<uint32_t>(isdbs.frequency),
1149 .streamId = static_cast<uint16_t>(isdbs.streamId),
1150 .streamIdType = static_cast<HidlFrontendIsdbsStreamIdType>(isdbs.streamIdType),
1151 .modulation = static_cast<HidlFrontendIsdbsModulation>(isdbs.modulation),
1152 .coderate = static_cast<HidlFrontendIsdbsCoderate>(isdbs.coderate),
1153 .symbolRate = static_cast<uint32_t>(isdbs.symbolRate),
1154 .rolloff = static_cast<HidlFrontendIsdbsRolloff>(isdbs.rolloff),
1155 });
1156 settingsExt.endFrequency = static_cast<uint32_t>(isdbs.endFrequency);
1157 settingsExt.settingExt.noinit();
1158 break;
1159 }
1160 case FrontendSettings::isdbs3: {
1161 const FrontendIsdbs3Settings& isdbs3 = aidlSettings.get<FrontendSettings::isdbs3>();
1162 settings.isdbs3({
1163 .frequency = static_cast<uint32_t>(isdbs3.frequency),
1164 .streamId = static_cast<uint16_t>(isdbs3.streamId),
1165 .streamIdType = static_cast<HidlFrontendIsdbsStreamIdType>(isdbs3.streamIdType),
1166 .modulation = static_cast<HidlFrontendIsdbs3Modulation>(isdbs3.modulation),
1167 .coderate = static_cast<HidlFrontendIsdbs3Coderate>(isdbs3.coderate),
1168 .symbolRate = static_cast<uint32_t>(isdbs3.symbolRate),
1169 .rolloff = static_cast<HidlFrontendIsdbs3Rolloff>(isdbs3.rolloff),
1170 });
1171 settingsExt.endFrequency = static_cast<uint32_t>(isdbs3.endFrequency);
1172 settingsExt.settingExt.noinit();
1173 break;
1174 }
1175 case FrontendSettings::isdbt: {
1176 const FrontendIsdbtSettings& isdbt = aidlSettings.get<FrontendSettings::isdbt>();
1177 HidlFrontendIsdbtModulation modulation = HidlFrontendIsdbtModulation::UNDEFINED;
1178 HidlFrontendIsdbtCoderate coderate = HidlFrontendIsdbtCoderate::UNDEFINED;
1179 if (isdbt.layerSettings.size() > 0) {
1180 modulation =
1181 static_cast<HidlFrontendIsdbtModulation>(isdbt.layerSettings[0].modulation);
1182 coderate = static_cast<HidlFrontendIsdbtCoderate>(isdbt.layerSettings[0].coderate);
1183 }
1184 settings.isdbt({
1185 .frequency = static_cast<uint32_t>(isdbt.frequency),
1186 .modulation = modulation,
1187 .bandwidth = static_cast<HidlFrontendIsdbtBandwidth>(isdbt.bandwidth),
1188 .mode = static_cast<HidlFrontendIsdbtMode>(isdbt.mode),
1189 .coderate = coderate,
1190 .guardInterval = static_cast<HidlFrontendIsdbtGuardInterval>(isdbt.guardInterval),
1191 .serviceAreaId = static_cast<uint32_t>(isdbt.serviceAreaId),
1192 });
1193 settingsExt.endFrequency = static_cast<uint32_t>(isdbt.endFrequency);
1194 settingsExt.inversion = static_cast<HidlFrontendSpectralInversion>(isdbt.inversion);
1195 settingsExt.settingExt.noinit();
1196 break;
1197 }
1198 case FrontendSettings::dtmb: {
1199 const FrontendDtmbSettings& dtmb = aidlSettings.get<FrontendSettings::dtmb>();
1200 settingsExt.settingExt.dtmb({
1201 .frequency = static_cast<uint32_t>(dtmb.frequency),
1202 .transmissionMode =
1203 static_cast<HidlFrontendDtmbTransmissionMode>(dtmb.transmissionMode),
1204 .bandwidth = static_cast<HidlFrontendDtmbBandwidth>(dtmb.bandwidth),
1205 .modulation = static_cast<HidlFrontendDtmbModulation>(dtmb.modulation),
1206 .codeRate = static_cast<HidlFrontendDtmbCodeRate>(dtmb.codeRate),
1207 .guardInterval = static_cast<HidlFrontendDtmbGuardInterval>(dtmb.guardInterval),
1208 .interleaveMode =
1209 static_cast<HidlFrontendDtmbTimeInterleaveMode>(dtmb.interleaveMode),
1210 });
1211 settingsExt.endFrequency = static_cast<uint32_t>(dtmb.endFrequency);
1212 settingsExt.inversion = static_cast<HidlFrontendSpectralInversion>(dtmb.inversion);
1213 break;
1214 }
1215 default:
1216 break;
1217 }
1218 }
1219
1220 } // namespace tuner
1221 } // namespace tv
1222 } // namespace media
1223 } // namespace android
1224 } // namespace aidl
1225