/* * Copyright 2020 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. */ #ifndef _ANDROID_MEDIA_TV_TUNER_CLIENT_H_ #define _ANDROID_MEDIA_TV_TUNER_CLIENT_H_ #include #include #include #include #include #include #include "DemuxClient.h" #include "ClientHelper.h" #include "FrontendClient.h" #include "DescramblerClient.h" #include "LnbClient.h" using Status = ::ndk::ScopedAStatus; using ::aidl::android::media::tv::tuner::TunerDemuxCapabilities; using ::aidl::android::media::tv::tuner::ITunerService; using ::aidl::android::media::tv::tuner::TunerFrontendInfo; using ::aidl::android::media::tv::tunerresourcemanager::ITunerResourceManager; using ::android::hardware::tv::tuner::V1_0::DemuxCapabilities; using ::android::hardware::tv::tuner::V1_0::FrontendId; using ::android::hardware::tv::tuner::V1_0::ITuner; using ::android::hardware::tv::tuner::V1_0::LnbId; using ::android::hardware::tv::tuner::V1_0::Result; using ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities; using namespace std; namespace android { const static int TUNER_HAL_VERSION_UNKNOWN = 0; const static int TUNER_HAL_VERSION_1_0 = 1 << 16; const static int TUNER_HAL_VERSION_1_1 = (1 << 16) | 1; typedef enum { FRONTEND, LNB, DEMUX, DESCRAMBLER, } TunerResourceType; struct TunerClient : public RefBase { public: TunerClient(); ~TunerClient(); /** * Retrieve all the frontend ids. * * @return a list of the available frontend ids */ vector getFrontendIds(); /** * Open a new interface of FrontendClient given a frontendHandle. * * @param frontendHandle the handle of the frontend granted by TRM. * @return a newly created FrontendClient interface. */ sp openFrontend(int frontendHandle); /** * Retrieve the granted frontend's information. * * @param id the id of the frontend granted by TRM. * @return the information for the frontend. */ shared_ptr getFrontendInfo(int id); /** * Retrieve the DTMB frontend's capabilities. * * @param id the id of the DTMB frontend. * @return the capabilities of the frontend. */ shared_ptr getFrontendDtmbCapabilities(int id); /** * Open a new interface of DemuxClient given a demuxHandle. * * @param demuxHandle the handle of the demux granted by TRM. * @return a newly created DemuxClient interface. */ sp openDemux(int demuxHandle); /** * Retrieve the Demux capabilities. * * @return the demux’s capabilities. */ shared_ptr getDemuxCaps(); /** * Open a new interface of DescramblerClient given a descramblerHandle. * * @param descramblerHandle the handle of the descrambler granted by TRM. * @return a newly created DescramblerClient interface. */ sp openDescrambler(int descramblerHandle); /** * Open a new interface of LnbClient given an lnbHandle. * * @param lnbHandle the handle of the LNB granted by TRM. * @return a newly created LnbClient interface. */ sp openLnb(int lnbHandle); /** * Open a new interface of LnbClient given a LNB name. * * @param lnbName the name for an external LNB to be opened. * @return a newly created LnbClient interface. */ sp openLnbByName(string lnbName); /** * Get the current Tuner HAL version. The high 16 bits are the major version number * while the low 16 bits are the minor version. Default value is unknown version 0. */ int getHalTunerVersion() { return mTunerVersion; } private: sp getHidlTuner(); sp openHidlFrontendById(int id); sp openHidlDemux(int& demuxId); Result getHidlFrontendInfo(int id, FrontendInfo& info); sp openHidlLnbById(int id); sp openHidlLnbByName(string name, LnbId& lnbId); sp openHidlDescrambler(); vector getLnbHandles(); DemuxCapabilities getHidlDemuxCaps(TunerDemuxCapabilities& aidlCaps); FrontendInfo frontendInfoAidlToHidl(TunerFrontendInfo aidlFrontendInfo); void updateTunerResources(); void updateFrontendResources(); void updateLnbResources(); int getResourceIdFromHandle(int handle, int resourceType); int getResourceHandleFromId(int id, int resourceType); /** * An AIDL Tuner Service Singleton assigned at the first time the Tuner Client * connects with the Tuner Service. Default null when the service does not exist. */ static shared_ptr mTunerService; /** * A Tuner 1.0 HAL interface that is ready before connecting to the TunerService * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. * Default null. */ static sp mTuner; /** * A Tuner 1.1 HAL interface that is ready before connecting to the TunerService * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. * Default null. */ static sp<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1; // An integer that carries the Tuner version. The high 16 bits are the major version number // while the low 16 bits are the minor version. Default value is unknown version 0. static int mTunerVersion; shared_ptr mTunerResourceManager; int mResourceRequestCount = 0; }; } // namespace android #endif // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_