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