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