blob: b509599d40339380241adf39ad05d46c34cf3b73 [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
Amy Zhang0fe25be2020-04-08 17:30:52 -070067 mTunerService->frontendStartTune(mId);
Amy5094ae12019-10-04 18:43:21 -070068 mCallback->onEvent(FrontendEventType::LOCKED);
Amy Zhang050bf782020-03-27 14:54:48 -070069 mIsLocked = false;
Amy126ee922019-08-09 16:25:12 -070070 return Result::SUCCESS;
71}
72
73Return<Result> Frontend::stopTune() {
74 ALOGV("%s", __FUNCTION__);
75
Amy5094ae12019-10-04 18:43:21 -070076 mTunerService->frontendStopTune(mId);
Amy Zhang050bf782020-03-27 14:54:48 -070077 mIsLocked = false;
Amy5094ae12019-10-04 18:43:21 -070078
Amy126ee922019-08-09 16:25:12 -070079 return Result::SUCCESS;
80}
81
Amy Zhang050bf782020-03-27 14:54:48 -070082Return<Result> Frontend::scan(const FrontendSettings& settings, FrontendScanType type) {
Amy016b7312019-09-16 15:51:28 -070083 ALOGV("%s", __FUNCTION__);
84
shubang71d60592020-04-10 18:08:49 -070085 if (mType == FrontendType::ATSC) {
shubanga990ece2020-04-17 18:25:45 -070086 FrontendScanMessage msg;
87 msg.isLocked(true);
88 mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
89 mIsLocked = true;
shubang71d60592020-04-10 18:08:49 -070090 return Result::SUCCESS;
91 }
Amy Zhang050bf782020-03-27 14:54:48 -070092 if (mType != FrontendType::DVBT) {
93 return Result::UNAVAILABLE;
94 }
95
Amyc830cfb2020-02-06 15:47:20 -080096 FrontendScanMessage msg;
Amy Zhang050bf782020-03-27 14:54:48 -070097
98 if (mIsLocked) {
99 msg.isEnd(true);
100 mCallback->onScanMessage(FrontendScanMessageType::END, msg);
101 return Result::SUCCESS;
102 }
103
104 uint32_t frequency = settings.dvbt().frequency;
105 if (type == FrontendScanType::SCAN_BLIND) {
106 frequency += 100;
107 }
108 msg.frequencies({frequency});
109 mCallback->onScanMessage(FrontendScanMessageType::FREQUENCY, msg);
Amyc830cfb2020-02-06 15:47:20 -0800110 msg.isLocked(true);
111 mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
Amy Zhang050bf782020-03-27 14:54:48 -0700112 mIsLocked = true;
Amyc830cfb2020-02-06 15:47:20 -0800113
Amy016b7312019-09-16 15:51:28 -0700114 return Result::SUCCESS;
115}
116
117Return<Result> Frontend::stopScan() {
118 ALOGV("%s", __FUNCTION__);
119
Amy Zhang050bf782020-03-27 14:54:48 -0700120 mIsLocked = false;
Amy016b7312019-09-16 15:51:28 -0700121 return Result::SUCCESS;
122}
123
shubangba232e42020-01-29 10:49:10 -0800124Return<void> Frontend::getStatus(const hidl_vec<FrontendStatusType>& statusTypes,
Amy016b7312019-09-16 15:51:28 -0700125 getStatus_cb _hidl_cb) {
126 ALOGV("%s", __FUNCTION__);
127
128 vector<FrontendStatus> statuses;
shubangba232e42020-01-29 10:49:10 -0800129 for (int i = 0; i < statusTypes.size(); i++) {
130 FrontendStatusType type = statusTypes[i];
131 FrontendStatus status;
132 // assign randomly selected values for testing.
133 switch (type) {
134 case FrontendStatusType::DEMOD_LOCK: {
135 status.isDemodLocked(true);
136 break;
137 }
138 case FrontendStatusType::SNR: {
139 status.snr(221);
140 break;
141 }
142 case FrontendStatusType::FEC: {
143 status.innerFec(FrontendInnerFec::FEC_2_9); // value = 1 << 7
144 break;
145 }
146 case FrontendStatusType::MODULATION: {
147 FrontendModulationStatus modulationStatus;
148 modulationStatus.isdbt(FrontendIsdbtModulation::MOD_16QAM); // value = 1 << 3
149 status.modulation(modulationStatus);
150 break;
151 }
152 case FrontendStatusType::PLP_ID: {
153 status.plpId(101); // type uint8_t
154 break;
155 }
156 case FrontendStatusType::LAYER_ERROR: {
157 vector<bool> v = {false, true, true};
158 status.isLayerError(v);
159 break;
160 }
161 case FrontendStatusType::ATSC3_PLP_INFO: {
162 vector<FrontendStatusAtsc3PlpInfo> v;
163 FrontendStatusAtsc3PlpInfo info1{
164 .plpId = 3,
165 .isLocked = false,
166 .uec = 313,
167 };
168 FrontendStatusAtsc3PlpInfo info2{
169 .plpId = 5,
170 .isLocked = true,
171 .uec = 515,
172 };
173 v.push_back(info1);
174 v.push_back(info2);
175 status.plpInfo(v);
176 break;
177 }
178 default: {
179 continue;
180 }
181 }
182 statuses.push_back(status);
183 }
Amy016b7312019-09-16 15:51:28 -0700184 _hidl_cb(Result::SUCCESS, statuses);
185
186 return Void();
187}
188
189Return<Result> Frontend::setLna(bool /* bEnable */) {
190 ALOGV("%s", __FUNCTION__);
191
192 return Result::SUCCESS;
193}
194
Amy42a5b4b2019-10-03 16:49:48 -0700195Return<Result> Frontend::setLnb(uint32_t /* lnb */) {
Amy016b7312019-09-16 15:51:28 -0700196 ALOGV("%s", __FUNCTION__);
197
198 return Result::SUCCESS;
199}
200
Amy126ee922019-08-09 16:25:12 -0700201FrontendType Frontend::getFrontendType() {
202 return mType;
203}
204
205FrontendId Frontend::getFrontendId() {
206 return mId;
207}
208
Amy5094ae12019-10-04 18:43:21 -0700209string Frontend::getSourceFile() {
Amyd6afead2020-03-10 16:56:59 -0700210 return FRONTEND_STREAM_FILE;
Amy5094ae12019-10-04 18:43:21 -0700211}
212
Amy126ee922019-08-09 16:25:12 -0700213} // namespace implementation
214} // namespace V1_0
215} // namespace tuner
216} // namespace tv
217} // namespace hardware
218} // namespace android