blob: dd2f8a68d569a3326662839b31f69b1cff4923a5 [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 // TODO dynamically allocate file to the source file
67 mSourceStreamFile = FRONTEND_STREAM_FILE;
68
69 mCallback->onEvent(FrontendEventType::LOCKED);
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);
77
Amy126ee922019-08-09 16:25:12 -070078 return Result::SUCCESS;
79}
80
Amy016b7312019-09-16 15:51:28 -070081Return<Result> Frontend::scan(const FrontendSettings& /* settings */, FrontendScanType /* type */) {
82 ALOGV("%s", __FUNCTION__);
83
84 return Result::SUCCESS;
85}
86
87Return<Result> Frontend::stopScan() {
88 ALOGV("%s", __FUNCTION__);
89
90 return Result::SUCCESS;
91}
92
shubangba232e42020-01-29 10:49:10 -080093Return<void> Frontend::getStatus(const hidl_vec<FrontendStatusType>& statusTypes,
Amy016b7312019-09-16 15:51:28 -070094 getStatus_cb _hidl_cb) {
95 ALOGV("%s", __FUNCTION__);
96
97 vector<FrontendStatus> statuses;
shubangba232e42020-01-29 10:49:10 -080098 for (int i = 0; i < statusTypes.size(); i++) {
99 FrontendStatusType type = statusTypes[i];
100 FrontendStatus status;
101 // assign randomly selected values for testing.
102 switch (type) {
103 case FrontendStatusType::DEMOD_LOCK: {
104 status.isDemodLocked(true);
105 break;
106 }
107 case FrontendStatusType::SNR: {
108 status.snr(221);
109 break;
110 }
111 case FrontendStatusType::FEC: {
112 status.innerFec(FrontendInnerFec::FEC_2_9); // value = 1 << 7
113 break;
114 }
115 case FrontendStatusType::MODULATION: {
116 FrontendModulationStatus modulationStatus;
117 modulationStatus.isdbt(FrontendIsdbtModulation::MOD_16QAM); // value = 1 << 3
118 status.modulation(modulationStatus);
119 break;
120 }
121 case FrontendStatusType::PLP_ID: {
122 status.plpId(101); // type uint8_t
123 break;
124 }
125 case FrontendStatusType::LAYER_ERROR: {
126 vector<bool> v = {false, true, true};
127 status.isLayerError(v);
128 break;
129 }
130 case FrontendStatusType::ATSC3_PLP_INFO: {
131 vector<FrontendStatusAtsc3PlpInfo> v;
132 FrontendStatusAtsc3PlpInfo info1{
133 .plpId = 3,
134 .isLocked = false,
135 .uec = 313,
136 };
137 FrontendStatusAtsc3PlpInfo info2{
138 .plpId = 5,
139 .isLocked = true,
140 .uec = 515,
141 };
142 v.push_back(info1);
143 v.push_back(info2);
144 status.plpInfo(v);
145 break;
146 }
147 default: {
148 continue;
149 }
150 }
151 statuses.push_back(status);
152 }
Amy016b7312019-09-16 15:51:28 -0700153 _hidl_cb(Result::SUCCESS, statuses);
154
155 return Void();
156}
157
158Return<Result> Frontend::setLna(bool /* bEnable */) {
159 ALOGV("%s", __FUNCTION__);
160
161 return Result::SUCCESS;
162}
163
Amy42a5b4b2019-10-03 16:49:48 -0700164Return<Result> Frontend::setLnb(uint32_t /* lnb */) {
Amy016b7312019-09-16 15:51:28 -0700165 ALOGV("%s", __FUNCTION__);
166
167 return Result::SUCCESS;
168}
169
Amy126ee922019-08-09 16:25:12 -0700170FrontendType Frontend::getFrontendType() {
171 return mType;
172}
173
174FrontendId Frontend::getFrontendId() {
175 return mId;
176}
177
Amy5094ae12019-10-04 18:43:21 -0700178string Frontend::getSourceFile() {
179 return mSourceStreamFile;
180}
181
Amy126ee922019-08-09 16:25:12 -0700182} // namespace implementation
183} // namespace V1_0
184} // namespace tuner
185} // namespace tv
186} // namespace hardware
187} // namespace android