diff options
Diffstat (limited to 'broadcastradio/1.2/default/VirtualProgram.cpp')
-rw-r--r-- | broadcastradio/1.2/default/VirtualProgram.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/broadcastradio/1.2/default/VirtualProgram.cpp b/broadcastradio/1.2/default/VirtualProgram.cpp new file mode 100644 index 00000000..95879e34 --- /dev/null +++ b/broadcastradio/1.2/default/VirtualProgram.cpp | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
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 | |||
18 | #include <broadcastradio-utils/Utils.h> | ||
19 | |||
20 | #include "resources.h" | ||
21 | |||
22 | namespace android { | ||
23 | namespace hardware { | ||
24 | namespace broadcastradio { | ||
25 | namespace V1_2 { | ||
26 | namespace implementation { | ||
27 | |||
28 | using std::vector; | ||
29 | |||
30 | using V1_0::MetaData; | ||
31 | using V1_0::MetadataKey; | ||
32 | using V1_0::MetadataType; | ||
33 | using V1_1::IdentifierType; | ||
34 | using V1_1::ProgramInfo; | ||
35 | using V1_1::VendorKeyValue; | ||
36 | using utils::HalRevision; | ||
37 | |||
38 | static MetaData createDemoBitmap(MetadataKey key, HalRevision halRev) { | ||
39 | MetaData bmp = {MetadataType::INT, key, resources::demoPngId, {}, {}, {}}; | ||
40 | if (halRev < HalRevision::V1_1) { | ||
41 | bmp.type = MetadataType::RAW; | ||
42 | bmp.intValue = 0; | ||
43 | bmp.rawValue = hidl_vec<uint8_t>(resources::demoPng, std::end(resources::demoPng)); | ||
44 | } | ||
45 | return bmp; | ||
46 | } | ||
47 | |||
48 | ProgramInfo VirtualProgram::getProgramInfo(HalRevision halRev) const { | ||
49 | ProgramInfo info11 = {}; | ||
50 | auto& info10 = info11.base; | ||
51 | |||
52 | utils::getLegacyChannel(selector, &info10.channel, &info10.subChannel); | ||
53 | info11.selector = selector; | ||
54 | info10.tuned = true; | ||
55 | info10.stereo = true; | ||
56 | info10.digital = utils::isDigital(selector); | ||
57 | info10.signalStrength = info10.digital ? 100 : 80; | ||
58 | |||
59 | info10.metadata = hidl_vec<MetaData>({ | ||
60 | {MetadataType::TEXT, MetadataKey::RDS_PS, {}, {}, programName, {}}, | ||
61 | {MetadataType::TEXT, MetadataKey::TITLE, {}, {}, songTitle, {}}, | ||
62 | {MetadataType::TEXT, MetadataKey::ARTIST, {}, {}, songArtist, {}}, | ||
63 | createDemoBitmap(MetadataKey::ICON, halRev), | ||
64 | createDemoBitmap(MetadataKey::ART, halRev), | ||
65 | }); | ||
66 | |||
67 | info11.vendorInfo = hidl_vec<VendorKeyValue>({ | ||
68 | {"com.google.dummy", "dummy"}, | ||
69 | {"com.google.dummy.VirtualProgram", std::to_string(reinterpret_cast<uintptr_t>(this))}, | ||
70 | }); | ||
71 | |||
72 | return info11; | ||
73 | } | ||
74 | |||
75 | // Defining order on virtual programs, how they appear on band. | ||
76 | // It's mostly for default implementation purposes, may not be complete or correct. | ||
77 | bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) { | ||
78 | auto& l = lhs.selector; | ||
79 | auto& r = rhs.selector; | ||
80 | |||
81 | // Two programs with the same primaryId is considered the same. | ||
82 | if (l.programType != r.programType) return l.programType < r.programType; | ||
83 | if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type; | ||
84 | if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value; | ||
85 | |||
86 | // A little exception for HD Radio subchannel - we check secondary ID too. | ||
87 | if (utils::hasId(l, IdentifierType::HD_SUBCHANNEL) && | ||
88 | utils::hasId(r, IdentifierType::HD_SUBCHANNEL)) { | ||
89 | return utils::getId(l, IdentifierType::HD_SUBCHANNEL) < | ||
90 | utils::getId(r, IdentifierType::HD_SUBCHANNEL); | ||
91 | } | ||
92 | |||
93 | return false; | ||
94 | } | ||
95 | |||
96 | vector<ProgramInfo> getProgramInfoVector(const vector<VirtualProgram>& vec, HalRevision halRev) { | ||
97 | vector<ProgramInfo> out; | ||
98 | out.reserve(vec.size()); | ||
99 | for (auto&& program : vec) { | ||
100 | out.push_back(program.getProgramInfo(halRev)); | ||
101 | } | ||
102 | return out; | ||
103 | } | ||
104 | |||
105 | } // namespace implementation | ||
106 | } // namespace V1_2 | ||
107 | } // namespace broadcastradio | ||
108 | } // namespace hardware | ||
109 | } // namespace android | ||