blob: ef8bd1c43d3f99329ba16e39ca74ee9a3d66a833 [file] [log] [blame]
Tomasz Wasilczyk48377552017-06-22 10:45:33 -07001/*
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 */
16#include "VirtualProgram.h"
17
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070018#include <Utils.h>
19
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070020namespace android {
21namespace hardware {
22namespace broadcastradio {
23namespace V1_1 {
24namespace implementation {
25
Tomasz Wasilczyk100f2ed2017-06-29 16:04:05 -070026using V1_0::MetaData;
27using V1_0::MetadataKey;
28using V1_0::MetadataType;
29
30VirtualProgram::operator ProgramInfo() const {
31 ProgramInfo info11 = {};
32 auto& info10 = info11.base;
33
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070034 utils::getLegacyChannel(selector, info10.channel, info10.subChannel);
35 info11.selector = selector;
Tomasz Wasilczyk100f2ed2017-06-29 16:04:05 -070036 info10.tuned = true;
37 info10.stereo = true;
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070038 info10.digital = utils::isDigital(selector);
39 info10.signalStrength = info10.digital ? 100 : 80;
Tomasz Wasilczyk100f2ed2017-06-29 16:04:05 -070040
41 info10.metadata = hidl_vec<MetaData>({
42 {MetadataType::TEXT, MetadataKey::RDS_PS, {}, {}, programName, {}},
43 {MetadataType::TEXT, MetadataKey::TITLE, {}, {}, songTitle, {}},
44 {MetadataType::TEXT, MetadataKey::ARTIST, {}, {}, songArtist, {}},
45 });
46
47 return info11;
48}
49
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070050// Defining order on virtual programs, how they appear on band.
51// It's mostly for default implementation purposes, may not be complete or correct.
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070052bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) {
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070053 auto& l = lhs.selector;
54 auto& r = rhs.selector;
55
56 // Two programs with the same primaryId is considered the same.
57 if (l.programType != r.programType) return l.programType < r.programType;
58 if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type;
59 if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value;
60
61 // A little exception for HD Radio subchannel - we check secondary ID too.
62 if (utils::hasId(l, IdentifierType::HD_SUBCHANNEL) &&
63 utils::hasId(r, IdentifierType::HD_SUBCHANNEL)) {
64 return utils::getId(l, IdentifierType::HD_SUBCHANNEL) <
65 utils::getId(r, IdentifierType::HD_SUBCHANNEL);
66 }
67
68 return false;
Tomasz Wasilczyk48377552017-06-22 10:45:33 -070069}
70
71} // namespace implementation
72} // namespace V1_1
73} // namespace broadcastradio
74} // namespace hardware
75} // namespace android