blob: 34efe016131d9316ca6dc97464cafab00351cb41 [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
19#include "TunerDemux.h"
Hongguangeae68392021-07-27 20:56:23 -070020
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"
Amy Zhang07428dc2021-02-04 15:58:02 -080029#include "TunerTimeFilter.h"
shubangae56a2e2021-01-21 07:29:55 -080030
Hongguangeae68392021-07-27 20:56:23 -070031using ::aidl::android::hardware::tv::tuner::IDvr;
32using ::aidl::android::hardware::tv::tuner::IDvrCallback;
33using ::aidl::android::hardware::tv::tuner::IFilter;
34using ::aidl::android::hardware::tv::tuner::IFilterCallback;
35using ::aidl::android::hardware::tv::tuner::ITimeFilter;
36using ::aidl::android::hardware::tv::tuner::Result;
shubangae56a2e2021-01-21 07:29:55 -080037
Hongguangeae68392021-07-27 20:56:23 -070038namespace aidl {
shubangae56a2e2021-01-21 07:29:55 -080039namespace android {
Hongguangeae68392021-07-27 20:56:23 -070040namespace media {
41namespace tv {
42namespace tuner {
shubangae56a2e2021-01-21 07:29:55 -080043
Hongguangeae68392021-07-27 20:56:23 -070044TunerDemux::TunerDemux(shared_ptr<IDemux> demux, int id) {
shubangae56a2e2021-01-21 07:29:55 -080045 mDemux = demux;
46 mDemuxId = id;
47}
48
49TunerDemux::~TunerDemux() {
50 mDemux = nullptr;
51}
52
Hongguangeae68392021-07-27 20:56:23 -070053::ndk::ScopedAStatus TunerDemux::setFrontendDataSource(
54 const shared_ptr<ITunerFrontend>& in_frontend) {
shubangae56a2e2021-01-21 07:29:55 -080055 if (mDemux == nullptr) {
56 ALOGE("IDemux is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070057 return ::ndk::ScopedAStatus::fromServiceSpecificError(
58 static_cast<int32_t>(Result::UNAVAILABLE));
shubangae56a2e2021-01-21 07:29:55 -080059 }
60
61 int frontendId;
Hongguangeae68392021-07-27 20:56:23 -070062 in_frontend->getFrontendId(&frontendId);
63
64 return mDemux->setFrontendDataSource(frontendId);
shubangae56a2e2021-01-21 07:29:55 -080065}
66
Hongguangeae68392021-07-27 20:56:23 -070067::ndk::ScopedAStatus TunerDemux::setFrontendDataSourceById(int frontendId) {
Kensuke Miyagi83f407b2021-07-30 17:38:06 -070068 if (mDemux == nullptr) {
69 ALOGE("IDemux is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070070 return ::ndk::ScopedAStatus::fromServiceSpecificError(
71 static_cast<int32_t>(Result::UNAVAILABLE));
Kensuke Miyagi83f407b2021-07-30 17:38:06 -070072 }
73
Hongguangeae68392021-07-27 20:56:23 -070074 return mDemux->setFrontendDataSource(frontendId);
Kensuke Miyagi83f407b2021-07-30 17:38:06 -070075}
76
Hongguangeae68392021-07-27 20:56:23 -070077::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<IFilterCallback> cb = ::ndk::SharedRefBase::make<TunerFilter::FilterCallback>(in_cb);
88 auto status = mDemux->openFilter(in_type, in_bufferSize, cb, &filter);
89 if (status.isOk()) {
90 *_aidl_return = ::ndk::SharedRefBase::make<TunerFilter>(filter, in_type);
91 }
92
93 return status;
94}
95
96::ndk::ScopedAStatus TunerDemux::openTimeFilter(shared_ptr<ITunerTimeFilter>* _aidl_return) {
shubangae56a2e2021-01-21 07:29:55 -080097 if (mDemux == nullptr) {
98 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -070099 return ::ndk::ScopedAStatus::fromServiceSpecificError(
100 static_cast<int32_t>(Result::UNAVAILABLE));
shubangae56a2e2021-01-21 07:29:55 -0800101 }
102
Hongguangeae68392021-07-27 20:56:23 -0700103 shared_ptr<ITimeFilter> filter;
104 auto status = mDemux->openTimeFilter(&filter);
105 if (status.isOk()) {
106 *_aidl_return = ::ndk::SharedRefBase::make<TunerTimeFilter>(filter);
shubangae56a2e2021-01-21 07:29:55 -0800107 }
108
Hongguangeae68392021-07-27 20:56:23 -0700109 return status;
shubangae56a2e2021-01-21 07:29:55 -0800110}
111
Hongguangeae68392021-07-27 20:56:23 -0700112::ndk::ScopedAStatus TunerDemux::getAvSyncHwId(const shared_ptr<ITunerFilter>& tunerFilter,
113 int32_t* _aidl_return) {
Amy Zhang07428dc2021-02-04 15:58:02 -0800114 if (mDemux == nullptr) {
115 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700116 return ::ndk::ScopedAStatus::fromServiceSpecificError(
117 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800118 }
119
Hongguangeae68392021-07-27 20:56:23 -0700120 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(tunerFilter.get()))->getHalFilter();
121 return mDemux->getAvSyncHwId(halFilter, _aidl_return);
Amy Zhang07428dc2021-02-04 15:58:02 -0800122}
123
Hongguangeae68392021-07-27 20:56:23 -0700124::ndk::ScopedAStatus TunerDemux::getAvSyncTime(int32_t avSyncHwId, int64_t* _aidl_return) {
Amy Zhang07428dc2021-02-04 15:58:02 -0800125 if (mDemux == nullptr) {
126 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700127 return ::ndk::ScopedAStatus::fromServiceSpecificError(
128 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800129 }
130
Hongguangeae68392021-07-27 20:56:23 -0700131 return mDemux->getAvSyncTime(avSyncHwId, _aidl_return);
Amy Zhang07428dc2021-02-04 15:58:02 -0800132}
133
Hongguangeae68392021-07-27 20:56:23 -0700134::ndk::ScopedAStatus TunerDemux::openDvr(DvrType in_dvbType, int32_t in_bufferSize,
135 const shared_ptr<ITunerDvrCallback>& in_cb,
136 shared_ptr<ITunerDvr>* _aidl_return) {
Amy Zhang07428dc2021-02-04 15:58:02 -0800137 if (mDemux == nullptr) {
138 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700139 return ::ndk::ScopedAStatus::fromServiceSpecificError(
140 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800141 }
142
Hongguangeae68392021-07-27 20:56:23 -0700143 shared_ptr<IDvrCallback> callback = ::ndk::SharedRefBase::make<TunerDvr::DvrCallback>(in_cb);
144 shared_ptr<IDvr> halDvr;
145 auto res = mDemux->openDvr(in_dvbType, in_bufferSize, callback, &halDvr);
146 if (res.isOk()) {
147 *_aidl_return = ::ndk::SharedRefBase::make<TunerDvr>(halDvr, in_dvbType);
Amy Zhang07428dc2021-02-04 15:58:02 -0800148 }
149
Hongguangeae68392021-07-27 20:56:23 -0700150 return res;
Amy Zhang07428dc2021-02-04 15:58:02 -0800151}
152
Hongguangeae68392021-07-27 20:56:23 -0700153::ndk::ScopedAStatus TunerDemux::connectCiCam(int32_t ciCamId) {
Amy Zhangada92d72021-01-22 16:45:53 -0800154 if (mDemux == nullptr) {
155 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700156 return ::ndk::ScopedAStatus::fromServiceSpecificError(
157 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800158 }
159
Hongguangeae68392021-07-27 20:56:23 -0700160 return mDemux->connectCiCam(ciCamId);
Amy Zhangada92d72021-01-22 16:45:53 -0800161}
Amy Zhangeb292c12021-01-26 16:28:19 -0800162
Hongguangeae68392021-07-27 20:56:23 -0700163::ndk::ScopedAStatus TunerDemux::disconnectCiCam() {
Amy Zhang07428dc2021-02-04 15:58:02 -0800164 if (mDemux == nullptr) {
165 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700166 return ::ndk::ScopedAStatus::fromServiceSpecificError(
167 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800168 }
169
Hongguangeae68392021-07-27 20:56:23 -0700170 return mDemux->disconnectCiCam();
Amy Zhang07428dc2021-02-04 15:58:02 -0800171}
172
Hongguangeae68392021-07-27 20:56:23 -0700173::ndk::ScopedAStatus TunerDemux::close() {
Amy Zhang07428dc2021-02-04 15:58:02 -0800174 if (mDemux == nullptr) {
175 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700176 return ::ndk::ScopedAStatus::fromServiceSpecificError(
177 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800178 }
179
Hongguangeae68392021-07-27 20:56:23 -0700180 auto res = mDemux->close();
181 mDemux = nullptr;
182
183 return res;
Amy Zhang07428dc2021-02-04 15:58:02 -0800184}
185
Hongguangeae68392021-07-27 20:56:23 -0700186} // namespace tuner
187} // namespace tv
188} // namespace media
shubangae56a2e2021-01-21 07:29:55 -0800189} // namespace android
Hongguangeae68392021-07-27 20:56:23 -0700190} // namespace aidl