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 20 #include <aidl/android/media/tv/tuner/BnTunerFrontendCallback.h> 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 26 #include "ClientHelper.h" 27 #include "FrontendClientCallback.h" 28 #include "LnbClient.h" 29 30 using Status = ::ndk::ScopedAStatus; 31 32 using ::aidl::android::media::tv::tuner::BnTunerFrontendCallback; 33 using ::aidl::android::media::tv::tuner::ITunerFrontend; 34 using ::aidl::android::media::tv::tuner::TunerFrontendAnalogSettings; 35 using ::aidl::android::media::tv::tuner::TunerFrontendAtscSettings; 36 using ::aidl::android::media::tv::tuner::TunerFrontendAtsc3Settings; 37 using ::aidl::android::media::tv::tuner::TunerFrontendCableSettings; 38 using ::aidl::android::media::tv::tuner::TunerFrontendDvbsSettings; 39 using ::aidl::android::media::tv::tuner::TunerFrontendDvbtSettings; 40 using ::aidl::android::media::tv::tuner::TunerFrontendDtmbSettings; 41 using ::aidl::android::media::tv::tuner::TunerFrontendIsdbsSettings; 42 using ::aidl::android::media::tv::tuner::TunerFrontendIsdbs3Settings; 43 using ::aidl::android::media::tv::tuner::TunerFrontendIsdbtSettings; 44 using ::aidl::android::media::tv::tuner::TunerFrontendScanMessage; 45 using ::aidl::android::media::tv::tuner::TunerFrontendSettings; 46 using ::aidl::android::media::tv::tuner::TunerFrontendStatus; 47 48 using ::android::hardware::Return; 49 using ::android::hardware::Void; 50 using ::android::hardware::tv::tuner::V1_0::FrontendInfo; 51 using ::android::hardware::tv::tuner::V1_0::FrontendEventType; 52 using ::android::hardware::tv::tuner::V1_0::FrontendScanMessage; 53 using ::android::hardware::tv::tuner::V1_0::FrontendScanMessageType; 54 using ::android::hardware::tv::tuner::V1_0::FrontendScanType; 55 using ::android::hardware::tv::tuner::V1_0::FrontendSettings; 56 using ::android::hardware::tv::tuner::V1_0::FrontendStatus; 57 using ::android::hardware::tv::tuner::V1_0::FrontendStatusType; 58 using ::android::hardware::tv::tuner::V1_0::IFrontend; 59 using ::android::hardware::tv::tuner::V1_0::Result; 60 61 using ::android::hardware::tv::tuner::V1_1::FrontendScanMessageExt1_1; 62 using ::android::hardware::tv::tuner::V1_1::FrontendScanMessageTypeExt1_1; 63 using ::android::hardware::tv::tuner::V1_1::FrontendSettingsExt1_1; 64 using ::android::hardware::tv::tuner::V1_1::FrontendStatusExt1_1; 65 using ::android::hardware::tv::tuner::V1_1::FrontendStatusTypeExt1_1; 66 using ::android::hardware::tv::tuner::V1_1::IFrontendCallback; 67 68 using namespace std; 69 70 namespace android { 71 72 class TunerFrontendCallback : public BnTunerFrontendCallback { 73 74 public: 75 TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback); 76 77 Status onEvent(int frontendEventType); 78 79 Status onScanMessage(int messageType, const TunerFrontendScanMessage& message); 80 setFrontendType(int frontendType)81 void setFrontendType(int frontendType) { mType = frontendType; } 82 83 private: 84 FrontendScanMessage getHalScanMessage(int messageType, const TunerFrontendScanMessage& message); 85 FrontendScanMessageExt1_1 getHalScanMessageExt1_1(int messageType, 86 const TunerFrontendScanMessage& message); 87 bool is1_1ExtendedScanMessage(int messageType); 88 89 sp<FrontendClientCallback> mFrontendClientCallback; 90 int mType; 91 }; 92 93 struct HidlFrontendCallback : public IFrontendCallback { 94 95 public: 96 HidlFrontendCallback(sp<FrontendClientCallback> frontendClientCallback); 97 98 virtual Return<void> onEvent(FrontendEventType frontendEventType); 99 virtual Return<void> onScanMessage( 100 FrontendScanMessageType type, const FrontendScanMessage& message); 101 virtual Return<void> onScanMessageExt1_1( 102 FrontendScanMessageTypeExt1_1 type, const FrontendScanMessageExt1_1& messageExt); 103 104 private: 105 sp<FrontendClientCallback> mFrontendClientCallback; 106 }; 107 108 struct FrontendClient : public RefBase { 109 110 public: 111 FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend, int type); 112 ~FrontendClient(); 113 114 /** 115 * Set a FrontendClientCallback to receive frontend events and scan messages. 116 */ 117 Result setCallback(sp<FrontendClientCallback> frontendClientCallback); 118 119 // TODO: remove after migration to Tuner Service is done. 120 void setHidlFrontend(sp<IFrontend> frontend); 121 122 /** 123 * Tuner Frontend with Frontend Settings. 124 */ 125 Result tune(const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1); 126 127 /** 128 * Stop tune Frontend. 129 */ 130 Result stopTune(); 131 132 /** 133 * Scan the frontend to use the settings given. 134 */ 135 Result scan(const FrontendSettings& settings, FrontendScanType frontendScanType, 136 const FrontendSettingsExt1_1& settingsExt1_1); 137 138 /** 139 * Stop the previous scanning. 140 */ 141 Result stopScan(); 142 143 /** 144 * Gets the statuses of the frontend. 145 */ 146 vector<FrontendStatus> getStatus(vector<FrontendStatusType> statusTypes); 147 148 /** 149 * Gets the 1.1 extended statuses of the frontend. 150 */ 151 vector<FrontendStatusExt1_1> getStatusExtended_1_1( 152 vector<FrontendStatusTypeExt1_1> statusTypes); 153 154 /** 155 * Sets Low-Noise Block downconverter (LNB) for satellite frontend. 156 */ 157 Result setLnb(sp<LnbClient> lnbClient); 158 159 /** 160 * Enable or Disable Low Noise Amplifier (LNA). 161 */ 162 Result setLna(bool bEnable); 163 164 /** 165 * Link Frontend to the cicam with given id. 166 * 167 * @return lts id 168 */ 169 int linkCiCamToFrontend(int ciCamId); 170 171 /** 172 * Unink Frontend to the cicam with given id. 173 */ 174 Result unlinkCiCamToFrontend(int ciCamId); 175 176 /** 177 * Close Frontend. 178 */ 179 Result close(); 180 181 shared_ptr<ITunerFrontend> getAidlFrontend(); 182 183 void setId(int id); 184 int getId(); 185 186 private: 187 vector<FrontendStatus> getHidlStatus(vector<TunerFrontendStatus>& aidlStatus); 188 vector<FrontendStatusExt1_1> getHidlStatusExt(vector<TunerFrontendStatus>& aidlStatus); 189 190 TunerFrontendSettings getAidlFrontendSettings( 191 const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1); 192 TunerFrontendAnalogSettings getAidlAnalogSettings( 193 const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1); 194 TunerFrontendDvbsSettings getAidlDvbsSettings( 195 const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1); 196 TunerFrontendCableSettings getAidlCableSettings( 197 const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1); 198 TunerFrontendDvbtSettings getAidlDvbtSettings( 199 const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1); 200 TunerFrontendDtmbSettings getAidlDtmbSettings(const FrontendSettingsExt1_1& settingsExt1_1); 201 TunerFrontendAtscSettings getAidlAtscSettings(const FrontendSettings& settings); 202 TunerFrontendAtsc3Settings getAidlAtsc3Settings(const FrontendSettings& settings); 203 TunerFrontendIsdbsSettings getAidlIsdbsSettings(const FrontendSettings& settings); 204 TunerFrontendIsdbs3Settings getAidlIsdbs3Settings(const FrontendSettings& settings); 205 TunerFrontendIsdbtSettings getAidlIsdbtSettings(const FrontendSettings& settings); 206 207 bool validateExtendedSettings(const FrontendSettingsExt1_1& settingsExt1_1); 208 209 /** 210 * An AIDL Tuner Frontend Singleton assigned at the first time when the Tuner Client 211 * opens a frontend cient. Default null when the service does not exist. 212 */ 213 shared_ptr<ITunerFrontend> mTunerFrontend; 214 215 /** 216 * A Frontend 1.0 HAL interface as a fall back interface when the Tuner Service does not exist. 217 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. 218 * Default null. 219 */ 220 sp<IFrontend> mFrontend; 221 222 /** 223 * A Frontend 1.1 HAL interface as a fall back interface when the Tuner Service does not exist. 224 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. 225 * Default null. 226 */ 227 sp<::android::hardware::tv::tuner::V1_1::IFrontend> mFrontend_1_1; 228 229 int mId; 230 int mType; 231 }; 232 } // namespace android 233 234 #endif // _ANDROID_MEDIA_TV_FRONTEND_CLIENT_H_ 235