blob: cf17ed6f43833675de0e5dc632429720ff42b98b [file] [log] [blame]
Amy Zhangbf68a162020-11-23 17:42:40 -08001/*
2 * Copyright 2020 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_TAG "TunerClient"
18
19#include <android/binder_manager.h>
20#include <android-base/logging.h>
21#include <utils/Log.h>
22
23#include "TunerClient.h"
24
Amy Zhang379cb482021-02-04 21:05:11 -080025using ::aidl::android::media::tv::tuner::TunerFrontendCapabilities;
26using ::aidl::android::media::tv::tuner::TunerFrontendDtmbCapabilities;
Amy Zhangbf68a162020-11-23 17:42:40 -080027using ::android::hardware::tv::tuner::V1_0::FrontendId;
Amy Zhang379cb482021-02-04 21:05:11 -080028using ::android::hardware::tv::tuner::V1_0::FrontendStatusType;
Amy Zhangbf68a162020-11-23 17:42:40 -080029using ::android::hardware::tv::tuner::V1_0::FrontendType;
30
31namespace android {
32
33sp<ITuner> TunerClient::mTuner;
34sp<::android::hardware::tv::tuner::V1_1::ITuner> TunerClient::mTuner_1_1;
35shared_ptr<ITunerService> TunerClient::mTunerService;
36int TunerClient::mTunerVersion;
37
38/////////////// TunerClient ///////////////////////
39
40TunerClient::TunerClient() {
41 // Get HIDL Tuner in migration stage.
42 getHidlTuner();
Amy Zhang9eeba432021-01-21 12:52:05 -080043 if (mTuner != NULL) {
44 updateTunerResources();
45 }
Amy Zhangbf68a162020-11-23 17:42:40 -080046 // Connect with Tuner Service.
47 ::ndk::SpAIBinder binder(AServiceManager_getService("media.tuner"));
48 mTunerService = ITunerService::fromBinder(binder);
49 if (mTunerService == NULL) {
50 ALOGE("Failed to get tuner service");
Amy Zhang9eeba432021-01-21 12:52:05 -080051 } else {
52 // TODO: b/178124017 update TRM in TunerService independently.
53 mTunerService->updateTunerResources();
Amy Zhang9abbe102021-02-08 19:51:18 -080054 mTunerService->getTunerHalVersion(&mTunerVersion);
Amy Zhangbf68a162020-11-23 17:42:40 -080055 }
56}
57
58TunerClient::~TunerClient() {
59 mTuner = NULL;
60 mTuner_1_1 = NULL;
61 mTunerVersion = 0;
62 mTunerService = NULL;
63}
64
65vector<FrontendId> TunerClient::getFrontendIds() {
66 vector<FrontendId> ids;
shubang68f32a32020-12-29 00:34:24 -080067
68 if (mTunerService != NULL) {
69 vector<int32_t> v;
Amy Zhang9eeba432021-01-21 12:52:05 -080070 Status s = mTunerService->getFrontendIds(&v);
Amy Zhang4a07e802021-01-21 17:10:21 -080071 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS || v.size() == 0) {
shubang68f32a32020-12-29 00:34:24 -080072 ids.clear();
73 return ids;
74 }
75 for (int32_t id : v) {
76 ids.push_back(static_cast<FrontendId>(id));
77 }
78 return ids;
79 }
Amy Zhangbf68a162020-11-23 17:42:40 -080080
81 if (mTuner != NULL) {
82 Result res;
83 mTuner->getFrontendIds([&](Result r, const hardware::hidl_vec<FrontendId>& frontendIds) {
84 res = r;
85 ids = frontendIds;
86 });
87 if (res != Result::SUCCESS || ids.size() == 0) {
88 ALOGW("Frontend ids not available");
89 ids.clear();
90 return ids;
91 }
92 return ids;
93 }
94
95 return ids;
96}
97
98
99sp<FrontendClient> TunerClient::openFrontend(int frontendHandle) {
100 if (mTunerService != NULL) {
Amy Zhangbf68a162020-11-23 17:42:40 -0800101 shared_ptr<ITunerFrontend> tunerFrontend;
Amy Zhang4a07e802021-01-21 17:10:21 -0800102 Status s = mTunerService->openFrontend(frontendHandle, &tunerFrontend);
103 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS
104 || tunerFrontend == NULL) {
Amy Zhangb9f3cab2021-01-13 15:24:14 -0800105 return NULL;
106 }
107 int id;
Amy Zhang4a07e802021-01-21 17:10:21 -0800108 s = tunerFrontend->getFrontendId(&id);
109 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
110 return NULL;
111 }
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800112 TunerFrontendInfo aidlFrontendInfo;
Amy Zhang4a07e802021-01-21 17:10:21 -0800113 s = mTunerService->getFrontendInfo(id, &aidlFrontendInfo);
114 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
115 return NULL;
116 }
Amy Zhang9abbe102021-02-08 19:51:18 -0800117 return new FrontendClient(tunerFrontend, aidlFrontendInfo.type);
Amy Zhangbf68a162020-11-23 17:42:40 -0800118 }
119
120 if (mTuner != NULL) {
Amy Zhang210c26a2021-01-12 11:25:27 -0800121 int id = getResourceIdFromHandle(frontendHandle, FRONTEND);
122 sp<IFrontend> hidlFrontend = openHidlFrontendById(id);
Amy Zhangbf68a162020-11-23 17:42:40 -0800123 if (hidlFrontend != NULL) {
Amy Zhangb9f3cab2021-01-13 15:24:14 -0800124 FrontendInfo hidlInfo;
125 Result res = getHidlFrontendInfo(id, hidlInfo);
126 if (res != Result::SUCCESS) {
127 return NULL;
128 }
Amy Zhang9abbe102021-02-08 19:51:18 -0800129 sp<FrontendClient> frontendClient = new FrontendClient(
130 NULL, (int)hidlInfo.type);
Amy Zhangbf68a162020-11-23 17:42:40 -0800131 frontendClient->setHidlFrontend(hidlFrontend);
Amy Zhang9abbe102021-02-08 19:51:18 -0800132 frontendClient->setId(id);
Amy Zhangbf68a162020-11-23 17:42:40 -0800133 return frontendClient;
134 }
135 }
136
137 return NULL;
138}
139
140shared_ptr<FrontendInfo> TunerClient::getFrontendInfo(int id) {
141 if (mTunerService != NULL) {
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800142 TunerFrontendInfo aidlFrontendInfo;
Amy Zhang4a07e802021-01-21 17:10:21 -0800143 Status s = mTunerService->getFrontendInfo(id, &aidlFrontendInfo);
144 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
145 return NULL;
146 }
Amy Zhang379cb482021-02-04 21:05:11 -0800147 return make_shared<FrontendInfo>(frontendInfoAidlToHidl(aidlFrontendInfo));
Amy Zhangbf68a162020-11-23 17:42:40 -0800148 }
149
150 if (mTuner != NULL) {
151 FrontendInfo hidlInfo;
152 Result res = getHidlFrontendInfo(id, hidlInfo);
153 if (res != Result::SUCCESS) {
154 return NULL;
155 }
156 return make_shared<FrontendInfo>(hidlInfo);
157 }
158
159 return NULL;
160}
161
162shared_ptr<FrontendDtmbCapabilities> TunerClient::getFrontendDtmbCapabilities(int id) {
Amy Zhang379cb482021-02-04 21:05:11 -0800163 if (mTunerService != NULL) {
164 TunerFrontendDtmbCapabilities dtmbCaps;
165 Status s = mTunerService->getFrontendDtmbCapabilities(id, &dtmbCaps);
166 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
167 return NULL;
168 }
169 FrontendDtmbCapabilities hidlCaps{
170 .transmissionModeCap = static_cast<uint32_t>(dtmbCaps.transmissionModeCap),
171 .bandwidthCap = static_cast<uint32_t>(dtmbCaps.bandwidthCap),
172 .modulationCap = static_cast<uint32_t>(dtmbCaps.modulationCap),
173 .codeRateCap = static_cast<uint32_t>(dtmbCaps.codeRateCap),
174 .guardIntervalCap = static_cast<uint32_t>(dtmbCaps.guardIntervalCap),
175 .interleaveModeCap = static_cast<uint32_t>(dtmbCaps.interleaveModeCap),
176 };
177 return make_shared<FrontendDtmbCapabilities>(hidlCaps);
178 }
Amy Zhangbf68a162020-11-23 17:42:40 -0800179
180 if (mTuner_1_1 != NULL) {
181 Result result;
182 FrontendDtmbCapabilities dtmbCaps;
183 mTuner_1_1->getFrontendDtmbCapabilities(id,
184 [&](Result r, const FrontendDtmbCapabilities& caps) {
185 dtmbCaps = caps;
186 result = r;
187 });
188 if (result == Result::SUCCESS) {
189 return make_shared<FrontendDtmbCapabilities>(dtmbCaps);
190 }
191 }
192
193 return NULL;
194}
195
Amy Zhang4a07e802021-01-21 17:10:21 -0800196sp<DemuxClient> TunerClient::openDemux(int demuxHandle) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800197 if (mTunerService != NULL) {
Amy Zhang4a07e802021-01-21 17:10:21 -0800198 shared_ptr<ITunerDemux> tunerDemux;
199 Status s = mTunerService->openDemux(demuxHandle, &tunerDemux);
200 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
201 return NULL;
202 }
203 return new DemuxClient(tunerDemux);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800204 }
205
206 if (mTuner != NULL) {
Amy Zhang4a07e802021-01-21 17:10:21 -0800207 sp<DemuxClient> demuxClient = new DemuxClient(NULL);
Amy Zhang921fd432021-01-07 13:18:27 -0800208 int demuxId;
209 sp<IDemux> hidlDemux = openHidlDemux(demuxId);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800210 if (hidlDemux != NULL) {
211 demuxClient->setHidlDemux(hidlDemux);
Amy Zhang921fd432021-01-07 13:18:27 -0800212 demuxClient->setId(demuxId);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800213 return demuxClient;
214 }
215 }
216
217 return NULL;
218}
219
Amy Zhang90a50b42021-01-11 16:58:59 -0800220shared_ptr<DemuxCapabilities> TunerClient::getDemuxCaps() {
Amy Zhang952794662021-02-04 15:56:22 -0800221 if (mTunerService != NULL) {
222 TunerDemuxCapabilities aidlCaps;
223 Status s = mTunerService->getDemuxCaps(&aidlCaps);
224 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
225 return NULL;
226 }
227 return make_shared<DemuxCapabilities>(getHidlDemuxCaps(aidlCaps));
228 }
Amy Zhang90a50b42021-01-11 16:58:59 -0800229
230 if (mTuner != NULL) {
231 Result res;
232 DemuxCapabilities caps;
233 mTuner->getDemuxCaps([&](Result r, const DemuxCapabilities& demuxCaps) {
234 caps = demuxCaps;
235 res = r;
236 });
237 if (res == Result::SUCCESS) {
238 return make_shared<DemuxCapabilities>(caps);
239 }
240 }
241
242 return NULL;
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800243}
244
Amy Zhang38261c32021-02-03 20:38:52 -0800245sp<DescramblerClient> TunerClient::openDescrambler(int descramblerHandle) {
Amy Zhang921fd432021-01-07 13:18:27 -0800246 if (mTunerService != NULL) {
Amy Zhang38261c32021-02-03 20:38:52 -0800247 shared_ptr<ITunerDescrambler> tunerDescrambler;
248 Status s = mTunerService->openDescrambler(descramblerHandle, &tunerDescrambler);
249 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
250 return NULL;
251 }
252 return new DescramblerClient(tunerDescrambler);
Amy Zhang921fd432021-01-07 13:18:27 -0800253 }
254
255 if (mTuner != NULL) {
Amy Zhang38261c32021-02-03 20:38:52 -0800256 sp<DescramblerClient> descramblerClient = new DescramblerClient(NULL);
Amy Zhang921fd432021-01-07 13:18:27 -0800257 sp<IDescrambler> hidlDescrambler = openHidlDescrambler();
258 if (hidlDescrambler != NULL) {
259 descramblerClient->setHidlDescrambler(hidlDescrambler);
260 return descramblerClient;
261 }
262 }
263
Amy Zhangb5809be2021-01-26 16:27:23 -0800264 return NULL;
265}
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800266
Amy Zhangd3d57b42021-01-07 11:14:43 -0800267sp<LnbClient> TunerClient::openLnb(int lnbHandle) {
268 if (mTunerService != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800269 shared_ptr<ITunerLnb> tunerLnb;
Amy Zhang4a07e802021-01-21 17:10:21 -0800270 Status s = mTunerService->openLnb(lnbHandle, &tunerLnb);
271 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
272 return NULL;
273 }
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800274 return new LnbClient(tunerLnb);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800275 }
276
277 if (mTuner != NULL) {
278 int id = getResourceIdFromHandle(lnbHandle, LNB);
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800279 sp<LnbClient> lnbClient = new LnbClient(NULL);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800280 sp<ILnb> hidlLnb = openHidlLnbById(id);
281 if (hidlLnb != NULL) {
282 lnbClient->setHidlLnb(hidlLnb);
283 lnbClient->setId(id);
284 return lnbClient;
285 }
286 }
287
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800288 return NULL;
289}
290
Amy Zhangd3d57b42021-01-07 11:14:43 -0800291sp<LnbClient> TunerClient::openLnbByName(string lnbName) {
292 if (mTunerService != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800293 shared_ptr<ITunerLnb> tunerLnb;
Amy Zhang4a07e802021-01-21 17:10:21 -0800294 Status s = mTunerService->openLnbByName(lnbName, &tunerLnb);
295 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
296 return NULL;
297 }
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800298 return new LnbClient(tunerLnb);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800299 }
300
301 if (mTuner != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800302 sp<LnbClient> lnbClient = new LnbClient(NULL);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800303 LnbId id;
304 sp<ILnb> hidlLnb = openHidlLnbByName(lnbName, id);
305 if (hidlLnb != NULL) {
306 lnbClient->setHidlLnb(hidlLnb);
307 lnbClient->setId(id);
308 return lnbClient;
309 }
310 }
311
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800312 return NULL;
313}
314
Amy Zhangbf68a162020-11-23 17:42:40 -0800315/////////////// TunerClient Helper Methods ///////////////////////
316
Amy Zhang39a3fa42020-12-21 16:56:03 -0800317void TunerClient::updateTunerResources() {
318 if (mTuner == NULL) {
319 return;
320 }
321
322 // Connect with Tuner Resource Manager.
323 ::ndk::SpAIBinder binder(AServiceManager_getService("tv_tuner_resource_mgr"));
324 mTunerResourceManager = ITunerResourceManager::fromBinder(binder);
325
326 updateFrontendResources();
327 updateLnbResources();
328 // TODO: update Demux, Descrambler.
329}
330
331void TunerClient::updateFrontendResources() {
332 vector<FrontendId> ids = getFrontendIds();
333 if (ids.size() == 0) {
334 return;
335 }
336 vector<TunerFrontendInfo> infos;
337 for (int i = 0; i < ids.size(); i++) {
338 shared_ptr<FrontendInfo> frontendInfo = getFrontendInfo((int)ids[i]);
339 if (frontendInfo == NULL) {
340 continue;
341 }
342 TunerFrontendInfo tunerFrontendInfo{
343 .handle = getResourceHandleFromId((int)ids[i], FRONTEND),
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800344 .type = static_cast<int>(frontendInfo->type),
Amy Zhang39a3fa42020-12-21 16:56:03 -0800345 .exclusiveGroupId = static_cast<int>(frontendInfo->exclusiveGroupId),
346 };
347 infos.push_back(tunerFrontendInfo);
348 }
349 mTunerResourceManager->setFrontendInfoList(infos);
350}
351
352void TunerClient::updateLnbResources() {
353 vector<int> handles = getLnbHandles();
354 if (handles.size() == 0) {
355 return;
356 }
357 mTunerResourceManager->setLnbInfoList(handles);
358}
359
Amy Zhangbf68a162020-11-23 17:42:40 -0800360sp<ITuner> TunerClient::getHidlTuner() {
361 if (mTuner == NULL) {
Amy Zhang9abbe102021-02-08 19:51:18 -0800362 mTunerVersion = TUNER_HAL_VERSION_UNKNOWN;
Amy Zhangbf68a162020-11-23 17:42:40 -0800363 mTuner_1_1 = ::android::hardware::tv::tuner::V1_1::ITuner::getService();
364
365 if (mTuner_1_1 == NULL) {
366 ALOGW("Failed to get tuner 1.1 service.");
367 mTuner = ITuner::getService();
368 if (mTuner == NULL) {
369 ALOGW("Failed to get tuner 1.0 service.");
370 } else {
Amy Zhang9abbe102021-02-08 19:51:18 -0800371 mTunerVersion = TUNER_HAL_VERSION_1_0;
Amy Zhangbf68a162020-11-23 17:42:40 -0800372 }
373 } else {
374 mTuner = static_cast<sp<ITuner>>(mTuner_1_1);
Amy Zhang9abbe102021-02-08 19:51:18 -0800375 mTunerVersion = TUNER_HAL_VERSION_1_1;
Amy Zhangbf68a162020-11-23 17:42:40 -0800376 }
377 }
378 return mTuner;
379}
380
Amy Zhang210c26a2021-01-12 11:25:27 -0800381sp<IFrontend> TunerClient::openHidlFrontendById(int id) {
Amy Zhangbf68a162020-11-23 17:42:40 -0800382 sp<IFrontend> fe;
383 Result res;
Amy Zhangbf68a162020-11-23 17:42:40 -0800384 mTuner->openFrontendById(id, [&](Result r, const sp<IFrontend>& frontend) {
385 fe = frontend;
386 res = r;
387 });
388 if (res != Result::SUCCESS || fe == nullptr) {
389 ALOGE("Failed to open frontend");
390 return NULL;
391 }
392 return fe;
393}
394
395Result TunerClient::getHidlFrontendInfo(int id, FrontendInfo& feInfo) {
396 Result res;
397 mTuner->getFrontendInfo(id, [&](Result r, const FrontendInfo& info) {
398 feInfo = info;
399 res = r;
400 });
401 return res;
402}
403
Amy Zhang921fd432021-01-07 13:18:27 -0800404sp<IDemux> TunerClient::openHidlDemux(int& demuxId) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800405 sp<IDemux> demux;
406 Result res;
407
Amy Zhang921fd432021-01-07 13:18:27 -0800408 mTuner->openDemux([&](Result result, uint32_t id, const sp<IDemux>& demuxSp) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800409 demux = demuxSp;
Amy Zhang921fd432021-01-07 13:18:27 -0800410 demuxId = id;
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800411 res = result;
412 });
413 if (res != Result::SUCCESS || demux == nullptr) {
414 ALOGE("Failed to open demux");
415 return NULL;
416 }
417 return demux;
418}
419
Amy Zhangd3d57b42021-01-07 11:14:43 -0800420sp<ILnb> TunerClient::openHidlLnbById(int id) {
421 sp<ILnb> lnb;
422 Result res;
423
424 mTuner->openLnbById(id, [&](Result r, const sp<ILnb>& lnbSp) {
425 res = r;
426 lnb = lnbSp;
427 });
428 if (res != Result::SUCCESS || lnb == nullptr) {
429 ALOGE("Failed to open lnb by id");
430 return NULL;
431 }
432 return lnb;
433}
434
435sp<ILnb> TunerClient::openHidlLnbByName(string name, LnbId& lnbId) {
436 sp<ILnb> lnb;
437 Result res;
438
439 mTuner->openLnbByName(name, [&](Result r, LnbId id, const sp<ILnb>& lnbSp) {
440 res = r;
441 lnb = lnbSp;
442 lnbId = id;
443 });
444 if (res != Result::SUCCESS || lnb == nullptr) {
445 ALOGE("Failed to open lnb by name");
446 return NULL;
447 }
448 return lnb;
449}
450
Amy Zhang39a3fa42020-12-21 16:56:03 -0800451vector<int> TunerClient::getLnbHandles() {
452 vector<int> lnbHandles;
Amy Zhang39a3fa42020-12-21 16:56:03 -0800453 if (mTuner != NULL) {
454 Result res;
455 vector<LnbId> lnbIds;
456 mTuner->getLnbIds([&](Result r, const hardware::hidl_vec<LnbId>& ids) {
457 lnbIds = ids;
458 res = r;
459 });
460 if (res != Result::SUCCESS || lnbIds.size() == 0) {
461 ALOGW("Lnb isn't available");
462 } else {
463 for (int i = 0; i < lnbIds.size(); i++) {
464 lnbHandles.push_back(getResourceHandleFromId((int)lnbIds[i], LNB));
465 }
466 }
467 }
468
469 return lnbHandles;
470}
471
Amy Zhang4a07e802021-01-21 17:10:21 -0800472sp<IDescrambler> TunerClient::openHidlDescrambler() {
473 sp<IDescrambler> descrambler;
474 Result res;
475
476 mTuner->openDescrambler([&](Result r, const sp<IDescrambler>& descramblerSp) {
477 res = r;
478 descrambler = descramblerSp;
479 });
480
481 if (res != Result::SUCCESS || descrambler == NULL) {
482 return NULL;
483 }
484
485 return descrambler;
486}
487
Amy Zhang952794662021-02-04 15:56:22 -0800488DemuxCapabilities TunerClient::getHidlDemuxCaps(TunerDemuxCapabilities& aidlCaps) {
489 DemuxCapabilities caps{
490 .numDemux = (uint32_t)aidlCaps.numDemux,
491 .numRecord = (uint32_t)aidlCaps.numRecord,
492 .numPlayback = (uint32_t)aidlCaps.numPlayback,
493 .numTsFilter = (uint32_t)aidlCaps.numTsFilter,
494 .numSectionFilter = (uint32_t)aidlCaps.numSectionFilter,
495 .numAudioFilter = (uint32_t)aidlCaps.numAudioFilter,
496 .numVideoFilter = (uint32_t)aidlCaps.numVideoFilter,
497 .numPesFilter = (uint32_t)aidlCaps.numPesFilter,
498 .numPcrFilter = (uint32_t)aidlCaps.numPcrFilter,
499 .numBytesInSectionFilter = (uint32_t)aidlCaps.numBytesInSectionFilter,
500 .filterCaps = (uint32_t)aidlCaps.filterCaps,
501 .bTimeFilter = aidlCaps.bTimeFilter,
502 };
503 caps.linkCaps.resize(aidlCaps.linkCaps.size());
504 copy(aidlCaps.linkCaps.begin(), aidlCaps.linkCaps.end(), caps.linkCaps.begin());
505 return caps;
506}
507
Amy Zhang379cb482021-02-04 21:05:11 -0800508FrontendInfo TunerClient::frontendInfoAidlToHidl(TunerFrontendInfo aidlFrontendInfo) {
Amy Zhangbf68a162020-11-23 17:42:40 -0800509 FrontendInfo hidlFrontendInfo {
510 .type = static_cast<FrontendType>(aidlFrontendInfo.type),
511 .minFrequency = static_cast<uint32_t>(aidlFrontendInfo.minFrequency),
512 .maxFrequency = static_cast<uint32_t>(aidlFrontendInfo.maxFrequency),
513 .minSymbolRate = static_cast<uint32_t>(aidlFrontendInfo.minSymbolRate),
514 .maxSymbolRate = static_cast<uint32_t>(aidlFrontendInfo.maxSymbolRate),
515 .acquireRange = static_cast<uint32_t>(aidlFrontendInfo.acquireRange),
516 .exclusiveGroupId = static_cast<uint32_t>(aidlFrontendInfo.exclusiveGroupId),
517 };
Amy Zhangbf68a162020-11-23 17:42:40 -0800518
Amy Zhang379cb482021-02-04 21:05:11 -0800519 int size = aidlFrontendInfo.statusCaps.size();
520 hidlFrontendInfo.statusCaps.resize(size);
521 for (int i = 0; i < size; i++) {
522 hidlFrontendInfo.statusCaps[i] =
523 static_cast<FrontendStatusType>(aidlFrontendInfo.statusCaps[i]);
524 }
525
526 switch (aidlFrontendInfo.caps.getTag()) {
527 case TunerFrontendCapabilities::analogCaps: {
528 auto analog = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::analogCaps>();
529 hidlFrontendInfo.frontendCaps.analogCaps({
530 .typeCap = static_cast<uint32_t>(analog.typeCap),
531 .sifStandardCap = static_cast<uint32_t>(analog.sifStandardCap),
532 });
533 break;
534 }
535 case TunerFrontendCapabilities::atscCaps: {
536 auto atsc = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::atscCaps>();
537 hidlFrontendInfo.frontendCaps.atscCaps({
538 .modulationCap = static_cast<uint32_t>(atsc.modulationCap),
539 });
540 break;
541 }
542 case TunerFrontendCapabilities::atsc3Caps: {
543 auto atsc3 = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::atsc3Caps>();
544 hidlFrontendInfo.frontendCaps.atsc3Caps({
545 .bandwidthCap = static_cast<uint32_t>(atsc3.bandwidthCap),
546 .modulationCap = static_cast<uint32_t>(atsc3.modulationCap),
547 .timeInterleaveModeCap = static_cast<uint32_t>(atsc3.timeInterleaveModeCap),
548 .codeRateCap = static_cast<uint32_t>(atsc3.codeRateCap),
549 .fecCap = static_cast<uint32_t>(atsc3.fecCap),
550 .demodOutputFormatCap = static_cast<uint8_t>(atsc3.demodOutputFormatCap),
551 });
552 break;
553 }
554 case TunerFrontendCapabilities::cableCaps: {
555 auto cable = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::cableCaps>();
556 hidlFrontendInfo.frontendCaps.dvbcCaps({
557 .modulationCap = static_cast<uint32_t>(cable.modulationCap),
558 .fecCap = static_cast<uint64_t>(cable.codeRateCap),
559 .annexCap = static_cast<uint8_t>(cable.annexCap),
560 });
561 break;
562 }
563 case TunerFrontendCapabilities::dvbsCaps: {
564 auto dvbs = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::dvbsCaps>();
565 hidlFrontendInfo.frontendCaps.dvbsCaps({
566 .modulationCap = static_cast<int32_t>(dvbs.modulationCap),
567 .innerfecCap = static_cast<uint64_t>(dvbs.codeRateCap),
568 .standard = static_cast<uint8_t>(dvbs.standard),
569 });
570 break;
571 }
572 case TunerFrontendCapabilities::dvbtCaps: {
573 auto dvbt = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::dvbtCaps>();
574 hidlFrontendInfo.frontendCaps.dvbtCaps({
575 .transmissionModeCap = static_cast<uint32_t>(dvbt.transmissionModeCap),
576 .bandwidthCap = static_cast<uint32_t>(dvbt.bandwidthCap),
577 .constellationCap = static_cast<uint32_t>(dvbt.constellationCap),
578 .coderateCap = static_cast<uint32_t>(dvbt.codeRateCap),
579 .hierarchyCap = static_cast<uint32_t>(dvbt.hierarchyCap),
580 .guardIntervalCap = static_cast<uint32_t>(dvbt.guardIntervalCap),
581 .isT2Supported = dvbt.isT2Supported,
582 .isMisoSupported = dvbt.isMisoSupported,
583 });
584 break;
585 }
586 case TunerFrontendCapabilities::isdbsCaps: {
587 auto isdbs = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbsCaps>();
588 hidlFrontendInfo.frontendCaps.isdbsCaps({
589 .modulationCap = static_cast<uint32_t>(isdbs.modulationCap),
590 .coderateCap = static_cast<uint32_t>(isdbs.codeRateCap),
591 });
592 break;
593 }
594 case TunerFrontendCapabilities::isdbs3Caps: {
595 auto isdbs3 = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbs3Caps>();
596 hidlFrontendInfo.frontendCaps.isdbs3Caps({
597 .modulationCap = static_cast<uint32_t>(isdbs3.modulationCap),
598 .coderateCap = static_cast<uint32_t>(isdbs3.codeRateCap),
599 });
600 break;
601 }
602 case TunerFrontendCapabilities::isdbtCaps: {
603 auto isdbt = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbtCaps>();
604 hidlFrontendInfo.frontendCaps.isdbtCaps({
605 .modeCap = static_cast<uint32_t>(isdbt.modeCap),
606 .bandwidthCap = static_cast<uint32_t>(isdbt.bandwidthCap),
607 .modulationCap = static_cast<uint32_t>(isdbt.modulationCap),
608 .coderateCap = static_cast<uint32_t>(isdbt.codeRateCap),
609 .guardIntervalCap = static_cast<uint32_t>(isdbt.guardIntervalCap),
610 });
611 break;
612 }
613 }
Amy Zhangbf68a162020-11-23 17:42:40 -0800614 return hidlFrontendInfo;
615}
Amy Zhang210c26a2021-01-12 11:25:27 -0800616
617int TunerClient::getResourceIdFromHandle(int handle, int /*resourceType*/) {
618 return (handle & 0x00ff0000) >> 16;
619}
620
621int TunerClient::getResourceHandleFromId(int id, int resourceType) {
622 // TODO: build up randomly generated id to handle mapping
623 return (resourceType & 0x000000ff) << 24
624 | (id << 16)
625 | (mResourceRequestCount++ & 0xffff);
626}
Amy Zhangbf68a162020-11-23 17:42:40 -0800627} // namespace android