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_FRONTEND_CLIENT_H_ |
| 18 | #define _ANDROID_MEDIA_TV_FRONTEND_CLIENT_H_ |
| 19 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 20 | #include <aidl/android/media/tv/tuner/BnTunerFrontendCallback.h> |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 21 | #include <aidl/android/media/tv/tuner/ITunerFrontend.h> |
| 22 | #include <android/hardware/tv/tuner/1.1/IFrontend.h> |
| 23 | #include <android/hardware/tv/tuner/1.1/IFrontendCallback.h> |
| 24 | #include <android/hardware/tv/tuner/1.1/types.h> |
| 25 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 26 | #include "FrontendClientCallback.h" |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 27 | #include "LnbClient.h" |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 28 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 29 | using Status = ::ndk::ScopedAStatus; |
| 30 | |
| 31 | using ::aidl::android::media::tv::tuner::BnTunerFrontendCallback; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 32 | using ::aidl::android::media::tv::tuner::ITunerFrontend; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 33 | using ::aidl::android::media::tv::tuner::TunerAtsc3PlpInfo; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 34 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 35 | using ::android::hardware::Return; |
| 36 | using ::android::hardware::Void; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 37 | using ::android::hardware::tv::tuner::V1_0::FrontendInfo; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 38 | using ::android::hardware::tv::tuner::V1_0::FrontendEventType; |
| 39 | using ::android::hardware::tv::tuner::V1_0::FrontendScanMessage; |
| 40 | using ::android::hardware::tv::tuner::V1_0::FrontendScanMessageType; |
Amy Zhang | d08c273 | 2021-01-08 17:22:59 -0800 | [diff] [blame] | 41 | using ::android::hardware::tv::tuner::V1_0::FrontendScanType; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 42 | using ::android::hardware::tv::tuner::V1_0::FrontendSettings; |
Amy Zhang | d08c273 | 2021-01-08 17:22:59 -0800 | [diff] [blame] | 43 | using ::android::hardware::tv::tuner::V1_0::FrontendStatus; |
| 44 | using ::android::hardware::tv::tuner::V1_0::FrontendStatusType; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 45 | using ::android::hardware::tv::tuner::V1_0::IFrontend; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 46 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 47 | |
| 48 | using ::android::hardware::tv::tuner::V1_1::FrontendScanMessageExt1_1; |
| 49 | using ::android::hardware::tv::tuner::V1_1::FrontendScanMessageTypeExt1_1; |
| 50 | using ::android::hardware::tv::tuner::V1_1::FrontendSettingsExt1_1; |
Amy Zhang | d08c273 | 2021-01-08 17:22:59 -0800 | [diff] [blame] | 51 | using ::android::hardware::tv::tuner::V1_1::FrontendStatusExt1_1; |
| 52 | using ::android::hardware::tv::tuner::V1_1::FrontendStatusTypeExt1_1; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 53 | using ::android::hardware::tv::tuner::V1_1::IFrontendCallback; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 54 | |
| 55 | using namespace std; |
| 56 | |
| 57 | namespace android { |
| 58 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 59 | class TunerFrontendCallback : public BnTunerFrontendCallback { |
| 60 | |
| 61 | public: |
| 62 | TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback); |
| 63 | |
| 64 | Status onEvent(int frontendEventType); |
| 65 | |
| 66 | Status onLocked(); |
| 67 | |
| 68 | Status onScanStopped(); |
| 69 | |
| 70 | Status onProgress(int percent); |
| 71 | |
| 72 | Status onFrequenciesReport(const vector<int>& frequency); |
| 73 | |
| 74 | Status onSymbolRates(const vector<int>& rates); |
| 75 | |
| 76 | Status onHierarchy(int hierarchy); |
| 77 | |
| 78 | Status onSignalType(int signalType); |
| 79 | |
| 80 | Status onPlpIds(const vector<int>& plpIds); |
| 81 | |
| 82 | Status onGroupIds(const vector<int>& groupIds); |
| 83 | |
| 84 | Status onInputStreamIds(const vector<int>& inputStreamIds); |
| 85 | |
| 86 | Status onDvbsStandard(int dvbsStandandard); |
| 87 | |
| 88 | Status onAnalogSifStandard(int sifStandandard); |
| 89 | |
| 90 | Status onAtsc3PlpInfos(const vector<TunerAtsc3PlpInfo>& atsc3PlpInfos); |
| 91 | |
| 92 | private: |
| 93 | sp<FrontendClientCallback> mFrontendClientCallback; |
| 94 | }; |
| 95 | |
| 96 | struct HidlFrontendCallback : public IFrontendCallback { |
| 97 | |
| 98 | public: |
| 99 | HidlFrontendCallback(sp<FrontendClientCallback> frontendClientCallback); |
| 100 | |
| 101 | virtual Return<void> onEvent(FrontendEventType frontendEventType); |
| 102 | virtual Return<void> onScanMessage( |
| 103 | FrontendScanMessageType type, const FrontendScanMessage& message); |
| 104 | virtual Return<void> onScanMessageExt1_1( |
| 105 | FrontendScanMessageTypeExt1_1 type, const FrontendScanMessageExt1_1& messageExt); |
| 106 | |
| 107 | private: |
| 108 | sp<FrontendClientCallback> mFrontendClientCallback; |
| 109 | }; |
| 110 | |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 111 | struct FrontendClient : public RefBase { |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 112 | |
| 113 | public: |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 114 | FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend, int id); |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 115 | ~FrontendClient(); |
| 116 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 117 | /** |
| 118 | * Set a FrontendClientCallback to receive frontend events and scan messages. |
| 119 | */ |
| 120 | Result setCallback(sp<FrontendClientCallback> frontendClientCallback); |
| 121 | |
| 122 | // TODO: remove after migration to Tuner Service is done. |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 123 | void setHidlFrontend(sp<IFrontend> frontend); |
| 124 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 125 | /** |
| 126 | * Tuner Frontend with Frontend Settings. |
| 127 | */ |
| 128 | Result tune(const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1); |
| 129 | |
| 130 | /** |
| 131 | * Stop tune Frontend. |
| 132 | */ |
| 133 | Result stopTune(); |
| 134 | |
| 135 | /** |
Amy Zhang | d08c273 | 2021-01-08 17:22:59 -0800 | [diff] [blame] | 136 | * Scan the frontend to use the settings given. |
| 137 | */ |
| 138 | Result scan(const FrontendSettings& settings, FrontendScanType frontendScanType, |
| 139 | const FrontendSettingsExt1_1& settingsExt1_1); |
| 140 | |
| 141 | /** |
| 142 | * Stop the previous scanning. |
| 143 | */ |
| 144 | Result stopScan(); |
| 145 | |
| 146 | /** |
| 147 | * Gets the statuses of the frontend. |
| 148 | */ |
| 149 | vector<FrontendStatus> getStatus(vector<FrontendStatusType> statusTypes); |
| 150 | |
| 151 | /** |
| 152 | * Gets the 1.1 extended statuses of the frontend. |
| 153 | */ |
| 154 | vector<FrontendStatusExt1_1> getStatusExtended_1_1( |
| 155 | vector<FrontendStatusTypeExt1_1> statusTypes); |
| 156 | |
| 157 | /** |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 158 | * Sets Low-Noise Block downconverter (LNB) for satellite frontend. |
| 159 | */ |
| 160 | Result setLnb(sp<LnbClient> lnbClient); |
| 161 | |
| 162 | /** |
Amy Zhang | d08c273 | 2021-01-08 17:22:59 -0800 | [diff] [blame] | 163 | * Enable or Disable Low Noise Amplifier (LNA). |
| 164 | */ |
| 165 | Result setLna(bool bEnable); |
| 166 | |
| 167 | /** |
| 168 | * Link Frontend to the cicam with given id. |
| 169 | * |
| 170 | * @return lts id |
| 171 | */ |
| 172 | int linkCiCamToFrontend(int ciCamId); |
| 173 | |
| 174 | /** |
| 175 | * Unink Frontend to the cicam with given id. |
| 176 | */ |
| 177 | Result unlinkCiCamToFrontend(int ciCamId); |
| 178 | |
| 179 | /** |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 180 | * Close Frontend. |
| 181 | */ |
| 182 | Result close(); |
| 183 | |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 184 | shared_ptr<ITunerFrontend> getAidlFrontend(); |
| 185 | |
| 186 | int getId(); |
| 187 | |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 188 | private: |
| 189 | /** |
| 190 | * An AIDL Tuner Frontend Singleton assigned at the first time when the Tuner Client |
| 191 | * opens a frontend cient. Default null when the service does not exist. |
| 192 | */ |
| 193 | shared_ptr<ITunerFrontend> mTunerFrontend; |
| 194 | |
| 195 | /** |
| 196 | * A Frontend 1.0 HAL interface as a fall back interface when the Tuner Service does not exist. |
| 197 | * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. |
| 198 | * Default null. |
| 199 | */ |
| 200 | sp<IFrontend> mFrontend; |
| 201 | |
| 202 | /** |
| 203 | * A Frontend 1.1 HAL interface as a fall back interface when the Tuner Service does not exist. |
| 204 | * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. |
| 205 | * Default null. |
| 206 | */ |
| 207 | sp<::android::hardware::tv::tuner::V1_1::IFrontend> mFrontend_1_1; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 208 | |
| 209 | shared_ptr<TunerFrontendCallback> mAidlCallback; |
| 210 | sp<HidlFrontendCallback> mHidlCallback; |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 211 | |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 212 | int mId; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 213 | }; |
| 214 | } // namespace android |
| 215 | |
| 216 | #endif // _ANDROID_MEDIA_TV_FRONTEND_CLIENT_H_ |