blob: 4ee3f48030567429fd6683b33ac471c561d0f985 [file] [log] [blame]
Amy Zhang6bfeaa02020-11-30 15:16:39 -08001/*
Hongguang56637e92021-07-28 17:32:55 -07002 * Copyright 2021 The Android Open Source Project
Amy Zhang6bfeaa02020-11-30 15:16:39 -08003 *
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
Amy Zhang9a9ed602020-12-07 16:37:33 -080017#define LOG_TAG "DemuxClient"
Amy Zhang6bfeaa02020-11-30 15:16:39 -080018
Hongguang56637e92021-07-28 17:32:55 -070019#include "DemuxClient.h"
20
21#include <aidl/android/hardware/tv/tuner/Constant.h>
22#include <aidl/android/hardware/tv/tuner/Constant64Bit.h>
Amy Zhang6bfeaa02020-11-30 15:16:39 -080023#include <android-base/logging.h>
24#include <utils/Log.h>
25
Hongguang56637e92021-07-28 17:32:55 -070026using ::aidl::android::hardware::tv::tuner::Constant;
27using ::aidl::android::hardware::tv::tuner::Constant64Bit;
Amy Zhang6bfeaa02020-11-30 15:16:39 -080028
29namespace android {
Amy Zhang6bfeaa02020-11-30 15:16:39 -080030/////////////// DemuxClient ///////////////////////
Amy Zhang4a07e802021-01-21 17:10:21 -080031DemuxClient::DemuxClient(shared_ptr<ITunerDemux> tunerDemux) {
32 mTunerDemux = tunerDemux;
Amy Zhang6bfeaa02020-11-30 15:16:39 -080033}
34
35DemuxClient::~DemuxClient() {
Hongguang56637e92021-07-28 17:32:55 -070036 mTunerDemux = nullptr;
Amy Zhang6bfeaa02020-11-30 15:16:39 -080037}
38
Amy Zhangb74185b2020-12-07 16:37:33 -080039Result DemuxClient::setFrontendDataSource(sp<FrontendClient> frontendClient) {
Hongguang56637e92021-07-28 17:32:55 -070040 if (frontendClient == nullptr) {
41 return Result::INVALID_ARGUMENT;
Amy Zhang4a07e802021-01-21 17:10:21 -080042 }
Amy Zhang6bfeaa02020-11-30 15:16:39 -080043
Hongguang56637e92021-07-28 17:32:55 -070044 if (mTunerDemux != nullptr) {
45 Status s = mTunerDemux->setFrontendDataSource(frontendClient->getAidlFrontend());
46 return ClientHelper::getServiceSpecificErrorCode(s);
Amy Zhang6bfeaa02020-11-30 15:16:39 -080047 }
48
49 return Result::INVALID_STATE;
50}
51
Kensuke Miyagi7a45c0a2021-07-30 17:40:52 -070052Result DemuxClient::setFrontendDataSourceById(int frontendId) {
Hongguang56637e92021-07-28 17:32:55 -070053 if (mTunerDemux != nullptr) {
Kensuke Miyagi7a45c0a2021-07-30 17:40:52 -070054 Status s = mTunerDemux->setFrontendDataSourceById(frontendId);
55 return ClientHelper::getServiceSpecificErrorCode(s);
56 }
57
58 return Result::INVALID_STATE;
59}
60
Hongguang56637e92021-07-28 17:32:55 -070061sp<FilterClient> DemuxClient::openFilter(const DemuxFilterType& type, int32_t bufferSize,
62 sp<FilterClientCallback> cb) {
63 if (cb == nullptr) {
64 return nullptr;
65 }
66
67 if (mTunerDemux != nullptr) {
Amy Zhang4a07e802021-01-21 17:10:21 -080068 shared_ptr<ITunerFilter> tunerFilter;
69 shared_ptr<TunerFilterCallback> callback =
70 ::ndk::SharedRefBase::make<TunerFilterCallback>(cb);
Hongguang56637e92021-07-28 17:32:55 -070071 Status s = mTunerDemux->openFilter(type, bufferSize, callback, &tunerFilter);
72 if (!s.isOk()) {
73 return nullptr;
Amy Zhang4a07e802021-01-21 17:10:21 -080074 }
75 return new FilterClient(type, tunerFilter);
76 }
Amy Zhang6bfeaa02020-11-30 15:16:39 -080077
Hongguang56637e92021-07-28 17:32:55 -070078 return nullptr;
Amy Zhangb74185b2020-12-07 16:37:33 -080079}
80
Amy Zhang90a50b42021-01-11 16:58:59 -080081sp<TimeFilterClient> DemuxClient::openTimeFilter() {
Hongguang56637e92021-07-28 17:32:55 -070082 if (mTunerDemux != nullptr) {
Amy Zhang952794662021-02-04 15:56:22 -080083 shared_ptr<ITunerTimeFilter> tunerTimeFilter;
84 Status s = mTunerDemux->openTimeFilter(&tunerTimeFilter);
Hongguang56637e92021-07-28 17:32:55 -070085 if (!s.isOk()) {
86 return nullptr;
Amy Zhang952794662021-02-04 15:56:22 -080087 }
88 return new TimeFilterClient(tunerTimeFilter);
89 }
Amy Zhang90a50b42021-01-11 16:58:59 -080090
Hongguang56637e92021-07-28 17:32:55 -070091 return nullptr;
Amy Zhang90a50b42021-01-11 16:58:59 -080092}
93
Hongguang56637e92021-07-28 17:32:55 -070094int32_t DemuxClient::getAvSyncHwId(sp<FilterClient> filterClient) {
95 if (filterClient == nullptr) {
96 return static_cast<int32_t>(Constant::INVALID_AV_SYNC_ID);
97 }
98
99 if (mTunerDemux != nullptr) {
100 int32_t hwId;
Amy Zhang952794662021-02-04 15:56:22 -0800101 Status s = mTunerDemux->getAvSyncHwId(filterClient->getAidlFilter(), &hwId);
Hongguang56637e92021-07-28 17:32:55 -0700102 if (!s.isOk()) {
103 return static_cast<int32_t>(Constant::INVALID_AV_SYNC_ID);
Amy Zhang952794662021-02-04 15:56:22 -0800104 }
105 return hwId;
106 }
Amy Zhangb74185b2020-12-07 16:37:33 -0800107
Hongguang56637e92021-07-28 17:32:55 -0700108 return static_cast<int32_t>(Constant::INVALID_AV_SYNC_ID);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800109}
110
Hongguang56637e92021-07-28 17:32:55 -0700111int64_t DemuxClient::getAvSyncTime(int32_t avSyncHwId) {
112 if (mTunerDemux != nullptr) {
Amy Zhang952794662021-02-04 15:56:22 -0800113 int64_t time;
114 Status s = mTunerDemux->getAvSyncTime(avSyncHwId, &time);
Hongguang56637e92021-07-28 17:32:55 -0700115 if (!s.isOk()) {
116 return static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP);
Amy Zhang952794662021-02-04 15:56:22 -0800117 }
118 return time;
119 }
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800120
Hongguang56637e92021-07-28 17:32:55 -0700121 return static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800122}
123
Hongguang56637e92021-07-28 17:32:55 -0700124sp<DvrClient> DemuxClient::openDvr(DvrType dvbType, int32_t bufferSize, sp<DvrClientCallback> cb) {
125 if (cb == nullptr) {
126 return nullptr;
127 }
128
129 if (mTunerDemux != nullptr) {
Amy Zhangb5809be2021-01-26 16:27:23 -0800130 shared_ptr<ITunerDvr> tunerDvr;
131 shared_ptr<TunerDvrCallback> callback =
132 ::ndk::SharedRefBase::make<TunerDvrCallback>(cb);
Hongguang56637e92021-07-28 17:32:55 -0700133 Status s = mTunerDemux->openDvr(dvbType, bufferSize, callback, &tunerDvr);
134 if (!s.isOk()) {
135 return nullptr;
Amy Zhangb5809be2021-01-26 16:27:23 -0800136 }
137 return new DvrClient(tunerDvr);
138 }
Amy Zhang9a9ed602020-12-07 16:37:33 -0800139
Hongguang56637e92021-07-28 17:32:55 -0700140 return nullptr;
Amy Zhang9a9ed602020-12-07 16:37:33 -0800141}
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800142
Hongguang56637e92021-07-28 17:32:55 -0700143Result DemuxClient::connectCiCam(int32_t ciCamId) {
144 if (mTunerDemux != nullptr) {
Amy Zhang952794662021-02-04 15:56:22 -0800145 Status s = mTunerDemux->connectCiCam(ciCamId);
146 return ClientHelper::getServiceSpecificErrorCode(s);
147 }
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800148
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800149 return Result::INVALID_STATE;
150}
151
152Result DemuxClient::disconnectCiCam() {
Hongguang56637e92021-07-28 17:32:55 -0700153 if (mTunerDemux != nullptr) {
Amy Zhang952794662021-02-04 15:56:22 -0800154 Status s = mTunerDemux->disconnectCiCam();
155 return ClientHelper::getServiceSpecificErrorCode(s);
156 }
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800157
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800158 return Result::INVALID_STATE;
159}
160
161Result DemuxClient::close() {
Hongguang56637e92021-07-28 17:32:55 -0700162 if (mTunerDemux != nullptr) {
Amy Zhangb5809be2021-01-26 16:27:23 -0800163 Status s = mTunerDemux->close();
Hongguang56637e92021-07-28 17:32:55 -0700164 mTunerDemux = nullptr;
Amy Zhangb5809be2021-01-26 16:27:23 -0800165 return ClientHelper::getServiceSpecificErrorCode(s);
166 }
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800167
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800168 return Result::INVALID_STATE;
169}
Amy Zhangb74185b2020-12-07 16:37:33 -0800170
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800171} // namespace android