Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | */ |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 16 | #define LOG_TAG "BroadcastRadioDefault.module" |
| 17 | #define LOG_NDEBUG 0 |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 18 | |
| 19 | #include "BroadcastRadio.h" |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 20 | |
| 21 | #include <log/log.h> |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace broadcastradio { |
| 26 | namespace V1_1 { |
| 27 | namespace implementation { |
| 28 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 29 | using V1_0::Band; |
| 30 | using V1_0::BandConfig; |
| 31 | using V1_0::Class; |
| 32 | using V1_0::Deemphasis; |
| 33 | using V1_0::Rds; |
| 34 | |
| 35 | using std::lock_guard; |
| 36 | using std::map; |
| 37 | using std::mutex; |
| 38 | using std::vector; |
| 39 | |
| 40 | // clang-format off |
| 41 | static const map<Class, ModuleConfig> gModuleConfigs{ |
| 42 | {Class::AM_FM, ModuleConfig({ |
| 43 | "Digital radio mock", |
| 44 | { // amFmBands |
| 45 | AmFmBandConfig({ |
| 46 | Band::AM_HD, |
| 47 | 540, // lowerLimit |
| 48 | 1610, // upperLimit |
| 49 | 10, // spacing |
| 50 | }), |
| 51 | AmFmBandConfig({ |
| 52 | Band::FM_HD, |
| 53 | 87900, // lowerLimit |
| 54 | 107900, // upperLimit |
| 55 | 200, // spacing |
| 56 | }), |
| 57 | }, |
| 58 | })}, |
| 59 | |
| 60 | {Class::SAT, ModuleConfig({ |
| 61 | "Satellite radio mock", |
| 62 | {}, // amFmBands |
| 63 | })}, |
| 64 | }; |
| 65 | // clang-format on |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 66 | |
| 67 | BroadcastRadio::BroadcastRadio(Class classId) |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 68 | : mClassId(classId), mConfig(gModuleConfigs.at(classId)) {} |
| 69 | |
| 70 | bool BroadcastRadio::isSupported(Class classId) { |
| 71 | return gModuleConfigs.find(classId) != gModuleConfigs.end(); |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 74 | Return<void> BroadcastRadio::getProperties(getProperties_cb _hidl_cb) { |
| 75 | ALOGV("%s", __func__); |
| 76 | return getProperties_1_1( |
| 77 | [&](const Properties& properties) { _hidl_cb(Result::OK, properties.base); }); |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Tomasz Wasilczyk | 02b9cba | 2017-06-13 09:34:30 -0700 | [diff] [blame] | 80 | Return<void> BroadcastRadio::getProperties_1_1(getProperties_1_1_cb _hidl_cb) { |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 81 | ALOGV("%s", __func__); |
| 82 | Properties prop11 = {}; |
| 83 | auto& prop10 = prop11.base; |
Tomasz Wasilczyk | 02b9cba | 2017-06-13 09:34:30 -0700 | [diff] [blame] | 84 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 85 | prop10.classId = mClassId; |
| 86 | prop10.implementor = "Google"; |
| 87 | prop10.product = mConfig.productName; |
| 88 | prop10.numTuners = 1; |
| 89 | prop10.numAudioSources = 1; |
| 90 | prop10.supportsCapture = false; |
| 91 | prop11.supportsBackgroundScanning = false; |
| 92 | prop11.vendorExension = "dummy"; |
Tomasz Wasilczyk | 02b9cba | 2017-06-13 09:34:30 -0700 | [diff] [blame] | 93 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 94 | prop10.bands.resize(mConfig.amFmBands.size()); |
| 95 | for (size_t i = 0; i < mConfig.amFmBands.size(); i++) { |
| 96 | auto& src = mConfig.amFmBands[i]; |
| 97 | auto& dst = prop10.bands[i]; |
Tomasz Wasilczyk | 803301a | 2017-03-13 14:30:15 -0700 | [diff] [blame] | 98 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 99 | dst.type = src.type; |
| 100 | dst.antennaConnected = true; |
| 101 | dst.lowerLimit = src.lowerLimit; |
| 102 | dst.upperLimit = src.upperLimit; |
| 103 | dst.spacings = vector<uint32_t>({src.spacing}); |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 104 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 105 | if (src.type == Band::AM) { |
| 106 | dst.ext.am.stereo = true; |
| 107 | } else if (src.type == Band::FM) { |
| 108 | dst.ext.fm.deemphasis = Deemphasis::D75; |
| 109 | dst.ext.fm.stereo = true; |
| 110 | dst.ext.fm.rds = Rds::US; |
| 111 | dst.ext.fm.ta = true; |
| 112 | dst.ext.fm.af = true; |
| 113 | dst.ext.fm.ea = true; |
| 114 | } |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 117 | _hidl_cb(prop11); |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 118 | return Void(); |
| 119 | } |
| 120 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 121 | Return<void> BroadcastRadio::openTuner(const BandConfig& config, bool audio __unused, |
| 122 | const sp<V1_0::ITunerCallback>& callback, |
| 123 | openTuner_cb _hidl_cb) { |
Tomasz Wasilczyk | c9ba646 | 2017-07-07 13:28:00 -0700 | [diff] [blame^] | 124 | ALOGV("%s(%s)", __func__, toString(config.type).c_str()); |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 125 | lock_guard<mutex> lk(mMut); |
| 126 | |
| 127 | auto oldTuner = mTuner.promote(); |
| 128 | if (oldTuner != nullptr) { |
| 129 | ALOGI("Force-closing previously opened tuner"); |
| 130 | oldTuner->forceClose(); |
| 131 | mTuner = nullptr; |
| 132 | } |
| 133 | |
| 134 | sp<Tuner> newTuner = new Tuner(callback); |
| 135 | mTuner = newTuner; |
| 136 | if (mClassId == Class::AM_FM) { |
| 137 | auto ret = newTuner->setConfiguration(config); |
| 138 | if (ret != Result::OK) { |
| 139 | _hidl_cb(Result::INVALID_ARGUMENTS, {}); |
| 140 | return Void(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | _hidl_cb(Result::OK, newTuner); |
| 145 | return Void(); |
| 146 | } |
| 147 | |
| 148 | } // namespace implementation |
Tomasz Wasilczyk | 213170b | 2017-02-07 17:38:21 -0800 | [diff] [blame] | 149 | } // namespace V1_1 |
| 150 | } // namespace broadcastradio |
| 151 | } // namespace hardware |
| 152 | } // namespace android |