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