blob: d47746d7c8d8fd784b3ddfc0234eb44d92ef644d [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 Wasilczyk06100b32017-12-04 09:53:32 -080016#ifndef ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_1X_H
17#define ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_1X_H
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070018
Tomasz Wasilczyk8c34c812018-02-08 13:42:31 -080019#include <android/hardware/broadcastradio/1.1/types.h>
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070020#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,
32};
33
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070034/**
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 */
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070044bool tunesTo(const V1_1::ProgramSelector& pointer, const V1_1::ProgramSelector& channel);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070045
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070046V1_1::ProgramType getType(const V1_1::ProgramSelector& sel);
47bool isAmFm(const V1_1::ProgramType type);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070048
Tomasz Wasilczyk701a5bd2017-08-10 12:32:45 -070049bool isAm(const V1_0::Band band);
50bool isFm(const V1_0::Band band);
51
Tomasz Wasilczyk8c34c812018-02-08 13:42:31 -080052bool hasId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070053
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 */
Tomasz Wasilczyk8c34c812018-02-08 13:42:31 -080059uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070060
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 */
Tomasz Wasilczyk8c34c812018-02-08 13:42:31 -080066uint64_t getId(const V1_1::ProgramSelector& sel, const V1_1::IdentifierType type, uint64_t defval);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070067
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070068V1_1::ProgramSelector make_selector(V1_0::Band band, uint32_t channel, uint32_t subChannel = 0);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070069
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080070bool getLegacyChannel(const V1_1::ProgramSelector& sel, uint32_t* channelOut,
71 uint32_t* subChannelOut);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070072
Tomasz Wasilczykf679e8b2017-09-14 09:43:35 -070073bool isDigital(const V1_1::ProgramSelector& sel);
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070074
75} // namespace utils
Tomasz Wasilczykc1763a62017-07-25 10:01:17 -070076
77namespace V1_0 {
78
79bool operator==(const BandConfig& l, const BandConfig& r);
80
81} // namespace V1_0
82
Tomasz Wasilczyka02b6ef2017-07-05 11:23:30 -070083} // namespace broadcastradio
84} // namespace hardware
85} // namespace android
86
Tomasz Wasilczyk06100b32017-12-04 09:53:32 -080087#endif // ANDROID_HARDWARE_BROADCASTRADIO_COMMON_UTILS_1X_H