2017-06-22 19:45:33 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-07-28 19:08:46 +02:00
|
|
|
#define LOG_TAG "BroadcastRadioDefault.VirtualRadio"
|
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
|
2017-06-22 19:45:33 +02:00
|
|
|
#include "VirtualRadio.h"
|
|
|
|
|
2017-07-25 19:01:17 +02:00
|
|
|
#include <broadcastradio-utils/Utils.h>
|
2017-07-28 19:08:46 +02:00
|
|
|
#include <log/log.h>
|
2017-07-05 20:23:30 +02:00
|
|
|
|
2017-06-22 19:45:33 +02:00
|
|
|
namespace android {
|
|
|
|
namespace hardware {
|
|
|
|
namespace broadcastradio {
|
|
|
|
namespace V1_1 {
|
|
|
|
namespace implementation {
|
|
|
|
|
2017-07-05 20:23:30 +02:00
|
|
|
using V1_0::Band;
|
2017-07-28 19:08:46 +02:00
|
|
|
using V1_0::Class;
|
2017-07-05 20:23:30 +02:00
|
|
|
|
2017-06-22 19:45:33 +02:00
|
|
|
using std::lock_guard;
|
|
|
|
using std::move;
|
|
|
|
using std::mutex;
|
|
|
|
using std::vector;
|
|
|
|
|
2017-07-05 20:23:30 +02:00
|
|
|
using utils::make_selector;
|
|
|
|
|
2017-07-28 19:08:46 +02:00
|
|
|
static const vector<VirtualProgram> gInitialFmPrograms{
|
2017-07-05 20:23:30 +02:00
|
|
|
{make_selector(Band::FM, 94900), "Wild 94.9", "Drake ft. Rihanna", "Too Good"},
|
|
|
|
{make_selector(Band::FM, 96500), "KOIT", "Celine Dion", "All By Myself"},
|
|
|
|
{make_selector(Band::FM, 97300), "Alice@97.3", "Drops of Jupiter", "Train"},
|
|
|
|
{make_selector(Band::FM, 99700), "99.7 Now!", "The Chainsmokers", "Closer"},
|
|
|
|
{make_selector(Band::FM, 101300), "101-3 KISS-FM", "Justin Timberlake", "Rock Your Body"},
|
|
|
|
{make_selector(Band::FM, 103700), "iHeart80s @ 103.7", "Michael Jackson", "Billie Jean"},
|
|
|
|
{make_selector(Band::FM, 106100), "106 KMEL", "Drake", "Marvins Room"},
|
2017-06-22 19:45:33 +02:00
|
|
|
};
|
|
|
|
|
2017-07-28 19:08:46 +02:00
|
|
|
static VirtualRadio gEmptyRadio({});
|
|
|
|
static VirtualRadio gFmRadio(gInitialFmPrograms);
|
2017-06-22 19:45:33 +02:00
|
|
|
|
2017-07-17 22:59:21 +02:00
|
|
|
VirtualRadio::VirtualRadio(const vector<VirtualProgram> initialList) : mPrograms(initialList) {}
|
2017-06-22 19:45:33 +02:00
|
|
|
|
|
|
|
vector<VirtualProgram> VirtualRadio::getProgramList() {
|
|
|
|
lock_guard<mutex> lk(mMut);
|
|
|
|
return mPrograms;
|
|
|
|
}
|
|
|
|
|
2017-07-05 20:23:30 +02:00
|
|
|
bool VirtualRadio::getProgram(const ProgramSelector& selector, VirtualProgram& programOut) {
|
2017-06-22 19:45:33 +02:00
|
|
|
lock_guard<mutex> lk(mMut);
|
|
|
|
for (auto&& program : mPrograms) {
|
2017-07-05 20:23:30 +02:00
|
|
|
if (utils::tunesTo(selector, program.selector)) {
|
2017-06-22 19:45:33 +02:00
|
|
|
programOut = program;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-28 19:08:46 +02:00
|
|
|
VirtualRadio& getRadio(V1_0::Class classId) {
|
|
|
|
switch (classId) {
|
|
|
|
case Class::AM_FM:
|
|
|
|
return getFmRadio();
|
|
|
|
case Class::SAT:
|
|
|
|
return getSatRadio();
|
|
|
|
case Class::DT:
|
|
|
|
return getDigitalRadio();
|
|
|
|
default:
|
|
|
|
ALOGE("Invalid class ID");
|
|
|
|
return gEmptyRadio;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VirtualRadio& getAmRadio() {
|
|
|
|
return gEmptyRadio;
|
|
|
|
}
|
|
|
|
|
|
|
|
VirtualRadio& getFmRadio() {
|
|
|
|
return gFmRadio;
|
|
|
|
}
|
|
|
|
|
|
|
|
VirtualRadio& getSatRadio() {
|
|
|
|
return gEmptyRadio;
|
|
|
|
}
|
|
|
|
|
|
|
|
VirtualRadio& getDigitalRadio() {
|
|
|
|
return gEmptyRadio;
|
2017-06-22 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace implementation
|
|
|
|
} // namespace V1_1
|
|
|
|
} // namespace broadcastradio
|
|
|
|
} // namespace hardware
|
|
|
|
} // namespace android
|