blob: 58f9a46bdbeb2a82fac698f85caf004d85b4f5ca [file] [log] [blame]
Amy Zhang6bfeaa02020-11-30 15:16:39 -08001/*
2 * Copyright 2020 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
Amy Zhang9a9ed602020-12-07 16:37:33 -080017#define LOG_TAG "DemuxClient"
Amy Zhang6bfeaa02020-11-30 15:16:39 -080018
19#include <android-base/logging.h>
20#include <utils/Log.h>
21
22#include "DemuxClient.h"
23
24using ::aidl::android::media::tv::tuner::TunerFrontendSettings;
25
26using ::android::hardware::tv::tuner::V1_0::Result;
27
28namespace android {
29
30/////////////// DemuxClient ///////////////////////
31
32// TODO: pending aidl interface
33DemuxClient::DemuxClient() {
34 //mTunerDemux = tunerDemux;
Amy Zhang921fd432021-01-07 13:18:27 -080035 mId = -1;
Amy Zhang6bfeaa02020-11-30 15:16:39 -080036}
37
38DemuxClient::~DemuxClient() {
39 //mTunerDemux = NULL;
40 mDemux = NULL;
Amy Zhang921fd432021-01-07 13:18:27 -080041 mId = -1;
Amy Zhang6bfeaa02020-11-30 15:16:39 -080042}
43
44// TODO: remove after migration to Tuner Service is done.
45void DemuxClient::setHidlDemux(sp<IDemux> demux) {
46 mDemux = demux;
47}
48
Amy Zhangb74185b2020-12-07 16:37:33 -080049Result DemuxClient::setFrontendDataSource(sp<FrontendClient> frontendClient) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -080050 // TODO: pending aidl interface
51 /*if (mTunerDemux != NULL) {
52 // TODO: handle error message
Amy Zhangb74185b2020-12-07 16:37:33 -080053 mTunerDemux->setFrontendDataSource(frontendClient->getAidlFrontend());
Amy Zhang6bfeaa02020-11-30 15:16:39 -080054 return (int) Result::SUCCESS;
55 }*/
56
57 if (mDemux != NULL) {
Amy Zhangb74185b2020-12-07 16:37:33 -080058 Result res = mDemux->setFrontendDataSource(frontendClient->getId());
Amy Zhang6bfeaa02020-11-30 15:16:39 -080059 return res;
60 }
61
62 return Result::INVALID_STATE;
63}
64
Amy Zhangb74185b2020-12-07 16:37:33 -080065sp<FilterClient> DemuxClient::openFilter(DemuxFilterType type, int bufferSize,
66 sp<FilterClientCallback> cb) {
67 // TODO: pending aidl interface
Amy Zhang6bfeaa02020-11-30 15:16:39 -080068
Amy Zhangb74185b2020-12-07 16:37:33 -080069 if (mDemux != NULL) {
70 sp<HidlFilterCallback> callback = new HidlFilterCallback(cb);
71 sp<IFilter> hidlFilter = openHidlFilter(type, bufferSize, callback);
72 if (hidlFilter != NULL) {
Amy Zhang9b5831b2020-12-09 21:13:58 -080073 sp<FilterClient> filterClient = new FilterClient(type);
Amy Zhangb74185b2020-12-07 16:37:33 -080074 filterClient->setHidlFilter(hidlFilter);
75 return filterClient;
76 }
77 }
78
Amy Zhangb74185b2020-12-07 16:37:33 -080079 return NULL;
80}
81
82int DemuxClient::getAvSyncHwId(sp<FilterClient> filterClient) {
83 // pending aidl interface
84
85 if (mDemux != NULL) {
86 uint32_t avSyncHwId;
87 Result res;
88 sp<IFilter> halFilter = filterClient->getHalFilter();
89 mDemux->getAvSyncHwId(halFilter,
90 [&](Result r, uint32_t id) {
91 res = r;
92 avSyncHwId = id;
93 });
94 if (res == Result::SUCCESS) {
95 return (int) avSyncHwId;
96 }
97 }
98
99 return -1;
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800100}
101
102long DemuxClient::getAvSyncTime(int avSyncHwId) {
103 // pending aidl interface
104
105 if (mDemux != NULL) {
106 uint64_t time;
107 Result res;
108 mDemux->getAvSyncTime(static_cast<uint32_t>(avSyncHwId),
109 [&](Result r, uint64_t ts) {
110 res = r;
111 time = ts;
112 });
113 if (res == Result::SUCCESS) {
114 return (long) time;
115 }
116 }
117
118 return -1;
119}
120
Amy Zhang9a9ed602020-12-07 16:37:33 -0800121sp<DvrClient> DemuxClient::openDvr(DvrType dvbType, int bufferSize, sp<DvrClientCallback> cb) {
122 // TODO: pending aidl interface
123
124 if (mDemux != NULL) {
125 sp<HidlDvrCallback> callback = new HidlDvrCallback(cb);
126 sp<IDvr> hidlDvr = openHidlDvr(dvbType, bufferSize, callback);
127 if (hidlDvr != NULL) {
128 sp<DvrClient> dvrClient = new DvrClient();
129 dvrClient->setHidlDvr(hidlDvr);
130 return dvrClient;
131 }
132 }
133
134 return NULL;
135}
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800136
137Result DemuxClient::connectCiCam(int ciCamId) {
138 // pending aidl interface
139
140 if (mDemux != NULL) {
141 return mDemux->connectCiCam(static_cast<uint32_t>(ciCamId));
142 }
143
144 return Result::INVALID_STATE;
145}
146
147Result DemuxClient::disconnectCiCam() {
148 // pending aidl interface
149
150 if (mDemux != NULL) {
151 return mDemux->disconnectCiCam();
152 }
153
154 return Result::INVALID_STATE;
155}
156
157Result DemuxClient::close() {
Amy Zhang9b5831b2020-12-09 21:13:58 -0800158 // TODO: pending aidl interface
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800159
160 if (mDemux != NULL) {
161 Result res = mDemux->close();
162 if (res == Result::SUCCESS) {
163 mDemux = NULL;
164 }
165 return res;
166 }
167
168 return Result::INVALID_STATE;
169}
Amy Zhangb74185b2020-12-07 16:37:33 -0800170
171/////////////// DemuxClient Helper Methods ///////////////////////
172
173sp<IFilter> DemuxClient::openHidlFilter(DemuxFilterType type, int bufferSize,
174 sp<HidlFilterCallback> callback) {
175 if (mDemux == NULL) {
176 return NULL;
177 }
178
179 sp<IFilter> hidlFilter;
180 Result res;
181 mDemux->openFilter(type, bufferSize, callback,
182 [&](Result r, const sp<IFilter>& filter) {
183 hidlFilter = filter;
184 res = r;
185 });
186 if (res != Result::SUCCESS || hidlFilter == NULL) {
187 return NULL;
188 }
189
190 return hidlFilter;
191}
Amy Zhang9a9ed602020-12-07 16:37:33 -0800192
193sp<IDvr> DemuxClient::openHidlDvr(DvrType dvrType, int bufferSize,
194 sp<HidlDvrCallback> callback) {
195 if (mDemux == NULL) {
196 return NULL;
197 }
198
199 sp<IDvr> hidlDvr;
200 Result res;
201 mDemux->openDvr(dvrType, bufferSize, callback,
202 [&](Result r, const sp<IDvr>& dvr) {
203 hidlDvr = dvr;
204 res = r;
205 });
206 if (res != Result::SUCCESS || hidlDvr == NULL) {
207 return NULL;
208 }
209
210 return hidlDvr;
211}
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800212} // namespace android