Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 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 "TunerHidlService" |
| 19 | |
| 20 | #include "TunerHidlService.h" |
| 21 | |
Hongguang | 15758a8 | 2021-10-29 13:32:07 -0700 | [diff] [blame^] | 22 | #include <aidl/android/hardware/tv/tuner/FrontendIsdbtTimeInterleaveMode.h> |
Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 23 | #include <aidl/android/hardware/tv/tuner/Result.h> |
| 24 | #include <android/binder_manager.h> |
Hongguang | 34a479e | 2021-10-04 16:14:47 -0700 | [diff] [blame] | 25 | #include <binder/IPCThreadState.h> |
| 26 | #include <binder/PermissionCache.h> |
Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 27 | #include <utils/Log.h> |
| 28 | |
| 29 | #include "TunerHelper.h" |
| 30 | #include "TunerHidlDemux.h" |
| 31 | #include "TunerHidlDescrambler.h" |
| 32 | #include "TunerHidlFrontend.h" |
| 33 | #include "TunerHidlLnb.h" |
| 34 | |
| 35 | using ::aidl::android::hardware::tv::tuner::FrontendAnalogCapabilities; |
| 36 | using ::aidl::android::hardware::tv::tuner::FrontendAtsc3Capabilities; |
| 37 | using ::aidl::android::hardware::tv::tuner::FrontendAtscCapabilities; |
| 38 | using ::aidl::android::hardware::tv::tuner::FrontendCapabilities; |
| 39 | using ::aidl::android::hardware::tv::tuner::FrontendDtmbCapabilities; |
| 40 | using ::aidl::android::hardware::tv::tuner::FrontendDvbcCapabilities; |
| 41 | using ::aidl::android::hardware::tv::tuner::FrontendDvbsCapabilities; |
| 42 | using ::aidl::android::hardware::tv::tuner::FrontendDvbtCapabilities; |
| 43 | using ::aidl::android::hardware::tv::tuner::FrontendIsdbs3Capabilities; |
| 44 | using ::aidl::android::hardware::tv::tuner::FrontendIsdbsCapabilities; |
| 45 | using ::aidl::android::hardware::tv::tuner::FrontendIsdbtCapabilities; |
Hongguang | 15758a8 | 2021-10-29 13:32:07 -0700 | [diff] [blame^] | 46 | using ::aidl::android::hardware::tv::tuner::FrontendIsdbtTimeInterleaveMode; |
Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 47 | using ::aidl::android::hardware::tv::tuner::FrontendType; |
| 48 | using ::aidl::android::hardware::tv::tuner::Result; |
| 49 | using ::aidl::android::media::tv::tunerresourcemanager::TunerFrontendInfo; |
Hongguang | 34a479e | 2021-10-04 16:14:47 -0700 | [diff] [blame] | 50 | using ::android::IPCThreadState; |
| 51 | using ::android::PermissionCache; |
Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 52 | using ::android::hardware::hidl_vec; |
| 53 | |
| 54 | using HidlFrontendId = ::android::hardware::tv::tuner::V1_0::FrontendId; |
| 55 | using HidlLnbId = ::android::hardware::tv::tuner::V1_0::LnbId; |
| 56 | using HidlFrontendType = ::android::hardware::tv::tuner::V1_1::FrontendType; |
| 57 | |
| 58 | using namespace std; |
| 59 | |
| 60 | namespace aidl { |
| 61 | namespace android { |
| 62 | namespace media { |
| 63 | namespace tv { |
| 64 | namespace tuner { |
| 65 | |
Hongguang | 34a479e | 2021-10-04 16:14:47 -0700 | [diff] [blame] | 66 | shared_ptr<TunerHidlService> TunerHidlService::sTunerService = nullptr; |
| 67 | |
Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 68 | TunerHidlService::TunerHidlService() { |
| 69 | if (!TunerHelper::checkTunerFeature()) { |
| 70 | ALOGD("Device doesn't have tuner hardware."); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | updateTunerResources(); |
| 75 | } |
| 76 | |
| 77 | TunerHidlService::~TunerHidlService() {} |
| 78 | |
| 79 | binder_status_t TunerHidlService::instantiate() { |
| 80 | if (HidlITuner::getService() == nullptr) { |
| 81 | ALOGD("Failed to get ITuner HIDL HAL"); |
| 82 | return STATUS_NAME_NOT_FOUND; |
| 83 | } |
| 84 | |
Hongguang | 34a479e | 2021-10-04 16:14:47 -0700 | [diff] [blame] | 85 | sTunerService = ::ndk::SharedRefBase::make<TunerHidlService>(); |
| 86 | return AServiceManager_addService(sTunerService->asBinder().get(), getServiceName()); |
| 87 | } |
| 88 | |
| 89 | shared_ptr<TunerHidlService> TunerHidlService::getTunerService() { |
| 90 | return sTunerService; |
Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | bool TunerHidlService::hasITuner() { |
| 94 | ALOGV("hasITuner"); |
| 95 | if (mTuner != nullptr) { |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | mTuner = HidlITuner::getService(); |
| 100 | if (mTuner == nullptr) { |
| 101 | ALOGE("Failed to get ITuner service"); |
| 102 | return false; |
| 103 | } |
| 104 | mTunerVersion = TUNER_HAL_VERSION_1_0; |
| 105 | |
| 106 | mTuner_1_1 = ::android::hardware::tv::tuner::V1_1::ITuner::castFrom(mTuner); |
| 107 | if (mTuner_1_1 != nullptr) { |
| 108 | mTunerVersion = TUNER_HAL_VERSION_1_1; |
| 109 | } else { |
| 110 | ALOGD("Failed to get ITuner_1_1 service"); |
| 111 | } |
| 112 | |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | bool TunerHidlService::hasITuner_1_1() { |
| 117 | ALOGV("hasITuner_1_1"); |
| 118 | hasITuner(); |
| 119 | return (mTunerVersion == TUNER_HAL_VERSION_1_1); |
| 120 | } |
| 121 | |
| 122 | ::ndk::ScopedAStatus TunerHidlService::openDemux(int32_t /* in_demuxHandle */, |
| 123 | shared_ptr<ITunerDemux>* _aidl_return) { |
| 124 | ALOGV("openDemux"); |
| 125 | if (!hasITuner()) { |
| 126 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 127 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 128 | } |
| 129 | |
| 130 | HidlResult res; |
| 131 | uint32_t id; |
| 132 | sp<IDemux> demuxSp = nullptr; |
| 133 | mTuner->openDemux([&](HidlResult r, uint32_t demuxId, const sp<IDemux>& demux) { |
| 134 | demuxSp = demux; |
| 135 | id = demuxId; |
| 136 | res = r; |
| 137 | ALOGD("open demux, id = %d", demuxId); |
| 138 | }); |
| 139 | if (res == HidlResult::SUCCESS) { |
| 140 | *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlDemux>(demuxSp, id); |
| 141 | return ::ndk::ScopedAStatus::ok(); |
| 142 | } |
| 143 | |
| 144 | ALOGW("open demux failed, res = %d", res); |
| 145 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 146 | } |
| 147 | |
| 148 | ::ndk::ScopedAStatus TunerHidlService::getDemuxCaps(DemuxCapabilities* _aidl_return) { |
| 149 | ALOGV("getDemuxCaps"); |
| 150 | if (!hasITuner()) { |
| 151 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 152 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 153 | } |
| 154 | |
| 155 | HidlResult res; |
| 156 | HidlDemuxCapabilities caps; |
| 157 | mTuner->getDemuxCaps([&](HidlResult r, const HidlDemuxCapabilities& demuxCaps) { |
| 158 | caps = demuxCaps; |
| 159 | res = r; |
| 160 | }); |
| 161 | if (res == HidlResult::SUCCESS) { |
| 162 | *_aidl_return = getAidlDemuxCaps(caps); |
| 163 | return ::ndk::ScopedAStatus::ok(); |
| 164 | } |
| 165 | |
| 166 | ALOGW("Get demux caps failed, res = %d", res); |
| 167 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 168 | } |
| 169 | |
| 170 | ::ndk::ScopedAStatus TunerHidlService::getFrontendIds(vector<int32_t>* ids) { |
| 171 | if (!hasITuner()) { |
| 172 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 173 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 174 | } |
| 175 | |
| 176 | hidl_vec<HidlFrontendId> feIds; |
| 177 | HidlResult res = getHidlFrontendIds(feIds); |
| 178 | if (res != HidlResult::SUCCESS) { |
| 179 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 180 | } |
| 181 | ids->resize(feIds.size()); |
| 182 | copy(feIds.begin(), feIds.end(), ids->begin()); |
| 183 | |
| 184 | return ::ndk::ScopedAStatus::ok(); |
| 185 | } |
| 186 | |
| 187 | ::ndk::ScopedAStatus TunerHidlService::getFrontendInfo(int32_t id, FrontendInfo* _aidl_return) { |
| 188 | if (!hasITuner()) { |
| 189 | ALOGE("ITuner service is not init."); |
| 190 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 191 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 192 | } |
| 193 | |
| 194 | HidlFrontendInfo info; |
| 195 | HidlResult res = getHidlFrontendInfo(id, info); |
| 196 | if (res != HidlResult::SUCCESS) { |
| 197 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 198 | } |
| 199 | |
| 200 | HidlFrontendDtmbCapabilities dtmbCaps; |
| 201 | if (static_cast<HidlFrontendType>(info.type) == HidlFrontendType::DTMB) { |
| 202 | if (!hasITuner_1_1()) { |
| 203 | ALOGE("ITuner_1_1 service is not init."); |
| 204 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 205 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 206 | } |
| 207 | |
| 208 | mTuner_1_1->getFrontendDtmbCapabilities( |
| 209 | id, [&](HidlResult r, const HidlFrontendDtmbCapabilities& caps) { |
| 210 | dtmbCaps = caps; |
| 211 | res = r; |
| 212 | }); |
| 213 | if (res != HidlResult::SUCCESS) { |
| 214 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | *_aidl_return = getAidlFrontendInfo(info, dtmbCaps); |
| 219 | return ::ndk::ScopedAStatus::ok(); |
| 220 | } |
| 221 | |
| 222 | ::ndk::ScopedAStatus TunerHidlService::openFrontend(int32_t frontendHandle, |
| 223 | shared_ptr<ITunerFrontend>* _aidl_return) { |
| 224 | if (!hasITuner()) { |
| 225 | ALOGE("ITuner service is not init."); |
| 226 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 227 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 228 | } |
| 229 | |
| 230 | HidlResult status; |
| 231 | sp<HidlIFrontend> frontend; |
| 232 | int id = TunerHelper::getResourceIdFromHandle(frontendHandle, FRONTEND); |
| 233 | mTuner->openFrontendById(id, [&](HidlResult result, const sp<HidlIFrontend>& fe) { |
| 234 | frontend = fe; |
| 235 | status = result; |
| 236 | }); |
| 237 | if (status != HidlResult::SUCCESS) { |
| 238 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 239 | } |
| 240 | *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlFrontend>(frontend, id); |
| 241 | return ::ndk::ScopedAStatus::ok(); |
| 242 | } |
| 243 | |
| 244 | ::ndk::ScopedAStatus TunerHidlService::openLnb(int lnbHandle, shared_ptr<ITunerLnb>* _aidl_return) { |
| 245 | if (!hasITuner()) { |
| 246 | ALOGD("get ITuner failed"); |
| 247 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 248 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 249 | } |
| 250 | |
| 251 | HidlResult status; |
| 252 | sp<HidlILnb> lnb; |
| 253 | int id = TunerHelper::getResourceIdFromHandle(lnbHandle, LNB); |
| 254 | mTuner->openLnbById(id, [&](HidlResult result, const sp<HidlILnb>& lnbSp) { |
| 255 | lnb = lnbSp; |
| 256 | status = result; |
| 257 | }); |
| 258 | if (status != HidlResult::SUCCESS) { |
| 259 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 260 | } |
| 261 | |
| 262 | *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlLnb>(lnb, id); |
| 263 | return ::ndk::ScopedAStatus::ok(); |
| 264 | } |
| 265 | |
| 266 | ::ndk::ScopedAStatus TunerHidlService::openLnbByName(const string& lnbName, |
| 267 | shared_ptr<ITunerLnb>* _aidl_return) { |
| 268 | if (!hasITuner()) { |
| 269 | ALOGE("get ITuner failed"); |
| 270 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 271 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 272 | } |
| 273 | |
| 274 | int lnbId; |
| 275 | HidlResult status; |
| 276 | sp<HidlILnb> lnb; |
| 277 | mTuner->openLnbByName(lnbName, [&](HidlResult r, HidlLnbId id, const sp<HidlILnb>& lnbSp) { |
| 278 | status = r; |
| 279 | lnb = lnbSp; |
| 280 | lnbId = static_cast<int32_t>(id); |
| 281 | }); |
| 282 | if (status != HidlResult::SUCCESS) { |
| 283 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 284 | } |
| 285 | |
| 286 | *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlLnb>(lnb, lnbId); |
| 287 | return ::ndk::ScopedAStatus::ok(); |
| 288 | } |
| 289 | |
| 290 | ::ndk::ScopedAStatus TunerHidlService::openDescrambler( |
| 291 | int32_t /*descramblerHandle*/, shared_ptr<ITunerDescrambler>* _aidl_return) { |
| 292 | if (!hasITuner()) { |
| 293 | ALOGD("get ITuner failed"); |
| 294 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 295 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 296 | } |
| 297 | |
| 298 | HidlResult status; |
| 299 | sp<HidlIDescrambler> descrambler; |
| 300 | //int id = TunerHelper::getResourceIdFromHandle(descramblerHandle, DESCRAMBLER); |
| 301 | mTuner->openDescrambler([&](HidlResult r, const sp<HidlIDescrambler>& descramblerSp) { |
| 302 | status = r; |
| 303 | descrambler = descramblerSp; |
| 304 | }); |
| 305 | if (status != HidlResult::SUCCESS) { |
| 306 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 307 | } |
| 308 | |
| 309 | *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlDescrambler>(descrambler); |
| 310 | return ::ndk::ScopedAStatus::ok(); |
| 311 | } |
| 312 | |
| 313 | ::ndk::ScopedAStatus TunerHidlService::getTunerHalVersion(int* _aidl_return) { |
| 314 | hasITuner(); |
| 315 | *_aidl_return = mTunerVersion; |
| 316 | return ::ndk::ScopedAStatus::ok(); |
| 317 | } |
| 318 | |
Hongguang | 34a479e | 2021-10-04 16:14:47 -0700 | [diff] [blame] | 319 | ::ndk::ScopedAStatus TunerHidlService::openSharedFilter( |
| 320 | const string& in_filterToken, const shared_ptr<ITunerFilterCallback>& in_cb, |
| 321 | shared_ptr<ITunerFilter>* _aidl_return) { |
| 322 | if (!hasITuner()) { |
| 323 | ALOGE("get ITuner failed"); |
| 324 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 325 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 326 | } |
| 327 | |
| 328 | if (!PermissionCache::checkCallingPermission(sSharedFilterPermission)) { |
| 329 | ALOGE("Request requires android.permission.ACCESS_TV_SHARED_FILTER"); |
| 330 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 331 | static_cast<int32_t>(Result::UNAVAILABLE)); |
| 332 | } |
| 333 | |
| 334 | Mutex::Autolock _l(mSharedFiltersLock); |
| 335 | if (mSharedFilters.find(in_filterToken) == mSharedFilters.end()) { |
| 336 | *_aidl_return = nullptr; |
| 337 | ALOGD("fail to find %s", in_filterToken.c_str()); |
| 338 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 339 | static_cast<int32_t>(Result::INVALID_STATE)); |
| 340 | } |
| 341 | |
| 342 | shared_ptr<TunerHidlFilter> filter = mSharedFilters.at(in_filterToken); |
| 343 | IPCThreadState* ipc = IPCThreadState::self(); |
| 344 | const int pid = ipc->getCallingPid(); |
| 345 | if (!filter->isSharedFilterAllowed(pid)) { |
| 346 | *_aidl_return = nullptr; |
| 347 | ALOGD("shared filter %s is opened in the same process", in_filterToken.c_str()); |
| 348 | return ::ndk::ScopedAStatus::fromServiceSpecificError( |
| 349 | static_cast<int32_t>(Result::INVALID_STATE)); |
| 350 | } |
| 351 | |
| 352 | filter->attachSharedFilterCallback(in_cb); |
| 353 | |
| 354 | *_aidl_return = filter; |
| 355 | return ::ndk::ScopedAStatus::ok(); |
| 356 | } |
| 357 | |
| 358 | string TunerHidlService::addFilterToShared(const shared_ptr<TunerHidlFilter>& sharedFilter) { |
| 359 | Mutex::Autolock _l(mSharedFiltersLock); |
| 360 | |
| 361 | // Use sharedFilter address as token. |
| 362 | string token = to_string(reinterpret_cast<std::uintptr_t>(sharedFilter.get())); |
| 363 | mSharedFilters[token] = sharedFilter; |
| 364 | |
| 365 | return token; |
| 366 | } |
| 367 | |
| 368 | void TunerHidlService::removeSharedFilter(const shared_ptr<TunerHidlFilter>& sharedFilter) { |
| 369 | Mutex::Autolock _l(mSharedFiltersLock); |
| 370 | |
| 371 | // Use sharedFilter address as token. |
| 372 | mSharedFilters.erase(to_string(reinterpret_cast<std::uintptr_t>(sharedFilter.get()))); |
| 373 | } |
| 374 | |
Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 375 | void TunerHidlService::updateTunerResources() { |
| 376 | if (!hasITuner()) { |
| 377 | ALOGE("Failed to updateTunerResources"); |
| 378 | return; |
| 379 | } |
| 380 | |
| 381 | TunerHelper::updateTunerResources(getTRMFrontendInfos(), getTRMLnbHandles()); |
| 382 | } |
| 383 | |
| 384 | vector<TunerFrontendInfo> TunerHidlService::getTRMFrontendInfos() { |
| 385 | vector<TunerFrontendInfo> infos; |
| 386 | hidl_vec<HidlFrontendId> ids; |
| 387 | HidlResult res = getHidlFrontendIds(ids); |
| 388 | if (res != HidlResult::SUCCESS) { |
| 389 | return infos; |
| 390 | } |
| 391 | |
| 392 | for (int i = 0; i < ids.size(); i++) { |
| 393 | HidlFrontendInfo frontendInfo; |
| 394 | HidlResult res = getHidlFrontendInfo(static_cast<int32_t>(ids[i]), frontendInfo); |
| 395 | if (res != HidlResult::SUCCESS) { |
| 396 | continue; |
| 397 | } |
| 398 | TunerFrontendInfo tunerFrontendInfo{ |
| 399 | .handle = TunerHelper::getResourceHandleFromId(static_cast<int32_t>(ids[i]), |
| 400 | FRONTEND), |
| 401 | .type = static_cast<int32_t>(frontendInfo.type), |
| 402 | .exclusiveGroupId = static_cast<int32_t>(frontendInfo.exclusiveGroupId), |
| 403 | }; |
| 404 | infos.push_back(tunerFrontendInfo); |
| 405 | } |
| 406 | |
| 407 | return infos; |
| 408 | } |
| 409 | |
| 410 | vector<int32_t> TunerHidlService::getTRMLnbHandles() { |
| 411 | vector<int32_t> lnbHandles; |
| 412 | if (mTuner != nullptr) { |
| 413 | HidlResult res; |
| 414 | vector<HidlLnbId> lnbIds; |
| 415 | mTuner->getLnbIds([&](HidlResult r, const hidl_vec<HidlLnbId>& ids) { |
| 416 | lnbIds = ids; |
| 417 | res = r; |
| 418 | }); |
| 419 | if (res == HidlResult::SUCCESS && lnbIds.size() > 0) { |
| 420 | for (int i = 0; i < lnbIds.size(); i++) { |
| 421 | lnbHandles.push_back( |
| 422 | TunerHelper::getResourceHandleFromId(static_cast<int32_t>(lnbIds[i]), LNB)); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | return lnbHandles; |
| 428 | } |
| 429 | |
| 430 | HidlResult TunerHidlService::getHidlFrontendIds(hidl_vec<HidlFrontendId>& ids) { |
| 431 | if (mTuner == nullptr) { |
| 432 | return HidlResult::NOT_INITIALIZED; |
| 433 | } |
| 434 | HidlResult res; |
| 435 | mTuner->getFrontendIds([&](HidlResult r, const hidl_vec<HidlFrontendId>& frontendIds) { |
| 436 | ids = frontendIds; |
| 437 | res = r; |
| 438 | }); |
| 439 | return res; |
| 440 | } |
| 441 | |
| 442 | HidlResult TunerHidlService::getHidlFrontendInfo(const int id, HidlFrontendInfo& info) { |
| 443 | if (mTuner == nullptr) { |
| 444 | return HidlResult::NOT_INITIALIZED; |
| 445 | } |
| 446 | HidlResult res; |
| 447 | mTuner->getFrontendInfo(id, [&](HidlResult r, const HidlFrontendInfo& feInfo) { |
| 448 | info = feInfo; |
| 449 | res = r; |
| 450 | }); |
| 451 | return res; |
| 452 | } |
| 453 | |
| 454 | DemuxCapabilities TunerHidlService::getAidlDemuxCaps(const HidlDemuxCapabilities& caps) { |
| 455 | DemuxCapabilities aidlCaps{ |
| 456 | .numDemux = static_cast<int32_t>(caps.numDemux), |
| 457 | .numRecord = static_cast<int32_t>(caps.numRecord), |
| 458 | .numPlayback = static_cast<int32_t>(caps.numPlayback), |
| 459 | .numTsFilter = static_cast<int32_t>(caps.numTsFilter), |
| 460 | .numSectionFilter = static_cast<int32_t>(caps.numSectionFilter), |
| 461 | .numAudioFilter = static_cast<int32_t>(caps.numAudioFilter), |
| 462 | .numVideoFilter = static_cast<int32_t>(caps.numVideoFilter), |
| 463 | .numPesFilter = static_cast<int32_t>(caps.numPesFilter), |
| 464 | .numPcrFilter = static_cast<int32_t>(caps.numPcrFilter), |
| 465 | .numBytesInSectionFilter = static_cast<int64_t>(caps.numBytesInSectionFilter), |
| 466 | .filterCaps = static_cast<int32_t>(caps.filterCaps), |
| 467 | .bTimeFilter = caps.bTimeFilter, |
| 468 | }; |
| 469 | aidlCaps.linkCaps.resize(caps.linkCaps.size()); |
| 470 | copy(caps.linkCaps.begin(), caps.linkCaps.end(), aidlCaps.linkCaps.begin()); |
| 471 | return aidlCaps; |
| 472 | } |
| 473 | |
| 474 | FrontendInfo TunerHidlService::getAidlFrontendInfo( |
| 475 | const HidlFrontendInfo& halInfo, const HidlFrontendDtmbCapabilities& halDtmbCaps) { |
| 476 | FrontendInfo info{ |
| 477 | .type = static_cast<FrontendType>(halInfo.type), |
| 478 | .minFrequency = static_cast<int64_t>(halInfo.minFrequency), |
| 479 | .maxFrequency = static_cast<int64_t>(halInfo.maxFrequency), |
| 480 | .minSymbolRate = static_cast<int32_t>(halInfo.minSymbolRate), |
| 481 | .maxSymbolRate = static_cast<int32_t>(halInfo.maxSymbolRate), |
| 482 | .acquireRange = static_cast<int64_t>(halInfo.acquireRange), |
| 483 | .exclusiveGroupId = static_cast<int32_t>(halInfo.exclusiveGroupId), |
| 484 | }; |
| 485 | for (int i = 0; i < halInfo.statusCaps.size(); i++) { |
| 486 | info.statusCaps.push_back(static_cast<FrontendStatusType>(halInfo.statusCaps[i])); |
| 487 | } |
| 488 | |
| 489 | FrontendCapabilities caps; |
| 490 | switch (halInfo.type) { |
| 491 | case ::android::hardware::tv::tuner::V1_0::FrontendType::ANALOG: { |
| 492 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::analogCaps == |
| 493 | halInfo.frontendCaps.getDiscriminator()) { |
| 494 | FrontendAnalogCapabilities analogCaps{ |
| 495 | .typeCap = static_cast<int32_t>(halInfo.frontendCaps.analogCaps().typeCap), |
| 496 | .sifStandardCap = |
| 497 | static_cast<int32_t>(halInfo.frontendCaps.analogCaps().sifStandardCap), |
| 498 | }; |
| 499 | caps.set<FrontendCapabilities::analogCaps>(analogCaps); |
| 500 | } |
| 501 | break; |
| 502 | } |
| 503 | case ::android::hardware::tv::tuner::V1_0::FrontendType::ATSC: { |
| 504 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::atscCaps == |
| 505 | halInfo.frontendCaps.getDiscriminator()) { |
| 506 | FrontendAtscCapabilities atscCaps{ |
| 507 | .modulationCap = |
| 508 | static_cast<int32_t>(halInfo.frontendCaps.atscCaps().modulationCap), |
| 509 | }; |
| 510 | caps.set<FrontendCapabilities::atscCaps>(atscCaps); |
| 511 | } |
| 512 | break; |
| 513 | } |
| 514 | case ::android::hardware::tv::tuner::V1_0::FrontendType::ATSC3: { |
| 515 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::atsc3Caps == |
| 516 | halInfo.frontendCaps.getDiscriminator()) { |
| 517 | FrontendAtsc3Capabilities atsc3Caps{ |
| 518 | .bandwidthCap = |
| 519 | static_cast<int32_t>(halInfo.frontendCaps.atsc3Caps().bandwidthCap), |
| 520 | .modulationCap = |
| 521 | static_cast<int32_t>(halInfo.frontendCaps.atsc3Caps().modulationCap), |
| 522 | .timeInterleaveModeCap = static_cast<int32_t>( |
| 523 | halInfo.frontendCaps.atsc3Caps().timeInterleaveModeCap), |
| 524 | .codeRateCap = |
| 525 | static_cast<int32_t>(halInfo.frontendCaps.atsc3Caps().codeRateCap), |
| 526 | .demodOutputFormatCap = static_cast<int8_t>( |
| 527 | halInfo.frontendCaps.atsc3Caps().demodOutputFormatCap), |
| 528 | .fecCap = static_cast<int32_t>(halInfo.frontendCaps.atsc3Caps().fecCap), |
| 529 | }; |
| 530 | caps.set<FrontendCapabilities::atsc3Caps>(atsc3Caps); |
| 531 | } |
| 532 | break; |
| 533 | } |
| 534 | case ::android::hardware::tv::tuner::V1_0::FrontendType::DVBC: { |
| 535 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::dvbcCaps == |
| 536 | halInfo.frontendCaps.getDiscriminator()) { |
| 537 | FrontendDvbcCapabilities dvbcCaps{ |
| 538 | .modulationCap = |
| 539 | static_cast<int32_t>(halInfo.frontendCaps.dvbcCaps().modulationCap), |
| 540 | .fecCap = static_cast<int64_t>(halInfo.frontendCaps.dvbcCaps().fecCap), |
| 541 | .annexCap = static_cast<int8_t>(halInfo.frontendCaps.dvbcCaps().annexCap), |
| 542 | }; |
| 543 | caps.set<FrontendCapabilities::dvbcCaps>(dvbcCaps); |
| 544 | } |
| 545 | break; |
| 546 | } |
| 547 | case ::android::hardware::tv::tuner::V1_0::FrontendType::DVBS: { |
| 548 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::dvbsCaps == |
| 549 | halInfo.frontendCaps.getDiscriminator()) { |
| 550 | FrontendDvbsCapabilities dvbsCaps{ |
| 551 | .modulationCap = |
| 552 | static_cast<int32_t>(halInfo.frontendCaps.dvbsCaps().modulationCap), |
| 553 | .innerfecCap = |
| 554 | static_cast<int64_t>(halInfo.frontendCaps.dvbsCaps().innerfecCap), |
| 555 | .standard = static_cast<int8_t>(halInfo.frontendCaps.dvbsCaps().standard), |
| 556 | }; |
| 557 | caps.set<FrontendCapabilities::dvbsCaps>(dvbsCaps); |
| 558 | } |
| 559 | break; |
| 560 | } |
| 561 | case ::android::hardware::tv::tuner::V1_0::FrontendType::DVBT: { |
| 562 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::dvbtCaps == |
| 563 | halInfo.frontendCaps.getDiscriminator()) { |
| 564 | FrontendDvbtCapabilities dvbtCaps{ |
| 565 | .transmissionModeCap = static_cast<int32_t>( |
| 566 | halInfo.frontendCaps.dvbtCaps().transmissionModeCap), |
| 567 | .bandwidthCap = |
| 568 | static_cast<int32_t>(halInfo.frontendCaps.dvbtCaps().bandwidthCap), |
| 569 | .constellationCap = |
| 570 | static_cast<int32_t>(halInfo.frontendCaps.dvbtCaps().constellationCap), |
| 571 | .coderateCap = |
| 572 | static_cast<int32_t>(halInfo.frontendCaps.dvbtCaps().coderateCap), |
| 573 | .hierarchyCap = |
| 574 | static_cast<int32_t>(halInfo.frontendCaps.dvbtCaps().hierarchyCap), |
| 575 | .guardIntervalCap = |
| 576 | static_cast<int32_t>(halInfo.frontendCaps.dvbtCaps().guardIntervalCap), |
| 577 | .isT2Supported = halInfo.frontendCaps.dvbtCaps().isT2Supported, |
| 578 | .isMisoSupported = halInfo.frontendCaps.dvbtCaps().isMisoSupported, |
| 579 | }; |
| 580 | caps.set<FrontendCapabilities::dvbtCaps>(dvbtCaps); |
| 581 | } |
| 582 | break; |
| 583 | } |
| 584 | case ::android::hardware::tv::tuner::V1_0::FrontendType::ISDBS: { |
| 585 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::isdbsCaps == |
| 586 | halInfo.frontendCaps.getDiscriminator()) { |
| 587 | FrontendIsdbsCapabilities isdbsCaps{ |
| 588 | .modulationCap = |
| 589 | static_cast<int32_t>(halInfo.frontendCaps.isdbsCaps().modulationCap), |
| 590 | .coderateCap = |
| 591 | static_cast<int32_t>(halInfo.frontendCaps.isdbsCaps().coderateCap), |
| 592 | }; |
| 593 | caps.set<FrontendCapabilities::isdbsCaps>(isdbsCaps); |
| 594 | } |
| 595 | break; |
| 596 | } |
| 597 | case ::android::hardware::tv::tuner::V1_0::FrontendType::ISDBS3: { |
| 598 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::isdbs3Caps == |
| 599 | halInfo.frontendCaps.getDiscriminator()) { |
| 600 | FrontendIsdbs3Capabilities isdbs3Caps{ |
| 601 | .modulationCap = |
| 602 | static_cast<int32_t>(halInfo.frontendCaps.isdbs3Caps().modulationCap), |
| 603 | .coderateCap = |
| 604 | static_cast<int32_t>(halInfo.frontendCaps.isdbs3Caps().coderateCap), |
| 605 | }; |
| 606 | caps.set<FrontendCapabilities::isdbs3Caps>(isdbs3Caps); |
| 607 | } |
| 608 | break; |
| 609 | } |
| 610 | case ::android::hardware::tv::tuner::V1_0::FrontendType::ISDBT: { |
| 611 | if (HidlFrontendInfo::FrontendCapabilities::hidl_discriminator::isdbtCaps == |
| 612 | halInfo.frontendCaps.getDiscriminator()) { |
| 613 | FrontendIsdbtCapabilities isdbtCaps{ |
| 614 | .modeCap = static_cast<int32_t>(halInfo.frontendCaps.isdbtCaps().modeCap), |
| 615 | .bandwidthCap = |
| 616 | static_cast<int32_t>(halInfo.frontendCaps.isdbtCaps().bandwidthCap), |
| 617 | .modulationCap = |
| 618 | static_cast<int32_t>(halInfo.frontendCaps.isdbtCaps().modulationCap), |
| 619 | .coderateCap = |
| 620 | static_cast<int32_t>(halInfo.frontendCaps.isdbtCaps().coderateCap), |
| 621 | .guardIntervalCap = |
| 622 | static_cast<int32_t>(halInfo.frontendCaps.isdbtCaps().guardIntervalCap), |
Hongguang | 15758a8 | 2021-10-29 13:32:07 -0700 | [diff] [blame^] | 623 | .timeInterleaveCap = |
| 624 | static_cast<int32_t>(FrontendIsdbtTimeInterleaveMode::UNDEFINED), |
| 625 | .isSegmentAuto = false, |
| 626 | .isFullSegment = false, |
Hongguang | 093c5f3 | 2021-08-09 19:46:34 -0700 | [diff] [blame] | 627 | }; |
| 628 | caps.set<FrontendCapabilities::isdbtCaps>(isdbtCaps); |
| 629 | } |
| 630 | break; |
| 631 | } |
| 632 | default: { |
| 633 | if (static_cast<HidlFrontendType>(info.type) == HidlFrontendType::DTMB) { |
| 634 | FrontendDtmbCapabilities dtmbCaps{ |
| 635 | .transmissionModeCap = static_cast<int32_t>(halDtmbCaps.transmissionModeCap), |
| 636 | .bandwidthCap = static_cast<int32_t>(halDtmbCaps.bandwidthCap), |
| 637 | .modulationCap = static_cast<int32_t>(halDtmbCaps.modulationCap), |
| 638 | .codeRateCap = static_cast<int32_t>(halDtmbCaps.codeRateCap), |
| 639 | .guardIntervalCap = static_cast<int32_t>(halDtmbCaps.guardIntervalCap), |
| 640 | .interleaveModeCap = static_cast<int32_t>(halDtmbCaps.interleaveModeCap), |
| 641 | }; |
| 642 | caps.set<FrontendCapabilities::dtmbCaps>(dtmbCaps); |
| 643 | } |
| 644 | break; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | info.frontendCaps = caps; |
| 649 | return info; |
| 650 | } |
| 651 | |
| 652 | } // namespace tuner |
| 653 | } // namespace tv |
| 654 | } // namespace media |
| 655 | } // namespace android |
| 656 | } // namespace aidl |