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