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 | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 27 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 28 | using Status = ::ndk::ScopedAStatus; |
| 29 | |
| 30 | using ::aidl::android::media::tv::tuner::BnTunerFrontendCallback; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 31 | using ::aidl::android::media::tv::tuner::ITunerFrontend; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 32 | using ::aidl::android::media::tv::tuner::TunerAtsc3PlpInfo; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 33 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 34 | using ::android::hardware::Return; |
| 35 | using ::android::hardware::Void; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 36 | using ::android::hardware::tv::tuner::V1_0::FrontendInfo; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 37 | using ::android::hardware::tv::tuner::V1_0::FrontendEventType; |
| 38 | using ::android::hardware::tv::tuner::V1_0::FrontendScanMessage; |
| 39 | using ::android::hardware::tv::tuner::V1_0::FrontendScanMessageType; |
| 40 | using ::android::hardware::tv::tuner::V1_0::FrontendSettings; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 41 | using ::android::hardware::tv::tuner::V1_0::IFrontend; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 42 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 43 | |
| 44 | using ::android::hardware::tv::tuner::V1_1::FrontendScanMessageExt1_1; |
| 45 | using ::android::hardware::tv::tuner::V1_1::FrontendScanMessageTypeExt1_1; |
| 46 | using ::android::hardware::tv::tuner::V1_1::FrontendSettingsExt1_1; |
| 47 | using ::android::hardware::tv::tuner::V1_1::IFrontendCallback; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 48 | |
| 49 | using namespace std; |
| 50 | |
| 51 | namespace android { |
| 52 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 53 | class TunerFrontendCallback : public BnTunerFrontendCallback { |
| 54 | |
| 55 | public: |
| 56 | TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback); |
| 57 | |
| 58 | Status onEvent(int frontendEventType); |
| 59 | |
| 60 | Status onLocked(); |
| 61 | |
| 62 | Status onScanStopped(); |
| 63 | |
| 64 | Status onProgress(int percent); |
| 65 | |
| 66 | Status onFrequenciesReport(const vector<int>& frequency); |
| 67 | |
| 68 | Status onSymbolRates(const vector<int>& rates); |
| 69 | |
| 70 | Status onHierarchy(int hierarchy); |
| 71 | |
| 72 | Status onSignalType(int signalType); |
| 73 | |
| 74 | Status onPlpIds(const vector<int>& plpIds); |
| 75 | |
| 76 | Status onGroupIds(const vector<int>& groupIds); |
| 77 | |
| 78 | Status onInputStreamIds(const vector<int>& inputStreamIds); |
| 79 | |
| 80 | Status onDvbsStandard(int dvbsStandandard); |
| 81 | |
| 82 | Status onAnalogSifStandard(int sifStandandard); |
| 83 | |
| 84 | Status onAtsc3PlpInfos(const vector<TunerAtsc3PlpInfo>& atsc3PlpInfos); |
| 85 | |
| 86 | private: |
| 87 | sp<FrontendClientCallback> mFrontendClientCallback; |
| 88 | }; |
| 89 | |
| 90 | struct HidlFrontendCallback : public IFrontendCallback { |
| 91 | |
| 92 | public: |
| 93 | HidlFrontendCallback(sp<FrontendClientCallback> frontendClientCallback); |
| 94 | |
| 95 | virtual Return<void> onEvent(FrontendEventType frontendEventType); |
| 96 | virtual Return<void> onScanMessage( |
| 97 | FrontendScanMessageType type, const FrontendScanMessage& message); |
| 98 | virtual Return<void> onScanMessageExt1_1( |
| 99 | FrontendScanMessageTypeExt1_1 type, const FrontendScanMessageExt1_1& messageExt); |
| 100 | |
| 101 | private: |
| 102 | sp<FrontendClientCallback> mFrontendClientCallback; |
| 103 | }; |
| 104 | |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 105 | struct FrontendClient : public RefBase { |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 106 | |
| 107 | public: |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 108 | FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend); |
| 109 | ~FrontendClient(); |
| 110 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 111 | /** |
| 112 | * Set a FrontendClientCallback to receive frontend events and scan messages. |
| 113 | */ |
| 114 | Result setCallback(sp<FrontendClientCallback> frontendClientCallback); |
| 115 | |
| 116 | // TODO: remove after migration to Tuner Service is done. |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 117 | void setHidlFrontend(sp<IFrontend> frontend); |
| 118 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 119 | /** |
| 120 | * Tuner Frontend with Frontend Settings. |
| 121 | */ |
| 122 | Result tune(const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1); |
| 123 | |
| 124 | /** |
| 125 | * Stop tune Frontend. |
| 126 | */ |
| 127 | Result stopTune(); |
| 128 | |
| 129 | /** |
| 130 | * Close Frontend. |
| 131 | */ |
| 132 | Result close(); |
| 133 | |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 134 | private: |
| 135 | /** |
| 136 | * An AIDL Tuner Frontend Singleton assigned at the first time when the Tuner Client |
| 137 | * opens a frontend cient. Default null when the service does not exist. |
| 138 | */ |
| 139 | shared_ptr<ITunerFrontend> mTunerFrontend; |
| 140 | |
| 141 | /** |
| 142 | * A Frontend 1.0 HAL interface as a fall back interface when the Tuner Service does not exist. |
| 143 | * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. |
| 144 | * Default null. |
| 145 | */ |
| 146 | sp<IFrontend> mFrontend; |
| 147 | |
| 148 | /** |
| 149 | * A Frontend 1.1 HAL interface as a fall back interface when the Tuner Service does not exist. |
| 150 | * This is a temprary connection before the Tuner Framework fully migrates to the TunerService. |
| 151 | * Default null. |
| 152 | */ |
| 153 | sp<::android::hardware::tv::tuner::V1_1::IFrontend> mFrontend_1_1; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame^] | 154 | |
| 155 | shared_ptr<TunerFrontendCallback> mAidlCallback; |
| 156 | sp<HidlFrontendCallback> mHidlCallback; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 157 | }; |
| 158 | } // namespace android |
| 159 | |
| 160 | #endif // _ANDROID_MEDIA_TV_FRONTEND_CLIENT_H_ |