blob: 1a1cbb2580423410967c9dded01565114542c9a6 [file] [log] [blame]
François Gaffie53615e22015-03-19 09:24:12 +01001/*
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
François Gaffie5fcd6f92015-11-27 13:46:12 +010021static const uint32_t gDynamicRate = 0;
22static const audio_format_t gDynamicFormat = AUDIO_FORMAT_DEFAULT;
23static const audio_channel_mask_t gDynamicChannelMask = AUDIO_CHANNEL_NONE;
24
François Gaffie53615e22015-03-19 09:24:12 +010025// For mixed output and inputs, the policy will use max mixer sampling rates.
26// Do not limit sampling rate otherwise
Andy Hungdb4c0312015-05-06 08:46:52 -070027#define MAX_MIXER_SAMPLING_RATE 192000
François Gaffie53615e22015-03-19 09:24:12 +010028
29// For mixed output and inputs, the policy will use max mixer channel count.
30// Do not limit channel count otherwise
31#define MAX_MIXER_CHANNEL_COUNT 8
32
33/**
34 * A device mask for all audio input devices that are considered "virtual" when evaluating
35 * active inputs in getActiveInput()
36 */
37#define APM_AUDIO_IN_DEVICE_VIRTUAL_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX|AUDIO_DEVICE_IN_FM_TUNER)
38
39
40/**
41 * A device mask for all audio input and output devices where matching inputs/outputs on device
42 * type alone is not enough: the address must match too
43 */
Eric Laurent7c1ec5f2015-07-09 14:52:47 -070044#define APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL (AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
45
46#define APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX)
François Gaffie53615e22015-03-19 09:24:12 +010047
48/**
49 * Check if the state given correspond to an in call state.
50 * @TODO find a better name for widely call state
51 *
52 * @param[in] state to consider
53 *
54 * @return true if given state represents a device in a telephony or VoIP call
55 */
56static inline bool is_state_in_call(int state)
57{
58 return (state == AUDIO_MODE_IN_CALL) || (state == AUDIO_MODE_IN_COMMUNICATION);
59}
60
61/**
62 * Check if the input device given is considered as a virtual device.
63 *
64 * @param[in] device to consider
65 *
66 * @return true if the device is a virtual one, false otherwise.
67 */
Chih-Hung Hsieh5603d282015-05-04 17:14:15 -070068static inline bool is_virtual_input_device(audio_devices_t device)
François Gaffie53615e22015-03-19 09:24:12 +010069{
70 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
71 device &= ~AUDIO_DEVICE_BIT_IN;
72 if ((popcount(device) == 1) && ((device & ~APM_AUDIO_IN_DEVICE_VIRTUAL_ALL) == 0))
73 return true;
74 }
75 return false;
76}
77
78/**
79 * Check whether the device type is one
80 * where addresses are used to distinguish between one connected device and another
81 *
82 * @param[in] device to consider
83 *
84 * @return true if the device needs distinguish on address, false otherwise..
85 */
Chih-Hung Hsieh5603d282015-05-04 17:14:15 -070086static inline bool device_distinguishes_on_address(audio_devices_t device)
François Gaffie53615e22015-03-19 09:24:12 +010087{
Eric Laurent7c1ec5f2015-07-09 14:52:47 -070088 return (((device & AUDIO_DEVICE_BIT_IN) != 0) &&
89 ((~AUDIO_DEVICE_BIT_IN & device & APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL) != 0)) ||
90 (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
91 ((device & APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL) != 0));
François Gaffie53615e22015-03-19 09:24:12 +010092}