blob: ae5f587b943467d559c717e3f6cbeb6c917f8a19 [file] [log] [blame]
Amy126ee922019-08-09 16:25:12 -07001/*
2 * Copyright (C) 2019 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_TAG "android.hardware.tv.tuner@1.0-Frontend"
18
19#include "Frontend.h"
20#include <android/hardware/tv/tuner/1.0/IFrontendCallback.h>
21#include <utils/Log.h>
22
23namespace android {
24namespace hardware {
25namespace tv {
26namespace tuner {
27namespace V1_0 {
28namespace implementation {
29
Amy5094ae12019-10-04 18:43:21 -070030Frontend::Frontend(FrontendType type, FrontendId id, sp<Tuner> tuner) {
Amy126ee922019-08-09 16:25:12 -070031 mType = type;
32 mId = id;
Amy5094ae12019-10-04 18:43:21 -070033 mTunerService = tuner;
Amy126ee922019-08-09 16:25:12 -070034 // Init callback to nullptr
35 mCallback = nullptr;
36}
37
38Frontend::~Frontend() {}
39
40Return<Result> Frontend::close() {
41 ALOGV("%s", __FUNCTION__);
42 // Reset callback
43 mCallback = nullptr;
Amy Zhang050bf782020-03-27 14:54:48 -070044 mIsLocked = false;
Amy126ee922019-08-09 16:25:12 -070045
46 return Result::SUCCESS;
47}
48
49Return<Result> Frontend::setCallback(const sp<IFrontendCallback>& callback) {
50 ALOGV("%s", __FUNCTION__);
51 if (callback == nullptr) {
52 ALOGW("[ WARN ] Set Frontend callback with nullptr");
53 return Result::INVALID_ARGUMENT;
54 }
55
56 mCallback = callback;
57 return Result::SUCCESS;
58}
59
60Return<Result> Frontend::tune(const FrontendSettings& /* settings */) {
61 ALOGV("%s", __FUNCTION__);
62 if (mCallback == nullptr) {
63 ALOGW("[ WARN ] Frontend callback is not set when tune");
64 return Result::INVALID_STATE;
65 }
66
Amy5094ae12019-10-04 18:43:21 -070067 mCallback->onEvent(FrontendEventType::LOCKED);
Amy Zhang050bf782020-03-27 14:54:48 -070068 mIsLocked = false;
Amy126ee922019-08-09 16:25:12 -070069 return Result::SUCCESS;
70}
71
72Return<Result> Frontend::stopTune() {
73 ALOGV("%s", __FUNCTION__);
74
Amy5094ae12019-10-04 18:43:21 -070075 mTunerService->frontendStopTune(mId);
Amy Zhang050bf782020-03-27 14:54:48 -070076 mIsLocked = false;
Amy5094ae12019-10-04 18:43:21 -070077
Amy126ee922019-08-09 16:25:12 -070078 return Result::SUCCESS;
79}
80
Amy Zhang050bf782020-03-27 14:54:48 -070081Return<Result> Frontend::scan(const FrontendSettings& settings, FrontendScanType type) {
Amy016b7312019-09-16 15:51:28 -070082 ALOGV("%s", __FUNCTION__);
83
shubang71d60592020-04-10 18:08:49 -070084 if (mType == FrontendType::ATSC) {
shubanga990ece2020-04-17 18:25:45 -070085 FrontendScanMessage msg;
86 msg.isLocked(true);
87 mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
88 mIsLocked = true;
shubang71d60592020-04-10 18:08:49 -070089 return Result::SUCCESS;
90 }
Amy Zhang050bf782020-03-27 14:54:48 -070091 if (mType != FrontendType::DVBT) {
92 return Result::UNAVAILABLE;
93 }
94
Amyc830cfb2020-02-06 15:47:20 -080095 FrontendScanMessage msg;
Amy Zhang050bf782020-03-27 14:54:48 -070096
97 if (mIsLocked) {
98 msg.isEnd(true);
99 mCallback->onScanMessage(FrontendScanMessageType::END, msg);
100 return Result::SUCCESS;
101 }
102
103 uint32_t frequency = settings.dvbt().frequency;
104 if (type == FrontendScanType::SCAN_BLIND) {
105 frequency += 100;
106 }
107 msg.frequencies({frequency});
108 mCallback->onScanMessage(FrontendScanMessageType::FREQUENCY, msg);
Amyc830cfb2020-02-06 15:47:20 -0800109 msg.isLocked(true);
110 mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
Amy Zhang050bf782020-03-27 14:54:48 -0700111 mIsLocked = true;
Amyc830cfb2020-02-06 15:47:20 -0800112
Amy016b7312019-09-16 15:51:28 -0700113 return Result::SUCCESS;
114}
115
116Return<Result> Frontend::stopScan() {
117 ALOGV("%s", __FUNCTION__);
118
Amy Zhang050bf782020-03-27 14:54:48 -0700119 mIsLocked = false;
Amy016b7312019-09-16 15:51:28 -0700120 return Result::SUCCESS;
121}
122
shubangba232e42020-01-29 10:49:10 -0800123Return<void> Frontend::getStatus(const hidl_vec<FrontendStatusType>& statusTypes,
Amy016b7312019-09-16 15:51:28 -0700124 getStatus_cb _hidl_cb) {
125 ALOGV("%s", __FUNCTION__);
126
127 vector<FrontendStatus> statuses;
shubangba232e42020-01-29 10:49:10 -0800128 for (int i = 0; i < statusTypes.size(); i++) {
129 FrontendStatusType type = statusTypes[i];
130 FrontendStatus status;
131 // assign randomly selected values for testing.
132 switch (type) {
133 case FrontendStatusType::DEMOD_LOCK: {
134 status.isDemodLocked(true);
135 break;
136 }
137 case FrontendStatusType::SNR: {
138 status.snr(221);
139 break;
140 }
141 case FrontendStatusType::FEC: {
142 status.innerFec(FrontendInnerFec::FEC_2_9); // value = 1 << 7
143 break;
144 }
145 case FrontendStatusType::MODULATION: {
146 FrontendModulationStatus modulationStatus;
147 modulationStatus.isdbt(FrontendIsdbtModulation::MOD_16QAM); // value = 1 << 3
148 status.modulation(modulationStatus);
149 break;
150 }
151 case FrontendStatusType::PLP_ID: {
152 status.plpId(101); // type uint8_t
153 break;
154 }
155 case FrontendStatusType::LAYER_ERROR: {
156 vector<bool> v = {false, true, true};
157 status.isLayerError(v);
158 break;
159 }
160 case FrontendStatusType::ATSC3_PLP_INFO: {
161 vector<FrontendStatusAtsc3PlpInfo> v;
162 FrontendStatusAtsc3PlpInfo info1{
163 .plpId = 3,
164 .isLocked = false,
165 .uec = 313,
166 };
167 FrontendStatusAtsc3PlpInfo info2{
168 .plpId = 5,
169 .isLocked = true,
170 .uec = 515,
171 };
172 v.push_back(info1);
173 v.push_back(info2);
174 status.plpInfo(v);
175 break;
176 }
177 default: {
178 continue;
179 }
180 }
181 statuses.push_back(status);
182 }
Amy016b7312019-09-16 15:51:28 -0700183 _hidl_cb(Result::SUCCESS, statuses);
184
185 return Void();
186}
187
188Return<Result> Frontend::setLna(bool /* bEnable */) {
189 ALOGV("%s", __FUNCTION__);
190
191 return Result::SUCCESS;
192}
193
Amy42a5b4b2019-10-03 16:49:48 -0700194Return<Result> Frontend::setLnb(uint32_t /* lnb */) {
Amy016b7312019-09-16 15:51:28 -0700195 ALOGV("%s", __FUNCTION__);
196
197 return Result::SUCCESS;
198}
199
Amy126ee922019-08-09 16:25:12 -0700200FrontendType Frontend::getFrontendType() {
201 return mType;
202}
203
204FrontendId Frontend::getFrontendId() {
205 return mId;
206}
207
Amy5094ae12019-10-04 18:43:21 -0700208string Frontend::getSourceFile() {
Amyd6afead2020-03-10 16:56:59 -0700209 return FRONTEND_STREAM_FILE;
Amy5094ae12019-10-04 18:43:21 -0700210}
211
Amy126ee922019-08-09 16:25:12 -0700212} // namespace implementation
213} // namespace V1_0
214} // namespace tuner
215} // namespace tv
216} // namespace hardware
217} // namespace android