blob: bbb7782ca6a98092de03bee4aca0b2acc4812e60 [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"
Hongguang5eef5142022-08-09 20:26:42 -070023#include "TunerHidlService.h"
Hongguang093c5f32021-08-09 19:46:34 -070024#include "TunerHidlTimeFilter.h"
25
26using ::aidl::android::hardware::tv::tuner::DemuxFilterSubType;
27
28using HidlDemuxAlpFilterType = ::android::hardware::tv::tuner::V1_0::DemuxAlpFilterType;
29using HidlDemuxFilterMainType = ::android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
30using HidlDemuxFilterType = ::android::hardware::tv::tuner::V1_0::DemuxFilterType;
31using HidlDemuxIpFilterType = ::android::hardware::tv::tuner::V1_0::DemuxIpFilterType;
32using HidlDemuxMmtpFilterType = ::android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType;
33using HidlDemuxTlvFilterType = ::android::hardware::tv::tuner::V1_0::DemuxTlvFilterType;
34using HidlDemuxTsFilterType = ::android::hardware::tv::tuner::V1_0::DemuxTsFilterType;
35using HidlDvrType = ::android::hardware::tv::tuner::V1_0::DvrType;
36using HidlResult = ::android::hardware::tv::tuner::V1_0::Result;
37
38using namespace std;
39
40namespace aidl {
41namespace android {
42namespace media {
43namespace tv {
44namespace tuner {
45
Hongguang5eef5142022-08-09 20:26:42 -070046TunerHidlDemux::TunerHidlDemux(const sp<IDemux> demux, const int id,
47 const shared_ptr<TunerHidlService> tuner) {
Hongguang093c5f32021-08-09 19:46:34 -070048 mDemux = demux;
49 mDemuxId = id;
Hongguang5eef5142022-08-09 20:26:42 -070050 mTunerService = tuner;
Hongguang093c5f32021-08-09 19:46:34 -070051}
52
53TunerHidlDemux::~TunerHidlDemux() {
54 mDemux = nullptr;
Hongguang5eef5142022-08-09 20:26:42 -070055 mTunerService = nullptr;
Hongguang093c5f32021-08-09 19:46:34 -070056}
57
58::ndk::ScopedAStatus TunerHidlDemux::setFrontendDataSource(
59 const shared_ptr<ITunerFrontend>& in_frontend) {
Hongguang093c5f32021-08-09 19:46:34 -070060 int frontendId;
61 in_frontend->getFrontendId(&frontendId);
62 HidlResult res = mDemux->setFrontendDataSource(frontendId);
63 if (res != HidlResult::SUCCESS) {
64 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
65 }
66 return ::ndk::ScopedAStatus::ok();
67}
68
69::ndk::ScopedAStatus TunerHidlDemux::setFrontendDataSourceById(int frontendId) {
Hongguang093c5f32021-08-09 19:46:34 -070070 HidlResult res = mDemux->setFrontendDataSource(frontendId);
71 if (res != HidlResult::SUCCESS) {
72 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
73 }
74 return ::ndk::ScopedAStatus::ok();
75}
76
77::ndk::ScopedAStatus TunerHidlDemux::openFilter(const DemuxFilterType& in_type,
78 int32_t in_bufferSize,
79 const shared_ptr<ITunerFilterCallback>& in_cb,
80 shared_ptr<ITunerFilter>* _aidl_return) {
Hongguang093c5f32021-08-09 19:46:34 -070081 HidlDemuxFilterMainType mainType = static_cast<HidlDemuxFilterMainType>(in_type.mainType);
82 HidlDemuxFilterType filterType{
83 .mainType = mainType,
84 };
85
86 switch (mainType) {
87 case HidlDemuxFilterMainType::TS:
88 filterType.subType.tsFilterType(static_cast<HidlDemuxTsFilterType>(
89 in_type.subType.get<DemuxFilterSubType::Tag::tsFilterType>()));
90 break;
91 case HidlDemuxFilterMainType::MMTP:
92 filterType.subType.mmtpFilterType(static_cast<HidlDemuxMmtpFilterType>(
93 in_type.subType.get<DemuxFilterSubType::Tag::mmtpFilterType>()));
94 break;
95 case HidlDemuxFilterMainType::IP:
96 filterType.subType.ipFilterType(static_cast<HidlDemuxIpFilterType>(
97 in_type.subType.get<DemuxFilterSubType::Tag::ipFilterType>()));
98 break;
99 case HidlDemuxFilterMainType::TLV:
100 filterType.subType.tlvFilterType(static_cast<HidlDemuxTlvFilterType>(
101 in_type.subType.get<DemuxFilterSubType::Tag::tlvFilterType>()));
102 break;
103 case HidlDemuxFilterMainType::ALP:
104 filterType.subType.alpFilterType(static_cast<HidlDemuxAlpFilterType>(
105 in_type.subType.get<DemuxFilterSubType::Tag::alpFilterType>()));
106 break;
107 }
108 HidlResult status;
109 sp<HidlIFilter> filterSp;
Hongguang34a479e2021-10-04 16:14:47 -0700110 sp<TunerHidlFilter::FilterCallback> filterCb = new TunerHidlFilter::FilterCallback(in_cb);
111 sp<::android::hardware::tv::tuner::V1_0::IFilterCallback> cbSp = filterCb;
Hongguang093c5f32021-08-09 19:46:34 -0700112 mDemux->openFilter(filterType, static_cast<uint32_t>(in_bufferSize), cbSp,
113 [&](HidlResult r, const sp<HidlIFilter>& filter) {
114 filterSp = filter;
115 status = r;
116 });
117 if (status != HidlResult::SUCCESS) {
118 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
119 }
120
Hongguang5eef5142022-08-09 20:26:42 -0700121 *_aidl_return =
122 ::ndk::SharedRefBase::make<TunerHidlFilter>(filterSp, filterCb, in_type, mTunerService);
Hongguang093c5f32021-08-09 19:46:34 -0700123 return ::ndk::ScopedAStatus::ok();
124}
125
126::ndk::ScopedAStatus TunerHidlDemux::openTimeFilter(shared_ptr<ITunerTimeFilter>* _aidl_return) {
Hongguang093c5f32021-08-09 19:46:34 -0700127 HidlResult status;
128 sp<HidlITimeFilter> filterSp;
129 mDemux->openTimeFilter([&](HidlResult r, const sp<HidlITimeFilter>& filter) {
130 filterSp = filter;
131 status = r;
132 });
133 if (status != HidlResult::SUCCESS) {
134 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
135 }
136
137 *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlTimeFilter>(filterSp);
138 return ::ndk::ScopedAStatus::ok();
139}
140
141::ndk::ScopedAStatus TunerHidlDemux::getAvSyncHwId(const shared_ptr<ITunerFilter>& tunerFilter,
142 int32_t* _aidl_return) {
Hongguang093c5f32021-08-09 19:46:34 -0700143 uint32_t avSyncHwId;
144 HidlResult res;
145 sp<HidlIFilter> halFilter = static_cast<TunerHidlFilter*>(tunerFilter.get())->getHalFilter();
146 mDemux->getAvSyncHwId(halFilter, [&](HidlResult r, uint32_t id) {
147 res = r;
148 avSyncHwId = id;
149 });
150 if (res != HidlResult::SUCCESS) {
151 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
152 }
153
154 *_aidl_return = (int)avSyncHwId;
155 return ::ndk::ScopedAStatus::ok();
156}
157
158::ndk::ScopedAStatus TunerHidlDemux::getAvSyncTime(int32_t avSyncHwId, int64_t* _aidl_return) {
Hongguang093c5f32021-08-09 19:46:34 -0700159 uint64_t time;
160 HidlResult res;
161 mDemux->getAvSyncTime(static_cast<uint32_t>(avSyncHwId), [&](HidlResult r, uint64_t ts) {
162 res = r;
163 time = ts;
164 });
165 if (res != HidlResult::SUCCESS) {
166 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
167 }
168
169 *_aidl_return = (int64_t)time;
170 return ::ndk::ScopedAStatus::ok();
171}
172
173::ndk::ScopedAStatus TunerHidlDemux::openDvr(DvrType in_dvbType, int32_t in_bufferSize,
174 const shared_ptr<ITunerDvrCallback>& in_cb,
175 shared_ptr<ITunerDvr>* _aidl_return) {
Hongguang093c5f32021-08-09 19:46:34 -0700176 HidlResult res;
177 sp<HidlIDvrCallback> callback = new TunerHidlDvr::DvrCallback(in_cb);
178 sp<HidlIDvr> hidlDvr;
179 mDemux->openDvr(static_cast<HidlDvrType>(in_dvbType), in_bufferSize, callback,
180 [&](HidlResult r, const sp<HidlIDvr>& dvr) {
181 hidlDvr = dvr;
182 res = r;
183 });
184 if (res != HidlResult::SUCCESS) {
185 *_aidl_return = nullptr;
186 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
187 }
188
189 *_aidl_return = ::ndk::SharedRefBase::make<TunerHidlDvr>(hidlDvr, in_dvbType);
190 return ::ndk::ScopedAStatus::ok();
191}
192
193::ndk::ScopedAStatus TunerHidlDemux::connectCiCam(int32_t ciCamId) {
Hongguang093c5f32021-08-09 19:46:34 -0700194 HidlResult res = mDemux->connectCiCam(static_cast<uint32_t>(ciCamId));
195 if (res != HidlResult::SUCCESS) {
196 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
197 }
198 return ::ndk::ScopedAStatus::ok();
199}
200
201::ndk::ScopedAStatus TunerHidlDemux::disconnectCiCam() {
Hongguang093c5f32021-08-09 19:46:34 -0700202 HidlResult res = mDemux->disconnectCiCam();
203 if (res != HidlResult::SUCCESS) {
204 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
205 }
206 return ::ndk::ScopedAStatus::ok();
207}
208
209::ndk::ScopedAStatus TunerHidlDemux::close() {
Hongguang093c5f32021-08-09 19:46:34 -0700210 HidlResult res = mDemux->close();
Hongguang093c5f32021-08-09 19:46:34 -0700211 if (res != HidlResult::SUCCESS) {
212 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
213 }
214 return ::ndk::ScopedAStatus::ok();
215}
216
217} // namespace tuner
218} // namespace tv
219} // namespace media
220} // namespace android
221} // namespace aidl