policy.h revision 7c1ec5f038e63a5eb8b04434577c25bc23f5f410
1/*
2 * Copyright (C) 2015 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
17#pragma once
18
19#include <system/audio.h>
20
21// For mixed output and inputs, the policy will use max mixer sampling rates.
22// Do not limit sampling rate otherwise
23#define MAX_MIXER_SAMPLING_RATE 192000
24
25// For mixed output and inputs, the policy will use max mixer channel count.
26// Do not limit channel count otherwise
27#define MAX_MIXER_CHANNEL_COUNT 8
28
29/**
30 * A device mask for all audio input devices that are considered "virtual" when evaluating
31 * active inputs in getActiveInput()
32 */
33#define APM_AUDIO_IN_DEVICE_VIRTUAL_ALL  (AUDIO_DEVICE_IN_REMOTE_SUBMIX|AUDIO_DEVICE_IN_FM_TUNER)
34
35
36/**
37 * A device mask for all audio input and output devices where matching inputs/outputs on device
38 * type alone is not enough: the address must match too
39 */
40#define APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL (AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
41
42#define APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX)
43
44/**
45 * Check if the state given correspond to an in call state.
46 * @TODO find a better name for widely call state
47 *
48 * @param[in] state to consider
49 *
50 * @return true if given state represents a device in a telephony or VoIP call
51 */
52static inline bool is_state_in_call(int state)
53{
54    return (state == AUDIO_MODE_IN_CALL) || (state == AUDIO_MODE_IN_COMMUNICATION);
55}
56
57/**
58 * Check if the input device given is considered as a virtual device.
59 *
60 * @param[in] device to consider
61 *
62 * @return true if the device is a virtual one, false otherwise.
63 */
64static inline bool is_virtual_input_device(audio_devices_t device)
65{
66    if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
67        device &= ~AUDIO_DEVICE_BIT_IN;
68        if ((popcount(device) == 1) && ((device & ~APM_AUDIO_IN_DEVICE_VIRTUAL_ALL) == 0))
69            return true;
70    }
71    return false;
72}
73
74/**
75 * Check whether the device type is one
76 * where addresses are used to distinguish between one connected device and another
77 *
78 * @param[in] device to consider
79 *
80 * @return true if the device needs distinguish on address, false otherwise..
81 */
82static inline bool device_distinguishes_on_address(audio_devices_t device)
83{
84    return (((device & AUDIO_DEVICE_BIT_IN) != 0) &&
85            ((~AUDIO_DEVICE_BIT_IN & device & APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL) != 0)) ||
86           (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
87            ((device & APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL) != 0));
88}
89