blob: b07ce79be2725dab3fbdfd11cab055add4b7851b [file] [log] [blame]
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -07001/*
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 Wasilczykf679e8b2017-09-14 09:43:35 -070016#ifndef ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_H
17#define ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_H
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070018
19#include <android/hardware/broadcastradio/1.1/types.h>
20#include <chrono>
21#include <queue>
22#include <thread>
23
24namespace android {
25namespace hardware {
26namespace broadcastradio {
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070027namespace utils {
28
Tomasz Wasilczyk5be4c2b2017-07-27 13:17:07 -070029enum class HalRevision : uint32_t {
30 V1_0 = 1,
31 V1_1,
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070032 V1_2,
Tomasz Wasilczyk5be4c2b2017-07-27 13:17:07 -070033};
34
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070035/**
36 * Checks, if {@code pointer} tunes to {@channel}.
37 *
38 * For example, having a channel {AMFM_FREQUENCY = 103.3}:
39 * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 0} can tune to this channel;
40 * - selector {AMFM_FREQUENCY = 103.3, HD_SUBCHANNEL = 1} can't.
41 *
42 * @param pointer selector we're trying to match against channel.
43 * @param channel existing channel.
44 */
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070045bool tunesTo(const V1_1::ProgramSelector& pointer, const V1_1::ProgramSelector& channel);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070046
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070047V1_1::ProgramType getType(const V1_1::ProgramSelector& sel);
48bool isAmFm(const V1_1::ProgramType type);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070049
Tomasz Wasilczyk701a5bd2017-08-10 12:32:45 -070050bool isAm(const V1_0::Band band);
51bool isFm(const V1_0::Band band);
52
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070053bool hasId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070054
55/**
56 * Returns ID (either primary or secondary) for a given program selector.
57 *
58 * If the selector does not contain given type, returns 0 and emits a warning.
59 */
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070060uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070061
62/**
63 * Returns ID (either primary or secondary) for a given program selector.
64 *
65 * If the selector does not contain given type, returns default value.
66 */
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070067uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type, uint64_t defval);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070068
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070069V1_1::ProgramSelector make_selector(V1_0::Band band, uint32_t channel, uint32_t subChannel = 0);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070070
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070071bool getLegacyChannel(const V1_1::ProgramSelector& sel,
72 uint32_t* channelOut, uint32_t* subChannelOut);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070073
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070074bool isDigital(const V1_1::ProgramSelector& sel);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070075
76} // namespace utils
Tomasz Wasilczykc1763a62017-07-25 10:01:17 -070077
78namespace V1_0 {
79
80bool operator==(const BandConfig& l, const BandConfig& r);
81
82} // namespace V1_0
83
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070084} // namespace broadcastradio
85} // namespace hardware
86} // namespace android
87
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070088#endif // ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_H