blob: ccc0d32632aa4a8c92bf1caac239ab2962a7b458 [file] [log] [blame]
Nate Jiang7a7fd842022-12-06 17:11:13 -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
17#include <cutils/config_utils.h>
18#include <cutils/misc.h>
19#include <hardware_legacy/AudioPolicyInterface.h>
20#include <stdint.h>
21#include <sys/types.h>
22#include <utils/Errors.h>
23#include <utils/KeyedVector.h>
24#include <utils/SortedVector.h>
25#include <utils/Timers.h>
26
27namespace android_audio_legacy {
28using android::DefaultKeyedVector;
29using android::KeyedVector;
30using android::SortedVector;
31
32// ----------------------------------------------------------------------------
33
34#define MAX_DEVICE_ADDRESS_LEN 20
35// Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB
36#define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5
37// Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB
38#define SONIFICATION_HEADSET_VOLUME_MIN 0.016
39// Time in milliseconds during which we consider that music is still active after a music
40// track was stopped - see computeVolume()
41#define SONIFICATION_HEADSET_MUSIC_DELAY 5000
42// Time in milliseconds after media stopped playing during which we consider that the
43// sonification should be as unobtrusive as during the time media was playing.
44#define SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY 5000
45// Time in milliseconds during witch some streams are muted while the audio path
46// is switched
47#define MUTE_TIME_MS 2000
48
49#define NUM_TEST_OUTPUTS 5
50
51#define NUM_VOL_CURVE_KNEES 2
52
53// Default minimum length allowed for offloading a compressed track
54// Can be overridden by the audio.offload.min.duration.secs property
55#define OFFLOAD_DEFAULT_MIN_DURATION_SECS 60
56
57// ----------------------------------------------------------------------------
58// AudioPolicyManagerBase implements audio policy manager behavior common to all platforms.
59// Each platform must implement an AudioPolicyManager class derived from AudioPolicyManagerBase
60// and override methods for which the platform specific behavior differs from the implementation
61// in AudioPolicyManagerBase. Even if no specific behavior is required, the AudioPolicyManager
62// class must be implemented as well as the class factory function createAudioPolicyManager()
63// and provided in a shared library libaudiopolicy.so.
64// ----------------------------------------------------------------------------
65
66class AudioPolicyManagerBase : public AudioPolicyInterface
67#ifdef AUDIO_POLICY_TEST
68 ,
69 public Thread
70#endif // AUDIO_POLICY_TEST
71{
72
73 public:
74 AudioPolicyManagerBase(AudioPolicyClientInterface* clientInterface);
75 virtual ~AudioPolicyManagerBase();
76
77 // AudioPolicyInterface
78 virtual status_t setDeviceConnectionState(audio_devices_t device,
79 AudioSystem::device_connection_state state,
80 const char* device_address);
81 virtual AudioSystem::device_connection_state getDeviceConnectionState(
82 audio_devices_t device, const char* device_address);
83 virtual void setPhoneState(int state);
84 virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config);
85 virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage);
86 virtual void setSystemProperty(const char* property, const char* value);
87 virtual status_t initCheck();
88 virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream, uint32_t samplingRate,
89 audio_format_t format, audio_channel_mask_t channelMask,
90 AudioSystem::output_flags flags,
91 const audio_offload_info_t* offloadInfo);
92 virtual status_t startOutput(audio_io_handle_t output, AudioSystem::stream_type stream,
93 audio_session_t session = AUDIO_SESSION_NONE);
94 virtual status_t stopOutput(audio_io_handle_t output, AudioSystem::stream_type stream,
95 audio_session_t session = AUDIO_SESSION_NONE);
96 virtual void releaseOutput(audio_io_handle_t output);
97 virtual audio_io_handle_t getInput(int inputSource, uint32_t samplingRate,
98 audio_format_t format, audio_channel_mask_t channelMask,
99 AudioSystem::audio_in_acoustics acoustics);
100
101 // indicates to the audio policy manager that the input starts being used.
102 virtual status_t startInput(audio_io_handle_t input);
103
104 // indicates to the audio policy manager that the input stops being used.
105 virtual status_t stopInput(audio_io_handle_t input);
106 virtual void releaseInput(audio_io_handle_t input);
107 virtual void closeAllInputs();
108 virtual void initStreamVolume(AudioSystem::stream_type stream, int indexMin, int indexMax);
109 virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, int index,
110 audio_devices_t device);
111 virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, int* index,
112 audio_devices_t device);
113
114 // return the strategy corresponding to a given stream type
115 virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream);
116
117 // return the enabled output devices for the given stream type
118 virtual audio_devices_t getDevicesForStream(AudioSystem::stream_type stream);
119
120 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t* desc = NULL);
121 virtual status_t registerEffect(const effect_descriptor_t* desc, audio_io_handle_t io,
122 uint32_t strategy, audio_session_t session, int id);
123 virtual status_t unregisterEffect(int id);
124 virtual status_t setEffectEnabled(int id, bool enabled);
125
126 virtual bool isStreamActive(int stream, uint32_t inPastMs = 0) const;
127 // return whether a stream is playing remotely, override to change the definition of
128 // local/remote playback, used for instance by notification manager to not make
129 // media players lose audio focus when not playing locally
130 virtual bool isStreamActiveRemotely(int stream, uint32_t inPastMs = 0) const;
131 virtual bool isSourceActive(audio_source_t source) const;
132
133 virtual status_t dump(int fd);
134
135 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
136
137 protected:
138 enum routing_strategy {
139 STRATEGY_MEDIA,
140 STRATEGY_PHONE,
141 STRATEGY_SONIFICATION,
142 STRATEGY_SONIFICATION_RESPECTFUL,
143 STRATEGY_DTMF,
144 STRATEGY_ENFORCED_AUDIBLE,
145 NUM_STRATEGIES
146 };
147
148 // 4 points to define the volume attenuation curve, each characterized by the volume
149 // index (from 0 to 100) at which they apply, and the attenuation in dB at that index.
150 // we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl()
151
152 enum { VOLMIN = 0, VOLKNEE1 = 1, VOLKNEE2 = 2, VOLMAX = 3, VOLCNT = 4 };
153
154 class VolumeCurvePoint {
155 public:
156 int mIndex;
157 float mDBAttenuation;
158 };
159
160 // device categories used for volume curve management.
161 enum device_category {
162 DEVICE_CATEGORY_HEADSET,
163 DEVICE_CATEGORY_SPEAKER,
164 DEVICE_CATEGORY_EARPIECE,
165 DEVICE_CATEGORY_CNT
166 };
167
168 class IOProfile;
169
170 class HwModule {
171 public:
172 HwModule(const char* name);
173 ~HwModule();
174
175 void dump(int fd);
176
177 const char* const mName; // base name of the audio HW module (primary, a2dp ...)
178 audio_module_handle_t mHandle;
179 Vector<IOProfile*> mOutputProfiles; // output profiles exposed by this module
180 Vector<IOProfile*> mInputProfiles; // input profiles exposed by this module
181 };
182
183 // the IOProfile class describes the capabilities of an output or input stream.
184 // It is currently assumed that all combination of listed parameters are supported.
185 // It is used by the policy manager to determine if an output or input is suitable for
186 // a given use case, open/close it accordingly and connect/disconnect audio tracks
187 // to/from it.
188 class IOProfile {
189 public:
190 IOProfile(HwModule* module);
191 ~IOProfile();
192
193 bool isCompatibleProfile(audio_devices_t device, uint32_t samplingRate,
194 audio_format_t format, audio_channel_mask_t channelMask,
195 audio_output_flags_t flags) const;
196
197 void dump(int fd);
198 void log();
199
200 // by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats
201 // indicates the supported parameters should be read from the output stream
202 // after it is opened for the first time
203 Vector<uint32_t> mSamplingRates; // supported sampling rates
204 Vector<audio_channel_mask_t> mChannelMasks; // supported channel masks
205 Vector<audio_format_t> mFormats; // supported audio formats
206 audio_devices_t mSupportedDevices; // supported devices (devices this output can be
207 // routed to)
208 audio_output_flags_t mFlags; // attribute flags (e.g primary output,
209 // direct output...). For outputs only.
210 HwModule* mModule; // audio HW module exposing this I/O stream
211 };
212
213 // default volume curve
214 static const VolumeCurvePoint sDefaultVolumeCurve[AudioPolicyManagerBase::VOLCNT];
215 // default volume curve for media strategy
216 static const VolumeCurvePoint sDefaultMediaVolumeCurve[AudioPolicyManagerBase::VOLCNT];
217 // volume curve for media strategy on speakers
218 static const VolumeCurvePoint sSpeakerMediaVolumeCurve[AudioPolicyManagerBase::VOLCNT];
219 // volume curve for sonification strategy on speakers
220 static const VolumeCurvePoint sSpeakerSonificationVolumeCurve[AudioPolicyManagerBase::VOLCNT];
221 static const VolumeCurvePoint
222 sSpeakerSonificationVolumeCurveDrc[AudioPolicyManagerBase::VOLCNT];
223 static const VolumeCurvePoint sDefaultSystemVolumeCurve[AudioPolicyManagerBase::VOLCNT];
224 static const VolumeCurvePoint sDefaultSystemVolumeCurveDrc[AudioPolicyManagerBase::VOLCNT];
225 static const VolumeCurvePoint sHeadsetSystemVolumeCurve[AudioPolicyManagerBase::VOLCNT];
226 static const VolumeCurvePoint sDefaultVoiceVolumeCurve[AudioPolicyManagerBase::VOLCNT];
227 static const VolumeCurvePoint sSpeakerVoiceVolumeCurve[AudioPolicyManagerBase::VOLCNT];
228 // default volume curves per stream and device category. See initializeVolumeCurves()
229 static const VolumeCurvePoint* sVolumeProfiles[AudioSystem::NUM_STREAM_TYPES]
230 [DEVICE_CATEGORY_CNT];
231
232 // descriptor for audio outputs. Used to maintain current configuration of each opened audio
233 // output and keep track of the usage of this output by each audio stream type.
234 class AudioOutputDescriptor {
235 public:
236 AudioOutputDescriptor(const IOProfile* profile);
237
238 status_t dump(int fd);
239
240 audio_devices_t device() const;
241 void changeRefCount(AudioSystem::stream_type stream, int delta);
242
243 bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); }
244 audio_devices_t supportedDevices();
245 uint32_t latency();
246 bool sharesHwModuleWith(const AudioOutputDescriptor* outputDesc);
247 bool isActive(uint32_t inPastMs = 0) const;
248 bool isStreamActive(AudioSystem::stream_type stream, uint32_t inPastMs = 0,
249 nsecs_t sysTime = 0) const;
250 bool isStrategyActive(routing_strategy strategy, uint32_t inPastMs = 0,
251 nsecs_t sysTime = 0) const;
252
253 audio_io_handle_t mId; // output handle
254 uint32_t mSamplingRate; //
255 audio_format_t mFormat; //
256 audio_channel_mask_t mChannelMask; // output configuration
257 uint32_t mLatency; //
258 audio_output_flags_t mFlags; //
259 audio_devices_t mDevice; // current device this output is routed to
260 uint32_t mRefCount[AudioSystem::NUM_STREAM_TYPES]; // number of streams of each type using
261 // this output
262 nsecs_t mStopTime[AudioSystem::NUM_STREAM_TYPES];
263 AudioOutputDescriptor* mOutput1; // used by duplicated outputs: first output
264 AudioOutputDescriptor* mOutput2; // used by duplicated outputs: second output
265 float mCurVolume[AudioSystem::NUM_STREAM_TYPES]; // current stream volume
266 int mMuteCount[AudioSystem::NUM_STREAM_TYPES]; // mute request counter
267 const IOProfile* mProfile; // I/O profile this output derives from
268 bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible
269 // device selection. See
270 // checkDeviceMuteStrategies()
271 uint32_t mDirectOpenCount; // number of clients using this output (direct outputs only)
272 bool mForceRouting; // Next routing for this output will be forced as current device routed
273 // is null
274 };
275
276 // descriptor for audio inputs. Used to maintain current configuration of each opened audio
277 // input and keep track of the usage of this input.
278 class AudioInputDescriptor {
279 public:
280 AudioInputDescriptor(const IOProfile* profile);
281
282 status_t dump(int fd);
283
284 audio_io_handle_t mId; // input handle
285 uint32_t mSamplingRate; //
286 audio_format_t mFormat; // input configuration
287 audio_channel_mask_t mChannelMask; //
288 audio_devices_t mDevice; // current device this input is routed to
289 uint32_t mRefCount; // number of AudioRecord clients using this output
290 int mInputSource; // input source selected by application (mediarecorder.h)
291 const IOProfile* mProfile; // I/O profile this output derives from
292 };
293
294 // stream descriptor used for volume control
295 class StreamDescriptor {
296 public:
297 StreamDescriptor();
298
299 int getVolumeIndex(audio_devices_t device);
300 void dump(int fd);
301
302 int mIndexMin; // min volume index
303 int mIndexMax; // max volume index
304 KeyedVector<audio_devices_t, int> mIndexCur; // current volume index per device
305 bool mCanBeMuted; // true is the stream can be muted
306
307 const VolumeCurvePoint* mVolumeCurve[DEVICE_CATEGORY_CNT];
308 };
309
310 // stream descriptor used for volume control
311 class EffectDescriptor {
312 public:
313 status_t dump(int fd);
314
315 int mIo; // io the effect is attached to
316 routing_strategy mStrategy; // routing strategy the effect is associated to
317 audio_session_t mSession; // audio session the effect is on
318 effect_descriptor_t mDesc; // effect descriptor
319 bool mEnabled; // enabled state: CPU load being used or not
320 };
321
322 void addOutput(audio_io_handle_t id, AudioOutputDescriptor* outputDesc);
323 void addInput(audio_io_handle_t id, AudioInputDescriptor* inputDesc);
324
325 // return the strategy corresponding to a given stream type
326 static routing_strategy getStrategy(AudioSystem::stream_type stream);
327
328 // return appropriate device for streams handled by the specified strategy according to current
329 // phone state, connected devices...
330 // if fromCache is true, the device is returned from mDeviceForStrategy[],
331 // otherwise it is determine by current state
332 // (device connected,phone state, force use, a2dp output...)
333 // This allows to:
334 // 1 speed up process when the state is stable (when starting or stopping an output)
335 // 2 access to either current device selection (fromCache == true) or
336 // "future" device selection (fromCache == false) when called from a context
337 // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
338 // before updateDevicesAndOutputs() is called.
339 virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, bool fromCache);
340
341 // change the route of the specified output. Returns the number of ms we have slept to
342 // allow new routing to take effect in certain cases.
343 uint32_t setOutputDevice(audio_io_handle_t output, audio_devices_t device, bool force = false,
344 int delayMs = 0);
345
346 // select input device corresponding to requested audio source
347 virtual audio_devices_t getDeviceForInputSource(int inputSource);
348
349 // return io handle of active input or 0 if no input is active
350 // Only considers inputs from physical devices (e.g. main mic, headset mic) when
351 // ignoreVirtualInputs is true.
352 audio_io_handle_t getActiveInput(bool ignoreVirtualInputs = true);
353
354 // initialize volume curves for each strategy and device category
355 void initializeVolumeCurves();
356
357 // compute the actual volume for a given stream according to the requested index and a
358 // particular device
359 virtual float computeVolume(int stream, int index, audio_io_handle_t output,
360 audio_devices_t device);
361
362 // check that volume change is permitted, compute and send new volume to audio hardware
363 status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output,
364 audio_devices_t device, int delayMs = 0, bool force = false);
365
366 // apply all stream volumes to the specified output and device
367 void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0,
368 bool force = false);
369
370 // Mute or unmute all streams handled by the specified strategy on the specified output
371 void setStrategyMute(routing_strategy strategy, bool on, audio_io_handle_t output,
372 int delayMs = 0, audio_devices_t device = (audio_devices_t)0);
373
374 // Mute or unmute the stream on the specified output
375 void setStreamMute(int stream, bool on, audio_io_handle_t output, int delayMs = 0,
376 audio_devices_t device = (audio_devices_t)0);
377
378 // handle special cases for sonification strategy while in call: mute streams or replace by
379 // a special tone in the device used for communication
380 void handleIncallSonification(int stream, bool starting, bool stateChange);
381
382 // true if device is in a telephony or VoIP call
383 virtual bool isInCall();
384
385 // true if given state represents a device in a telephony or VoIP call
386 virtual bool isStateInCall(int state);
387
388 // when a device is connected, checks if an open output can be routed
389 // to this device. If none is open, tries to open one of the available outputs.
390 // Returns an output suitable to this device or 0.
391 // when a device is disconnected, checks if an output is not used any more and
392 // returns its handle if any.
393 // transfers the audio tracks and effects from one output thread to another accordingly.
394 status_t checkOutputsForDevice(audio_devices_t device,
395 AudioSystem::device_connection_state state,
396 SortedVector<audio_io_handle_t>& outputs,
397 const String8 paramStr);
398
399 status_t checkInputsForDevice(audio_devices_t device,
400 AudioSystem::device_connection_state state,
401 SortedVector<audio_io_handle_t>& inputs, const String8 paramStr);
402
403 // close an output and its companion duplicating output.
404 void closeOutput(audio_io_handle_t output);
405
406 // checks and if necessary changes outputs used for all strategies.
407 // must be called every time a condition that affects the output choice for a given strategy
408 // changes: connected device, phone state, force use...
409 // Must be called before updateDevicesAndOutputs()
410 void checkOutputForStrategy(routing_strategy strategy);
411
412 // Same as checkOutputForStrategy() but for a all strategies in order of priority
413 void checkOutputForAllStrategies();
414
415 // manages A2DP output suspend/restore according to phone state and BT SCO usage
416 void checkA2dpSuspend();
417
418 // returns the A2DP output handle if it is open or 0 otherwise
419 audio_io_handle_t getA2dpOutput();
420
421 // selects the most appropriate device on output for current state
422 // must be called every time a condition that affects the device choice for a given output is
423 // changed: connected device, phone state, force use, output start, output stop..
424 // see getDeviceForStrategy() for the use of fromCache parameter
425
426 audio_devices_t getNewDevice(audio_io_handle_t output, bool fromCache);
427 // updates cache of device used by all strategies (mDeviceForStrategy[])
428 // must be called every time a condition that affects the device choice for a given strategy is
429 // changed: connected device, phone state, force use...
430 // cached values are used by getDeviceForStrategy() if parameter fromCache is true.
431 // Must be called after checkOutputForAllStrategies()
432
433 void updateDevicesAndOutputs();
434
435 virtual uint32_t getMaxEffectsCpuLoad();
436 virtual uint32_t getMaxEffectsMemory();
437#ifdef AUDIO_POLICY_TEST
438 virtual bool threadLoop();
439 void exit();
440 int testOutputIndex(audio_io_handle_t output);
441#endif // AUDIO_POLICY_TEST
442
443 status_t setEffectEnabled(EffectDescriptor* pDesc, bool enabled);
444
445 // returns the category the device belongs to with regard to volume curve management
446 static device_category getDeviceCategory(audio_devices_t device);
447
448 // extract one device relevant for volume control from multiple device selection
449 static audio_devices_t getDeviceForVolume(audio_devices_t device);
450
451 SortedVector<audio_io_handle_t> getOutputsForDevice(
452 audio_devices_t device,
453 DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor*> openOutputs);
454 bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
455 SortedVector<audio_io_handle_t>& outputs2);
456
457 // mute/unmute strategies using an incompatible device combination
458 // if muting, wait for the audio in pcm buffer to be drained before proceeding
459 // if unmuting, unmute only after the specified delay
460 // Returns the number of ms waited
461 uint32_t checkDeviceMuteStrategies(AudioOutputDescriptor* outputDesc,
462 audio_devices_t prevDevice, uint32_t delayMs);
463
464 audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs,
465 AudioSystem::output_flags flags);
466 IOProfile* getInputProfile(audio_devices_t device, uint32_t samplingRate, audio_format_t format,
467 audio_channel_mask_t channelMask);
468 IOProfile* getProfileForDirectOutput(audio_devices_t device, uint32_t samplingRate,
469 audio_format_t format, audio_channel_mask_t channelMask,
470 audio_output_flags_t flags);
471
472 audio_io_handle_t selectOutputForEffects(const SortedVector<audio_io_handle_t>& outputs);
473
474 bool isNonOffloadableEffectEnabled();
475
476 //
477 // Audio policy configuration file parsing (audio_policy.conf)
478 //
479 static uint32_t stringToEnum(const struct StringToEnum* table, size_t size, const char* name);
480 static bool stringToBool(const char* value);
481 static audio_output_flags_t parseFlagNames(char* name);
482 static audio_devices_t parseDeviceNames(char* name);
483 void loadSamplingRates(char* name, IOProfile* profile);
484 void loadFormats(char* name, IOProfile* profile);
485 void loadOutChannels(char* name, IOProfile* profile);
486 void loadInChannels(char* name, IOProfile* profile);
487 status_t loadOutput(cnode* root, HwModule* module);
488 status_t loadInput(cnode* root, HwModule* module);
489 void loadHwModule(cnode* root);
490 void loadHwModules(cnode* root);
491 void loadGlobalConfig(cnode* root);
492 status_t loadAudioPolicyConfig(const char* path);
493 void defaultAudioPolicyConfig(void);
494
495 AudioPolicyClientInterface* mpClientInterface; // audio policy client interface
496 audio_io_handle_t mPrimaryOutput; // primary output handle
497 // list of descriptors for outputs currently opened
498 DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor*> mOutputs;
499 // copy of mOutputs before setDeviceConnectionState() opens new outputs
500 // reset to mOutputs when updateDevicesAndOutputs() is called.
501 DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor*> mPreviousOutputs;
502
503 // list of input descriptors currently opened
504 DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor*> mInputs;
505
506 audio_devices_t mAvailableOutputDevices; // bit field of all available output devices
507 audio_devices_t mAvailableInputDevices; // bit field of all available input devices
508 // without AUDIO_DEVICE_BIT_IN to allow direct bit
509 // field comparisons
510 int mPhoneState; // current phone state
511 AudioSystem::forced_config
512 mForceUse[AudioSystem::NUM_FORCE_USE]; // current forced use configuration
513
514 StreamDescriptor
515 mStreams[AudioSystem::NUM_STREAM_TYPES]; // stream descriptors for volume control
516 String8 mA2dpDeviceAddress; // A2DP device MAC address
517 String8 mScoDeviceAddress; // SCO device MAC address
518 String8 mUsbOutCardAndDevice; // USB audio ALSA card and device numbers:
519 // card=<card_number>;device=<><device_number>
520 bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected
521 audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
522 float mLastVoiceVolume; // last voice volume value sent to audio HAL
523
524 // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
525 static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000;
526 // Maximum memory allocated to audio effects in KB
527 static const uint32_t MAX_EFFECTS_MEMORY = 512;
528 uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects
529 uint32_t mTotalEffectsMemory; // current memory used by effects
530 KeyedVector<int, EffectDescriptor*> mEffects; // list of registered audio effects
531 bool mA2dpSuspended; // true if A2DP output is suspended
532 bool mHasA2dp; // true on platforms with support for bluetooth A2DP
533 bool mHasUsb; // true on platforms with support for USB audio
534 bool mHasRemoteSubmix; // true on platforms with support for remote presentation of a submix
535 audio_devices_t mAttachedOutputDevices; // output devices always available on the platform
536 audio_devices_t mDefaultOutputDevice; // output device selected by default at boot time
537 // (must be in mAttachedOutputDevices)
538 bool mSpeakerDrcEnabled; // true on devices that use DRC on the DEVICE_CATEGORY_SPEAKER path
539 // to boost soft sounds, used to adjust volume curves accordingly
540
541 Vector<HwModule*> mHwModules;
542
543#ifdef AUDIO_POLICY_TEST
544 Mutex mLock;
545 Condition mWaitWorkCV;
546
547 int mCurOutput;
548 bool mDirectOutput;
549 audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS];
550 int mTestInput;
551 uint32_t mTestDevice;
552 uint32_t mTestSamplingRate;
553 uint32_t mTestFormat;
554 uint32_t mTestChannels;
555 uint32_t mTestLatencyMs;
556#endif // AUDIO_POLICY_TEST
557
558 private:
559 static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
560 int indexInUi);
561 // updates device caching and output for streams that can influence the
562 // routing of notifications
563 void handleNotificationRoutingForStream(AudioSystem::stream_type stream);
564 static bool isVirtualInputDevice(audio_devices_t device);
565};
566
567}; // namespace android_audio_legacy