blob: c9a7e8340dda45c169185adefd86983b09d5d6dc [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 {
Amy Zhang9abbe102021-02-08 19:51:18 -080052 mTunerService->getTunerHalVersion(&mTunerVersion);
Amy Zhangbf68a162020-11-23 17:42:40 -080053 }
54}
55
56TunerClient::~TunerClient() {
57 mTuner = NULL;
58 mTuner_1_1 = NULL;
59 mTunerVersion = 0;
60 mTunerService = NULL;
61}
62
63vector<FrontendId> TunerClient::getFrontendIds() {
64 vector<FrontendId> ids;
shubang68f32a32020-12-29 00:34:24 -080065
66 if (mTunerService != NULL) {
67 vector<int32_t> v;
Amy Zhang9eeba432021-01-21 12:52:05 -080068 Status s = mTunerService->getFrontendIds(&v);
Amy Zhang4a07e802021-01-21 17:10:21 -080069 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS || v.size() == 0) {
shubang68f32a32020-12-29 00:34:24 -080070 ids.clear();
71 return ids;
72 }
73 for (int32_t id : v) {
74 ids.push_back(static_cast<FrontendId>(id));
75 }
76 return ids;
77 }
Amy Zhangbf68a162020-11-23 17:42:40 -080078
79 if (mTuner != NULL) {
80 Result res;
81 mTuner->getFrontendIds([&](Result r, const hardware::hidl_vec<FrontendId>& frontendIds) {
82 res = r;
83 ids = frontendIds;
84 });
85 if (res != Result::SUCCESS || ids.size() == 0) {
86 ALOGW("Frontend ids not available");
87 ids.clear();
88 return ids;
89 }
90 return ids;
91 }
92
93 return ids;
94}
95
96
97sp<FrontendClient> TunerClient::openFrontend(int frontendHandle) {
98 if (mTunerService != NULL) {
Amy Zhangbf68a162020-11-23 17:42:40 -080099 shared_ptr<ITunerFrontend> tunerFrontend;
Amy Zhang4a07e802021-01-21 17:10:21 -0800100 Status s = mTunerService->openFrontend(frontendHandle, &tunerFrontend);
101 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS
102 || tunerFrontend == NULL) {
Amy Zhangb9f3cab2021-01-13 15:24:14 -0800103 return NULL;
104 }
105 int id;
Amy Zhang4a07e802021-01-21 17:10:21 -0800106 s = tunerFrontend->getFrontendId(&id);
107 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
108 return NULL;
109 }
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800110 TunerFrontendInfo aidlFrontendInfo;
Amy Zhang4a07e802021-01-21 17:10:21 -0800111 s = mTunerService->getFrontendInfo(id, &aidlFrontendInfo);
112 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
113 return NULL;
114 }
Amy Zhang9abbe102021-02-08 19:51:18 -0800115 return new FrontendClient(tunerFrontend, aidlFrontendInfo.type);
Amy Zhangbf68a162020-11-23 17:42:40 -0800116 }
117
118 if (mTuner != NULL) {
Amy Zhang210c26a2021-01-12 11:25:27 -0800119 int id = getResourceIdFromHandle(frontendHandle, FRONTEND);
120 sp<IFrontend> hidlFrontend = openHidlFrontendById(id);
Amy Zhangbf68a162020-11-23 17:42:40 -0800121 if (hidlFrontend != NULL) {
Amy Zhangb9f3cab2021-01-13 15:24:14 -0800122 FrontendInfo hidlInfo;
123 Result res = getHidlFrontendInfo(id, hidlInfo);
124 if (res != Result::SUCCESS) {
125 return NULL;
126 }
Amy Zhang9abbe102021-02-08 19:51:18 -0800127 sp<FrontendClient> frontendClient = new FrontendClient(
128 NULL, (int)hidlInfo.type);
Amy Zhangbf68a162020-11-23 17:42:40 -0800129 frontendClient->setHidlFrontend(hidlFrontend);
Amy Zhang9abbe102021-02-08 19:51:18 -0800130 frontendClient->setId(id);
Amy Zhangbf68a162020-11-23 17:42:40 -0800131 return frontendClient;
132 }
133 }
134
135 return NULL;
136}
137
138shared_ptr<FrontendInfo> TunerClient::getFrontendInfo(int id) {
139 if (mTunerService != NULL) {
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800140 TunerFrontendInfo aidlFrontendInfo;
Amy Zhang4a07e802021-01-21 17:10:21 -0800141 Status s = mTunerService->getFrontendInfo(id, &aidlFrontendInfo);
142 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
143 return NULL;
144 }
Amy Zhang379cb482021-02-04 21:05:11 -0800145 return make_shared<FrontendInfo>(frontendInfoAidlToHidl(aidlFrontendInfo));
Amy Zhangbf68a162020-11-23 17:42:40 -0800146 }
147
148 if (mTuner != NULL) {
149 FrontendInfo hidlInfo;
150 Result res = getHidlFrontendInfo(id, hidlInfo);
151 if (res != Result::SUCCESS) {
152 return NULL;
153 }
154 return make_shared<FrontendInfo>(hidlInfo);
155 }
156
157 return NULL;
158}
159
160shared_ptr<FrontendDtmbCapabilities> TunerClient::getFrontendDtmbCapabilities(int id) {
Amy Zhang379cb482021-02-04 21:05:11 -0800161 if (mTunerService != NULL) {
162 TunerFrontendDtmbCapabilities dtmbCaps;
163 Status s = mTunerService->getFrontendDtmbCapabilities(id, &dtmbCaps);
164 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
165 return NULL;
166 }
167 FrontendDtmbCapabilities hidlCaps{
168 .transmissionModeCap = static_cast<uint32_t>(dtmbCaps.transmissionModeCap),
169 .bandwidthCap = static_cast<uint32_t>(dtmbCaps.bandwidthCap),
170 .modulationCap = static_cast<uint32_t>(dtmbCaps.modulationCap),
171 .codeRateCap = static_cast<uint32_t>(dtmbCaps.codeRateCap),
172 .guardIntervalCap = static_cast<uint32_t>(dtmbCaps.guardIntervalCap),
173 .interleaveModeCap = static_cast<uint32_t>(dtmbCaps.interleaveModeCap),
174 };
175 return make_shared<FrontendDtmbCapabilities>(hidlCaps);
176 }
Amy Zhangbf68a162020-11-23 17:42:40 -0800177
178 if (mTuner_1_1 != NULL) {
179 Result result;
180 FrontendDtmbCapabilities dtmbCaps;
181 mTuner_1_1->getFrontendDtmbCapabilities(id,
182 [&](Result r, const FrontendDtmbCapabilities& caps) {
183 dtmbCaps = caps;
184 result = r;
185 });
186 if (result == Result::SUCCESS) {
187 return make_shared<FrontendDtmbCapabilities>(dtmbCaps);
188 }
189 }
190
191 return NULL;
192}
193
Amy Zhang4a07e802021-01-21 17:10:21 -0800194sp<DemuxClient> TunerClient::openDemux(int demuxHandle) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800195 if (mTunerService != NULL) {
Amy Zhang4a07e802021-01-21 17:10:21 -0800196 shared_ptr<ITunerDemux> tunerDemux;
197 Status s = mTunerService->openDemux(demuxHandle, &tunerDemux);
198 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
199 return NULL;
200 }
201 return new DemuxClient(tunerDemux);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800202 }
203
204 if (mTuner != NULL) {
Amy Zhang4a07e802021-01-21 17:10:21 -0800205 sp<DemuxClient> demuxClient = new DemuxClient(NULL);
Amy Zhang921fd432021-01-07 13:18:27 -0800206 int demuxId;
207 sp<IDemux> hidlDemux = openHidlDemux(demuxId);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800208 if (hidlDemux != NULL) {
209 demuxClient->setHidlDemux(hidlDemux);
Amy Zhang921fd432021-01-07 13:18:27 -0800210 demuxClient->setId(demuxId);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800211 return demuxClient;
212 }
213 }
214
215 return NULL;
216}
217
Amy Zhang90a50b42021-01-11 16:58:59 -0800218shared_ptr<DemuxCapabilities> TunerClient::getDemuxCaps() {
Amy Zhang952794662021-02-04 15:56:22 -0800219 if (mTunerService != NULL) {
220 TunerDemuxCapabilities aidlCaps;
221 Status s = mTunerService->getDemuxCaps(&aidlCaps);
222 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
223 return NULL;
224 }
225 return make_shared<DemuxCapabilities>(getHidlDemuxCaps(aidlCaps));
226 }
Amy Zhang90a50b42021-01-11 16:58:59 -0800227
228 if (mTuner != NULL) {
229 Result res;
230 DemuxCapabilities caps;
231 mTuner->getDemuxCaps([&](Result r, const DemuxCapabilities& demuxCaps) {
232 caps = demuxCaps;
233 res = r;
234 });
235 if (res == Result::SUCCESS) {
236 return make_shared<DemuxCapabilities>(caps);
237 }
238 }
239
240 return NULL;
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800241}
242
Amy Zhang38261c32021-02-03 20:38:52 -0800243sp<DescramblerClient> TunerClient::openDescrambler(int descramblerHandle) {
Amy Zhang921fd432021-01-07 13:18:27 -0800244 if (mTunerService != NULL) {
Amy Zhang38261c32021-02-03 20:38:52 -0800245 shared_ptr<ITunerDescrambler> tunerDescrambler;
246 Status s = mTunerService->openDescrambler(descramblerHandle, &tunerDescrambler);
247 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
248 return NULL;
249 }
250 return new DescramblerClient(tunerDescrambler);
Amy Zhang921fd432021-01-07 13:18:27 -0800251 }
252
253 if (mTuner != NULL) {
Amy Zhang38261c32021-02-03 20:38:52 -0800254 sp<DescramblerClient> descramblerClient = new DescramblerClient(NULL);
Amy Zhang921fd432021-01-07 13:18:27 -0800255 sp<IDescrambler> hidlDescrambler = openHidlDescrambler();
256 if (hidlDescrambler != NULL) {
257 descramblerClient->setHidlDescrambler(hidlDescrambler);
258 return descramblerClient;
259 }
260 }
261
Amy Zhangb5809be2021-01-26 16:27:23 -0800262 return NULL;
263}
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800264
Amy Zhangd3d57b42021-01-07 11:14:43 -0800265sp<LnbClient> TunerClient::openLnb(int lnbHandle) {
266 if (mTunerService != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800267 shared_ptr<ITunerLnb> tunerLnb;
Amy Zhang4a07e802021-01-21 17:10:21 -0800268 Status s = mTunerService->openLnb(lnbHandle, &tunerLnb);
269 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
270 return NULL;
271 }
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800272 return new LnbClient(tunerLnb);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800273 }
274
275 if (mTuner != NULL) {
276 int id = getResourceIdFromHandle(lnbHandle, LNB);
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800277 sp<LnbClient> lnbClient = new LnbClient(NULL);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800278 sp<ILnb> hidlLnb = openHidlLnbById(id);
279 if (hidlLnb != NULL) {
280 lnbClient->setHidlLnb(hidlLnb);
281 lnbClient->setId(id);
282 return lnbClient;
283 }
284 }
285
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800286 return NULL;
287}
288
Amy Zhangd3d57b42021-01-07 11:14:43 -0800289sp<LnbClient> TunerClient::openLnbByName(string lnbName) {
290 if (mTunerService != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800291 shared_ptr<ITunerLnb> tunerLnb;
Amy Zhang4a07e802021-01-21 17:10:21 -0800292 Status s = mTunerService->openLnbByName(lnbName, &tunerLnb);
293 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
294 return NULL;
295 }
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800296 return new LnbClient(tunerLnb);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800297 }
298
299 if (mTuner != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800300 sp<LnbClient> lnbClient = new LnbClient(NULL);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800301 LnbId id;
302 sp<ILnb> hidlLnb = openHidlLnbByName(lnbName, id);
303 if (hidlLnb != NULL) {
304 lnbClient->setHidlLnb(hidlLnb);
305 lnbClient->setId(id);
306 return lnbClient;
307 }
308 }
309
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800310 return NULL;
311}
312
Amy Zhangbf68a162020-11-23 17:42:40 -0800313/////////////// TunerClient Helper Methods ///////////////////////
314
Amy Zhang39a3fa42020-12-21 16:56:03 -0800315void TunerClient::updateTunerResources() {
316 if (mTuner == NULL) {
317 return;
318 }
319
320 // Connect with Tuner Resource Manager.
321 ::ndk::SpAIBinder binder(AServiceManager_getService("tv_tuner_resource_mgr"));
322 mTunerResourceManager = ITunerResourceManager::fromBinder(binder);
323
324 updateFrontendResources();
325 updateLnbResources();
326 // TODO: update Demux, Descrambler.
327}
328
329void TunerClient::updateFrontendResources() {
330 vector<FrontendId> ids = getFrontendIds();
331 if (ids.size() == 0) {
332 return;
333 }
334 vector<TunerFrontendInfo> infos;
335 for (int i = 0; i < ids.size(); i++) {
336 shared_ptr<FrontendInfo> frontendInfo = getFrontendInfo((int)ids[i]);
337 if (frontendInfo == NULL) {
338 continue;
339 }
340 TunerFrontendInfo tunerFrontendInfo{
341 .handle = getResourceHandleFromId((int)ids[i], FRONTEND),
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800342 .type = static_cast<int>(frontendInfo->type),
Amy Zhang39a3fa42020-12-21 16:56:03 -0800343 .exclusiveGroupId = static_cast<int>(frontendInfo->exclusiveGroupId),
344 };
345 infos.push_back(tunerFrontendInfo);
346 }
347 mTunerResourceManager->setFrontendInfoList(infos);
348}
349
350void TunerClient::updateLnbResources() {
351 vector<int> handles = getLnbHandles();
352 if (handles.size() == 0) {
353 return;
354 }
355 mTunerResourceManager->setLnbInfoList(handles);
356}
357
Amy Zhangbf68a162020-11-23 17:42:40 -0800358sp<ITuner> TunerClient::getHidlTuner() {
359 if (mTuner == NULL) {
Amy Zhang9abbe102021-02-08 19:51:18 -0800360 mTunerVersion = TUNER_HAL_VERSION_UNKNOWN;
Amy Zhangbf68a162020-11-23 17:42:40 -0800361 mTuner_1_1 = ::android::hardware::tv::tuner::V1_1::ITuner::getService();
362
363 if (mTuner_1_1 == NULL) {
364 ALOGW("Failed to get tuner 1.1 service.");
365 mTuner = ITuner::getService();
366 if (mTuner == NULL) {
367 ALOGW("Failed to get tuner 1.0 service.");
368 } else {
Amy Zhang9abbe102021-02-08 19:51:18 -0800369 mTunerVersion = TUNER_HAL_VERSION_1_0;
Amy Zhangbf68a162020-11-23 17:42:40 -0800370 }
371 } else {
372 mTuner = static_cast<sp<ITuner>>(mTuner_1_1);
Amy Zhang9abbe102021-02-08 19:51:18 -0800373 mTunerVersion = TUNER_HAL_VERSION_1_1;
Amy Zhangbf68a162020-11-23 17:42:40 -0800374 }
375 }
376 return mTuner;
377}
378
Amy Zhang210c26a2021-01-12 11:25:27 -0800379sp<IFrontend> TunerClient::openHidlFrontendById(int id) {
Amy Zhangbf68a162020-11-23 17:42:40 -0800380 sp<IFrontend> fe;
381 Result res;
Amy Zhangbf68a162020-11-23 17:42:40 -0800382 mTuner->openFrontendById(id, [&](Result r, const sp<IFrontend>& frontend) {
383 fe = frontend;
384 res = r;
385 });
386 if (res != Result::SUCCESS || fe == nullptr) {
387 ALOGE("Failed to open frontend");
388 return NULL;
389 }
390 return fe;
391}
392
393Result TunerClient::getHidlFrontendInfo(int id, FrontendInfo& feInfo) {
394 Result res;
395 mTuner->getFrontendInfo(id, [&](Result r, const FrontendInfo& info) {
396 feInfo = info;
397 res = r;
398 });
399 return res;
400}
401
Amy Zhang921fd432021-01-07 13:18:27 -0800402sp<IDemux> TunerClient::openHidlDemux(int& demuxId) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800403 sp<IDemux> demux;
404 Result res;
405
Amy Zhang921fd432021-01-07 13:18:27 -0800406 mTuner->openDemux([&](Result result, uint32_t id, const sp<IDemux>& demuxSp) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800407 demux = demuxSp;
Amy Zhang921fd432021-01-07 13:18:27 -0800408 demuxId = id;
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800409 res = result;
410 });
411 if (res != Result::SUCCESS || demux == nullptr) {
412 ALOGE("Failed to open demux");
413 return NULL;
414 }
415 return demux;
416}
417
Amy Zhangd3d57b42021-01-07 11:14:43 -0800418sp<ILnb> TunerClient::openHidlLnbById(int id) {
419 sp<ILnb> lnb;
420 Result res;
421
422 mTuner->openLnbById(id, [&](Result r, const sp<ILnb>& lnbSp) {
423 res = r;
424 lnb = lnbSp;
425 });
426 if (res != Result::SUCCESS || lnb == nullptr) {
427 ALOGE("Failed to open lnb by id");
428 return NULL;
429 }
430 return lnb;
431}
432
433sp<ILnb> TunerClient::openHidlLnbByName(string name, LnbId& lnbId) {
434 sp<ILnb> lnb;
435 Result res;
436
437 mTuner->openLnbByName(name, [&](Result r, LnbId id, const sp<ILnb>& lnbSp) {
438 res = r;
439 lnb = lnbSp;
440 lnbId = id;
441 });
442 if (res != Result::SUCCESS || lnb == nullptr) {
443 ALOGE("Failed to open lnb by name");
444 return NULL;
445 }
446 return lnb;
447}
448
Amy Zhang39a3fa42020-12-21 16:56:03 -0800449vector<int> TunerClient::getLnbHandles() {
450 vector<int> lnbHandles;
Amy Zhang39a3fa42020-12-21 16:56:03 -0800451 if (mTuner != NULL) {
452 Result res;
453 vector<LnbId> lnbIds;
454 mTuner->getLnbIds([&](Result r, const hardware::hidl_vec<LnbId>& ids) {
455 lnbIds = ids;
456 res = r;
457 });
458 if (res != Result::SUCCESS || lnbIds.size() == 0) {
459 ALOGW("Lnb isn't available");
460 } else {
461 for (int i = 0; i < lnbIds.size(); i++) {
462 lnbHandles.push_back(getResourceHandleFromId((int)lnbIds[i], LNB));
463 }
464 }
465 }
466
467 return lnbHandles;
468}
469
Amy Zhang4a07e802021-01-21 17:10:21 -0800470sp<IDescrambler> TunerClient::openHidlDescrambler() {
471 sp<IDescrambler> descrambler;
472 Result res;
473
474 mTuner->openDescrambler([&](Result r, const sp<IDescrambler>& descramblerSp) {
475 res = r;
476 descrambler = descramblerSp;
477 });
478
479 if (res != Result::SUCCESS || descrambler == NULL) {
480 return NULL;
481 }
482
483 return descrambler;
484}
485
Amy Zhang952794662021-02-04 15:56:22 -0800486DemuxCapabilities TunerClient::getHidlDemuxCaps(TunerDemuxCapabilities& aidlCaps) {
487 DemuxCapabilities caps{
488 .numDemux = (uint32_t)aidlCaps.numDemux,
489 .numRecord = (uint32_t)aidlCaps.numRecord,
490 .numPlayback = (uint32_t)aidlCaps.numPlayback,
491 .numTsFilter = (uint32_t)aidlCaps.numTsFilter,
492 .numSectionFilter = (uint32_t)aidlCaps.numSectionFilter,
493 .numAudioFilter = (uint32_t)aidlCaps.numAudioFilter,
494 .numVideoFilter = (uint32_t)aidlCaps.numVideoFilter,
495 .numPesFilter = (uint32_t)aidlCaps.numPesFilter,
496 .numPcrFilter = (uint32_t)aidlCaps.numPcrFilter,
497 .numBytesInSectionFilter = (uint32_t)aidlCaps.numBytesInSectionFilter,
498 .filterCaps = (uint32_t)aidlCaps.filterCaps,
499 .bTimeFilter = aidlCaps.bTimeFilter,
500 };
501 caps.linkCaps.resize(aidlCaps.linkCaps.size());
502 copy(aidlCaps.linkCaps.begin(), aidlCaps.linkCaps.end(), caps.linkCaps.begin());
503 return caps;
504}
505
Amy Zhang379cb482021-02-04 21:05:11 -0800506FrontendInfo TunerClient::frontendInfoAidlToHidl(TunerFrontendInfo aidlFrontendInfo) {
Amy Zhangbf68a162020-11-23 17:42:40 -0800507 FrontendInfo hidlFrontendInfo {
508 .type = static_cast<FrontendType>(aidlFrontendInfo.type),
509 .minFrequency = static_cast<uint32_t>(aidlFrontendInfo.minFrequency),
510 .maxFrequency = static_cast<uint32_t>(aidlFrontendInfo.maxFrequency),
511 .minSymbolRate = static_cast<uint32_t>(aidlFrontendInfo.minSymbolRate),
512 .maxSymbolRate = static_cast<uint32_t>(aidlFrontendInfo.maxSymbolRate),
513 .acquireRange = static_cast<uint32_t>(aidlFrontendInfo.acquireRange),
514 .exclusiveGroupId = static_cast<uint32_t>(aidlFrontendInfo.exclusiveGroupId),
515 };
Amy Zhangbf68a162020-11-23 17:42:40 -0800516
Amy Zhang379cb482021-02-04 21:05:11 -0800517 int size = aidlFrontendInfo.statusCaps.size();
518 hidlFrontendInfo.statusCaps.resize(size);
519 for (int i = 0; i < size; i++) {
520 hidlFrontendInfo.statusCaps[i] =
521 static_cast<FrontendStatusType>(aidlFrontendInfo.statusCaps[i]);
522 }
523
524 switch (aidlFrontendInfo.caps.getTag()) {
525 case TunerFrontendCapabilities::analogCaps: {
526 auto analog = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::analogCaps>();
527 hidlFrontendInfo.frontendCaps.analogCaps({
528 .typeCap = static_cast<uint32_t>(analog.typeCap),
529 .sifStandardCap = static_cast<uint32_t>(analog.sifStandardCap),
530 });
531 break;
532 }
533 case TunerFrontendCapabilities::atscCaps: {
534 auto atsc = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::atscCaps>();
535 hidlFrontendInfo.frontendCaps.atscCaps({
536 .modulationCap = static_cast<uint32_t>(atsc.modulationCap),
537 });
538 break;
539 }
540 case TunerFrontendCapabilities::atsc3Caps: {
541 auto atsc3 = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::atsc3Caps>();
542 hidlFrontendInfo.frontendCaps.atsc3Caps({
543 .bandwidthCap = static_cast<uint32_t>(atsc3.bandwidthCap),
544 .modulationCap = static_cast<uint32_t>(atsc3.modulationCap),
545 .timeInterleaveModeCap = static_cast<uint32_t>(atsc3.timeInterleaveModeCap),
546 .codeRateCap = static_cast<uint32_t>(atsc3.codeRateCap),
547 .fecCap = static_cast<uint32_t>(atsc3.fecCap),
548 .demodOutputFormatCap = static_cast<uint8_t>(atsc3.demodOutputFormatCap),
549 });
550 break;
551 }
552 case TunerFrontendCapabilities::cableCaps: {
553 auto cable = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::cableCaps>();
554 hidlFrontendInfo.frontendCaps.dvbcCaps({
555 .modulationCap = static_cast<uint32_t>(cable.modulationCap),
556 .fecCap = static_cast<uint64_t>(cable.codeRateCap),
557 .annexCap = static_cast<uint8_t>(cable.annexCap),
558 });
559 break;
560 }
561 case TunerFrontendCapabilities::dvbsCaps: {
562 auto dvbs = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::dvbsCaps>();
563 hidlFrontendInfo.frontendCaps.dvbsCaps({
564 .modulationCap = static_cast<int32_t>(dvbs.modulationCap),
565 .innerfecCap = static_cast<uint64_t>(dvbs.codeRateCap),
566 .standard = static_cast<uint8_t>(dvbs.standard),
567 });
568 break;
569 }
570 case TunerFrontendCapabilities::dvbtCaps: {
571 auto dvbt = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::dvbtCaps>();
572 hidlFrontendInfo.frontendCaps.dvbtCaps({
573 .transmissionModeCap = static_cast<uint32_t>(dvbt.transmissionModeCap),
574 .bandwidthCap = static_cast<uint32_t>(dvbt.bandwidthCap),
575 .constellationCap = static_cast<uint32_t>(dvbt.constellationCap),
576 .coderateCap = static_cast<uint32_t>(dvbt.codeRateCap),
577 .hierarchyCap = static_cast<uint32_t>(dvbt.hierarchyCap),
578 .guardIntervalCap = static_cast<uint32_t>(dvbt.guardIntervalCap),
579 .isT2Supported = dvbt.isT2Supported,
580 .isMisoSupported = dvbt.isMisoSupported,
581 });
582 break;
583 }
584 case TunerFrontendCapabilities::isdbsCaps: {
585 auto isdbs = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbsCaps>();
586 hidlFrontendInfo.frontendCaps.isdbsCaps({
587 .modulationCap = static_cast<uint32_t>(isdbs.modulationCap),
588 .coderateCap = static_cast<uint32_t>(isdbs.codeRateCap),
589 });
590 break;
591 }
592 case TunerFrontendCapabilities::isdbs3Caps: {
593 auto isdbs3 = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbs3Caps>();
594 hidlFrontendInfo.frontendCaps.isdbs3Caps({
595 .modulationCap = static_cast<uint32_t>(isdbs3.modulationCap),
596 .coderateCap = static_cast<uint32_t>(isdbs3.codeRateCap),
597 });
598 break;
599 }
600 case TunerFrontendCapabilities::isdbtCaps: {
601 auto isdbt = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbtCaps>();
602 hidlFrontendInfo.frontendCaps.isdbtCaps({
603 .modeCap = static_cast<uint32_t>(isdbt.modeCap),
604 .bandwidthCap = static_cast<uint32_t>(isdbt.bandwidthCap),
605 .modulationCap = static_cast<uint32_t>(isdbt.modulationCap),
606 .coderateCap = static_cast<uint32_t>(isdbt.codeRateCap),
607 .guardIntervalCap = static_cast<uint32_t>(isdbt.guardIntervalCap),
608 });
609 break;
610 }
611 }
Amy Zhangbf68a162020-11-23 17:42:40 -0800612 return hidlFrontendInfo;
613}
Amy Zhang210c26a2021-01-12 11:25:27 -0800614
615int TunerClient::getResourceIdFromHandle(int handle, int /*resourceType*/) {
616 return (handle & 0x00ff0000) >> 16;
617}
618
619int TunerClient::getResourceHandleFromId(int id, int resourceType) {
620 // TODO: build up randomly generated id to handle mapping
621 return (resourceType & 0x000000ff) << 24
622 | (id << 16)
623 | (mResourceRequestCount++ & 0xffff);
624}
Amy Zhangbf68a162020-11-23 17:42:40 -0800625} // namespace android