blob: 6b70f2eee31656184a51813bcfbb102fa77a0b58 [file] [log] [blame]
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -08001/*
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 Gaffiead3183e2015-03-18 16:55:35 +010017#pragma once
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -080018
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
François Gaffie98cc1912015-03-18 17:52:40 +010030#include <AudioGain.h>
31#include <AudioPort.h>
32#include <AudioPatch.h>
33#include <ConfigParsingUtils.h>
34#include <DeviceDescriptor.h>
35#include <IOProfile.h>
36#include <HwModule.h>
37#include <AudioInputDescriptor.h>
38#include <AudioOutputDescriptor.h>
François Gaffie036e1e92015-03-19 10:16:24 +010039#include <AudioPolicyMix.h>
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -080040
41namespace android {
42
43// ----------------------------------------------------------------------------
44
45// Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB
46#define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5
47// Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB
48#define SONIFICATION_HEADSET_VOLUME_MIN 0.016
49// Time in milliseconds during which we consider that music is still active after a music
50// track was stopped - see computeVolume()
51#define SONIFICATION_HEADSET_MUSIC_DELAY 5000
52// Time in milliseconds after media stopped playing during which we consider that the
53// sonification should be as unobtrusive as during the time media was playing.
54#define SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY 5000
55// Time in milliseconds during witch some streams are muted while the audio path
56// is switched
57#define MUTE_TIME_MS 2000
58
59#define NUM_TEST_OUTPUTS 5
60
61#define NUM_VOL_CURVE_KNEES 2
62
63// Default minimum length allowed for offloading a compressed track
64// Can be overridden by the audio.offload.min.duration.secs property
65#define OFFLOAD_DEFAULT_MIN_DURATION_SECS 60
66
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -080067// ----------------------------------------------------------------------------
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
François Gaffie53615e22015-03-19 09:24:12 +0100164 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const
165 {
166 return mOutputs.isStreamActive(stream, inPastMs);
167 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800168 // return whether a stream is playing remotely, override to change the definition of
169 // local/remote playback, used for instance by notification manager to not make
170 // media players lose audio focus when not playing locally
171 // For the base implementation, "remotely" means playing during screen mirroring which
172 // uses an output for playback with a non-empty, non "0" address.
François Gaffie53615e22015-03-19 09:24:12 +0100173 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const
174 {
175 return mOutputs.isStreamActiveRemotely(stream, inPastMs);
176 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800177 virtual bool isSourceActive(audio_source_t source) const;
178
179 virtual status_t dump(int fd);
180
181 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
182
183 virtual status_t listAudioPorts(audio_port_role_t role,
184 audio_port_type_t type,
185 unsigned int *num_ports,
186 struct audio_port *ports,
187 unsigned int *generation);
188 virtual status_t getAudioPort(struct audio_port *port);
189 virtual status_t createAudioPatch(const struct audio_patch *patch,
190 audio_patch_handle_t *handle,
191 uid_t uid);
192 virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
193 uid_t uid);
194 virtual status_t listAudioPatches(unsigned int *num_patches,
195 struct audio_patch *patches,
196 unsigned int *generation);
197 virtual status_t setAudioPortConfig(const struct audio_port_config *config);
198 virtual void clearAudioPatches(uid_t uid);
199
200 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
201 audio_io_handle_t *ioHandle,
202 audio_devices_t *device);
203
204 virtual status_t releaseSoundTriggerSession(audio_session_t session);
205
206 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes);
207 virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes);
208
209 // Audio policy configuration file parsing (audio_policy.conf)
210 // TODO candidates to be moved to ConfigParsingUtils
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800211 void defaultAudioPolicyConfig(void);
212
213 // return the strategy corresponding to a given stream type
214 static routing_strategy getStrategy(audio_stream_type_t stream);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800215protected:
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);
François Gaffie53615e22015-03-19 09:24:12 +0100231 void removeOutput(audio_io_handle_t output);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800232 void addInput(audio_io_handle_t input, sp<AudioInputDescriptor> inputDesc);
233
234 // return appropriate device for streams handled by the specified strategy according to current
235 // phone state, connected devices...
236 // if fromCache is true, the device is returned from mDeviceForStrategy[],
237 // otherwise it is determine by current state
238 // (device connected,phone state, force use, a2dp output...)
239 // This allows to:
240 // 1 speed up process when the state is stable (when starting or stopping an output)
241 // 2 access to either current device selection (fromCache == true) or
242 // "future" device selection (fromCache == false) when called from a context
243 // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
244 // before updateDevicesAndOutputs() is called.
245 virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy,
246 bool fromCache);
247
248 // change the route of the specified output. Returns the number of ms we have slept to
249 // allow new routing to take effect in certain cases.
250 virtual uint32_t setOutputDevice(audio_io_handle_t output,
251 audio_devices_t device,
252 bool force = false,
253 int delayMs = 0,
254 audio_patch_handle_t *patchHandle = NULL,
255 const char* address = NULL);
256 status_t resetOutputDevice(audio_io_handle_t output,
257 int delayMs = 0,
258 audio_patch_handle_t *patchHandle = NULL);
259 status_t setInputDevice(audio_io_handle_t input,
260 audio_devices_t device,
261 bool force = false,
262 audio_patch_handle_t *patchHandle = NULL);
263 status_t resetInputDevice(audio_io_handle_t input,
264 audio_patch_handle_t *patchHandle = NULL);
265
266 // select input device corresponding to requested audio source
267 virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource);
268
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800269 // initialize volume curves for each strategy and device category
270 void initializeVolumeCurves();
271
272 // compute the actual volume for a given stream according to the requested index and a particular
273 // device
274 virtual float computeVolume(audio_stream_type_t stream, int index,
275 audio_io_handle_t output, audio_devices_t device);
276
277 // check that volume change is permitted, compute and send new volume to audio hardware
278 virtual status_t checkAndSetVolume(audio_stream_type_t stream, int index,
279 audio_io_handle_t output,
280 audio_devices_t device,
281 int delayMs = 0, bool force = false);
282
283 // apply all stream volumes to the specified output and device
284 void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
285
286 // Mute or unmute all streams handled by the specified strategy on the specified output
287 void setStrategyMute(routing_strategy strategy,
288 bool on,
289 audio_io_handle_t output,
290 int delayMs = 0,
291 audio_devices_t device = (audio_devices_t)0);
292
293 // Mute or unmute the stream on the specified output
294 void setStreamMute(audio_stream_type_t stream,
295 bool on,
296 audio_io_handle_t output,
297 int delayMs = 0,
298 audio_devices_t device = (audio_devices_t)0);
299
300 // handle special cases for sonification strategy while in call: mute streams or replace by
301 // a special tone in the device used for communication
302 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange);
303
304 // true if device is in a telephony or VoIP call
305 virtual bool isInCall();
306
307 // true if given state represents a device in a telephony or VoIP call
308 virtual bool isStateInCall(int state);
309
310 // when a device is connected, checks if an open output can be routed
311 // to this device. If none is open, tries to open one of the available outputs.
312 // Returns an output suitable to this device or 0.
313 // when a device is disconnected, checks if an output is not used any more and
314 // returns its handle if any.
315 // transfers the audio tracks and effects from one output thread to another accordingly.
316 status_t checkOutputsForDevice(const sp<DeviceDescriptor> devDesc,
317 audio_policy_dev_state_t state,
318 SortedVector<audio_io_handle_t>& outputs,
319 const String8 address);
320
321 status_t checkInputsForDevice(audio_devices_t device,
322 audio_policy_dev_state_t state,
323 SortedVector<audio_io_handle_t>& inputs,
324 const String8 address);
325
326 // close an output and its companion duplicating output.
327 void closeOutput(audio_io_handle_t output);
328
329 // close an input.
330 void closeInput(audio_io_handle_t input);
331
332 // checks and if necessary changes outputs used for all strategies.
333 // must be called every time a condition that affects the output choice for a given strategy
334 // changes: connected device, phone state, force use...
335 // Must be called before updateDevicesAndOutputs()
336 void checkOutputForStrategy(routing_strategy strategy);
337
338 // Same as checkOutputForStrategy() but for a all strategies in order of priority
339 void checkOutputForAllStrategies();
340
341 // manages A2DP output suspend/restore according to phone state and BT SCO usage
342 void checkA2dpSuspend();
343
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800344 // selects the most appropriate device on output for current state
345 // must be called every time a condition that affects the device choice for a given output is
346 // changed: connected device, phone state, force use, output start, output stop..
347 // see getDeviceForStrategy() for the use of fromCache parameter
348 audio_devices_t getNewOutputDevice(audio_io_handle_t output, bool fromCache);
349
350 // updates cache of device used by all strategies (mDeviceForStrategy[])
351 // must be called every time a condition that affects the device choice for a given strategy is
352 // changed: connected device, phone state, force use...
353 // cached values are used by getDeviceForStrategy() if parameter fromCache is true.
354 // Must be called after checkOutputForAllStrategies()
355 void updateDevicesAndOutputs();
356
357 // selects the most appropriate device on input for current state
358 audio_devices_t getNewInputDevice(audio_io_handle_t input);
359
360 virtual uint32_t getMaxEffectsCpuLoad();
361 virtual uint32_t getMaxEffectsMemory();
362#ifdef AUDIO_POLICY_TEST
363 virtual bool threadLoop();
364 void exit();
365 int testOutputIndex(audio_io_handle_t output);
366#endif //AUDIO_POLICY_TEST
367
368 status_t setEffectEnabled(const sp<EffectDescriptor>& effectDesc, bool enabled);
369
370 SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device,
François Gaffie53615e22015-03-19 09:24:12 +0100371 AudioOutputCollection openOutputs);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800372 bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
373 SortedVector<audio_io_handle_t>& outputs2);
374
375 // mute/unmute strategies using an incompatible device combination
376 // if muting, wait for the audio in pcm buffer to be drained before proceeding
377 // if unmuting, unmute only after the specified delay
378 // Returns the number of ms waited
379 virtual uint32_t checkDeviceMuteStrategies(sp<AudioOutputDescriptor> outputDesc,
380 audio_devices_t prevDevice,
381 uint32_t delayMs);
382
383 audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs,
384 audio_output_flags_t flags,
385 audio_format_t format);
386 // samplingRate parameter is an in/out and so may be modified
387 sp<IOProfile> getInputProfile(audio_devices_t device,
388 String8 address,
389 uint32_t& samplingRate,
390 audio_format_t format,
391 audio_channel_mask_t channelMask,
392 audio_input_flags_t flags);
393 sp<IOProfile> getProfileForDirectOutput(audio_devices_t device,
394 uint32_t samplingRate,
395 audio_format_t format,
396 audio_channel_mask_t channelMask,
397 audio_output_flags_t flags);
398
399 audio_io_handle_t selectOutputForEffects(const SortedVector<audio_io_handle_t>& outputs);
400
401 bool isNonOffloadableEffectEnabled();
402
François Gaffie53615e22015-03-19 09:24:12 +0100403 virtual status_t addAudioPatch(audio_patch_handle_t handle, const sp<AudioPatch>& patch)
404 {
405 return mAudioPatches.addAudioPatch(handle, patch);
406 }
407 virtual status_t removeAudioPatch(audio_patch_handle_t handle)
408 {
409 return mAudioPatches.removeAudioPatch(handle);
410 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800411
François Gaffie53615e22015-03-19 09:24:12 +0100412 audio_devices_t availablePrimaryOutputDevices() const
413 {
414 return mOutputs.getSupportedDevices(mPrimaryOutput) & mAvailableOutputDevices.types();
415 }
416 audio_devices_t availablePrimaryInputDevices() const
417 {
418 return mAvailableInputDevices.getDevicesFromHwModule(
419 mOutputs.valueFor(mPrimaryOutput)->getModuleHandle());
420 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800421
422 void updateCallRouting(audio_devices_t rxDevice, int delayMs = 0);
423
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800424 uid_t mUidCached;
425 AudioPolicyClientInterface *mpClientInterface; // audio policy client interface
426 audio_io_handle_t mPrimaryOutput; // primary output handle
427 // list of descriptors for outputs currently opened
François Gaffie53615e22015-03-19 09:24:12 +0100428 AudioOutputCollection mOutputs;
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800429 // copy of mOutputs before setDeviceConnectionState() opens new outputs
430 // reset to mOutputs when updateDevicesAndOutputs() is called.
François Gaffie53615e22015-03-19 09:24:12 +0100431 AudioOutputCollection mPreviousOutputs;
432 AudioInputCollection mInputs; // list of input descriptors
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800433 DeviceVector mAvailableOutputDevices; // all available output devices
434 DeviceVector mAvailableInputDevices; // all available input devices
435 int mPhoneState; // current phone state
436 audio_policy_forced_cfg_t mForceUse[AUDIO_POLICY_FORCE_USE_CNT]; // current forced use configuration
437
438 StreamDescriptor mStreams[AUDIO_STREAM_CNT]; // stream descriptors for volume control
439 bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected
440 audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
441 float mLastVoiceVolume; // last voice volume value sent to audio HAL
442
443 // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
444 static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000;
445 // Maximum memory allocated to audio effects in KB
446 static const uint32_t MAX_EFFECTS_MEMORY = 512;
447 uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects
448 uint32_t mTotalEffectsMemory; // current memory used by effects
449 KeyedVector<int, sp<EffectDescriptor> > mEffects; // list of registered audio effects
450 bool mA2dpSuspended; // true if A2DP output is suspended
451 sp<DeviceDescriptor> mDefaultOutputDevice; // output device selected by default at boot time
452 bool mSpeakerDrcEnabled;// true on devices that use DRC on the DEVICE_CATEGORY_SPEAKER path
453 // to boost soft sounds, used to adjust volume curves accordingly
454
François Gaffie53615e22015-03-19 09:24:12 +0100455 HwModuleCollection mHwModules;
456
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800457 volatile int32_t mAudioPortGeneration;
458
François Gaffie53615e22015-03-19 09:24:12 +0100459 AudioPatchCollection mAudioPatches;
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800460
461 DefaultKeyedVector<audio_session_t, audio_io_handle_t> mSoundTriggerSessions;
462
463 sp<AudioPatch> mCallTxPatch;
464 sp<AudioPatch> mCallRxPatch;
465
466 // for supporting "beacon" streams, i.e. streams that only play on speaker, and never
467 // when something other than STREAM_TTS (a.k.a. "Transmitted Through Speaker") is playing
468 enum {
469 STARTING_OUTPUT,
470 STARTING_BEACON,
471 STOPPING_OUTPUT,
472 STOPPING_BEACON
473 };
474 uint32_t mBeaconMuteRefCount; // ref count for stream that would mute beacon
475 uint32_t mBeaconPlayingRefCount;// ref count for the playing beacon streams
476 bool mBeaconMuted; // has STREAM_TTS been muted
477
François Gaffie036e1e92015-03-19 10:16:24 +0100478 AudioPolicyMixCollection mPolicyMixes; // list of registered mixes
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800479
480#ifdef AUDIO_POLICY_TEST
481 Mutex mLock;
482 Condition mWaitWorkCV;
483
484 int mCurOutput;
485 bool mDirectOutput;
486 audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS];
487 int mTestInput;
488 uint32_t mTestDevice;
489 uint32_t mTestSamplingRate;
490 uint32_t mTestFormat;
491 uint32_t mTestChannels;
492 uint32_t mTestLatencyMs;
493#endif //AUDIO_POLICY_TEST
494
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800495 uint32_t nextAudioPortGeneration();
496private:
497 // updates device caching and output for streams that can influence the
498 // routing of notifications
499 void handleNotificationRoutingForStream(audio_stream_type_t stream);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800500 // find the outputs on a given output descriptor that have the given address.
501 // to be called on an AudioOutputDescriptor whose supported devices (as defined
502 // in mProfile->mSupportedDevices) matches the device whose address is to be matched.
503 // see deviceDistinguishesOnAddress(audio_devices_t) for whether the device type is one
504 // where addresses are used to distinguish between one connected device and another.
505 void findIoHandlesByAddress(sp<AudioOutputDescriptor> desc /*in*/,
506 const audio_devices_t device /*in*/,
507 const String8 address /*in*/,
508 SortedVector<audio_io_handle_t>& outputs /*out*/);
509 uint32_t curAudioPortGeneration() const { return mAudioPortGeneration; }
510 // internal method to return the output handle for the given device and format
511 audio_io_handle_t getOutputForDevice(
512 audio_devices_t device,
513 audio_session_t session,
514 audio_stream_type_t stream,
515 uint32_t samplingRate,
516 audio_format_t format,
517 audio_channel_mask_t channelMask,
518 audio_output_flags_t flags,
519 const audio_offload_info_t *offloadInfo);
520 // internal function to derive a stream type value from audio attributes
521 audio_stream_type_t streamTypefromAttributesInt(const audio_attributes_t *attr);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800522 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON
523 // returns 0 if no mute/unmute event happened, the largest latency of the device where
524 // the mute/unmute happened
525 uint32_t handleEventForBeacon(int event);
526 uint32_t setBeaconMute(bool mute);
527 bool isValidAttributes(const audio_attributes_t *paa);
528
529 // select input device corresponding to requested audio source and return associated policy
530 // mix if any. Calls getDeviceForInputSource().
531 audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource,
532 AudioMix **policyMix = NULL);
533
534 // Called by setDeviceConnectionState().
535 status_t setDeviceConnectionStateInt(audio_devices_t device,
536 audio_policy_dev_state_t state,
537 const char *device_address,
538 const char *device_name);
François Gaffiead3183e2015-03-18 16:55:35 +0100539
540 bool isStrategyActive(const sp<AudioOutputDescriptor> outputDesc, routing_strategy strategy,
541 uint32_t inPastMs = 0, nsecs_t sysTime = 0) const;
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800542};
543
544};