1 /**
2 * Copyright 2021, 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "TunerFrontend"
19
20 #include "TunerFrontend.h"
21
22 #include <aidl/android/hardware/tv/tuner/Result.h>
23
24 #include "TunerLnb.h"
25
26 using ::aidl::android::hardware::tv::tuner::Result;
27
28 namespace aidl {
29 namespace android {
30 namespace media {
31 namespace tv {
32 namespace tuner {
33
TunerFrontend(shared_ptr<IFrontend> frontend,int id)34 TunerFrontend::TunerFrontend(shared_ptr<IFrontend> frontend, int id) {
35 mFrontend = frontend;
36 mId = id;
37 }
38
~TunerFrontend()39 TunerFrontend::~TunerFrontend() {
40 mFrontend = nullptr;
41 mId = -1;
42 }
43
setCallback(const shared_ptr<ITunerFrontendCallback> & tunerFrontendCallback)44 ::ndk::ScopedAStatus TunerFrontend::setCallback(
45 const shared_ptr<ITunerFrontendCallback>& tunerFrontendCallback) {
46 if (mFrontend == nullptr) {
47 ALOGE("IFrontend is not initialized");
48 return ::ndk::ScopedAStatus::fromServiceSpecificError(
49 static_cast<int32_t>(Result::UNAVAILABLE));
50 }
51
52 if (tunerFrontendCallback == nullptr) {
53 return ::ndk::ScopedAStatus::fromServiceSpecificError(
54 static_cast<int32_t>(Result::INVALID_ARGUMENT));
55 }
56
57 shared_ptr<IFrontendCallback> frontendCallback =
58 ::ndk::SharedRefBase::make<FrontendCallback>(tunerFrontendCallback);
59 return mFrontend->setCallback(frontendCallback);
60 }
61
tune(const FrontendSettings & settings)62 ::ndk::ScopedAStatus TunerFrontend::tune(const FrontendSettings& settings) {
63 if (mFrontend == nullptr) {
64 ALOGE("IFrontend is not initialized");
65 return ::ndk::ScopedAStatus::fromServiceSpecificError(
66 static_cast<int32_t>(Result::UNAVAILABLE));
67 }
68
69 return mFrontend->tune(settings);
70 }
71
stopTune()72 ::ndk::ScopedAStatus TunerFrontend::stopTune() {
73 if (mFrontend == nullptr) {
74 ALOGD("IFrontend is not initialized");
75 return ::ndk::ScopedAStatus::fromServiceSpecificError(
76 static_cast<int32_t>(Result::UNAVAILABLE));
77 }
78
79 return mFrontend->stopTune();
80 }
81
scan(const FrontendSettings & settings,FrontendScanType frontendScanType)82 ::ndk::ScopedAStatus TunerFrontend::scan(const FrontendSettings& settings,
83 FrontendScanType frontendScanType) {
84 if (mFrontend == nullptr) {
85 ALOGD("IFrontend is not initialized");
86 return ::ndk::ScopedAStatus::fromServiceSpecificError(
87 static_cast<int32_t>(Result::UNAVAILABLE));
88 }
89
90 return mFrontend->scan(settings, frontendScanType);
91 }
92
stopScan()93 ::ndk::ScopedAStatus TunerFrontend::stopScan() {
94 if (mFrontend == nullptr) {
95 ALOGD("IFrontend is not initialized");
96 return ::ndk::ScopedAStatus::fromServiceSpecificError(
97 static_cast<int32_t>(Result::UNAVAILABLE));
98 }
99
100 return mFrontend->stopScan();
101 }
102
setLnb(const shared_ptr<ITunerLnb> & lnb)103 ::ndk::ScopedAStatus TunerFrontend::setLnb(const shared_ptr<ITunerLnb>& lnb) {
104 if (mFrontend == nullptr) {
105 ALOGD("IFrontend is not initialized");
106 return ::ndk::ScopedAStatus::fromServiceSpecificError(
107 static_cast<int32_t>(Result::UNAVAILABLE));
108 }
109
110 if (lnb == nullptr) {
111 return ::ndk::ScopedAStatus::fromServiceSpecificError(
112 static_cast<int32_t>(Result::INVALID_ARGUMENT));
113 }
114
115 return mFrontend->setLnb(static_cast<TunerLnb*>(lnb.get())->getId());
116 }
117
linkCiCamToFrontend(int32_t ciCamId,int32_t * _aidl_return)118 ::ndk::ScopedAStatus TunerFrontend::linkCiCamToFrontend(int32_t ciCamId, int32_t* _aidl_return) {
119 if (mFrontend == nullptr) {
120 ALOGD("IFrontend is not initialized");
121 return ::ndk::ScopedAStatus::fromServiceSpecificError(
122 static_cast<int32_t>(Result::UNAVAILABLE));
123 }
124
125 return mFrontend->linkCiCam(ciCamId, _aidl_return);
126 }
127
unlinkCiCamToFrontend(int32_t ciCamId)128 ::ndk::ScopedAStatus TunerFrontend::unlinkCiCamToFrontend(int32_t ciCamId) {
129 if (mFrontend == nullptr) {
130 ALOGD("IFrontend is not initialized");
131 return ::ndk::ScopedAStatus::fromServiceSpecificError(
132 static_cast<int32_t>(Result::UNAVAILABLE));
133 }
134
135 return mFrontend->unlinkCiCam(ciCamId);
136 }
137
close()138 ::ndk::ScopedAStatus TunerFrontend::close() {
139 if (mFrontend == nullptr) {
140 ALOGD("IFrontend is not initialized");
141 return ::ndk::ScopedAStatus::fromServiceSpecificError(
142 static_cast<int32_t>(Result::UNAVAILABLE));
143 }
144
145 auto res = mFrontend->close();
146 mFrontend = nullptr;
147
148 return res;
149 }
150
getStatus(const vector<FrontendStatusType> & in_statusTypes,vector<FrontendStatus> * _aidl_return)151 ::ndk::ScopedAStatus TunerFrontend::getStatus(const vector<FrontendStatusType>& in_statusTypes,
152 vector<FrontendStatus>* _aidl_return) {
153 if (mFrontend == nullptr) {
154 ALOGD("IFrontend is not initialized");
155 return ::ndk::ScopedAStatus::fromServiceSpecificError(
156 static_cast<int32_t>(Result::UNAVAILABLE));
157 }
158
159 return mFrontend->getStatus(in_statusTypes, _aidl_return);
160 }
161
getFrontendId(int32_t * _aidl_return)162 ::ndk::ScopedAStatus TunerFrontend::getFrontendId(int32_t* _aidl_return) {
163 *_aidl_return = mId;
164 return ::ndk::ScopedAStatus::ok();
165 }
166
getHardwareInfo(std::string * _aidl_return)167 ::ndk::ScopedAStatus TunerFrontend::getHardwareInfo(std::string* _aidl_return) {
168 if (mFrontend == nullptr) {
169 ALOGD("IFrontend is not initialized");
170 return ::ndk::ScopedAStatus::fromServiceSpecificError(
171 static_cast<int32_t>(Result::UNAVAILABLE));
172 }
173
174 return mFrontend->getHardwareInfo(_aidl_return);
175 }
176
removeOutputPid(int32_t in_pid)177 ::ndk::ScopedAStatus TunerFrontend::removeOutputPid(int32_t in_pid) {
178 if (mFrontend == nullptr) {
179 ALOGD("IFrontend is not initialized");
180 return ::ndk::ScopedAStatus::fromServiceSpecificError(
181 static_cast<int32_t>(Result::UNAVAILABLE));
182 }
183
184 return mFrontend->removeOutputPid(in_pid);
185 }
186
getFrontendStatusReadiness(const std::vector<FrontendStatusType> & in_statusTypes,std::vector<FrontendStatusReadiness> * _aidl_return)187 ::ndk::ScopedAStatus TunerFrontend::getFrontendStatusReadiness(
188 const std::vector<FrontendStatusType>& in_statusTypes,
189 std::vector<FrontendStatusReadiness>* _aidl_return) {
190 if (mFrontend == nullptr) {
191 ALOGD("IFrontend is not initialized");
192 return ::ndk::ScopedAStatus::fromServiceSpecificError(
193 static_cast<int32_t>(Result::UNAVAILABLE));
194 }
195
196 return mFrontend->getFrontendStatusReadiness(in_statusTypes, _aidl_return);
197 }
198
199 /////////////// FrontendCallback ///////////////////////
onEvent(FrontendEventType frontendEventType)200 ::ndk::ScopedAStatus TunerFrontend::FrontendCallback::onEvent(FrontendEventType frontendEventType) {
201 ALOGV("FrontendCallback::onEvent, type=%d", frontendEventType);
202 if (mTunerFrontendCallback != nullptr) {
203 mTunerFrontendCallback->onEvent(frontendEventType);
204 }
205 return ndk::ScopedAStatus::ok();
206 }
207
onScanMessage(FrontendScanMessageType type,const FrontendScanMessage & message)208 ::ndk::ScopedAStatus TunerFrontend::FrontendCallback::onScanMessage(
209 FrontendScanMessageType type, const FrontendScanMessage& message) {
210 ALOGV("FrontendCallback::onScanMessage, type=%d", type);
211 if (mTunerFrontendCallback != nullptr) {
212 mTunerFrontendCallback->onScanMessage(type, message);
213 }
214 return ndk::ScopedAStatus::ok();
215 }
216
217 } // namespace tuner
218 } // namespace tv
219 } // namespace media
220 } // namespace android
221 } // namespace aidl
222