blob: 59dfd704179ed2320ef0a20b94c2f8ffc8753134 [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;
35}
36
37DemuxClient::~DemuxClient() {
38 //mTunerDemux = NULL;
39 mDemux = NULL;
40}
41
42// TODO: remove after migration to Tuner Service is done.
43void DemuxClient::setHidlDemux(sp<IDemux> demux) {
44 mDemux = demux;
45}
46
Amy Zhangb74185b2020-12-07 16:37:33 -080047Result DemuxClient::setFrontendDataSource(sp<FrontendClient> frontendClient) {
Amy Zhang6bfeaa02020-11-30 15:16:39 -080048 // TODO: pending aidl interface
49 /*if (mTunerDemux != NULL) {
50 // TODO: handle error message
Amy Zhangb74185b2020-12-07 16:37:33 -080051 mTunerDemux->setFrontendDataSource(frontendClient->getAidlFrontend());
Amy Zhang6bfeaa02020-11-30 15:16:39 -080052 return (int) Result::SUCCESS;
53 }*/
54
55 if (mDemux != NULL) {
Amy Zhangb74185b2020-12-07 16:37:33 -080056 Result res = mDemux->setFrontendDataSource(frontendClient->getId());
Amy Zhang6bfeaa02020-11-30 15:16:39 -080057 return res;
58 }
59
60 return Result::INVALID_STATE;
61}
62
Amy Zhangb74185b2020-12-07 16:37:33 -080063sp<FilterClient> DemuxClient::openFilter(DemuxFilterType type, int bufferSize,
64 sp<FilterClientCallback> cb) {
65 // TODO: pending aidl interface
Amy Zhang6bfeaa02020-11-30 15:16:39 -080066
Amy Zhangb74185b2020-12-07 16:37:33 -080067 if (mDemux != NULL) {
68 sp<HidlFilterCallback> callback = new HidlFilterCallback(cb);
69 sp<IFilter> hidlFilter = openHidlFilter(type, bufferSize, callback);
70 if (hidlFilter != NULL) {
Amy Zhang9b5831b2020-12-09 21:13:58 -080071 sp<FilterClient> filterClient = new FilterClient(type);
Amy Zhangb74185b2020-12-07 16:37:33 -080072 filterClient->setHidlFilter(hidlFilter);
73 return filterClient;
74 }
75 }
76
Amy Zhangb74185b2020-12-07 16:37:33 -080077 return NULL;
78}
79
80int DemuxClient::getAvSyncHwId(sp<FilterClient> filterClient) {
81 // pending aidl interface
82
83 if (mDemux != NULL) {
84 uint32_t avSyncHwId;
85 Result res;
86 sp<IFilter> halFilter = filterClient->getHalFilter();
87 mDemux->getAvSyncHwId(halFilter,
88 [&](Result r, uint32_t id) {
89 res = r;
90 avSyncHwId = id;
91 });
92 if (res == Result::SUCCESS) {
93 return (int) avSyncHwId;
94 }
95 }
96
97 return -1;
Amy Zhang6bfeaa02020-11-30 15:16:39 -080098}
99
100long DemuxClient::getAvSyncTime(int avSyncHwId) {
101 // pending aidl interface
102
103 if (mDemux != NULL) {
104 uint64_t time;
105 Result res;
106 mDemux->getAvSyncTime(static_cast<uint32_t>(avSyncHwId),
107 [&](Result r, uint64_t ts) {
108 res = r;
109 time = ts;
110 });
111 if (res == Result::SUCCESS) {
112 return (long) time;
113 }
114 }
115
116 return -1;
117}
118
Amy Zhang9a9ed602020-12-07 16:37:33 -0800119sp<DvrClient> DemuxClient::openDvr(DvrType dvbType, int bufferSize, sp<DvrClientCallback> cb) {
120 // TODO: pending aidl interface
121
122 if (mDemux != NULL) {
123 sp<HidlDvrCallback> callback = new HidlDvrCallback(cb);
124 sp<IDvr> hidlDvr = openHidlDvr(dvbType, bufferSize, callback);
125 if (hidlDvr != NULL) {
126 sp<DvrClient> dvrClient = new DvrClient();
127 dvrClient->setHidlDvr(hidlDvr);
128 return dvrClient;
129 }
130 }
131
132 return NULL;
133}
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800134
135Result DemuxClient::connectCiCam(int ciCamId) {
136 // pending aidl interface
137
138 if (mDemux != NULL) {
139 return mDemux->connectCiCam(static_cast<uint32_t>(ciCamId));
140 }
141
142 return Result::INVALID_STATE;
143}
144
145Result DemuxClient::disconnectCiCam() {
146 // pending aidl interface
147
148 if (mDemux != NULL) {
149 return mDemux->disconnectCiCam();
150 }
151
152 return Result::INVALID_STATE;
153}
154
155Result DemuxClient::close() {
Amy Zhang9b5831b2020-12-09 21:13:58 -0800156 // TODO: pending aidl interface
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800157
158 if (mDemux != NULL) {
159 Result res = mDemux->close();
160 if (res == Result::SUCCESS) {
161 mDemux = NULL;
162 }
163 return res;
164 }
165
166 return Result::INVALID_STATE;
167}
Amy Zhangb74185b2020-12-07 16:37:33 -0800168
169/////////////// DemuxClient Helper Methods ///////////////////////
170
171sp<IFilter> DemuxClient::openHidlFilter(DemuxFilterType type, int bufferSize,
172 sp<HidlFilterCallback> callback) {
173 if (mDemux == NULL) {
174 return NULL;
175 }
176
177 sp<IFilter> hidlFilter;
178 Result res;
179 mDemux->openFilter(type, bufferSize, callback,
180 [&](Result r, const sp<IFilter>& filter) {
181 hidlFilter = filter;
182 res = r;
183 });
184 if (res != Result::SUCCESS || hidlFilter == NULL) {
185 return NULL;
186 }
187
188 return hidlFilter;
189}
Amy Zhang9a9ed602020-12-07 16:37:33 -0800190
191sp<IDvr> DemuxClient::openHidlDvr(DvrType dvrType, int bufferSize,
192 sp<HidlDvrCallback> callback) {
193 if (mDemux == NULL) {
194 return NULL;
195 }
196
197 sp<IDvr> hidlDvr;
198 Result res;
199 mDemux->openDvr(dvrType, bufferSize, callback,
200 [&](Result r, const sp<IDvr>& dvr) {
201 hidlDvr = dvr;
202 res = r;
203 });
204 if (res != Result::SUCCESS || hidlDvr == NULL) {
205 return NULL;
206 }
207
208 return hidlDvr;
209}
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800210} // namespace android