blob: 46a2a40453af35bf54197c328d42b83382b77c8d [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
Glenn Kasten05ddca52016-02-11 08:17:12 -080025#define SAMPLE_RATE_HZ_MAX 192000
26
27// Used when a client opens a capture stream, without specifying a desired sample rate.
28#define SAMPLE_RATE_HZ_DEFAULT 48000
François Gaffie53615e22015-03-19 09:24:12 +010029
30// For mixed output and inputs, the policy will use max mixer channel count.
31// Do not limit channel count otherwise
Glenn Kasten05ddca52016-02-11 08:17:12 -080032#define MAX_MIXER_CHANNEL_COUNT FCC_8
François Gaffie53615e22015-03-19 09:24:12 +010033
34/**
François Gaffie53615e22015-03-19 09:24:12 +010035 * A device mask for all audio input and output devices where matching inputs/outputs on device
36 * type alone is not enough: the address must match too
37 */
Jean-Michel Trivi7638ca22016-03-04 17:42:44 -080038#define APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL (AUDIO_DEVICE_OUT_REMOTE_SUBMIX|AUDIO_DEVICE_OUT_BUS)
Eric Laurent7c1ec5f2015-07-09 14:52:47 -070039
Jean-Michel Trivi7638ca22016-03-04 17:42:44 -080040#define APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX|AUDIO_DEVICE_IN_BUS)
François Gaffie53615e22015-03-19 09:24:12 +010041
42/**
Eric Laurent5a2b6292016-04-14 18:05:57 -070043 * Alias to AUDIO_DEVICE_OUT_DEFAULT defined for clarification when this value is used by volume
44 * control APIs (e.g setStreamVolumeIndex().
45 */
46#define AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME AUDIO_DEVICE_OUT_DEFAULT
47
48
49/**
François Gaffie53615e22015-03-19 09:24:12 +010050 * Check if the state given correspond to an in call state.
51 * @TODO find a better name for widely call state
52 *
53 * @param[in] state to consider
54 *
55 * @return true if given state represents a device in a telephony or VoIP call
56 */
57static inline bool is_state_in_call(int state)
58{
59 return (state == AUDIO_MODE_IN_CALL) || (state == AUDIO_MODE_IN_COMMUNICATION);
60}
61
62/**
François Gaffie53615e22015-03-19 09:24:12 +010063 * Check whether the device type is one
64 * where addresses are used to distinguish between one connected device and another
65 *
66 * @param[in] device to consider
67 *
68 * @return true if the device needs distinguish on address, false otherwise..
69 */
Chih-Hung Hsieh5603d282015-05-04 17:14:15 -070070static inline bool device_distinguishes_on_address(audio_devices_t device)
François Gaffie53615e22015-03-19 09:24:12 +010071{
Eric Laurent7c1ec5f2015-07-09 14:52:47 -070072 return (((device & AUDIO_DEVICE_BIT_IN) != 0) &&
73 ((~AUDIO_DEVICE_BIT_IN & device & APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL) != 0)) ||
74 (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
75 ((device & APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL) != 0));
François Gaffie53615e22015-03-19 09:24:12 +010076}
Eric Laurentfb66dd92016-01-28 18:32:03 -080077
78/**
79 * Returns the priority of a given audio source for capture. The priority is used when more than one
80 * capture session is active on a given input stream to determine which session drives routing and
81 * effect configuration.
82 *
83 * @param[in] inputSource to consider. Valid sources are:
84 * - AUDIO_SOURCE_VOICE_COMMUNICATION
85 * - AUDIO_SOURCE_CAMCORDER
Eric Laurentae4b6ec2019-01-15 18:34:38 -080086 * - AUDIO_SOURCE_VOICE_PERFORMANCE
87 * - AUDIO_SOURCE_UNPROCESSED
Eric Laurentfb66dd92016-01-28 18:32:03 -080088 * - AUDIO_SOURCE_MIC
Eric Laurentae4b6ec2019-01-15 18:34:38 -080089 * - AUDIO_SOURCE_ECHO_REFERENCE
Eric Laurentfb66dd92016-01-28 18:32:03 -080090 * - AUDIO_SOURCE_FM_TUNER
91 * - AUDIO_SOURCE_VOICE_RECOGNITION
92 * - AUDIO_SOURCE_HOTWORD
93 *
94 * @return the corresponding input source priority or 0 if priority is irrelevant for this source.
95 * This happens when the specified source cannot share a given input stream (e.g remote submix)
96 * The higher the value, the higher the priority.
97 */
98static inline int32_t source_priority(audio_source_t inputSource)
99{
100 switch (inputSource) {
101 case AUDIO_SOURCE_VOICE_COMMUNICATION:
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800102 return 9;
Eric Laurentfb66dd92016-01-28 18:32:03 -0800103 case AUDIO_SOURCE_CAMCORDER:
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800104 return 8;
105 case AUDIO_SOURCE_VOICE_PERFORMANCE:
106 return 7;
107 case AUDIO_SOURCE_UNPROCESSED:
108 return 6;
Eric Laurentfb66dd92016-01-28 18:32:03 -0800109 case AUDIO_SOURCE_MIC:
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800110 return 5;
111 case AUDIO_SOURCE_ECHO_REFERENCE:
Eric Laurentfb66dd92016-01-28 18:32:03 -0800112 return 4;
113 case AUDIO_SOURCE_FM_TUNER:
114 return 3;
115 case AUDIO_SOURCE_VOICE_RECOGNITION:
116 return 2;
117 case AUDIO_SOURCE_HOTWORD:
118 return 1;
119 default:
120 break;
121 }
122 return 0;
123}
Eric Laurente6930022016-02-11 10:20:40 -0800124
125/* Indicates if audio formats are equivalent when considering a match between
126 * audio HAL supported formats and client requested formats
127 */
128static inline bool audio_formats_match(audio_format_t format1,
129 audio_format_t format2)
130{
131 if (audio_is_linear_pcm(format1) &&
132 (audio_bytes_per_sample(format1) > 2) &&
133 audio_is_linear_pcm(format2) &&
134 (audio_bytes_per_sample(format2) > 2)) {
135 return true;
136 }
137 return format1 == format2;
138}