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