Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 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 | |
Tomasz Wasilczyk | c1763a6 | 2017-07-25 10:01:17 -0700 | [diff] [blame] | 18 | #include <broadcastradio-utils/Utils.h> |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 19 | |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 20 | #include "resources.h" |
| 21 | |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 22 | namespace android { |
| 23 | namespace hardware { |
| 24 | namespace broadcastradio { |
| 25 | namespace V1_1 { |
| 26 | namespace implementation { |
| 27 | |
Tomasz Wasilczyk | 100f2ed | 2017-06-29 16:04:05 -0700 | [diff] [blame] | 28 | using V1_0::MetaData; |
| 29 | using V1_0::MetadataKey; |
| 30 | using V1_0::MetadataType; |
| 31 | |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 32 | // TODO (b/36864090): inject this data in a more elegant way |
| 33 | static int gHalVersion = 2; // 1 = 1.0, 2 = 1.1 |
| 34 | |
| 35 | void setCompatibilityLevel(int halversion) { |
| 36 | gHalVersion = halversion; |
| 37 | } |
| 38 | |
| 39 | static MetaData createDemoBitmap(MetadataKey key) { |
| 40 | MetaData bmp = {MetadataType::INT, key, resources::demoPngId, {}, {}, {}}; |
| 41 | if (gHalVersion < 2) { |
| 42 | bmp.type = MetadataType::RAW; |
| 43 | bmp.intValue = 0; |
| 44 | bmp.rawValue = std::vector<uint8_t>(resources::demoPng, std::end(resources::demoPng)); |
| 45 | } |
| 46 | return bmp; |
| 47 | } |
| 48 | |
Tomasz Wasilczyk | 100f2ed | 2017-06-29 16:04:05 -0700 | [diff] [blame] | 49 | VirtualProgram::operator ProgramInfo() const { |
| 50 | ProgramInfo info11 = {}; |
| 51 | auto& info10 = info11.base; |
| 52 | |
Tomasz Wasilczyk | 2834b95 | 2017-07-12 14:17:09 -0700 | [diff] [blame] | 53 | utils::getLegacyChannel(selector, &info10.channel, &info10.subChannel); |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 54 | info11.selector = selector; |
Tomasz Wasilczyk | 100f2ed | 2017-06-29 16:04:05 -0700 | [diff] [blame] | 55 | info10.tuned = true; |
| 56 | info10.stereo = true; |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 57 | info10.digital = utils::isDigital(selector); |
| 58 | info10.signalStrength = info10.digital ? 100 : 80; |
Tomasz Wasilczyk | 100f2ed | 2017-06-29 16:04:05 -0700 | [diff] [blame] | 59 | |
| 60 | info10.metadata = hidl_vec<MetaData>({ |
| 61 | {MetadataType::TEXT, MetadataKey::RDS_PS, {}, {}, programName, {}}, |
| 62 | {MetadataType::TEXT, MetadataKey::TITLE, {}, {}, songTitle, {}}, |
| 63 | {MetadataType::TEXT, MetadataKey::ARTIST, {}, {}, songArtist, {}}, |
Tomasz Wasilczyk | ba3e254 | 2017-07-17 13:59:21 -0700 | [diff] [blame] | 64 | createDemoBitmap(MetadataKey::ICON), |
| 65 | createDemoBitmap(MetadataKey::ART), |
Tomasz Wasilczyk | 100f2ed | 2017-06-29 16:04:05 -0700 | [diff] [blame] | 66 | }); |
| 67 | |
| 68 | return info11; |
| 69 | } |
| 70 | |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 71 | // Defining order on virtual programs, how they appear on band. |
| 72 | // It's mostly for default implementation purposes, may not be complete or correct. |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 73 | bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) { |
Tomasz Wasilczyk | a02b6ef | 2017-07-05 11:23:30 -0700 | [diff] [blame] | 74 | auto& l = lhs.selector; |
| 75 | auto& r = rhs.selector; |
| 76 | |
| 77 | // Two programs with the same primaryId is considered the same. |
| 78 | if (l.programType != r.programType) return l.programType < r.programType; |
| 79 | if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type; |
| 80 | if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value; |
| 81 | |
| 82 | // A little exception for HD Radio subchannel - we check secondary ID too. |
| 83 | if (utils::hasId(l, IdentifierType::HD_SUBCHANNEL) && |
| 84 | utils::hasId(r, IdentifierType::HD_SUBCHANNEL)) { |
| 85 | return utils::getId(l, IdentifierType::HD_SUBCHANNEL) < |
| 86 | utils::getId(r, IdentifierType::HD_SUBCHANNEL); |
| 87 | } |
| 88 | |
| 89 | return false; |
Tomasz Wasilczyk | 4837755 | 2017-06-22 10:45:33 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | } // namespace implementation |
| 93 | } // namespace V1_1 |
| 94 | } // namespace broadcastradio |
| 95 | } // namespace hardware |
| 96 | } // namespace android |