blob: a6f3a2c38b993cbe291590987a6c98a0f1ea9719 [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;
Hongguang34a479e2021-10-04 16:14:47 -070087 shared_ptr<TunerFilter::FilterCallback> filterCb =
88 ::ndk::SharedRefBase::make<TunerFilter::FilterCallback>(in_cb);
89 shared_ptr<IFilterCallback> cb = filterCb;
Hongguangeae68392021-07-27 20:56:23 -070090 auto status = mDemux->openFilter(in_type, in_bufferSize, cb, &filter);
91 if (status.isOk()) {
Hongguang34a479e2021-10-04 16:14:47 -070092 *_aidl_return = ::ndk::SharedRefBase::make<TunerFilter>(filter, filterCb, in_type);
Hongguangeae68392021-07-27 20:56:23 -070093 }
94
95 return status;
96}
97
98::ndk::ScopedAStatus TunerDemux::openTimeFilter(shared_ptr<ITunerTimeFilter>* _aidl_return) {
shubangae56a2e2021-01-21 07:29:55 -080099 if (mDemux == nullptr) {
100 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700101 return ::ndk::ScopedAStatus::fromServiceSpecificError(
102 static_cast<int32_t>(Result::UNAVAILABLE));
shubangae56a2e2021-01-21 07:29:55 -0800103 }
104
Hongguangeae68392021-07-27 20:56:23 -0700105 shared_ptr<ITimeFilter> filter;
106 auto status = mDemux->openTimeFilter(&filter);
107 if (status.isOk()) {
108 *_aidl_return = ::ndk::SharedRefBase::make<TunerTimeFilter>(filter);
shubangae56a2e2021-01-21 07:29:55 -0800109 }
110
Hongguangeae68392021-07-27 20:56:23 -0700111 return status;
shubangae56a2e2021-01-21 07:29:55 -0800112}
113
Hongguangeae68392021-07-27 20:56:23 -0700114::ndk::ScopedAStatus TunerDemux::getAvSyncHwId(const shared_ptr<ITunerFilter>& tunerFilter,
115 int32_t* _aidl_return) {
Amy Zhang07428dc2021-02-04 15:58:02 -0800116 if (mDemux == nullptr) {
117 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700118 return ::ndk::ScopedAStatus::fromServiceSpecificError(
119 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800120 }
121
Hongguangeae68392021-07-27 20:56:23 -0700122 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(tunerFilter.get()))->getHalFilter();
123 return mDemux->getAvSyncHwId(halFilter, _aidl_return);
Amy Zhang07428dc2021-02-04 15:58:02 -0800124}
125
Hongguangeae68392021-07-27 20:56:23 -0700126::ndk::ScopedAStatus TunerDemux::getAvSyncTime(int32_t avSyncHwId, int64_t* _aidl_return) {
Amy Zhang07428dc2021-02-04 15:58:02 -0800127 if (mDemux == nullptr) {
128 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700129 return ::ndk::ScopedAStatus::fromServiceSpecificError(
130 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800131 }
132
Hongguangeae68392021-07-27 20:56:23 -0700133 return mDemux->getAvSyncTime(avSyncHwId, _aidl_return);
Amy Zhang07428dc2021-02-04 15:58:02 -0800134}
135
Hongguangeae68392021-07-27 20:56:23 -0700136::ndk::ScopedAStatus TunerDemux::openDvr(DvrType in_dvbType, int32_t in_bufferSize,
137 const shared_ptr<ITunerDvrCallback>& in_cb,
138 shared_ptr<ITunerDvr>* _aidl_return) {
Amy Zhang07428dc2021-02-04 15:58:02 -0800139 if (mDemux == nullptr) {
140 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700141 return ::ndk::ScopedAStatus::fromServiceSpecificError(
142 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800143 }
144
Hongguangeae68392021-07-27 20:56:23 -0700145 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);
Amy Zhang07428dc2021-02-04 15:58:02 -0800150 }
151
Hongguangeae68392021-07-27 20:56:23 -0700152 return res;
Amy Zhang07428dc2021-02-04 15:58:02 -0800153}
154
Hongguangeae68392021-07-27 20:56:23 -0700155::ndk::ScopedAStatus TunerDemux::connectCiCam(int32_t ciCamId) {
Amy Zhangada92d72021-01-22 16:45:53 -0800156 if (mDemux == nullptr) {
157 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700158 return ::ndk::ScopedAStatus::fromServiceSpecificError(
159 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800160 }
161
Hongguangeae68392021-07-27 20:56:23 -0700162 return mDemux->connectCiCam(ciCamId);
Amy Zhangada92d72021-01-22 16:45:53 -0800163}
Amy Zhangeb292c12021-01-26 16:28:19 -0800164
Hongguangeae68392021-07-27 20:56:23 -0700165::ndk::ScopedAStatus TunerDemux::disconnectCiCam() {
Amy Zhang07428dc2021-02-04 15:58:02 -0800166 if (mDemux == nullptr) {
167 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700168 return ::ndk::ScopedAStatus::fromServiceSpecificError(
169 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800170 }
171
Hongguangeae68392021-07-27 20:56:23 -0700172 return mDemux->disconnectCiCam();
Amy Zhang07428dc2021-02-04 15:58:02 -0800173}
174
Hongguangeae68392021-07-27 20:56:23 -0700175::ndk::ScopedAStatus TunerDemux::close() {
Amy Zhang07428dc2021-02-04 15:58:02 -0800176 if (mDemux == nullptr) {
177 ALOGE("IDemux is not initialized.");
Hongguangeae68392021-07-27 20:56:23 -0700178 return ::ndk::ScopedAStatus::fromServiceSpecificError(
179 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang07428dc2021-02-04 15:58:02 -0800180 }
181
Hongguangeae68392021-07-27 20:56:23 -0700182 auto res = mDemux->close();
183 mDemux = nullptr;
184
185 return res;
Amy Zhang07428dc2021-02-04 15:58:02 -0800186}
187
Hongguangeae68392021-07-27 20:56:23 -0700188} // namespace tuner
189} // namespace tv
190} // namespace media
shubangae56a2e2021-01-21 07:29:55 -0800191} // namespace android
Hongguangeae68392021-07-27 20:56:23 -0700192} // namespace aidl