blob: 02b678ae2dcab7fbe09c56fe6b40ac44b7a71420 [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
Jean-Michel Trivi887a9ed2015-03-31 18:02:24 -070030#include <AudioPolicyManagerInterface.h>
François Gaffie2110e042015-03-24 08:41:51 +010031#include <AudioPolicyManagerObserver.h>
François Gaffie98cc1912015-03-18 17:52:40 +010032#include <AudioGain.h>
33#include <AudioPort.h>
34#include <AudioPatch.h>
35#include <ConfigParsingUtils.h>
36#include <DeviceDescriptor.h>
37#include <IOProfile.h>
38#include <HwModule.h>
39#include <AudioInputDescriptor.h>
40#include <AudioOutputDescriptor.h>
François Gaffie036e1e92015-03-19 10:16:24 +010041#include <AudioPolicyMix.h>
François Gaffie45ed3b02015-03-19 10:35:14 +010042#include <EffectDescriptor.h>
François Gaffiedf372692015-03-19 10:43:27 +010043#include <SoundTriggerSession.h>
François Gaffiedfd74092015-03-19 12:10:59 +010044#include <StreamDescriptor.h>
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -080045
46namespace android {
47
48// ----------------------------------------------------------------------------
49
50// Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB
51#define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5
52// Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB
53#define SONIFICATION_HEADSET_VOLUME_MIN 0.016
54// Time in milliseconds during which we consider that music is still active after a music
55// track was stopped - see computeVolume()
56#define SONIFICATION_HEADSET_MUSIC_DELAY 5000
François Gaffie2110e042015-03-24 08:41:51 +010057
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -080058// 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
François Gaffie2110e042015-03-24 08:41:51 +010074class AudioPolicyManager : public AudioPolicyInterface, public AudioPolicyManagerObserver
75
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -080076#ifdef AUDIO_POLICY_TEST
77 , public Thread
78#endif //AUDIO_POLICY_TEST
79{
80
81public:
82 AudioPolicyManager(AudioPolicyClientInterface *clientInterface);
83 virtual ~AudioPolicyManager();
84
85 // AudioPolicyInterface
86 virtual status_t setDeviceConnectionState(audio_devices_t device,
87 audio_policy_dev_state_t state,
88 const char *device_address,
89 const char *device_name);
90 virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
91 const char *device_address);
92 virtual void setPhoneState(audio_mode_t state);
93 virtual void setForceUse(audio_policy_force_use_t usage,
94 audio_policy_forced_cfg_t config);
95 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage);
François Gaffie2110e042015-03-24 08:41:51 +010096
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -080097 virtual void setSystemProperty(const char* property, const char* value);
98 virtual status_t initCheck();
99 virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
100 uint32_t samplingRate,
101 audio_format_t format,
102 audio_channel_mask_t channelMask,
103 audio_output_flags_t flags,
104 const audio_offload_info_t *offloadInfo);
105 virtual status_t getOutputForAttr(const audio_attributes_t *attr,
106 audio_io_handle_t *output,
107 audio_session_t session,
108 audio_stream_type_t *stream,
109 uint32_t samplingRate,
110 audio_format_t format,
111 audio_channel_mask_t channelMask,
112 audio_output_flags_t flags,
113 const audio_offload_info_t *offloadInfo);
114 virtual status_t startOutput(audio_io_handle_t output,
115 audio_stream_type_t stream,
116 audio_session_t session);
117 virtual status_t stopOutput(audio_io_handle_t output,
118 audio_stream_type_t stream,
119 audio_session_t session);
120 virtual void releaseOutput(audio_io_handle_t output,
121 audio_stream_type_t stream,
122 audio_session_t session);
123 virtual status_t getInputForAttr(const audio_attributes_t *attr,
124 audio_io_handle_t *input,
125 audio_session_t session,
126 uint32_t samplingRate,
127 audio_format_t format,
128 audio_channel_mask_t channelMask,
129 audio_input_flags_t flags,
130 input_type_t *inputType);
131
132 // indicates to the audio policy manager that the input starts being used.
133 virtual status_t startInput(audio_io_handle_t input,
134 audio_session_t session);
135
136 // indicates to the audio policy manager that the input stops being used.
137 virtual status_t stopInput(audio_io_handle_t input,
138 audio_session_t session);
139 virtual void releaseInput(audio_io_handle_t input,
140 audio_session_t session);
141 virtual void closeAllInputs();
142 virtual void initStreamVolume(audio_stream_type_t stream,
143 int indexMin,
144 int indexMax);
145 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
146 int index,
147 audio_devices_t device);
148 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
149 int *index,
150 audio_devices_t device);
151
152 // return the strategy corresponding to a given stream type
153 virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
154 // return the strategy corresponding to the given audio attributes
155 virtual uint32_t getStrategyForAttr(const audio_attributes_t *attr);
156
157 // return the enabled output devices for the given stream type
158 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream);
159
160 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc = NULL);
161 virtual status_t registerEffect(const effect_descriptor_t *desc,
162 audio_io_handle_t io,
163 uint32_t strategy,
164 int session,
165 int id);
François Gaffie45ed3b02015-03-19 10:35:14 +0100166 virtual status_t unregisterEffect(int id)
167 {
168 return mEffects.unregisterEffect(id);
169 }
170 virtual status_t setEffectEnabled(int id, bool enabled)
171 {
172 return mEffects.setEffectEnabled(id, enabled);
173 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800174
François Gaffie53615e22015-03-19 09:24:12 +0100175 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const
176 {
177 return mOutputs.isStreamActive(stream, inPastMs);
178 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800179 // return whether a stream is playing remotely, override to change the definition of
180 // local/remote playback, used for instance by notification manager to not make
181 // media players lose audio focus when not playing locally
182 // For the base implementation, "remotely" means playing during screen mirroring which
183 // uses an output for playback with a non-empty, non "0" address.
François Gaffie53615e22015-03-19 09:24:12 +0100184 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const
185 {
186 return mOutputs.isStreamActiveRemotely(stream, inPastMs);
187 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800188 virtual bool isSourceActive(audio_source_t source) const;
189
190 virtual status_t dump(int fd);
191
192 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
193
194 virtual status_t listAudioPorts(audio_port_role_t role,
195 audio_port_type_t type,
196 unsigned int *num_ports,
197 struct audio_port *ports,
198 unsigned int *generation);
199 virtual status_t getAudioPort(struct audio_port *port);
200 virtual status_t createAudioPatch(const struct audio_patch *patch,
201 audio_patch_handle_t *handle,
202 uid_t uid);
203 virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
204 uid_t uid);
205 virtual status_t listAudioPatches(unsigned int *num_patches,
206 struct audio_patch *patches,
207 unsigned int *generation);
208 virtual status_t setAudioPortConfig(const struct audio_port_config *config);
209 virtual void clearAudioPatches(uid_t uid);
210
211 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
212 audio_io_handle_t *ioHandle,
213 audio_devices_t *device);
214
François Gaffiedf372692015-03-19 10:43:27 +0100215 virtual status_t releaseSoundTriggerSession(audio_session_t session)
216 {
217 return mSoundTriggerSessions.releaseSession(session);
218 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800219
220 virtual status_t registerPolicyMixes(Vector<AudioMix> mixes);
221 virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes);
222
223 // Audio policy configuration file parsing (audio_policy.conf)
224 // TODO candidates to be moved to ConfigParsingUtils
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800225 void defaultAudioPolicyConfig(void);
226
François Gaffie2110e042015-03-24 08:41:51 +0100227 // return the strategy corresponding to a given stream type
228 routing_strategy getStrategy(audio_stream_type_t stream) const;
229
230 // From AudioPolicyManagerObserver
231 virtual const AudioPatchCollection &getAudioPatches() const
232 {
233 return mAudioPatches;
234 }
235 virtual const SoundTriggerSessionCollection &getSoundTriggerSessionCollection() const
236 {
237 return mSoundTriggerSessions;
238 }
239 virtual const AudioPolicyMixCollection &getAudioPolicyMixCollection() const
240 {
241 return mPolicyMixes;
242 }
243 virtual const AudioOutputCollection &getOutputs() const
244 {
245 return mOutputs;
246 }
247 virtual const AudioInputCollection &getInputs() const
248 {
249 return mInputs;
250 }
251 virtual const DeviceVector &getAvailableOutputDevices() const
252 {
253 return mAvailableOutputDevices;
254 }
255 virtual const DeviceVector &getAvailableInputDevices() const
256 {
257 return mAvailableInputDevices;
258 }
259 virtual StreamDescriptorCollection &getStreamDescriptors()
260 {
261 return mStreams;
262 }
263 virtual const sp<DeviceDescriptor> &getDefaultOutputDevice() const
264 {
265 return mDefaultOutputDevice;
266 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800267protected:
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800268 void addOutput(audio_io_handle_t output, sp<AudioOutputDescriptor> outputDesc);
François Gaffie53615e22015-03-19 09:24:12 +0100269 void removeOutput(audio_io_handle_t output);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800270 void addInput(audio_io_handle_t input, sp<AudioInputDescriptor> inputDesc);
271
272 // return appropriate device for streams handled by the specified strategy according to current
273 // phone state, connected devices...
274 // if fromCache is true, the device is returned from mDeviceForStrategy[],
275 // otherwise it is determine by current state
276 // (device connected,phone state, force use, a2dp output...)
277 // This allows to:
278 // 1 speed up process when the state is stable (when starting or stopping an output)
279 // 2 access to either current device selection (fromCache == true) or
280 // "future" device selection (fromCache == false) when called from a context
281 // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
282 // before updateDevicesAndOutputs() is called.
283 virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy,
284 bool fromCache);
285
Jean-Michel Trivi887a9ed2015-03-31 18:02:24 -0700286 bool isStrategyActive(const sp<AudioOutputDescriptor> outputDesc, routing_strategy strategy,
287 uint32_t inPastMs = 0, nsecs_t sysTime = 0) const;
288
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800289 // change the route of the specified output. Returns the number of ms we have slept to
290 // allow new routing to take effect in certain cases.
291 virtual uint32_t setOutputDevice(audio_io_handle_t output,
292 audio_devices_t device,
293 bool force = false,
294 int delayMs = 0,
295 audio_patch_handle_t *patchHandle = NULL,
296 const char* address = NULL);
297 status_t resetOutputDevice(audio_io_handle_t output,
298 int delayMs = 0,
299 audio_patch_handle_t *patchHandle = NULL);
300 status_t setInputDevice(audio_io_handle_t input,
301 audio_devices_t device,
302 bool force = false,
303 audio_patch_handle_t *patchHandle = NULL);
304 status_t resetInputDevice(audio_io_handle_t input,
305 audio_patch_handle_t *patchHandle = NULL);
306
307 // select input device corresponding to requested audio source
308 virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource);
309
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800310 // compute the actual volume for a given stream according to the requested index and a particular
311 // device
312 virtual float computeVolume(audio_stream_type_t stream, int index,
313 audio_io_handle_t output, audio_devices_t device);
314
315 // check that volume change is permitted, compute and send new volume to audio hardware
316 virtual status_t checkAndSetVolume(audio_stream_type_t stream, int index,
317 audio_io_handle_t output,
318 audio_devices_t device,
319 int delayMs = 0, bool force = false);
320
321 // apply all stream volumes to the specified output and device
322 void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
323
324 // Mute or unmute all streams handled by the specified strategy on the specified output
325 void setStrategyMute(routing_strategy strategy,
326 bool on,
327 audio_io_handle_t output,
328 int delayMs = 0,
329 audio_devices_t device = (audio_devices_t)0);
330
331 // Mute or unmute the stream on the specified output
332 void setStreamMute(audio_stream_type_t stream,
333 bool on,
334 audio_io_handle_t output,
335 int delayMs = 0,
336 audio_devices_t device = (audio_devices_t)0);
337
338 // handle special cases for sonification strategy while in call: mute streams or replace by
339 // a special tone in the device used for communication
340 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange);
341
Jean-Michel Trivi887a9ed2015-03-31 18:02:24 -0700342 audio_mode_t getPhoneState();
343
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800344 // true if device is in a telephony or VoIP call
345 virtual bool isInCall();
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800346 // true if given state represents a device in a telephony or VoIP call
347 virtual bool isStateInCall(int state);
348
349 // when a device is connected, checks if an open output can be routed
350 // to this device. If none is open, tries to open one of the available outputs.
351 // Returns an output suitable to this device or 0.
352 // when a device is disconnected, checks if an output is not used any more and
353 // returns its handle if any.
354 // transfers the audio tracks and effects from one output thread to another accordingly.
355 status_t checkOutputsForDevice(const sp<DeviceDescriptor> devDesc,
356 audio_policy_dev_state_t state,
357 SortedVector<audio_io_handle_t>& outputs,
358 const String8 address);
359
360 status_t checkInputsForDevice(audio_devices_t device,
361 audio_policy_dev_state_t state,
362 SortedVector<audio_io_handle_t>& inputs,
363 const String8 address);
364
365 // close an output and its companion duplicating output.
366 void closeOutput(audio_io_handle_t output);
367
368 // close an input.
369 void closeInput(audio_io_handle_t input);
370
371 // checks and if necessary changes outputs used for all strategies.
372 // must be called every time a condition that affects the output choice for a given strategy
373 // changes: connected device, phone state, force use...
374 // Must be called before updateDevicesAndOutputs()
375 void checkOutputForStrategy(routing_strategy strategy);
376
377 // Same as checkOutputForStrategy() but for a all strategies in order of priority
378 void checkOutputForAllStrategies();
379
380 // manages A2DP output suspend/restore according to phone state and BT SCO usage
381 void checkA2dpSuspend();
382
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800383 // selects the most appropriate device on output for current state
384 // must be called every time a condition that affects the device choice for a given output is
385 // changed: connected device, phone state, force use, output start, output stop..
386 // see getDeviceForStrategy() for the use of fromCache parameter
387 audio_devices_t getNewOutputDevice(audio_io_handle_t output, bool fromCache);
388
389 // updates cache of device used by all strategies (mDeviceForStrategy[])
390 // must be called every time a condition that affects the device choice for a given strategy is
391 // changed: connected device, phone state, force use...
392 // cached values are used by getDeviceForStrategy() if parameter fromCache is true.
393 // Must be called after checkOutputForAllStrategies()
394 void updateDevicesAndOutputs();
395
396 // selects the most appropriate device on input for current state
397 audio_devices_t getNewInputDevice(audio_io_handle_t input);
398
François Gaffie45ed3b02015-03-19 10:35:14 +0100399 virtual uint32_t getMaxEffectsCpuLoad()
400 {
401 return mEffects.getMaxEffectsCpuLoad();
402 }
403
404 virtual uint32_t getMaxEffectsMemory()
405 {
406 return mEffects.getMaxEffectsMemory();
407 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800408#ifdef AUDIO_POLICY_TEST
409 virtual bool threadLoop();
410 void exit();
411 int testOutputIndex(audio_io_handle_t output);
412#endif //AUDIO_POLICY_TEST
413
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800414 SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device,
François Gaffie53615e22015-03-19 09:24:12 +0100415 AudioOutputCollection openOutputs);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800416 bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
417 SortedVector<audio_io_handle_t>& outputs2);
418
419 // mute/unmute strategies using an incompatible device combination
420 // if muting, wait for the audio in pcm buffer to be drained before proceeding
421 // if unmuting, unmute only after the specified delay
422 // Returns the number of ms waited
423 virtual uint32_t checkDeviceMuteStrategies(sp<AudioOutputDescriptor> outputDesc,
424 audio_devices_t prevDevice,
425 uint32_t delayMs);
426
427 audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs,
428 audio_output_flags_t flags,
429 audio_format_t format);
430 // samplingRate parameter is an in/out and so may be modified
431 sp<IOProfile> getInputProfile(audio_devices_t device,
432 String8 address,
433 uint32_t& samplingRate,
434 audio_format_t format,
435 audio_channel_mask_t channelMask,
436 audio_input_flags_t flags);
437 sp<IOProfile> getProfileForDirectOutput(audio_devices_t device,
438 uint32_t samplingRate,
439 audio_format_t format,
440 audio_channel_mask_t channelMask,
441 audio_output_flags_t flags);
442
443 audio_io_handle_t selectOutputForEffects(const SortedVector<audio_io_handle_t>& outputs);
444
François Gaffie53615e22015-03-19 09:24:12 +0100445 virtual status_t addAudioPatch(audio_patch_handle_t handle, const sp<AudioPatch>& patch)
446 {
447 return mAudioPatches.addAudioPatch(handle, patch);
448 }
449 virtual status_t removeAudioPatch(audio_patch_handle_t handle)
450 {
451 return mAudioPatches.removeAudioPatch(handle);
452 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800453
François Gaffie53615e22015-03-19 09:24:12 +0100454 audio_devices_t availablePrimaryOutputDevices() const
455 {
456 return mOutputs.getSupportedDevices(mPrimaryOutput) & mAvailableOutputDevices.types();
457 }
458 audio_devices_t availablePrimaryInputDevices() const
459 {
460 return mAvailableInputDevices.getDevicesFromHwModule(
461 mOutputs.valueFor(mPrimaryOutput)->getModuleHandle());
462 }
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800463
464 void updateCallRouting(audio_devices_t rxDevice, int delayMs = 0);
465
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800466 uid_t mUidCached;
467 AudioPolicyClientInterface *mpClientInterface; // audio policy client interface
468 audio_io_handle_t mPrimaryOutput; // primary output handle
469 // list of descriptors for outputs currently opened
François Gaffie53615e22015-03-19 09:24:12 +0100470 AudioOutputCollection mOutputs;
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800471 // copy of mOutputs before setDeviceConnectionState() opens new outputs
472 // reset to mOutputs when updateDevicesAndOutputs() is called.
François Gaffie53615e22015-03-19 09:24:12 +0100473 AudioOutputCollection mPreviousOutputs;
474 AudioInputCollection mInputs; // list of input descriptors
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800475 DeviceVector mAvailableOutputDevices; // all available output devices
476 DeviceVector mAvailableInputDevices; // all available input devices
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800477
François Gaffiedfd74092015-03-19 12:10:59 +0100478 StreamDescriptorCollection mStreams; // stream descriptors for volume control
479 bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800480 audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
François Gaffiedfd74092015-03-19 12:10:59 +0100481 float mLastVoiceVolume; // last voice volume value sent to audio HAL
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800482
François Gaffie45ed3b02015-03-19 10:35:14 +0100483 EffectDescriptorCollection mEffects; // list of registered audio effects
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800484 bool mA2dpSuspended; // true if A2DP output is suspended
485 sp<DeviceDescriptor> mDefaultOutputDevice; // output device selected by default at boot time
486 bool mSpeakerDrcEnabled;// true on devices that use DRC on the DEVICE_CATEGORY_SPEAKER path
487 // to boost soft sounds, used to adjust volume curves accordingly
488
François Gaffie53615e22015-03-19 09:24:12 +0100489 HwModuleCollection mHwModules;
490
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800491 volatile int32_t mAudioPortGeneration;
492
François Gaffie53615e22015-03-19 09:24:12 +0100493 AudioPatchCollection mAudioPatches;
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800494
François Gaffiedf372692015-03-19 10:43:27 +0100495 SoundTriggerSessionCollection mSoundTriggerSessions;
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800496
497 sp<AudioPatch> mCallTxPatch;
498 sp<AudioPatch> mCallRxPatch;
499
500 // for supporting "beacon" streams, i.e. streams that only play on speaker, and never
501 // when something other than STREAM_TTS (a.k.a. "Transmitted Through Speaker") is playing
502 enum {
503 STARTING_OUTPUT,
504 STARTING_BEACON,
505 STOPPING_OUTPUT,
506 STOPPING_BEACON
507 };
508 uint32_t mBeaconMuteRefCount; // ref count for stream that would mute beacon
509 uint32_t mBeaconPlayingRefCount;// ref count for the playing beacon streams
510 bool mBeaconMuted; // has STREAM_TTS been muted
511
François Gaffie036e1e92015-03-19 10:16:24 +0100512 AudioPolicyMixCollection mPolicyMixes; // list of registered mixes
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800513
514#ifdef AUDIO_POLICY_TEST
515 Mutex mLock;
516 Condition mWaitWorkCV;
517
518 int mCurOutput;
519 bool mDirectOutput;
520 audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS];
521 int mTestInput;
522 uint32_t mTestDevice;
523 uint32_t mTestSamplingRate;
524 uint32_t mTestFormat;
525 uint32_t mTestChannels;
526 uint32_t mTestLatencyMs;
527#endif //AUDIO_POLICY_TEST
528
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800529 uint32_t nextAudioPortGeneration();
Jean-Michel Trivi887a9ed2015-03-31 18:02:24 -0700530
531 // Audio Policy Engine Interface.
532 AudioPolicyManagerInterface *mEngine;
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800533private:
534 // updates device caching and output for streams that can influence the
535 // routing of notifications
536 void handleNotificationRoutingForStream(audio_stream_type_t stream);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800537 // find the outputs on a given output descriptor that have the given address.
538 // to be called on an AudioOutputDescriptor whose supported devices (as defined
539 // in mProfile->mSupportedDevices) matches the device whose address is to be matched.
540 // see deviceDistinguishesOnAddress(audio_devices_t) for whether the device type is one
541 // where addresses are used to distinguish between one connected device and another.
542 void findIoHandlesByAddress(sp<AudioOutputDescriptor> desc /*in*/,
543 const audio_devices_t device /*in*/,
544 const String8 address /*in*/,
545 SortedVector<audio_io_handle_t>& outputs /*out*/);
546 uint32_t curAudioPortGeneration() const { return mAudioPortGeneration; }
547 // internal method to return the output handle for the given device and format
548 audio_io_handle_t getOutputForDevice(
549 audio_devices_t device,
550 audio_session_t session,
551 audio_stream_type_t stream,
552 uint32_t samplingRate,
553 audio_format_t format,
554 audio_channel_mask_t channelMask,
555 audio_output_flags_t flags,
556 const audio_offload_info_t *offloadInfo);
557 // internal function to derive a stream type value from audio attributes
558 audio_stream_type_t streamTypefromAttributesInt(const audio_attributes_t *attr);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800559 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON
560 // returns 0 if no mute/unmute event happened, the largest latency of the device where
561 // the mute/unmute happened
562 uint32_t handleEventForBeacon(int event);
563 uint32_t setBeaconMute(bool mute);
564 bool isValidAttributes(const audio_attributes_t *paa);
565
566 // select input device corresponding to requested audio source and return associated policy
567 // mix if any. Calls getDeviceForInputSource().
568 audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource,
569 AudioMix **policyMix = NULL);
570
571 // Called by setDeviceConnectionState().
572 status_t setDeviceConnectionStateInt(audio_devices_t device,
573 audio_policy_dev_state_t state,
574 const char *device_address,
575 const char *device_name);
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -0800576};
577
578};