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