Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #include "VirtualRadio.h" |
| 18 | #include <broadcastradio-utils-aidl/Utils.h> |
| 19 | |
| 20 | namespace aidl::android::hardware::broadcastradio { |
| 21 | |
| 22 | using ::aidl::android::hardware::broadcastradio::utils::makeSelectorAmfm; |
| 23 | using ::aidl::android::hardware::broadcastradio::utils::makeSelectorDab; |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 24 | using ::aidl::android::hardware::broadcastradio::utils::makeSelectorHd; |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 25 | using ::std::string; |
| 26 | using ::std::vector; |
| 27 | |
| 28 | VirtualRadio::VirtualRadio(const string& name, const vector<VirtualProgram>& initialList) |
| 29 | : mName(name), mPrograms(initialList) { |
| 30 | sort(mPrograms.begin(), mPrograms.end()); |
| 31 | } |
| 32 | |
| 33 | string VirtualRadio::getName() const { |
| 34 | return mName; |
| 35 | } |
| 36 | |
| 37 | const vector<VirtualProgram>& VirtualRadio::getProgramList() const { |
| 38 | return mPrograms; |
| 39 | } |
| 40 | |
| 41 | bool VirtualRadio::getProgram(const ProgramSelector& selector, VirtualProgram* programOut) const { |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 42 | for (auto it = mPrograms.begin(); it != mPrograms.end(); it++) { |
| 43 | if (!utils::tunesTo(selector, it->selector)) { |
| 44 | continue; |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 45 | } |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 46 | auto firstMatchIt = it; |
| 47 | if (utils::hasAmFmFrequency(it->selector)) { |
| 48 | uint32_t channelFreq = utils::getAmFmFrequency(it->selector); |
| 49 | it++; |
| 50 | while (it != mPrograms.end() && utils::hasAmFmFrequency(it->selector) && |
| 51 | utils::getAmFmFrequency(it->selector) == channelFreq) { |
| 52 | if (it->selector == selector) { |
| 53 | *programOut = *it; |
| 54 | return true; |
| 55 | } |
| 56 | it++; |
| 57 | } |
| 58 | } |
| 59 | *programOut = *firstMatchIt; |
| 60 | return true; |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | // get singleton of AMFM Virtual Radio |
| 66 | const VirtualRadio& VirtualRadio::getAmFmRadio() { |
| 67 | // clang-format off |
| 68 | static VirtualRadio amFmRadioMock( |
| 69 | "AM/FM radio mock", |
| 70 | { |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 71 | {makeSelectorAmfm(/* frequency= */ 94900u), "Wild 94.9", "Drake ft. Rihanna", |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 72 | "Too Good"}, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 73 | {makeSelectorAmfm(/* frequency= */ 96500u), "KOIT", "Celine Dion", "All By Myself"}, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 74 | {makeSelectorAmfm(/* frequency= */ 101300u), "101-3 KISS-FM", "Justin Timberlake", |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 75 | "Rock Your Body"}, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 76 | {makeSelectorAmfm(/* frequency= */ 103700u), "iHeart80s @ 103.7", "Michael Jackson", |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 77 | "Billie Jean"}, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 78 | {makeSelectorAmfm(/* frequency= */ 106100u), "106 KMEL", "Drake", "Marvins Room"}, |
Weilin Xu | 39dd0f8 | 2023-09-07 17:00:57 -0700 | [diff] [blame] | 79 | {makeSelectorAmfm(/* frequency= */ 560u), "Talk Radio 560 KSFO", "Artist560", "Title560"}, |
| 80 | {makeSelectorAmfm(/* frequency= */ 680u), "KNBR 680", "Artist680", "Title680"}, |
| 81 | {makeSelectorAmfm(/* frequency= */ 97300u), "Alice@97.3", "Drops of Jupiter", "Train"}, |
| 82 | {makeSelectorAmfm(/* frequency= */ 99700u), "99.7 Now!", "The Chainsmokers", "Closer"}, |
| 83 | {makeSelectorHd(/* stationId= */ 0xA0000001u, /* subChannel= */ 0u, /* frequency= */ 97700u), |
| 84 | "K-LOVE", "ArtistHd0", "TitleHd0"}, |
| 85 | {makeSelectorHd(/* stationId= */ 0xA0000001u, /* subChannel= */ 1u, /* frequency= */ 97700u), |
| 86 | "Air1", "ArtistHd1", "TitleHd1"}, |
| 87 | {makeSelectorHd(/* stationId= */ 0xA0000001u, /* subChannel= */ 2u, /* frequency= */ 97700u), |
| 88 | "K-LOVE Classics", "ArtistHd2", "TitleHd2"}, |
| 89 | {makeSelectorHd(/* stationId= */ 0xA0000001u, /* subChannel= */ 0u, /* frequency= */ 98500u), |
| 90 | "98.5-1 South Bay's Classic Rock", "ArtistHd0", "TitleHd0"}, |
| 91 | {makeSelectorHd(/* stationId= */ 0xA0000001u, /* subChannel= */ 1u, /* frequency= */ 98500u), |
| 92 | "Highway 1 - Different", "ArtistHd1", "TitleHd1"}, |
| 93 | {makeSelectorHd(/* stationId= */ 0xB0000001u, /* subChannel= */ 0u, /* frequency= */ 1170u), |
| 94 | "KLOK", "ArtistHd1", "TitleHd1"}, |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 95 | }); |
| 96 | // clang-format on |
| 97 | return amFmRadioMock; |
| 98 | } |
| 99 | |
| 100 | // get singleton of DAB Virtual Radio |
| 101 | const VirtualRadio& VirtualRadio::getDabRadio() { |
| 102 | // clang-format off |
| 103 | static VirtualRadio dabRadioMock( |
| 104 | "DAB radio mock", |
| 105 | { |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 106 | {makeSelectorDab(/* sidExt= */ 0xA000000001u, /* ensemble= */ 0x0001u, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 107 | /* freq= */ 225648u), "BBC Radio 1", "Khalid", "Talk"}, |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 108 | {makeSelectorDab(/* sidExt= */ 0xB000000001u, /* ensemble= */ 0x1001u, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 109 | /* freq= */ 222064u), "Classic FM", "Jean Sibelius", "Andante Festivo"}, |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 110 | {makeSelectorDab(/* sidExt= */ 0xB000000002u, /* ensemble= */ 0x1002u, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 111 | /* freq= */ 227360u), "Absolute Radio", "Coldplay", "Clocks"}, |
Weilin Xu | 0d4207d | 2022-12-09 00:37:44 +0000 | [diff] [blame] | 112 | {makeSelectorDab(/* sidExt= */ 0xB000000002u, /* ensemble= */ 0x1002u, |
Weilin Xu | 664048f | 2023-09-07 11:26:38 -0700 | [diff] [blame] | 113 | /* freq= */ 222064u), "Absolute Radio", "Coldplay", "Clocks"}, |
Weilin Xu | b2a6ca6 | 2022-05-08 23:47:04 +0000 | [diff] [blame] | 114 | }); |
| 115 | // clang-format on |
| 116 | return dabRadioMock; |
| 117 | } |
| 118 | |
| 119 | } // namespace aidl::android::hardware::broadcastradio |