Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | using ::aidl::android::media::tv::tuner::TunerFrontendSettings; |
| 25 | |
| 26 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | /////////////// DemuxClient /////////////////////// |
| 31 | |
| 32 | // TODO: pending aidl interface |
| 33 | DemuxClient::DemuxClient() { |
| 34 | //mTunerDemux = tunerDemux; |
| 35 | } |
| 36 | |
| 37 | DemuxClient::~DemuxClient() { |
| 38 | //mTunerDemux = NULL; |
| 39 | mDemux = NULL; |
| 40 | } |
| 41 | |
| 42 | // TODO: remove after migration to Tuner Service is done. |
| 43 | void DemuxClient::setHidlDemux(sp<IDemux> demux) { |
| 44 | mDemux = demux; |
| 45 | } |
| 46 | |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 47 | Result DemuxClient::setFrontendDataSource(sp<FrontendClient> frontendClient) { |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 48 | // TODO: pending aidl interface |
| 49 | /*if (mTunerDemux != NULL) { |
| 50 | // TODO: handle error message |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 51 | mTunerDemux->setFrontendDataSource(frontendClient->getAidlFrontend()); |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 52 | return (int) Result::SUCCESS; |
| 53 | }*/ |
| 54 | |
| 55 | if (mDemux != NULL) { |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 56 | Result res = mDemux->setFrontendDataSource(frontendClient->getId()); |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 57 | return res; |
| 58 | } |
| 59 | |
| 60 | return Result::INVALID_STATE; |
| 61 | } |
| 62 | |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 63 | sp<FilterClient> DemuxClient::openFilter(DemuxFilterType type, int bufferSize, |
| 64 | sp<FilterClientCallback> cb) { |
| 65 | // TODO: pending aidl interface |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 66 | |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 67 | 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 | |
| 82 | int 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 Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | long 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 | |
| 123 | Result 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 | |
| 133 | Result DemuxClient::disconnectCiCam() { |
| 134 | // pending aidl interface |
| 135 | |
| 136 | if (mDemux != NULL) { |
| 137 | return mDemux->disconnectCiCam(); |
| 138 | } |
| 139 | |
| 140 | return Result::INVALID_STATE; |
| 141 | } |
| 142 | |
| 143 | Result 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 Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 156 | |
| 157 | /////////////// DemuxClient Helper Methods /////////////////////// |
| 158 | |
| 159 | sp<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 Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 178 | } // namespace android |