François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 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 | |
François Gaffie | 5fcd6f9 | 2015-11-27 13:46:12 +0100 | [diff] [blame] | 21 | static const audio_format_t gDynamicFormat = AUDIO_FORMAT_DEFAULT; |
François Gaffie | 5fcd6f9 | 2015-11-27 13:46:12 +0100 | [diff] [blame] | 22 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 23 | // For mixed output and inputs, the policy will use max mixer sampling rates. |
| 24 | // Do not limit sampling rate otherwise |
Glenn Kasten | 05ddca5 | 2016-02-11 08:17:12 -0800 | [diff] [blame] | 25 | #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 Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 29 | |
| 30 | // For mixed output and inputs, the policy will use max mixer channel count. |
| 31 | // Do not limit channel count otherwise |
Glenn Kasten | 05ddca5 | 2016-02-11 08:17:12 -0800 | [diff] [blame] | 32 | #define MAX_MIXER_CHANNEL_COUNT FCC_8 |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 33 | |
| 34 | /** |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 35 | * 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 Trivi | 7638ca2 | 2016-03-04 17:42:44 -0800 | [diff] [blame] | 38 | #define APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL (AUDIO_DEVICE_OUT_REMOTE_SUBMIX|AUDIO_DEVICE_OUT_BUS) |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 39 | |
Jean-Michel Trivi | 7638ca2 | 2016-03-04 17:42:44 -0800 | [diff] [blame] | 40 | #define APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX|AUDIO_DEVICE_IN_BUS) |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 41 | |
| 42 | /** |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame] | 43 | * 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 Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 50 | * 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 | */ |
| 57 | static 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 Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 63 | * 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 Hsieh | 5603d28 | 2015-05-04 17:14:15 -0700 | [diff] [blame] | 70 | static inline bool device_distinguishes_on_address(audio_devices_t device) |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 71 | { |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 72 | 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 Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 76 | } |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 77 | |
| 78 | /** |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame^] | 79 | * Check whether audio device has encoding capability. |
| 80 | * |
| 81 | * @param[in] device to consider |
| 82 | * |
| 83 | * @return true if device has encoding capability, false otherwise.. |
| 84 | */ |
| 85 | static inline bool device_has_encoding_capability(audio_devices_t device) |
| 86 | { |
| 87 | if (device & AUDIO_DEVICE_OUT_ALL_A2DP) { |
| 88 | return true; |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | /** |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 94 | * Returns the priority of a given audio source for capture. The priority is used when more than one |
| 95 | * capture session is active on a given input stream to determine which session drives routing and |
| 96 | * effect configuration. |
| 97 | * |
| 98 | * @param[in] inputSource to consider. Valid sources are: |
| 99 | * - AUDIO_SOURCE_VOICE_COMMUNICATION |
| 100 | * - AUDIO_SOURCE_CAMCORDER |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 101 | * - AUDIO_SOURCE_VOICE_PERFORMANCE |
| 102 | * - AUDIO_SOURCE_UNPROCESSED |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 103 | * - AUDIO_SOURCE_MIC |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 104 | * - AUDIO_SOURCE_ECHO_REFERENCE |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 105 | * - AUDIO_SOURCE_FM_TUNER |
| 106 | * - AUDIO_SOURCE_VOICE_RECOGNITION |
| 107 | * - AUDIO_SOURCE_HOTWORD |
| 108 | * |
| 109 | * @return the corresponding input source priority or 0 if priority is irrelevant for this source. |
| 110 | * This happens when the specified source cannot share a given input stream (e.g remote submix) |
| 111 | * The higher the value, the higher the priority. |
| 112 | */ |
| 113 | static inline int32_t source_priority(audio_source_t inputSource) |
| 114 | { |
| 115 | switch (inputSource) { |
| 116 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 117 | return 9; |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 118 | case AUDIO_SOURCE_CAMCORDER: |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 119 | return 8; |
| 120 | case AUDIO_SOURCE_VOICE_PERFORMANCE: |
| 121 | return 7; |
| 122 | case AUDIO_SOURCE_UNPROCESSED: |
| 123 | return 6; |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 124 | case AUDIO_SOURCE_MIC: |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 125 | return 5; |
| 126 | case AUDIO_SOURCE_ECHO_REFERENCE: |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 127 | return 4; |
| 128 | case AUDIO_SOURCE_FM_TUNER: |
| 129 | return 3; |
| 130 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
| 131 | return 2; |
| 132 | case AUDIO_SOURCE_HOTWORD: |
| 133 | return 1; |
| 134 | default: |
| 135 | break; |
| 136 | } |
| 137 | return 0; |
| 138 | } |
Eric Laurent | e693002 | 2016-02-11 10:20:40 -0800 | [diff] [blame] | 139 | |
| 140 | /* Indicates if audio formats are equivalent when considering a match between |
| 141 | * audio HAL supported formats and client requested formats |
| 142 | */ |
| 143 | static inline bool audio_formats_match(audio_format_t format1, |
| 144 | audio_format_t format2) |
| 145 | { |
| 146 | if (audio_is_linear_pcm(format1) && |
| 147 | (audio_bytes_per_sample(format1) > 2) && |
| 148 | audio_is_linear_pcm(format2) && |
| 149 | (audio_bytes_per_sample(format2) > 2)) { |
| 150 | return true; |
| 151 | } |
| 152 | return format1 == format2; |
| 153 | } |