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 "TunerService.h"
30 #include "TunerTimeFilter.h"
31
32 using ::aidl::android::hardware::tv::tuner::IDvr;
33 using ::aidl::android::hardware::tv::tuner::IDvrCallback;
34 using ::aidl::android::hardware::tv::tuner::IFilter;
35 using ::aidl::android::hardware::tv::tuner::IFilterCallback;
36 using ::aidl::android::hardware::tv::tuner::ITimeFilter;
37 using ::aidl::android::hardware::tv::tuner::Result;
38
39 namespace aidl {
40 namespace android {
41 namespace media {
42 namespace tv {
43 namespace tuner {
44
TunerDemux(const shared_ptr<IDemux> demux,const int id,const shared_ptr<TunerService> tuner)45 TunerDemux::TunerDemux(const shared_ptr<IDemux> demux, const int id,
46 const shared_ptr<TunerService> tuner) {
47 mDemux = demux;
48 mDemuxId = id;
49 mTunerService = tuner;
50 }
51
~TunerDemux()52 TunerDemux::~TunerDemux() {
53 if (!isClosed) {
54 close();
55 }
56 mDemux = nullptr;
57 mTunerService = nullptr;
58 }
59
setFrontendDataSource(const shared_ptr<ITunerFrontend> & in_frontend)60 ::ndk::ScopedAStatus TunerDemux::setFrontendDataSource(
61 const shared_ptr<ITunerFrontend>& in_frontend) {
62 int frontendId;
63 in_frontend->getFrontendId(&frontendId);
64
65 return mDemux->setFrontendDataSource(frontendId);
66 }
67
setFrontendDataSourceById(int frontendId)68 ::ndk::ScopedAStatus TunerDemux::setFrontendDataSourceById(int frontendId) {
69 return mDemux->setFrontendDataSource(frontendId);
70 }
71
openFilter(const DemuxFilterType & in_type,int32_t in_bufferSize,const shared_ptr<ITunerFilterCallback> & in_cb,shared_ptr<ITunerFilter> * _aidl_return)72 ::ndk::ScopedAStatus TunerDemux::openFilter(const DemuxFilterType& in_type, int32_t in_bufferSize,
73 const shared_ptr<ITunerFilterCallback>& in_cb,
74 shared_ptr<ITunerFilter>* _aidl_return) {
75 shared_ptr<IFilter> filter;
76 shared_ptr<TunerFilter::FilterCallback> filterCb =
77 ::ndk::SharedRefBase::make<TunerFilter::FilterCallback>(in_cb);
78 shared_ptr<IFilterCallback> cb = filterCb;
79 auto status = mDemux->openFilter(in_type, in_bufferSize, cb, &filter);
80 if (status.isOk()) {
81 *_aidl_return =
82 ::ndk::SharedRefBase::make<TunerFilter>(filter, filterCb, in_type, mTunerService);
83 }
84
85 return status;
86 }
87
openTimeFilter(shared_ptr<ITunerTimeFilter> * _aidl_return)88 ::ndk::ScopedAStatus TunerDemux::openTimeFilter(shared_ptr<ITunerTimeFilter>* _aidl_return) {
89 shared_ptr<ITimeFilter> filter;
90 auto status = mDemux->openTimeFilter(&filter);
91 if (status.isOk()) {
92 *_aidl_return = ::ndk::SharedRefBase::make<TunerTimeFilter>(filter);
93 }
94
95 return status;
96 }
97
getAvSyncHwId(const shared_ptr<ITunerFilter> & tunerFilter,int32_t * _aidl_return)98 ::ndk::ScopedAStatus TunerDemux::getAvSyncHwId(const shared_ptr<ITunerFilter>& tunerFilter,
99 int32_t* _aidl_return) {
100 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(tunerFilter.get()))->getHalFilter();
101 return mDemux->getAvSyncHwId(halFilter, _aidl_return);
102 }
103
getAvSyncTime(int32_t avSyncHwId,int64_t * _aidl_return)104 ::ndk::ScopedAStatus TunerDemux::getAvSyncTime(int32_t avSyncHwId, int64_t* _aidl_return) {
105 return mDemux->getAvSyncTime(avSyncHwId, _aidl_return);
106 }
107
openDvr(DvrType in_dvbType,int32_t in_bufferSize,const shared_ptr<ITunerDvrCallback> & in_cb,shared_ptr<ITunerDvr> * _aidl_return)108 ::ndk::ScopedAStatus TunerDemux::openDvr(DvrType in_dvbType, int32_t in_bufferSize,
109 const shared_ptr<ITunerDvrCallback>& in_cb,
110 shared_ptr<ITunerDvr>* _aidl_return) {
111 shared_ptr<IDvrCallback> callback = ::ndk::SharedRefBase::make<TunerDvr::DvrCallback>(in_cb);
112 shared_ptr<IDvr> halDvr;
113 auto res = mDemux->openDvr(in_dvbType, in_bufferSize, callback, &halDvr);
114 if (res.isOk()) {
115 *_aidl_return = ::ndk::SharedRefBase::make<TunerDvr>(halDvr, in_dvbType);
116 }
117
118 return res;
119 }
120
connectCiCam(int32_t ciCamId)121 ::ndk::ScopedAStatus TunerDemux::connectCiCam(int32_t ciCamId) {
122 return mDemux->connectCiCam(ciCamId);
123 }
124
disconnectCiCam()125 ::ndk::ScopedAStatus TunerDemux::disconnectCiCam() {
126 return mDemux->disconnectCiCam();
127 }
128
close()129 ::ndk::ScopedAStatus TunerDemux::close() {
130 isClosed = true;
131 return mDemux->close();
132 }
133
134 } // namespace tuner
135 } // namespace tv
136 } // namespace media
137 } // namespace android
138 } // namespace aidl
139