Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [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 | |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | #include <cutils/config_utils.h> |
| 21 | #include <cutils/misc.h> |
| 22 | #include <utils/Timers.h> |
| 23 | #include <utils/Errors.h> |
| 24 | #include <utils/KeyedVector.h> |
| 25 | #include <utils/SortedVector.h> |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 26 | #include <media/AudioPolicy.h> |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 27 | #include "AudioPolicyInterface.h" |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 28 | |
| 29 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 30 | namespace android { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 31 | |
| 32 | // ---------------------------------------------------------------------------- |
| 33 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 34 | // Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB |
| 35 | #define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5 |
| 36 | // Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB |
| 37 | #define SONIFICATION_HEADSET_VOLUME_MIN 0.016 |
| 38 | // Time in milliseconds during which we consider that music is still active after a music |
| 39 | // track was stopped - see computeVolume() |
| 40 | #define SONIFICATION_HEADSET_MUSIC_DELAY 5000 |
| 41 | // Time in milliseconds after media stopped playing during which we consider that the |
| 42 | // sonification should be as unobtrusive as during the time media was playing. |
| 43 | #define SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY 5000 |
| 44 | // Time in milliseconds during witch some streams are muted while the audio path |
| 45 | // is switched |
| 46 | #define MUTE_TIME_MS 2000 |
| 47 | |
| 48 | #define NUM_TEST_OUTPUTS 5 |
| 49 | |
| 50 | #define NUM_VOL_CURVE_KNEES 2 |
| 51 | |
| 52 | // Default minimum length allowed for offloading a compressed track |
| 53 | // Can be overridden by the audio.offload.min.duration.secs property |
| 54 | #define OFFLOAD_DEFAULT_MIN_DURATION_SECS 60 |
| 55 | |
Eric Laurent | 1e693b5 | 2014-07-09 15:03:28 -0700 | [diff] [blame] | 56 | #define MAX_MIXER_SAMPLING_RATE 48000 |
Andy Hung | 9a60538 | 2014-07-28 16:16:31 -0700 | [diff] [blame] | 57 | #define MAX_MIXER_CHANNEL_COUNT 8 |
Eric Laurent | 1e693b5 | 2014-07-09 15:03:28 -0700 | [diff] [blame] | 58 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 59 | // ---------------------------------------------------------------------------- |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 60 | // AudioPolicyManager implements audio policy manager behavior common to all platforms. |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 61 | // ---------------------------------------------------------------------------- |
| 62 | |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 63 | class AudioPolicyManager: public AudioPolicyInterface |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 64 | #ifdef AUDIO_POLICY_TEST |
| 65 | , public Thread |
| 66 | #endif //AUDIO_POLICY_TEST |
| 67 | { |
| 68 | |
| 69 | public: |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 70 | AudioPolicyManager(AudioPolicyClientInterface *clientInterface); |
| 71 | virtual ~AudioPolicyManager(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 72 | |
| 73 | // AudioPolicyInterface |
| 74 | virtual status_t setDeviceConnectionState(audio_devices_t device, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 75 | audio_policy_dev_state_t state, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 76 | const char *device_address); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 77 | virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 78 | const char *device_address); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 79 | virtual void setPhoneState(audio_mode_t state); |
| 80 | virtual void setForceUse(audio_policy_force_use_t usage, |
| 81 | audio_policy_forced_cfg_t config); |
| 82 | virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 83 | virtual void setSystemProperty(const char* property, const char* value); |
| 84 | virtual status_t initCheck(); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 85 | virtual audio_io_handle_t getOutput(audio_stream_type_t stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 86 | uint32_t samplingRate, |
| 87 | audio_format_t format, |
| 88 | audio_channel_mask_t channelMask, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 89 | audio_output_flags_t flags, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 90 | const audio_offload_info_t *offloadInfo); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 91 | virtual status_t getOutputForAttr(const audio_attributes_t *attr, |
| 92 | audio_io_handle_t *output, |
| 93 | audio_session_t session, |
| 94 | audio_stream_type_t *stream, |
| 95 | uint32_t samplingRate, |
| 96 | audio_format_t format, |
| 97 | audio_channel_mask_t channelMask, |
| 98 | audio_output_flags_t flags, |
| 99 | const audio_offload_info_t *offloadInfo); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 100 | virtual status_t startOutput(audio_io_handle_t output, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 101 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 102 | audio_session_t session); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 103 | virtual status_t stopOutput(audio_io_handle_t output, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 104 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 105 | audio_session_t session); |
| 106 | virtual void releaseOutput(audio_io_handle_t output, |
| 107 | audio_stream_type_t stream, |
| 108 | audio_session_t session); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 109 | virtual status_t getInputForAttr(const audio_attributes_t *attr, |
| 110 | audio_io_handle_t *input, |
| 111 | audio_session_t session, |
| 112 | uint32_t samplingRate, |
| 113 | audio_format_t format, |
| 114 | audio_channel_mask_t channelMask, |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame^] | 115 | audio_input_flags_t flags, |
| 116 | input_type_t *inputType); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 117 | |
| 118 | // indicates to the audio policy manager that the input starts being used. |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 119 | virtual status_t startInput(audio_io_handle_t input, |
| 120 | audio_session_t session); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 121 | |
| 122 | // indicates to the audio policy manager that the input stops being used. |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 123 | virtual status_t stopInput(audio_io_handle_t input, |
| 124 | audio_session_t session); |
| 125 | virtual void releaseInput(audio_io_handle_t input, |
| 126 | audio_session_t session); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 127 | virtual void closeAllInputs(); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 128 | virtual void initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 129 | int indexMin, |
| 130 | int indexMax); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 131 | virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 132 | int index, |
| 133 | audio_devices_t device); |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 134 | virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 135 | int *index, |
| 136 | audio_devices_t device); |
| 137 | |
| 138 | // return the strategy corresponding to a given stream type |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 139 | virtual uint32_t getStrategyForStream(audio_stream_type_t stream); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 140 | // return the strategy corresponding to the given audio attributes |
| 141 | virtual uint32_t getStrategyForAttr(const audio_attributes_t *attr); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 142 | |
| 143 | // return the enabled output devices for the given stream type |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 144 | virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 145 | |
| 146 | virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc = NULL); |
| 147 | virtual status_t registerEffect(const effect_descriptor_t *desc, |
| 148 | audio_io_handle_t io, |
| 149 | uint32_t strategy, |
| 150 | int session, |
| 151 | int id); |
| 152 | virtual status_t unregisterEffect(int id); |
| 153 | virtual status_t setEffectEnabled(int id, bool enabled); |
| 154 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 155 | virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 156 | // return whether a stream is playing remotely, override to change the definition of |
| 157 | // local/remote playback, used for instance by notification manager to not make |
| 158 | // media players lose audio focus when not playing locally |
Jean-Michel Trivi | 1767df7 | 2014-12-09 18:11:49 -0800 | [diff] [blame] | 159 | // For the base implementation, "remotely" means playing during screen mirroring which |
| 160 | // uses an output for playback with a non-empty, non "0" address. |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 161 | virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 162 | virtual bool isSourceActive(audio_source_t source) const; |
| 163 | |
| 164 | virtual status_t dump(int fd); |
| 165 | |
| 166 | virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo); |
| 167 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 168 | virtual status_t listAudioPorts(audio_port_role_t role, |
| 169 | audio_port_type_t type, |
| 170 | unsigned int *num_ports, |
| 171 | struct audio_port *ports, |
| 172 | unsigned int *generation); |
| 173 | virtual status_t getAudioPort(struct audio_port *port); |
| 174 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 175 | audio_patch_handle_t *handle, |
| 176 | uid_t uid); |
| 177 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle, |
| 178 | uid_t uid); |
| 179 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 180 | struct audio_patch *patches, |
| 181 | unsigned int *generation); |
| 182 | virtual status_t setAudioPortConfig(const struct audio_port_config *config); |
| 183 | virtual void clearAudioPatches(uid_t uid); |
| 184 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 185 | virtual status_t acquireSoundTriggerSession(audio_session_t *session, |
| 186 | audio_io_handle_t *ioHandle, |
| 187 | audio_devices_t *device); |
| 188 | |
| 189 | virtual status_t releaseSoundTriggerSession(audio_session_t session); |
| 190 | |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 191 | virtual status_t registerPolicyMixes(Vector<AudioMix> mixes); |
| 192 | virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes); |
| 193 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 194 | protected: |
| 195 | |
| 196 | enum routing_strategy { |
| 197 | STRATEGY_MEDIA, |
| 198 | STRATEGY_PHONE, |
| 199 | STRATEGY_SONIFICATION, |
| 200 | STRATEGY_SONIFICATION_RESPECTFUL, |
| 201 | STRATEGY_DTMF, |
| 202 | STRATEGY_ENFORCED_AUDIBLE, |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 203 | STRATEGY_TRANSMITTED_THROUGH_SPEAKER, |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 204 | STRATEGY_ACCESSIBILITY, |
| 205 | STRATEGY_REROUTING, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 206 | NUM_STRATEGIES |
| 207 | }; |
| 208 | |
| 209 | // 4 points to define the volume attenuation curve, each characterized by the volume |
| 210 | // index (from 0 to 100) at which they apply, and the attenuation in dB at that index. |
| 211 | // we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl() |
| 212 | |
| 213 | enum { VOLMIN = 0, VOLKNEE1 = 1, VOLKNEE2 = 2, VOLMAX = 3, VOLCNT = 4}; |
| 214 | |
| 215 | class VolumeCurvePoint |
| 216 | { |
| 217 | public: |
| 218 | int mIndex; |
| 219 | float mDBAttenuation; |
| 220 | }; |
| 221 | |
| 222 | // device categories used for volume curve management. |
| 223 | enum device_category { |
| 224 | DEVICE_CATEGORY_HEADSET, |
| 225 | DEVICE_CATEGORY_SPEAKER, |
| 226 | DEVICE_CATEGORY_EARPIECE, |
Jon Eklund | ac29afa | 2014-07-28 16:06:06 -0500 | [diff] [blame] | 227 | DEVICE_CATEGORY_EXT_MEDIA, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 228 | DEVICE_CATEGORY_CNT |
| 229 | }; |
| 230 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 231 | class HwModule; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 232 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 233 | class AudioGain: public RefBase |
| 234 | { |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 235 | public: |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 236 | AudioGain(int index, bool useInChannelMask); |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 237 | virtual ~AudioGain() {} |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 238 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 239 | void dump(int fd, int spaces, int index) const; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 240 | |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 241 | void getDefaultConfig(struct audio_gain_config *config); |
| 242 | status_t checkConfig(const struct audio_gain_config *config); |
| 243 | int mIndex; |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 244 | struct audio_gain mGain; |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 245 | bool mUseInChannelMask; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 248 | class AudioPort: public virtual RefBase |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 249 | { |
| 250 | public: |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 251 | AudioPort(const String8& name, audio_port_type_t type, |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 252 | audio_port_role_t role, const sp<HwModule>& module); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 253 | virtual ~AudioPort() {} |
| 254 | |
| 255 | virtual void toAudioPort(struct audio_port *port) const; |
| 256 | |
Jean-Michel Trivi | f17026d | 2014-08-10 14:30:48 -0700 | [diff] [blame] | 257 | void importAudioPort(const sp<AudioPort> port); |
| 258 | void clearCapabilities(); |
| 259 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 260 | void loadSamplingRates(char *name); |
| 261 | void loadFormats(char *name); |
| 262 | void loadOutChannels(char *name); |
| 263 | void loadInChannels(char *name); |
| 264 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 265 | audio_gain_mode_t loadGainMode(char *name); |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 266 | void loadGain(cnode *root, int index); |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 267 | void loadGains(cnode *root); |
| 268 | |
Glenn Kasten | cbd4802 | 2014-07-24 13:46:44 -0700 | [diff] [blame] | 269 | // searches for an exact match |
| 270 | status_t checkExactSamplingRate(uint32_t samplingRate) const; |
| 271 | // searches for a compatible match, and returns the best match via updatedSamplingRate |
| 272 | status_t checkCompatibleSamplingRate(uint32_t samplingRate, |
| 273 | uint32_t *updatedSamplingRate) const; |
| 274 | // searches for an exact match |
| 275 | status_t checkExactChannelMask(audio_channel_mask_t channelMask) const; |
| 276 | // searches for a compatible match, currently implemented for input channel masks only |
| 277 | status_t checkCompatibleChannelMask(audio_channel_mask_t channelMask) const; |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 278 | status_t checkFormat(audio_format_t format) const; |
| 279 | status_t checkGain(const struct audio_gain_config *gainConfig, int index) const; |
| 280 | |
Eric Laurent | 1e693b5 | 2014-07-09 15:03:28 -0700 | [diff] [blame] | 281 | uint32_t pickSamplingRate() const; |
| 282 | audio_channel_mask_t pickChannelMask() const; |
| 283 | audio_format_t pickFormat() const; |
| 284 | |
| 285 | static const audio_format_t sPcmFormatCompareTable[]; |
| 286 | static int compareFormats(audio_format_t format1, audio_format_t format2); |
| 287 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 288 | void dump(int fd, int spaces) const; |
| 289 | |
| 290 | String8 mName; |
| 291 | audio_port_type_t mType; |
| 292 | audio_port_role_t mRole; |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 293 | bool mUseInChannelMask; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 294 | // by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats |
| 295 | // indicates the supported parameters should be read from the output stream |
| 296 | // after it is opened for the first time |
| 297 | Vector <uint32_t> mSamplingRates; // supported sampling rates |
| 298 | Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks |
| 299 | Vector <audio_format_t> mFormats; // supported audio formats |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 300 | Vector < sp<AudioGain> > mGains; // gain controllers |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 301 | sp<HwModule> mModule; // audio HW module exposing this I/O stream |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 302 | uint32_t mFlags; // attribute flags (e.g primary output, |
| 303 | // direct output...). |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 306 | class AudioPortConfig: public virtual RefBase |
| 307 | { |
| 308 | public: |
| 309 | AudioPortConfig(); |
| 310 | virtual ~AudioPortConfig() {} |
| 311 | |
Eric Laurent | a121f90 | 2014-06-03 13:32:54 -0700 | [diff] [blame] | 312 | status_t applyAudioPortConfig(const struct audio_port_config *config, |
| 313 | struct audio_port_config *backupConfig = NULL); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 314 | virtual void toAudioPortConfig(struct audio_port_config *dstConfig, |
| 315 | const struct audio_port_config *srcConfig = NULL) const = 0; |
Marco Nelissen | 961ec21 | 2014-08-25 15:58:39 -0700 | [diff] [blame] | 316 | virtual sp<AudioPort> getAudioPort() const = 0; |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 317 | uint32_t mSamplingRate; |
| 318 | audio_format_t mFormat; |
| 319 | audio_channel_mask_t mChannelMask; |
| 320 | struct audio_gain_config mGain; |
| 321 | }; |
| 322 | |
| 323 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 324 | class AudioPatch: public RefBase |
| 325 | { |
| 326 | public: |
| 327 | AudioPatch(audio_patch_handle_t handle, |
| 328 | const struct audio_patch *patch, uid_t uid) : |
| 329 | mHandle(handle), mPatch(*patch), mUid(uid), mAfPatchHandle(0) {} |
| 330 | |
Eric Laurent | 4d41695 | 2014-08-10 14:07:09 -0700 | [diff] [blame] | 331 | status_t dump(int fd, int spaces, int index) const; |
| 332 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 333 | audio_patch_handle_t mHandle; |
| 334 | struct audio_patch mPatch; |
| 335 | uid_t mUid; |
| 336 | audio_patch_handle_t mAfPatchHandle; |
| 337 | }; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 338 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 339 | class DeviceDescriptor: public AudioPort, public AudioPortConfig |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 340 | { |
| 341 | public: |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 342 | DeviceDescriptor(const String8& name, audio_devices_t type); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 343 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 344 | virtual ~DeviceDescriptor() {} |
| 345 | |
| 346 | bool equals(const sp<DeviceDescriptor>& other) const; |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 347 | virtual void toAudioPortConfig(struct audio_port_config *dstConfig, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 348 | const struct audio_port_config *srcConfig = NULL) const; |
Marco Nelissen | 961ec21 | 2014-08-25 15:58:39 -0700 | [diff] [blame] | 349 | virtual sp<AudioPort> getAudioPort() const { return (AudioPort*) this; } |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 350 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 351 | virtual void toAudioPort(struct audio_port *port) const; |
| 352 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 353 | status_t dump(int fd, int spaces, int index) const; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 354 | |
| 355 | audio_devices_t mDeviceType; |
| 356 | String8 mAddress; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 357 | audio_port_handle_t mId; |
| 358 | }; |
| 359 | |
| 360 | class DeviceVector : public SortedVector< sp<DeviceDescriptor> > |
| 361 | { |
| 362 | public: |
| 363 | DeviceVector() : SortedVector(), mDeviceTypes(AUDIO_DEVICE_NONE) {} |
| 364 | |
| 365 | ssize_t add(const sp<DeviceDescriptor>& item); |
| 366 | ssize_t remove(const sp<DeviceDescriptor>& item); |
| 367 | ssize_t indexOf(const sp<DeviceDescriptor>& item) const; |
| 368 | |
| 369 | audio_devices_t types() const { return mDeviceTypes; } |
| 370 | |
| 371 | void loadDevicesFromType(audio_devices_t types); |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 372 | void loadDevicesFromName(char *name, const DeviceVector& declaredDevices); |
| 373 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 374 | sp<DeviceDescriptor> getDevice(audio_devices_t type, String8 address) const; |
| 375 | DeviceVector getDevicesFromType(audio_devices_t types) const; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 376 | sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const; |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 377 | sp<DeviceDescriptor> getDeviceFromName(const String8& name) const; |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 378 | DeviceVector getDevicesFromTypeAddr(audio_devices_t type, String8 address) |
| 379 | const; |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 380 | |
| 381 | private: |
| 382 | void refreshTypes(); |
| 383 | audio_devices_t mDeviceTypes; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | // the IOProfile class describes the capabilities of an output or input stream. |
| 387 | // It is currently assumed that all combination of listed parameters are supported. |
| 388 | // It is used by the policy manager to determine if an output or input is suitable for |
| 389 | // a given use case, open/close it accordingly and connect/disconnect audio tracks |
| 390 | // to/from it. |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 391 | class IOProfile : public AudioPort |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 392 | { |
| 393 | public: |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 394 | IOProfile(const String8& name, audio_port_role_t role, const sp<HwModule>& module); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 395 | virtual ~IOProfile(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 396 | |
Glenn Kasten | cbd4802 | 2014-07-24 13:46:44 -0700 | [diff] [blame] | 397 | // This method is used for both output and input. |
| 398 | // If parameter updatedSamplingRate is non-NULL, it is assigned the actual sample rate. |
| 399 | // For input, flags is interpreted as audio_input_flags_t. |
| 400 | // TODO: merge audio_output_flags_t and audio_input_flags_t. |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 401 | bool isCompatibleProfile(audio_devices_t device, |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 402 | String8 address, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 403 | uint32_t samplingRate, |
Glenn Kasten | cbd4802 | 2014-07-24 13:46:44 -0700 | [diff] [blame] | 404 | uint32_t *updatedSamplingRate, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 405 | audio_format_t format, |
| 406 | audio_channel_mask_t channelMask, |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 407 | uint32_t flags) const; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 408 | |
| 409 | void dump(int fd); |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 410 | void log(); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 411 | |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 412 | DeviceVector mSupportedDevices; // supported devices |
| 413 | // (devices this output can be routed to) |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 414 | }; |
| 415 | |
Eric Laurent | 1e693b5 | 2014-07-09 15:03:28 -0700 | [diff] [blame] | 416 | class HwModule : public RefBase |
| 417 | { |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 418 | public: |
| 419 | HwModule(const char *name); |
| 420 | ~HwModule(); |
| 421 | |
| 422 | status_t loadOutput(cnode *root); |
| 423 | status_t loadInput(cnode *root); |
| 424 | status_t loadDevice(cnode *root); |
| 425 | |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 426 | status_t addOutputProfile(String8 name, const audio_config_t *config, |
| 427 | audio_devices_t device, String8 address); |
| 428 | status_t removeOutputProfile(String8 name); |
| 429 | status_t addInputProfile(String8 name, const audio_config_t *config, |
| 430 | audio_devices_t device, String8 address); |
| 431 | status_t removeInputProfile(String8 name); |
| 432 | |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 433 | void dump(int fd); |
| 434 | |
Eric Laurent | eb108a4 | 2014-06-06 14:56:52 -0700 | [diff] [blame] | 435 | const char *const mName; // base name of the audio HW module (primary, a2dp ...) |
| 436 | uint32_t mHalVersion; // audio HAL API version |
| 437 | audio_module_handle_t mHandle; |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 438 | Vector < sp<IOProfile> > mOutputProfiles; // output profiles exposed by this module |
| 439 | Vector < sp<IOProfile> > mInputProfiles; // input profiles exposed by this module |
| 440 | DeviceVector mDeclaredDevices; // devices declared in audio_policy.conf |
| 441 | |
| 442 | }; |
| 443 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 444 | // default volume curve |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 445 | static const VolumeCurvePoint sDefaultVolumeCurve[AudioPolicyManager::VOLCNT]; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 446 | // default volume curve for media strategy |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 447 | static const VolumeCurvePoint sDefaultMediaVolumeCurve[AudioPolicyManager::VOLCNT]; |
Jon Eklund | ac29afa | 2014-07-28 16:06:06 -0500 | [diff] [blame] | 448 | // volume curve for non-media audio on ext media outputs (HDMI, Line, etc) |
| 449 | static const VolumeCurvePoint sExtMediaSystemVolumeCurve[AudioPolicyManager::VOLCNT]; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 450 | // volume curve for media strategy on speakers |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 451 | static const VolumeCurvePoint sSpeakerMediaVolumeCurve[AudioPolicyManager::VOLCNT]; |
Jean-Michel Trivi | ccd8e4a | 2014-06-05 15:33:20 -0700 | [diff] [blame] | 452 | static const VolumeCurvePoint sSpeakerMediaVolumeCurveDrc[AudioPolicyManager::VOLCNT]; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 453 | // volume curve for sonification strategy on speakers |
Eric Laurent | e072087 | 2014-03-11 09:30:41 -0700 | [diff] [blame] | 454 | static const VolumeCurvePoint sSpeakerSonificationVolumeCurve[AudioPolicyManager::VOLCNT]; |
| 455 | static const VolumeCurvePoint sSpeakerSonificationVolumeCurveDrc[AudioPolicyManager::VOLCNT]; |
| 456 | static const VolumeCurvePoint sDefaultSystemVolumeCurve[AudioPolicyManager::VOLCNT]; |
| 457 | static const VolumeCurvePoint sDefaultSystemVolumeCurveDrc[AudioPolicyManager::VOLCNT]; |
| 458 | static const VolumeCurvePoint sHeadsetSystemVolumeCurve[AudioPolicyManager::VOLCNT]; |
| 459 | static const VolumeCurvePoint sDefaultVoiceVolumeCurve[AudioPolicyManager::VOLCNT]; |
| 460 | static const VolumeCurvePoint sSpeakerVoiceVolumeCurve[AudioPolicyManager::VOLCNT]; |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 461 | static const VolumeCurvePoint sLinearVolumeCurve[AudioPolicyManager::VOLCNT]; |
| 462 | static const VolumeCurvePoint sSilentVolumeCurve[AudioPolicyManager::VOLCNT]; |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 463 | static const VolumeCurvePoint sFullScaleVolumeCurve[AudioPolicyManager::VOLCNT]; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 464 | // default volume curves per stream and device category. See initializeVolumeCurves() |
| 465 | static const VolumeCurvePoint *sVolumeProfiles[AUDIO_STREAM_CNT][DEVICE_CATEGORY_CNT]; |
| 466 | |
| 467 | // descriptor for audio outputs. Used to maintain current configuration of each opened audio output |
| 468 | // and keep track of the usage of this output by each audio stream type. |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 469 | class AudioOutputDescriptor: public AudioPortConfig |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 470 | { |
| 471 | public: |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 472 | AudioOutputDescriptor(const sp<IOProfile>& profile); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 473 | |
| 474 | status_t dump(int fd); |
| 475 | |
| 476 | audio_devices_t device() const; |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 477 | void changeRefCount(audio_stream_type_t stream, int delta); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 478 | |
| 479 | bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); } |
| 480 | audio_devices_t supportedDevices(); |
| 481 | uint32_t latency(); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 482 | bool sharesHwModuleWith(const sp<AudioOutputDescriptor> outputDesc); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 483 | bool isActive(uint32_t inPastMs = 0) const; |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 484 | bool isStreamActive(audio_stream_type_t stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 485 | uint32_t inPastMs = 0, |
| 486 | nsecs_t sysTime = 0) const; |
| 487 | bool isStrategyActive(routing_strategy strategy, |
| 488 | uint32_t inPastMs = 0, |
| 489 | nsecs_t sysTime = 0) const; |
| 490 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 491 | virtual void toAudioPortConfig(struct audio_port_config *dstConfig, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 492 | const struct audio_port_config *srcConfig = NULL) const; |
Marco Nelissen | 961ec21 | 2014-08-25 15:58:39 -0700 | [diff] [blame] | 493 | virtual sp<AudioPort> getAudioPort() const { return mProfile; } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 494 | void toAudioPort(struct audio_port *port) const; |
| 495 | |
| 496 | audio_port_handle_t mId; |
| 497 | audio_io_handle_t mIoHandle; // output handle |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 498 | uint32_t mLatency; // |
| 499 | audio_output_flags_t mFlags; // |
| 500 | audio_devices_t mDevice; // current device this output is routed to |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 501 | AudioMix *mPolicyMix; // non NULL when used by a dynamic policy |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 502 | audio_patch_handle_t mPatchHandle; |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 503 | uint32_t mRefCount[AUDIO_STREAM_CNT]; // number of streams of each type using this output |
| 504 | nsecs_t mStopTime[AUDIO_STREAM_CNT]; |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 505 | sp<AudioOutputDescriptor> mOutput1; // used by duplicated outputs: first output |
| 506 | sp<AudioOutputDescriptor> mOutput2; // used by duplicated outputs: second output |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 507 | float mCurVolume[AUDIO_STREAM_CNT]; // current stream volume |
| 508 | int mMuteCount[AUDIO_STREAM_CNT]; // mute request counter |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 509 | const sp<IOProfile> mProfile; // I/O profile this output derives from |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 510 | bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible |
| 511 | // device selection. See checkDeviceMuteStrategies() |
| 512 | uint32_t mDirectOpenCount; // number of clients using this output (direct outputs only) |
| 513 | }; |
| 514 | |
| 515 | // descriptor for audio inputs. Used to maintain current configuration of each opened audio input |
| 516 | // and keep track of the usage of this input. |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 517 | class AudioInputDescriptor: public AudioPortConfig |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 518 | { |
| 519 | public: |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 520 | AudioInputDescriptor(const sp<IOProfile>& profile); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 521 | |
| 522 | status_t dump(int fd); |
| 523 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 524 | audio_port_handle_t mId; |
| 525 | audio_io_handle_t mIoHandle; // input handle |
| 526 | audio_devices_t mDevice; // current device this input is routed to |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 527 | AudioMix *mPolicyMix; // non NULL when used by a dynamic policy |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 528 | audio_patch_handle_t mPatchHandle; |
| 529 | uint32_t mRefCount; // number of AudioRecord clients using |
| 530 | // this input |
| 531 | uint32_t mOpenRefCount; |
| 532 | audio_source_t mInputSource; // input source selected by application |
| 533 | //(mediarecorder.h) |
| 534 | const sp<IOProfile> mProfile; // I/O profile this output derives from |
Eric Laurent | c722f30 | 2014-12-10 11:21:49 -0800 | [diff] [blame] | 535 | SortedVector<audio_session_t> mSessions; // audio sessions attached to this input |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 536 | bool mIsSoundTrigger; // used by a soundtrigger capture |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 537 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 538 | virtual void toAudioPortConfig(struct audio_port_config *dstConfig, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 539 | const struct audio_port_config *srcConfig = NULL) const; |
Marco Nelissen | 961ec21 | 2014-08-25 15:58:39 -0700 | [diff] [blame] | 540 | virtual sp<AudioPort> getAudioPort() const { return mProfile; } |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 541 | void toAudioPort(struct audio_port *port) const; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 542 | }; |
| 543 | |
| 544 | // stream descriptor used for volume control |
| 545 | class StreamDescriptor |
| 546 | { |
| 547 | public: |
| 548 | StreamDescriptor(); |
| 549 | |
| 550 | int getVolumeIndex(audio_devices_t device); |
| 551 | void dump(int fd); |
| 552 | |
| 553 | int mIndexMin; // min volume index |
| 554 | int mIndexMax; // max volume index |
| 555 | KeyedVector<audio_devices_t, int> mIndexCur; // current volume index per device |
| 556 | bool mCanBeMuted; // true is the stream can be muted |
| 557 | |
| 558 | const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT]; |
| 559 | }; |
| 560 | |
| 561 | // stream descriptor used for volume control |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 562 | class EffectDescriptor : public RefBase |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 563 | { |
| 564 | public: |
| 565 | |
| 566 | status_t dump(int fd); |
| 567 | |
| 568 | int mIo; // io the effect is attached to |
| 569 | routing_strategy mStrategy; // routing strategy the effect is associated to |
| 570 | int mSession; // audio session the effect is on |
| 571 | effect_descriptor_t mDesc; // effect descriptor |
| 572 | bool mEnabled; // enabled state: CPU load being used or not |
| 573 | }; |
| 574 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 575 | void addOutput(audio_io_handle_t output, sp<AudioOutputDescriptor> outputDesc); |
| 576 | void addInput(audio_io_handle_t input, sp<AudioInputDescriptor> inputDesc); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 577 | |
| 578 | // return the strategy corresponding to a given stream type |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 579 | static routing_strategy getStrategy(audio_stream_type_t stream); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 580 | |
| 581 | // return appropriate device for streams handled by the specified strategy according to current |
| 582 | // phone state, connected devices... |
| 583 | // if fromCache is true, the device is returned from mDeviceForStrategy[], |
| 584 | // otherwise it is determine by current state |
| 585 | // (device connected,phone state, force use, a2dp output...) |
| 586 | // This allows to: |
| 587 | // 1 speed up process when the state is stable (when starting or stopping an output) |
| 588 | // 2 access to either current device selection (fromCache == true) or |
| 589 | // "future" device selection (fromCache == false) when called from a context |
| 590 | // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND |
| 591 | // before updateDevicesAndOutputs() is called. |
| 592 | virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, |
| 593 | bool fromCache); |
| 594 | |
| 595 | // change the route of the specified output. Returns the number of ms we have slept to |
| 596 | // allow new routing to take effect in certain cases. |
| 597 | uint32_t setOutputDevice(audio_io_handle_t output, |
| 598 | audio_devices_t device, |
| 599 | bool force = false, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 600 | int delayMs = 0, |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 601 | audio_patch_handle_t *patchHandle = NULL, |
| 602 | const char* address = NULL); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 603 | status_t resetOutputDevice(audio_io_handle_t output, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 604 | int delayMs = 0, |
| 605 | audio_patch_handle_t *patchHandle = NULL); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 606 | status_t setInputDevice(audio_io_handle_t input, |
| 607 | audio_devices_t device, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 608 | bool force = false, |
| 609 | audio_patch_handle_t *patchHandle = NULL); |
| 610 | status_t resetInputDevice(audio_io_handle_t input, |
| 611 | audio_patch_handle_t *patchHandle = NULL); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 612 | |
| 613 | // select input device corresponding to requested audio source |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 614 | virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 615 | |
| 616 | // return io handle of active input or 0 if no input is active |
| 617 | // Only considers inputs from physical devices (e.g. main mic, headset mic) when |
| 618 | // ignoreVirtualInputs is true. |
| 619 | audio_io_handle_t getActiveInput(bool ignoreVirtualInputs = true); |
| 620 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 621 | uint32_t activeInputsCount() const; |
| 622 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 623 | // initialize volume curves for each strategy and device category |
| 624 | void initializeVolumeCurves(); |
| 625 | |
| 626 | // compute the actual volume for a given stream according to the requested index and a particular |
| 627 | // device |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 628 | virtual float computeVolume(audio_stream_type_t stream, int index, |
| 629 | audio_io_handle_t output, audio_devices_t device); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 630 | |
| 631 | // check that volume change is permitted, compute and send new volume to audio hardware |
Hochi Huang | 327cb70 | 2014-09-21 09:47:31 +0800 | [diff] [blame] | 632 | virtual status_t checkAndSetVolume(audio_stream_type_t stream, int index, |
| 633 | audio_io_handle_t output, |
| 634 | audio_devices_t device, |
| 635 | int delayMs = 0, bool force = false); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 636 | |
| 637 | // apply all stream volumes to the specified output and device |
| 638 | void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false); |
| 639 | |
| 640 | // Mute or unmute all streams handled by the specified strategy on the specified output |
| 641 | void setStrategyMute(routing_strategy strategy, |
| 642 | bool on, |
| 643 | audio_io_handle_t output, |
| 644 | int delayMs = 0, |
| 645 | audio_devices_t device = (audio_devices_t)0); |
| 646 | |
| 647 | // Mute or unmute the stream on the specified output |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 648 | void setStreamMute(audio_stream_type_t stream, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 649 | bool on, |
| 650 | audio_io_handle_t output, |
| 651 | int delayMs = 0, |
| 652 | audio_devices_t device = (audio_devices_t)0); |
| 653 | |
| 654 | // handle special cases for sonification strategy while in call: mute streams or replace by |
| 655 | // a special tone in the device used for communication |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 656 | void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 657 | |
| 658 | // true if device is in a telephony or VoIP call |
| 659 | virtual bool isInCall(); |
| 660 | |
| 661 | // true if given state represents a device in a telephony or VoIP call |
| 662 | virtual bool isStateInCall(int state); |
| 663 | |
| 664 | // when a device is connected, checks if an open output can be routed |
| 665 | // to this device. If none is open, tries to open one of the available outputs. |
| 666 | // Returns an output suitable to this device or 0. |
| 667 | // when a device is disconnected, checks if an output is not used any more and |
| 668 | // returns its handle if any. |
| 669 | // transfers the audio tracks and effects from one output thread to another accordingly. |
Jean-Michel Trivi | f17026d | 2014-08-10 14:30:48 -0700 | [diff] [blame] | 670 | status_t checkOutputsForDevice(const sp<DeviceDescriptor> devDesc, |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 671 | audio_policy_dev_state_t state, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 672 | SortedVector<audio_io_handle_t>& outputs, |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 673 | const String8 address); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 674 | |
Eric Laurent | d469296 | 2014-05-05 18:13:44 -0700 | [diff] [blame] | 675 | status_t checkInputsForDevice(audio_devices_t device, |
| 676 | audio_policy_dev_state_t state, |
| 677 | SortedVector<audio_io_handle_t>& inputs, |
| 678 | const String8 address); |
| 679 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 680 | // close an output and its companion duplicating output. |
| 681 | void closeOutput(audio_io_handle_t output); |
| 682 | |
Eric Laurent | 05b90f8 | 2014-08-27 15:32:29 -0700 | [diff] [blame] | 683 | // close an input. |
| 684 | void closeInput(audio_io_handle_t input); |
| 685 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 686 | // checks and if necessary changes outputs used for all strategies. |
| 687 | // must be called every time a condition that affects the output choice for a given strategy |
| 688 | // changes: connected device, phone state, force use... |
| 689 | // Must be called before updateDevicesAndOutputs() |
| 690 | void checkOutputForStrategy(routing_strategy strategy); |
| 691 | |
| 692 | // Same as checkOutputForStrategy() but for a all strategies in order of priority |
| 693 | void checkOutputForAllStrategies(); |
| 694 | |
| 695 | // manages A2DP output suspend/restore according to phone state and BT SCO usage |
| 696 | void checkA2dpSuspend(); |
| 697 | |
| 698 | // returns the A2DP output handle if it is open or 0 otherwise |
| 699 | audio_io_handle_t getA2dpOutput(); |
| 700 | |
| 701 | // selects the most appropriate device on output for current state |
| 702 | // must be called every time a condition that affects the device choice for a given output is |
| 703 | // changed: connected device, phone state, force use, output start, output stop.. |
| 704 | // see getDeviceForStrategy() for the use of fromCache parameter |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 705 | audio_devices_t getNewOutputDevice(audio_io_handle_t output, bool fromCache); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 706 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 707 | // updates cache of device used by all strategies (mDeviceForStrategy[]) |
| 708 | // must be called every time a condition that affects the device choice for a given strategy is |
| 709 | // changed: connected device, phone state, force use... |
| 710 | // cached values are used by getDeviceForStrategy() if parameter fromCache is true. |
| 711 | // Must be called after checkOutputForAllStrategies() |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 712 | void updateDevicesAndOutputs(); |
| 713 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 714 | // selects the most appropriate device on input for current state |
| 715 | audio_devices_t getNewInputDevice(audio_io_handle_t input); |
| 716 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 717 | virtual uint32_t getMaxEffectsCpuLoad(); |
| 718 | virtual uint32_t getMaxEffectsMemory(); |
| 719 | #ifdef AUDIO_POLICY_TEST |
| 720 | virtual bool threadLoop(); |
| 721 | void exit(); |
| 722 | int testOutputIndex(audio_io_handle_t output); |
| 723 | #endif //AUDIO_POLICY_TEST |
| 724 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 725 | status_t setEffectEnabled(const sp<EffectDescriptor>& effectDesc, bool enabled); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 726 | |
| 727 | // returns the category the device belongs to with regard to volume curve management |
| 728 | static device_category getDeviceCategory(audio_devices_t device); |
| 729 | |
| 730 | // extract one device relevant for volume control from multiple device selection |
| 731 | static audio_devices_t getDeviceForVolume(audio_devices_t device); |
| 732 | |
| 733 | SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device, |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 734 | DefaultKeyedVector<audio_io_handle_t, sp<AudioOutputDescriptor> > openOutputs); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 735 | bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1, |
| 736 | SortedVector<audio_io_handle_t>& outputs2); |
| 737 | |
| 738 | // mute/unmute strategies using an incompatible device combination |
| 739 | // if muting, wait for the audio in pcm buffer to be drained before proceeding |
| 740 | // if unmuting, unmute only after the specified delay |
| 741 | // Returns the number of ms waited |
Hochi Huang | 18f2f90 | 2014-12-03 15:23:36 +0800 | [diff] [blame] | 742 | virtual uint32_t checkDeviceMuteStrategies(sp<AudioOutputDescriptor> outputDesc, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 743 | audio_devices_t prevDevice, |
| 744 | uint32_t delayMs); |
| 745 | |
| 746 | audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs, |
Eric Laurent | 8838a38 | 2014-09-08 16:44:28 -0700 | [diff] [blame] | 747 | audio_output_flags_t flags, |
| 748 | audio_format_t format); |
Glenn Kasten | cbd4802 | 2014-07-24 13:46:44 -0700 | [diff] [blame] | 749 | // samplingRate parameter is an in/out and so may be modified |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 750 | sp<IOProfile> getInputProfile(audio_devices_t device, |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 751 | String8 address, |
| 752 | uint32_t& samplingRate, |
| 753 | audio_format_t format, |
| 754 | audio_channel_mask_t channelMask, |
| 755 | audio_input_flags_t flags); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 756 | sp<IOProfile> getProfileForDirectOutput(audio_devices_t device, |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 757 | uint32_t samplingRate, |
| 758 | audio_format_t format, |
| 759 | audio_channel_mask_t channelMask, |
| 760 | audio_output_flags_t flags); |
| 761 | |
| 762 | audio_io_handle_t selectOutputForEffects(const SortedVector<audio_io_handle_t>& outputs); |
| 763 | |
| 764 | bool isNonOffloadableEffectEnabled(); |
| 765 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 766 | status_t addAudioPatch(audio_patch_handle_t handle, |
| 767 | const sp<AudioPatch>& patch); |
| 768 | status_t removeAudioPatch(audio_patch_handle_t handle); |
| 769 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 770 | sp<AudioOutputDescriptor> getOutputFromId(audio_port_handle_t id) const; |
| 771 | sp<AudioInputDescriptor> getInputFromId(audio_port_handle_t id) const; |
| 772 | sp<HwModule> getModuleForDevice(audio_devices_t device) const; |
| 773 | sp<HwModule> getModuleFromName(const char *name) const; |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 774 | audio_devices_t availablePrimaryOutputDevices(); |
| 775 | audio_devices_t availablePrimaryInputDevices(); |
| 776 | |
| 777 | void updateCallRouting(audio_devices_t rxDevice, int delayMs = 0); |
| 778 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 779 | // |
| 780 | // Audio policy configuration file parsing (audio_policy.conf) |
| 781 | // |
| 782 | static uint32_t stringToEnum(const struct StringToEnum *table, |
| 783 | size_t size, |
| 784 | const char *name); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 785 | static const char *enumToString(const struct StringToEnum *table, |
| 786 | size_t size, |
| 787 | uint32_t value); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 788 | static bool stringToBool(const char *value); |
Eric Laurent | 5dbe471 | 2014-09-19 19:04:57 -0700 | [diff] [blame] | 789 | static uint32_t parseOutputFlagNames(char *name); |
| 790 | static uint32_t parseInputFlagNames(char *name); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 791 | static audio_devices_t parseDeviceNames(char *name); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 792 | void loadHwModule(cnode *root); |
| 793 | void loadHwModules(cnode *root); |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 794 | void loadGlobalConfig(cnode *root, const sp<HwModule>& module); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 795 | status_t loadAudioPolicyConfig(const char *path); |
| 796 | void defaultAudioPolicyConfig(void); |
| 797 | |
| 798 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 799 | uid_t mUidCached; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 800 | AudioPolicyClientInterface *mpClientInterface; // audio policy client interface |
| 801 | audio_io_handle_t mPrimaryOutput; // primary output handle |
| 802 | // list of descriptors for outputs currently opened |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 803 | DefaultKeyedVector<audio_io_handle_t, sp<AudioOutputDescriptor> > mOutputs; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 804 | // copy of mOutputs before setDeviceConnectionState() opens new outputs |
| 805 | // reset to mOutputs when updateDevicesAndOutputs() is called. |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 806 | DefaultKeyedVector<audio_io_handle_t, sp<AudioOutputDescriptor> > mPreviousOutputs; |
| 807 | DefaultKeyedVector<audio_io_handle_t, sp<AudioInputDescriptor> > mInputs; // list of input descriptors |
Eric Laurent | 1afeecb | 2014-05-14 08:52:28 -0700 | [diff] [blame] | 808 | DeviceVector mAvailableOutputDevices; // all available output devices |
| 809 | DeviceVector mAvailableInputDevices; // all available input devices |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 810 | int mPhoneState; // current phone state |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 811 | audio_policy_forced_cfg_t mForceUse[AUDIO_POLICY_FORCE_USE_CNT]; // current forced use configuration |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 812 | |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 813 | StreamDescriptor mStreams[AUDIO_STREAM_CNT]; // stream descriptors for volume control |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 814 | bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected |
| 815 | audio_devices_t mDeviceForStrategy[NUM_STRATEGIES]; |
| 816 | float mLastVoiceVolume; // last voice volume value sent to audio HAL |
| 817 | |
| 818 | // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units |
| 819 | static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000; |
| 820 | // Maximum memory allocated to audio effects in KB |
| 821 | static const uint32_t MAX_EFFECTS_MEMORY = 512; |
| 822 | uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects |
| 823 | uint32_t mTotalEffectsMemory; // current memory used by effects |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 824 | KeyedVector<int, sp<EffectDescriptor> > mEffects; // list of registered audio effects |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 825 | bool mA2dpSuspended; // true if A2DP output is suspended |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 826 | sp<DeviceDescriptor> mDefaultOutputDevice; // output device selected by default at boot time |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 827 | bool mSpeakerDrcEnabled;// true on devices that use DRC on the DEVICE_CATEGORY_SPEAKER path |
| 828 | // to boost soft sounds, used to adjust volume curves accordingly |
| 829 | |
Eric Laurent | 1f2f223 | 2014-06-02 12:01:23 -0700 | [diff] [blame] | 830 | Vector < sp<HwModule> > mHwModules; |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 831 | volatile int32_t mNextUniqueId; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 832 | volatile int32_t mAudioPortGeneration; |
| 833 | |
| 834 | DefaultKeyedVector<audio_patch_handle_t, sp<AudioPatch> > mAudioPatches; |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 835 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 836 | DefaultKeyedVector<audio_session_t, audio_io_handle_t> mSoundTriggerSessions; |
| 837 | |
Eric Laurent | c2730ba | 2014-07-20 15:47:07 -0700 | [diff] [blame] | 838 | sp<AudioPatch> mCallTxPatch; |
| 839 | sp<AudioPatch> mCallRxPatch; |
| 840 | |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 841 | // for supporting "beacon" streams, i.e. streams that only play on speaker, and never |
| 842 | // when something other than STREAM_TTS (a.k.a. "Transmitted Through Speaker") is playing |
| 843 | enum { |
| 844 | STARTING_OUTPUT, |
| 845 | STARTING_BEACON, |
| 846 | STOPPING_OUTPUT, |
| 847 | STOPPING_BEACON |
| 848 | }; |
| 849 | uint32_t mBeaconMuteRefCount; // ref count for stream that would mute beacon |
| 850 | uint32_t mBeaconPlayingRefCount;// ref count for the playing beacon streams |
| 851 | bool mBeaconMuted; // has STREAM_TTS been muted |
| 852 | |
Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 853 | // custom mix entry in mPolicyMixes |
| 854 | class AudioPolicyMix : public RefBase { |
| 855 | public: |
| 856 | AudioPolicyMix() {} |
| 857 | |
| 858 | AudioMix mMix; // Audio policy mix descriptor |
| 859 | sp<AudioOutputDescriptor> mOutput; // Corresponding output stream |
| 860 | }; |
| 861 | DefaultKeyedVector<String8, sp<AudioPolicyMix> > mPolicyMixes; // list of registered mixes |
| 862 | |
| 863 | |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 864 | #ifdef AUDIO_POLICY_TEST |
| 865 | Mutex mLock; |
| 866 | Condition mWaitWorkCV; |
| 867 | |
| 868 | int mCurOutput; |
| 869 | bool mDirectOutput; |
| 870 | audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS]; |
| 871 | int mTestInput; |
| 872 | uint32_t mTestDevice; |
| 873 | uint32_t mTestSamplingRate; |
| 874 | uint32_t mTestFormat; |
| 875 | uint32_t mTestChannels; |
| 876 | uint32_t mTestLatencyMs; |
| 877 | #endif //AUDIO_POLICY_TEST |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 878 | static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc, |
| 879 | int indexInUi); |
Hochi Huang | 327cb70 | 2014-09-21 09:47:31 +0800 | [diff] [blame] | 880 | private: |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 881 | // updates device caching and output for streams that can influence the |
| 882 | // routing of notifications |
Eric Laurent | 3b73df7 | 2014-03-11 09:06:29 -0700 | [diff] [blame] | 883 | void handleNotificationRoutingForStream(audio_stream_type_t stream); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 884 | static bool isVirtualInputDevice(audio_devices_t device); |
Jean-Michel Trivi | 0fb4775 | 2014-07-22 16:19:14 -0700 | [diff] [blame] | 885 | static bool deviceDistinguishesOnAddress(audio_devices_t device); |
| 886 | // find the outputs on a given output descriptor that have the given address. |
| 887 | // to be called on an AudioOutputDescriptor whose supported devices (as defined |
| 888 | // in mProfile->mSupportedDevices) matches the device whose address is to be matched. |
| 889 | // see deviceDistinguishesOnAddress(audio_devices_t) for whether the device type is one |
| 890 | // where addresses are used to distinguish between one connected device and another. |
| 891 | void findIoHandlesByAddress(sp<AudioOutputDescriptor> desc /*in*/, |
| 892 | const String8 address /*in*/, |
| 893 | SortedVector<audio_io_handle_t>& outputs /*out*/); |
Eric Laurent | 3a4311c | 2014-03-17 12:00:47 -0700 | [diff] [blame] | 894 | uint32_t nextUniqueId(); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 895 | uint32_t nextAudioPortGeneration(); |
| 896 | uint32_t curAudioPortGeneration() const { return mAudioPortGeneration; } |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 897 | // internal method to return the output handle for the given device and format |
| 898 | audio_io_handle_t getOutputForDevice( |
| 899 | audio_devices_t device, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 900 | audio_session_t session, |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 901 | audio_stream_type_t stream, |
| 902 | uint32_t samplingRate, |
| 903 | audio_format_t format, |
| 904 | audio_channel_mask_t channelMask, |
| 905 | audio_output_flags_t flags, |
| 906 | const audio_offload_info_t *offloadInfo); |
| 907 | // internal function to derive a stream type value from audio attributes |
| 908 | audio_stream_type_t streamTypefromAttributesInt(const audio_attributes_t *attr); |
Jean-Michel Trivi | d9cfeb4 | 2014-09-22 16:51:34 -0700 | [diff] [blame] | 909 | // return true if any output is playing anything besides the stream to ignore |
| 910 | bool isAnyOutputActive(audio_stream_type_t streamToIgnore); |
| 911 | // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON |
| 912 | // returns 0 if no mute/unmute event happened, the largest latency of the device where |
| 913 | // the mute/unmute happened |
| 914 | uint32_t handleEventForBeacon(int event); |
| 915 | uint32_t setBeaconMute(bool mute); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 916 | bool isValidAttributes(const audio_attributes_t *paa); |
Eric Laurent | c73ca6e | 2014-12-12 14:34:22 -0800 | [diff] [blame] | 917 | |
| 918 | // select input device corresponding to requested audio source and return associated policy |
| 919 | // mix if any. Calls getDeviceForInputSource(). |
| 920 | audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource, |
| 921 | AudioMix **policyMix = NULL); |
| 922 | |
| 923 | // Called by setDeviceConnectionState(). |
| 924 | status_t setDeviceConnectionStateInt(audio_devices_t device, |
| 925 | audio_policy_dev_state_t state, |
| 926 | const char *device_address); |
Eric Laurent | e552edb | 2014-03-10 17:42:56 -0700 | [diff] [blame] | 927 | }; |
| 928 | |
| 929 | }; |