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