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 | /** |
| 35 | * A device mask for all audio input devices that are considered "virtual" when evaluating |
Eric Laurent | 232f26f | 2016-02-17 18:06:27 -0800 | [diff] [blame] | 36 | * active inputs in getActiveInput() |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 37 | */ |
Eric Laurent | 232f26f | 2016-02-17 18:06:27 -0800 | [diff] [blame] | 38 | #define APM_AUDIO_IN_DEVICE_VIRTUAL_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX|AUDIO_DEVICE_IN_FM_TUNER) |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 39 | |
| 40 | |
| 41 | /** |
| 42 | * A device mask for all audio input and output devices where matching inputs/outputs on device |
| 43 | * type alone is not enough: the address must match too |
| 44 | */ |
Jean-Michel Trivi | 7638ca2 | 2016-03-04 17:42:44 -0800 | [diff] [blame] | 45 | #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] | 46 | |
Jean-Michel Trivi | 7638ca2 | 2016-03-04 17:42:44 -0800 | [diff] [blame] | 47 | #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] | 48 | |
| 49 | /** |
Eric Laurent | 5a2b629 | 2016-04-14 18:05:57 -0700 | [diff] [blame^] | 50 | * Stub audio output device. Used in policy configuration file on platforms without audio outputs. |
| 51 | * This alias value to AUDIO_DEVICE_OUT_DEFAULT is only used in the audio policy context. |
| 52 | */ |
| 53 | #define AUDIO_DEVICE_OUT_STUB AUDIO_DEVICE_OUT_DEFAULT |
| 54 | /** |
| 55 | * Stub audio input device. Used in policy configuration file on platforms without audio inputs. |
| 56 | * This alias value to AUDIO_DEVICE_IN_DEFAULT is only used in the audio policy context. |
| 57 | */ |
| 58 | #define AUDIO_DEVICE_IN_STUB AUDIO_DEVICE_IN_DEFAULT |
| 59 | /** |
| 60 | * Alias to AUDIO_DEVICE_OUT_DEFAULT defined for clarification when this value is used by volume |
| 61 | * control APIs (e.g setStreamVolumeIndex(). |
| 62 | */ |
| 63 | #define AUDIO_DEVICE_OUT_DEFAULT_FOR_VOLUME AUDIO_DEVICE_OUT_DEFAULT |
| 64 | |
| 65 | |
| 66 | /** |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 67 | * Check if the state given correspond to an in call state. |
| 68 | * @TODO find a better name for widely call state |
| 69 | * |
| 70 | * @param[in] state to consider |
| 71 | * |
| 72 | * @return true if given state represents a device in a telephony or VoIP call |
| 73 | */ |
| 74 | static inline bool is_state_in_call(int state) |
| 75 | { |
| 76 | return (state == AUDIO_MODE_IN_CALL) || (state == AUDIO_MODE_IN_COMMUNICATION); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Check if the input device given is considered as a virtual device. |
| 81 | * |
| 82 | * @param[in] device to consider |
| 83 | * |
| 84 | * @return true if the device is a virtual one, false otherwise. |
| 85 | */ |
Chih-Hung Hsieh | 5603d28 | 2015-05-04 17:14:15 -0700 | [diff] [blame] | 86 | static inline bool is_virtual_input_device(audio_devices_t device) |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 87 | { |
| 88 | if ((device & AUDIO_DEVICE_BIT_IN) != 0) { |
| 89 | device &= ~AUDIO_DEVICE_BIT_IN; |
| 90 | if ((popcount(device) == 1) && ((device & ~APM_AUDIO_IN_DEVICE_VIRTUAL_ALL) == 0)) |
| 91 | return true; |
| 92 | } |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Check whether the device type is one |
| 98 | * where addresses are used to distinguish between one connected device and another |
| 99 | * |
| 100 | * @param[in] device to consider |
| 101 | * |
| 102 | * @return true if the device needs distinguish on address, false otherwise.. |
| 103 | */ |
Chih-Hung Hsieh | 5603d28 | 2015-05-04 17:14:15 -0700 | [diff] [blame] | 104 | static inline bool device_distinguishes_on_address(audio_devices_t device) |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 105 | { |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 106 | return (((device & AUDIO_DEVICE_BIT_IN) != 0) && |
| 107 | ((~AUDIO_DEVICE_BIT_IN & device & APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL) != 0)) || |
| 108 | (((device & AUDIO_DEVICE_BIT_IN) == 0) && |
| 109 | ((device & APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL) != 0)); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 110 | } |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 111 | |
Eric Laurent | e693002 | 2016-02-11 10:20:40 -0800 | [diff] [blame] | 112 | /* Indicates if audio formats are equivalent when considering a match between |
| 113 | * audio HAL supported formats and client requested formats |
| 114 | */ |
| 115 | static inline bool audio_formats_match(audio_format_t format1, |
| 116 | audio_format_t format2) |
| 117 | { |
| 118 | if (audio_is_linear_pcm(format1) && |
| 119 | (audio_bytes_per_sample(format1) > 2) && |
| 120 | audio_is_linear_pcm(format2) && |
| 121 | (audio_bytes_per_sample(format2) > 2)) { |
| 122 | return true; |
| 123 | } |
| 124 | return format1 == format2; |
| 125 | } |