Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 1 | /* |
| 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 | #ifndef _ANDROID_MEDIA_TV_TUNER_CLIENT_H_ |
| 18 | #define _ANDROID_MEDIA_TV_TUNER_CLIENT_H_ |
| 19 | |
Amy Zhang | 39a3fa4 | 2020-12-21 16:56:03 -0800 | [diff] [blame] | 20 | #include <aidl/android/media/tv/tunerresourcemanager/ITunerResourceManager.h> |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 21 | #include <aidl/android/media/tv/tuner/ITunerService.h> |
Amy Zhang | d1fd5ac | 2021-01-13 16:30:24 -0800 | [diff] [blame^] | 22 | #include <aidl/android/media/tv/tuner/TunerFrontendInfo.h> |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 23 | #include <android/hardware/tv/tuner/1.1/ITuner.h> |
| 24 | #include <android/hardware/tv/tuner/1.1/types.h> |
| 25 | |
| 26 | #include "FrontendClient.h" |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 27 | #include "DemuxClient.h" |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 28 | #include "DescramblerClient.h" |
| 29 | #include "LnbClient.h" |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 30 | |
| 31 | using ::aidl::android::media::tv::tuner::ITunerService; |
Amy Zhang | d1fd5ac | 2021-01-13 16:30:24 -0800 | [diff] [blame^] | 32 | using ::aidl::android::media::tv::tuner::TunerFrontendInfo; |
Amy Zhang | 39a3fa4 | 2020-12-21 16:56:03 -0800 | [diff] [blame] | 33 | using ::aidl::android::media::tv::tunerresourcemanager::ITunerResourceManager; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 34 | |
| 35 | using ::android::hardware::tv::tuner::V1_0::DemuxCapabilities; |
| 36 | using ::android::hardware::tv::tuner::V1_0::FrontendId; |
| 37 | using ::android::hardware::tv::tuner::V1_0::ITuner; |
Amy Zhang | 39a3fa4 | 2020-12-21 16:56:03 -0800 | [diff] [blame] | 38 | using ::android::hardware::tv::tuner::V1_0::LnbId; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 39 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 40 | using ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities; |
| 41 | |
| 42 | using namespace std; |
| 43 | |
| 44 | namespace android { |
| 45 | |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 46 | typedef enum { |
| 47 | FRONTEND, |
| 48 | LNB, |
| 49 | DEMUX, |
| 50 | DESCRAMBLER, |
| 51 | } TunerResourceType; |
| 52 | |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 53 | struct TunerClient : public RefBase { |
| 54 | |
| 55 | public: |
| 56 | TunerClient(); |
| 57 | ~TunerClient(); |
| 58 | |
| 59 | /** |
| 60 | * Retrieve all the frontend ids. |
| 61 | * |
| 62 | * @return a list of the available frontend ids |
| 63 | */ |
| 64 | vector<FrontendId> getFrontendIds(); |
| 65 | |
| 66 | /** |
| 67 | * Open a new interface of FrontendClient given a frontendHandle. |
| 68 | * |
| 69 | * @param frontendHandle the handle of the frontend granted by TRM. |
| 70 | * @return a newly created FrontendClient interface. |
| 71 | */ |
| 72 | sp<FrontendClient> openFrontend(int frontendHandle); |
| 73 | |
| 74 | /** |
| 75 | * Retrieve the granted frontend's information. |
| 76 | * |
| 77 | * @param id the id of the frontend granted by TRM. |
| 78 | * @return the information for the frontend. |
| 79 | */ |
| 80 | shared_ptr<FrontendInfo> getFrontendInfo(int id); |
| 81 | |
| 82 | /** |
| 83 | * Retrieve the DTMB frontend's capabilities. |
| 84 | * |
| 85 | * @param id the id of the DTMB frontend. |
| 86 | * @return the capabilities of the frontend. |
| 87 | */ |
| 88 | shared_ptr<FrontendDtmbCapabilities> getFrontendDtmbCapabilities(int id); |
| 89 | |
| 90 | /** |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 91 | * Open a new interface of DemuxClient given a demuxHandle. |
| 92 | * |
| 93 | * @param demuxHandle the handle of the demux granted by TRM. |
| 94 | * @return a newly created DemuxClient interface. |
| 95 | */ |
| 96 | sp<DemuxClient> openDemux(int demuxHandle); |
| 97 | |
| 98 | /** |
| 99 | * Retrieve the Demux capabilities. |
| 100 | * |
| 101 | * @return the demux’s capabilities. |
| 102 | */ |
Amy Zhang | 90a50b4 | 2021-01-11 16:58:59 -0800 | [diff] [blame] | 103 | shared_ptr<DemuxCapabilities> getDemuxCaps(); |
Amy Zhang | b0f63ab | 2021-01-06 17:19:27 -0800 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Open a new interface of DescramblerClient given a descramblerHandle. |
| 107 | * |
| 108 | * @param descramblerHandle the handle of the descrambler granted by TRM. |
| 109 | * @return a newly created DescramblerClient interface. |
| 110 | */ |
| 111 | sp<DescramblerClient> openDescrambler(int descramblerHandle); |
| 112 | |
| 113 | /** |
| 114 | * Open a new interface of LnbClient given an lnbHandle. |
| 115 | * |
| 116 | * @param lnbHandle the handle of the LNB granted by TRM. |
| 117 | * @return a newly created LnbClient interface. |
| 118 | */ |
| 119 | sp<LnbClient> openLnb(int lnbHandle); |
| 120 | |
| 121 | /** |
| 122 | * Open a new interface of LnbClient given a LNB name. |
| 123 | * |
| 124 | * @param lnbName the name for an external LNB to be opened. |
| 125 | * @return a newly created LnbClient interface. |
| 126 | */ |
| 127 | sp<LnbClient> openLnbByName(string lnbName); |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 128 | |
| 129 | /** |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 130 | * Get the current Tuner HAL version. The high 16 bits are the major version number |
| 131 | * while the low 16 bits are the minor version. Default value is unknown version 0. |
| 132 | */ |
| 133 | int getHalTunerVersion() { return mTunerVersion; } |
| 134 | |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 135 | private: |
| 136 | sp<ITuner> getHidlTuner(); |
| 137 | sp<IFrontend> openHidlFrontendById(int id); |
Amy Zhang | 921fd43 | 2021-01-07 13:18:27 -0800 | [diff] [blame] | 138 | sp<IDemux> openHidlDemux(int& demuxId); |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 139 | Result getHidlFrontendInfo(int id, FrontendInfo& info); |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 140 | sp<ILnb> openHidlLnbById(int id); |
| 141 | sp<ILnb> openHidlLnbByName(string name, LnbId& lnbId); |
Amy Zhang | 921fd43 | 2021-01-07 13:18:27 -0800 | [diff] [blame] | 142 | sp<IDescrambler> openHidlDescrambler(); |
Amy Zhang | 39a3fa4 | 2020-12-21 16:56:03 -0800 | [diff] [blame] | 143 | vector<int> getLnbHandles(); |
Amy Zhang | d1fd5ac | 2021-01-13 16:30:24 -0800 | [diff] [blame^] | 144 | FrontendInfo FrontendInfoAidlToHidl(TunerFrontendInfo aidlFrontendInfo); |
Amy Zhang | 39a3fa4 | 2020-12-21 16:56:03 -0800 | [diff] [blame] | 145 | void updateTunerResources(); |
| 146 | void updateFrontendResources(); |
| 147 | void updateLnbResources(); |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 148 | |
| 149 | int getResourceIdFromHandle(int handle, int resourceType); |
| 150 | |
| 151 | int getResourceHandleFromId(int id, int resourceType); |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 152 | |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 153 | /** |
| 154 | * An AIDL Tuner Service Singleton assigned at the first time the Tuner Client |
| 155 | * connects with the Tuner Service. Default null when the service does not exist. |
| 156 | */ |
| 157 | static shared_ptr<ITunerService> mTunerService; |
| 158 | |
| 159 | /** |
| 160 | * A Tuner 1.0 HAL interface that is ready before connecting to the TunerService |
| 161 | * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. |
| 162 | * Default null. |
| 163 | */ |
| 164 | static sp<ITuner> mTuner; |
| 165 | |
| 166 | /** |
| 167 | * A Tuner 1.1 HAL interface that is ready before connecting to the TunerService |
| 168 | * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. |
| 169 | * Default null. |
| 170 | */ |
| 171 | static sp<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1; |
| 172 | |
| 173 | // An integer that carries the Tuner version. The high 16 bits are the major version number |
| 174 | // while the low 16 bits are the minor version. Default value is unknown version 0. |
| 175 | static int mTunerVersion; |
| 176 | |
Amy Zhang | 39a3fa4 | 2020-12-21 16:56:03 -0800 | [diff] [blame] | 177 | shared_ptr<ITunerResourceManager> mTunerResourceManager; |
| 178 | |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 179 | int mResourceRequestCount = 0; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 180 | }; |
| 181 | } // namespace android |
| 182 | |
| 183 | #endif // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_ |