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