blob: acde704f9ba852760b5d41d845f85fe922569e5c [file] [log] [blame]
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -08001/*
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 */
Tomasz Wasilczyk4ce63822017-12-21 14:25:54 -080016#define LOG_TAG "BcRadioDef.VirtualProgram"
17
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080018#include "VirtualProgram.h"
19
20#include "resources.h"
21
Tomasz Wasilczyk4ce63822017-12-21 14:25:54 -080022#include <android-base/logging.h>
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080023#include <broadcastradio-utils-2x/Utils.h>
Tomasz Wasilczyk4ce63822017-12-21 14:25:54 -080024#include <log/log.h>
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080025
26namespace android {
27namespace hardware {
28namespace broadcastradio {
29namespace V2_0 {
30namespace implementation {
31
32using utils::getType;
33using utils::make_metadata;
34
35using std::vector;
36
37VirtualProgram::operator ProgramInfo() const {
38 ProgramInfo info = {};
39
40 info.selector = selector;
41
42 auto pType = getType(selector.primaryId);
43 auto isDigital = (pType != IdentifierType::AMFM_FREQUENCY && pType != IdentifierType::RDS_PI);
44
Tomasz Wasilczyk4ce63822017-12-21 14:25:54 -080045 auto selectId = [&info](IdentifierType type) {
46 return utils::make_identifier(type, utils::getId(info.selector, type));
47 };
48
49 switch (pType) {
50 case IdentifierType::AMFM_FREQUENCY:
51 info.logicallyTunedTo = info.physicallyTunedTo =
52 selectId(IdentifierType::AMFM_FREQUENCY);
53 break;
54 case IdentifierType::RDS_PI:
55 info.logicallyTunedTo = selectId(IdentifierType::RDS_PI);
56 info.physicallyTunedTo = selectId(IdentifierType::AMFM_FREQUENCY);
57 break;
58 case IdentifierType::HD_STATION_ID_EXT:
59 info.logicallyTunedTo = selectId(IdentifierType::HD_STATION_ID_EXT);
60 info.physicallyTunedTo = selectId(IdentifierType::AMFM_FREQUENCY);
61 break;
62 case IdentifierType::DAB_SID_EXT:
63 info.logicallyTunedTo = selectId(IdentifierType::DAB_SID_EXT);
64 info.physicallyTunedTo = selectId(IdentifierType::DAB_ENSEMBLE);
65 break;
66 case IdentifierType::DRMO_SERVICE_ID:
67 info.logicallyTunedTo = selectId(IdentifierType::DRMO_SERVICE_ID);
68 info.physicallyTunedTo = selectId(IdentifierType::DRMO_FREQUENCY);
69 break;
70 case IdentifierType::SXM_SERVICE_ID:
71 info.logicallyTunedTo = selectId(IdentifierType::SXM_SERVICE_ID);
72 info.physicallyTunedTo = selectId(IdentifierType::SXM_CHANNEL);
73 break;
74 default:
75 LOG(FATAL) << "Unsupported program type: " << toString(pType);
76 }
77
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080078 info.infoFlags |= ProgramInfoFlags::TUNED;
79 info.infoFlags |= ProgramInfoFlags::STEREO;
80 info.signalQuality = isDigital ? 100 : 80;
81
82 info.metadata = hidl_vec<Metadata>({
83 make_metadata(MetadataKey::RDS_PS, programName),
84 make_metadata(MetadataKey::SONG_TITLE, songTitle),
85 make_metadata(MetadataKey::SONG_ARTIST, songArtist),
86 make_metadata(MetadataKey::STATION_ICON, resources::demoPngId),
87 make_metadata(MetadataKey::ALBUM_ART, resources::demoPngId),
88 });
89
90 info.vendorInfo = hidl_vec<VendorKeyValue>({
91 {"com.google.dummy", "dummy"},
92 {"com.google.dummy.VirtualProgram", std::to_string(reinterpret_cast<uintptr_t>(this))},
93 });
94
95 return info;
96}
97
98bool operator<(const VirtualProgram& lhs, const VirtualProgram& rhs) {
99 auto& l = lhs.selector;
100 auto& r = rhs.selector;
101
102 // Two programs with the same primaryId are considered the same.
103 if (l.primaryId.type != r.primaryId.type) return l.primaryId.type < r.primaryId.type;
104 if (l.primaryId.value != r.primaryId.value) return l.primaryId.value < r.primaryId.value;
105
106 return false;
107}
108
109} // namespace implementation
110} // namespace V2_0
111} // namespace broadcastradio
112} // namespace hardware
113} // namespace android