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