blob: 2cff9be459e5d2abd00f1d213bff4bef3de1f17e [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
Amy Zhang050bf782020-03-27 14:54:48 -070084 if (mType != FrontendType::DVBT) {
85 return Result::UNAVAILABLE;
86 }
87
Amyc830cfb2020-02-06 15:47:20 -080088 FrontendScanMessage msg;
Amy Zhang050bf782020-03-27 14:54:48 -070089
90 if (mIsLocked) {
91 msg.isEnd(true);
92 mCallback->onScanMessage(FrontendScanMessageType::END, msg);
93 return Result::SUCCESS;
94 }
95
96 uint32_t frequency = settings.dvbt().frequency;
97 if (type == FrontendScanType::SCAN_BLIND) {
98 frequency += 100;
99 }
100 msg.frequencies({frequency});
101 mCallback->onScanMessage(FrontendScanMessageType::FREQUENCY, msg);
Amyc830cfb2020-02-06 15:47:20 -0800102 msg.isLocked(true);
103 mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
Amy Zhang050bf782020-03-27 14:54:48 -0700104 mIsLocked = true;
Amyc830cfb2020-02-06 15:47:20 -0800105
Amy016b7312019-09-16 15:51:28 -0700106 return Result::SUCCESS;
107}
108
109Return<Result> Frontend::stopScan() {
110 ALOGV("%s", __FUNCTION__);
111
Amy Zhang050bf782020-03-27 14:54:48 -0700112 mIsLocked = false;
Amy016b7312019-09-16 15:51:28 -0700113 return Result::SUCCESS;
114}
115
shubangba232e42020-01-29 10:49:10 -0800116Return<void> Frontend::getStatus(const hidl_vec<FrontendStatusType>& statusTypes,
Amy016b7312019-09-16 15:51:28 -0700117 getStatus_cb _hidl_cb) {
118 ALOGV("%s", __FUNCTION__);
119
120 vector<FrontendStatus> statuses;
shubangba232e42020-01-29 10:49:10 -0800121 for (int i = 0; i < statusTypes.size(); i++) {
122 FrontendStatusType type = statusTypes[i];
123 FrontendStatus status;
124 // assign randomly selected values for testing.
125 switch (type) {
126 case FrontendStatusType::DEMOD_LOCK: {
127 status.isDemodLocked(true);
128 break;
129 }
130 case FrontendStatusType::SNR: {
131 status.snr(221);
132 break;
133 }
134 case FrontendStatusType::FEC: {
135 status.innerFec(FrontendInnerFec::FEC_2_9); // value = 1 << 7
136 break;
137 }
138 case FrontendStatusType::MODULATION: {
139 FrontendModulationStatus modulationStatus;
140 modulationStatus.isdbt(FrontendIsdbtModulation::MOD_16QAM); // value = 1 << 3
141 status.modulation(modulationStatus);
142 break;
143 }
144 case FrontendStatusType::PLP_ID: {
145 status.plpId(101); // type uint8_t
146 break;
147 }
148 case FrontendStatusType::LAYER_ERROR: {
149 vector<bool> v = {false, true, true};
150 status.isLayerError(v);
151 break;
152 }
153 case FrontendStatusType::ATSC3_PLP_INFO: {
154 vector<FrontendStatusAtsc3PlpInfo> v;
155 FrontendStatusAtsc3PlpInfo info1{
156 .plpId = 3,
157 .isLocked = false,
158 .uec = 313,
159 };
160 FrontendStatusAtsc3PlpInfo info2{
161 .plpId = 5,
162 .isLocked = true,
163 .uec = 515,
164 };
165 v.push_back(info1);
166 v.push_back(info2);
167 status.plpInfo(v);
168 break;
169 }
170 default: {
171 continue;
172 }
173 }
174 statuses.push_back(status);
175 }
Amy016b7312019-09-16 15:51:28 -0700176 _hidl_cb(Result::SUCCESS, statuses);
177
178 return Void();
179}
180
181Return<Result> Frontend::setLna(bool /* bEnable */) {
182 ALOGV("%s", __FUNCTION__);
183
184 return Result::SUCCESS;
185}
186
Amy42a5b4b2019-10-03 16:49:48 -0700187Return<Result> Frontend::setLnb(uint32_t /* lnb */) {
Amy016b7312019-09-16 15:51:28 -0700188 ALOGV("%s", __FUNCTION__);
189
190 return Result::SUCCESS;
191}
192
Amy126ee922019-08-09 16:25:12 -0700193FrontendType Frontend::getFrontendType() {
194 return mType;
195}
196
197FrontendId Frontend::getFrontendId() {
198 return mId;
199}
200
Amy5094ae12019-10-04 18:43:21 -0700201string Frontend::getSourceFile() {
Amyd6afead2020-03-10 16:56:59 -0700202 return FRONTEND_STREAM_FILE;
Amy5094ae12019-10-04 18:43:21 -0700203}
204
Amy126ee922019-08-09 16:25:12 -0700205} // namespace implementation
206} // namespace V1_0
207} // namespace tuner
208} // namespace tv
209} // namespace hardware
210} // namespace android