Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -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 "FrontendClient.h" |
| 23 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 24 | using ::aidl::android::media::tv::tuner::TunerFrontendSettings; |
Amy Zhang | d08c273 | 2021-01-08 17:22:59 -0800 | [diff] [blame] | 25 | using ::android::hardware::tv::tuner::V1_1::Constant; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 26 | |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 27 | namespace android { |
| 28 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 29 | /////////////// FrontendClient /////////////////////// |
| 30 | |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 31 | FrontendClient::FrontendClient(shared_ptr<ITunerFrontend> tunerFrontend, int id) { |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 32 | mTunerFrontend = tunerFrontend; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 33 | mAidlCallback = NULL; |
| 34 | mHidlCallback = NULL; |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 35 | mId = id; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | FrontendClient::~FrontendClient() { |
| 39 | mTunerFrontend = NULL; |
| 40 | mFrontend = NULL; |
| 41 | mFrontend_1_1 = NULL; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 42 | mAidlCallback = NULL; |
| 43 | mHidlCallback = NULL; |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 44 | mId = -1; |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | Result FrontendClient::setCallback(sp<FrontendClientCallback> frontendClientCallback) { |
| 48 | if (mTunerFrontend != NULL) { |
| 49 | mAidlCallback = ::ndk::SharedRefBase::make<TunerFrontendCallback>(frontendClientCallback); |
| 50 | mTunerFrontend->setCallback(mAidlCallback); |
| 51 | return Result::SUCCESS; |
| 52 | } |
| 53 | |
| 54 | mHidlCallback = new HidlFrontendCallback(frontendClientCallback); |
| 55 | return mFrontend->setCallback(mHidlCallback); |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void FrontendClient::setHidlFrontend(sp<IFrontend> frontend) { |
| 59 | mFrontend = frontend; |
| 60 | mFrontend_1_1 = ::android::hardware::tv::tuner::V1_1::IFrontend::castFrom(mFrontend); |
| 61 | } |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 62 | |
| 63 | Result FrontendClient::tune(const FrontendSettings& settings, |
| 64 | const FrontendSettingsExt1_1& settingsExt1_1) { |
| 65 | if (mTunerFrontend != NULL) { |
| 66 | // TODO: parse hidl settings to aidl settings |
| 67 | // TODO: aidl frontend settings to include Tuner HAL 1.1 settings |
| 68 | TunerFrontendSettings settings; |
| 69 | // TODO: handle error message. |
| 70 | mTunerFrontend->tune(settings); |
| 71 | return Result::SUCCESS; |
| 72 | } |
| 73 | |
| 74 | Result result; |
| 75 | if (mFrontend_1_1 != NULL) { |
| 76 | result = mFrontend_1_1->tune_1_1(settings, settingsExt1_1); |
| 77 | return result; |
| 78 | } |
| 79 | |
| 80 | if (mFrontend != NULL) { |
| 81 | result = mFrontend->tune(settings); |
| 82 | return result; |
| 83 | } |
| 84 | |
| 85 | return Result::INVALID_STATE; |
Amy Zhang | bf68a16 | 2020-11-23 17:42:40 -0800 | [diff] [blame] | 86 | } |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 87 | |
| 88 | Result FrontendClient::stopTune() { |
| 89 | if (mTunerFrontend != NULL) { |
| 90 | // TODO: handle error message. |
| 91 | mTunerFrontend->stopTune(); |
| 92 | return Result::SUCCESS; |
| 93 | } |
| 94 | |
| 95 | if (mFrontend != NULL) { |
| 96 | Result result = mFrontend->stopTune(); |
| 97 | return result; |
| 98 | } |
| 99 | |
| 100 | return Result::INVALID_STATE; |
| 101 | } |
| 102 | |
Amy Zhang | d08c273 | 2021-01-08 17:22:59 -0800 | [diff] [blame] | 103 | Result FrontendClient::scan(const FrontendSettings& settings, FrontendScanType type, |
| 104 | const FrontendSettingsExt1_1& settingsExt1_1) { |
| 105 | if (mTunerFrontend != NULL) { |
| 106 | // TODO: parse hidl settings to aidl settings |
| 107 | // TODO: aidl frontend settings to include Tuner HAL 1.1 settings |
| 108 | TunerFrontendSettings settings; |
| 109 | // TODO: handle error message. |
| 110 | mTunerFrontend->scan(settings, (int)type); |
| 111 | return Result::SUCCESS; |
| 112 | } |
| 113 | |
| 114 | Result result; |
| 115 | if (mFrontend_1_1 != NULL) { |
| 116 | result = mFrontend_1_1->scan_1_1(settings, type, settingsExt1_1); |
| 117 | return result; |
| 118 | } |
| 119 | |
| 120 | if (mFrontend != NULL) { |
| 121 | result = mFrontend->scan(settings, type); |
| 122 | return result; |
| 123 | } |
| 124 | |
| 125 | return Result::INVALID_STATE; |
| 126 | } |
| 127 | |
| 128 | Result FrontendClient::stopScan() { |
| 129 | if (mTunerFrontend != NULL) { |
| 130 | // TODO: handle error message. |
| 131 | mTunerFrontend->stopScan(); |
| 132 | return Result::SUCCESS; |
| 133 | } |
| 134 | |
| 135 | if (mFrontend != NULL) { |
| 136 | Result result = mFrontend->stopScan(); |
| 137 | return result; |
| 138 | } |
| 139 | |
| 140 | return Result::INVALID_STATE; |
| 141 | } |
| 142 | |
| 143 | vector<FrontendStatus> FrontendClient::getStatus(vector<FrontendStatusType> statusTypes) { |
| 144 | vector<FrontendStatus> status; |
| 145 | |
| 146 | if (mTunerFrontend != NULL) { |
| 147 | // TODO: handle error message. |
| 148 | /*status = mTunerFrontend->getStatus(statusTypes); |
| 149 | return status;*/ |
| 150 | } |
| 151 | |
| 152 | if (mFrontend != NULL && statusTypes.size() > 0) { |
| 153 | Result res; |
| 154 | mFrontend->getStatus(statusTypes, |
| 155 | [&](Result r, const hidl_vec<FrontendStatus>& s) { |
| 156 | res = r; |
| 157 | status = s; |
| 158 | }); |
| 159 | if (res != Result::SUCCESS) { |
| 160 | status.clear(); |
| 161 | return status; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return status; |
| 166 | } |
| 167 | vector<FrontendStatusExt1_1> FrontendClient::getStatusExtended_1_1( |
| 168 | vector<FrontendStatusTypeExt1_1> statusTypes) { |
| 169 | vector<FrontendStatusExt1_1> status; |
| 170 | |
| 171 | if (mTunerFrontend != NULL) { |
| 172 | // TODO: handle error message. |
| 173 | /*status = mTunerFrontend->getStatusExtended_1_1(statusTypes); |
| 174 | return status;*/ |
| 175 | } |
| 176 | |
| 177 | if (mFrontend_1_1 != NULL && statusTypes.size() > 0) { |
| 178 | Result res; |
| 179 | mFrontend_1_1->getStatusExt1_1(statusTypes, |
| 180 | [&](Result r, const hidl_vec<FrontendStatusExt1_1>& s) { |
| 181 | res = r; |
| 182 | status = s; |
| 183 | }); |
| 184 | if (res != Result::SUCCESS) { |
| 185 | status.clear(); |
| 186 | return status; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return status; |
| 191 | } |
| 192 | |
Amy Zhang | d3d57b4 | 2021-01-07 11:14:43 -0800 | [diff] [blame] | 193 | Result FrontendClient::setLnb(sp<LnbClient> lnbClient) { |
| 194 | if (mTunerFrontend != NULL) { |
| 195 | // TODO: handle error message. |
| 196 | /*mTunerFrontend->setLnb(lnbClient->getAidlLnb()); |
| 197 | return Result::SUCCESS;*/ |
| 198 | } |
| 199 | |
| 200 | if (mFrontend != NULL) { |
| 201 | Result result = mFrontend->setLnb(lnbClient->getId()); |
| 202 | return result; |
| 203 | } |
| 204 | |
| 205 | return Result::INVALID_STATE; |
| 206 | } |
| 207 | |
Amy Zhang | d08c273 | 2021-01-08 17:22:59 -0800 | [diff] [blame] | 208 | Result FrontendClient::setLna(bool bEnable) { |
| 209 | if (mTunerFrontend != NULL) { |
| 210 | // TODO: handle error message. |
| 211 | /*mTunerFrontend->setLna(bEnable); |
| 212 | return Result::SUCCESS;*/ |
| 213 | } |
| 214 | |
| 215 | if (mFrontend != NULL) { |
| 216 | Result result = mFrontend->setLna(bEnable); |
| 217 | return result; |
| 218 | } |
| 219 | |
| 220 | return Result::INVALID_STATE; |
| 221 | } |
| 222 | |
| 223 | int FrontendClient::linkCiCamToFrontend(int ciCamId) { |
| 224 | int ltsId = (int)Constant::INVALID_LTS_ID; |
| 225 | |
| 226 | if (mTunerFrontend != NULL) { |
| 227 | // TODO: handle error message. |
| 228 | /*mTunerFrontend->linkCiCamToFrontend(ciCamId, ltsId); |
| 229 | return ltsId;*/ |
| 230 | } |
| 231 | |
| 232 | if (mFrontend_1_1 != NULL) { |
| 233 | Result res; |
| 234 | mFrontend_1_1->linkCiCam(static_cast<uint32_t>(ciCamId), |
| 235 | [&](Result r, uint32_t id) { |
| 236 | res = r; |
| 237 | ltsId = id; |
| 238 | }); |
| 239 | if (res != Result::SUCCESS) { |
| 240 | return (int)Constant::INVALID_LTS_ID; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | return ltsId; |
| 245 | } |
| 246 | |
| 247 | Result FrontendClient::unlinkCiCamToFrontend(int ciCamId) { |
| 248 | if (mTunerFrontend != NULL) { |
| 249 | // TODO: handle error message. |
| 250 | /*mTunerFrontend->unlinkCiCamToFrontend(ciCamId); |
| 251 | return Result::SUCCESS;*/ |
| 252 | } |
| 253 | |
| 254 | if (mFrontend_1_1 != NULL) { |
| 255 | return mFrontend_1_1->unlinkCiCam(static_cast<uint32_t>(ciCamId)); |
| 256 | } |
| 257 | |
| 258 | return Result::INVALID_STATE; |
| 259 | } |
| 260 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 261 | Result FrontendClient::close() { |
| 262 | if (mTunerFrontend != NULL) { |
| 263 | // TODO: handle error message. |
| 264 | mTunerFrontend->close(); |
| 265 | return Result::SUCCESS; |
| 266 | } |
| 267 | |
| 268 | if (mFrontend != NULL) { |
| 269 | Result result = mFrontend->close(); |
| 270 | if (result == Result::SUCCESS) { |
| 271 | mFrontend = NULL; |
| 272 | mFrontend_1_1 = NULL; |
| 273 | } |
| 274 | return result; |
| 275 | } |
| 276 | |
| 277 | return Result::INVALID_STATE; |
| 278 | } |
| 279 | |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 280 | shared_ptr<ITunerFrontend> FrontendClient::getAidlFrontend() { |
| 281 | return mTunerFrontend; |
| 282 | } |
| 283 | |
| 284 | int FrontendClient::getId() { |
Amy Zhang | 210c26a | 2021-01-12 11:25:27 -0800 | [diff] [blame] | 285 | return mId; |
Amy Zhang | 6bfeaa0 | 2020-11-30 15:16:39 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Amy Zhang | a673468 | 2020-11-30 16:14:38 -0800 | [diff] [blame] | 288 | /////////////// TunerFrontendCallback /////////////////////// |
| 289 | |
| 290 | TunerFrontendCallback::TunerFrontendCallback(sp<FrontendClientCallback> frontendClientCallback) |
| 291 | : mFrontendClientCallback(frontendClientCallback) {} |
| 292 | |
| 293 | Status TunerFrontendCallback::onEvent(int frontendEventType) { |
| 294 | if (mFrontendClientCallback != NULL) { |
| 295 | mFrontendClientCallback->onEvent(static_cast<FrontendEventType>(frontendEventType)); |
| 296 | return Status::ok(); |
| 297 | } |
| 298 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_STATE)); |
| 299 | } |
| 300 | |
| 301 | Status TunerFrontendCallback::onLocked() { |
| 302 | return Status::ok(); |
| 303 | } |
| 304 | |
| 305 | Status TunerFrontendCallback::onScanStopped() { |
| 306 | return Status::ok(); |
| 307 | } |
| 308 | |
| 309 | Status TunerFrontendCallback::onProgress(int /*percent*/) { |
| 310 | return Status::ok(); |
| 311 | } |
| 312 | |
| 313 | Status TunerFrontendCallback::onFrequenciesReport(const vector<int>& /*frequency*/) { |
| 314 | return Status::ok(); |
| 315 | } |
| 316 | |
| 317 | Status TunerFrontendCallback::onSymbolRates(const vector<int>& /*rates*/) { |
| 318 | return Status::ok(); |
| 319 | } |
| 320 | |
| 321 | Status TunerFrontendCallback::onHierarchy(int /*hierarchy*/) { |
| 322 | return Status::ok(); |
| 323 | } |
| 324 | |
| 325 | Status TunerFrontendCallback::onSignalType(int /*signalType*/) { |
| 326 | return Status::ok(); |
| 327 | } |
| 328 | |
| 329 | Status TunerFrontendCallback::onPlpIds(const vector<int>& /*plpIds*/) { |
| 330 | return Status::ok(); |
| 331 | } |
| 332 | |
| 333 | Status TunerFrontendCallback::onGroupIds(const vector<int>& /*groupIds*/) { |
| 334 | return Status::ok(); |
| 335 | } |
| 336 | |
| 337 | Status TunerFrontendCallback::onInputStreamIds(const vector<int>& /*inputStreamIds*/) { |
| 338 | return Status::ok(); |
| 339 | } |
| 340 | |
| 341 | Status TunerFrontendCallback::onDvbsStandard(int /*dvbsStandandard*/) { |
| 342 | return Status::ok(); |
| 343 | } |
| 344 | |
| 345 | Status TunerFrontendCallback::onAnalogSifStandard(int /*sifStandandard*/) { |
| 346 | return Status::ok(); |
| 347 | } |
| 348 | |
| 349 | Status TunerFrontendCallback::onAtsc3PlpInfos(const vector<TunerAtsc3PlpInfo>& /*atsc3PlpInfos*/) { |
| 350 | return Status::ok(); |
| 351 | } |
| 352 | |
| 353 | /////////////// IFrontendCallback /////////////////////// |
| 354 | |
| 355 | HidlFrontendCallback::HidlFrontendCallback(sp<FrontendClientCallback> frontendClientCallback) |
| 356 | : mFrontendClientCallback(frontendClientCallback) {} |
| 357 | |
| 358 | Return<void> HidlFrontendCallback::onEvent(FrontendEventType frontendEventType) { |
| 359 | if (mFrontendClientCallback != NULL) { |
| 360 | mFrontendClientCallback->onEvent(frontendEventType); |
| 361 | } |
| 362 | return Void(); |
| 363 | } |
| 364 | |
| 365 | Return<void> HidlFrontendCallback::onScanMessage(FrontendScanMessageType type, |
| 366 | const FrontendScanMessage& message) { |
| 367 | if (mFrontendClientCallback != NULL) { |
| 368 | mFrontendClientCallback->onScanMessage(type, message); |
| 369 | } |
| 370 | return Void(); |
| 371 | } |
| 372 | |
| 373 | Return<void> HidlFrontendCallback::onScanMessageExt1_1(FrontendScanMessageTypeExt1_1 type, |
| 374 | const FrontendScanMessageExt1_1& message) { |
| 375 | if (mFrontendClientCallback != NULL) { |
| 376 | mFrontendClientCallback->onScanMessageExt1_1(type, message); |
| 377 | } |
| 378 | return Void(); |
| 379 | } |
| 380 | } // namespace android |