1 /**
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
19 #include "TunerDemux.h"
20
21 #include <aidl/android/hardware/tv/tuner/IDvr.h>
22 #include <aidl/android/hardware/tv/tuner/IDvrCallback.h>
23 #include <aidl/android/hardware/tv/tuner/IFilter.h>
24 #include <aidl/android/hardware/tv/tuner/IFilterCallback.h>
25 #include <aidl/android/hardware/tv/tuner/ITimeFilter.h>
26 #include <aidl/android/hardware/tv/tuner/Result.h>
27
28 #include "TunerDvr.h"
29 #include "TunerTimeFilter.h"
30
31 using ::aidl::android::hardware::tv::tuner::IDvr;
32 using ::aidl::android::hardware::tv::tuner::IDvrCallback;
33 using ::aidl::android::hardware::tv::tuner::IFilter;
34 using ::aidl::android::hardware::tv::tuner::IFilterCallback;
35 using ::aidl::android::hardware::tv::tuner::ITimeFilter;
36 using ::aidl::android::hardware::tv::tuner::Result;
37
38 namespace aidl {
39 namespace android {
40 namespace media {
41 namespace tv {
42 namespace tuner {
43
TunerDemux(shared_ptr<IDemux> demux,int id)44 TunerDemux::TunerDemux(shared_ptr<IDemux> demux, int id) {
45 mDemux = demux;
46 mDemuxId = id;
47 }
48
~TunerDemux()49 TunerDemux::~TunerDemux() {
50 mDemux = nullptr;
51 }
52
setFrontendDataSource(const shared_ptr<ITunerFrontend> & in_frontend)53 ::ndk::ScopedAStatus TunerDemux::setFrontendDataSource(
54 const shared_ptr<ITunerFrontend>& in_frontend) {
55 if (mDemux == nullptr) {
56 ALOGE("IDemux is not initialized");
57 return ::ndk::ScopedAStatus::fromServiceSpecificError(
58 static_cast<int32_t>(Result::UNAVAILABLE));
59 }
60
61 int frontendId;
62 in_frontend->getFrontendId(&frontendId);
63
64 return mDemux->setFrontendDataSource(frontendId);
65 }
66
setFrontendDataSourceById(int frontendId)67 ::ndk::ScopedAStatus TunerDemux::setFrontendDataSourceById(int frontendId) {
68 if (mDemux == nullptr) {
69 ALOGE("IDemux is not initialized");
70 return ::ndk::ScopedAStatus::fromServiceSpecificError(
71 static_cast<int32_t>(Result::UNAVAILABLE));
72 }
73
74 return mDemux->setFrontendDataSource(frontendId);
75 }
76
openFilter(const DemuxFilterType & in_type,int32_t in_bufferSize,const shared_ptr<ITunerFilterCallback> & in_cb,shared_ptr<ITunerFilter> * _aidl_return)77 ::ndk::ScopedAStatus TunerDemux::openFilter(const DemuxFilterType& in_type, int32_t in_bufferSize,
78 const shared_ptr<ITunerFilterCallback>& in_cb,
79 shared_ptr<ITunerFilter>* _aidl_return) {
80 if (mDemux == nullptr) {
81 ALOGE("IDemux is not initialized");
82 return ::ndk::ScopedAStatus::fromServiceSpecificError(
83 static_cast<int32_t>(Result::UNAVAILABLE));
84 }
85
86 shared_ptr<IFilter> filter;
87 shared_ptr<TunerFilter::FilterCallback> filterCb =
88 ::ndk::SharedRefBase::make<TunerFilter::FilterCallback>(in_cb);
89 shared_ptr<IFilterCallback> cb = filterCb;
90 auto status = mDemux->openFilter(in_type, in_bufferSize, cb, &filter);
91 if (status.isOk()) {
92 *_aidl_return = ::ndk::SharedRefBase::make<TunerFilter>(filter, filterCb, in_type);
93 }
94
95 return status;
96 }
97
openTimeFilter(shared_ptr<ITunerTimeFilter> * _aidl_return)98 ::ndk::ScopedAStatus TunerDemux::openTimeFilter(shared_ptr<ITunerTimeFilter>* _aidl_return) {
99 if (mDemux == nullptr) {
100 ALOGE("IDemux is not initialized.");
101 return ::ndk::ScopedAStatus::fromServiceSpecificError(
102 static_cast<int32_t>(Result::UNAVAILABLE));
103 }
104
105 shared_ptr<ITimeFilter> filter;
106 auto status = mDemux->openTimeFilter(&filter);
107 if (status.isOk()) {
108 *_aidl_return = ::ndk::SharedRefBase::make<TunerTimeFilter>(filter);
109 }
110
111 return status;
112 }
113
getAvSyncHwId(const shared_ptr<ITunerFilter> & tunerFilter,int32_t * _aidl_return)114 ::ndk::ScopedAStatus TunerDemux::getAvSyncHwId(const shared_ptr<ITunerFilter>& tunerFilter,
115 int32_t* _aidl_return) {
116 if (mDemux == nullptr) {
117 ALOGE("IDemux is not initialized.");
118 return ::ndk::ScopedAStatus::fromServiceSpecificError(
119 static_cast<int32_t>(Result::UNAVAILABLE));
120 }
121
122 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(tunerFilter.get()))->getHalFilter();
123 return mDemux->getAvSyncHwId(halFilter, _aidl_return);
124 }
125
getAvSyncTime(int32_t avSyncHwId,int64_t * _aidl_return)126 ::ndk::ScopedAStatus TunerDemux::getAvSyncTime(int32_t avSyncHwId, int64_t* _aidl_return) {
127 if (mDemux == nullptr) {
128 ALOGE("IDemux is not initialized.");
129 return ::ndk::ScopedAStatus::fromServiceSpecificError(
130 static_cast<int32_t>(Result::UNAVAILABLE));
131 }
132
133 return mDemux->getAvSyncTime(avSyncHwId, _aidl_return);
134 }
135
openDvr(DvrType in_dvbType,int32_t in_bufferSize,const shared_ptr<ITunerDvrCallback> & in_cb,shared_ptr<ITunerDvr> * _aidl_return)136 ::ndk::ScopedAStatus TunerDemux::openDvr(DvrType in_dvbType, int32_t in_bufferSize,
137 const shared_ptr<ITunerDvrCallback>& in_cb,
138 shared_ptr<ITunerDvr>* _aidl_return) {
139 if (mDemux == nullptr) {
140 ALOGE("IDemux is not initialized.");
141 return ::ndk::ScopedAStatus::fromServiceSpecificError(
142 static_cast<int32_t>(Result::UNAVAILABLE));
143 }
144
145 shared_ptr<IDvrCallback> callback = ::ndk::SharedRefBase::make<TunerDvr::DvrCallback>(in_cb);
146 shared_ptr<IDvr> halDvr;
147 auto res = mDemux->openDvr(in_dvbType, in_bufferSize, callback, &halDvr);
148 if (res.isOk()) {
149 *_aidl_return = ::ndk::SharedRefBase::make<TunerDvr>(halDvr, in_dvbType);
150 }
151
152 return res;
153 }
154
connectCiCam(int32_t ciCamId)155 ::ndk::ScopedAStatus TunerDemux::connectCiCam(int32_t ciCamId) {
156 if (mDemux == nullptr) {
157 ALOGE("IDemux is not initialized.");
158 return ::ndk::ScopedAStatus::fromServiceSpecificError(
159 static_cast<int32_t>(Result::UNAVAILABLE));
160 }
161
162 return mDemux->connectCiCam(ciCamId);
163 }
164
disconnectCiCam()165 ::ndk::ScopedAStatus TunerDemux::disconnectCiCam() {
166 if (mDemux == nullptr) {
167 ALOGE("IDemux is not initialized.");
168 return ::ndk::ScopedAStatus::fromServiceSpecificError(
169 static_cast<int32_t>(Result::UNAVAILABLE));
170 }
171
172 return mDemux->disconnectCiCam();
173 }
174
close()175 ::ndk::ScopedAStatus TunerDemux::close() {
176 if (mDemux == nullptr) {
177 ALOGE("IDemux is not initialized.");
178 return ::ndk::ScopedAStatus::fromServiceSpecificError(
179 static_cast<int32_t>(Result::UNAVAILABLE));
180 }
181
182 auto res = mDemux->close();
183 mDemux = nullptr;
184
185 return res;
186 }
187
188 } // namespace tuner
189 } // namespace tv
190 } // namespace media
191 } // namespace android
192 } // namespace aidl
193