blob: c220ea26823577480ab0fc6587d4fb8c7d2762ec [file] [log] [blame]
Amy Zhangbb94eeb2020-07-09 22:48:04 -07001/*
2 * Copyright 2020 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.1-Tuner"
18
19#include "Tuner.h"
20#include <utils/Log.h>
21#include "Demux.h"
22#include "Descrambler.h"
23#include "Frontend.h"
24#include "Lnb.h"
25
26namespace android {
27namespace hardware {
28namespace tv {
29namespace tuner {
30namespace V1_0 {
31namespace implementation {
32
33Tuner::Tuner() {
34 // Static Frontends array to maintain local frontends information
35 // Array index matches their FrontendId in the default impl
36 mFrontendSize = 8;
37 mFrontends.resize(mFrontendSize);
38 mFrontends[0] = new Frontend(FrontendType::DVBT, 0, this);
39 mFrontends[1] = new Frontend(FrontendType::ATSC, 1, this);
40 mFrontends[2] = new Frontend(FrontendType::DVBC, 2, this);
41 mFrontends[3] = new Frontend(FrontendType::DVBS, 3, this);
42 mFrontends[4] = new Frontend(FrontendType::DVBT, 4, this);
43 mFrontends[5] = new Frontend(FrontendType::ISDBT, 5, this);
44 mFrontends[6] = new Frontend(FrontendType::ANALOG, 6, this);
45 mFrontends[7] = new Frontend(FrontendType::ATSC, 7, this);
46
47 FrontendInfo::FrontendCapabilities caps;
48 mFrontendCaps.resize(mFrontendSize);
49 caps = FrontendInfo::FrontendCapabilities();
50 caps.dvbtCaps(FrontendDvbtCapabilities());
51 mFrontendCaps[0] = caps;
52
53 caps = FrontendInfo::FrontendCapabilities();
54 caps.atscCaps(FrontendAtscCapabilities());
55 mFrontendCaps[1] = caps;
56
57 caps = FrontendInfo::FrontendCapabilities();
58 caps.dvbcCaps(FrontendDvbcCapabilities());
59 mFrontendCaps[2] = caps;
60
61 caps = FrontendInfo::FrontendCapabilities();
62 caps.dvbsCaps(FrontendDvbsCapabilities());
63 mFrontendCaps[3] = caps;
64
65 caps = FrontendInfo::FrontendCapabilities();
66 caps.dvbtCaps(FrontendDvbtCapabilities());
67 mFrontendCaps[4] = caps;
68
69 caps = FrontendInfo::FrontendCapabilities();
70 FrontendIsdbtCapabilities isdbtCaps{
71 .modeCap = FrontendIsdbtMode::MODE_1 | FrontendIsdbtMode::MODE_2,
72 .bandwidthCap = (unsigned int)FrontendIsdbtBandwidth::BANDWIDTH_6MHZ,
73 .modulationCap = (unsigned int)FrontendIsdbtModulation::MOD_16QAM,
74 // ISDBT shares coderate and guard interval with DVBT
75 .coderateCap = FrontendDvbtCoderate::CODERATE_4_5 | FrontendDvbtCoderate::CODERATE_6_7,
76 .guardIntervalCap = (unsigned int)FrontendDvbtGuardInterval::INTERVAL_1_128,
77 };
78 caps.isdbtCaps(isdbtCaps);
79 mFrontendCaps[5] = caps;
80
81 caps = FrontendInfo::FrontendCapabilities();
82 caps.analogCaps(FrontendAnalogCapabilities());
83 mFrontendCaps[6] = caps;
84
85 caps = FrontendInfo::FrontendCapabilities();
86 caps.atscCaps(FrontendAtscCapabilities());
87 mFrontendCaps[7] = caps;
88
89 mLnbs.resize(2);
90 mLnbs[0] = new Lnb(0);
91 mLnbs[1] = new Lnb(1);
92}
93
94Tuner::~Tuner() {}
95
96Return<void> Tuner::getFrontendIds(getFrontendIds_cb _hidl_cb) {
97 ALOGV("%s", __FUNCTION__);
98
99 vector<FrontendId> frontendIds;
100 frontendIds.resize(mFrontendSize);
101 for (int i = 0; i < mFrontendSize; i++) {
102 frontendIds[i] = mFrontends[i]->getFrontendId();
103 }
104
105 _hidl_cb(Result::SUCCESS, frontendIds);
106 return Void();
107}
108
109Return<void> Tuner::openFrontendById(uint32_t frontendId, openFrontendById_cb _hidl_cb) {
110 ALOGV("%s", __FUNCTION__);
111
112 if (frontendId >= mFrontendSize || frontendId < 0) {
113 ALOGW("[ WARN ] Frontend with id %d isn't available", frontendId);
114 _hidl_cb(Result::UNAVAILABLE, nullptr);
115 return Void();
116 }
117
118 _hidl_cb(Result::SUCCESS, mFrontends[frontendId]);
119 return Void();
120}
121
122Return<void> Tuner::openDemux(openDemux_cb _hidl_cb) {
123 ALOGV("%s", __FUNCTION__);
124
125 uint32_t demuxId = mLastUsedId + 1;
126 mLastUsedId += 1;
127 sp<Demux> demux = new Demux(demuxId, this);
128 mDemuxes[demuxId] = demux;
129
130 _hidl_cb(Result::SUCCESS, demuxId, demux);
131 return Void();
132}
133
134Return<void> Tuner::getDemuxCaps(getDemuxCaps_cb _hidl_cb) {
135 ALOGV("%s", __FUNCTION__);
136
137 DemuxCapabilities caps;
138
139 // IP filter can be an MMTP filter's data source.
140 caps.linkCaps = {0x00, 0x00, 0x02, 0x00, 0x00};
141 _hidl_cb(Result::SUCCESS, caps);
142 return Void();
143}
144
145Return<void> Tuner::openDescrambler(openDescrambler_cb _hidl_cb) {
146 ALOGV("%s", __FUNCTION__);
147
148 sp<V1_0::IDescrambler> descrambler = new Descrambler();
149
150 _hidl_cb(Result::SUCCESS, descrambler);
151 return Void();
152}
153
154Return<void> Tuner::getFrontendInfo(FrontendId frontendId, getFrontendInfo_cb _hidl_cb) {
155 ALOGV("%s", __FUNCTION__);
156
157 FrontendInfo info;
158 if (frontendId >= mFrontendSize) {
159 _hidl_cb(Result::INVALID_ARGUMENT, info);
160 return Void();
161 }
162
163 vector<FrontendStatusType> statusCaps = {
164 FrontendStatusType::DEMOD_LOCK,
165 FrontendStatusType::SNR,
166 FrontendStatusType::FEC,
167 FrontendStatusType::MODULATION,
168 FrontendStatusType::PLP_ID,
169 FrontendStatusType::LAYER_ERROR,
170 FrontendStatusType::ATSC3_PLP_INFO,
171 };
172 // assign randomly selected values for testing.
173 info = {
174 .type = mFrontends[frontendId]->getFrontendType(),
175 .minFrequency = 139,
176 .maxFrequency = 1139,
177 .minSymbolRate = 45,
178 .maxSymbolRate = 1145,
179 .acquireRange = 30,
180 .exclusiveGroupId = 57,
181 .statusCaps = statusCaps,
182 .frontendCaps = mFrontendCaps[frontendId],
183 };
184
185 _hidl_cb(Result::SUCCESS, info);
186 return Void();
187}
188
189Return<void> Tuner::getLnbIds(getLnbIds_cb _hidl_cb) {
190 ALOGV("%s", __FUNCTION__);
191
192 vector<V1_0::LnbId> lnbIds;
193 lnbIds.resize(mLnbs.size());
194 for (int i = 0; i < lnbIds.size(); i++) {
195 lnbIds[i] = mLnbs[i]->getId();
196 }
197
198 _hidl_cb(Result::SUCCESS, lnbIds);
199 return Void();
200}
201
202Return<void> Tuner::openLnbById(V1_0::LnbId lnbId, openLnbById_cb _hidl_cb) {
203 ALOGV("%s", __FUNCTION__);
204
205 if (lnbId >= mLnbs.size()) {
206 _hidl_cb(Result::INVALID_ARGUMENT, nullptr);
207 return Void();
208 }
209
210 _hidl_cb(Result::SUCCESS, mLnbs[lnbId]);
211 return Void();
212}
213
214sp<Frontend> Tuner::getFrontendById(uint32_t frontendId) {
215 ALOGV("%s", __FUNCTION__);
216
217 return mFrontends[frontendId];
218}
219
220Return<void> Tuner::openLnbByName(const hidl_string& /*lnbName*/, openLnbByName_cb _hidl_cb) {
221 ALOGV("%s", __FUNCTION__);
222
223 sp<V1_0::ILnb> lnb = new Lnb();
224
225 _hidl_cb(Result::SUCCESS, 1234, lnb);
226 return Void();
227}
228
229void Tuner::setFrontendAsDemuxSource(uint32_t frontendId, uint32_t demuxId) {
230 mFrontendToDemux[frontendId] = demuxId;
231 if (mFrontends[frontendId] != nullptr && mFrontends[frontendId]->isLocked()) {
232 mDemuxes[demuxId]->startFrontendInputLoop();
233 }
234}
235
236void Tuner::frontendStopTune(uint32_t frontendId) {
237 map<uint32_t, uint32_t>::iterator it = mFrontendToDemux.find(frontendId);
238 uint32_t demuxId;
239 if (it != mFrontendToDemux.end()) {
240 demuxId = it->second;
241 mDemuxes[demuxId]->stopFrontendInput();
242 }
243}
244
245void Tuner::frontendStartTune(uint32_t frontendId) {
246 map<uint32_t, uint32_t>::iterator it = mFrontendToDemux.find(frontendId);
247 uint32_t demuxId;
248 if (it != mFrontendToDemux.end()) {
249 demuxId = it->second;
250 mDemuxes[demuxId]->startFrontendInputLoop();
251 }
252}
253
254} // namespace implementation
255} // namespace V1_0
256} // namespace tuner
257} // namespace tv
258} // namespace hardware
259} // namespace android