blob: 821d83f87b5c791510a58fca889556eca3cf903a [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
142 _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;
232}
233
234void Tuner::frontendStopTune(uint32_t frontendId) {
235 map<uint32_t, uint32_t>::iterator it = mFrontendToDemux.find(frontendId);
236 uint32_t demuxId;
237 if (it != mFrontendToDemux.end()) {
238 demuxId = it->second;
Amy5ed13572019-12-11 15:33:51 -0800239 mDemuxes[demuxId]->stopFrontendInput();
Amy5094ae12019-10-04 18:43:21 -0700240 }
241}
242
Amy Zhang0fe25be2020-04-08 17:30:52 -0700243void Tuner::frontendStartTune(uint32_t frontendId) {
244 map<uint32_t, uint32_t>::iterator it = mFrontendToDemux.find(frontendId);
245 uint32_t demuxId;
246 if (it != mFrontendToDemux.end()) {
247 demuxId = it->second;
248 mDemuxes[demuxId]->startFrontendInputLoop();
249 }
250}
251
Amy126ee922019-08-09 16:25:12 -0700252} // namespace implementation
253} // namespace V1_0
254} // namespace tuner
255} // namespace tv
256} // namespace hardware
257} // namespace android