blob: 88a726fefb9832fe60335ef2efe7e4a9fbce5412 [file] [log] [blame]
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -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 Wasilczyk06100b32017-12-04 09:53:32 -080016#include "BroadcastRadio.h"
17
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080018#include "resources.h"
19
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -080020#include <android-base/logging.h>
21
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080022namespace android {
23namespace hardware {
24namespace broadcastradio {
25namespace V2_0 {
26namespace implementation {
27
28using std::lock_guard;
29using std::map;
30using std::mutex;
31using std::vector;
32
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080033static const AmFmRegionConfig gDefaultAmFmConfig = { //
34 {
35 {87500, 108000, 100, 100}, // FM
36 {153, 282, 3, 9}, // AM LW
37 {531, 1620, 9, 9}, // AM MW
38 {1600, 30000, 1, 5}, // AM SW
39 },
40 static_cast<uint32_t>(Deemphasis::D50),
41 static_cast<uint32_t>(Rds::RDS)};
42
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080043static Properties initProperties(const VirtualRadio& virtualRadio) {
44 Properties prop = {};
45
46 prop.maker = "Google";
47 prop.product = virtualRadio.getName();
48 prop.supportedIdentifierTypes = hidl_vec<uint32_t>({
49 static_cast<uint32_t>(IdentifierType::AMFM_FREQUENCY),
50 static_cast<uint32_t>(IdentifierType::RDS_PI),
51 static_cast<uint32_t>(IdentifierType::HD_STATION_ID_EXT),
Allief62374d2019-02-19 16:21:51 -080052 static_cast<uint32_t>(IdentifierType::DAB_SID_EXT),
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080053 });
54 prop.vendorInfo = hidl_vec<VendorKeyValue>({
55 {"com.google.dummy", "dummy"},
56 });
57
58 return prop;
59}
60
61BroadcastRadio::BroadcastRadio(const VirtualRadio& virtualRadio)
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080062 : mVirtualRadio(virtualRadio),
63 mProperties(initProperties(virtualRadio)),
64 mAmFmConfig(gDefaultAmFmConfig) {}
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080065
66Return<void> BroadcastRadio::getProperties(getProperties_cb _hidl_cb) {
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080067 _hidl_cb(mProperties);
68 return {};
69}
70
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080071AmFmRegionConfig BroadcastRadio::getAmFmConfig() const {
72 lock_guard<mutex> lk(mMut);
73 return mAmFmConfig;
74}
75
76Return<void> BroadcastRadio::getAmFmRegionConfig(bool full, getAmFmRegionConfig_cb _hidl_cb) {
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080077 if (full) {
78 AmFmRegionConfig config = {};
79 config.ranges = hidl_vec<AmFmBandRange>({
80 {65000, 108000, 10, 0}, // FM
81 {150, 30000, 1, 0}, // AM
82 });
83 config.fmDeemphasis = Deemphasis::D50 | Deemphasis::D75;
84 config.fmRds = Rds::RDS | Rds::RBDS;
85 _hidl_cb(Result::OK, config);
86 return {};
87 } else {
88 _hidl_cb(Result::OK, getAmFmConfig());
89 return {};
90 }
91}
92
93Return<void> BroadcastRadio::getDabRegionConfig(getDabRegionConfig_cb _hidl_cb) {
Tomasz Wasilczyk8b70ee42017-12-21 11:51:29 -080094 hidl_vec<DabTableEntry> config = {
95 {"5A", 174928}, {"7D", 194064}, {"8A", 195936}, {"8B", 197648}, {"9A", 202928},
96 {"9B", 204640}, {"9C", 206352}, {"10B", 211648}, {"10C", 213360}, {"10D", 215072},
97 {"11A", 216928}, {"11B", 218640}, {"11C", 220352}, {"11D", 222064}, {"12A", 223936},
98 {"12B", 225648}, {"12C", 227360}, {"12D", 229072},
99 };
100
101 _hidl_cb(Result::OK, config);
102 return {};
103}
104
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800105Return<void> BroadcastRadio::openSession(const sp<ITunerCallback>& callback,
106 openSession_cb _hidl_cb) {
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800107 LOG(DEBUG) << "opening new session...";
Tomasz Wasilczykdb902862018-01-14 17:22:03 -0800108
109 /* For the needs of default implementation it's fine to instantiate new session object
110 * out of the lock scope. If your implementation needs it, use reentrant lock.
111 */
112 sp<TunerSession> newSession = new TunerSession(*this, callback);
113
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800114 lock_guard<mutex> lk(mMut);
115
116 auto oldSession = mSession.promote();
117 if (oldSession != nullptr) {
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800118 LOG(INFO) << "closing previously opened tuner";
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800119 oldSession->close();
120 mSession = nullptr;
121 }
122
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800123 mSession = newSession;
124
125 _hidl_cb(Result::OK, newSession);
126 return {};
127}
128
129Return<void> BroadcastRadio::getImage(uint32_t id, getImage_cb _hidl_cb) {
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800130 LOG(DEBUG) << "fetching image " << std::hex << id;
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800131
132 if (id == resources::demoPngId) {
133 _hidl_cb(std::vector<uint8_t>(resources::demoPng, std::end(resources::demoPng)));
134 return {};
135 }
136
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800137 LOG(INFO) << "image " << std::hex << id << " doesn't exists";
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800138 _hidl_cb({});
139 return {};
140}
141
Tomasz Wasilczyk0d5ef5d2018-01-10 10:58:20 -0800142Return<void> BroadcastRadio::registerAnnouncementListener(
143 const hidl_vec<AnnouncementType>& enabled, const sp<IAnnouncementListener>& /* listener */,
144 registerAnnouncementListener_cb _hidl_cb) {
Tomasz Wasilczyk84ec4e12018-11-13 11:26:23 -0800145 LOG(DEBUG) << "registering announcement listener for " << toString(enabled);
Tomasz Wasilczyk6a9f8562017-12-27 09:46:43 -0800146
147 _hidl_cb(Result::NOT_SUPPORTED, nullptr);
148 return {};
149}
150
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -0800151} // namespace implementation
152} // namespace V2_0
153} // namespace broadcastradio
154} // namespace hardware
155} // namespace android