blob: 9a6ecf704fa3b9b1618db6f79785653bb485ab9a [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-Tuner"
18
19#include "Tuner.h"
20#include <android/hardware/tv/tuner/1.0/IFrontendCallback.h>
21#include <utils/Log.h>
Amyfd4243a2019-08-16 16:01:27 -070022#include "Demux.h"
23#include "Descrambler.h"
Amy126ee922019-08-09 16:25:12 -070024#include "Frontend.h"
Amy016b7312019-09-16 15:51:28 -070025#include "Lnb.h"
Amy126ee922019-08-09 16:25:12 -070026
27namespace android {
28namespace hardware {
29namespace tv {
30namespace tuner {
31namespace V1_0 {
32namespace implementation {
33
Henry Fangf3eec032019-08-15 18:57:08 -070034using ::android::hardware::tv::tuner::V1_0::DemuxId;
35
Amy126ee922019-08-09 16:25:12 -070036Tuner::Tuner() {
37 // Static Frontends array to maintain local frontends information
38 // Array index matches their FrontendId in the default impl
39 mFrontendSize = 8;
Amy5094ae12019-10-04 18:43:21 -070040 mFrontends[0] = new Frontend(FrontendType::DVBT, 0, this);
41 mFrontends[1] = new Frontend(FrontendType::ATSC, 1, this);
42 mFrontends[2] = new Frontend(FrontendType::DVBC, 2, this);
43 mFrontends[3] = new Frontend(FrontendType::DVBS, 3, this);
44 mFrontends[4] = new Frontend(FrontendType::DVBT, 4, this);
45 mFrontends[5] = new Frontend(FrontendType::ISDBT, 5, this);
46 mFrontends[6] = new Frontend(FrontendType::ANALOG, 6, this);
47 mFrontends[7] = new Frontend(FrontendType::ATSC, 7, this);
shubangb0c1bbb2020-04-06 22:41:33 -070048
49 FrontendInfo::FrontendCapabilities caps;
shubangb0c1bbb2020-04-06 22:41:33 -070050 caps = FrontendInfo::FrontendCapabilities();
51 caps.dvbtCaps(FrontendDvbtCapabilities());
52 mFrontendCaps[0] = caps;
53
54 caps = FrontendInfo::FrontendCapabilities();
55 caps.atscCaps(FrontendAtscCapabilities());
56 mFrontendCaps[1] = caps;
57
58 caps = FrontendInfo::FrontendCapabilities();
59 caps.dvbcCaps(FrontendDvbcCapabilities());
60 mFrontendCaps[2] = caps;
61
62 caps = FrontendInfo::FrontendCapabilities();
63 caps.dvbsCaps(FrontendDvbsCapabilities());
64 mFrontendCaps[3] = caps;
65
66 caps = FrontendInfo::FrontendCapabilities();
67 caps.dvbtCaps(FrontendDvbtCapabilities());
68 mFrontendCaps[4] = caps;
69
70 caps = FrontendInfo::FrontendCapabilities();
71 FrontendIsdbtCapabilities isdbtCaps{
72 .modeCap = FrontendIsdbtMode::MODE_1 | FrontendIsdbtMode::MODE_2,
73 .bandwidthCap = (unsigned int)FrontendIsdbtBandwidth::BANDWIDTH_6MHZ,
74 .modulationCap = (unsigned int)FrontendIsdbtModulation::MOD_16QAM,
75 // ISDBT shares coderate and guard interval with DVBT
76 .coderateCap = FrontendDvbtCoderate::CODERATE_4_5 | FrontendDvbtCoderate::CODERATE_6_7,
77 .guardIntervalCap = (unsigned int)FrontendDvbtGuardInterval::INTERVAL_1_128,
78 };
79 caps.isdbtCaps(isdbtCaps);
80 mFrontendCaps[5] = caps;
81
82 caps = FrontendInfo::FrontendCapabilities();
83 caps.analogCaps(FrontendAnalogCapabilities());
84 mFrontendCaps[6] = caps;
85
86 caps = FrontendInfo::FrontendCapabilities();
87 caps.atscCaps(FrontendAtscCapabilities());
88 mFrontendCaps[7] = caps;
shubangfd882512020-04-22 14:59:03 -070089
90 mLnbs.resize(2);
91 mLnbs[0] = new Lnb(0);
92 mLnbs[1] = new Lnb(1);
Amy126ee922019-08-09 16:25:12 -070093}
94
95Tuner::~Tuner() {}
96
97Return<void> Tuner::getFrontendIds(getFrontendIds_cb _hidl_cb) {
98 ALOGV("%s", __FUNCTION__);
99
100 vector<FrontendId> frontendIds;
101 frontendIds.resize(mFrontendSize);
102 for (int i = 0; i < mFrontendSize; i++) {
103 frontendIds[i] = mFrontends[i]->getFrontendId();
104 }
105
106 _hidl_cb(Result::SUCCESS, frontendIds);
107 return Void();
108}
109
110Return<void> Tuner::openFrontendById(uint32_t frontendId, openFrontendById_cb _hidl_cb) {
111 ALOGV("%s", __FUNCTION__);
112
113 if (frontendId >= mFrontendSize || frontendId < 0) {
114 ALOGW("[ WARN ] Frontend with id %d isn't available", frontendId);
115 _hidl_cb(Result::UNAVAILABLE, nullptr);
116 return Void();
117 }
118
119 _hidl_cb(Result::SUCCESS, mFrontends[frontendId]);
120 return Void();
121}
122
Henry Fangf3eec032019-08-15 18:57:08 -0700123Return<void> Tuner::openDemux(openDemux_cb _hidl_cb) {
124 ALOGV("%s", __FUNCTION__);
125
Amyfd4243a2019-08-16 16:01:27 -0700126 DemuxId demuxId = mLastUsedId + 1;
127 mLastUsedId += 1;
Amy5094ae12019-10-04 18:43:21 -0700128 sp<Demux> demux = new Demux(demuxId, this);
129 mDemuxes[demuxId] = demux;
Henry Fangf3eec032019-08-15 18:57:08 -0700130
131 _hidl_cb(Result::SUCCESS, demuxId, demux);
132 return Void();
133}
134
Amy42a5b4b2019-10-03 16:49:48 -0700135Return<void> Tuner::getDemuxCaps(getDemuxCaps_cb _hidl_cb) {
136 ALOGV("%s", __FUNCTION__);
137
138 DemuxCapabilities caps;
139
Amy Zhangf4c09fb2020-06-03 17:00:17 -0700140 // IP filter can be an MMTP filter's data source.
141 caps.linkCaps = {0x00, 0x00, 0x02, 0x00, 0x00};
Amy42a5b4b2019-10-03 16:49:48 -0700142 _hidl_cb(Result::SUCCESS, caps);
143 return Void();
144}
145
Henry Fangf3eec032019-08-15 18:57:08 -0700146Return<void> Tuner::openDescrambler(openDescrambler_cb _hidl_cb) {
147 ALOGV("%s", __FUNCTION__);
148
Amyfd4243a2019-08-16 16:01:27 -0700149 sp<IDescrambler> descrambler = new Descrambler();
Henry Fangf3eec032019-08-15 18:57:08 -0700150
151 _hidl_cb(Result::SUCCESS, descrambler);
152 return Void();
153}
154
Amy Zhang050bf782020-03-27 14:54:48 -0700155Return<void> Tuner::getFrontendInfo(FrontendId frontendId, getFrontendInfo_cb _hidl_cb) {
Amy016b7312019-09-16 15:51:28 -0700156 ALOGV("%s", __FUNCTION__);
157
Amy Zhang050bf782020-03-27 14:54:48 -0700158 FrontendInfo info;
159 if (frontendId >= mFrontendSize) {
160 _hidl_cb(Result::INVALID_ARGUMENT, info);
161 return Void();
162 }
163
shubangf809fae2020-04-29 18:16:39 -0700164 vector<FrontendStatusType> statusCaps = {
165 FrontendStatusType::DEMOD_LOCK,
166 FrontendStatusType::SNR,
167 FrontendStatusType::FEC,
168 FrontendStatusType::MODULATION,
169 FrontendStatusType::PLP_ID,
170 FrontendStatusType::LAYER_ERROR,
171 FrontendStatusType::ATSC3_PLP_INFO,
172 };
173 // assign randomly selected values for testing.
174 info = {
175 .type = mFrontends[frontendId]->getFrontendType(),
176 .minFrequency = 139,
177 .maxFrequency = 1139,
178 .minSymbolRate = 45,
179 .maxSymbolRate = 1145,
180 .acquireRange = 30,
181 .exclusiveGroupId = 57,
182 .statusCaps = statusCaps,
183 .frontendCaps = mFrontendCaps[frontendId],
184 };
Amy016b7312019-09-16 15:51:28 -0700185
186 _hidl_cb(Result::SUCCESS, info);
187 return Void();
188}
189
190Return<void> Tuner::getLnbIds(getLnbIds_cb _hidl_cb) {
191 ALOGV("%s", __FUNCTION__);
192
193 vector<LnbId> lnbIds;
shubangfd882512020-04-22 14:59:03 -0700194 lnbIds.resize(mLnbs.size());
195 for (int i = 0; i < lnbIds.size(); i++) {
196 lnbIds[i] = mLnbs[i]->getId();
197 }
Amy016b7312019-09-16 15:51:28 -0700198
199 _hidl_cb(Result::SUCCESS, lnbIds);
200 return Void();
201}
202
shubangfd882512020-04-22 14:59:03 -0700203Return<void> Tuner::openLnbById(LnbId lnbId, openLnbById_cb _hidl_cb) {
Amy016b7312019-09-16 15:51:28 -0700204 ALOGV("%s", __FUNCTION__);
205
shubangfd882512020-04-22 14:59:03 -0700206 if (lnbId >= mLnbs.size()) {
207 _hidl_cb(Result::INVALID_ARGUMENT, nullptr);
208 return Void();
209 }
Amy016b7312019-09-16 15:51:28 -0700210
shubangfd882512020-04-22 14:59:03 -0700211 _hidl_cb(Result::SUCCESS, mLnbs[lnbId]);
Amy016b7312019-09-16 15:51:28 -0700212 return Void();
213}
214
Amy5094ae12019-10-04 18:43:21 -0700215sp<Frontend> Tuner::getFrontendById(uint32_t frontendId) {
216 ALOGV("%s", __FUNCTION__);
217
218 return mFrontends[frontendId];
219}
220
Henry Fangfe019ac2019-12-23 18:13:43 -0800221Return<void> Tuner::openLnbByName(const hidl_string& /*lnbName*/, openLnbByName_cb _hidl_cb) {
222 ALOGV("%s", __FUNCTION__);
223
224 sp<ILnb> lnb = new Lnb();
225
226 _hidl_cb(Result::SUCCESS, 1234, lnb);
227 return Void();
228}
229
Amy5094ae12019-10-04 18:43:21 -0700230void Tuner::setFrontendAsDemuxSource(uint32_t frontendId, uint32_t demuxId) {
231 mFrontendToDemux[frontendId] = demuxId;
Amy Zhange0422232020-06-12 12:53:12 -0700232 if (mFrontends[frontendId] != nullptr && mFrontends[frontendId]->isLocked()) {
233 mDemuxes[demuxId]->startFrontendInputLoop();
234 }
Amy5094ae12019-10-04 18:43:21 -0700235}
236
Amy Zhang45c12632020-07-16 14:06:25 -0700237void Tuner::removeDemux(uint32_t demuxId) {
238 map<uint32_t, uint32_t>::iterator it;
239 for (it = mFrontendToDemux.begin(); it != mFrontendToDemux.end(); it++) {
240 if (it->second == demuxId) {
241 it = mFrontendToDemux.erase(it);
242 break;
243 }
244 }
245 mDemuxes.erase(demuxId);
246}
247
248void Tuner::removeFrontend(uint32_t frontendId) {
249 mFrontendToDemux.erase(frontendId);
250}
251
Amy5094ae12019-10-04 18:43:21 -0700252void Tuner::frontendStopTune(uint32_t frontendId) {
253 map<uint32_t, uint32_t>::iterator it = mFrontendToDemux.find(frontendId);
254 uint32_t demuxId;
255 if (it != mFrontendToDemux.end()) {
256 demuxId = it->second;
Amy5ed13572019-12-11 15:33:51 -0800257 mDemuxes[demuxId]->stopFrontendInput();
Amy5094ae12019-10-04 18:43:21 -0700258 }
259}
260
Amy Zhang0fe25be2020-04-08 17:30:52 -0700261void Tuner::frontendStartTune(uint32_t frontendId) {
262 map<uint32_t, uint32_t>::iterator it = mFrontendToDemux.find(frontendId);
263 uint32_t demuxId;
264 if (it != mFrontendToDemux.end()) {
265 demuxId = it->second;
266 mDemuxes[demuxId]->startFrontendInputLoop();
267 }
268}
269
Amy126ee922019-08-09 16:25:12 -0700270} // namespace implementation
271} // namespace V1_0
272} // namespace tuner
273} // namespace tv
274} // namespace hardware
275} // namespace android