blob: 6565746c767a0d3afbd613f974c7a2401088ff98 [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) {
85 return Result::SUCCESS;
86 }
Amy Zhang050bf782020-03-27 14:54:48 -070087 if (mType != FrontendType::DVBT) {
88 return Result::UNAVAILABLE;
89 }
90
Amyc830cfb2020-02-06 15:47:20 -080091 FrontendScanMessage msg;
Amy Zhang050bf782020-03-27 14:54:48 -070092
93 if (mIsLocked) {
94 msg.isEnd(true);
95 mCallback->onScanMessage(FrontendScanMessageType::END, msg);
96 return Result::SUCCESS;
97 }
98
99 uint32_t frequency = settings.dvbt().frequency;
100 if (type == FrontendScanType::SCAN_BLIND) {
101 frequency += 100;
102 }
103 msg.frequencies({frequency});
104 mCallback->onScanMessage(FrontendScanMessageType::FREQUENCY, msg);
Amyc830cfb2020-02-06 15:47:20 -0800105 msg.isLocked(true);
106 mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
Amy Zhang050bf782020-03-27 14:54:48 -0700107 mIsLocked = true;
Amyc830cfb2020-02-06 15:47:20 -0800108
Amy016b7312019-09-16 15:51:28 -0700109 return Result::SUCCESS;
110}
111
112Return<Result> Frontend::stopScan() {
113 ALOGV("%s", __FUNCTION__);
114
Amy Zhang050bf782020-03-27 14:54:48 -0700115 mIsLocked = false;
Amy016b7312019-09-16 15:51:28 -0700116 return Result::SUCCESS;
117}
118
shubangba232e42020-01-29 10:49:10 -0800119Return<void> Frontend::getStatus(const hidl_vec<FrontendStatusType>& statusTypes,
Amy016b7312019-09-16 15:51:28 -0700120 getStatus_cb _hidl_cb) {
121 ALOGV("%s", __FUNCTION__);
122
123 vector<FrontendStatus> statuses;
shubangba232e42020-01-29 10:49:10 -0800124 for (int i = 0; i < statusTypes.size(); i++) {
125 FrontendStatusType type = statusTypes[i];
126 FrontendStatus status;
127 // assign randomly selected values for testing.
128 switch (type) {
129 case FrontendStatusType::DEMOD_LOCK: {
130 status.isDemodLocked(true);
131 break;
132 }
133 case FrontendStatusType::SNR: {
134 status.snr(221);
135 break;
136 }
137 case FrontendStatusType::FEC: {
138 status.innerFec(FrontendInnerFec::FEC_2_9); // value = 1 << 7
139 break;
140 }
141 case FrontendStatusType::MODULATION: {
142 FrontendModulationStatus modulationStatus;
143 modulationStatus.isdbt(FrontendIsdbtModulation::MOD_16QAM); // value = 1 << 3
144 status.modulation(modulationStatus);
145 break;
146 }
147 case FrontendStatusType::PLP_ID: {
148 status.plpId(101); // type uint8_t
149 break;
150 }
151 case FrontendStatusType::LAYER_ERROR: {
152 vector<bool> v = {false, true, true};
153 status.isLayerError(v);
154 break;
155 }
156 case FrontendStatusType::ATSC3_PLP_INFO: {
157 vector<FrontendStatusAtsc3PlpInfo> v;
158 FrontendStatusAtsc3PlpInfo info1{
159 .plpId = 3,
160 .isLocked = false,
161 .uec = 313,
162 };
163 FrontendStatusAtsc3PlpInfo info2{
164 .plpId = 5,
165 .isLocked = true,
166 .uec = 515,
167 };
168 v.push_back(info1);
169 v.push_back(info2);
170 status.plpInfo(v);
171 break;
172 }
173 default: {
174 continue;
175 }
176 }
177 statuses.push_back(status);
178 }
Amy016b7312019-09-16 15:51:28 -0700179 _hidl_cb(Result::SUCCESS, statuses);
180
181 return Void();
182}
183
184Return<Result> Frontend::setLna(bool /* bEnable */) {
185 ALOGV("%s", __FUNCTION__);
186
187 return Result::SUCCESS;
188}
189
Amy42a5b4b2019-10-03 16:49:48 -0700190Return<Result> Frontend::setLnb(uint32_t /* lnb */) {
Amy016b7312019-09-16 15:51:28 -0700191 ALOGV("%s", __FUNCTION__);
192
193 return Result::SUCCESS;
194}
195
Amy126ee922019-08-09 16:25:12 -0700196FrontendType Frontend::getFrontendType() {
197 return mType;
198}
199
200FrontendId Frontend::getFrontendId() {
201 return mId;
202}
203
Amy5094ae12019-10-04 18:43:21 -0700204string Frontend::getSourceFile() {
Amyd6afead2020-03-10 16:56:59 -0700205 return FRONTEND_STREAM_FILE;
Amy5094ae12019-10-04 18:43:21 -0700206}
207
Amy126ee922019-08-09 16:25:12 -0700208} // namespace implementation
209} // namespace V1_0
210} // namespace tuner
211} // namespace tv
212} // namespace hardware
213} // namespace android