blob: ae8070c5f7b46c3cd176cde56d7a5f0fc5ee4a3b [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;
40 mFrontends.resize(mFrontendSize);
Amy5094ae12019-10-04 18:43:21 -070041 mFrontends[0] = new Frontend(FrontendType::DVBT, 0, this);
42 mFrontends[1] = new Frontend(FrontendType::ATSC, 1, this);
43 mFrontends[2] = new Frontend(FrontendType::DVBC, 2, this);
44 mFrontends[3] = new Frontend(FrontendType::DVBS, 3, this);
45 mFrontends[4] = new Frontend(FrontendType::DVBT, 4, this);
46 mFrontends[5] = new Frontend(FrontendType::ISDBT, 5, this);
47 mFrontends[6] = new Frontend(FrontendType::ANALOG, 6, this);
48 mFrontends[7] = new Frontend(FrontendType::ATSC, 7, this);
shubangb0c1bbb2020-04-06 22:41:33 -070049
50 FrontendInfo::FrontendCapabilities caps;
51 mFrontendCaps.resize(mFrontendSize);
52 caps = FrontendInfo::FrontendCapabilities();
53 caps.dvbtCaps(FrontendDvbtCapabilities());
54 mFrontendCaps[0] = caps;
55
56 caps = FrontendInfo::FrontendCapabilities();
57 caps.atscCaps(FrontendAtscCapabilities());
58 mFrontendCaps[1] = caps;
59
60 caps = FrontendInfo::FrontendCapabilities();
61 caps.dvbcCaps(FrontendDvbcCapabilities());
62 mFrontendCaps[2] = caps;
63
64 caps = FrontendInfo::FrontendCapabilities();
65 caps.dvbsCaps(FrontendDvbsCapabilities());
66 mFrontendCaps[3] = caps;
67
68 caps = FrontendInfo::FrontendCapabilities();
69 caps.dvbtCaps(FrontendDvbtCapabilities());
70 mFrontendCaps[4] = caps;
71
72 caps = FrontendInfo::FrontendCapabilities();
73 FrontendIsdbtCapabilities isdbtCaps{
74 .modeCap = FrontendIsdbtMode::MODE_1 | FrontendIsdbtMode::MODE_2,
75 .bandwidthCap = (unsigned int)FrontendIsdbtBandwidth::BANDWIDTH_6MHZ,
76 .modulationCap = (unsigned int)FrontendIsdbtModulation::MOD_16QAM,
77 // ISDBT shares coderate and guard interval with DVBT
78 .coderateCap = FrontendDvbtCoderate::CODERATE_4_5 | FrontendDvbtCoderate::CODERATE_6_7,
79 .guardIntervalCap = (unsigned int)FrontendDvbtGuardInterval::INTERVAL_1_128,
80 };
81 caps.isdbtCaps(isdbtCaps);
82 mFrontendCaps[5] = caps;
83
84 caps = FrontendInfo::FrontendCapabilities();
85 caps.analogCaps(FrontendAnalogCapabilities());
86 mFrontendCaps[6] = caps;
87
88 caps = FrontendInfo::FrontendCapabilities();
89 caps.atscCaps(FrontendAtscCapabilities());
90 mFrontendCaps[7] = caps;
shubangfd882512020-04-22 14:59:03 -070091
92 mLnbs.resize(2);
93 mLnbs[0] = new Lnb(0);
94 mLnbs[1] = new Lnb(1);
Amy126ee922019-08-09 16:25:12 -070095}
96
97Tuner::~Tuner() {}
98
99Return<void> Tuner::getFrontendIds(getFrontendIds_cb _hidl_cb) {
100 ALOGV("%s", __FUNCTION__);
101
102 vector<FrontendId> frontendIds;
103 frontendIds.resize(mFrontendSize);
104 for (int i = 0; i < mFrontendSize; i++) {
105 frontendIds[i] = mFrontends[i]->getFrontendId();
106 }
107
108 _hidl_cb(Result::SUCCESS, frontendIds);
109 return Void();
110}
111
112Return<void> Tuner::openFrontendById(uint32_t frontendId, openFrontendById_cb _hidl_cb) {
113 ALOGV("%s", __FUNCTION__);
114
115 if (frontendId >= mFrontendSize || frontendId < 0) {
116 ALOGW("[ WARN ] Frontend with id %d isn't available", frontendId);
117 _hidl_cb(Result::UNAVAILABLE, nullptr);
118 return Void();
119 }
120
121 _hidl_cb(Result::SUCCESS, mFrontends[frontendId]);
122 return Void();
123}
124
Henry Fangf3eec032019-08-15 18:57:08 -0700125Return<void> Tuner::openDemux(openDemux_cb _hidl_cb) {
126 ALOGV("%s", __FUNCTION__);
127
Amyfd4243a2019-08-16 16:01:27 -0700128 DemuxId demuxId = mLastUsedId + 1;
129 mLastUsedId += 1;
Amy5094ae12019-10-04 18:43:21 -0700130 sp<Demux> demux = new Demux(demuxId, this);
131 mDemuxes[demuxId] = demux;
Henry Fangf3eec032019-08-15 18:57:08 -0700132
133 _hidl_cb(Result::SUCCESS, demuxId, demux);
134 return Void();
135}
136
Amy42a5b4b2019-10-03 16:49:48 -0700137Return<void> Tuner::getDemuxCaps(getDemuxCaps_cb _hidl_cb) {
138 ALOGV("%s", __FUNCTION__);
139
140 DemuxCapabilities caps;
141
Amy Zhangf4c09fb2020-06-03 17:00:17 -0700142 // IP filter can be an MMTP filter's data source.
143 caps.linkCaps = {0x00, 0x00, 0x02, 0x00, 0x00};
Amy42a5b4b2019-10-03 16:49:48 -0700144 _hidl_cb(Result::SUCCESS, caps);
145 return Void();
146}
147
Henry Fangf3eec032019-08-15 18:57:08 -0700148Return<void> Tuner::openDescrambler(openDescrambler_cb _hidl_cb) {
149 ALOGV("%s", __FUNCTION__);
150
Amyfd4243a2019-08-16 16:01:27 -0700151 sp<IDescrambler> descrambler = new Descrambler();
Henry Fangf3eec032019-08-15 18:57:08 -0700152
153 _hidl_cb(Result::SUCCESS, descrambler);
154 return Void();
155}
156
Amy Zhang050bf782020-03-27 14:54:48 -0700157Return<void> Tuner::getFrontendInfo(FrontendId frontendId, getFrontendInfo_cb _hidl_cb) {
Amy016b7312019-09-16 15:51:28 -0700158 ALOGV("%s", __FUNCTION__);
159
Amy Zhang050bf782020-03-27 14:54:48 -0700160 FrontendInfo info;
161 if (frontendId >= mFrontendSize) {
162 _hidl_cb(Result::INVALID_ARGUMENT, info);
163 return Void();
164 }
165
shubangf809fae2020-04-29 18:16:39 -0700166 vector<FrontendStatusType> statusCaps = {
167 FrontendStatusType::DEMOD_LOCK,
168 FrontendStatusType::SNR,
169 FrontendStatusType::FEC,
170 FrontendStatusType::MODULATION,
171 FrontendStatusType::PLP_ID,
172 FrontendStatusType::LAYER_ERROR,
173 FrontendStatusType::ATSC3_PLP_INFO,
174 };
175 // assign randomly selected values for testing.
176 info = {
177 .type = mFrontends[frontendId]->getFrontendType(),
178 .minFrequency = 139,
179 .maxFrequency = 1139,
180 .minSymbolRate = 45,
181 .maxSymbolRate = 1145,
182 .acquireRange = 30,
183 .exclusiveGroupId = 57,
184 .statusCaps = statusCaps,
185 .frontendCaps = mFrontendCaps[frontendId],
186 };
Amy016b7312019-09-16 15:51:28 -0700187
188 _hidl_cb(Result::SUCCESS, info);
189 return Void();
190}
191
192Return<void> Tuner::getLnbIds(getLnbIds_cb _hidl_cb) {
193 ALOGV("%s", __FUNCTION__);
194
195 vector<LnbId> lnbIds;
shubangfd882512020-04-22 14:59:03 -0700196 lnbIds.resize(mLnbs.size());
197 for (int i = 0; i < lnbIds.size(); i++) {
198 lnbIds[i] = mLnbs[i]->getId();
199 }
Amy016b7312019-09-16 15:51:28 -0700200
201 _hidl_cb(Result::SUCCESS, lnbIds);
202 return Void();
203}
204
shubangfd882512020-04-22 14:59:03 -0700205Return<void> Tuner::openLnbById(LnbId lnbId, openLnbById_cb _hidl_cb) {
Amy016b7312019-09-16 15:51:28 -0700206 ALOGV("%s", __FUNCTION__);
207
shubangfd882512020-04-22 14:59:03 -0700208 if (lnbId >= mLnbs.size()) {
209 _hidl_cb(Result::INVALID_ARGUMENT, nullptr);
210 return Void();
211 }
Amy016b7312019-09-16 15:51:28 -0700212
shubangfd882512020-04-22 14:59:03 -0700213 _hidl_cb(Result::SUCCESS, mLnbs[lnbId]);
Amy016b7312019-09-16 15:51:28 -0700214 return Void();
215}
216
Amy5094ae12019-10-04 18:43:21 -0700217sp<Frontend> Tuner::getFrontendById(uint32_t frontendId) {
218 ALOGV("%s", __FUNCTION__);
219
220 return mFrontends[frontendId];
221}
222
Henry Fangfe019ac2019-12-23 18:13:43 -0800223Return<void> Tuner::openLnbByName(const hidl_string& /*lnbName*/, openLnbByName_cb _hidl_cb) {
224 ALOGV("%s", __FUNCTION__);
225
226 sp<ILnb> lnb = new Lnb();
227
228 _hidl_cb(Result::SUCCESS, 1234, lnb);
229 return Void();
230}
231
Amy5094ae12019-10-04 18:43:21 -0700232void Tuner::setFrontendAsDemuxSource(uint32_t frontendId, uint32_t demuxId) {
233 mFrontendToDemux[frontendId] = demuxId;
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;
Amy5ed13572019-12-11 15:33:51 -0800241 mDemuxes[demuxId]->stopFrontendInput();
Amy5094ae12019-10-04 18:43:21 -0700242 }
243}
244
Amy Zhang0fe25be2020-04-08 17:30:52 -0700245void 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
Amy126ee922019-08-09 16:25:12 -0700254} // namespace implementation
255} // namespace V1_0
256} // namespace tuner
257} // namespace tv
258} // namespace hardware
259} // namespace android