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 | |
| 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <cutils/config_utils.h> |
| 22 | #include <cutils/misc.h> |
| 23 | #include <utils/Timers.h> |
| 24 | #include <utils/Errors.h> |
| 25 | #include <utils/KeyedVector.h> |
| 26 | #include <utils/SortedVector.h> |
| 27 | #include <media/AudioPolicy.h> |
| 28 | #include "AudioPolicyInterface.h" |
| 29 | |
Jean-Michel Trivi | 887a9ed | 2015-03-31 18:02:24 -0700 | [diff] [blame] | 30 | #include <AudioPolicyManagerInterface.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 31 | #include <AudioPolicyManagerObserver.h> |
François Gaffie | 98cc191 | 2015-03-18 17:52:40 +0100 | [diff] [blame] | 32 | #include <AudioGain.h> |
| 33 | #include <AudioPort.h> |
| 34 | #include <AudioPatch.h> |
| 35 | #include <ConfigParsingUtils.h> |
| 36 | #include <DeviceDescriptor.h> |
| 37 | #include <IOProfile.h> |
| 38 | #include <HwModule.h> |
| 39 | #include <AudioInputDescriptor.h> |
| 40 | #include <AudioOutputDescriptor.h> |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 41 | #include <AudioPolicyMix.h> |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 42 | #include <EffectDescriptor.h> |
François Gaffie | df37269 | 2015-03-19 10:43:27 +0100 | [diff] [blame] | 43 | #include <SoundTriggerSession.h> |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 44 | #include <StreamDescriptor.h> |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 45 | |
| 46 | namespace android { |
| 47 | |
| 48 | // ---------------------------------------------------------------------------- |
| 49 | |
| 50 | // Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB |
| 51 | #define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5 |
Eric Laurent | ffbc80f | 2015-03-18 18:30:19 -0700 | [diff] [blame] | 52 | #define SONIFICATION_HEADSET_VOLUME_FACTOR_DB (-6) |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 53 | // Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB |
| 54 | #define SONIFICATION_HEADSET_VOLUME_MIN 0.016 |
Eric Laurent | ffbc80f | 2015-03-18 18:30:19 -0700 | [diff] [blame] | 55 | #define SONIFICATION_HEADSET_VOLUME_MIN_DB (-36) |
| 56 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 57 | // Time in milliseconds during which we consider that music is still active after a music |
| 58 | // track was stopped - see computeVolume() |
| 59 | #define SONIFICATION_HEADSET_MUSIC_DELAY 5000 |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 60 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 61 | // Time in milliseconds during witch some streams are muted while the audio path |
| 62 | // is switched |
| 63 | #define MUTE_TIME_MS 2000 |
| 64 | |
| 65 | #define NUM_TEST_OUTPUTS 5 |
| 66 | |
| 67 | #define NUM_VOL_CURVE_KNEES 2 |
| 68 | |
| 69 | // Default minimum length allowed for offloading a compressed track |
| 70 | // Can be overridden by the audio.offload.min.duration.secs property |
| 71 | #define OFFLOAD_DEFAULT_MIN_DURATION_SECS 60 |
| 72 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 73 | // ---------------------------------------------------------------------------- |
| 74 | // AudioPolicyManager implements audio policy manager behavior common to all platforms. |
| 75 | // ---------------------------------------------------------------------------- |
| 76 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 77 | class AudioPolicyManager : public AudioPolicyInterface, public AudioPolicyManagerObserver |
| 78 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 79 | #ifdef AUDIO_POLICY_TEST |
| 80 | , public Thread |
| 81 | #endif //AUDIO_POLICY_TEST |
| 82 | { |
| 83 | |
| 84 | public: |
| 85 | AudioPolicyManager(AudioPolicyClientInterface *clientInterface); |
| 86 | virtual ~AudioPolicyManager(); |
| 87 | |
| 88 | // AudioPolicyInterface |
| 89 | virtual status_t setDeviceConnectionState(audio_devices_t device, |
| 90 | audio_policy_dev_state_t state, |
| 91 | const char *device_address, |
| 92 | const char *device_name); |
| 93 | virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device, |
| 94 | const char *device_address); |
| 95 | virtual void setPhoneState(audio_mode_t state); |
| 96 | virtual void setForceUse(audio_policy_force_use_t usage, |
| 97 | audio_policy_forced_cfg_t config); |
| 98 | 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] | 99 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 100 | virtual void setSystemProperty(const char* property, const char* value); |
| 101 | virtual status_t initCheck(); |
| 102 | virtual audio_io_handle_t getOutput(audio_stream_type_t stream, |
| 103 | uint32_t samplingRate, |
| 104 | audio_format_t format, |
| 105 | audio_channel_mask_t channelMask, |
| 106 | audio_output_flags_t flags, |
| 107 | const audio_offload_info_t *offloadInfo); |
| 108 | virtual status_t getOutputForAttr(const audio_attributes_t *attr, |
| 109 | audio_io_handle_t *output, |
| 110 | audio_session_t session, |
| 111 | audio_stream_type_t *stream, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 112 | uid_t uid, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 113 | uint32_t samplingRate, |
| 114 | audio_format_t format, |
| 115 | audio_channel_mask_t channelMask, |
| 116 | audio_output_flags_t flags, |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 117 | audio_port_handle_t selectedDeviceId, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 118 | const audio_offload_info_t *offloadInfo); |
| 119 | virtual status_t startOutput(audio_io_handle_t output, |
| 120 | audio_stream_type_t stream, |
| 121 | audio_session_t session); |
| 122 | virtual status_t stopOutput(audio_io_handle_t output, |
| 123 | audio_stream_type_t stream, |
| 124 | audio_session_t session); |
| 125 | virtual void releaseOutput(audio_io_handle_t output, |
| 126 | audio_stream_type_t stream, |
| 127 | audio_session_t session); |
| 128 | virtual status_t getInputForAttr(const audio_attributes_t *attr, |
| 129 | audio_io_handle_t *input, |
| 130 | audio_session_t session, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 131 | uid_t uid, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 132 | uint32_t samplingRate, |
| 133 | audio_format_t format, |
| 134 | audio_channel_mask_t channelMask, |
| 135 | audio_input_flags_t flags, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 136 | audio_port_handle_t selectedDeviceId, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 137 | input_type_t *inputType); |
| 138 | |
| 139 | // indicates to the audio policy manager that the input starts being used. |
| 140 | virtual status_t startInput(audio_io_handle_t input, |
| 141 | audio_session_t session); |
| 142 | |
| 143 | // indicates to the audio policy manager that the input stops being used. |
| 144 | virtual status_t stopInput(audio_io_handle_t input, |
| 145 | audio_session_t session); |
| 146 | virtual void releaseInput(audio_io_handle_t input, |
| 147 | audio_session_t session); |
| 148 | virtual void closeAllInputs(); |
| 149 | virtual void initStreamVolume(audio_stream_type_t stream, |
| 150 | int indexMin, |
| 151 | int indexMax); |
| 152 | virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, |
| 153 | int index, |
| 154 | audio_devices_t device); |
| 155 | virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, |
| 156 | int *index, |
| 157 | audio_devices_t device); |
| 158 | |
| 159 | // return the strategy corresponding to a given stream type |
| 160 | virtual uint32_t getStrategyForStream(audio_stream_type_t stream); |
| 161 | // return the strategy corresponding to the given audio attributes |
| 162 | virtual uint32_t getStrategyForAttr(const audio_attributes_t *attr); |
| 163 | |
| 164 | // return the enabled output devices for the given stream type |
| 165 | virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream); |
| 166 | |
| 167 | virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc = NULL); |
| 168 | virtual status_t registerEffect(const effect_descriptor_t *desc, |
| 169 | audio_io_handle_t io, |
| 170 | uint32_t strategy, |
| 171 | int session, |
| 172 | int id); |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 173 | virtual status_t unregisterEffect(int id) |
| 174 | { |
| 175 | return mEffects.unregisterEffect(id); |
| 176 | } |
| 177 | virtual status_t setEffectEnabled(int id, bool enabled) |
| 178 | { |
| 179 | return mEffects.setEffectEnabled(id, enabled); |
| 180 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 181 | |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 182 | 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] | 183 | // return whether a stream is playing remotely, override to change the definition of |
| 184 | // local/remote playback, used for instance by notification manager to not make |
| 185 | // media players lose audio focus when not playing locally |
| 186 | // For the base implementation, "remotely" means playing during screen mirroring which |
| 187 | // uses an output for playback with a non-empty, non "0" address. |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 188 | virtual bool isStreamActiveRemotely(audio_stream_type_t stream, |
| 189 | uint32_t inPastMs = 0) const; |
| 190 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 191 | virtual bool isSourceActive(audio_source_t source) const; |
| 192 | |
| 193 | virtual status_t dump(int fd); |
| 194 | |
| 195 | virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo); |
| 196 | |
| 197 | virtual status_t listAudioPorts(audio_port_role_t role, |
| 198 | audio_port_type_t type, |
| 199 | unsigned int *num_ports, |
| 200 | struct audio_port *ports, |
| 201 | unsigned int *generation); |
| 202 | virtual status_t getAudioPort(struct audio_port *port); |
| 203 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 204 | audio_patch_handle_t *handle, |
| 205 | uid_t uid); |
| 206 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle, |
| 207 | uid_t uid); |
| 208 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 209 | struct audio_patch *patches, |
| 210 | unsigned int *generation); |
| 211 | virtual status_t setAudioPortConfig(const struct audio_port_config *config); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 212 | |
| 213 | virtual status_t acquireSoundTriggerSession(audio_session_t *session, |
| 214 | audio_io_handle_t *ioHandle, |
| 215 | audio_devices_t *device); |
| 216 | |
François Gaffie | df37269 | 2015-03-19 10:43:27 +0100 | [diff] [blame] | 217 | virtual status_t releaseSoundTriggerSession(audio_session_t session) |
| 218 | { |
| 219 | return mSoundTriggerSessions.releaseSession(session); |
| 220 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 221 | |
| 222 | virtual status_t registerPolicyMixes(Vector<AudioMix> mixes); |
| 223 | virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes); |
| 224 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 225 | virtual status_t startAudioSource(const struct audio_port_config *source, |
| 226 | const audio_attributes_t *attributes, |
| 227 | audio_io_handle_t *handle); |
| 228 | virtual status_t stopAudioSource(audio_io_handle_t handle); |
| 229 | |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 230 | virtual void releaseResourcesForUid(uid_t uid); |
| 231 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 232 | // Audio policy configuration file parsing (audio_policy.conf) |
| 233 | // TODO candidates to be moved to ConfigParsingUtils |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 234 | void defaultAudioPolicyConfig(void); |
| 235 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 236 | // return the strategy corresponding to a given stream type |
| 237 | routing_strategy getStrategy(audio_stream_type_t stream) const; |
| 238 | |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 239 | protected: |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 240 | class SessionRoute : public RefBase { |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 241 | public: |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 242 | // For Input (Source) routes, use STREAM_TYPE_NA ("NA" = "not applicable)for the |
| 243 | // streamType argument |
| 244 | static const audio_stream_type_t STREAM_TYPE_NA = AUDIO_STREAM_DEFAULT; |
| 245 | |
| 246 | // For Output (Sink) routes, use SOURCE_TYPE_NA ("NA" = "not applicable") for the |
| 247 | // source argument |
| 248 | |
| 249 | static const audio_source_t SOURCE_TYPE_NA = AUDIO_SOURCE_DEFAULT; |
| 250 | |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 251 | SessionRoute(audio_session_t session, |
| 252 | audio_stream_type_t streamType, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 253 | audio_source_t source, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 254 | sp<DeviceDescriptor> deviceDescriptor, |
| 255 | uid_t uid) |
| 256 | : mUid(uid), |
| 257 | mSession(session), |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 258 | mDeviceDescriptor(deviceDescriptor), |
| 259 | mRefCount(0), |
| 260 | mActivityCount(0), |
| 261 | mChanged(false), |
| 262 | mStreamType(streamType), |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 263 | mSource(source) |
| 264 | {} |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 265 | |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 266 | void log(const char* prefix); |
| 267 | |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 268 | bool isActive() { |
| 269 | return (mDeviceDescriptor != 0) && (mChanged || (mActivityCount > 0)); |
| 270 | } |
| 271 | |
| 272 | uid_t mUid; |
| 273 | audio_session_t mSession; |
| 274 | sp<DeviceDescriptor> mDeviceDescriptor; |
| 275 | |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 276 | // "reference" counting |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 277 | int mRefCount; // +/- on references |
| 278 | int mActivityCount; // +/- on start/stop |
| 279 | bool mChanged; |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 280 | // for outputs |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 281 | const audio_stream_type_t mStreamType; |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 282 | // for inputs |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 283 | const audio_source_t mSource; |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 286 | class SessionRouteMap: public KeyedVector<audio_session_t, sp<SessionRoute>> { |
| 287 | public: |
| 288 | // These constants identify the SessionRoutMap as holding EITHER input routes, |
| 289 | // or output routes. An error will occur if an attempt is made to add a SessionRoute |
| 290 | // object with mStreamType == STREAM_TYPE_NA (i.e. an input SessionRoute) to a |
| 291 | // SessionRoutMap that is marked for output (i.e. mMapType == SESSION_ROUTE_MAP_OUTPUT) |
| 292 | // and similarly for output SessionRoutes and Input SessionRouteMaps. |
| 293 | typedef enum { |
| 294 | MAPTYPE_INPUT = 0, |
| 295 | MAPTYPE_OUTPUT = 1 |
| 296 | } session_route_map_type_t; |
| 297 | |
| 298 | SessionRouteMap(session_route_map_type_t mapType) : |
| 299 | mMapType(mapType) { |
| 300 | } |
| 301 | |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 302 | bool hasRoute(audio_session_t session); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 303 | |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 304 | void removeRoute(audio_session_t session); |
| 305 | |
| 306 | int incRouteActivity(audio_session_t session); |
| 307 | int decRouteActivity(audio_session_t session); |
Eric Laurent | 493404d | 2015-04-21 15:07:36 -0700 | [diff] [blame] | 308 | bool hasRouteChanged(audio_session_t session); // also clears the changed flag |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 309 | void log(const char* caption); |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 310 | |
| 311 | // Specify an Output(Sink) route by passing SessionRoute::SOURCE_TYPE_NA in the |
| 312 | // source argument. |
| 313 | // Specify an Input(Source) rout by passing SessionRoute::AUDIO_STREAM_DEFAULT |
| 314 | // in the streamType argument. |
| 315 | void addRoute(audio_session_t session, |
| 316 | audio_stream_type_t streamType, |
| 317 | audio_source_t source, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 318 | sp<DeviceDescriptor> deviceDescriptor, |
| 319 | uid_t uid); |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 320 | |
| 321 | private: |
| 322 | // Used to mark a SessionRoute as for either inputs (mMapType == kSessionRouteMap_Input) |
| 323 | // or outputs (mMapType == kSessionRouteMap_Output) |
| 324 | const session_route_map_type_t mMapType; |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 327 | // From AudioPolicyManagerObserver |
| 328 | virtual const AudioPatchCollection &getAudioPatches() const |
| 329 | { |
| 330 | return mAudioPatches; |
| 331 | } |
| 332 | virtual const SoundTriggerSessionCollection &getSoundTriggerSessionCollection() const |
| 333 | { |
| 334 | return mSoundTriggerSessions; |
| 335 | } |
| 336 | virtual const AudioPolicyMixCollection &getAudioPolicyMixCollection() const |
| 337 | { |
| 338 | return mPolicyMixes; |
| 339 | } |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 340 | virtual const SwAudioOutputCollection &getOutputs() const |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 341 | { |
| 342 | return mOutputs; |
| 343 | } |
| 344 | virtual const AudioInputCollection &getInputs() const |
| 345 | { |
| 346 | return mInputs; |
| 347 | } |
| 348 | virtual const DeviceVector &getAvailableOutputDevices() const |
| 349 | { |
| 350 | return mAvailableOutputDevices; |
| 351 | } |
| 352 | virtual const DeviceVector &getAvailableInputDevices() const |
| 353 | { |
| 354 | return mAvailableInputDevices; |
| 355 | } |
| 356 | virtual StreamDescriptorCollection &getStreamDescriptors() |
| 357 | { |
| 358 | return mStreams; |
| 359 | } |
| 360 | virtual const sp<DeviceDescriptor> &getDefaultOutputDevice() const |
| 361 | { |
| 362 | return mDefaultOutputDevice; |
| 363 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 364 | protected: |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 365 | void addOutput(audio_io_handle_t output, sp<SwAudioOutputDescriptor> outputDesc); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 366 | void removeOutput(audio_io_handle_t output); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 367 | void addInput(audio_io_handle_t input, sp<AudioInputDescriptor> inputDesc); |
| 368 | |
| 369 | // return appropriate device for streams handled by the specified strategy according to current |
| 370 | // phone state, connected devices... |
| 371 | // if fromCache is true, the device is returned from mDeviceForStrategy[], |
| 372 | // otherwise it is determine by current state |
| 373 | // (device connected,phone state, force use, a2dp output...) |
| 374 | // This allows to: |
| 375 | // 1 speed up process when the state is stable (when starting or stopping an output) |
| 376 | // 2 access to either current device selection (fromCache == true) or |
| 377 | // "future" device selection (fromCache == false) when called from a context |
| 378 | // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND |
| 379 | // before updateDevicesAndOutputs() is called. |
| 380 | virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, |
| 381 | bool fromCache); |
| 382 | |
Jean-Michel Trivi | 887a9ed | 2015-03-31 18:02:24 -0700 | [diff] [blame] | 383 | bool isStrategyActive(const sp<AudioOutputDescriptor> outputDesc, routing_strategy strategy, |
| 384 | uint32_t inPastMs = 0, nsecs_t sysTime = 0) const; |
| 385 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 386 | // change the route of the specified output. Returns the number of ms we have slept to |
| 387 | // allow new routing to take effect in certain cases. |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 388 | virtual uint32_t setOutputDevice(const sp<AudioOutputDescriptor>& outputDesc, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 389 | audio_devices_t device, |
| 390 | bool force = false, |
| 391 | int delayMs = 0, |
| 392 | audio_patch_handle_t *patchHandle = NULL, |
| 393 | const char* address = NULL); |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 394 | status_t resetOutputDevice(const sp<AudioOutputDescriptor>& outputDesc, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 395 | int delayMs = 0, |
| 396 | audio_patch_handle_t *patchHandle = NULL); |
| 397 | status_t setInputDevice(audio_io_handle_t input, |
| 398 | audio_devices_t device, |
| 399 | bool force = false, |
| 400 | audio_patch_handle_t *patchHandle = NULL); |
| 401 | status_t resetInputDevice(audio_io_handle_t input, |
| 402 | audio_patch_handle_t *patchHandle = NULL); |
| 403 | |
| 404 | // select input device corresponding to requested audio source |
| 405 | virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource); |
| 406 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 407 | // compute the actual volume for a given stream according to the requested index and a particular |
| 408 | // device |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 409 | virtual float computeVolume(audio_stream_type_t stream, |
| 410 | int index, |
| 411 | audio_devices_t device); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 412 | |
| 413 | // check that volume change is permitted, compute and send new volume to audio hardware |
| 414 | virtual status_t checkAndSetVolume(audio_stream_type_t stream, int index, |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 415 | const sp<AudioOutputDescriptor>& outputDesc, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 416 | audio_devices_t device, |
| 417 | int delayMs = 0, bool force = false); |
| 418 | |
| 419 | // apply all stream volumes to the specified output and device |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 420 | void applyStreamVolumes(const sp<AudioOutputDescriptor>& outputDesc, |
| 421 | audio_devices_t device, int delayMs = 0, bool force = false); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 422 | |
| 423 | // Mute or unmute all streams handled by the specified strategy on the specified output |
| 424 | void setStrategyMute(routing_strategy strategy, |
| 425 | bool on, |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 426 | const sp<AudioOutputDescriptor>& outputDesc, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 427 | int delayMs = 0, |
| 428 | audio_devices_t device = (audio_devices_t)0); |
| 429 | |
| 430 | // Mute or unmute the stream on the specified output |
| 431 | void setStreamMute(audio_stream_type_t stream, |
| 432 | bool on, |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 433 | const sp<AudioOutputDescriptor>& outputDesc, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 434 | int delayMs = 0, |
| 435 | audio_devices_t device = (audio_devices_t)0); |
| 436 | |
| 437 | // handle special cases for sonification strategy while in call: mute streams or replace by |
| 438 | // a special tone in the device used for communication |
| 439 | void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange); |
| 440 | |
Jean-Michel Trivi | 887a9ed | 2015-03-31 18:02:24 -0700 | [diff] [blame] | 441 | audio_mode_t getPhoneState(); |
| 442 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 443 | // true if device is in a telephony or VoIP call |
| 444 | virtual bool isInCall(); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 445 | // true if given state represents a device in a telephony or VoIP call |
| 446 | virtual bool isStateInCall(int state); |
| 447 | |
| 448 | // when a device is connected, checks if an open output can be routed |
| 449 | // to this device. If none is open, tries to open one of the available outputs. |
| 450 | // Returns an output suitable to this device or 0. |
| 451 | // when a device is disconnected, checks if an output is not used any more and |
| 452 | // returns its handle if any. |
| 453 | // transfers the audio tracks and effects from one output thread to another accordingly. |
| 454 | status_t checkOutputsForDevice(const sp<DeviceDescriptor> devDesc, |
| 455 | audio_policy_dev_state_t state, |
| 456 | SortedVector<audio_io_handle_t>& outputs, |
| 457 | const String8 address); |
| 458 | |
| 459 | status_t checkInputsForDevice(audio_devices_t device, |
| 460 | audio_policy_dev_state_t state, |
| 461 | SortedVector<audio_io_handle_t>& inputs, |
| 462 | const String8 address); |
| 463 | |
| 464 | // close an output and its companion duplicating output. |
| 465 | void closeOutput(audio_io_handle_t output); |
| 466 | |
| 467 | // close an input. |
| 468 | void closeInput(audio_io_handle_t input); |
| 469 | |
| 470 | // checks and if necessary changes outputs used for all strategies. |
| 471 | // must be called every time a condition that affects the output choice for a given strategy |
| 472 | // changes: connected device, phone state, force use... |
| 473 | // Must be called before updateDevicesAndOutputs() |
| 474 | void checkOutputForStrategy(routing_strategy strategy); |
| 475 | |
| 476 | // Same as checkOutputForStrategy() but for a all strategies in order of priority |
| 477 | void checkOutputForAllStrategies(); |
| 478 | |
| 479 | // manages A2DP output suspend/restore according to phone state and BT SCO usage |
| 480 | void checkA2dpSuspend(); |
| 481 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 482 | // selects the most appropriate device on output for current state |
| 483 | // must be called every time a condition that affects the device choice for a given output is |
| 484 | // changed: connected device, phone state, force use, output start, output stop.. |
| 485 | // see getDeviceForStrategy() for the use of fromCache parameter |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 486 | audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc, |
| 487 | bool fromCache); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 488 | |
| 489 | // updates cache of device used by all strategies (mDeviceForStrategy[]) |
| 490 | // must be called every time a condition that affects the device choice for a given strategy is |
| 491 | // changed: connected device, phone state, force use... |
| 492 | // cached values are used by getDeviceForStrategy() if parameter fromCache is true. |
| 493 | // Must be called after checkOutputForAllStrategies() |
| 494 | void updateDevicesAndOutputs(); |
| 495 | |
| 496 | // selects the most appropriate device on input for current state |
| 497 | audio_devices_t getNewInputDevice(audio_io_handle_t input); |
| 498 | |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 499 | virtual uint32_t getMaxEffectsCpuLoad() |
| 500 | { |
| 501 | return mEffects.getMaxEffectsCpuLoad(); |
| 502 | } |
| 503 | |
| 504 | virtual uint32_t getMaxEffectsMemory() |
| 505 | { |
| 506 | return mEffects.getMaxEffectsMemory(); |
| 507 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 508 | #ifdef AUDIO_POLICY_TEST |
| 509 | virtual bool threadLoop(); |
| 510 | void exit(); |
| 511 | int testOutputIndex(audio_io_handle_t output); |
| 512 | #endif //AUDIO_POLICY_TEST |
| 513 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 514 | SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device, |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 515 | SwAudioOutputCollection openOutputs); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 516 | bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1, |
| 517 | SortedVector<audio_io_handle_t>& outputs2); |
| 518 | |
| 519 | // mute/unmute strategies using an incompatible device combination |
| 520 | // if muting, wait for the audio in pcm buffer to be drained before proceeding |
| 521 | // if unmuting, unmute only after the specified delay |
| 522 | // Returns the number of ms waited |
| 523 | virtual uint32_t checkDeviceMuteStrategies(sp<AudioOutputDescriptor> outputDesc, |
| 524 | audio_devices_t prevDevice, |
| 525 | uint32_t delayMs); |
| 526 | |
| 527 | audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs, |
| 528 | audio_output_flags_t flags, |
| 529 | audio_format_t format); |
Andy Hung | f129b03 | 2015-04-07 13:45:50 -0700 | [diff] [blame] | 530 | // samplingRate, format, channelMask are in/out and so may be modified |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 531 | sp<IOProfile> getInputProfile(audio_devices_t device, |
| 532 | String8 address, |
| 533 | uint32_t& samplingRate, |
Andy Hung | f129b03 | 2015-04-07 13:45:50 -0700 | [diff] [blame] | 534 | audio_format_t& format, |
| 535 | audio_channel_mask_t& channelMask, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 536 | audio_input_flags_t flags); |
| 537 | sp<IOProfile> getProfileForDirectOutput(audio_devices_t device, |
| 538 | uint32_t samplingRate, |
| 539 | audio_format_t format, |
| 540 | audio_channel_mask_t channelMask, |
| 541 | audio_output_flags_t flags); |
| 542 | |
| 543 | audio_io_handle_t selectOutputForEffects(const SortedVector<audio_io_handle_t>& outputs); |
| 544 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 545 | virtual status_t addAudioPatch(audio_patch_handle_t handle, const sp<AudioPatch>& patch) |
| 546 | { |
| 547 | return mAudioPatches.addAudioPatch(handle, patch); |
| 548 | } |
| 549 | virtual status_t removeAudioPatch(audio_patch_handle_t handle) |
| 550 | { |
| 551 | return mAudioPatches.removeAudioPatch(handle); |
| 552 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 553 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 554 | audio_devices_t availablePrimaryOutputDevices() const |
| 555 | { |
Eric Laurent | 87ffa39 | 2015-05-22 10:32:38 -0700 | [diff] [blame^] | 556 | if (!hasPrimaryOutput()) { |
| 557 | return AUDIO_DEVICE_NONE; |
| 558 | } |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 559 | return mPrimaryOutput->supportedDevices() & mAvailableOutputDevices.types(); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 560 | } |
| 561 | audio_devices_t availablePrimaryInputDevices() const |
| 562 | { |
Eric Laurent | 87ffa39 | 2015-05-22 10:32:38 -0700 | [diff] [blame^] | 563 | if (!hasPrimaryOutput()) { |
| 564 | return AUDIO_DEVICE_NONE; |
| 565 | } |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 566 | return mAvailableInputDevices.getDevicesFromHwModule(mPrimaryOutput->getModuleHandle()); |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 567 | } |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 568 | |
| 569 | void updateCallRouting(audio_devices_t rxDevice, int delayMs = 0); |
| 570 | |
Eric Laurent | 493404d | 2015-04-21 15:07:36 -0700 | [diff] [blame] | 571 | // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force |
| 572 | // the re-evaluation of the output device. |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 573 | status_t startSource(sp<AudioOutputDescriptor> outputDesc, |
| 574 | audio_stream_type_t stream, |
| 575 | audio_devices_t device, |
| 576 | uint32_t *delayMs); |
| 577 | status_t stopSource(sp<AudioOutputDescriptor> outputDesc, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 578 | audio_stream_type_t stream, |
| 579 | bool forceDeviceUpdate); |
| 580 | |
| 581 | void clearAudioPatches(uid_t uid); |
| 582 | void clearSessionRoutes(uid_t uid); |
| 583 | void checkStrategyRoute(routing_strategy strategy, audio_io_handle_t ouptutToSkip); |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 584 | |
Eric Laurent | 87ffa39 | 2015-05-22 10:32:38 -0700 | [diff] [blame^] | 585 | status_t hasPrimaryOutput() const { return mPrimaryOutput != 0; } |
| 586 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 587 | uid_t mUidCached; |
| 588 | AudioPolicyClientInterface *mpClientInterface; // audio policy client interface |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 589 | sp<SwAudioOutputDescriptor> mPrimaryOutput; // primary output descriptor |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 590 | // list of descriptors for outputs currently opened |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 591 | |
| 592 | SwAudioOutputCollection mOutputs; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 593 | // copy of mOutputs before setDeviceConnectionState() opens new outputs |
| 594 | // reset to mOutputs when updateDevicesAndOutputs() is called. |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 595 | SwAudioOutputCollection mPreviousOutputs; |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 596 | AudioInputCollection mInputs; // list of input descriptors |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 597 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 598 | DeviceVector mAvailableOutputDevices; // all available output devices |
| 599 | DeviceVector mAvailableInputDevices; // all available input devices |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 600 | |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 601 | SessionRouteMap mOutputRoutes = SessionRouteMap(SessionRouteMap::MAPTYPE_OUTPUT); |
| 602 | SessionRouteMap mInputRoutes = SessionRouteMap(SessionRouteMap::MAPTYPE_INPUT); |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 603 | |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 604 | StreamDescriptorCollection mStreams; // stream descriptors for volume control |
| 605 | bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 606 | audio_devices_t mDeviceForStrategy[NUM_STRATEGIES]; |
François Gaffie | dfd7409 | 2015-03-19 12:10:59 +0100 | [diff] [blame] | 607 | float mLastVoiceVolume; // last voice volume value sent to audio HAL |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 608 | |
François Gaffie | 45ed3b0 | 2015-03-19 10:35:14 +0100 | [diff] [blame] | 609 | EffectDescriptorCollection mEffects; // list of registered audio effects |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 610 | bool mA2dpSuspended; // true if A2DP output is suspended |
| 611 | sp<DeviceDescriptor> mDefaultOutputDevice; // output device selected by default at boot time |
| 612 | bool mSpeakerDrcEnabled;// true on devices that use DRC on the DEVICE_CATEGORY_SPEAKER path |
| 613 | // to boost soft sounds, used to adjust volume curves accordingly |
| 614 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 615 | HwModuleCollection mHwModules; |
| 616 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 617 | volatile int32_t mAudioPortGeneration; |
| 618 | |
François Gaffie | 53615e2 | 2015-03-19 09:24:12 +0100 | [diff] [blame] | 619 | AudioPatchCollection mAudioPatches; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 620 | |
François Gaffie | df37269 | 2015-03-19 10:43:27 +0100 | [diff] [blame] | 621 | SoundTriggerSessionCollection mSoundTriggerSessions; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 622 | |
| 623 | sp<AudioPatch> mCallTxPatch; |
| 624 | sp<AudioPatch> mCallRxPatch; |
| 625 | |
| 626 | // for supporting "beacon" streams, i.e. streams that only play on speaker, and never |
| 627 | // when something other than STREAM_TTS (a.k.a. "Transmitted Through Speaker") is playing |
| 628 | enum { |
| 629 | STARTING_OUTPUT, |
| 630 | STARTING_BEACON, |
| 631 | STOPPING_OUTPUT, |
| 632 | STOPPING_BEACON |
| 633 | }; |
| 634 | uint32_t mBeaconMuteRefCount; // ref count for stream that would mute beacon |
| 635 | uint32_t mBeaconPlayingRefCount;// ref count for the playing beacon streams |
| 636 | bool mBeaconMuted; // has STREAM_TTS been muted |
| 637 | |
François Gaffie | 036e1e9 | 2015-03-19 10:16:24 +0100 | [diff] [blame] | 638 | AudioPolicyMixCollection mPolicyMixes; // list of registered mixes |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 639 | |
| 640 | #ifdef AUDIO_POLICY_TEST |
| 641 | Mutex mLock; |
| 642 | Condition mWaitWorkCV; |
| 643 | |
| 644 | int mCurOutput; |
| 645 | bool mDirectOutput; |
| 646 | audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS]; |
| 647 | int mTestInput; |
| 648 | uint32_t mTestDevice; |
| 649 | uint32_t mTestSamplingRate; |
| 650 | uint32_t mTestFormat; |
| 651 | uint32_t mTestChannels; |
| 652 | uint32_t mTestLatencyMs; |
| 653 | #endif //AUDIO_POLICY_TEST |
| 654 | |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 655 | uint32_t nextAudioPortGeneration(); |
Jean-Michel Trivi | 887a9ed | 2015-03-31 18:02:24 -0700 | [diff] [blame] | 656 | |
| 657 | // Audio Policy Engine Interface. |
| 658 | AudioPolicyManagerInterface *mEngine; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 659 | private: |
| 660 | // updates device caching and output for streams that can influence the |
| 661 | // routing of notifications |
| 662 | void handleNotificationRoutingForStream(audio_stream_type_t stream); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 663 | // find the outputs on a given output descriptor that have the given address. |
| 664 | // to be called on an AudioOutputDescriptor whose supported devices (as defined |
| 665 | // in mProfile->mSupportedDevices) matches the device whose address is to be matched. |
| 666 | // see deviceDistinguishesOnAddress(audio_devices_t) for whether the device type is one |
| 667 | // where addresses are used to distinguish between one connected device and another. |
Eric Laurent | c75307b | 2015-03-17 15:29:32 -0700 | [diff] [blame] | 668 | void findIoHandlesByAddress(sp<SwAudioOutputDescriptor> desc /*in*/, |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 669 | const audio_devices_t device /*in*/, |
| 670 | const String8 address /*in*/, |
| 671 | SortedVector<audio_io_handle_t>& outputs /*out*/); |
| 672 | uint32_t curAudioPortGeneration() const { return mAudioPortGeneration; } |
| 673 | // internal method to return the output handle for the given device and format |
| 674 | audio_io_handle_t getOutputForDevice( |
| 675 | audio_devices_t device, |
| 676 | audio_session_t session, |
| 677 | audio_stream_type_t stream, |
| 678 | uint32_t samplingRate, |
| 679 | audio_format_t format, |
| 680 | audio_channel_mask_t channelMask, |
| 681 | audio_output_flags_t flags, |
| 682 | const audio_offload_info_t *offloadInfo); |
| 683 | // internal function to derive a stream type value from audio attributes |
| 684 | audio_stream_type_t streamTypefromAttributesInt(const audio_attributes_t *attr); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 685 | // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON |
| 686 | // returns 0 if no mute/unmute event happened, the largest latency of the device where |
| 687 | // the mute/unmute happened |
| 688 | uint32_t handleEventForBeacon(int event); |
| 689 | uint32_t setBeaconMute(bool mute); |
| 690 | bool isValidAttributes(const audio_attributes_t *paa); |
| 691 | |
| 692 | // select input device corresponding to requested audio source and return associated policy |
| 693 | // mix if any. Calls getDeviceForInputSource(). |
| 694 | audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource, |
| 695 | AudioMix **policyMix = NULL); |
| 696 | |
| 697 | // Called by setDeviceConnectionState(). |
| 698 | status_t setDeviceConnectionStateInt(audio_devices_t device, |
| 699 | audio_policy_dev_state_t state, |
| 700 | const char *device_address, |
| 701 | const char *device_name); |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 702 | }; |
| 703 | |
| 704 | }; |