blob: bb0d8dcaf957010e6357c47893ac1f0b8cb23083 [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;
44
45 return Result::SUCCESS;
46}
47
48Return<Result> Frontend::setCallback(const sp<IFrontendCallback>& callback) {
49 ALOGV("%s", __FUNCTION__);
50 if (callback == nullptr) {
51 ALOGW("[ WARN ] Set Frontend callback with nullptr");
52 return Result::INVALID_ARGUMENT;
53 }
54
55 mCallback = callback;
56 return Result::SUCCESS;
57}
58
59Return<Result> Frontend::tune(const FrontendSettings& /* settings */) {
60 ALOGV("%s", __FUNCTION__);
61 if (mCallback == nullptr) {
62 ALOGW("[ WARN ] Frontend callback is not set when tune");
63 return Result::INVALID_STATE;
64 }
65
Amy5094ae12019-10-04 18:43:21 -070066 mCallback->onEvent(FrontendEventType::LOCKED);
Amy126ee922019-08-09 16:25:12 -070067 return Result::SUCCESS;
68}
69
70Return<Result> Frontend::stopTune() {
71 ALOGV("%s", __FUNCTION__);
72
Amy5094ae12019-10-04 18:43:21 -070073 mTunerService->frontendStopTune(mId);
74
Amy126ee922019-08-09 16:25:12 -070075 return Result::SUCCESS;
76}
77
Amy016b7312019-09-16 15:51:28 -070078Return<Result> Frontend::scan(const FrontendSettings& /* settings */, FrontendScanType /* type */) {
79 ALOGV("%s", __FUNCTION__);
80
Amyc830cfb2020-02-06 15:47:20 -080081 FrontendScanMessage msg;
82 msg.isLocked(true);
83 mCallback->onScanMessage(FrontendScanMessageType::LOCKED, msg);
84
Amy016b7312019-09-16 15:51:28 -070085 return Result::SUCCESS;
86}
87
88Return<Result> Frontend::stopScan() {
89 ALOGV("%s", __FUNCTION__);
90
91 return Result::SUCCESS;
92}
93
shubangba232e42020-01-29 10:49:10 -080094Return<void> Frontend::getStatus(const hidl_vec<FrontendStatusType>& statusTypes,
Amy016b7312019-09-16 15:51:28 -070095 getStatus_cb _hidl_cb) {
96 ALOGV("%s", __FUNCTION__);
97
98 vector<FrontendStatus> statuses;
shubangba232e42020-01-29 10:49:10 -080099 for (int i = 0; i < statusTypes.size(); i++) {
100 FrontendStatusType type = statusTypes[i];
101 FrontendStatus status;
102 // assign randomly selected values for testing.
103 switch (type) {
104 case FrontendStatusType::DEMOD_LOCK: {
105 status.isDemodLocked(true);
106 break;
107 }
108 case FrontendStatusType::SNR: {
109 status.snr(221);
110 break;
111 }
112 case FrontendStatusType::FEC: {
113 status.innerFec(FrontendInnerFec::FEC_2_9); // value = 1 << 7
114 break;
115 }
116 case FrontendStatusType::MODULATION: {
117 FrontendModulationStatus modulationStatus;
118 modulationStatus.isdbt(FrontendIsdbtModulation::MOD_16QAM); // value = 1 << 3
119 status.modulation(modulationStatus);
120 break;
121 }
122 case FrontendStatusType::PLP_ID: {
123 status.plpId(101); // type uint8_t
124 break;
125 }
126 case FrontendStatusType::LAYER_ERROR: {
127 vector<bool> v = {false, true, true};
128 status.isLayerError(v);
129 break;
130 }
131 case FrontendStatusType::ATSC3_PLP_INFO: {
132 vector<FrontendStatusAtsc3PlpInfo> v;
133 FrontendStatusAtsc3PlpInfo info1{
134 .plpId = 3,
135 .isLocked = false,
136 .uec = 313,
137 };
138 FrontendStatusAtsc3PlpInfo info2{
139 .plpId = 5,
140 .isLocked = true,
141 .uec = 515,
142 };
143 v.push_back(info1);
144 v.push_back(info2);
145 status.plpInfo(v);
146 break;
147 }
148 default: {
149 continue;
150 }
151 }
152 statuses.push_back(status);
153 }
Amy016b7312019-09-16 15:51:28 -0700154 _hidl_cb(Result::SUCCESS, statuses);
155
156 return Void();
157}
158
159Return<Result> Frontend::setLna(bool /* bEnable */) {
160 ALOGV("%s", __FUNCTION__);
161
162 return Result::SUCCESS;
163}
164
Amy42a5b4b2019-10-03 16:49:48 -0700165Return<Result> Frontend::setLnb(uint32_t /* lnb */) {
Amy016b7312019-09-16 15:51:28 -0700166 ALOGV("%s", __FUNCTION__);
167
168 return Result::SUCCESS;
169}
170
Amy126ee922019-08-09 16:25:12 -0700171FrontendType Frontend::getFrontendType() {
172 return mType;
173}
174
175FrontendId Frontend::getFrontendId() {
176 return mId;
177}
178
Amy5094ae12019-10-04 18:43:21 -0700179string Frontend::getSourceFile() {
Amyd6afead2020-03-10 16:56:59 -0700180 return FRONTEND_STREAM_FILE;
Amy5094ae12019-10-04 18:43:21 -0700181}
182
Amy126ee922019-08-09 16:25:12 -0700183} // namespace implementation
184} // namespace V1_0
185} // namespace tuner
186} // namespace tv
187} // namespace hardware
188} // namespace android