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 #ifndef ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_1X_H
17 #define ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_1X_H
18 
19 #include <android/hardware/broadcastradio/1.1/types.h>
20 #include <chrono>
21 #include <queue>
22 #include <thread>
23 
24 namespace android {
25 namespace hardware {
26 namespace broadcastradio {
27 namespace utils {
28 
29 enum class HalRevision : uint32_t {
30     V1_0 = 1,
31     V1_1,
32 };
33 
34 /**
35  * Checks, if {@code pointer} tunes to {@channel}.
36  *
37  * For example, having a channel {AMFM_FREQUENCY = 103.3}:
38  * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 0} can tune to this channel;
39  * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 1} can't.
40  *
41  * @param pointer selector we're trying to match against channel.
42  * @param channel existing channel.
43  */
44 bool tunesTo(const V1_1::ProgramSelector& pointer, const V1_1::ProgramSelector& channel);
45 
46 V1_1::ProgramType getType(const V1_1::ProgramSelector& sel);
47 bool isAmFm(const V1_1::ProgramType type);
48 
49 bool isAm(const V1_0::Band band);
50 bool isFm(const V1_0::Band band);
51 
52 bool hasId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
53 
54 /**
55  * Returns ID (either primary or secondary) for a given program selector.
56  *
57  * If the selector does not contain given type, returns 0 and emits a warning.
58  */
59 uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
60 
61 /**
62  * Returns ID (either primary or secondary) for a given program selector.
63  *
64  * If the selector does not contain given type, returns default value.
65  */
66 uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type, uint64_t defval);
67 
68 V1_1::ProgramSelector make_selector(V1_0::Band band, uint32_t channel, uint32_t subChannel = 0);
69 
70 bool getLegacyChannel(const V1_1::ProgramSelector& sel, uint32_t* channelOut,
71                       uint32_t* subChannelOut);
72 
73 bool isDigital(const V1_1::ProgramSelector& sel);
74 
75 }  // namespace utils
76 
77 namespace V1_0 {
78 
79 bool operator==(const BandConfig& l, const BandConfig& r);
80 
81 }  // namespace V1_0
82 
83 }  // namespace broadcastradio
84 }  // namespace hardware
85 }  // namespace android
86 
87 #endif  // ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_1X_H
88