Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 1 | /* |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 2 | * Copyright 2021 The Android Open Source Project |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 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 Zhang | 9a9ed60 | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 17 | #define LOG_TAG "DemuxClient" |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 18 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 19 | #include "DemuxClient.h" |
| 20 | |
| 21 | #include <aidl/android/hardware/tv/tuner/Constant.h> |
| 22 | #include <aidl/android/hardware/tv/tuner/Constant64Bit.h> |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 23 | #include <android-base/logging.h> |
| 24 | #include <utils/Log.h> |
| 25 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 26 | using ::aidl::android::hardware::tv::tuner::Constant; |
| 27 | using ::aidl::android::hardware::tv::tuner::Constant64Bit; |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 30 | /////////////// DemuxClient /////////////////////// |
Amy Zhang | 4a07e80 | 2021-01-21 17:10:21 -0800 | [diff] [blame] | 31 | DemuxClient::DemuxClient(shared_ptr<ITunerDemux> tunerDemux) { |
| 32 | mTunerDemux = tunerDemux; |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | DemuxClient::~DemuxClient() { |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 36 | mTunerDemux = nullptr; |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 37 | } |
| 38 | |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 39 | Result DemuxClient::setFrontendDataSource(sp<FrontendClient> frontendClient) { |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 40 | if (frontendClient == nullptr) { |
| 41 | return Result::INVALID_ARGUMENT; |
Amy Zhang | 4a07e80 | 2021-01-21 17:10:21 -0800 | [diff] [blame] | 42 | } |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 43 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 44 | if (mTunerDemux != nullptr) { |
| 45 | Status s = mTunerDemux->setFrontendDataSource(frontendClient->getAidlFrontend()); |
| 46 | return ClientHelper::getServiceSpecificErrorCode(s); |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | return Result::INVALID_STATE; |
| 50 | } |
| 51 | |
Kensuke Miyagi | 7a45c0a | 2021-07-30 17:40:52 -0700 | [diff] [blame] | 52 | Result DemuxClient::setFrontendDataSourceById(int frontendId) { |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 53 | if (mTunerDemux != nullptr) { |
Kensuke Miyagi | 7a45c0a | 2021-07-30 17:40:52 -0700 | [diff] [blame] | 54 | Status s = mTunerDemux->setFrontendDataSourceById(frontendId); |
| 55 | return ClientHelper::getServiceSpecificErrorCode(s); |
| 56 | } |
| 57 | |
| 58 | return Result::INVALID_STATE; |
| 59 | } |
| 60 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 61 | sp<FilterClient> DemuxClient::openFilter(const DemuxFilterType& type, int32_t bufferSize, |
| 62 | sp<FilterClientCallback> cb) { |
| 63 | if (cb == nullptr) { |
| 64 | return nullptr; |
| 65 | } |
| 66 | |
| 67 | if (mTunerDemux != nullptr) { |
Amy Zhang | 4a07e80 | 2021-01-21 17:10:21 -0800 | [diff] [blame] | 68 | shared_ptr<ITunerFilter> tunerFilter; |
| 69 | shared_ptr<TunerFilterCallback> callback = |
| 70 | ::ndk::SharedRefBase::make<TunerFilterCallback>(cb); |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 71 | Status s = mTunerDemux->openFilter(type, bufferSize, callback, &tunerFilter); |
| 72 | if (!s.isOk()) { |
| 73 | return nullptr; |
Amy Zhang | 4a07e80 | 2021-01-21 17:10:21 -0800 | [diff] [blame] | 74 | } |
| 75 | return new FilterClient(type, tunerFilter); |
| 76 | } |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 77 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 78 | return nullptr; |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Amy Zhang | 90a50b4 | 2021-01-11 16:58:59 -0800 | [diff] [blame] | 81 | sp<TimeFilterClient> DemuxClient::openTimeFilter() { |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 82 | if (mTunerDemux != nullptr) { |
Amy Zhang | 95279466 | 2021-02-04 15:56:22 -0800 | [diff] [blame] | 83 | shared_ptr<ITunerTimeFilter> tunerTimeFilter; |
| 84 | Status s = mTunerDemux->openTimeFilter(&tunerTimeFilter); |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 85 | if (!s.isOk()) { |
| 86 | return nullptr; |
Amy Zhang | 95279466 | 2021-02-04 15:56:22 -0800 | [diff] [blame] | 87 | } |
| 88 | return new TimeFilterClient(tunerTimeFilter); |
| 89 | } |
Amy Zhang | 90a50b4 | 2021-01-11 16:58:59 -0800 | [diff] [blame] | 90 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 91 | return nullptr; |
Amy Zhang | 90a50b4 | 2021-01-11 16:58:59 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 94 | int32_t DemuxClient::getAvSyncHwId(sp<FilterClient> filterClient) { |
| 95 | if (filterClient == nullptr) { |
| 96 | return static_cast<int32_t>(Constant::INVALID_AV_SYNC_ID); |
| 97 | } |
| 98 | |
| 99 | if (mTunerDemux != nullptr) { |
| 100 | int32_t hwId; |
Amy Zhang | 95279466 | 2021-02-04 15:56:22 -0800 | [diff] [blame] | 101 | Status s = mTunerDemux->getAvSyncHwId(filterClient->getAidlFilter(), &hwId); |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 102 | if (!s.isOk()) { |
| 103 | return static_cast<int32_t>(Constant::INVALID_AV_SYNC_ID); |
Amy Zhang | 95279466 | 2021-02-04 15:56:22 -0800 | [diff] [blame] | 104 | } |
| 105 | return hwId; |
| 106 | } |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 107 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 108 | return static_cast<int32_t>(Constant::INVALID_AV_SYNC_ID); |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 111 | int64_t DemuxClient::getAvSyncTime(int32_t avSyncHwId) { |
| 112 | if (mTunerDemux != nullptr) { |
Amy Zhang | 95279466 | 2021-02-04 15:56:22 -0800 | [diff] [blame] | 113 | int64_t time; |
| 114 | Status s = mTunerDemux->getAvSyncTime(avSyncHwId, &time); |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 115 | if (!s.isOk()) { |
| 116 | return static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP); |
Amy Zhang | 95279466 | 2021-02-04 15:56:22 -0800 | [diff] [blame] | 117 | } |
| 118 | return time; |
| 119 | } |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 120 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 121 | return static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP); |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 124 | sp<DvrClient> DemuxClient::openDvr(DvrType dvbType, int32_t bufferSize, sp<DvrClientCallback> cb) { |
| 125 | if (cb == nullptr) { |
| 126 | return nullptr; |
| 127 | } |
| 128 | |
| 129 | if (mTunerDemux != nullptr) { |
Amy Zhang | b5809be | 2021-01-26 16:27:23 -0800 | [diff] [blame] | 130 | shared_ptr<ITunerDvr> tunerDvr; |
| 131 | shared_ptr<TunerDvrCallback> callback = |
| 132 | ::ndk::SharedRefBase::make<TunerDvrCallback>(cb); |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 133 | Status s = mTunerDemux->openDvr(dvbType, bufferSize, callback, &tunerDvr); |
| 134 | if (!s.isOk()) { |
| 135 | return nullptr; |
Amy Zhang | b5809be | 2021-01-26 16:27:23 -0800 | [diff] [blame] | 136 | } |
| 137 | return new DvrClient(tunerDvr); |
| 138 | } |
Amy Zhang | 9a9ed60 | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 139 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 140 | return nullptr; |
Amy Zhang | 9a9ed60 | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 141 | } |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 142 | |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 143 | Result DemuxClient::connectCiCam(int32_t ciCamId) { |
| 144 | if (mTunerDemux != nullptr) { |
Amy Zhang | 95279466 | 2021-02-04 15:56:22 -0800 | [diff] [blame] | 145 | Status s = mTunerDemux->connectCiCam(ciCamId); |
| 146 | return ClientHelper::getServiceSpecificErrorCode(s); |
| 147 | } |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 148 | |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 149 | return Result::INVALID_STATE; |
| 150 | } |
| 151 | |
| 152 | Result DemuxClient::disconnectCiCam() { |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 153 | if (mTunerDemux != nullptr) { |
Amy Zhang | 95279466 | 2021-02-04 15:56:22 -0800 | [diff] [blame] | 154 | Status s = mTunerDemux->disconnectCiCam(); |
| 155 | return ClientHelper::getServiceSpecificErrorCode(s); |
| 156 | } |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 157 | |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 158 | return Result::INVALID_STATE; |
| 159 | } |
| 160 | |
| 161 | Result DemuxClient::close() { |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 162 | if (mTunerDemux != nullptr) { |
Amy Zhang | b5809be | 2021-01-26 16:27:23 -0800 | [diff] [blame] | 163 | Status s = mTunerDemux->close(); |
Hongguang | 56637e9 | 2021-07-28 17:32:55 -0700 | [diff] [blame] | 164 | mTunerDemux = nullptr; |
Amy Zhang | b5809be | 2021-01-26 16:27:23 -0800 | [diff] [blame] | 165 | return ClientHelper::getServiceSpecificErrorCode(s); |
| 166 | } |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 167 | |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 168 | return Result::INVALID_STATE; |
| 169 | } |
Amy Zhang | b74185b | 2020-12-07 16:37:33 -0800 | [diff] [blame] | 170 | |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 171 | } // namespace android |