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) { |
Amy Zhang | 9b5831b | 2020-12-09 21:13:58 -0800 | [diff] [blame] | 71 | sp<FilterClient> filterClient = new FilterClient(type); |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 72 | filterClient->setHidlFilter(hidlFilter); |
| 73 | return filterClient; |
| 74 | } |
| 75 | } |
| 76 | |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 77 | return NULL; |
| 78 | } |
| 79 | |
| 80 | int 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 Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | long 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 | |
| 119 | //DvrClient openDvr(int dvbType, int bufferSize, DvrClientCallback cb); |
| 120 | |
| 121 | Result DemuxClient::connectCiCam(int ciCamId) { |
| 122 | // pending aidl interface |
| 123 | |
| 124 | if (mDemux != NULL) { |
| 125 | return mDemux->connectCiCam(static_cast<uint32_t>(ciCamId)); |
| 126 | } |
| 127 | |
| 128 | return Result::INVALID_STATE; |
| 129 | } |
| 130 | |
| 131 | Result DemuxClient::disconnectCiCam() { |
| 132 | // pending aidl interface |
| 133 | |
| 134 | if (mDemux != NULL) { |
| 135 | return mDemux->disconnectCiCam(); |
| 136 | } |
| 137 | |
| 138 | return Result::INVALID_STATE; |
| 139 | } |
| 140 | |
| 141 | Result DemuxClient::close() { |
Amy Zhang | 9b5831b | 2020-12-09 21:13:58 -0800 | [diff] [blame] | 142 | // TODO: pending aidl interface |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 143 | |
| 144 | if (mDemux != NULL) { |
| 145 | Result res = mDemux->close(); |
| 146 | if (res == Result::SUCCESS) { |
| 147 | mDemux = NULL; |
| 148 | } |
| 149 | return res; |
| 150 | } |
| 151 | |
| 152 | return Result::INVALID_STATE; |
| 153 | } |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 154 | |
| 155 | /////////////// DemuxClient Helper Methods /////////////////////// |
| 156 | |
| 157 | sp<IFilter> DemuxClient::openHidlFilter(DemuxFilterType type, int bufferSize, |
| 158 | sp<HidlFilterCallback> callback) { |
| 159 | if (mDemux == NULL) { |
| 160 | return NULL; |
| 161 | } |
| 162 | |
| 163 | sp<IFilter> hidlFilter; |
| 164 | Result res; |
| 165 | mDemux->openFilter(type, bufferSize, callback, |
| 166 | [&](Result r, const sp<IFilter>& filter) { |
| 167 | hidlFilter = filter; |
| 168 | res = r; |
| 169 | }); |
| 170 | if (res != Result::SUCCESS || hidlFilter == NULL) { |
| 171 | return NULL; |
| 172 | } |
| 173 | |
| 174 | return hidlFilter; |
| 175 | } |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 176 | } // namespace android |