blob: 03ebb8704ef70ba5228b4f336826d316d1a88bc9 [file] [log] [blame]
Amy Zhangbf68a162020-11-23 17:42:40 -08001/*
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 Zhanga6734682020-11-30 16:14:38 -080020#include <aidl/android/media/tv/tuner/BnTunerFrontendCallback.h>
Amy Zhangbf68a162020-11-23 17:42:40 -080021#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 Zhang4a07e802021-01-21 17:10:21 -080026#include "ClientHelper.h"
Amy Zhanga6734682020-11-30 16:14:38 -080027#include "FrontendClientCallback.h"
Amy Zhangd3d57b42021-01-07 11:14:43 -080028#include "LnbClient.h"
Amy Zhangbf68a162020-11-23 17:42:40 -080029
Amy Zhanga6734682020-11-30 16:14:38 -080030using Status = ::ndk::ScopedAStatus;
31
32using ::aidl::android::media::tv::tuner::BnTunerFrontendCallback;
Amy Zhangbf68a162020-11-23 17:42:40 -080033using ::aidl::android::media::tv::tuner::ITunerFrontend;
Amy Zhangb9f3cab2021-01-13 15:24:14 -080034using ::aidl::android::media::tv::tuner::TunerFrontendScanMessage;
Amy Zhangbf68a162020-11-23 17:42:40 -080035
Amy Zhanga6734682020-11-30 16:14:38 -080036using ::android::hardware::Return;
37using ::android::hardware::Void;
Amy Zhangbf68a162020-11-23 17:42:40 -080038using ::android::hardware::tv::tuner::V1_0::FrontendInfo;
Amy Zhanga6734682020-11-30 16:14:38 -080039using ::android::hardware::tv::tuner::V1_0::FrontendEventType;
40using ::android::hardware::tv::tuner::V1_0::FrontendScanMessage;
41using ::android::hardware::tv::tuner::V1_0::FrontendScanMessageType;
Amy Zhangd08c2732021-01-08 17:22:59 -080042using ::android::hardware::tv::tuner::V1_0::FrontendScanType;
Amy Zhanga6734682020-11-30 16:14:38 -080043using ::android::hardware::tv::tuner::V1_0::FrontendSettings;
Amy Zhangd08c2732021-01-08 17:22:59 -080044using ::android::hardware::tv::tuner::V1_0::FrontendStatus;
45using ::android::hardware::tv::tuner::V1_0::FrontendStatusType;
Amy Zhangbf68a162020-11-23 17:42:40 -080046using ::android::hardware::tv::tuner::V1_0::IFrontend;
Amy Zhanga6734682020-11-30 16:14:38 -080047using ::android::hardware::tv::tuner::V1_0::Result;
48
49using ::android::hardware::tv::tuner::V1_1::FrontendScanMessageExt1_1;
50using ::android::hardware::tv::tuner::V1_1::FrontendScanMessageTypeExt1_1;
51using ::android::hardware::tv::tuner::V1_1::FrontendSettingsExt1_1;
Amy Zhangd08c2732021-01-08 17:22:59 -080052using ::android::hardware::tv::tuner::V1_1::FrontendStatusExt1_1;
53using ::android::hardware::tv::tuner::V1_1::FrontendStatusTypeExt1_1;
Amy Zhanga6734682020-11-30 16:14:38 -080054using ::android::hardware::tv::tuner::V1_1::IFrontendCallback;
Amy Zhangbf68a162020-11-23 17:42:40 -080055
56using namespace std;
57
58namespace android {
59
Amy Zhanga6734682020-11-30 16:14:38 -080060class TunerFrontendCallback : public BnTunerFrontendCallback {
61
62public:
63 TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback);
64
65 Status onEvent(int frontendEventType);
66
Amy Zhangb9f3cab2021-01-13 15:24:14 -080067 Status onScanMessage(int messageType, const TunerFrontendScanMessage& message);
Amy Zhanga6734682020-11-30 16:14:38 -080068
Amy Zhangb9f3cab2021-01-13 15:24:14 -080069 void setFrontendType(int frontendType) { mType = frontendType; }
Amy Zhanga6734682020-11-30 16:14:38 -080070
71private:
Amy Zhangb9f3cab2021-01-13 15:24:14 -080072 FrontendScanMessage getHalScanMessage(int messageType, const TunerFrontendScanMessage& message);
73 FrontendScanMessageExt1_1 getHalScanMessageExt1_1(int messageType,
74 const TunerFrontendScanMessage& message);
75 bool is1_1ExtendedScanMessage(int messageType);
76
Amy Zhanga6734682020-11-30 16:14:38 -080077 sp<FrontendClientCallback> mFrontendClientCallback;
Amy Zhangb9f3cab2021-01-13 15:24:14 -080078 int mType;
Amy Zhanga6734682020-11-30 16:14:38 -080079};
80
81struct HidlFrontendCallback : public IFrontendCallback {
82
83public:
84 HidlFrontendCallback(sp<FrontendClientCallback> frontendClientCallback);
85
86 virtual Return<void> onEvent(FrontendEventType frontendEventType);
87 virtual Return<void> onScanMessage(
88 FrontendScanMessageType type, const FrontendScanMessage& message);
89 virtual Return<void> onScanMessageExt1_1(
90 FrontendScanMessageTypeExt1_1 type, const FrontendScanMessageExt1_1& messageExt);
91
92private:
93 sp<FrontendClientCallback> mFrontendClientCallback;
94};
95
Amy Zhangbf68a162020-11-23 17:42:40 -080096struct FrontendClient : public RefBase {
Amy Zhanga6734682020-11-30 16:14:38 -080097
98public:
Amy Zhangb9f3cab2021-01-13 15:24:14 -080099 FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend, int id, int type);
Amy Zhangbf68a162020-11-23 17:42:40 -0800100 ~FrontendClient();
101
Amy Zhanga6734682020-11-30 16:14:38 -0800102 /**
103 * Set a FrontendClientCallback to receive frontend events and scan messages.
104 */
105 Result setCallback(sp<FrontendClientCallback> frontendClientCallback);
106
107 // TODO: remove after migration to Tuner Service is done.
Amy Zhangbf68a162020-11-23 17:42:40 -0800108 void setHidlFrontend(sp<IFrontend> frontend);
109
Amy Zhanga6734682020-11-30 16:14:38 -0800110 /**
111 * Tuner Frontend with Frontend Settings.
112 */
113 Result tune(const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1);
114
115 /**
116 * Stop tune Frontend.
117 */
118 Result stopTune();
119
120 /**
Amy Zhangd08c2732021-01-08 17:22:59 -0800121 * Scan the frontend to use the settings given.
122 */
123 Result scan(const FrontendSettings& settings, FrontendScanType frontendScanType,
124 const FrontendSettingsExt1_1& settingsExt1_1);
125
126 /**
127 * Stop the previous scanning.
128 */
129 Result stopScan();
130
131 /**
132 * Gets the statuses of the frontend.
133 */
134 vector<FrontendStatus> getStatus(vector<FrontendStatusType> statusTypes);
135
136 /**
137 * Gets the 1.1 extended statuses of the frontend.
138 */
139 vector<FrontendStatusExt1_1> getStatusExtended_1_1(
140 vector<FrontendStatusTypeExt1_1> statusTypes);
141
142 /**
Amy Zhangd3d57b42021-01-07 11:14:43 -0800143 * Sets Low-Noise Block downconverter (LNB) for satellite frontend.
144 */
145 Result setLnb(sp<LnbClient> lnbClient);
146
147 /**
Amy Zhangd08c2732021-01-08 17:22:59 -0800148 * Enable or Disable Low Noise Amplifier (LNA).
149 */
150 Result setLna(bool bEnable);
151
152 /**
153 * Link Frontend to the cicam with given id.
154 *
155 * @return lts id
156 */
157 int linkCiCamToFrontend(int ciCamId);
158
159 /**
160 * Unink Frontend to the cicam with given id.
161 */
162 Result unlinkCiCamToFrontend(int ciCamId);
163
164 /**
Amy Zhanga6734682020-11-30 16:14:38 -0800165 * Close Frontend.
166 */
167 Result close();
168
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800169 shared_ptr<ITunerFrontend> getAidlFrontend();
170
171 int getId();
172
Amy Zhangbf68a162020-11-23 17:42:40 -0800173private:
174 /**
175 * An AIDL Tuner Frontend Singleton assigned at the first time when the Tuner Client
176 * opens a frontend cient. Default null when the service does not exist.
177 */
178 shared_ptr<ITunerFrontend> mTunerFrontend;
179
180 /**
181 * A Frontend 1.0 HAL interface as a fall back interface when the Tuner Service does not exist.
182 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
183 * Default null.
184 */
185 sp<IFrontend> mFrontend;
186
187 /**
188 * A Frontend 1.1 HAL interface as a fall back interface when the Tuner Service does not exist.
189 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
190 * Default null.
191 */
192 sp<::android::hardware::tv::tuner::V1_1::IFrontend> mFrontend_1_1;
Amy Zhanga6734682020-11-30 16:14:38 -0800193
194 shared_ptr<TunerFrontendCallback> mAidlCallback;
195 sp<HidlFrontendCallback> mHidlCallback;
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800196
Amy Zhang210c26a2021-01-12 11:25:27 -0800197 int mId;
Amy Zhangb9f3cab2021-01-13 15:24:14 -0800198 int mType;
Amy Zhangbf68a162020-11-23 17:42:40 -0800199};
200} // namespace android
201
202#endif // _ANDROID_MEDIA_TV_FRONTEND_CLIENT_H_