blob: 17ec7803ae7041baae721bf9e5b11c2897774eaf [file] [log] [blame]
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -08001/*
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 Wasilczyk48377552017-06-22 10:45:33 -070016#define LOG_TAG "BroadcastRadioDefault.module"
17#define LOG_NDEBUG 0
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080018
19#include "BroadcastRadio.h"
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070020
21#include <log/log.h>
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080022
Tomasz Wasilczykba3e2542017-07-17 13:59:21 -070023#include "resources.h"
24
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080025namespace android {
26namespace hardware {
27namespace broadcastradio {
28namespace V1_1 {
29namespace implementation {
30
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070031using V1_0::Band;
32using V1_0::BandConfig;
33using V1_0::Class;
34using V1_0::Deemphasis;
35using V1_0::Rds;
36
37using std::lock_guard;
38using std::map;
39using std::mutex;
40using std::vector;
41
42// clang-format off
43static 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 Wasilczyk213170b2017-02-07 17:38:21 -080068
69BroadcastRadio::BroadcastRadio(Class classId)
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070070 : mClassId(classId), mConfig(gModuleConfigs.at(classId)) {}
71
72bool BroadcastRadio::isSupported(Class classId) {
73 return gModuleConfigs.find(classId) != gModuleConfigs.end();
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -080074}
75
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070076Return<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 Wasilczyk213170b2017-02-07 17:38:21 -080080}
81
Tomasz Wasilczyk02b9cba2017-06-13 09:34:30 -070082Return<void> BroadcastRadio::getProperties_1_1(getProperties_1_1_cb _hidl_cb) {
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070083 ALOGV("%s", __func__);
84 Properties prop11 = {};
85 auto& prop10 = prop11.base;
Tomasz Wasilczyk02b9cba2017-06-13 09:34:30 -070086
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070087 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 Wasilczyke192c392017-07-16 15:14:34 -070094 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 Wasilczyk5ca56432017-07-19 14:48:02 -0700104 prop11.vendorInfo = "dummy";
Tomasz Wasilczyk02b9cba2017-06-13 09:34:30 -0700105
Tomasz Wasilczyk48377552017-06-22 10:45:33 -0700106 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 Wasilczyk803301a2017-03-13 14:30:15 -0700110
Tomasz Wasilczyk48377552017-06-22 10:45:33 -0700111 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 Wasilczyk213170b2017-02-07 17:38:21 -0800116
Tomasz Wasilczyk48377552017-06-22 10:45:33 -0700117 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 Wasilczyk213170b2017-02-07 17:38:21 -0800127 }
128
Tomasz Wasilczyk48377552017-06-22 10:45:33 -0700129 _hidl_cb(prop11);
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -0800130 return Void();
131}
132
Tomasz Wasilczyk48377552017-06-22 10:45:33 -0700133Return<void> BroadcastRadio::openTuner(const BandConfig& config, bool audio __unused,
134 const sp<V1_0::ITunerCallback>& callback,
135 openTuner_cb _hidl_cb) {
Tomasz Wasilczykc9ba6462017-07-07 13:28:00 -0700136 ALOGV("%s(%s)", __func__, toString(config.type).c_str());
Tomasz Wasilczyk48377552017-06-22 10:45:33 -0700137 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 Wasilczykefadc192017-07-28 10:08:46 -0700146 sp<Tuner> newTuner = new Tuner(mClassId, callback);
Tomasz Wasilczyk48377552017-06-22 10:45:33 -0700147 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 Wasilczykba3e2542017-07-17 13:59:21 -0700160Return<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 Wasilczyk48377552017-06-22 10:45:33 -0700173} // namespace implementation
Tomasz Wasilczyk213170b2017-02-07 17:38:21 -0800174} // namespace V1_1
175} // namespace broadcastradio
176} // namespace hardware
177} // namespace android