blob: a8151d2b3774a6a68b3673a5aef929316c273fbd [file] [log] [blame]
Hongguang093c5f32021-08-09 19:46:34 -07001/**
2 * Copyright 2021, 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 "TunerHidlDemux"
18
19#include "TunerHidlDemux.h"
20
21#include "TunerHidlDvr.h"
22#include "TunerHidlFilter.h"
23#include "TunerHidlTimeFilter.h"
24
25using ::aidl::android::hardware::tv::tuner::DemuxFilterSubType;
26
27using HidlDemuxAlpFilterType = ::android::hardware::tv::tuner::V1_0::DemuxAlpFilterType;
28using HidlDemuxFilterMainType = ::android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
29using HidlDemuxFilterType = ::android::hardware::tv::tuner::V1_0::DemuxFilterType;
30using HidlDemuxIpFilterType = ::android::hardware::tv::tuner::V1_0::DemuxIpFilterType;
31using HidlDemuxMmtpFilterType = ::android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType;
32using HidlDemuxTlvFilterType = ::android::hardware::tv::tuner::V1_0::DemuxTlvFilterType;
33using HidlDemuxTsFilterType = ::android::hardware::tv::tuner::V1_0::DemuxTsFilterType;
34using HidlDvrType = ::android::hardware::tv::tuner::V1_0::DvrType;
35using HidlResult = ::android::hardware::tv::tuner::V1_0::Result;
36
37using namespace std;
38
39namespace aidl {
40namespace android {
41namespace media {
42namespace tv {
43namespace tuner {
44
45TunerHidlDemux::TunerHidlDemux(sp<IDemux> demux, int id) {
46 mDemux = demux;
47 mDemuxId = id;
48}
49
50TunerHidlDemux::~TunerHidlDemux() {
51 mDemux = nullptr;
52}
53
54::ndk::ScopedAStatus TunerHidlDemux::setFrontendDataSource(
55 const shared_ptr<ITunerFrontend>& in_frontend) {
56 if (mDemux == nullptr) {
57 ALOGE("IDemux is not initialized");
58 return ::ndk::ScopedAStatus::fromServiceSpecificError(
59 static_cast<int32_t>(HidlResult::UNAVAILABLE));
60 }
61
62 int frontendId;
63 in_frontend->getFrontendId(&frontendId);
64 HidlResult res = mDemux->setFrontendDataSource(frontendId);
65 if (res != HidlResult::SUCCESS) {
66 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
67 }
68 return ::ndk::ScopedAStatus::ok();
69}
70
71::ndk::ScopedAStatus TunerHidlDemux::setFrontendDataSourceById(int frontendId) {
72 if (mDemux == nullptr) {
73 ALOGE("IDemux is not initialized");
74 return ::ndk::ScopedAStatus::fromServiceSpecificError(
75 static_cast<int32_t>(HidlResult::UNAVAILABLE));
76 }
77
78 HidlResult res = mDemux->setFrontendDataSource(frontendId);
79 if (res != HidlResult::SUCCESS) {
80 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
81 }
82 return ::ndk::ScopedAStatus::ok();
83}
84
85::ndk::ScopedAStatus TunerHidlDemux::openFilter(const DemuxFilterType& in_type,
86 int32_t in_bufferSize,
87 const shared_ptr<ITunerFilterCallback>& in_cb,
88 shared_ptr<ITunerFilter>* _aidl_return) {
89 if (mDemux == nullptr) {
90 ALOGE("IDemux is not initialized");
91 return ::ndk::ScopedAStatus::fromServiceSpecificError(
92 static_cast<int32_t>(HidlResult::UNAVAILABLE));
93 }
94
95 HidlDemuxFilterMainType mainType = static_cast<HidlDemuxFilterMainType>(in_type.mainType);
96 HidlDemuxFilterType filterType{
97 .mainType = mainType,
98 };
99
100 switch (mainType) {
101 case HidlDemuxFilterMainType::TS:
102 filterType.subType.tsFilterType(static_cast<HidlDemuxTsFilterType>(
103 in_type.subType.get<DemuxFilterSubType::Tag::tsFilterType>()));
104 break;
105 case HidlDemuxFilterMainType::MMTP:
106 filterType.subType.mmtpFilterType(static_cast<HidlDemuxMmtpFilterType>(
107 in_type.subType.get<DemuxFilterSubType::Tag::mmtpFilterType>()));
108 break;
109 case HidlDemuxFilterMainType::IP:
110 filterType.subType.ipFilterType(static_cast<HidlDemuxIpFilterType>(
111 in_type.subType.get<DemuxFilterSubType::Tag::ipFilterType>()));
112 break;
113 case HidlDemuxFilterMainType::TLV:
114 filterType.subType.tlvFilterType(static_cast<HidlDemuxTlvFilterType>(
115 in_type.subType.get<DemuxFilterSubType::Tag::tlvFilterType>()));
116 break;
117 case HidlDemuxFilterMainType::ALP:
118 filterType.subType.alpFilterType(static_cast<HidlDemuxAlpFilterType>(
119 in_type.subType.get<DemuxFilterSubType::Tag::alpFilterType>()));
120 break;
121 }
122 HidlResult status;
123 sp<HidlIFilter> filterSp;
Hongguang34a479e2021-10-04 16:14:47 -0700124 sp<TunerHidlFilter::FilterCallback> filterCb = new TunerHidlFilter::FilterCallback(in_cb);
125 sp<::android::hardware::tv::tuner::V1_0::IFilterCallback> cbSp = filterCb;
Hongguang093c5f32021-08-09 19:46:34 -0700126 mDemux->openFilter(filterType, static_cast<uint32_t>(in_bufferSize), cbSp,
127 [&](HidlResult r, const sp<HidlIFilter>& filter) {
128 filterSp = filter;
129 status = r;
130 });
131 if (status != HidlResult::SUCCESS) {
132 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
133 }
134
Hongguang34a479e2021-10-04 16:14:47 -0700135 *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlFilter>(filterSp, filterCb, in_type);
Hongguang093c5f32021-08-09 19:46:34 -0700136 return ::ndk::ScopedAStatus::ok();
137}
138
139::ndk::ScopedAStatus TunerHidlDemux::openTimeFilter(shared_ptr<ITunerTimeFilter>* _aidl_return) {
140 if (mDemux == nullptr) {
141 ALOGE("IDemux is not initialized.");
142 return ::ndk::ScopedAStatus::fromServiceSpecificError(
143 static_cast<int32_t>(HidlResult::UNAVAILABLE));
144 }
145
146 HidlResult status;
147 sp<HidlITimeFilter> filterSp;
148 mDemux->openTimeFilter([&](HidlResult r, const sp<HidlITimeFilter>& filter) {
149 filterSp = filter;
150 status = r;
151 });
152 if (status != HidlResult::SUCCESS) {
153 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
154 }
155
156 *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlTimeFilter>(filterSp);
157 return ::ndk::ScopedAStatus::ok();
158}
159
160::ndk::ScopedAStatus TunerHidlDemux::getAvSyncHwId(const shared_ptr<ITunerFilter>& tunerFilter,
161 int32_t* _aidl_return) {
162 if (mDemux == nullptr) {
163 ALOGE("IDemux is not initialized.");
164 return ::ndk::ScopedAStatus::fromServiceSpecificError(
165 static_cast<int32_t>(HidlResult::UNAVAILABLE));
166 }
167
168 uint32_t avSyncHwId;
169 HidlResult res;
170 sp<HidlIFilter> halFilter = static_cast<TunerHidlFilter*>(tunerFilter.get())->getHalFilter();
171 mDemux->getAvSyncHwId(halFilter, [&](HidlResult r, uint32_t id) {
172 res = r;
173 avSyncHwId = id;
174 });
175 if (res != HidlResult::SUCCESS) {
176 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
177 }
178
179 *_aidl_return = (int)avSyncHwId;
180 return ::ndk::ScopedAStatus::ok();
181}
182
183::ndk::ScopedAStatus TunerHidlDemux::getAvSyncTime(int32_t avSyncHwId, int64_t* _aidl_return) {
184 if (mDemux == nullptr) {
185 ALOGE("IDemux is not initialized.");
186 return ::ndk::ScopedAStatus::fromServiceSpecificError(
187 static_cast<int32_t>(HidlResult::UNAVAILABLE));
188 }
189
190 uint64_t time;
191 HidlResult res;
192 mDemux->getAvSyncTime(static_cast<uint32_t>(avSyncHwId), [&](HidlResult r, uint64_t ts) {
193 res = r;
194 time = ts;
195 });
196 if (res != HidlResult::SUCCESS) {
197 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
198 }
199
200 *_aidl_return = (int64_t)time;
201 return ::ndk::ScopedAStatus::ok();
202}
203
204::ndk::ScopedAStatus TunerHidlDemux::openDvr(DvrType in_dvbType, int32_t in_bufferSize,
205 const shared_ptr<ITunerDvrCallback>& in_cb,
206 shared_ptr<ITunerDvr>* _aidl_return) {
207 if (mDemux == nullptr) {
208 ALOGE("IDemux is not initialized.");
209 return ::ndk::ScopedAStatus::fromServiceSpecificError(
210 static_cast<int32_t>(HidlResult::UNAVAILABLE));
211 }
212
213 HidlResult res;
214 sp<HidlIDvrCallback> callback = new TunerHidlDvr::DvrCallback(in_cb);
215 sp<HidlIDvr> hidlDvr;
216 mDemux->openDvr(static_cast<HidlDvrType>(in_dvbType), in_bufferSize, callback,
217 [&](HidlResult r, const sp<HidlIDvr>& dvr) {
218 hidlDvr = dvr;
219 res = r;
220 });
221 if (res != HidlResult::SUCCESS) {
222 *_aidl_return = nullptr;
223 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
224 }
225
226 *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlDvr>(hidlDvr, in_dvbType);
227 return ::ndk::ScopedAStatus::ok();
228}
229
230::ndk::ScopedAStatus TunerHidlDemux::connectCiCam(int32_t ciCamId) {
231 if (mDemux == nullptr) {
232 ALOGE("IDemux is not initialized.");
233 return ::ndk::ScopedAStatus::fromServiceSpecificError(
234 static_cast<int32_t>(HidlResult::UNAVAILABLE));
235 }
236
237 HidlResult res = mDemux->connectCiCam(static_cast<uint32_t>(ciCamId));
238 if (res != HidlResult::SUCCESS) {
239 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
240 }
241 return ::ndk::ScopedAStatus::ok();
242}
243
244::ndk::ScopedAStatus TunerHidlDemux::disconnectCiCam() {
245 if (mDemux == nullptr) {
246 ALOGE("IDemux is not initialized.");
247 return ::ndk::ScopedAStatus::fromServiceSpecificError(
248 static_cast<int32_t>(HidlResult::UNAVAILABLE));
249 }
250
251 HidlResult res = mDemux->disconnectCiCam();
252 if (res != HidlResult::SUCCESS) {
253 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
254 }
255 return ::ndk::ScopedAStatus::ok();
256}
257
258::ndk::ScopedAStatus TunerHidlDemux::close() {
259 if (mDemux == nullptr) {
260 ALOGE("IDemux is not initialized.");
261 return ::ndk::ScopedAStatus::fromServiceSpecificError(
262 static_cast<int32_t>(HidlResult::UNAVAILABLE));
263 }
264
265 HidlResult res = mDemux->close();
266 mDemux = nullptr;
267
268 if (res != HidlResult::SUCCESS) {
269 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
270 }
271 return ::ndk::ScopedAStatus::ok();
272}
273
274} // namespace tuner
275} // namespace tv
276} // namespace media
277} // namespace android
278} // namespace aidl