| 1 | /* |
| 2 | * Copyright 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 | #ifndef _ANDROID_MEDIA_TV_TUNER_CLIENT_H_ |
| 18 | #define _ANDROID_MEDIA_TV_TUNER_CLIENT_H_ |
| 19 | |
| 20 | #include <aidl/android/media/tv/tuner/ITunerService.h> |
| 21 | #include <android/binder_parcel_utils.h> |
| 22 | |
| 23 | #include "ClientHelper.h" |
| 24 | #include "DemuxClient.h" |
| 25 | #include "DescramblerClient.h" |
| 26 | #include "FilterClient.h" |
| 27 | #include "FilterClientCallback.h" |
| 28 | #include "FrontendClient.h" |
| 29 | #include "LnbClient.h" |
| 30 | |
| 31 | using Status = ::ndk::ScopedAStatus; |
| 32 | |
| 33 | using ::aidl::android::hardware::tv::tuner::DemuxCapabilities; |
| 34 | using ::aidl::android::hardware::tv::tuner::FrontendInfo; |
| 35 | using ::aidl::android::hardware::tv::tuner::FrontendType; |
| 36 | using ::aidl::android::hardware::tv::tuner::Result; |
| 37 | using ::aidl::android::media::tv::tuner::ITunerService; |
| 38 | |
| 39 | using namespace std; |
| 40 | |
| 41 | namespace android { |
| 42 | |
| 43 | const static int32_t TUNER_HAL_VERSION_UNKNOWN = 0; |
| 44 | const static int32_t TUNER_HAL_VERSION_1_0 = 1 << 16; |
| 45 | const static int32_t TUNER_HAL_VERSION_1_1 = (1 << 16) | 1; |
| 46 | const static int32_t TUNER_HAL_VERSION_2_0 = 2 << 16; |
| 47 | |
| 48 | struct TunerClient : public RefBase { |
| 49 | |
| 50 | public: |
| 51 | TunerClient(); |
| 52 | ~TunerClient(); |
| 53 | |
| 54 | /** |
| 55 | * Retrieve all the frontend ids. |
| 56 | * |
| 57 | * @return a list of the available frontend ids |
| 58 | */ |
| 59 | vector<int32_t> getFrontendIds(); |
| 60 | |
| 61 | /** |
| 62 | * Open a new interface of FrontendClient given a frontendHandle. |
| 63 | * |
| 64 | * @param frontendHandle the handle of the frontend granted by TRM. |
| 65 | * @return a newly created FrontendClient interface. |
| 66 | */ |
| 67 | sp<FrontendClient> openFrontend(int32_t frontendHandle); |
| 68 | |
| 69 | /** |
| 70 | * Retrieve the granted frontend's information. |
| 71 | * |
| 72 | * @param id the id of the frontend granted by TRM. |
| 73 | * @return the information for the frontend. |
| 74 | */ |
| 75 | shared_ptr<FrontendInfo> getFrontendInfo(int32_t id); |
| 76 | |
| 77 | /** |
| 78 | * Open a new interface of DemuxClient given a demuxHandle. |
| 79 | * |
| 80 | * @param demuxHandle the handle of the demux granted by TRM. |
| 81 | * @return a newly created DemuxClient interface. |
| 82 | */ |
| 83 | sp<DemuxClient> openDemux(int32_t demuxHandle); |
| 84 | |
| 85 | /** |
| 86 | * Retrieve the Demux capabilities. |
| 87 | * |
| 88 | * @return the demux’s capabilities. |
| 89 | */ |
| 90 | shared_ptr<DemuxCapabilities> getDemuxCaps(); |
| 91 | |
| 92 | /** |
| 93 | * Open a new interface of DescramblerClient given a descramblerHandle. |
| 94 | * |
| 95 | * @param descramblerHandle the handle of the descrambler granted by TRM. |
| 96 | * @return a newly created DescramblerClient interface. |
| 97 | */ |
| 98 | sp<DescramblerClient> openDescrambler(int32_t descramblerHandle); |
| 99 | |
| 100 | /** |
| 101 | * Open a new interface of LnbClient given an lnbHandle. |
| 102 | * |
| 103 | * @param lnbHandle the handle of the LNB granted by TRM. |
| 104 | * @return a newly created LnbClient interface. |
| 105 | */ |
| 106 | sp<LnbClient> openLnb(int32_t lnbHandle); |
| 107 | |
| 108 | /** |
| 109 | * Open a new interface of LnbClient given a LNB name. |
| 110 | * |
| 111 | * @param lnbName the name for an external LNB to be opened. |
| 112 | * @return a newly created LnbClient interface. |
| 113 | */ |
| 114 | sp<LnbClient> openLnbByName(string lnbName); |
| 115 | |
| 116 | /** |
| 117 | * Get the current Tuner HAL version. The high 16 bits are the major version number |
| 118 | * while the low 16 bits are the minor version. Default value is unknown version 0. |
| 119 | */ |
| 120 | int32_t getHalTunerVersion() { return mTunerVersion; } |
| 121 | |
| 122 | /** |
| 123 | * Open a new shared filter client. |
| 124 | * |
| 125 | * @param filterToken the shared filter token created by FilterClient. |
| 126 | * @param cb the FilterClientCallback to receive filter events. |
| 127 | * @return a newly created TunerFilter interface. |
| 128 | */ |
| 129 | sp<FilterClient> openSharedFilter(const string& filterToken, sp<FilterClientCallback> cb); |
| 130 | |
| 131 | /** |
| 132 | * Enable or Disable Low Noise Amplifier (LNA). |
| 133 | */ |
| 134 | Result setLna(bool bEnable); |
| 135 | |
| 136 | /** |
| 137 | * Set the maximum frontend number of a given frontend type. |
| 138 | * |
| 139 | * @param frontendType the frontend type which maximum number will be set. |
| 140 | * @param maxNumber the new maximum number. |
| 141 | */ |
| 142 | Result setMaxNumberOfFrontends(FrontendType frontendType, int32_t maxNumber); |
| 143 | |
| 144 | /** |
| 145 | * Get the maximum frontend number of a given frontend type. |
| 146 | * |
| 147 | * @param frontendType the frontend type which maximum number will be queried. |
| 148 | */ |
| 149 | int getMaxNumberOfFrontends(FrontendType frontendType); |
| 150 | |
| 151 | private: |
| 152 | /** |
| 153 | * An AIDL Tuner Service Singleton assigned at the first time the Tuner Client |
| 154 | * connects with the Tuner Service. Default null when the service does not exist. |
| 155 | */ |
| 156 | static shared_ptr<ITunerService> mTunerService; |
| 157 | |
| 158 | // An integer that carries the Tuner version. The high 16 bits are the major version number |
| 159 | // while the low 16 bits are the minor version. Default value is unknown version 0. |
| 160 | static int32_t mTunerVersion; |
| 161 | }; |
| 162 | } // namespace android |
| 163 | |
| 164 | #endif // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_ |