blob: 0e0cd3b64ad6f9d67cda390c8ef2083f1409101a [file] [log] [blame]
shubangae56a2e2021-01-21 07:29:55 -08001/**
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 "TunerDemux"
18
Amy Zhangada92d72021-01-22 16:45:53 -080019#include "TunerDvr.h"
shubangae56a2e2021-01-21 07:29:55 -080020#include "TunerDemux.h"
shubangae56a2e2021-01-21 07:29:55 -080021
22using ::android::hardware::tv::tuner::V1_0::DemuxAlpFilterType;
23using ::android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
24using ::android::hardware::tv::tuner::V1_0::DemuxFilterType;
25using ::android::hardware::tv::tuner::V1_0::DemuxIpFilterType;
26using ::android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType;
27using ::android::hardware::tv::tuner::V1_0::DemuxTlvFilterType;
28using ::android::hardware::tv::tuner::V1_0::DemuxTsFilterType;
Amy Zhangada92d72021-01-22 16:45:53 -080029using ::android::hardware::tv::tuner::V1_0::DvrType;
shubangae56a2e2021-01-21 07:29:55 -080030using ::android::hardware::tv::tuner::V1_0::Result;
31
32namespace android {
33
34TunerDemux::TunerDemux(sp<IDemux> demux, int id) {
35 mDemux = demux;
36 mDemuxId = id;
37}
38
39TunerDemux::~TunerDemux() {
40 mDemux = nullptr;
41}
42
43Status TunerDemux::setFrontendDataSource(const std::shared_ptr<ITunerFrontend>& frontend) {
44 if (mDemux == nullptr) {
45 ALOGE("IDemux is not initialized");
46 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
47 }
48
49 int frontendId;
50 frontend->getFrontendId(&frontendId);
51 Result res = mDemux->setFrontendDataSource(frontendId);
52 if (res != Result::SUCCESS) {
53 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
54 }
55 return Status::ok();
56}
57
58Status TunerDemux::openFilter(
59 int type, int subType, int bufferSize, const std::shared_ptr<ITunerFilterCallback>& cb,
60 std::shared_ptr<ITunerFilter>* _aidl_return) {
61 if (mDemux == nullptr) {
62 ALOGE("IDemux is not initialized.");
63 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
64 }
65
66 DemuxFilterMainType mainType = static_cast<DemuxFilterMainType>(type);
67 DemuxFilterType filterType {
68 .mainType = mainType,
69 };
70
71 switch(mainType) {
72 case DemuxFilterMainType::TS:
73 filterType.subType.tsFilterType(static_cast<DemuxTsFilterType>(subType));
74 break;
75 case DemuxFilterMainType::MMTP:
76 filterType.subType.mmtpFilterType(static_cast<DemuxMmtpFilterType>(subType));
77 break;
78 case DemuxFilterMainType::IP:
79 filterType.subType.ipFilterType(static_cast<DemuxIpFilterType>(subType));
80 break;
81 case DemuxFilterMainType::TLV:
82 filterType.subType.tlvFilterType(static_cast<DemuxTlvFilterType>(subType));
83 break;
84 case DemuxFilterMainType::ALP:
85 filterType.subType.alpFilterType(static_cast<DemuxAlpFilterType>(subType));
86 break;
87 }
88 Result status;
89 sp<IFilter> filterSp;
90 sp<IFilterCallback> cbSp = new TunerFilter::FilterCallback(cb);
91 mDemux->openFilter(filterType, bufferSize, cbSp,
92 [&](Result r, const sp<IFilter>& filter) {
93 filterSp = filter;
94 status = r;
95 });
96 if (status != Result::SUCCESS) {
97 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
98 }
99
100 *_aidl_return = ::ndk::SharedRefBase::make<TunerFilter>(filterSp, cbSp);
101 return Status::ok();
102}
103
Amy Zhangada92d72021-01-22 16:45:53 -0800104Status TunerDemux::openDvr(int dvrType, int bufferSize, const shared_ptr<ITunerDvrCallback>& cb,
105 shared_ptr<ITunerDvr>* _aidl_return) {
106 if (mDemux == nullptr) {
107 ALOGE("IDemux is not initialized.");
108 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
109 }
110
111 Result res;
112 sp<IDvrCallback> callback = new TunerDvr::DvrCallback(cb);
113 sp<IDvr> hidlDvr;
114 mDemux->openDvr(static_cast<DvrType>(dvrType), bufferSize, callback,
115 [&](Result r, const sp<IDvr>& dvr) {
116 hidlDvr = dvr;
117 res = r;
118 });
119 if (res != Result::SUCCESS) {
120 *_aidl_return = NULL;
121 return Status::fromServiceSpecificError(static_cast<int32_t>(res));
122 }
123
124 *_aidl_return = ::ndk::SharedRefBase::make<TunerDvr>(hidlDvr, dvrType);
125 return Status::ok();
126}
shubangae56a2e2021-01-21 07:29:55 -0800127} // namespace android