Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame] | 17 | #pragma once |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 18 | |
Mikhail Naganov | 2773dd7 | 2017-12-08 10:12:11 -0800 | [diff] [blame] | 19 | #include <atomic> |
Mikhail Naganov | 3797715 | 2018-07-11 15:54:44 -0700 | [diff] [blame] | 20 | #include <functional> |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame] | 21 | #include <memory> |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 22 | #include <unordered_set> |
Mikhail Naganov | 2773dd7 | 2017-12-08 10:12:11 -0800 | [diff] [blame] | 23 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 24 | #include <stdint.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <cutils/config_utils.h> |
| 27 | #include <cutils/misc.h> |
| 28 | #include <utils/Timers.h> |
| 29 | #include <utils/Errors.h> |
| 30 | #include <utils/KeyedVector.h> |
| 31 | #include <utils/SortedVector.h> |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 32 | #include <media/AudioParameter.h> |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 33 | #include <media/AudioPolicy.h> |
jiabin | 811797a | 2019-09-10 14:29:14 -0700 | [diff] [blame] | 34 | #include <media/AudioProfile.h> |
Mikhail Naganov | 15be9d2 | 2017-11-08 14:18:13 +1100 | [diff] [blame] | 35 | #include <media/PatchBuilder.h> |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 36 | #include "AudioPolicyInterface.h" |
| 37 | |
jiabin | c004863 | 2023-04-27 22:04:31 +0000 | [diff] [blame] | 38 | #include <android/media/DeviceConnectedState.h> |
Nathalie Le Clair | 88fa275 | 2021-11-23 13:03:41 +0100 | [diff] [blame] | 39 | #include <android/media/audio/common/AudioPort.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 40 | #include <AudioPolicyManagerObserver.h> |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 41 | #include <AudioPolicyConfig.h> |
jiabin | e128485 | 2019-09-11 10:15:46 -0700 | [diff] [blame] | 42 | #include <PolicyAudioPort.h> |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 43 | #include <AudioPatch.h> |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 44 | #include <DeviceDescriptor.h> |
| 45 | #include <IOProfile.h> |
| 46 | #include <HwModule.h> |
| 47 | #include <AudioInputDescriptor.h> |
| 48 | #include <AudioOutputDescriptor.h> |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 49 | #include <AudioPolicyMix.h> |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 50 | #include <EffectDescriptor.h> |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 51 | #include <PreferredMixerAttributesInfo.h> |
François Gaffie | df37269 | 2015-03-19 10:43:27 +0100 | [diff] [blame] | 52 | #include <SoundTriggerSession.h> |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 53 | #include "EngineLibrary.h" |
Eric Laurent | f5aa58d | 2019-02-22 18:20:11 -0800 | [diff] [blame] | 54 | #include "TypeConverter.h" |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 55 | |
| 56 | namespace android { |
| 57 | |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 58 | using content::AttributionSourceState; |
| 59 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 60 | // ---------------------------------------------------------------------------- |
| 61 | |
| 62 | // Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB |
Eric Laurent | ffbc80f | 2015-03-18 18:30:19 -0700 | [diff] [blame] | 63 | #define SONIFICATION_HEADSET_VOLUME_FACTOR_DB (-6) |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 64 | // Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB |
Eric Laurent | ffbc80f | 2015-03-18 18:30:19 -0700 | [diff] [blame] | 65 | #define SONIFICATION_HEADSET_VOLUME_MIN_DB (-36) |
Jean-Michel Trivi | 00a2096 | 2016-05-25 19:11:01 -0700 | [diff] [blame] | 66 | // Max volume difference on A2DP between playing media and STRATEGY_SONIFICATION streams: 12dB |
| 67 | #define SONIFICATION_A2DP_MAX_MEDIA_DIFF_DB (12) |
Eric Laurent | ffbc80f | 2015-03-18 18:30:19 -0700 | [diff] [blame] | 68 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 69 | // Time in milliseconds during which we consider that music is still active after a music |
| 70 | // track was stopped - see computeVolume() |
| 71 | #define SONIFICATION_HEADSET_MUSIC_DELAY 5000 |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 72 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 73 | // Time in milliseconds during witch some streams are muted while the audio path |
| 74 | // is switched |
| 75 | #define MUTE_TIME_MS 2000 |
| 76 | |
Eric Laurent | ac3a690 | 2018-05-11 16:39:10 -0700 | [diff] [blame] | 77 | // multiplication factor applied to output latency when calculating a safe mute delay when |
| 78 | // invalidating tracks |
| 79 | #define LATENCY_MUTE_FACTOR 4 |
| 80 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 81 | #define NUM_TEST_OUTPUTS 5 |
| 82 | |
| 83 | #define NUM_VOL_CURVE_KNEES 2 |
| 84 | |
| 85 | // Default minimum length allowed for offloading a compressed track |
| 86 | // Can be overridden by the audio.offload.min.duration.secs property |
| 87 | #define OFFLOAD_DEFAULT_MIN_DURATION_SECS 60 |
| 88 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 89 | // ---------------------------------------------------------------------------- |
| 90 | // AudioPolicyManager implements audio policy manager behavior common to all platforms. |
| 91 | // ---------------------------------------------------------------------------- |
| 92 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 93 | class AudioPolicyManager : public AudioPolicyInterface, public AudioPolicyManagerObserver |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 94 | { |
| 95 | |
| 96 | public: |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 97 | AudioPolicyManager(const sp<const AudioPolicyConfig>& config, |
Mikhail Naganov | f1b6d97 | 2023-05-02 13:56:01 -0700 | [diff] [blame] | 98 | EngineInstance&& engine, |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 99 | AudioPolicyClientInterface *clientInterface); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 100 | virtual ~AudioPolicyManager(); |
| 101 | |
| 102 | // AudioPolicyInterface |
Nathalie Le Clair | 88fa275 | 2021-11-23 13:03:41 +0100 | [diff] [blame] | 103 | virtual status_t setDeviceConnectionState(audio_policy_dev_state_t state, |
| 104 | const android::media::audio::common::AudioPort& port, audio_format_t encodedFormat); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 105 | virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device, |
Vlad Popa | 87e0e58 | 2024-05-20 18:49:20 -0700 | [diff] [blame] | 106 | const char *device_address); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 107 | virtual status_t handleDeviceConfigChange(audio_devices_t device, |
| 108 | const char *device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 109 | const char *device_name, |
| 110 | audio_format_t encodedFormat); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 111 | virtual void setPhoneState(audio_mode_t state); |
| 112 | virtual void setForceUse(audio_policy_force_use_t usage, |
| 113 | audio_policy_forced_cfg_t config); |
| 114 | virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 115 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 116 | virtual void setSystemProperty(const char* property, const char* value); |
| 117 | virtual status_t initCheck(); |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 118 | virtual audio_io_handle_t getOutput(audio_stream_type_t stream); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 119 | status_t getOutputForAttr(const audio_attributes_t *attr, |
| 120 | audio_io_handle_t *output, |
| 121 | audio_session_t session, |
| 122 | audio_stream_type_t *stream, |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 123 | const AttributionSourceState& attributionSource, |
jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 124 | audio_config_t *config, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 125 | audio_output_flags_t *flags, |
| 126 | audio_port_handle_t *selectedDeviceId, |
| 127 | audio_port_handle_t *portId, |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 128 | std::vector<audio_io_handle_t> *secondaryOutputs, |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 129 | output_type_t *outputType, |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 130 | bool *isSpatialized, |
| 131 | bool *isBitPerfect) override; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 132 | virtual status_t startOutput(audio_port_handle_t portId); |
| 133 | virtual status_t stopOutput(audio_port_handle_t portId); |
jiabin | bce0c1d | 2020-10-05 11:20:18 -0700 | [diff] [blame] | 134 | virtual bool releaseOutput(audio_port_handle_t portId); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 135 | virtual status_t getInputForAttr(const audio_attributes_t *attr, |
| 136 | audio_io_handle_t *input, |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 137 | audio_unique_id_t riid, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 138 | audio_session_t session, |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 139 | const AttributionSourceState& attributionSource, |
jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 140 | audio_config_base_t *config, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 141 | audio_input_flags_t flags, |
Eric Laurent | 2ac7694 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 142 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 143 | input_type_t *inputType, |
Marvin Ramin | e5a122d | 2023-12-07 13:57:59 +0100 | [diff] [blame] | 144 | audio_port_handle_t *portId, |
| 145 | uint32_t *virtualDeviceId); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 146 | |
| 147 | // indicates to the audio policy manager that the input starts being used. |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 148 | virtual status_t startInput(audio_port_handle_t portId); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 149 | |
| 150 | // indicates to the audio policy manager that the input stops being used. |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 151 | virtual status_t stopInput(audio_port_handle_t portId); |
| 152 | virtual void releaseInput(audio_port_handle_t portId); |
Eric Laurent | 0dd5185 | 2019-04-19 18:18:58 -0700 | [diff] [blame] | 153 | virtual void checkCloseInputs(); |
Vlad Popa | 87e0e58 | 2024-05-20 18:49:20 -0700 | [diff] [blame] | 154 | virtual status_t setDeviceAbsoluteVolumeEnabled(audio_devices_t deviceType, |
| 155 | const char *address, |
| 156 | bool enabled, |
| 157 | audio_stream_type_t streamToDriveAbs); |
François Gaffie | 251c7f0 | 2018-11-07 10:41:08 +0100 | [diff] [blame] | 158 | /** |
| 159 | * @brief initStreamVolume: even if the engine volume files provides min and max, keep this |
| 160 | * api for compatibility reason. |
| 161 | * AudioServer will get the min and max and may overwrite them if: |
| 162 | * -using property (highest priority) |
| 163 | * -not defined (-1 by convention), case when still using apm volume tables XML files |
| 164 | * @param stream to be considered |
| 165 | * @param indexMin to set |
| 166 | * @param indexMax to set |
| 167 | */ |
| 168 | virtual void initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 169 | virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, |
| 170 | int index, |
| 171 | audio_devices_t device); |
| 172 | virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, |
| 173 | int *index, |
| 174 | audio_devices_t device); |
| 175 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 176 | virtual status_t setVolumeIndexForAttributes(const audio_attributes_t &attr, |
| 177 | int index, |
| 178 | audio_devices_t device); |
| 179 | virtual status_t getVolumeIndexForAttributes(const audio_attributes_t &attr, |
| 180 | int &index, |
| 181 | audio_devices_t device); |
| 182 | virtual status_t getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index); |
| 183 | |
| 184 | virtual status_t getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index); |
| 185 | |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 186 | status_t setVolumeCurveIndex(int index, |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 187 | audio_devices_t device, |
| 188 | IVolumeCurves &volumeCurves); |
| 189 | |
| 190 | status_t getVolumeIndex(const IVolumeCurves &curves, int &index, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 191 | const DeviceTypeSet& deviceTypes) const; |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 192 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 193 | // return the strategy corresponding to a given stream type |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 194 | virtual product_strategy_t getStrategyForStream(audio_stream_type_t stream) |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 195 | { |
| 196 | return streamToStrategy(stream); |
| 197 | } |
| 198 | product_strategy_t streamToStrategy(audio_stream_type_t stream) const |
| 199 | { |
| 200 | auto attributes = mEngine->getAttributesForStreamType(stream); |
| 201 | return mEngine->getProductStrategyForAttributes(attributes); |
| 202 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 203 | |
Andy Hung | 6d23c0f | 2022-02-16 09:37:15 -0800 | [diff] [blame] | 204 | /** |
| 205 | * Returns a vector of devices associated with attributes. |
| 206 | * |
| 207 | * An AudioTrack opened with specified attributes should play on the returned devices. |
| 208 | * If forVolume is set to true, the caller is AudioService, determining the proper |
| 209 | * device volume to adjust. |
| 210 | * |
| 211 | * Devices are determined in the following precedence: |
| 212 | * 1) Devices associated with a dynamic policy matching the attributes. This is often |
| 213 | * a remote submix from MIX_ROUTE_FLAG_LOOP_BACK. Secondary mixes from a |
| 214 | * dynamic policy are not included. |
| 215 | * |
| 216 | * If no such dynamic policy then |
| 217 | * 2) Devices containing an active client using setPreferredDevice |
| 218 | * with same strategy as the attributes. |
| 219 | * (from the default Engine::getOutputDevicesForAttributes() implementation). |
| 220 | * |
| 221 | * If no corresponding active client with setPreferredDevice then |
| 222 | * 3) Devices associated with the strategy determined by the attributes |
| 223 | * (from the default Engine::getOutputDevicesForAttributes() implementation). |
| 224 | * |
| 225 | * @param attributes to be considered |
| 226 | * @param devices an AudioDeviceTypeAddrVector container passed in that |
| 227 | * will be filled on success. |
| 228 | * @param forVolume true if the devices are to be associated with current device volume. |
| 229 | * @return NO_ERROR on success. |
| 230 | */ |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 231 | virtual status_t getDevicesForAttributes( |
| 232 | const audio_attributes_t &attributes, |
Andy Hung | 6d23c0f | 2022-02-16 09:37:15 -0800 | [diff] [blame] | 233 | AudioDeviceTypeAddrVector *devices, |
| 234 | bool forVolume); |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 235 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 236 | virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc = NULL); |
| 237 | virtual status_t registerEffect(const effect_descriptor_t *desc, |
| 238 | audio_io_handle_t io, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 239 | product_strategy_t strategy, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 240 | int session, |
| 241 | int id); |
Eric Laurent | c241b0d | 2018-11-28 09:08:49 -0800 | [diff] [blame] | 242 | virtual status_t unregisterEffect(int id); |
| 243 | virtual status_t setEffectEnabled(int id, bool enabled); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 244 | status_t moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) override; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 245 | |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 246 | virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 247 | // return whether a stream is playing remotely, override to change the definition of |
| 248 | // local/remote playback, used for instance by notification manager to not make |
| 249 | // media players lose audio focus when not playing locally |
| 250 | // For the base implementation, "remotely" means playing during screen mirroring which |
| 251 | // uses an output for playback with a non-empty, non "0" address. |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 252 | virtual bool isStreamActiveRemotely(audio_stream_type_t stream, |
| 253 | uint32_t inPastMs = 0) const; |
| 254 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 255 | virtual bool isSourceActive(audio_source_t source) const; |
| 256 | |
Mikhail Naganov | 100f012 | 2018-11-29 11:22:16 -0800 | [diff] [blame] | 257 | // helpers for dump(int fd) |
| 258 | void dumpManualSurroundFormats(String8 *dst) const; |
| 259 | void dump(String8 *dst) const; |
Andy Hung | c29d82b | 2018-10-05 12:23:17 -0700 | [diff] [blame] | 260 | |
| 261 | status_t dump(int fd) override; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 262 | |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 263 | status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t capturePolicy) override; |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 264 | virtual audio_offload_mode_t getOffloadSupport(const audio_offload_info_t& offloadInfo); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 265 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 266 | virtual bool isDirectOutputSupported(const audio_config_base_t& config, |
| 267 | const audio_attributes_t& attributes); |
| 268 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 269 | virtual status_t listAudioPorts(audio_port_role_t role, |
| 270 | audio_port_type_t type, |
| 271 | unsigned int *num_ports, |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 272 | struct audio_port_v7 *ports, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 273 | unsigned int *generation); |
Mikhail Naganov | 5edc5ed | 2023-03-23 14:52:15 -0700 | [diff] [blame] | 274 | status_t listDeclaredDevicePorts(media::AudioPortRole role, |
| 275 | std::vector<media::AudioPortFw>* result) override; |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 276 | virtual status_t getAudioPort(struct audio_port_v7 *port); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 277 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 278 | audio_patch_handle_t *handle, |
Francois Gaffie | b2e5cb5 | 2021-06-22 13:16:09 +0200 | [diff] [blame] | 279 | uid_t uid); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 280 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle, |
| 281 | uid_t uid); |
| 282 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 283 | struct audio_patch *patches, |
| 284 | unsigned int *generation); |
| 285 | virtual status_t setAudioPortConfig(const struct audio_port_config *config); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 286 | |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 287 | virtual void releaseResourcesForUid(uid_t uid); |
| 288 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 289 | virtual status_t acquireSoundTriggerSession(audio_session_t *session, |
| 290 | audio_io_handle_t *ioHandle, |
| 291 | audio_devices_t *device); |
| 292 | |
François Gaffie | df37269 | 2015-03-19 10:43:27 +0100 | [diff] [blame] | 293 | virtual status_t releaseSoundTriggerSession(audio_session_t session) |
| 294 | { |
| 295 | return mSoundTriggerSessions.releaseSession(session); |
| 296 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 297 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 298 | virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 299 | virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes); |
Marvin Ramin | bdefaf0 | 2023-11-01 09:10:32 +0100 | [diff] [blame] | 300 | virtual status_t getRegisteredPolicyMixes(std::vector<AudioMix>& mixes) override; |
Jan Sebechlebsky | 0af8e87 | 2023-08-11 14:45:08 +0200 | [diff] [blame] | 301 | virtual status_t updatePolicyMix( |
| 302 | const AudioMix& mix, |
| 303 | const std::vector<AudioMixMatchCriterion>& updatedCriteria) override; |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 304 | virtual status_t setUidDeviceAffinities(uid_t uid, |
jiabin | 6a02d53 | 2020-08-07 11:56:38 -0700 | [diff] [blame] | 305 | const AudioDeviceTypeAddrVector& devices); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 306 | virtual status_t removeUidDeviceAffinities(uid_t uid); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 307 | virtual status_t setUserIdDeviceAffinities(int userId, |
jiabin | 6a02d53 | 2020-08-07 11:56:38 -0700 | [diff] [blame] | 308 | const AudioDeviceTypeAddrVector& devices); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 309 | virtual status_t removeUserIdDeviceAffinities(int userId); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 310 | |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 311 | virtual status_t setDevicesRoleForStrategy(product_strategy_t strategy, |
| 312 | device_role_t role, |
| 313 | const AudioDeviceTypeAddrVector &devices); |
| 314 | |
| 315 | virtual status_t removeDevicesRoleForStrategy(product_strategy_t strategy, |
Paul Wang | 5d7cdb5 | 2022-11-22 09:45:06 +0000 | [diff] [blame] | 316 | device_role_t role, |
| 317 | const AudioDeviceTypeAddrVector &devices); |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 318 | |
Paul Wang | 5d7cdb5 | 2022-11-22 09:45:06 +0000 | [diff] [blame] | 319 | virtual status_t clearDevicesRoleForStrategy(product_strategy_t strategy, |
| 320 | device_role_t role); |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 321 | |
| 322 | virtual status_t getDevicesForRoleAndStrategy(product_strategy_t strategy, |
| 323 | device_role_t role, |
| 324 | AudioDeviceTypeAddrVector &devices); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 325 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 326 | virtual status_t setDevicesRoleForCapturePreset(audio_source_t audioSource, |
| 327 | device_role_t role, |
| 328 | const AudioDeviceTypeAddrVector &devices); |
| 329 | |
| 330 | virtual status_t addDevicesRoleForCapturePreset(audio_source_t audioSource, |
| 331 | device_role_t role, |
| 332 | const AudioDeviceTypeAddrVector &devices); |
| 333 | |
| 334 | virtual status_t removeDevicesRoleForCapturePreset( |
| 335 | audio_source_t audioSource, device_role_t role, |
| 336 | const AudioDeviceTypeAddrVector& devices); |
| 337 | |
| 338 | virtual status_t clearDevicesRoleForCapturePreset(audio_source_t audioSource, |
| 339 | device_role_t role); |
| 340 | |
| 341 | virtual status_t getDevicesForRoleAndCapturePreset(audio_source_t audioSource, |
| 342 | device_role_t role, |
| 343 | AudioDeviceTypeAddrVector &devices); |
| 344 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 345 | virtual status_t startAudioSource(const struct audio_port_config *source, |
| 346 | const audio_attributes_t *attributes, |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 347 | audio_port_handle_t *portId, |
Eric Laurent | 963dbcc | 2024-06-20 12:34:15 +0000 | [diff] [blame] | 348 | uid_t uid); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 349 | virtual status_t stopAudioSource(audio_port_handle_t portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 350 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 351 | virtual status_t setMasterMono(bool mono); |
| 352 | virtual status_t getMasterMono(bool *mono); |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 353 | virtual float getStreamVolumeDB( |
| 354 | audio_stream_type_t stream, int index, audio_devices_t device); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 355 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 356 | virtual status_t getSurroundFormats(unsigned int *numSurroundFormats, |
| 357 | audio_format_t *surroundFormats, |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 358 | bool *surroundFormatsEnabled); |
| 359 | virtual status_t getReportedSurroundFormats(unsigned int *numSurroundFormats, |
| 360 | audio_format_t *surroundFormats); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 361 | virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled); |
| 362 | |
Patty | dd80758 | 2021-11-04 21:01:03 +0800 | [diff] [blame] | 363 | virtual status_t getHwOffloadFormatsSupportedForBluetoothMedia( |
| 364 | audio_devices_t device, std::vector<audio_format_t> *formats); |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 365 | |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 366 | virtual void setAppState(audio_port_handle_t portId, app_state_t state); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 367 | |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 368 | virtual bool isHapticPlaybackSupported(); |
| 369 | |
Carter Hsu | 325a8eb | 2022-01-19 19:56:51 +0800 | [diff] [blame] | 370 | virtual bool isUltrasoundSupported(); |
| 371 | |
Atneya Nair | 698f5ef | 2022-12-15 16:15:09 -0800 | [diff] [blame] | 372 | bool isHotwordStreamSupported(bool lookbackAudio) override; |
| 373 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 374 | virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies) |
| 375 | { |
| 376 | return mEngine->listAudioProductStrategies(strategies); |
| 377 | } |
| 378 | |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 379 | virtual status_t getProductStrategyFromAudioAttributes( |
François Gaffie | 1e2b56f | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 380 | const audio_attributes_t &aa, product_strategy_t &productStrategy, |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 381 | bool fallbackOnDefault) |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 382 | { |
François Gaffie | 1e2b56f | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 383 | productStrategy = mEngine->getProductStrategyForAttributes(aa, fallbackOnDefault); |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 384 | return (fallbackOnDefault && productStrategy == PRODUCT_STRATEGY_NONE) ? |
| 385 | BAD_VALUE : NO_ERROR; |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | virtual status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups) |
| 389 | { |
| 390 | return mEngine->listAudioVolumeGroups(groups); |
| 391 | } |
| 392 | |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 393 | virtual status_t getVolumeGroupFromAudioAttributes( |
François Gaffie | 1e2b56f | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 394 | const audio_attributes_t &aa, volume_group_t &volumeGroup, bool fallbackOnDefault) |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 395 | { |
François Gaffie | 1e2b56f | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 396 | volumeGroup = mEngine->getVolumeGroupForAttributes(aa, fallbackOnDefault); |
Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 397 | return (fallbackOnDefault && volumeGroup == VOLUME_GROUP_NONE) ? |
| 398 | BAD_VALUE : NO_ERROR; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Eric Laurent | fa0f674 | 2021-08-17 18:39:44 +0200 | [diff] [blame] | 401 | virtual bool canBeSpatialized(const audio_attributes_t *attr, |
Eric Laurent | cad6c0d | 2021-07-13 15:12:39 +0200 | [diff] [blame] | 402 | const audio_config_t *config, |
Eric Laurent | b4f42a9 | 2022-01-17 17:37:31 +0100 | [diff] [blame] | 403 | const AudioDeviceTypeAddrVector &devices) const { |
| 404 | return canBeSpatializedInt(attr, config, devices); |
| 405 | } |
Eric Laurent | cad6c0d | 2021-07-13 15:12:39 +0200 | [diff] [blame] | 406 | |
Eric Laurent | fa0f674 | 2021-08-17 18:39:44 +0200 | [diff] [blame] | 407 | virtual status_t getSpatializerOutput(const audio_config_base_t *config, |
Eric Laurent | cad6c0d | 2021-07-13 15:12:39 +0200 | [diff] [blame] | 408 | const audio_attributes_t *attr, |
| 409 | audio_io_handle_t *output); |
| 410 | |
Eric Laurent | fa0f674 | 2021-08-17 18:39:44 +0200 | [diff] [blame] | 411 | virtual status_t releaseSpatializerOutput(audio_io_handle_t output); |
Eric Laurent | cad6c0d | 2021-07-13 15:12:39 +0200 | [diff] [blame] | 412 | |
jiabin | 2b9d5a1 | 2021-12-10 01:06:29 +0000 | [diff] [blame] | 413 | virtual audio_direct_mode_t getDirectPlaybackSupport(const audio_attributes_t *attr, |
| 414 | const audio_config_t *config); |
| 415 | |
Dorin Drimus | f2196d8 | 2022-01-03 12:11:18 +0100 | [diff] [blame] | 416 | virtual status_t getDirectProfilesForAttributes(const audio_attributes_t* attr, |
| 417 | AudioProfileVector& audioProfiles); |
| 418 | |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 419 | status_t getSupportedMixerAttributes( |
| 420 | audio_port_handle_t portId, |
| 421 | std::vector<audio_mixer_attributes_t>& mixerAttrs) override; |
| 422 | status_t setPreferredMixerAttributes( |
| 423 | const audio_attributes_t* attr, |
| 424 | audio_port_handle_t portId, |
| 425 | uid_t uid, |
| 426 | const audio_mixer_attributes_t* mixerAttributes) override; |
| 427 | status_t getPreferredMixerAttributes(const audio_attributes_t* attr, |
| 428 | audio_port_handle_t portId, |
| 429 | audio_mixer_attributes_t* mixerAttributes) override; |
| 430 | status_t clearPreferredMixerAttributes(const audio_attributes_t* attr, |
| 431 | audio_port_handle_t portId, |
| 432 | uid_t uid) override; |
| 433 | |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 434 | bool isCallScreenModeSupported() override; |
| 435 | |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 436 | void onNewAudioModulesAvailable() override; |
| 437 | |
Eric Laurent | caafba4 | 2019-07-13 10:12:45 -0700 | [diff] [blame] | 438 | status_t initialize(); |
| 439 | |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 440 | protected: |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 441 | const AudioPolicyConfig& getConfig() const { return *(mConfig.get()); } |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 442 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 443 | // From AudioPolicyManagerObserver |
| 444 | virtual const AudioPatchCollection &getAudioPatches() const |
| 445 | { |
| 446 | return mAudioPatches; |
| 447 | } |
| 448 | virtual const SoundTriggerSessionCollection &getSoundTriggerSessionCollection() const |
| 449 | { |
| 450 | return mSoundTriggerSessions; |
| 451 | } |
| 452 | virtual const AudioPolicyMixCollection &getAudioPolicyMixCollection() const |
| 453 | { |
| 454 | return mPolicyMixes; |
| 455 | } |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 456 | virtual const SwAudioOutputCollection &getOutputs() const |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 457 | { |
| 458 | return mOutputs; |
| 459 | } |
| 460 | virtual const AudioInputCollection &getInputs() const |
| 461 | { |
| 462 | return mInputs; |
| 463 | } |
Eric Laurent | af37777 | 2019-03-29 14:50:21 -0700 | [diff] [blame] | 464 | virtual const DeviceVector getAvailableOutputDevices() const |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 465 | { |
Kevin Rocard | e0d004f | 2019-10-10 10:06:18 +0000 | [diff] [blame] | 466 | return mAvailableOutputDevices.filterForEngine(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 467 | } |
Eric Laurent | af37777 | 2019-03-29 14:50:21 -0700 | [diff] [blame] | 468 | virtual const DeviceVector getAvailableInputDevices() const |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 469 | { |
Francois Gaffie | 698d353 | 2019-04-10 15:20:05 +0200 | [diff] [blame] | 470 | // legacy and non-legacy remote-submix are managed by the engine, do not filter |
| 471 | return mAvailableInputDevices; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 472 | } |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 473 | virtual const sp<DeviceDescriptor> &getDefaultOutputDevice() const |
| 474 | { |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 475 | return mConfig->getDefaultOutputDevice(); |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 476 | } |
Mikhail Naganov | d412014 | 2017-12-06 15:49:22 -0800 | [diff] [blame] | 477 | |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 478 | std::vector<volume_group_t> getVolumeGroups() const |
| 479 | { |
| 480 | return mEngine->getVolumeGroups(); |
| 481 | } |
| 482 | |
| 483 | VolumeSource toVolumeSource(volume_group_t volumeGroup) const |
| 484 | { |
| 485 | return static_cast<VolumeSource>(volumeGroup); |
| 486 | } |
Francois Gaffie | 4404ddb | 2021-02-04 17:03:38 +0100 | [diff] [blame] | 487 | /** |
| 488 | * @brief toVolumeSource converts an audio attributes into a volume source |
| 489 | * (either a legacy stream or a volume group). If fallback on default is allowed, and if |
| 490 | * the audio attributes do not follow any specific product strategy's rule, it will be |
| 491 | * associated to default volume source, e.g. music. Thus, any of call of volume API |
| 492 | * using this translation function may affect the default volume source. |
| 493 | * If fallback is not allowed and no matching rule is identified for the given attributes, |
| 494 | * the volume source will be undefined, thus, no volume will be altered/modified. |
| 495 | * @param attributes to be considered |
| 496 | * @param fallbackOnDefault |
| 497 | * @return volume source associated with given attributes, otherwise either music if |
| 498 | * fallbackOnDefault is set or none. |
| 499 | */ |
| 500 | VolumeSource toVolumeSource( |
| 501 | const audio_attributes_t &attributes, bool fallbackOnDefault = true) const |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 502 | { |
Francois Gaffie | 4404ddb | 2021-02-04 17:03:38 +0100 | [diff] [blame] | 503 | return toVolumeSource(mEngine->getVolumeGroupForAttributes( |
| 504 | attributes, fallbackOnDefault)); |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 505 | } |
Francois Gaffie | 4404ddb | 2021-02-04 17:03:38 +0100 | [diff] [blame] | 506 | VolumeSource toVolumeSource( |
| 507 | audio_stream_type_t stream, bool fallbackOnDefault = true) const |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 508 | { |
Francois Gaffie | 4404ddb | 2021-02-04 17:03:38 +0100 | [diff] [blame] | 509 | return toVolumeSource(mEngine->getVolumeGroupForStreamType( |
| 510 | stream, fallbackOnDefault)); |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 511 | } |
| 512 | IVolumeCurves &getVolumeCurves(VolumeSource volumeSource) |
| 513 | { |
| 514 | auto *curves = mEngine->getVolumeCurvesForVolumeGroup( |
| 515 | static_cast<volume_group_t>(volumeSource)); |
| 516 | ALOG_ASSERT(curves != nullptr, "No curves for volume source %d", volumeSource); |
| 517 | return *curves; |
| 518 | } |
Eric Laurent | f5aa58d | 2019-02-22 18:20:11 -0800 | [diff] [blame] | 519 | IVolumeCurves &getVolumeCurves(const audio_attributes_t &attr) |
| 520 | { |
| 521 | auto *curves = mEngine->getVolumeCurvesForAttributes(attr); |
| 522 | ALOG_ASSERT(curves != nullptr, "No curves for attributes %s", toString(attr).c_str()); |
| 523 | return *curves; |
| 524 | } |
| 525 | IVolumeCurves &getVolumeCurves(audio_stream_type_t stream) |
| 526 | { |
| 527 | auto *curves = mEngine->getVolumeCurvesForStreamType(stream); |
| 528 | ALOG_ASSERT(curves != nullptr, "No curves for stream %s", toString(stream).c_str()); |
| 529 | return *curves; |
| 530 | } |
| 531 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 532 | void addOutput(audio_io_handle_t output, const sp<SwAudioOutputDescriptor>& outputDesc); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 533 | void removeOutput(audio_io_handle_t output); |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 534 | void addInput(audio_io_handle_t input, const sp<AudioInputDescriptor>& inputDesc); |
Mikhail Naganov | c66ffc1 | 2024-05-30 16:56:25 -0700 | [diff] [blame] | 535 | bool checkCloseInput(const sp<AudioInputDescriptor>& input); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 536 | |
Francois Gaffie | 3523ab3 | 2021-06-22 13:24:34 +0200 | [diff] [blame] | 537 | /** |
| 538 | * @brief setOutputDevices change the route of the specified output. |
Jaideep Sharma | 4b5c425 | 2023-07-27 14:47:32 +0530 | [diff] [blame] | 539 | * @param caller of the method |
Francois Gaffie | 3523ab3 | 2021-06-22 13:24:34 +0200 | [diff] [blame] | 540 | * @param outputDesc to be considered |
| 541 | * @param device to be considered to route the output |
| 542 | * @param force if true, force the routing even if no change. |
| 543 | * @param delayMs if specified, delay to apply for mute/volume op when changing device |
| 544 | * @param patchHandle if specified, the patch handle this output is connected through. |
| 545 | * @param requiresMuteCheck if specified, for e.g. when another output is on a shared device |
| 546 | * and currently active, allow to have proper drain and avoid pops |
| 547 | * @param requiresVolumeCheck true if called requires to reapply volume if the routing did |
| 548 | * not change (but the output is still routed). |
Oscar Azucena | 2995655 | 2023-04-27 16:32:09 -0700 | [diff] [blame] | 549 | * @param skipMuteDelay if true will skip mute delay when installing audio patch |
Francois Gaffie | 3523ab3 | 2021-06-22 13:24:34 +0200 | [diff] [blame] | 550 | * @return the number of ms we have slept to allow new routing to take effect in certain |
Oscar Azucena | 2995655 | 2023-04-27 16:32:09 -0700 | [diff] [blame] | 551 | * cases. |
Francois Gaffie | 3523ab3 | 2021-06-22 13:24:34 +0200 | [diff] [blame] | 552 | */ |
Jaideep Sharma | 4b5c425 | 2023-07-27 14:47:32 +0530 | [diff] [blame] | 553 | uint32_t setOutputDevices(const char *caller, |
| 554 | const sp<SwAudioOutputDescriptor>& outputDesc, |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 555 | const DeviceVector &device, |
| 556 | bool force = false, |
| 557 | int delayMs = 0, |
| 558 | audio_patch_handle_t *patchHandle = NULL, |
Francois Gaffie | 3523ab3 | 2021-06-22 13:24:34 +0200 | [diff] [blame] | 559 | bool requiresMuteCheck = true, |
Oscar Azucena | 2995655 | 2023-04-27 16:32:09 -0700 | [diff] [blame] | 560 | bool requiresVolumeCheck = false, |
| 561 | bool skipMuteDelay = false); |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 562 | status_t resetOutputDevice(const sp<AudioOutputDescriptor>& outputDesc, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 563 | int delayMs = 0, |
| 564 | audio_patch_handle_t *patchHandle = NULL); |
| 565 | status_t setInputDevice(audio_io_handle_t input, |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 566 | const sp<DeviceDescriptor> &device, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 567 | bool force = false, |
| 568 | audio_patch_handle_t *patchHandle = NULL); |
| 569 | status_t resetInputDevice(audio_io_handle_t input, |
| 570 | audio_patch_handle_t *patchHandle = NULL); |
| 571 | |
Oscar Azucena | e763f7a | 2024-03-27 18:56:02 -0700 | [diff] [blame] | 572 | /** |
| 573 | * Compute volume in DB that should be applied for a volume source and device types for a |
| 574 | * particular volume index. |
| 575 | * |
| 576 | * <p><b>Note:</b>Internally the compute method recursively calls itself to accurately |
| 577 | * determine the volume given the currently active sources and devices. Some of the |
| 578 | * interaction that require recursive computation are: |
| 579 | * <ul> |
| 580 | * <li>Match accessibility volume if ringtone volume is much louder</li> |
| 581 | * <li>If voice call is active cap other volumes (except ringtone and accessibility)</li> |
| 582 | * <li>Attenuate notification if headset is connected to prevent burst in user's ear</li> |
| 583 | * <li>Attenuate ringtone if headset is connected and music is not playing and speaker is |
| 584 | * part of the devices to prevent burst in user's ear</li> |
| 585 | * <li>Limit music volume if headset is connected and notification is also active</li> |
| 586 | * </ul> |
| 587 | * |
| 588 | * @param curves volume curves to use for calculating volume value given the index |
| 589 | * @param volumeSource source (use case) of the volume |
| 590 | * @param index index to match in the volume curves for the calculation |
| 591 | * @param deviceTypes devices that should be considered in the volume curves for the |
| 592 | * calculation |
| 593 | * @param computeInternalInteraction boolean indicating whether recursive volume computation |
| 594 | * should continue within the volume computation. Defaults to {@code true} so the |
| 595 | * volume interactions can be computed. Calls within the method should always set the |
| 596 | * the value to {@code false} to prevent infinite recursion. |
| 597 | * @return computed volume in DB |
| 598 | */ |
| 599 | virtual float computeVolume(IVolumeCurves &curves, VolumeSource volumeSource, |
| 600 | int index, const DeviceTypeSet& deviceTypes, |
| 601 | bool computeInternalInteraction = true); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 602 | |
Eric Laurent | 3839bc0 | 2018-07-10 18:33:34 -0700 | [diff] [blame] | 603 | // rescale volume index from srcStream within range of dstStream |
| 604 | int rescaleVolumeIndex(int srcIndex, |
Francois Gaffie | 2ffdfce | 2019-03-12 11:26:42 +0100 | [diff] [blame] | 605 | VolumeSource fromVolumeSource, |
| 606 | VolumeSource toVolumeSource); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 607 | // check that volume change is permitted, compute and send new volume to audio hardware |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 608 | virtual status_t checkAndSetVolume(IVolumeCurves &curves, |
| 609 | VolumeSource volumeSource, int index, |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 610 | const sp<AudioOutputDescriptor>& outputDesc, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 611 | DeviceTypeSet deviceTypes, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 612 | int delayMs = 0, bool force = false); |
| 613 | |
Eric Laurent | ae6e88c | 2024-01-10 14:42:57 +0100 | [diff] [blame] | 614 | void setVoiceVolume(int index, IVolumeCurves &curves, bool isVoiceVolSrc, int delayMs); |
| 615 | |
| 616 | // returns true if the supplied set of volume source and devices are consistent with |
| 617 | // call volume rules: |
| 618 | // if Bluetooth SCO and voice call use different volume curves: |
| 619 | // - do not apply voice call volume if Bluetooth SCO is used for call |
| 620 | // - do not apply Bluetooth SCO volume if SCO or Hearing Aid is not used for call. |
| 621 | // Also updates the booleans isVoiceVolSrc and isBtScoVolSrc according to the |
| 622 | // volume source supplied. |
| 623 | bool isVolumeConsistentForCalls(VolumeSource volumeSource, |
| 624 | const DeviceTypeSet& deviceTypes, |
| 625 | bool& isVoiceVolSrc, |
| 626 | bool& isBtScoVolSrc, |
| 627 | const char* caller); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 628 | // apply all stream volumes to the specified output and device |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 629 | void applyStreamVolumes(const sp<AudioOutputDescriptor>& outputDesc, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 630 | const DeviceTypeSet& deviceTypes, |
| 631 | int delayMs = 0, bool force = false); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 632 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 633 | /** |
| 634 | * @brief setStrategyMute Mute or unmute all active clients on the considered output |
| 635 | * following the given strategy. |
| 636 | * @param strategy to be considered |
| 637 | * @param on true for mute, false for unmute |
| 638 | * @param outputDesc to be considered |
| 639 | * @param delayMs |
| 640 | * @param device |
| 641 | */ |
| 642 | void setStrategyMute(product_strategy_t strategy, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 643 | bool on, |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 644 | const sp<AudioOutputDescriptor>& outputDesc, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 645 | int delayMs = 0, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 646 | DeviceTypeSet deviceTypes = DeviceTypeSet()); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 647 | |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 648 | /** |
| 649 | * @brief setVolumeSourceMute Mute or unmute the volume source on the specified output |
| 650 | * @param volumeSource to be muted/unmute (may host legacy streams or by extension set of |
| 651 | * audio attributes) |
| 652 | * @param on true to mute, false to umute |
| 653 | * @param outputDesc on which the client following the volume group shall be muted/umuted |
| 654 | * @param delayMs |
| 655 | * @param device |
François Gaffie | aaac0fd | 2018-11-22 17:56:39 +0100 | [diff] [blame] | 656 | */ |
| 657 | void setVolumeSourceMute(VolumeSource volumeSource, |
| 658 | bool on, |
| 659 | const sp<AudioOutputDescriptor>& outputDesc, |
| 660 | int delayMs = 0, |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 661 | DeviceTypeSet deviceTypes = DeviceTypeSet()); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 662 | |
Jean-Michel Trivi | 887a9ed | 2015-03-31 18:02:24 -0700 | [diff] [blame] | 663 | audio_mode_t getPhoneState(); |
| 664 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 665 | // true if device is in a telephony or VoIP call |
Eric Laurent | 96d1dda | 2022-03-14 17:14:19 +0100 | [diff] [blame] | 666 | virtual bool isInCall() const; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 667 | // true if given state represents a device in a telephony or VoIP call |
Eric Laurent | 96d1dda | 2022-03-14 17:14:19 +0100 | [diff] [blame] | 668 | virtual bool isStateInCall(int state) const; |
Eric Laurent | 74b7151 | 2019-11-06 17:21:57 -0800 | [diff] [blame] | 669 | // true if playback to call TX or capture from call RX is possible |
Eric Laurent | f9cccec | 2022-11-16 19:12:00 +0100 | [diff] [blame] | 670 | bool isCallAudioAccessible() const; |
| 671 | // true if device is in a telephony or VoIP call or call screening is active |
| 672 | bool isInCallOrScreening() const; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 673 | |
| 674 | // when a device is connected, checks if an open output can be routed |
| 675 | // to this device. If none is open, tries to open one of the available outputs. |
| 676 | // Returns an output suitable to this device or 0. |
| 677 | // when a device is disconnected, checks if an output is not used any more and |
| 678 | // returns its handle if any. |
| 679 | // transfers the audio tracks and effects from one output thread to another accordingly. |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 680 | status_t checkOutputsForDevice(const sp<DeviceDescriptor>& device, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 681 | audio_policy_dev_state_t state, |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 682 | SortedVector<audio_io_handle_t>& outputs); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 683 | |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 684 | status_t checkInputsForDevice(const sp<DeviceDescriptor>& device, |
Eric Laurent | 0dd5185 | 2019-04-19 18:18:58 -0700 | [diff] [blame] | 685 | audio_policy_dev_state_t state); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 686 | |
| 687 | // close an output and its companion duplicating output. |
| 688 | void closeOutput(audio_io_handle_t output); |
| 689 | |
| 690 | // close an input. |
| 691 | void closeInput(audio_io_handle_t input); |
| 692 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 693 | // runs all the checks required for accommodating changes in devices and outputs |
Mikhail Naganov | 3797715 | 2018-07-11 15:54:44 -0700 | [diff] [blame] | 694 | // if 'onOutputsChecked' callback is provided, it is executed after the outputs |
| 695 | // check via 'checkOutputForAllStrategies'. If the callback returns 'true', |
| 696 | // A2DP suspend status is rechecked. |
Mikhail Naganov | 15be9d2 | 2017-11-08 14:18:13 +1100 | [diff] [blame] | 697 | void checkForDeviceAndOutputChanges(std::function<bool()> onOutputsChecked = nullptr); |
Mikhail Naganov | 3797715 | 2018-07-11 15:54:44 -0700 | [diff] [blame] | 698 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 699 | /** |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 700 | * @brief updates routing for all outputs (including call if call in progress). |
| 701 | * @param delayMs delay for unmuting if required |
Oscar Azucena | 2995655 | 2023-04-27 16:32:09 -0700 | [diff] [blame] | 702 | * @param skipDelays if true all the delays will be skip while updating routing |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 703 | */ |
Oscar Azucena | 2995655 | 2023-04-27 16:32:09 -0700 | [diff] [blame] | 704 | void updateCallAndOutputRouting(bool forceVolumeReeval = true, uint32_t delayMs = 0, |
| 705 | bool skipDelays = false); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 706 | |
David Li | 48b6a83 | 2024-07-01 13:14:10 +0000 | [diff] [blame] | 707 | void connectTelephonyRxAudioSource(uint32_t delayMs); |
Francois Gaffie | 51c9ccd | 2020-10-14 18:02:07 +0200 | [diff] [blame] | 708 | |
Francois Gaffie | 601801d | 2021-06-22 13:27:39 +0200 | [diff] [blame] | 709 | void disconnectTelephonyAudioSource(sp<SourceClientDescriptor> &clientDesc); |
Francois Gaffie | b2e5cb5 | 2021-06-22 13:16:09 +0200 | [diff] [blame] | 710 | |
| 711 | void connectTelephonyTxAudioSource(const sp<DeviceDescriptor> &srcdevice, |
| 712 | const sp<DeviceDescriptor> &sinkDevice, |
| 713 | uint32_t delayMs); |
| 714 | |
Francois Gaffie | 601801d | 2021-06-22 13:27:39 +0200 | [diff] [blame] | 715 | bool isTelephonyRxOrTx(const sp<SwAudioOutputDescriptor>& desc) const { |
| 716 | return (mCallRxSourceClient != nullptr && mCallRxSourceClient->belongsToOutput(desc)) |
| 717 | || (mCallTxSourceClient != nullptr |
| 718 | && mCallTxSourceClient->belongsToOutput(desc)); |
| 719 | } |
Francois Gaffie | 51c9ccd | 2020-10-14 18:02:07 +0200 | [diff] [blame] | 720 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 721 | /** |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 722 | * @brief updates routing for all inputs. |
| 723 | */ |
| 724 | void updateInputRouting(); |
| 725 | |
| 726 | /** |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 727 | * @brief checkOutputForAttributes checks and if necessary changes outputs used for the |
| 728 | * given audio attributes. |
| 729 | * must be called every time a condition that affects the output choice for a given |
| 730 | * attributes changes: connected device, phone state, force use... |
| 731 | * Must be called before updateDevicesAndOutputs() |
| 732 | * @param attr to be considered |
| 733 | */ |
| 734 | void checkOutputForAttributes(const audio_attributes_t &attr); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 735 | |
Francois Gaffie | ff1eb52 | 2020-05-06 18:37:04 +0200 | [diff] [blame] | 736 | /** |
| 737 | * @brief checkAudioSourceForAttributes checks if any AudioSource following the same routing |
| 738 | * as the given audio attributes is not routed and try to connect it. |
| 739 | * It must be called once checkOutputForAttributes has been called for orphans AudioSource, |
| 740 | * aka AudioSource not attached to any Audio Output (e.g. AudioSource connected to direct |
| 741 | * Output which has been disconnected (and output closed) due to sink device unavailable). |
| 742 | * @param attr to be considered |
| 743 | */ |
| 744 | void checkAudioSourceForAttributes(const audio_attributes_t &attr); |
| 745 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 746 | bool followsSameRouting(const audio_attributes_t &lAttr, |
| 747 | const audio_attributes_t &rAttr) const; |
| 748 | |
| 749 | /** |
| 750 | * @brief checkOutputForAllStrategies Same as @see checkOutputForAttributes() |
| 751 | * but for a all product strategies in order of priority |
| 752 | */ |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 753 | void checkOutputForAllStrategies(); |
| 754 | |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 755 | // Same as checkOutputForStrategy but for secondary outputs. Make sure if a secondary |
| 756 | // output condition changes, the track is properly rerouted |
| 757 | void checkSecondaryOutputs(); |
| 758 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 759 | // manages A2DP output suspend/restore according to phone state and BT SCO usage |
| 760 | void checkA2dpSuspend(); |
| 761 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 762 | // selects the most appropriate device on output for current state |
| 763 | // must be called every time a condition that affects the device choice for a given output is |
| 764 | // changed: connected device, phone state, force use, output start, output stop.. |
| 765 | // see getDeviceForStrategy() for the use of fromCache parameter |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 766 | DeviceVector getNewOutputDevices(const sp<SwAudioOutputDescriptor>& outputDesc, |
| 767 | bool fromCache); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 768 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 769 | /** |
| 770 | * @brief updateDevicesAndOutputs: updates cache of devices of the engine |
| 771 | * must be called every time a condition that affects the device choice is changed: |
| 772 | * connected device, phone state, force use... |
| 773 | * cached values are used by getOutputDevicesForStream()/getDevicesForAttributes if |
| 774 | * parameter fromCache is true. |
| 775 | * Must be called after checkOutputForAllStrategies() |
| 776 | */ |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 777 | void updateDevicesAndOutputs(); |
| 778 | |
| 779 | // selects the most appropriate device on input for current state |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 780 | sp<DeviceDescriptor> getNewInputDevice(const sp<AudioInputDescriptor>& inputDesc); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 781 | |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 782 | virtual uint32_t getMaxEffectsCpuLoad() |
| 783 | { |
| 784 | return mEffects.getMaxEffectsCpuLoad(); |
| 785 | } |
| 786 | |
| 787 | virtual uint32_t getMaxEffectsMemory() |
| 788 | { |
| 789 | return mEffects.getMaxEffectsMemory(); |
| 790 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 791 | |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 792 | SortedVector<audio_io_handle_t> getOutputsForDevices( |
| 793 | const DeviceVector &devices, const SwAudioOutputCollection& openOutputs); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 794 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 795 | /** |
| 796 | * @brief checkDeviceMuteStrategies mute/unmute strategies |
| 797 | * using an incompatible device combination. |
| 798 | * if muting, wait for the audio in pcm buffer to be drained before proceeding |
| 799 | * if unmuting, unmute only after the specified delay |
| 800 | * @param outputDesc |
| 801 | * @param prevDevice |
| 802 | * @param delayMs |
| 803 | * @return the number of ms waited |
| 804 | */ |
| 805 | virtual uint32_t checkDeviceMuteStrategies(const sp<AudioOutputDescriptor>& outputDesc, |
| 806 | const DeviceVector &prevDevices, |
| 807 | uint32_t delayMs); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 808 | |
| 809 | audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs, |
jiabin | 4057332 | 2018-11-08 12:08:02 -0800 | [diff] [blame] | 810 | audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, |
| 811 | audio_format_t format = AUDIO_FORMAT_INVALID, |
| 812 | audio_channel_mask_t channelMask = AUDIO_CHANNEL_NONE, |
jiabin | ebb6af4 | 2020-06-09 17:31:17 -0700 | [diff] [blame] | 813 | uint32_t samplingRate = 0, |
| 814 | audio_session_t sessionId = AUDIO_SESSION_NONE); |
Andy Hung | f129b03 | 2015-04-07 13:45:50 -0700 | [diff] [blame] | 815 | // samplingRate, format, channelMask are in/out and so may be modified |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 816 | sp<IOProfile> getInputProfile(const sp<DeviceDescriptor> & device, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 817 | uint32_t& samplingRate, |
Andy Hung | f129b03 | 2015-04-07 13:45:50 -0700 | [diff] [blame] | 818 | audio_format_t& format, |
| 819 | audio_channel_mask_t& channelMask, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 820 | audio_input_flags_t flags); |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 821 | /** |
| 822 | * @brief getProfileForOutput |
| 823 | * @param devices vector of descriptors, may be empty if ignoring the device is required |
| 824 | * @param samplingRate |
| 825 | * @param format |
| 826 | * @param channelMask |
| 827 | * @param flags |
| 828 | * @param directOnly |
| 829 | * @return IOProfile to be used if found, nullptr otherwise |
| 830 | */ |
| 831 | sp<IOProfile> getProfileForOutput(const DeviceVector &devices, |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 832 | uint32_t samplingRate, |
| 833 | audio_format_t format, |
| 834 | audio_channel_mask_t channelMask, |
| 835 | audio_output_flags_t flags, |
| 836 | bool directOnly); |
Dorin Drimus | ecc9f42 | 2022-03-09 17:57:40 +0100 | [diff] [blame] | 837 | /** |
| 838 | * Same as getProfileForOutput, but it looks for an MSD profile |
| 839 | */ |
| 840 | sp<IOProfile> getMsdProfileForOutput(const DeviceVector &devices, |
| 841 | uint32_t samplingRate, |
| 842 | audio_format_t format, |
| 843 | audio_channel_mask_t channelMask, |
| 844 | audio_output_flags_t flags, |
| 845 | bool directOnly); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 846 | |
Eric Laurent | 36829f9 | 2017-04-07 19:04:42 -0700 | [diff] [blame] | 847 | audio_io_handle_t selectOutputForMusicEffects(); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 848 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 849 | virtual status_t addAudioPatch(audio_patch_handle_t handle, const sp<AudioPatch>& patch) |
| 850 | { |
| 851 | return mAudioPatches.addAudioPatch(handle, patch); |
| 852 | } |
| 853 | virtual status_t removeAudioPatch(audio_patch_handle_t handle) |
| 854 | { |
| 855 | return mAudioPatches.removeAudioPatch(handle); |
| 856 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 857 | |
François Gaffie | 9eb1855 | 2018-11-05 10:33:26 +0100 | [diff] [blame] | 858 | bool isPrimaryModule(const sp<HwModule> &module) const |
| 859 | { |
François Gaffie | db1755b | 2023-09-01 11:50:35 +0200 | [diff] [blame] | 860 | if (module == nullptr || mPrimaryModuleHandle == AUDIO_MODULE_HANDLE_NONE) { |
François Gaffie | 9eb1855 | 2018-11-05 10:33:26 +0100 | [diff] [blame] | 861 | return false; |
| 862 | } |
François Gaffie | db1755b | 2023-09-01 11:50:35 +0200 | [diff] [blame] | 863 | return module->getHandle() == mPrimaryModuleHandle; |
François Gaffie | 9eb1855 | 2018-11-05 10:33:26 +0100 | [diff] [blame] | 864 | } |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 865 | DeviceVector availablePrimaryOutputDevices() const |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 866 | { |
Eric Laurent | 87ffa39 | 2015-05-22 10:32:38 -0700 | [diff] [blame] | 867 | if (!hasPrimaryOutput()) { |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 868 | return DeviceVector(); |
Eric Laurent | 87ffa39 | 2015-05-22 10:32:38 -0700 | [diff] [blame] | 869 | } |
Francois Gaffie | 716e143 | 2019-01-14 16:58:59 +0100 | [diff] [blame] | 870 | return mAvailableOutputDevices.filter(mPrimaryOutput->supportedDevices()); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 871 | } |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 872 | DeviceVector availablePrimaryModuleInputDevices() const |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 873 | { |
Eric Laurent | 87ffa39 | 2015-05-22 10:32:38 -0700 | [diff] [blame] | 874 | if (!hasPrimaryOutput()) { |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 875 | return DeviceVector(); |
Eric Laurent | 87ffa39 | 2015-05-22 10:32:38 -0700 | [diff] [blame] | 876 | } |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 877 | return mAvailableInputDevices.getDevicesFromHwModule( |
Mikhail Naganov | 9366193 | 2018-07-26 14:37:41 -0700 | [diff] [blame] | 878 | mPrimaryOutput->getModuleHandle()); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 879 | } |
François Gaffie | aca677c | 2018-05-03 10:47:50 +0200 | [diff] [blame] | 880 | /** |
| 881 | * @brief getFirstDeviceId of the Device Vector |
| 882 | * @return if the collection is not empty, it returns the first device Id, |
| 883 | * otherwise AUDIO_PORT_HANDLE_NONE |
| 884 | */ |
| 885 | audio_port_handle_t getFirstDeviceId(const DeviceVector &devices) const |
| 886 | { |
| 887 | return (devices.size() > 0) ? devices.itemAt(0)->getId() : AUDIO_PORT_HANDLE_NONE; |
| 888 | } |
| 889 | String8 getFirstDeviceAddress(const DeviceVector &devices) const |
| 890 | { |
jiabin | ce9f20e | 2019-09-12 16:29:15 -0700 | [diff] [blame] | 891 | return (devices.size() > 0) ? |
| 892 | String8(devices.itemAt(0)->address().c_str()) : String8(""); |
François Gaffie | aca677c | 2018-05-03 10:47:50 +0200 | [diff] [blame] | 893 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 894 | |
Francois Gaffie | 19fd6c5 | 2021-02-04 17:02:59 +0100 | [diff] [blame] | 895 | status_t updateCallRouting( |
| 896 | bool fromCache, uint32_t delayMs = 0, uint32_t *waitMs = nullptr); |
| 897 | status_t updateCallRoutingInternal( |
| 898 | const DeviceVector &rxDevices, uint32_t delayMs, uint32_t *waitMs); |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 899 | sp<AudioPatch> createTelephonyPatch(bool isRx, const sp<DeviceDescriptor> &device, |
| 900 | uint32_t delayMs); |
Francois Gaffie | 19fd6c5 | 2021-02-04 17:02:59 +0100 | [diff] [blame] | 901 | /** |
| 902 | * @brief selectBestRxSinkDevicesForCall: if the primary module host both Telephony Rx/Tx |
| 903 | * devices, and it declares also supporting a HW bridge between the Telephony Rx and the |
| 904 | * given sink device for Voice Call audio attributes, select this device in prio. |
| 905 | * Otherwise, getNewOutputDevices() is called on the primary output to select sink device. |
| 906 | * @param fromCache true to prevent engine reconsidering all product strategies and retrieve |
| 907 | * from engine cache. |
| 908 | * @return vector of devices, empty if none is found. |
| 909 | */ |
| 910 | DeviceVector selectBestRxSinkDevicesForCall(bool fromCache); |
Mikhail Naganov | 100f012 | 2018-11-29 11:22:16 -0800 | [diff] [blame] | 911 | bool isDeviceOfModule(const sp<DeviceDescriptor>& devDesc, const char *moduleId) const; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 912 | |
Eric Laurent | 97ac871 | 2018-07-27 18:59:02 -0700 | [diff] [blame] | 913 | status_t startSource(const sp<SwAudioOutputDescriptor>& outputDesc, |
| 914 | const sp<TrackClientDescriptor>& client, |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 915 | uint32_t *delayMs); |
Eric Laurent | 97ac871 | 2018-07-27 18:59:02 -0700 | [diff] [blame] | 916 | status_t stopSource(const sp<SwAudioOutputDescriptor>& outputDesc, |
| 917 | const sp<TrackClientDescriptor>& client); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 918 | |
| 919 | void clearAudioPatches(uid_t uid); |
| 920 | void clearSessionRoutes(uid_t uid); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 921 | |
| 922 | /** |
| 923 | * @brief checkStrategyRoute: when an output is beeing rerouted, reconsider each output |
| 924 | * that may host a strategy playing on the considered output. |
| 925 | * @param ps product strategy that initiated the rerouting |
| 926 | * @param ouptutToSkip output that initiated the rerouting |
| 927 | */ |
| 928 | void checkStrategyRoute(product_strategy_t ps, audio_io_handle_t ouptutToSkip); |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 929 | |
Eric Laurent | 87ffa39 | 2015-05-22 10:32:38 -0700 | [diff] [blame] | 930 | status_t hasPrimaryOutput() const { return mPrimaryOutput != 0; } |
| 931 | |
David Li | 48b6a83 | 2024-07-01 13:14:10 +0000 | [diff] [blame] | 932 | status_t connectAudioSource(const sp<SourceClientDescriptor>& sourceDesc, |
| 933 | uint32_t delayMs); |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 934 | status_t disconnectAudioSource(const sp<SourceClientDescriptor>& sourceDesc); |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 935 | |
Francois Gaffie | b2e5cb5 | 2021-06-22 13:16:09 +0200 | [diff] [blame] | 936 | status_t connectAudioSourceToSink(const sp<SourceClientDescriptor>& sourceDesc, |
| 937 | const sp<DeviceDescriptor> &sinkDevice, |
| 938 | const struct audio_patch *patch, |
| 939 | audio_patch_handle_t &handle, |
| 940 | uid_t uid, uint32_t delayMs); |
| 941 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 942 | sp<SourceClientDescriptor> getSourceForAttributesOnOutput(audio_io_handle_t output, |
| 943 | const audio_attributes_t &attr); |
Francois Gaffie | ff1eb52 | 2020-05-06 18:37:04 +0200 | [diff] [blame] | 944 | void clearAudioSourcesForOutput(audio_io_handle_t output); |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 945 | |
| 946 | void cleanUpForDevice(const sp<DeviceDescriptor>& deviceDesc); |
| 947 | |
| 948 | void clearAudioSources(uid_t uid); |
| 949 | |
Eric Laurent | 794fde2 | 2016-03-11 09:50:45 -0800 | [diff] [blame] | 950 | static bool streamsMatchForvolume(audio_stream_type_t stream1, |
| 951 | audio_stream_type_t stream2); |
Eric Laurent | 28d09f0 | 2016-03-08 10:43:05 -0800 | [diff] [blame] | 952 | |
Eric Laurent | 8f42ea1 | 2018-08-08 09:08:25 -0700 | [diff] [blame] | 953 | void closeActiveClients(const sp<AudioInputDescriptor>& input); |
| 954 | void closeClient(audio_port_handle_t portId); |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 955 | |
Eric Laurent | 96d1dda | 2022-03-14 17:14:19 +0100 | [diff] [blame] | 956 | /** |
| 957 | * @brief isAnyDeviceTypeActive: returns true if at least one active client is routed to |
| 958 | * one of the specified devices |
| 959 | * @param deviceTypes list of devices to consider |
| 960 | */ |
| 961 | bool isAnyDeviceTypeActive(const DeviceTypeSet& deviceTypes) const; |
| 962 | /** |
| 963 | * @brief isLeUnicastActive: returns true if a call is active or at least one active client |
| 964 | * is routed to a LE unicast device |
| 965 | */ |
| 966 | bool isLeUnicastActive() const; |
| 967 | |
| 968 | void checkLeBroadcastRoutes(bool wasUnicastActive, |
| 969 | sp<SwAudioOutputDescriptor> ignoredOutput, uint32_t delayMs); |
| 970 | |
Eric Laurent | 963dbcc | 2024-06-20 12:34:15 +0000 | [diff] [blame] | 971 | status_t startAudioSourceInternal(const struct audio_port_config *source, |
| 972 | const audio_attributes_t *attributes, |
| 973 | audio_port_handle_t *portId, |
| 974 | uid_t uid, |
| 975 | bool internal, |
David Li | 48b6a83 | 2024-07-01 13:14:10 +0000 | [diff] [blame] | 976 | bool isCallRx, |
| 977 | uint32_t delayMs); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 978 | const uid_t mUidCached; // AID_AUDIOSERVER |
Mikhail Naganov | 68e3f64 | 2023-04-28 13:06:32 -0700 | [diff] [blame] | 979 | sp<const AudioPolicyConfig> mConfig; |
Mikhail Naganov | f1b6d97 | 2023-05-02 13:56:01 -0700 | [diff] [blame] | 980 | EngineInstance mEngine; // Audio Policy Engine instance |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 981 | AudioPolicyClientInterface *mpClientInterface; // audio policy client interface |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 982 | sp<SwAudioOutputDescriptor> mPrimaryOutput; // primary output descriptor |
François Gaffie | db1755b | 2023-09-01 11:50:35 +0200 | [diff] [blame] | 983 | // mPrimaryModuleHandle is cached mPrimaryOutput->getModuleHandle(); |
| 984 | audio_module_handle_t mPrimaryModuleHandle = AUDIO_MODULE_HANDLE_NONE; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 985 | // list of descriptors for outputs currently opened |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 986 | |
Eric Laurent | fa0f674 | 2021-08-17 18:39:44 +0200 | [diff] [blame] | 987 | sp<SwAudioOutputDescriptor> mSpatializerOutput; |
Eric Laurent | cad6c0d | 2021-07-13 15:12:39 +0200 | [diff] [blame] | 988 | |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 989 | SwAudioOutputCollection mOutputs; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 990 | // copy of mOutputs before setDeviceConnectionState() opens new outputs |
| 991 | // reset to mOutputs when updateDevicesAndOutputs() is called. |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 992 | SwAudioOutputCollection mPreviousOutputs; |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 993 | AudioInputCollection mInputs; // list of input descriptors |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 994 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 995 | DeviceVector mAvailableOutputDevices; // all available output devices |
| 996 | DeviceVector mAvailableInputDevices; // all available input devices |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 997 | |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 998 | bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 999 | |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 1000 | float mLastVoiceVolume; // last voice volume value sent to audio HAL |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1001 | bool mA2dpSuspended; // true if A2DP output is suspended |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 1002 | |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 1003 | EffectDescriptorCollection mEffects; // list of registered audio effects |
Mikhail Naganov | c0d0498 | 2020-03-02 21:02:28 +0000 | [diff] [blame] | 1004 | HwModuleCollection mHwModules; // contains modules that have been loaded successfully |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1005 | |
Mikhail Naganov | 2773dd7 | 2017-12-08 10:12:11 -0800 | [diff] [blame] | 1006 | std::atomic<uint32_t> mAudioPortGeneration; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1007 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 1008 | AudioPatchCollection mAudioPatches; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1009 | |
François Gaffie | df37269 | 2015-03-19 10:43:27 +0100 | [diff] [blame] | 1010 | SoundTriggerSessionCollection mSoundTriggerSessions; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1011 | |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 1012 | HwAudioOutputCollection mHwOutputs; |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1013 | SourceClientCollection mAudioSources; |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 1014 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1015 | // for supporting "beacon" streams, i.e. streams that only play on speaker, and never |
| 1016 | // when something other than STREAM_TTS (a.k.a. "Transmitted Through Speaker") is playing |
| 1017 | enum { |
| 1018 | STARTING_OUTPUT, |
| 1019 | STARTING_BEACON, |
| 1020 | STOPPING_OUTPUT, |
| 1021 | STOPPING_BEACON |
| 1022 | }; |
| 1023 | uint32_t mBeaconMuteRefCount; // ref count for stream that would mute beacon |
| 1024 | uint32_t mBeaconPlayingRefCount;// ref count for the playing beacon streams |
| 1025 | bool mBeaconMuted; // has STREAM_TTS been muted |
Carter Hsu | 1a3364a | 2022-01-21 15:32:56 +0800 | [diff] [blame] | 1026 | // true if a dedicated output for TTS stream or Ultrasound is available |
| 1027 | bool mTtsOutputAvailable; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1028 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1029 | bool mMasterMono; // true if we wish to force all outputs to mono |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 1030 | AudioPolicyMixCollection mPolicyMixes; // list of registered mixes |
Eric Laurent | 36829f9 | 2017-04-07 19:04:42 -0700 | [diff] [blame] | 1031 | audio_io_handle_t mMusicEffectOutput; // output selected for music effects |
| 1032 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1033 | uint32_t nextAudioPortGeneration(); |
Jean-Michel Trivi | 887a9ed | 2015-03-31 18:02:24 -0700 | [diff] [blame] | 1034 | |
Mikhail Naganov | 100f012 | 2018-11-29 11:22:16 -0800 | [diff] [blame] | 1035 | // Surround formats that are enabled manually. Taken into account when |
| 1036 | // "encoded surround" is forced into "manual" mode. |
| 1037 | std::unordered_set<audio_format_t> mManualSurroundFormats; |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1038 | |
| 1039 | std::unordered_map<uid_t, audio_flags_mask_t> mAllowedCapturePolicies; |
Kriti Dang | ef6be8f | 2020-11-05 11:58:19 +0100 | [diff] [blame] | 1040 | |
| 1041 | // The map of device descriptor and formats reported by the device. |
| 1042 | std::map<wp<DeviceDescriptor>, FormatVector> mReportedFormatsMap; |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 1043 | |
| 1044 | // Cached product strategy ID corresponding to legacy strategy STRATEGY_PHONE |
| 1045 | product_strategy_t mCommunnicationStrategy; |
| 1046 | |
Francois Gaffie | 51c9ccd | 2020-10-14 18:02:07 +0200 | [diff] [blame] | 1047 | // The port handle of the hardware audio source created internally for the Call RX audio |
| 1048 | // end point. |
Francois Gaffie | 601801d | 2021-06-22 13:27:39 +0200 | [diff] [blame] | 1049 | sp<SourceClientDescriptor> mCallRxSourceClient; |
| 1050 | sp<SourceClientDescriptor> mCallTxSourceClient; |
Francois Gaffie | 51c9ccd | 2020-10-14 18:02:07 +0200 | [diff] [blame] | 1051 | |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 1052 | std::map<audio_port_handle_t, |
| 1053 | std::map<product_strategy_t, |
| 1054 | sp<PreferredMixerAttributesInfo>>> mPreferredMixerAttrInfos; |
| 1055 | |
Mikhail Naganov | 15be9d2 | 2017-11-08 14:18:13 +1100 | [diff] [blame] | 1056 | // Support for Multi-Stream Decoder (MSD) module |
| 1057 | sp<DeviceDescriptor> getMsdAudioInDevice() const; |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 1058 | DeviceVector getMsdAudioOutDevices() const; |
Dean Wheatley | 8bee85a | 2021-02-10 16:02:23 +1100 | [diff] [blame] | 1059 | const AudioPatchCollection getMsdOutputPatches() const; |
| 1060 | status_t getMsdProfiles(bool hwAvSync, |
| 1061 | const InputProfileCollection &inputProfiles, |
| 1062 | const OutputProfileCollection &outputProfiles, |
| 1063 | const sp<DeviceDescriptor> &sourceDevice, |
| 1064 | const sp<DeviceDescriptor> &sinkDevice, |
| 1065 | AudioProfileVector &sourceProfiles, |
| 1066 | AudioProfileVector &sinkProfiles) const; |
| 1067 | status_t getBestMsdConfig(bool hwAvSync, |
| 1068 | const AudioProfileVector &sourceProfiles, |
| 1069 | const AudioProfileVector &sinkProfiles, |
| 1070 | audio_port_config *sourceConfig, |
| 1071 | audio_port_config *sinkConfig) const; |
| 1072 | PatchBuilder buildMsdPatch(bool msdIsSource, const sp<DeviceDescriptor> &device) const; |
| 1073 | status_t setMsdOutputPatches(const DeviceVector *outputDevices = nullptr); |
| 1074 | void releaseMsdOutputPatches(const DeviceVector& devices); |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 1075 | bool msdHasPatchesToAllDevices(const AudioDeviceTypeAddrVector& devices); |
Nathalie Le Clair | 88fa275 | 2021-11-23 13:03:41 +0100 | [diff] [blame] | 1076 | |
| 1077 | // Overload of setDeviceConnectionState() |
| 1078 | status_t setDeviceConnectionState(audio_devices_t deviceType, |
| 1079 | audio_policy_dev_state_t state, |
| 1080 | const char* device_address, const char* device_name, |
| 1081 | audio_format_t encodedFormat); |
| 1082 | |
| 1083 | // Called by setDeviceConnectionState() |
| 1084 | status_t deviceToAudioPort(audio_devices_t deviceType, const char* device_address, |
Atneya Nair | 638a6e4 | 2022-12-18 16:45:15 -0800 | [diff] [blame] | 1085 | const char* device_name, media::AudioPortFw* aidPort); |
Francois Gaffie | b2e5cb5 | 2021-06-22 13:16:09 +0200 | [diff] [blame] | 1086 | bool isMsdPatch(const audio_patch_handle_t &handle) const; |
| 1087 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 1088 | private: |
Francois Gaffie | 601801d | 2021-06-22 13:27:39 +0200 | [diff] [blame] | 1089 | |
Michael Chan | 6fb3449 | 2020-12-08 15:44:49 +1100 | [diff] [blame] | 1090 | void onNewAudioModulesAvailableInt(DeviceVector *newDevices); |
| 1091 | |
| 1092 | // Add or remove AC3 DTS encodings based on user preferences. |
| 1093 | void modifySurroundFormats(const sp<DeviceDescriptor>& devDesc, FormatVector *formatsPtr); |
| 1094 | void modifySurroundChannelMasks(ChannelMaskSet *channelMasksPtr); |
Mikhail Naganov | 15be9d2 | 2017-11-08 14:18:13 +1100 | [diff] [blame] | 1095 | |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 1096 | // If any, resolve any "dynamic" fields of the Audio Profiles collection of and IOProfile |
Mikhail Naganov | d5e1805 | 2018-11-30 14:55:45 -0800 | [diff] [blame] | 1097 | void updateAudioProfiles(const sp<DeviceDescriptor>& devDesc, audio_io_handle_t ioHandle, |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 1098 | const sp<IOProfile> &profiles); |
François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 1099 | |
jiabin | c004863 | 2023-04-27 22:04:31 +0000 | [diff] [blame] | 1100 | // Notify the policy client to prepare for disconnecting external device. |
| 1101 | void prepareToDisconnectExternalDevice(const sp<DeviceDescriptor> &device); |
| 1102 | |
François Gaffie | 44481e7 | 2016-04-20 07:49:57 +0200 | [diff] [blame] | 1103 | // Notify the policy client of any change of device state with AUDIO_IO_HANDLE_NONE, |
| 1104 | // so that the client interprets it as global to audio hardware interfaces. |
| 1105 | // It can give a chance to HAL implementer to retrieve dynamic capabilities associated |
| 1106 | // to this device for example. |
| 1107 | // TODO avoid opening stream to retrieve capabilities of a profile. |
Ping Tsai | 2a5a524 | 2024-08-16 13:39:10 +0800 | [diff] [blame^] | 1108 | status_t broadcastDeviceConnectionState(const sp<DeviceDescriptor> &device, |
| 1109 | media::DeviceConnectedState state); |
François Gaffie | 44481e7 | 2016-04-20 07:49:57 +0200 | [diff] [blame] | 1110 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1111 | // updates device caching and output for streams that can influence the |
| 1112 | // routing of notifications |
| 1113 | void handleNotificationRoutingForStream(audio_stream_type_t stream); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1114 | uint32_t curAudioPortGeneration() const { return mAudioPortGeneration; } |
Hongwei Wang | bb93dfb | 2018-10-23 13:54:22 -0700 | [diff] [blame] | 1115 | // internal method, get audio_attributes_t from either a source audio_attributes_t |
| 1116 | // or audio_stream_type_t, respectively. |
| 1117 | status_t getAudioAttributes(audio_attributes_t *dstAttr, |
| 1118 | const audio_attributes_t *srcAttr, |
| 1119 | audio_stream_type_t srcStream); |
| 1120 | // internal method, called by getOutputForAttr() and connectAudioSource. |
| 1121 | status_t getOutputForAttrInt(audio_attributes_t *resultAttr, |
| 1122 | audio_io_handle_t *output, |
| 1123 | audio_session_t session, |
| 1124 | const audio_attributes_t *attr, |
| 1125 | audio_stream_type_t *stream, |
| 1126 | uid_t uid, |
jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1127 | audio_config_t *config, |
Hongwei Wang | bb93dfb | 2018-10-23 13:54:22 -0700 | [diff] [blame] | 1128 | audio_output_flags_t *flags, |
François Gaffie | f579db5 | 2018-11-13 11:25:16 +0100 | [diff] [blame] | 1129 | audio_port_handle_t *selectedDeviceId, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 1130 | bool *isRequestedDeviceForExclusiveUse, |
Eric Laurent | c529cf6 | 2020-04-17 18:19:10 -0700 | [diff] [blame] | 1131 | std::vector<sp<AudioPolicyMix>> *secondaryMixes, |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 1132 | output_type_t *outputType, |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 1133 | bool *isSpatialized, |
| 1134 | bool *isBitPerfect); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1135 | // internal method to return the output handle for the given device and format |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 1136 | audio_io_handle_t getOutputForDevices( |
| 1137 | const DeviceVector &devices, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1138 | audio_session_t session, |
Eric Laurent | cad6c0d | 2021-07-13 15:12:39 +0200 | [diff] [blame] | 1139 | const audio_attributes_t *attr, |
Eric Laurent | fe23112 | 2017-11-17 17:48:06 -0800 | [diff] [blame] | 1140 | const audio_config_t *config, |
jiabin | e375d41 | 2019-02-26 12:54:53 -0800 | [diff] [blame] | 1141 | audio_output_flags_t *flags, |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 1142 | bool *isSpatialized, |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 1143 | sp<PreferredMixerAttributesInfo> prefMixerAttrInfo = nullptr, |
jiabin | e375d41 | 2019-02-26 12:54:53 -0800 | [diff] [blame] | 1144 | bool forceMutingHaptic = false); |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1145 | |
Eric Laurent | c529cf6 | 2020-04-17 18:19:10 -0700 | [diff] [blame] | 1146 | // Internal method checking if a direct output can be opened matching the requested |
| 1147 | // attributes, flags, config and devices. |
| 1148 | // If NAME_NOT_FOUND is returned, an attempt can be made to open a mixed output. |
| 1149 | status_t openDirectOutput( |
| 1150 | audio_stream_type_t stream, |
| 1151 | audio_session_t session, |
| 1152 | const audio_config_t *config, |
| 1153 | audio_output_flags_t flags, |
| 1154 | const DeviceVector &devices, |
Haofan Wang | b75aa6a | 2024-07-09 23:06:58 -0700 | [diff] [blame] | 1155 | audio_io_handle_t *output, |
| 1156 | audio_attributes_t attributes); |
Eric Laurent | cad6c0d | 2021-07-13 15:12:39 +0200 | [diff] [blame] | 1157 | |
Eric Laurent | b4f42a9 | 2022-01-17 17:37:31 +0100 | [diff] [blame] | 1158 | /** |
| 1159 | * @brief Queries if some kind of spatialization will be performed if the audio playback |
| 1160 | * context described by the provided arguments is present. |
| 1161 | * The context is made of: |
| 1162 | * - The audio attributes describing the playback use case. |
| 1163 | * - The audio configuration describing the audio format, channels, sampling rate ... |
| 1164 | * - The devices describing the sink audio device selected for playback. |
| 1165 | * All arguments are optional and only the specified arguments are used to match against |
| 1166 | * supported criteria. For instance, supplying no argument will tell if spatialization is |
| 1167 | * supported or not in general. |
| 1168 | * @param attr audio attributes describing the playback use case |
| 1169 | * @param config audio configuration describing the audio format, channels, sample rate... |
| 1170 | * @param devices the sink audio device selected for playback |
Eric Laurent | b4f42a9 | 2022-01-17 17:37:31 +0100 | [diff] [blame] | 1171 | * @return true if spatialization is possible for this context, false otherwise. |
| 1172 | */ |
| 1173 | virtual bool canBeSpatializedInt(const audio_attributes_t *attr, |
| 1174 | const audio_config_t *config, |
Andy Hung | 9dd1a5b | 2022-05-10 15:39:39 -0700 | [diff] [blame] | 1175 | const AudioDeviceTypeAddrVector &devices) const; |
Eric Laurent | b4f42a9 | 2022-01-17 17:37:31 +0100 | [diff] [blame] | 1176 | |
Eric Laurent | 0c8f7cc | 2022-06-24 14:32:36 +0200 | [diff] [blame] | 1177 | |
| 1178 | /** |
| 1179 | * @brief Gets an IOProfile for a spatializer output with the best match with |
| 1180 | * provided arguments. |
| 1181 | * The caller can have the devices criteria ignored by passing and empty vector, and |
| 1182 | * getSpatializerOutputProfile() will ignore the devices when looking for a match. |
| 1183 | * Otherwise an output profile supporting a spatializer effect that can be routed |
| 1184 | * to the specified devices must exist. |
| 1185 | * @param config audio configuration describing the audio format, channels, sample rate... |
| 1186 | * @param devices the sink audio device selected for playback |
| 1187 | * @return an IOProfile that canbe used to open a spatializer output. |
| 1188 | */ |
Eric Laurent | fa0f674 | 2021-08-17 18:39:44 +0200 | [diff] [blame] | 1189 | sp<IOProfile> getSpatializerOutputProfile(const audio_config_t *config, |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 1190 | const AudioDeviceTypeAddrVector &devices) const; |
| 1191 | |
Eric Laurent | cad6c0d | 2021-07-13 15:12:39 +0200 | [diff] [blame] | 1192 | void checkVirtualizerClientRoutes(); |
| 1193 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1194 | /** |
Eric Laurent | e191d1b | 2022-04-15 11:59:25 +0200 | [diff] [blame] | 1195 | * @brief Returns true if at least one device can only be reached via the output passed |
| 1196 | * as argument. Always returns false for duplicated outputs. |
| 1197 | * This can be used to decide if an output can be closed without forbidding |
| 1198 | * playback to any given device. |
| 1199 | * @param outputDesc the output to consider |
| 1200 | * @return true if at least one device can only be reached via the output. |
| 1201 | */ |
| 1202 | bool isOutputOnlyAvailableRouteToSomeDevice(const sp<SwAudioOutputDescriptor>& outputDesc); |
| 1203 | |
| 1204 | /** |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1205 | * @brief getInputForDevice selects an input handle for a given input device and |
| 1206 | * requester context |
| 1207 | * @param device to be used by requester, selected by policy mix rules or engine |
| 1208 | * @param session requester session id |
| 1209 | * @param uid requester uid |
| 1210 | * @param attributes requester audio attributes (e.g. input source and tags matter) |
jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1211 | * @param config requested audio configuration (e.g. sample rate, format, channel mask), |
| 1212 | * will be updated if current configuration doesn't support but another |
| 1213 | * one does |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1214 | * @param flags requester input flags |
| 1215 | * @param policyMix may be null, policy rules to be followed by the requester |
| 1216 | * @return input io handle aka unique input identifier selected for this device. |
| 1217 | */ |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 1218 | audio_io_handle_t getInputForDevice(const sp<DeviceDescriptor> &device, |
Eric Laurent | 599c758 | 2015-12-07 18:05:55 -0800 | [diff] [blame] | 1219 | audio_session_t session, |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1220 | const audio_attributes_t &attributes, |
jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1221 | audio_config_base_t *config, |
Eric Laurent | 599c758 | 2015-12-07 18:05:55 -0800 | [diff] [blame] | 1222 | audio_input_flags_t flags, |
Mikhail Naganov | bfac583 | 2019-03-05 16:55:28 -0800 | [diff] [blame] | 1223 | const sp<AudioPolicyMix> &policyMix); |
Eric Laurent | 599c758 | 2015-12-07 18:05:55 -0800 | [diff] [blame] | 1224 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1225 | // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON |
| 1226 | // returns 0 if no mute/unmute event happened, the largest latency of the device where |
| 1227 | // the mute/unmute happened |
| 1228 | uint32_t handleEventForBeacon(int event); |
| 1229 | uint32_t setBeaconMute(bool mute); |
| 1230 | bool isValidAttributes(const audio_attributes_t *paa); |
| 1231 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1232 | // Called by setDeviceConnectionState(). |
Nathalie Le Clair | 88fa275 | 2021-11-23 13:03:41 +0100 | [diff] [blame] | 1233 | status_t setDeviceConnectionStateInt(audio_policy_dev_state_t state, |
| 1234 | const android::media::audio::common::AudioPort& port, |
| 1235 | audio_format_t encodedFormat); |
François Gaffie | 11d3010 | 2018-11-02 16:09:09 +0100 | [diff] [blame] | 1236 | status_t setDeviceConnectionStateInt(audio_devices_t deviceType, |
| 1237 | audio_policy_dev_state_t state, |
| 1238 | const char *device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 1239 | const char *device_name, |
| 1240 | audio_format_t encodedFormat); |
Mikhail Naganov | d0e2c74 | 2020-03-25 15:59:59 -0700 | [diff] [blame] | 1241 | status_t setDeviceConnectionStateInt(const sp<DeviceDescriptor> &device, |
| 1242 | audio_policy_dev_state_t state); |
Eric Laurent | 736a102 | 2019-03-27 18:28:46 -0700 | [diff] [blame] | 1243 | |
| 1244 | void setEngineDeviceConnectionState(const sp<DeviceDescriptor> device, |
| 1245 | audio_policy_dev_state_t state); |
| 1246 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1247 | void updateMono(audio_io_handle_t output) { |
| 1248 | AudioParameter param; |
Mikhail Naganov | 388360c | 2016-10-17 17:09:41 -0700 | [diff] [blame] | 1249 | param.addInt(String8(AudioParameter::keyMonoOutput), (int)mMasterMono); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1250 | mpClientInterface->setParameters(output, param.toString()); |
| 1251 | } |
François Gaffie | afd4cea | 2019-11-18 15:50:22 +0100 | [diff] [blame] | 1252 | |
| 1253 | /** |
| 1254 | * @brief createAudioPatchInternal internal function to manage audio patch creation |
| 1255 | * @param[in] patch structure containing sink and source ports configuration |
| 1256 | * @param[out] handle patch handle to be provided if patch installed correctly |
| 1257 | * @param[in] uid of the client |
| 1258 | * @param[in] delayMs if required |
Francois Gaffie | b2e5cb5 | 2021-06-22 13:16:09 +0200 | [diff] [blame] | 1259 | * @param[in] sourceDesc source client to be configured when creating the patch, i.e. |
| 1260 | * assigning an Output (HW or SW) used for volume control. |
François Gaffie | afd4cea | 2019-11-18 15:50:22 +0100 | [diff] [blame] | 1261 | * @return NO_ERROR if patch installed correctly, error code otherwise. |
| 1262 | */ |
| 1263 | status_t createAudioPatchInternal(const struct audio_patch *patch, |
| 1264 | audio_patch_handle_t *handle, |
Francois Gaffie | b2e5cb5 | 2021-06-22 13:16:09 +0200 | [diff] [blame] | 1265 | uid_t uid, uint32_t delayMs, |
| 1266 | const sp<SourceClientDescriptor>& sourceDesc); |
François Gaffie | afd4cea | 2019-11-18 15:50:22 +0100 | [diff] [blame] | 1267 | /** |
| 1268 | * @brief releaseAudioPatchInternal internal function to remove an audio patch |
| 1269 | * @param[in] handle of the patch to be removed |
| 1270 | * @param[in] delayMs if required |
Francois Gaffie | b2e5cb5 | 2021-06-22 13:16:09 +0200 | [diff] [blame] | 1271 | * @param[in] sourceDesc [optional] in case of external source, source client to be |
| 1272 | * unrouted from the patch, i.e. assigning an Output (HW or SW) |
François Gaffie | afd4cea | 2019-11-18 15:50:22 +0100 | [diff] [blame] | 1273 | * @return NO_ERROR if patch removed correctly, error code otherwise. |
| 1274 | */ |
Francois Gaffie | b2e5cb5 | 2021-06-22 13:16:09 +0200 | [diff] [blame] | 1275 | status_t releaseAudioPatchInternal(audio_patch_handle_t handle, |
| 1276 | uint32_t delayMs = 0, |
| 1277 | const sp<SourceClientDescriptor>& sourceDesc = nullptr); |
François Gaffie | afd4cea | 2019-11-18 15:50:22 +0100 | [diff] [blame] | 1278 | |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 1279 | status_t installPatch(const char *caller, |
| 1280 | audio_patch_handle_t *patchHandle, |
| 1281 | AudioIODescriptorInterface *ioDescriptor, |
| 1282 | const struct audio_patch *patch, |
| 1283 | int delayMs); |
| 1284 | status_t installPatch(const char *caller, |
| 1285 | ssize_t index, |
| 1286 | audio_patch_handle_t *patchHandle, |
| 1287 | const struct audio_patch *patch, |
| 1288 | int delayMs, |
| 1289 | uid_t uid, |
| 1290 | sp<AudioPatch> *patchDescPtr); |
Eric Laurent | c529cf6 | 2020-04-17 18:19:10 -0700 | [diff] [blame] | 1291 | |
| 1292 | bool areAllDevicesSupported( |
jiabin | 6a02d53 | 2020-08-07 11:56:38 -0700 | [diff] [blame] | 1293 | const AudioDeviceTypeAddrVector& devices, |
Eric Laurent | c529cf6 | 2020-04-17 18:19:10 -0700 | [diff] [blame] | 1294 | std::function<bool(audio_devices_t)> predicate, |
Eric Laurent | 78fedbf | 2023-03-09 14:40:44 +0100 | [diff] [blame] | 1295 | const char* context, |
| 1296 | bool matchAddress = true); |
Eric Laurent | c529cf6 | 2020-04-17 18:19:10 -0700 | [diff] [blame] | 1297 | |
Oscar Azucena | 2995655 | 2023-04-27 16:32:09 -0700 | [diff] [blame] | 1298 | /** |
| 1299 | * @brief changeOutputDevicesMuteState mute/unmute devices using checkDeviceMuteStrategies |
| 1300 | * @param devices devices to mute/unmute |
| 1301 | */ |
| 1302 | void changeOutputDevicesMuteState(const AudioDeviceTypeAddrVector& devices); |
| 1303 | |
| 1304 | /** |
| 1305 | * @brief Returns a vector of software output descriptor that support the queried devices |
| 1306 | * @param devices devices to query |
| 1307 | * @param openOutputs open outputs where the devices are supported as determined by |
| 1308 | * SwAudioOutputDescriptor::supportsAtLeastOne |
| 1309 | */ |
| 1310 | std::vector<sp<SwAudioOutputDescriptor>> getSoftwareOutputsForDevices( |
| 1311 | const AudioDeviceTypeAddrVector& devices) const; |
| 1312 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 1313 | bool isScoRequestedForComm() const; |
jiabin | bce0c1d | 2020-10-05 11:20:18 -0700 | [diff] [blame] | 1314 | |
Eric Laurent | 1a8b45f | 2022-04-13 16:01:47 +0200 | [diff] [blame] | 1315 | bool isHearingAidUsedForComm() const; |
| 1316 | |
jiabin | bce0c1d | 2020-10-05 11:20:18 -0700 | [diff] [blame] | 1317 | bool areAllActiveTracksRerouted(const sp<SwAudioOutputDescriptor>& output); |
| 1318 | |
Eric Laurent | b4f42a9 | 2022-01-17 17:37:31 +0100 | [diff] [blame] | 1319 | /** |
| 1320 | * @brief Opens an output stream from the supplied IOProfile and route it to the |
| 1321 | * supplied audio devices. If a mixer config is specified, it is forwarded to audio |
| 1322 | * flinger. If not, a default config is derived from the output stream config. |
| 1323 | * Also opens a duplicating output if needed and queries the audio HAL for supported |
| 1324 | * audio profiles if the IOProfile is dynamic. |
| 1325 | * @param[in] profile IOProfile to use as template |
| 1326 | * @param[in] devices initial route to apply to this output stream |
| 1327 | * @param[in] mixerConfig if not null, use this to configure the mixer |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 1328 | * @param[in] halConfig if not null, use this to configure the HAL |
| 1329 | * @param[in] flags the flags to be used to open the output |
Eric Laurent | b4f42a9 | 2022-01-17 17:37:31 +0100 | [diff] [blame] | 1330 | * @return an output descriptor for the newly opened stream or null in case of error. |
| 1331 | */ |
| 1332 | sp<SwAudioOutputDescriptor> openOutputWithProfileAndDevice( |
| 1333 | const sp<IOProfile>& profile, const DeviceVector& devices, |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 1334 | const audio_config_base_t *mixerConfig = nullptr, |
| 1335 | const audio_config_t *halConfig = nullptr, |
| 1336 | audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE); |
jiabin | bce0c1d | 2020-10-05 11:20:18 -0700 | [diff] [blame] | 1337 | |
jiabin | 2b9d5a1 | 2021-12-10 01:06:29 +0000 | [diff] [blame] | 1338 | bool isOffloadPossible(const audio_offload_info_t& offloadInfo, |
| 1339 | bool durationIgnored = false); |
| 1340 | |
Dorin Drimus | 94d9441 | 2022-02-02 09:05:02 +0100 | [diff] [blame] | 1341 | // adds the profiles from the outputProfile to the passed audioProfilesVector |
| 1342 | // without duplicating them if already present |
| 1343 | void addPortProfilesToVector(sp<IOProfile> outputProfile, |
| 1344 | AudioProfileVector& audioProfilesVector); |
Dorin Drimus | ecc9f42 | 2022-03-09 17:57:40 +0100 | [diff] [blame] | 1345 | |
| 1346 | // Searches for a compatible profile with the sample rate, audio format and channel mask |
| 1347 | // in the list of passed HwModule(s). |
| 1348 | // returns a compatible profile if found, nullptr otherwise |
| 1349 | sp<IOProfile> searchCompatibleProfileHwModules ( |
| 1350 | const HwModuleCollection& hwModules, |
| 1351 | const DeviceVector& devices, |
| 1352 | uint32_t samplingRate, |
| 1353 | audio_format_t format, |
| 1354 | audio_channel_mask_t channelMask, |
| 1355 | audio_output_flags_t flags, |
| 1356 | bool directOnly); |
| 1357 | |
| 1358 | // Filters only the relevant flags for getProfileForOutput |
| 1359 | audio_output_flags_t getRelevantFlags (audio_output_flags_t flags, bool directOnly); |
jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1360 | |
| 1361 | status_t getDevicesForAttributes(const audio_attributes_t &attr, |
| 1362 | DeviceVector &devices, |
| 1363 | bool forVolume); |
| 1364 | |
| 1365 | status_t getProfilesForDevices(const DeviceVector& devices, |
| 1366 | AudioProfileVector& audioProfiles, |
| 1367 | uint32_t flags, |
| 1368 | bool isInput); |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 1369 | |
jiabin | d9a58d3 | 2023-06-01 17:57:30 +0000 | [diff] [blame] | 1370 | /** |
| 1371 | * Returns the preferred mixer attributes info for the given device port id and strategy. |
| 1372 | * Bit-perfect mixer attributes will be returned if it is active and |
| 1373 | * `activeBitPerfectPreferred` is true. |
| 1374 | */ |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 1375 | sp<PreferredMixerAttributesInfo> getPreferredMixerAttributesInfo( |
jiabin | d9a58d3 | 2023-06-01 17:57:30 +0000 | [diff] [blame] | 1376 | audio_port_handle_t devicePortId, |
| 1377 | product_strategy_t strategy, |
| 1378 | bool activeBitPerfectPreferred = false); |
jiabin | c44b346 | 2022-12-08 12:52:31 -0800 | [diff] [blame] | 1379 | |
jiabin | 3ff8d7d | 2022-12-13 06:27:44 +0000 | [diff] [blame] | 1380 | sp<SwAudioOutputDescriptor> reopenOutput( |
| 1381 | sp<SwAudioOutputDescriptor> outputDesc, |
| 1382 | const audio_config_t *config, |
| 1383 | audio_output_flags_t flags, |
| 1384 | const char* caller); |
| 1385 | |
| 1386 | void reopenOutputsWithDevices( |
| 1387 | const std::map<audio_io_handle_t, DeviceVector>& outputsToReopen); |
jiabin | c44b346 | 2022-12-08 12:52:31 -0800 | [diff] [blame] | 1388 | |
| 1389 | PortHandleVector getClientsForStream(audio_stream_type_t streamType) const; |
| 1390 | void invalidateStreams(StreamTypeVector streams) const; |
Shunkai Yao | 4c3af93 | 2024-04-26 04:12:21 +0000 | [diff] [blame] | 1391 | |
| 1392 | bool checkHapticCompatibilityOnSpatializerOutput(const audio_config_t* config, |
| 1393 | audio_session_t sessionId) const; |
jiabin | 220eea1 | 2024-05-17 17:55:20 +0000 | [diff] [blame] | 1394 | |
| 1395 | void updateClientsInternalMute(const sp<SwAudioOutputDescriptor>& desc); |
Vlad Popa | 87e0e58 | 2024-05-20 18:49:20 -0700 | [diff] [blame] | 1396 | |
| 1397 | float adjustDeviceAttenuationForAbsVolume(IVolumeCurves &curves, |
| 1398 | VolumeSource volumeSource, |
| 1399 | int index, |
| 1400 | const DeviceTypeSet &deviceTypes); |
| 1401 | |
| 1402 | // Contains for devices that support absolute volume the audio attributes |
| 1403 | // corresponding to the streams that are driving the volume changes |
| 1404 | std::unordered_map<audio_devices_t, audio_attributes_t> mAbsoluteVolumeDrivingStreams; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1405 | }; |
| 1406 | |
| 1407 | }; |