Amy | 126ee92 | 2019-08-09 16:25:12 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2019 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 "android.hardware.tv.tuner@1.0-Tuner" |
| 18 | |
| 19 | #include "Tuner.h" |
| 20 | #include <android/hardware/tv/tuner/1.0/IFrontendCallback.h> |
| 21 | #include <utils/Log.h> |
| 22 | #include "Frontend.h" |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace tv { |
| 27 | namespace tuner { |
| 28 | namespace V1_0 { |
| 29 | namespace implementation { |
| 30 | |
| 31 | Tuner::Tuner() { |
| 32 | // Static Frontends array to maintain local frontends information |
| 33 | // Array index matches their FrontendId in the default impl |
| 34 | mFrontendSize = 8; |
| 35 | mFrontends.resize(mFrontendSize); |
| 36 | mFrontends[0] = new Frontend(); |
| 37 | mFrontends[1] = new Frontend(FrontendType::ATSC, 1); |
| 38 | mFrontends[2] = new Frontend(FrontendType::DVBC, 2); |
| 39 | mFrontends[3] = new Frontend(FrontendType::DVBS, 3); |
| 40 | mFrontends[4] = new Frontend(FrontendType::DVBT, 4); |
| 41 | mFrontends[5] = new Frontend(FrontendType::ISDBT, 5); |
| 42 | mFrontends[6] = new Frontend(FrontendType::ANALOG, 6); |
| 43 | mFrontends[7] = new Frontend(FrontendType::ATSC, 7); |
| 44 | } |
| 45 | |
| 46 | Tuner::~Tuner() {} |
| 47 | |
| 48 | Return<void> Tuner::getFrontendIds(getFrontendIds_cb _hidl_cb) { |
| 49 | ALOGV("%s", __FUNCTION__); |
| 50 | |
| 51 | vector<FrontendId> frontendIds; |
| 52 | frontendIds.resize(mFrontendSize); |
| 53 | for (int i = 0; i < mFrontendSize; i++) { |
| 54 | frontendIds[i] = mFrontends[i]->getFrontendId(); |
| 55 | } |
| 56 | |
| 57 | _hidl_cb(Result::SUCCESS, frontendIds); |
| 58 | return Void(); |
| 59 | } |
| 60 | |
| 61 | Return<void> Tuner::openFrontendById(uint32_t frontendId, openFrontendById_cb _hidl_cb) { |
| 62 | ALOGV("%s", __FUNCTION__); |
| 63 | |
| 64 | if (frontendId >= mFrontendSize || frontendId < 0) { |
| 65 | ALOGW("[ WARN ] Frontend with id %d isn't available", frontendId); |
| 66 | _hidl_cb(Result::UNAVAILABLE, nullptr); |
| 67 | return Void(); |
| 68 | } |
| 69 | |
| 70 | _hidl_cb(Result::SUCCESS, mFrontends[frontendId]); |
| 71 | return Void(); |
| 72 | } |
| 73 | |
| 74 | } // namespace implementation |
| 75 | } // namespace V1_0 |
| 76 | } // namespace tuner |
| 77 | } // namespace tv |
| 78 | } // namespace hardware |
| 79 | } // namespace android |