blob: 7f954b561567c6b3cb9294e67f891bcb015a3f34 [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);
Amy Zhang9a9ed602020-12-07 16:37:33 -080049 // TODO: Remove after JNI migration is done.
50 mTunerService = NULL;
Amy Zhangbf68a162020-11-23 17:42:40 -080051 if (mTunerService == NULL) {
52 ALOGE("Failed to get tuner service");
Amy Zhang9eeba432021-01-21 12:52:05 -080053 } else {
54 // TODO: b/178124017 update TRM in TunerService independently.
55 mTunerService->updateTunerResources();
Amy Zhangbf68a162020-11-23 17:42:40 -080056 }
57}
58
59TunerClient::~TunerClient() {
60 mTuner = NULL;
61 mTuner_1_1 = NULL;
62 mTunerVersion = 0;
63 mTunerService = NULL;
64}
65
66vector<FrontendId> TunerClient::getFrontendIds() {
67 vector<FrontendId> ids;
shubang68f32a32020-12-29 00:34:24 -080068
69 if (mTunerService != NULL) {
70 vector<int32_t> v;
Amy Zhang9eeba432021-01-21 12:52:05 -080071 Status s = mTunerService->getFrontendIds(&v);
Amy Zhang4a07e802021-01-21 17:10:21 -080072 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS || v.size() == 0) {
shubang68f32a32020-12-29 00:34:24 -080073 ids.clear();
74 return ids;
75 }
76 for (int32_t id : v) {
77 ids.push_back(static_cast<FrontendId>(id));
78 }
79 return ids;
80 }
Amy Zhangbf68a162020-11-23 17:42:40 -080081
82 if (mTuner != NULL) {
83 Result res;
84 mTuner->getFrontendIds([&](Result r, const hardware::hidl_vec<FrontendId>& frontendIds) {
85 res = r;
86 ids = frontendIds;
87 });
88 if (res != Result::SUCCESS || ids.size() == 0) {
89 ALOGW("Frontend ids not available");
90 ids.clear();
91 return ids;
92 }
93 return ids;
94 }
95
96 return ids;
97}
98
99
100sp<FrontendClient> TunerClient::openFrontend(int frontendHandle) {
101 if (mTunerService != NULL) {
Amy Zhangbf68a162020-11-23 17:42:40 -0800102 shared_ptr<ITunerFrontend> tunerFrontend;
Amy Zhang4a07e802021-01-21 17:10:21 -0800103 Status s = mTunerService->openFrontend(frontendHandle, &tunerFrontend);
104 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS
105 || tunerFrontend == NULL) {
Amy Zhangb9f3cab2021-01-13 15:24:14 -0800106 return NULL;
107 }
108 int id;
Amy Zhang4a07e802021-01-21 17:10:21 -0800109 s = tunerFrontend->getFrontendId(&id);
110 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
111 return NULL;
112 }
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800113 TunerFrontendInfo aidlFrontendInfo;
Amy Zhang4a07e802021-01-21 17:10:21 -0800114 s = mTunerService->getFrontendInfo(id, &aidlFrontendInfo);
115 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
116 return NULL;
117 }
Amy Zhangb9f3cab2021-01-13 15:24:14 -0800118 return new FrontendClient(tunerFrontend, frontendHandle, aidlFrontendInfo.type);
Amy Zhangbf68a162020-11-23 17:42:40 -0800119 }
120
121 if (mTuner != NULL) {
Amy Zhang210c26a2021-01-12 11:25:27 -0800122 int id = getResourceIdFromHandle(frontendHandle, FRONTEND);
123 sp<IFrontend> hidlFrontend = openHidlFrontendById(id);
Amy Zhangbf68a162020-11-23 17:42:40 -0800124 if (hidlFrontend != NULL) {
Amy Zhangb9f3cab2021-01-13 15:24:14 -0800125 FrontendInfo hidlInfo;
126 Result res = getHidlFrontendInfo(id, hidlInfo);
127 if (res != Result::SUCCESS) {
128 return NULL;
129 }
130 sp<FrontendClient> frontendClient = new FrontendClient(NULL, id, (int)hidlInfo.type);
Amy Zhangbf68a162020-11-23 17:42:40 -0800131 frontendClient->setHidlFrontend(hidlFrontend);
132 return frontendClient;
133 }
134 }
135
136 return NULL;
137}
138
139shared_ptr<FrontendInfo> TunerClient::getFrontendInfo(int id) {
140 if (mTunerService != NULL) {
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800141 TunerFrontendInfo aidlFrontendInfo;
Amy Zhang4a07e802021-01-21 17:10:21 -0800142 Status s = mTunerService->getFrontendInfo(id, &aidlFrontendInfo);
143 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
144 return NULL;
145 }
Amy Zhang379cb482021-02-04 21:05:11 -0800146 return make_shared<FrontendInfo>(frontendInfoAidlToHidl(aidlFrontendInfo));
Amy Zhangbf68a162020-11-23 17:42:40 -0800147 }
148
149 if (mTuner != NULL) {
150 FrontendInfo hidlInfo;
151 Result res = getHidlFrontendInfo(id, hidlInfo);
152 if (res != Result::SUCCESS) {
153 return NULL;
154 }
155 return make_shared<FrontendInfo>(hidlInfo);
156 }
157
158 return NULL;
159}
160
161shared_ptr<FrontendDtmbCapabilities> TunerClient::getFrontendDtmbCapabilities(int id) {
Amy Zhang379cb482021-02-04 21:05:11 -0800162 if (mTunerService != NULL) {
163 TunerFrontendDtmbCapabilities dtmbCaps;
164 Status s = mTunerService->getFrontendDtmbCapabilities(id, &dtmbCaps);
165 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
166 return NULL;
167 }
168 FrontendDtmbCapabilities hidlCaps{
169 .transmissionModeCap = static_cast<uint32_t>(dtmbCaps.transmissionModeCap),
170 .bandwidthCap = static_cast<uint32_t>(dtmbCaps.bandwidthCap),
171 .modulationCap = static_cast<uint32_t>(dtmbCaps.modulationCap),
172 .codeRateCap = static_cast<uint32_t>(dtmbCaps.codeRateCap),
173 .guardIntervalCap = static_cast<uint32_t>(dtmbCaps.guardIntervalCap),
174 .interleaveModeCap = static_cast<uint32_t>(dtmbCaps.interleaveModeCap),
175 };
176 return make_shared<FrontendDtmbCapabilities>(hidlCaps);
177 }
Amy Zhangbf68a162020-11-23 17:42:40 -0800178
179 if (mTuner_1_1 != NULL) {
180 Result result;
181 FrontendDtmbCapabilities dtmbCaps;
182 mTuner_1_1->getFrontendDtmbCapabilities(id,
183 [&](Result r, const FrontendDtmbCapabilities& caps) {
184 dtmbCaps = caps;
185 result = r;
186 });
187 if (result == Result::SUCCESS) {
188 return make_shared<FrontendDtmbCapabilities>(dtmbCaps);
189 }
190 }
191
192 return NULL;
193}
194
Amy Zhang4a07e802021-01-21 17:10:21 -0800195sp<DemuxClient> TunerClient::openDemux(int demuxHandle) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800196 if (mTunerService != NULL) {
Amy Zhang4a07e802021-01-21 17:10:21 -0800197 shared_ptr<ITunerDemux> tunerDemux;
198 Status s = mTunerService->openDemux(demuxHandle, &tunerDemux);
199 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
200 return NULL;
201 }
202 return new DemuxClient(tunerDemux);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800203 }
204
205 if (mTuner != NULL) {
Amy Zhang4a07e802021-01-21 17:10:21 -0800206 sp<DemuxClient> demuxClient = new DemuxClient(NULL);
Amy Zhang921fd432021-01-07 13:18:27 -0800207 int demuxId;
208 sp<IDemux> hidlDemux = openHidlDemux(demuxId);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800209 if (hidlDemux != NULL) {
210 demuxClient->setHidlDemux(hidlDemux);
Amy Zhang921fd432021-01-07 13:18:27 -0800211 demuxClient->setId(demuxId);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800212 return demuxClient;
213 }
214 }
215
216 return NULL;
217}
218
Amy Zhang90a50b42021-01-11 16:58:59 -0800219shared_ptr<DemuxCapabilities> TunerClient::getDemuxCaps() {
Amy Zhang952794662021-02-04 15:56:22 -0800220 if (mTunerService != NULL) {
221 TunerDemuxCapabilities aidlCaps;
222 Status s = mTunerService->getDemuxCaps(&aidlCaps);
223 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
224 return NULL;
225 }
226 return make_shared<DemuxCapabilities>(getHidlDemuxCaps(aidlCaps));
227 }
Amy Zhang90a50b42021-01-11 16:58:59 -0800228
229 if (mTuner != NULL) {
230 Result res;
231 DemuxCapabilities caps;
232 mTuner->getDemuxCaps([&](Result r, const DemuxCapabilities& demuxCaps) {
233 caps = demuxCaps;
234 res = r;
235 });
236 if (res == Result::SUCCESS) {
237 return make_shared<DemuxCapabilities>(caps);
238 }
239 }
240
241 return NULL;
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800242}
243
Amy Zhang38261c32021-02-03 20:38:52 -0800244sp<DescramblerClient> TunerClient::openDescrambler(int descramblerHandle) {
Amy Zhang921fd432021-01-07 13:18:27 -0800245 if (mTunerService != NULL) {
Amy Zhang38261c32021-02-03 20:38:52 -0800246 shared_ptr<ITunerDescrambler> tunerDescrambler;
247 Status s = mTunerService->openDescrambler(descramblerHandle, &tunerDescrambler);
248 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
249 return NULL;
250 }
251 return new DescramblerClient(tunerDescrambler);
Amy Zhang921fd432021-01-07 13:18:27 -0800252 }
253
254 if (mTuner != NULL) {
Amy Zhang38261c32021-02-03 20:38:52 -0800255 sp<DescramblerClient> descramblerClient = new DescramblerClient(NULL);
Amy Zhang921fd432021-01-07 13:18:27 -0800256 sp<IDescrambler> hidlDescrambler = openHidlDescrambler();
257 if (hidlDescrambler != NULL) {
258 descramblerClient->setHidlDescrambler(hidlDescrambler);
259 return descramblerClient;
260 }
261 }
262
Amy Zhangb5809be2021-01-26 16:27:23 -0800263 return NULL;
264}
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800265
Amy Zhangd3d57b42021-01-07 11:14:43 -0800266sp<LnbClient> TunerClient::openLnb(int lnbHandle) {
267 if (mTunerService != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800268 shared_ptr<ITunerLnb> tunerLnb;
Amy Zhang4a07e802021-01-21 17:10:21 -0800269 Status s = mTunerService->openLnb(lnbHandle, &tunerLnb);
270 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
271 return NULL;
272 }
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800273 return new LnbClient(tunerLnb);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800274 }
275
276 if (mTuner != NULL) {
277 int id = getResourceIdFromHandle(lnbHandle, LNB);
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800278 sp<LnbClient> lnbClient = new LnbClient(NULL);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800279 sp<ILnb> hidlLnb = openHidlLnbById(id);
280 if (hidlLnb != NULL) {
281 lnbClient->setHidlLnb(hidlLnb);
282 lnbClient->setId(id);
283 return lnbClient;
284 }
285 }
286
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800287 return NULL;
288}
289
Amy Zhangd3d57b42021-01-07 11:14:43 -0800290sp<LnbClient> TunerClient::openLnbByName(string lnbName) {
291 if (mTunerService != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800292 shared_ptr<ITunerLnb> tunerLnb;
Amy Zhang4a07e802021-01-21 17:10:21 -0800293 Status s = mTunerService->openLnbByName(lnbName, &tunerLnb);
294 if (ClientHelper::getServiceSpecificErrorCode(s) != Result::SUCCESS) {
295 return NULL;
296 }
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800297 return new LnbClient(tunerLnb);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800298 }
299
300 if (mTuner != NULL) {
Amy Zhang3ac0a3e2021-01-14 18:55:10 -0800301 sp<LnbClient> lnbClient = new LnbClient(NULL);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800302 LnbId id;
303 sp<ILnb> hidlLnb = openHidlLnbByName(lnbName, id);
304 if (hidlLnb != NULL) {
305 lnbClient->setHidlLnb(hidlLnb);
306 lnbClient->setId(id);
307 return lnbClient;
308 }
309 }
310
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800311 return NULL;
312}
313
Amy Zhangbf68a162020-11-23 17:42:40 -0800314/////////////// TunerClient Helper Methods ///////////////////////
315
Amy Zhang39a3fa42020-12-21 16:56:03 -0800316void TunerClient::updateTunerResources() {
317 if (mTuner == NULL) {
318 return;
319 }
320
321 // Connect with Tuner Resource Manager.
322 ::ndk::SpAIBinder binder(AServiceManager_getService("tv_tuner_resource_mgr"));
323 mTunerResourceManager = ITunerResourceManager::fromBinder(binder);
324
325 updateFrontendResources();
326 updateLnbResources();
327 // TODO: update Demux, Descrambler.
328}
329
330void TunerClient::updateFrontendResources() {
331 vector<FrontendId> ids = getFrontendIds();
332 if (ids.size() == 0) {
333 return;
334 }
335 vector<TunerFrontendInfo> infos;
336 for (int i = 0; i < ids.size(); i++) {
337 shared_ptr<FrontendInfo> frontendInfo = getFrontendInfo((int)ids[i]);
338 if (frontendInfo == NULL) {
339 continue;
340 }
341 TunerFrontendInfo tunerFrontendInfo{
342 .handle = getResourceHandleFromId((int)ids[i], FRONTEND),
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800343 .type = static_cast<int>(frontendInfo->type),
Amy Zhang39a3fa42020-12-21 16:56:03 -0800344 .exclusiveGroupId = static_cast<int>(frontendInfo->exclusiveGroupId),
345 };
346 infos.push_back(tunerFrontendInfo);
347 }
348 mTunerResourceManager->setFrontendInfoList(infos);
349}
350
351void TunerClient::updateLnbResources() {
352 vector<int> handles = getLnbHandles();
353 if (handles.size() == 0) {
354 return;
355 }
356 mTunerResourceManager->setLnbInfoList(handles);
357}
358
Amy Zhangbf68a162020-11-23 17:42:40 -0800359sp<ITuner> TunerClient::getHidlTuner() {
360 if (mTuner == NULL) {
361 mTunerVersion = 0;
362 mTuner_1_1 = ::android::hardware::tv::tuner::V1_1::ITuner::getService();
363
364 if (mTuner_1_1 == NULL) {
365 ALOGW("Failed to get tuner 1.1 service.");
366 mTuner = ITuner::getService();
367 if (mTuner == NULL) {
368 ALOGW("Failed to get tuner 1.0 service.");
369 } else {
370 mTunerVersion = 1 << 16;
371 }
372 } else {
373 mTuner = static_cast<sp<ITuner>>(mTuner_1_1);
374 mTunerVersion = ((1 << 16) | 1);
375 }
376 }
377 return mTuner;
378}
379
Amy Zhang210c26a2021-01-12 11:25:27 -0800380sp<IFrontend> TunerClient::openHidlFrontendById(int id) {
Amy Zhangbf68a162020-11-23 17:42:40 -0800381 sp<IFrontend> fe;
382 Result res;
Amy Zhangbf68a162020-11-23 17:42:40 -0800383 mTuner->openFrontendById(id, [&](Result r, const sp<IFrontend>& frontend) {
384 fe = frontend;
385 res = r;
386 });
387 if (res != Result::SUCCESS || fe == nullptr) {
388 ALOGE("Failed to open frontend");
389 return NULL;
390 }
391 return fe;
392}
393
394Result TunerClient::getHidlFrontendInfo(int id, FrontendInfo& feInfo) {
395 Result res;
396 mTuner->getFrontendInfo(id, [&](Result r, const FrontendInfo& info) {
397 feInfo = info;
398 res = r;
399 });
400 return res;
401}
402
Amy Zhang921fd432021-01-07 13:18:27 -0800403sp<IDemux> TunerClient::openHidlDemux(int& demuxId) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800404 sp<IDemux> demux;
405 Result res;
406
Amy Zhang921fd432021-01-07 13:18:27 -0800407 mTuner->openDemux([&](Result result, uint32_t id, const sp<IDemux>& demuxSp) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800408 demux = demuxSp;
Amy Zhang921fd432021-01-07 13:18:27 -0800409 demuxId = id;
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800410 res = result;
411 });
412 if (res != Result::SUCCESS || demux == nullptr) {
413 ALOGE("Failed to open demux");
414 return NULL;
415 }
416 return demux;
417}
418
Amy Zhangd3d57b42021-01-07 11:14:43 -0800419sp<ILnb> TunerClient::openHidlLnbById(int id) {
420 sp<ILnb> lnb;
421 Result res;
422
423 mTuner->openLnbById(id, [&](Result r, const sp<ILnb>& lnbSp) {
424 res = r;
425 lnb = lnbSp;
426 });
427 if (res != Result::SUCCESS || lnb == nullptr) {
428 ALOGE("Failed to open lnb by id");
429 return NULL;
430 }
431 return lnb;
432}
433
434sp<ILnb> TunerClient::openHidlLnbByName(string name, LnbId& lnbId) {
435 sp<ILnb> lnb;
436 Result res;
437
438 mTuner->openLnbByName(name, [&](Result r, LnbId id, const sp<ILnb>& lnbSp) {
439 res = r;
440 lnb = lnbSp;
441 lnbId = id;
442 });
443 if (res != Result::SUCCESS || lnb == nullptr) {
444 ALOGE("Failed to open lnb by name");
445 return NULL;
446 }
447 return lnb;
448}
449
Amy Zhang39a3fa42020-12-21 16:56:03 -0800450vector<int> TunerClient::getLnbHandles() {
451 vector<int> lnbHandles;
Amy Zhang39a3fa42020-12-21 16:56:03 -0800452 if (mTuner != NULL) {
453 Result res;
454 vector<LnbId> lnbIds;
455 mTuner->getLnbIds([&](Result r, const hardware::hidl_vec<LnbId>& ids) {
456 lnbIds = ids;
457 res = r;
458 });
459 if (res != Result::SUCCESS || lnbIds.size() == 0) {
460 ALOGW("Lnb isn't available");
461 } else {
462 for (int i = 0; i < lnbIds.size(); i++) {
463 lnbHandles.push_back(getResourceHandleFromId((int)lnbIds[i], LNB));
464 }
465 }
466 }
467
468 return lnbHandles;
469}
470
Amy Zhang4a07e802021-01-21 17:10:21 -0800471sp<IDescrambler> TunerClient::openHidlDescrambler() {
472 sp<IDescrambler> descrambler;
473 Result res;
474
475 mTuner->openDescrambler([&](Result r, const sp<IDescrambler>& descramblerSp) {
476 res = r;
477 descrambler = descramblerSp;
478 });
479
480 if (res != Result::SUCCESS || descrambler == NULL) {
481 return NULL;
482 }
483
484 return descrambler;
485}
486
Amy Zhang952794662021-02-04 15:56:22 -0800487DemuxCapabilities TunerClient::getHidlDemuxCaps(TunerDemuxCapabilities& aidlCaps) {
488 DemuxCapabilities caps{
489 .numDemux = (uint32_t)aidlCaps.numDemux,
490 .numRecord = (uint32_t)aidlCaps.numRecord,
491 .numPlayback = (uint32_t)aidlCaps.numPlayback,
492 .numTsFilter = (uint32_t)aidlCaps.numTsFilter,
493 .numSectionFilter = (uint32_t)aidlCaps.numSectionFilter,
494 .numAudioFilter = (uint32_t)aidlCaps.numAudioFilter,
495 .numVideoFilter = (uint32_t)aidlCaps.numVideoFilter,
496 .numPesFilter = (uint32_t)aidlCaps.numPesFilter,
497 .numPcrFilter = (uint32_t)aidlCaps.numPcrFilter,
498 .numBytesInSectionFilter = (uint32_t)aidlCaps.numBytesInSectionFilter,
499 .filterCaps = (uint32_t)aidlCaps.filterCaps,
500 .bTimeFilter = aidlCaps.bTimeFilter,
501 };
502 caps.linkCaps.resize(aidlCaps.linkCaps.size());
503 copy(aidlCaps.linkCaps.begin(), aidlCaps.linkCaps.end(), caps.linkCaps.begin());
504 return caps;
505}
506
Amy Zhang379cb482021-02-04 21:05:11 -0800507FrontendInfo TunerClient::frontendInfoAidlToHidl(TunerFrontendInfo aidlFrontendInfo) {
Amy Zhangbf68a162020-11-23 17:42:40 -0800508 FrontendInfo hidlFrontendInfo {
509 .type = static_cast<FrontendType>(aidlFrontendInfo.type),
510 .minFrequency = static_cast<uint32_t>(aidlFrontendInfo.minFrequency),
511 .maxFrequency = static_cast<uint32_t>(aidlFrontendInfo.maxFrequency),
512 .minSymbolRate = static_cast<uint32_t>(aidlFrontendInfo.minSymbolRate),
513 .maxSymbolRate = static_cast<uint32_t>(aidlFrontendInfo.maxSymbolRate),
514 .acquireRange = static_cast<uint32_t>(aidlFrontendInfo.acquireRange),
515 .exclusiveGroupId = static_cast<uint32_t>(aidlFrontendInfo.exclusiveGroupId),
516 };
Amy Zhangbf68a162020-11-23 17:42:40 -0800517
Amy Zhang379cb482021-02-04 21:05:11 -0800518 int size = aidlFrontendInfo.statusCaps.size();
519 hidlFrontendInfo.statusCaps.resize(size);
520 for (int i = 0; i < size; i++) {
521 hidlFrontendInfo.statusCaps[i] =
522 static_cast<FrontendStatusType>(aidlFrontendInfo.statusCaps[i]);
523 }
524
525 switch (aidlFrontendInfo.caps.getTag()) {
526 case TunerFrontendCapabilities::analogCaps: {
527 auto analog = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::analogCaps>();
528 hidlFrontendInfo.frontendCaps.analogCaps({
529 .typeCap = static_cast<uint32_t>(analog.typeCap),
530 .sifStandardCap = static_cast<uint32_t>(analog.sifStandardCap),
531 });
532 break;
533 }
534 case TunerFrontendCapabilities::atscCaps: {
535 auto atsc = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::atscCaps>();
536 hidlFrontendInfo.frontendCaps.atscCaps({
537 .modulationCap = static_cast<uint32_t>(atsc.modulationCap),
538 });
539 break;
540 }
541 case TunerFrontendCapabilities::atsc3Caps: {
542 auto atsc3 = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::atsc3Caps>();
543 hidlFrontendInfo.frontendCaps.atsc3Caps({
544 .bandwidthCap = static_cast<uint32_t>(atsc3.bandwidthCap),
545 .modulationCap = static_cast<uint32_t>(atsc3.modulationCap),
546 .timeInterleaveModeCap = static_cast<uint32_t>(atsc3.timeInterleaveModeCap),
547 .codeRateCap = static_cast<uint32_t>(atsc3.codeRateCap),
548 .fecCap = static_cast<uint32_t>(atsc3.fecCap),
549 .demodOutputFormatCap = static_cast<uint8_t>(atsc3.demodOutputFormatCap),
550 });
551 break;
552 }
553 case TunerFrontendCapabilities::cableCaps: {
554 auto cable = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::cableCaps>();
555 hidlFrontendInfo.frontendCaps.dvbcCaps({
556 .modulationCap = static_cast<uint32_t>(cable.modulationCap),
557 .fecCap = static_cast<uint64_t>(cable.codeRateCap),
558 .annexCap = static_cast<uint8_t>(cable.annexCap),
559 });
560 break;
561 }
562 case TunerFrontendCapabilities::dvbsCaps: {
563 auto dvbs = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::dvbsCaps>();
564 hidlFrontendInfo.frontendCaps.dvbsCaps({
565 .modulationCap = static_cast<int32_t>(dvbs.modulationCap),
566 .innerfecCap = static_cast<uint64_t>(dvbs.codeRateCap),
567 .standard = static_cast<uint8_t>(dvbs.standard),
568 });
569 break;
570 }
571 case TunerFrontendCapabilities::dvbtCaps: {
572 auto dvbt = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::dvbtCaps>();
573 hidlFrontendInfo.frontendCaps.dvbtCaps({
574 .transmissionModeCap = static_cast<uint32_t>(dvbt.transmissionModeCap),
575 .bandwidthCap = static_cast<uint32_t>(dvbt.bandwidthCap),
576 .constellationCap = static_cast<uint32_t>(dvbt.constellationCap),
577 .coderateCap = static_cast<uint32_t>(dvbt.codeRateCap),
578 .hierarchyCap = static_cast<uint32_t>(dvbt.hierarchyCap),
579 .guardIntervalCap = static_cast<uint32_t>(dvbt.guardIntervalCap),
580 .isT2Supported = dvbt.isT2Supported,
581 .isMisoSupported = dvbt.isMisoSupported,
582 });
583 break;
584 }
585 case TunerFrontendCapabilities::isdbsCaps: {
586 auto isdbs = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbsCaps>();
587 hidlFrontendInfo.frontendCaps.isdbsCaps({
588 .modulationCap = static_cast<uint32_t>(isdbs.modulationCap),
589 .coderateCap = static_cast<uint32_t>(isdbs.codeRateCap),
590 });
591 break;
592 }
593 case TunerFrontendCapabilities::isdbs3Caps: {
594 auto isdbs3 = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbs3Caps>();
595 hidlFrontendInfo.frontendCaps.isdbs3Caps({
596 .modulationCap = static_cast<uint32_t>(isdbs3.modulationCap),
597 .coderateCap = static_cast<uint32_t>(isdbs3.codeRateCap),
598 });
599 break;
600 }
601 case TunerFrontendCapabilities::isdbtCaps: {
602 auto isdbt = aidlFrontendInfo.caps.get<TunerFrontendCapabilities::isdbtCaps>();
603 hidlFrontendInfo.frontendCaps.isdbtCaps({
604 .modeCap = static_cast<uint32_t>(isdbt.modeCap),
605 .bandwidthCap = static_cast<uint32_t>(isdbt.bandwidthCap),
606 .modulationCap = static_cast<uint32_t>(isdbt.modulationCap),
607 .coderateCap = static_cast<uint32_t>(isdbt.codeRateCap),
608 .guardIntervalCap = static_cast<uint32_t>(isdbt.guardIntervalCap),
609 });
610 break;
611 }
612 }
Amy Zhangbf68a162020-11-23 17:42:40 -0800613 return hidlFrontendInfo;
614}
Amy Zhang210c26a2021-01-12 11:25:27 -0800615
616int TunerClient::getResourceIdFromHandle(int handle, int /*resourceType*/) {
617 return (handle & 0x00ff0000) >> 16;
618}
619
620int TunerClient::getResourceHandleFromId(int id, int resourceType) {
621 // TODO: build up randomly generated id to handle mapping
622 return (resourceType & 0x000000ff) << 24
623 | (id << 16)
624 | (mResourceRequestCount++ & 0xffff);
625}
Amy Zhangbf68a162020-11-23 17:42:40 -0800626} // namespace android