blob: 11acb5ebf52e42f60e251a978ddeebf42338786a [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
17#define LOG_TAG "FrontendClient"
18
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) {
71 sp<FilterClient> filterClient = new FilterClient();
72 filterClient->setHidlFilter(hidlFilter);
73 return filterClient;
74 }
75 }
76
77 // TODO: handle share av memory handle
78
79 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
121//DvrClient openDvr(int dvbType, int bufferSize, DvrClientCallback cb);
122
123Result DemuxClient::connectCiCam(int ciCamId) {
124 // pending aidl interface
125
126 if (mDemux != NULL) {
127 return mDemux->connectCiCam(static_cast<uint32_t>(ciCamId));
128 }
129
130 return Result::INVALID_STATE;
131}
132
133Result DemuxClient::disconnectCiCam() {
134 // pending aidl interface
135
136 if (mDemux != NULL) {
137 return mDemux->disconnectCiCam();
138 }
139
140 return Result::INVALID_STATE;
141}
142
143Result DemuxClient::close() {
144 // pending aidl interface
145
146 if (mDemux != NULL) {
147 Result res = mDemux->close();
148 if (res == Result::SUCCESS) {
149 mDemux = NULL;
150 }
151 return res;
152 }
153
154 return Result::INVALID_STATE;
155}
Amy Zhangb74185b2020-12-07 16:37:33 -0800156
157/////////////// DemuxClient Helper Methods ///////////////////////
158
159sp<IFilter> DemuxClient::openHidlFilter(DemuxFilterType type, int bufferSize,
160 sp<HidlFilterCallback> callback) {
161 if (mDemux == NULL) {
162 return NULL;
163 }
164
165 sp<IFilter> hidlFilter;
166 Result res;
167 mDemux->openFilter(type, bufferSize, callback,
168 [&](Result r, const sp<IFilter>& filter) {
169 hidlFilter = filter;
170 res = r;
171 });
172 if (res != Result::SUCCESS || hidlFilter == NULL) {
173 return NULL;
174 }
175
176 return hidlFilter;
177}
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800178} // namespace android