/* * Copyright 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "TunerClient" #include #include #include #include "TunerClient.h" using ::aidl::android::hardware::tv::tuner::FrontendType; namespace android { int32_t TunerClient::mTunerVersion; /////////////// TunerClient /////////////////////// TunerClient::TunerClient() { ::ndk::SpAIBinder binder(AServiceManager_waitForService("media.tuner")); mTunerService = ITunerService::fromBinder(binder); if (mTunerService == nullptr) { ALOGE("Failed to get tuner service"); } else { mTunerService->getTunerHalVersion(&mTunerVersion); } } TunerClient::~TunerClient() { } vector TunerClient::getFrontendIds() { vector ids; if (mTunerService != nullptr) { Status s = mTunerService->getFrontendIds(&ids); if (!s.isOk()) { ids.clear(); } } return ids; } sp TunerClient::openFrontend(int32_t frontendHandle) { if (mTunerService != nullptr) { shared_ptr tunerFrontend; Status s = mTunerService->openFrontend(frontendHandle, &tunerFrontend); if (!s.isOk() || tunerFrontend == nullptr) { return nullptr; } int32_t id; s = tunerFrontend->getFrontendId(&id); if (!s.isOk()) { tunerFrontend->close(); return nullptr; } FrontendInfo frontendInfo; s = mTunerService->getFrontendInfo(id, &frontendInfo); if (!s.isOk()) { tunerFrontend->close(); return nullptr; } return new FrontendClient(tunerFrontend, frontendInfo.type); } return nullptr; } shared_ptr TunerClient::getFrontendInfo(int32_t id) { if (mTunerService != nullptr) { FrontendInfo aidlFrontendInfo; Status s = mTunerService->getFrontendInfo(id, &aidlFrontendInfo); if (!s.isOk()) { return nullptr; } return make_shared(aidlFrontendInfo); } return nullptr; } sp TunerClient::openDemux(int32_t demuxHandle) { if (mTunerService != nullptr) { shared_ptr tunerDemux; Status s = mTunerService->openDemux(demuxHandle, &tunerDemux); if (!s.isOk()) { return nullptr; } return new DemuxClient(tunerDemux); } return nullptr; } shared_ptr TunerClient::getDemuxInfo(int32_t demuxHandle) { if (mTunerService != nullptr) { DemuxInfo aidlDemuxInfo; Status s = mTunerService->getDemuxInfo(demuxHandle, &aidlDemuxInfo); if (!s.isOk()) { return nullptr; } return make_shared(aidlDemuxInfo); } return nullptr; } void TunerClient::getDemuxInfoList(vector* demuxInfoList) { if (mTunerService != nullptr) { Status s = mTunerService->getDemuxInfoList(demuxInfoList); if (!s.isOk()) { demuxInfoList->clear(); } } } shared_ptr TunerClient::getDemuxCaps() { if (mTunerService != nullptr) { DemuxCapabilities aidlCaps; Status s = mTunerService->getDemuxCaps(&aidlCaps); if (!s.isOk()) { return nullptr; } return make_shared(aidlCaps); } return nullptr; } sp TunerClient::openDescrambler(int32_t descramblerHandle) { if (mTunerService != nullptr) { shared_ptr tunerDescrambler; Status s = mTunerService->openDescrambler(descramblerHandle, &tunerDescrambler); if (!s.isOk()) { return nullptr; } return new DescramblerClient(tunerDescrambler); } return nullptr; } sp TunerClient::openLnb(int32_t lnbHandle) { if (mTunerService != nullptr) { shared_ptr tunerLnb; Status s = mTunerService->openLnb(lnbHandle, &tunerLnb); if (!s.isOk()) { return nullptr; } return new LnbClient(tunerLnb); } return nullptr; } sp TunerClient::openLnbByName(string lnbName) { if (mTunerService != nullptr) { shared_ptr tunerLnb; Status s = mTunerService->openLnbByName(lnbName, &tunerLnb); if (!s.isOk()) { return nullptr; } return new LnbClient(tunerLnb); } return nullptr; } sp TunerClient::openSharedFilter(const string& filterToken, sp cb) { if (cb == nullptr) { return nullptr; } if (mTunerService != nullptr) { shared_ptr tunerFilter; shared_ptr callback = ::ndk::SharedRefBase::make(cb); Status s = mTunerService->openSharedFilter(filterToken, callback, &tunerFilter); if (!s.isOk()) { return nullptr; } DemuxFilterType type; tunerFilter->getFilterType(&type); return new FilterClient(type, tunerFilter); } return nullptr; } Result TunerClient::setLna(bool bEnable) { if (mTunerService != nullptr) { Status s = mTunerService->setLna(bEnable); return ClientHelper::getServiceSpecificErrorCode(s); } return Result::INVALID_STATE; } Result TunerClient::setMaxNumberOfFrontends(FrontendType frontendType, int32_t maxNumber) { if (mTunerService != nullptr) { Status s = mTunerService->setMaxNumberOfFrontends(frontendType, maxNumber); return ClientHelper::getServiceSpecificErrorCode(s); } return Result::INVALID_STATE; } int TunerClient::getMaxNumberOfFrontends(FrontendType frontendType) { if (mTunerService != nullptr) { int32_t maxNumber; mTunerService->getMaxNumberOfFrontends(frontendType, &maxNumber); return maxNumber; } return -1; } bool TunerClient::isLnaSupported() { if (mTunerService != nullptr) { bool lnaSupported; Status s = mTunerService->isLnaSupported(&lnaSupported); if (!s.isOk()) { return false; } return lnaSupported; } return false; } } // namespace android