blob: e3ee4e54dbc517fad7d59b296d6ed6ad23e7d34a [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 audio_format_t gDynamicFormat = AUDIO_FORMAT_DEFAULT;
François Gaffie5fcd6f92015-11-27 13:46:12 +010022
François Gaffie53615e22015-03-19 09:24:12 +010023// For mixed output and inputs, the policy will use max mixer sampling rates.
24// Do not limit sampling rate otherwise
Andy Hungdb4c0312015-05-06 08:46:52 -070025#define MAX_MIXER_SAMPLING_RATE 192000
François Gaffie53615e22015-03-19 09:24:12 +010026
27// For mixed output and inputs, the policy will use max mixer channel count.
28// Do not limit channel count otherwise
29#define MAX_MIXER_CHANNEL_COUNT 8
30
31/**
32 * A device mask for all audio input devices that are considered "virtual" when evaluating
Eric Laurentfb66dd92016-01-28 18:32:03 -080033 * active inputs in getActiveInputs()
François Gaffie53615e22015-03-19 09:24:12 +010034 */
Eric Laurentfb66dd92016-01-28 18:32:03 -080035#define APM_AUDIO_IN_DEVICE_VIRTUAL_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX)
François Gaffie53615e22015-03-19 09:24:12 +010036
37
38/**
39 * A device mask for all audio input and output devices where matching inputs/outputs on device
40 * type alone is not enough: the address must match too
41 */
Eric Laurent7c1ec5f2015-07-09 14:52:47 -070042#define APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL (AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
43
44#define APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX)
François Gaffie53615e22015-03-19 09:24:12 +010045
46/**
47 * Check if the state given correspond to an in call state.
48 * @TODO find a better name for widely call state
49 *
50 * @param[in] state to consider
51 *
52 * @return true if given state represents a device in a telephony or VoIP call
53 */
54static inline bool is_state_in_call(int state)
55{
56 return (state == AUDIO_MODE_IN_CALL) || (state == AUDIO_MODE_IN_COMMUNICATION);
57}
58
59/**
60 * Check if the input device given is considered as a virtual device.
61 *
62 * @param[in] device to consider
63 *
64 * @return true if the device is a virtual one, false otherwise.
65 */
Chih-Hung Hsieh5603d282015-05-04 17:14:15 -070066static inline bool is_virtual_input_device(audio_devices_t device)
François Gaffie53615e22015-03-19 09:24:12 +010067{
68 if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
69 device &= ~AUDIO_DEVICE_BIT_IN;
70 if ((popcount(device) == 1) && ((device & ~APM_AUDIO_IN_DEVICE_VIRTUAL_ALL) == 0))
71 return true;
72 }
73 return false;
74}
75
76/**
77 * Check whether the device type is one
78 * where addresses are used to distinguish between one connected device and another
79 *
80 * @param[in] device to consider
81 *
82 * @return true if the device needs distinguish on address, false otherwise..
83 */
Chih-Hung Hsieh5603d282015-05-04 17:14:15 -070084static inline bool device_distinguishes_on_address(audio_devices_t device)
François Gaffie53615e22015-03-19 09:24:12 +010085{
Eric Laurent7c1ec5f2015-07-09 14:52:47 -070086 return (((device & AUDIO_DEVICE_BIT_IN) != 0) &&
87 ((~AUDIO_DEVICE_BIT_IN & device & APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL) != 0)) ||
88 (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
89 ((device & APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL) != 0));
François Gaffie53615e22015-03-19 09:24:12 +010090}
Eric Laurentfb66dd92016-01-28 18:32:03 -080091
92/**
93 * Returns the priority of a given audio source for capture. The priority is used when more than one
94 * capture session is active on a given input stream to determine which session drives routing and
95 * effect configuration.
96 *
97 * @param[in] inputSource to consider. Valid sources are:
98 * - AUDIO_SOURCE_VOICE_COMMUNICATION
99 * - AUDIO_SOURCE_CAMCORDER
100 * - AUDIO_SOURCE_MIC
101 * - AUDIO_SOURCE_FM_TUNER
102 * - AUDIO_SOURCE_VOICE_RECOGNITION
103 * - AUDIO_SOURCE_HOTWORD
104 *
105 * @return the corresponding input source priority or 0 if priority is irrelevant for this source.
106 * This happens when the specified source cannot share a given input stream (e.g remote submix)
107 * The higher the value, the higher the priority.
108 */
109static inline int32_t source_priority(audio_source_t inputSource)
110{
111 switch (inputSource) {
112 case AUDIO_SOURCE_VOICE_COMMUNICATION:
113 return 6;
114 case AUDIO_SOURCE_CAMCORDER:
115 return 5;
116 case AUDIO_SOURCE_MIC:
117 return 4;
118 case AUDIO_SOURCE_FM_TUNER:
119 return 3;
120 case AUDIO_SOURCE_VOICE_RECOGNITION:
121 return 2;
122 case AUDIO_SOURCE_HOTWORD:
123 return 1;
124 default:
125 break;
126 }
127 return 0;
128}