summaryrefslogtreecommitdiffstats
blob: b07ce79be2725dab3fbdfd11cab055add4b7851b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_H
#define ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_H

#include <android/hardware/broadcastradio/1.1/types.h>
#include <chrono>
#include <queue>
#include <thread>

namespace android {
namespace hardware {
namespace broadcastradio {
namespace utils {

enum class HalRevision : uint32_t {
    V1_0 = 1,
    V1_1,
    V1_2,
};

/**
 * Checks, if {@code pointer} tunes to {@channel}.
 *
 * For example, having a channel {AMFM_FREQUENCY = 103.3}:
 * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 0} can tune to this channel;
 * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 1} can't.
 *
 * @param pointer selector we're trying to match against channel.
 * @param channel existing channel.
 */
bool tunesTo(const V1_1::ProgramSelector& pointer, const V1_1::ProgramSelector& channel);

V1_1::ProgramType getType(const V1_1::ProgramSelector& sel);
bool isAmFm(const V1_1::ProgramType type);

bool isAm(const V1_0::Band band);
bool isFm(const V1_0::Band band);

bool hasId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);

/**
 * Returns ID (either primary or secondary) for a given program selector.
 *
 * If the selector does not contain given type, returns 0 and emits a warning.
 */
uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);

/**
 * Returns ID (either primary or secondary) for a given program selector.
 *
 * If the selector does not contain given type, returns default value.
 */
uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type, uint64_t defval);

V1_1::ProgramSelector make_selector(V1_0::Band band, uint32_t channel, uint32_t subChannel = 0);

bool getLegacyChannel(const V1_1::ProgramSelector& sel,
        uint32_t* channelOut, uint32_t* subChannelOut);

bool isDigital(const V1_1::ProgramSelector& sel);

}  // namespace utils

namespace V1_0 {

bool operator==(const BandConfig& l, const BandConfig& r);

}  // namespace V1_0

}  // namespace broadcastradio
}  // namespace hardware
}  // namespace android

#endif  // ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_H