2009-12-14 14:18:18 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
2012-03-20 21:44:51 +01:00
|
|
|
#include <cutils/config_utils.h>
|
|
|
|
#include <cutils/misc.h>
|
2009-12-14 14:18:18 +01:00
|
|
|
#include <utils/Timers.h>
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/KeyedVector.h>
|
2012-02-17 19:55:44 +01:00
|
|
|
#include <utils/SortedVector.h>
|
2009-12-14 14:18:18 +01:00
|
|
|
#include <hardware_legacy/AudioPolicyInterface.h>
|
|
|
|
|
|
|
|
|
2011-04-20 01:53:42 +02:00
|
|
|
namespace android_audio_legacy {
|
|
|
|
using android::KeyedVector;
|
2012-02-17 19:55:44 +01:00
|
|
|
using android::DefaultKeyedVector;
|
|
|
|
using android::SortedVector;
|
2009-12-14 14:18:18 +01:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define MAX_DEVICE_ADDRESS_LEN 20
|
|
|
|
// Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB
|
|
|
|
#define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5
|
|
|
|
// Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB
|
|
|
|
#define SONIFICATION_HEADSET_VOLUME_MIN 0.016
|
2011-02-02 21:10:13 +01:00
|
|
|
// Time in milliseconds during which we consider that music is still active after a music
|
2009-12-14 14:18:18 +01:00
|
|
|
// track was stopped - see computeVolume()
|
2011-02-02 21:10:13 +01:00
|
|
|
#define SONIFICATION_HEADSET_MUSIC_DELAY 5000
|
2012-03-15 17:33:34 +01:00
|
|
|
// Time in milliseconds after media stopped playing during which we consider that the
|
|
|
|
// sonification should be as unobtrusive as during the time media was playing.
|
|
|
|
#define SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY 5000
|
2010-02-23 19:56:00 +01:00
|
|
|
// Time in milliseconds during witch some streams are muted while the audio path
|
|
|
|
// is switched
|
|
|
|
#define MUTE_TIME_MS 2000
|
2009-12-14 14:18:18 +01:00
|
|
|
|
|
|
|
#define NUM_TEST_OUTPUTS 5
|
|
|
|
|
2011-01-25 01:05:03 +01:00
|
|
|
#define NUM_VOL_CURVE_KNEES 2
|
|
|
|
|
2013-05-13 12:52:24 +02:00
|
|
|
// Default minimum length allowed for offloading a compressed track
|
|
|
|
// Can be overridden by the audio.offload.min.duration.secs property
|
2013-09-09 22:24:05 +02:00
|
|
|
#define OFFLOAD_DEFAULT_MIN_DURATION_SECS 60
|
2013-05-13 12:52:24 +02:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// AudioPolicyManagerBase implements audio policy manager behavior common to all platforms.
|
|
|
|
// Each platform must implement an AudioPolicyManager class derived from AudioPolicyManagerBase
|
2010-07-13 14:01:51 +02:00
|
|
|
// and override methods for which the platform specific behavior differs from the implementation
|
2009-12-14 14:18:18 +01:00
|
|
|
// in AudioPolicyManagerBase. Even if no specific behavior is required, the AudioPolicyManager
|
|
|
|
// class must be implemented as well as the class factory function createAudioPolicyManager()
|
|
|
|
// and provided in a shared library libaudiopolicy.so.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class AudioPolicyManagerBase: public AudioPolicyInterface
|
|
|
|
#ifdef AUDIO_POLICY_TEST
|
|
|
|
, public Thread
|
|
|
|
#endif //AUDIO_POLICY_TEST
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
AudioPolicyManagerBase(AudioPolicyClientInterface *clientInterface);
|
|
|
|
virtual ~AudioPolicyManagerBase();
|
|
|
|
|
|
|
|
// AudioPolicyInterface
|
2012-08-24 20:45:04 +02:00
|
|
|
virtual status_t setDeviceConnectionState(audio_devices_t device,
|
2009-12-14 14:18:18 +01:00
|
|
|
AudioSystem::device_connection_state state,
|
|
|
|
const char *device_address);
|
2012-08-24 20:45:04 +02:00
|
|
|
virtual AudioSystem::device_connection_state getDeviceConnectionState(audio_devices_t device,
|
2009-12-14 14:18:18 +01:00
|
|
|
const char *device_address);
|
|
|
|
virtual void setPhoneState(int state);
|
|
|
|
virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config);
|
|
|
|
virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage);
|
|
|
|
virtual void setSystemProperty(const char* property, const char* value);
|
2011-01-19 04:11:00 +01:00
|
|
|
virtual status_t initCheck();
|
2009-12-14 14:18:18 +01:00
|
|
|
virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream,
|
2013-12-10 18:53:22 +01:00
|
|
|
uint32_t samplingRate,
|
|
|
|
audio_format_t format,
|
2013-12-10 18:10:28 +01:00
|
|
|
audio_channel_mask_t channelMask,
|
2013-12-10 18:53:22 +01:00
|
|
|
AudioSystem::output_flags flags,
|
|
|
|
const audio_offload_info_t *offloadInfo);
|
2010-07-13 14:01:51 +02:00
|
|
|
virtual status_t startOutput(audio_io_handle_t output,
|
|
|
|
AudioSystem::stream_type stream,
|
2016-03-08 21:10:28 +01:00
|
|
|
audio_session_t session = AUDIO_SESSION_NONE);
|
2010-07-13 14:01:51 +02:00
|
|
|
virtual status_t stopOutput(audio_io_handle_t output,
|
|
|
|
AudioSystem::stream_type stream,
|
2016-03-08 21:10:28 +01:00
|
|
|
audio_session_t session = AUDIO_SESSION_NONE);
|
2009-12-14 14:18:18 +01:00
|
|
|
virtual void releaseOutput(audio_io_handle_t output);
|
|
|
|
virtual audio_io_handle_t getInput(int inputSource,
|
|
|
|
uint32_t samplingRate,
|
2013-12-10 18:53:22 +01:00
|
|
|
audio_format_t format,
|
2013-12-10 18:10:28 +01:00
|
|
|
audio_channel_mask_t channelMask,
|
2009-12-14 14:18:18 +01:00
|
|
|
AudioSystem::audio_in_acoustics acoustics);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// indicates to the audio policy manager that the input starts being used.
|
|
|
|
virtual status_t startInput(audio_io_handle_t input);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// indicates to the audio policy manager that the input stops being used.
|
|
|
|
virtual status_t stopInput(audio_io_handle_t input);
|
|
|
|
virtual void releaseInput(audio_io_handle_t input);
|
2014-04-18 23:01:12 +02:00
|
|
|
virtual void closeAllInputs();
|
2009-12-14 14:18:18 +01:00
|
|
|
virtual void initStreamVolume(AudioSystem::stream_type stream,
|
|
|
|
int indexMin,
|
|
|
|
int indexMax);
|
2011-12-15 03:18:36 +01:00
|
|
|
virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream,
|
|
|
|
int index,
|
|
|
|
audio_devices_t device);
|
|
|
|
virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream,
|
|
|
|
int *index,
|
|
|
|
audio_devices_t device);
|
2009-12-14 14:18:18 +01:00
|
|
|
|
2010-07-13 14:01:51 +02:00
|
|
|
// return the strategy corresponding to a given stream type
|
|
|
|
virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream);
|
|
|
|
|
2011-02-10 22:31:26 +01:00
|
|
|
// return the enabled output devices for the given stream type
|
2012-03-08 22:39:13 +01:00
|
|
|
virtual audio_devices_t getDevicesForStream(AudioSystem::stream_type stream);
|
2011-02-10 22:31:26 +01:00
|
|
|
|
2013-09-13 02:39:21 +02:00
|
|
|
virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc = NULL);
|
2012-07-24 16:51:26 +02:00
|
|
|
virtual status_t registerEffect(const effect_descriptor_t *desc,
|
2011-06-18 06:51:11 +02:00
|
|
|
audio_io_handle_t io,
|
2010-07-13 14:01:51 +02:00
|
|
|
uint32_t strategy,
|
2016-03-08 21:10:28 +01:00
|
|
|
audio_session_t session,
|
2010-07-13 14:01:51 +02:00
|
|
|
int id);
|
|
|
|
virtual status_t unregisterEffect(int id);
|
2011-08-11 05:16:23 +02:00
|
|
|
virtual status_t setEffectEnabled(int id, bool enabled);
|
2010-07-13 14:01:51 +02:00
|
|
|
|
2011-02-02 21:10:13 +01:00
|
|
|
virtual bool isStreamActive(int stream, uint32_t inPastMs = 0) const;
|
2013-02-05 01:28:31 +01:00
|
|
|
// return whether a stream is playing remotely, override to change the definition of
|
|
|
|
// local/remote playback, used for instance by notification manager to not make
|
|
|
|
// media players lose audio focus when not playing locally
|
|
|
|
virtual bool isStreamActiveRemotely(int stream, uint32_t inPastMs = 0) const;
|
2012-10-10 21:39:04 +02:00
|
|
|
virtual bool isSourceActive(audio_source_t source) const;
|
2011-02-02 21:10:13 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
virtual status_t dump(int fd);
|
|
|
|
|
2013-03-25 17:18:26 +01:00
|
|
|
virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
|
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
protected:
|
|
|
|
|
|
|
|
enum routing_strategy {
|
|
|
|
STRATEGY_MEDIA,
|
|
|
|
STRATEGY_PHONE,
|
|
|
|
STRATEGY_SONIFICATION,
|
2012-03-15 17:33:34 +01:00
|
|
|
STRATEGY_SONIFICATION_RESPECTFUL,
|
2009-12-14 14:18:18 +01:00
|
|
|
STRATEGY_DTMF,
|
2011-11-01 21:54:26 +01:00
|
|
|
STRATEGY_ENFORCED_AUDIBLE,
|
2009-12-14 14:18:18 +01:00
|
|
|
NUM_STRATEGIES
|
|
|
|
};
|
|
|
|
|
2011-09-12 20:38:12 +02:00
|
|
|
// 4 points to define the volume attenuation curve, each characterized by the volume
|
|
|
|
// index (from 0 to 100) at which they apply, and the attenuation in dB at that index.
|
|
|
|
// we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl()
|
|
|
|
|
|
|
|
enum { VOLMIN = 0, VOLKNEE1 = 1, VOLKNEE2 = 2, VOLMAX = 3, VOLCNT = 4};
|
|
|
|
|
|
|
|
class VolumeCurvePoint
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int mIndex;
|
|
|
|
float mDBAttenuation;
|
|
|
|
};
|
|
|
|
|
2011-10-18 23:03:28 +02:00
|
|
|
// device categories used for volume curve management.
|
|
|
|
enum device_category {
|
|
|
|
DEVICE_CATEGORY_HEADSET,
|
|
|
|
DEVICE_CATEGORY_SPEAKER,
|
|
|
|
DEVICE_CATEGORY_EARPIECE,
|
|
|
|
DEVICE_CATEGORY_CNT
|
|
|
|
};
|
|
|
|
|
2012-03-28 20:27:13 +02:00
|
|
|
class IOProfile;
|
|
|
|
|
|
|
|
class HwModule {
|
|
|
|
public:
|
|
|
|
HwModule(const char *name);
|
|
|
|
~HwModule();
|
|
|
|
|
|
|
|
void dump(int fd);
|
|
|
|
|
|
|
|
const char *const mName; // base name of the audio HW module (primary, a2dp ...)
|
|
|
|
audio_module_handle_t mHandle;
|
|
|
|
Vector <IOProfile *> mOutputProfiles; // output profiles exposed by this module
|
|
|
|
Vector <IOProfile *> mInputProfiles; // input profiles exposed by this module
|
|
|
|
};
|
|
|
|
|
2012-03-20 21:44:51 +01:00
|
|
|
// the IOProfile class describes the capabilities of an output or input stream.
|
|
|
|
// It is currently assumed that all combination of listed parameters are supported.
|
|
|
|
// It is used by the policy manager to determine if an output or input is suitable for
|
|
|
|
// a given use case, open/close it accordingly and connect/disconnect audio tracks
|
|
|
|
// to/from it.
|
|
|
|
class IOProfile
|
|
|
|
{
|
2012-03-28 20:27:13 +02:00
|
|
|
public:
|
|
|
|
IOProfile(HwModule *module);
|
2012-03-20 21:44:51 +01:00
|
|
|
~IOProfile();
|
|
|
|
|
2012-03-28 20:27:13 +02:00
|
|
|
bool isCompatibleProfile(audio_devices_t device,
|
|
|
|
uint32_t samplingRate,
|
2013-12-10 18:53:22 +01:00
|
|
|
audio_format_t format,
|
2013-12-10 18:10:28 +01:00
|
|
|
audio_channel_mask_t channelMask,
|
2012-04-18 18:28:52 +02:00
|
|
|
audio_output_flags_t flags) const;
|
2012-03-28 20:27:13 +02:00
|
|
|
|
2012-03-20 21:44:51 +01:00
|
|
|
void dump(int fd);
|
2014-04-18 23:01:12 +02:00
|
|
|
void log();
|
2012-03-20 21:44:51 +01:00
|
|
|
|
2012-05-01 03:28:24 +02:00
|
|
|
// by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats
|
|
|
|
// indicates the supported parameters should be read from the output stream
|
|
|
|
// after it is opened for the first time
|
2012-03-20 21:44:51 +01:00
|
|
|
Vector <uint32_t> mSamplingRates; // supported sampling rates
|
|
|
|
Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks
|
|
|
|
Vector <audio_format_t> mFormats; // supported audio formats
|
|
|
|
audio_devices_t mSupportedDevices; // supported devices (devices this output can be
|
|
|
|
// routed to)
|
2012-04-18 18:28:52 +02:00
|
|
|
audio_output_flags_t mFlags; // attribute flags (e.g primary output,
|
2012-03-20 21:44:51 +01:00
|
|
|
// direct output...). For outputs only.
|
2012-03-28 20:27:13 +02:00
|
|
|
HwModule *mModule; // audio HW module exposing this I/O stream
|
2012-03-20 21:44:51 +01:00
|
|
|
};
|
|
|
|
|
2011-10-18 23:03:28 +02:00
|
|
|
// default volume curve
|
|
|
|
static const VolumeCurvePoint sDefaultVolumeCurve[AudioPolicyManagerBase::VOLCNT];
|
|
|
|
// default volume curve for media strategy
|
|
|
|
static const VolumeCurvePoint sDefaultMediaVolumeCurve[AudioPolicyManagerBase::VOLCNT];
|
|
|
|
// volume curve for media strategy on speakers
|
|
|
|
static const VolumeCurvePoint sSpeakerMediaVolumeCurve[AudioPolicyManagerBase::VOLCNT];
|
|
|
|
// volume curve for sonification strategy on speakers
|
|
|
|
static const VolumeCurvePoint sSpeakerSonificationVolumeCurve[AudioPolicyManagerBase::VOLCNT];
|
2013-11-15 01:30:20 +01:00
|
|
|
static const VolumeCurvePoint sSpeakerSonificationVolumeCurveDrc[AudioPolicyManagerBase::VOLCNT];
|
2012-04-26 00:47:56 +02:00
|
|
|
static const VolumeCurvePoint sDefaultSystemVolumeCurve[AudioPolicyManagerBase::VOLCNT];
|
2013-11-15 01:30:20 +01:00
|
|
|
static const VolumeCurvePoint sDefaultSystemVolumeCurveDrc[AudioPolicyManagerBase::VOLCNT];
|
2012-04-26 00:47:56 +02:00
|
|
|
static const VolumeCurvePoint sHeadsetSystemVolumeCurve[AudioPolicyManagerBase::VOLCNT];
|
2012-10-17 19:14:14 +02:00
|
|
|
static const VolumeCurvePoint sDefaultVoiceVolumeCurve[AudioPolicyManagerBase::VOLCNT];
|
|
|
|
static const VolumeCurvePoint sSpeakerVoiceVolumeCurve[AudioPolicyManagerBase::VOLCNT];
|
2012-04-26 00:47:56 +02:00
|
|
|
// default volume curves per stream and device category. See initializeVolumeCurves()
|
2014-11-11 23:01:13 +01:00
|
|
|
static const VolumeCurvePoint *sVolumeProfiles[AudioSystem::NUM_STREAM_TYPES][DEVICE_CATEGORY_CNT];
|
2011-09-12 20:38:12 +02:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// descriptor for audio outputs. Used to maintain current configuration of each opened audio output
|
|
|
|
// and keep track of the usage of this output by each audio stream type.
|
|
|
|
class AudioOutputDescriptor
|
|
|
|
{
|
|
|
|
public:
|
2012-03-20 21:44:51 +01:00
|
|
|
AudioOutputDescriptor(const IOProfile *profile);
|
2009-12-14 14:18:18 +01:00
|
|
|
|
|
|
|
status_t dump(int fd);
|
|
|
|
|
2013-02-05 01:28:31 +01:00
|
|
|
audio_devices_t device() const;
|
2013-03-25 17:58:09 +01:00
|
|
|
void changeRefCount(AudioSystem::stream_type stream, int delta);
|
2013-03-25 17:18:26 +01:00
|
|
|
|
2012-03-20 21:44:51 +01:00
|
|
|
bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); }
|
2012-03-08 22:39:13 +01:00
|
|
|
audio_devices_t supportedDevices();
|
2012-03-20 21:44:51 +01:00
|
|
|
uint32_t latency();
|
|
|
|
bool sharesHwModuleWith(const AudioOutputDescriptor *outputDesc);
|
2013-03-25 17:58:09 +01:00
|
|
|
bool isActive(uint32_t inPastMs = 0) const;
|
|
|
|
bool isStreamActive(AudioSystem::stream_type stream,
|
|
|
|
uint32_t inPastMs = 0,
|
|
|
|
nsecs_t sysTime = 0) const;
|
|
|
|
bool isStrategyActive(routing_strategy strategy,
|
|
|
|
uint32_t inPastMs = 0,
|
|
|
|
nsecs_t sysTime = 0) const;
|
2009-12-14 14:18:18 +01:00
|
|
|
|
|
|
|
audio_io_handle_t mId; // output handle
|
|
|
|
uint32_t mSamplingRate; //
|
2012-03-28 20:27:13 +02:00
|
|
|
audio_format_t mFormat; //
|
|
|
|
audio_channel_mask_t mChannelMask; // output configuration
|
2009-12-14 14:18:18 +01:00
|
|
|
uint32_t mLatency; //
|
2012-04-18 18:28:52 +02:00
|
|
|
audio_output_flags_t mFlags; //
|
2012-03-08 22:39:13 +01:00
|
|
|
audio_devices_t mDevice; // current device this output is routed to
|
2009-12-14 14:18:18 +01:00
|
|
|
uint32_t mRefCount[AudioSystem::NUM_STREAM_TYPES]; // number of streams of each type using this output
|
2011-02-02 21:10:13 +01:00
|
|
|
nsecs_t mStopTime[AudioSystem::NUM_STREAM_TYPES];
|
2009-12-14 14:18:18 +01:00
|
|
|
AudioOutputDescriptor *mOutput1; // used by duplicated outputs: first output
|
|
|
|
AudioOutputDescriptor *mOutput2; // used by duplicated outputs: second output
|
|
|
|
float mCurVolume[AudioSystem::NUM_STREAM_TYPES]; // current stream volume
|
|
|
|
int mMuteCount[AudioSystem::NUM_STREAM_TYPES]; // mute request counter
|
2012-03-20 21:44:51 +01:00
|
|
|
const IOProfile *mProfile; // I/O profile this output derives from
|
|
|
|
bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible
|
|
|
|
// device selection. See checkDeviceMuteStrategies()
|
2013-04-04 02:31:04 +02:00
|
|
|
uint32_t mDirectOpenCount; // number of clients using this output (direct outputs only)
|
2012-09-03 08:29:57 +02:00
|
|
|
bool mForceRouting; // Next routing for this output will be forced as current device routed is null
|
2009-12-14 14:18:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// descriptor for audio inputs. Used to maintain current configuration of each opened audio input
|
|
|
|
// and keep track of the usage of this input.
|
|
|
|
class AudioInputDescriptor
|
|
|
|
{
|
|
|
|
public:
|
2012-03-20 21:44:51 +01:00
|
|
|
AudioInputDescriptor(const IOProfile *profile);
|
2009-12-14 14:18:18 +01:00
|
|
|
|
|
|
|
status_t dump(int fd);
|
|
|
|
|
2014-04-18 23:01:12 +02:00
|
|
|
audio_io_handle_t mId; // input handle
|
2009-12-14 14:18:18 +01:00
|
|
|
uint32_t mSamplingRate; //
|
2012-03-28 20:27:13 +02:00
|
|
|
audio_format_t mFormat; // input configuration
|
|
|
|
audio_channel_mask_t mChannelMask; //
|
2012-03-08 22:39:13 +01:00
|
|
|
audio_devices_t mDevice; // current device this input is routed to
|
2009-12-14 14:18:18 +01:00
|
|
|
uint32_t mRefCount; // number of AudioRecord clients using this output
|
2012-03-08 22:39:13 +01:00
|
|
|
int mInputSource; // input source selected by application (mediarecorder.h)
|
2012-03-20 21:44:51 +01:00
|
|
|
const IOProfile *mProfile; // I/O profile this output derives from
|
2009-12-14 14:18:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// stream descriptor used for volume control
|
|
|
|
class StreamDescriptor
|
|
|
|
{
|
|
|
|
public:
|
2011-12-15 03:18:36 +01:00
|
|
|
StreamDescriptor();
|
2009-12-14 14:18:18 +01:00
|
|
|
|
2011-12-15 03:18:36 +01:00
|
|
|
int getVolumeIndex(audio_devices_t device);
|
|
|
|
void dump(int fd);
|
2009-12-14 14:18:18 +01:00
|
|
|
|
|
|
|
int mIndexMin; // min volume index
|
|
|
|
int mIndexMax; // max volume index
|
2011-12-15 03:18:36 +01:00
|
|
|
KeyedVector<audio_devices_t, int> mIndexCur; // current volume index per device
|
2009-12-14 14:18:18 +01:00
|
|
|
bool mCanBeMuted; // true is the stream can be muted
|
2011-01-25 01:05:03 +01:00
|
|
|
|
2011-10-18 23:03:28 +02:00
|
|
|
const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT];
|
2009-12-14 14:18:18 +01:00
|
|
|
};
|
|
|
|
|
2010-07-13 14:01:51 +02:00
|
|
|
// stream descriptor used for volume control
|
|
|
|
class EffectDescriptor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
status_t dump(int fd);
|
|
|
|
|
2011-06-18 06:51:11 +02:00
|
|
|
int mIo; // io the effect is attached to
|
2010-07-13 14:01:51 +02:00
|
|
|
routing_strategy mStrategy; // routing strategy the effect is associated to
|
2016-03-08 21:10:28 +01:00
|
|
|
audio_session_t mSession; // audio session the effect is on
|
2010-07-13 14:01:51 +02:00
|
|
|
effect_descriptor_t mDesc; // effect descriptor
|
2011-08-11 05:16:23 +02:00
|
|
|
bool mEnabled; // enabled state: CPU load being used or not
|
2010-07-13 14:01:51 +02:00
|
|
|
};
|
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
void addOutput(audio_io_handle_t id, AudioOutputDescriptor *outputDesc);
|
2014-04-18 23:01:12 +02:00
|
|
|
void addInput(audio_io_handle_t id, AudioInputDescriptor *inputDesc);
|
2009-12-14 14:18:18 +01:00
|
|
|
|
|
|
|
// return the strategy corresponding to a given stream type
|
|
|
|
static routing_strategy getStrategy(AudioSystem::stream_type stream);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// return appropriate device for streams handled by the specified strategy according to current
|
|
|
|
// phone state, connected devices...
|
2012-03-20 21:44:51 +01:00
|
|
|
// if fromCache is true, the device is returned from mDeviceForStrategy[],
|
|
|
|
// otherwise it is determine by current state
|
|
|
|
// (device connected,phone state, force use, a2dp output...)
|
2009-12-14 14:18:18 +01:00
|
|
|
// This allows to:
|
|
|
|
// 1 speed up process when the state is stable (when starting or stopping an output)
|
|
|
|
// 2 access to either current device selection (fromCache == true) or
|
|
|
|
// "future" device selection (fromCache == false) when called from a context
|
|
|
|
// where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
|
2012-06-21 18:55:49 +02:00
|
|
|
// before updateDevicesAndOutputs() is called.
|
2012-03-20 21:44:51 +01:00
|
|
|
virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy,
|
|
|
|
bool fromCache);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2012-04-14 03:48:06 +02:00
|
|
|
// change the route of the specified output. Returns the number of ms we have slept to
|
|
|
|
// allow new routing to take effect in certain cases.
|
|
|
|
uint32_t setOutputDevice(audio_io_handle_t output,
|
2012-03-08 22:39:13 +01:00
|
|
|
audio_devices_t device,
|
|
|
|
bool force = false,
|
|
|
|
int delayMs = 0);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// select input device corresponding to requested audio source
|
2012-03-08 22:39:13 +01:00
|
|
|
virtual audio_devices_t getDeviceForInputSource(int inputSource);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// return io handle of active input or 0 if no input is active
|
2012-09-17 22:40:35 +02:00
|
|
|
// Only considers inputs from physical devices (e.g. main mic, headset mic) when
|
|
|
|
// ignoreVirtualInputs is true.
|
|
|
|
audio_io_handle_t getActiveInput(bool ignoreVirtualInputs = true);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2011-10-18 23:03:28 +02:00
|
|
|
// initialize volume curves for each strategy and device category
|
|
|
|
void initializeVolumeCurves();
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// compute the actual volume for a given stream according to the requested index and a particular
|
|
|
|
// device
|
2012-03-08 22:39:13 +01:00
|
|
|
virtual float computeVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// check that volume change is permitted, compute and send new volume to audio hardware
|
2012-03-08 22:39:13 +01:00
|
|
|
status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// apply all stream volumes to the specified output and device
|
2012-03-08 22:39:13 +01:00
|
|
|
void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// Mute or unmute all streams handled by the specified strategy on the specified output
|
2012-05-16 04:16:30 +02:00
|
|
|
void setStrategyMute(routing_strategy strategy,
|
|
|
|
bool on,
|
|
|
|
audio_io_handle_t output,
|
|
|
|
int delayMs = 0,
|
|
|
|
audio_devices_t device = (audio_devices_t)0);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// Mute or unmute the stream on the specified output
|
2012-05-16 04:16:30 +02:00
|
|
|
void setStreamMute(int stream,
|
|
|
|
bool on,
|
|
|
|
audio_io_handle_t output,
|
|
|
|
int delayMs = 0,
|
|
|
|
audio_devices_t device = (audio_devices_t)0);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// handle special cases for sonification strategy while in call: mute streams or replace by
|
|
|
|
// a special tone in the device used for communication
|
|
|
|
void handleIncallSonification(int stream, bool starting, bool stateChange);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2010-11-16 01:02:06 +01:00
|
|
|
// true if device is in a telephony or VoIP call
|
|
|
|
virtual bool isInCall();
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2010-11-16 01:02:06 +01:00
|
|
|
// true if given state represents a device in a telephony or VoIP call
|
|
|
|
virtual bool isStateInCall(int state);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2012-02-17 19:55:44 +01:00
|
|
|
// when a device is connected, checks if an open output can be routed
|
|
|
|
// to this device. If none is open, tries to open one of the available outputs.
|
|
|
|
// Returns an output suitable to this device or 0.
|
|
|
|
// when a device is disconnected, checks if an output is not used any more and
|
|
|
|
// returns its handle if any.
|
|
|
|
// transfers the audio tracks and effects from one output thread to another accordingly.
|
2012-05-01 03:28:24 +02:00
|
|
|
status_t checkOutputsForDevice(audio_devices_t device,
|
|
|
|
AudioSystem::device_connection_state state,
|
2014-01-06 19:04:43 +01:00
|
|
|
SortedVector<audio_io_handle_t>& outputs,
|
|
|
|
const String8 paramStr);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2014-04-18 23:01:12 +02:00
|
|
|
status_t checkInputsForDevice(audio_devices_t device,
|
|
|
|
AudioSystem::device_connection_state state,
|
|
|
|
SortedVector<audio_io_handle_t>& inputs,
|
|
|
|
const String8 paramStr);
|
|
|
|
|
2012-02-17 19:55:44 +01:00
|
|
|
// close an output and its companion duplicating output.
|
|
|
|
void closeOutput(audio_io_handle_t output);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2012-02-17 19:55:44 +01:00
|
|
|
// checks and if necessary changes outputs used for all strategies.
|
|
|
|
// must be called every time a condition that affects the output choice for a given strategy
|
|
|
|
// changes: connected device, phone state, force use...
|
2012-06-21 18:55:49 +02:00
|
|
|
// Must be called before updateDevicesAndOutputs()
|
2010-08-28 02:16:29 +02:00
|
|
|
void checkOutputForStrategy(routing_strategy strategy);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// Same as checkOutputForStrategy() but for a all strategies in order of priority
|
2010-08-28 02:16:29 +02:00
|
|
|
void checkOutputForAllStrategies();
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2010-11-02 20:03:04 +01:00
|
|
|
// manages A2DP output suspend/restore according to phone state and BT SCO usage
|
|
|
|
void checkA2dpSuspend();
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2012-02-17 19:55:44 +01:00
|
|
|
// returns the A2DP output handle if it is open or 0 otherwise
|
|
|
|
audio_io_handle_t getA2dpOutput();
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
// selects the most appropriate device on output for current state
|
|
|
|
// must be called every time a condition that affects the device choice for a given output is
|
|
|
|
// changed: connected device, phone state, force use, output start, output stop..
|
|
|
|
// see getDeviceForStrategy() for the use of fromCache parameter
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2012-03-20 21:44:51 +01:00
|
|
|
audio_devices_t getNewDevice(audio_io_handle_t output, bool fromCache);
|
2009-12-14 14:18:18 +01:00
|
|
|
// updates cache of device used by all strategies (mDeviceForStrategy[])
|
|
|
|
// must be called every time a condition that affects the device choice for a given strategy is
|
|
|
|
// changed: connected device, phone state, force use...
|
|
|
|
// cached values are used by getDeviceForStrategy() if parameter fromCache is true.
|
|
|
|
// Must be called after checkOutputForAllStrategies()
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2012-06-21 18:55:49 +02:00
|
|
|
void updateDevicesAndOutputs();
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2010-07-13 14:01:51 +02:00
|
|
|
virtual uint32_t getMaxEffectsCpuLoad();
|
|
|
|
virtual uint32_t getMaxEffectsMemory();
|
2009-12-14 14:18:18 +01:00
|
|
|
#ifdef AUDIO_POLICY_TEST
|
|
|
|
virtual bool threadLoop();
|
|
|
|
void exit();
|
|
|
|
int testOutputIndex(audio_io_handle_t output);
|
|
|
|
#endif //AUDIO_POLICY_TEST
|
|
|
|
|
2011-08-11 05:16:23 +02:00
|
|
|
status_t setEffectEnabled(EffectDescriptor *pDesc, bool enabled);
|
|
|
|
|
2011-10-18 23:03:28 +02:00
|
|
|
// returns the category the device belongs to with regard to volume curve management
|
2012-03-08 22:39:13 +01:00
|
|
|
static device_category getDeviceCategory(audio_devices_t device);
|
2012-03-08 04:19:29 +01:00
|
|
|
|
2011-12-15 03:18:36 +01:00
|
|
|
// extract one device relevant for volume control from multiple device selection
|
|
|
|
static audio_devices_t getDeviceForVolume(audio_devices_t device);
|
2011-10-18 23:03:28 +02:00
|
|
|
|
2012-06-21 18:55:49 +02:00
|
|
|
SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device,
|
|
|
|
DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> openOutputs);
|
2012-02-17 19:55:44 +01:00
|
|
|
bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
|
|
|
|
SortedVector<audio_io_handle_t>& outputs2);
|
2009-12-14 14:18:18 +01:00
|
|
|
|
2012-04-14 03:48:06 +02:00
|
|
|
// mute/unmute strategies using an incompatible device combination
|
|
|
|
// if muting, wait for the audio in pcm buffer to be drained before proceeding
|
|
|
|
// if unmuting, unmute only after the specified delay
|
|
|
|
// Returns the number of ms waited
|
|
|
|
uint32_t checkDeviceMuteStrategies(AudioOutputDescriptor *outputDesc,
|
2012-04-22 22:57:53 +02:00
|
|
|
audio_devices_t prevDevice,
|
|
|
|
uint32_t delayMs);
|
2012-03-20 21:44:51 +01:00
|
|
|
|
|
|
|
audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs,
|
|
|
|
AudioSystem::output_flags flags);
|
|
|
|
IOProfile *getInputProfile(audio_devices_t device,
|
|
|
|
uint32_t samplingRate,
|
2013-12-10 18:53:22 +01:00
|
|
|
audio_format_t format,
|
2013-12-10 18:10:28 +01:00
|
|
|
audio_channel_mask_t channelMask);
|
2012-05-01 03:28:24 +02:00
|
|
|
IOProfile *getProfileForDirectOutput(audio_devices_t device,
|
2012-03-28 20:27:13 +02:00
|
|
|
uint32_t samplingRate,
|
2013-12-10 18:53:22 +01:00
|
|
|
audio_format_t format,
|
2013-12-10 18:10:28 +01:00
|
|
|
audio_channel_mask_t channelMask,
|
2012-04-18 18:28:52 +02:00
|
|
|
audio_output_flags_t flags);
|
2013-09-13 02:39:21 +02:00
|
|
|
|
|
|
|
audio_io_handle_t selectOutputForEffects(const SortedVector<audio_io_handle_t>& outputs);
|
|
|
|
|
2013-10-13 01:29:39 +02:00
|
|
|
bool isNonOffloadableEffectEnabled();
|
|
|
|
|
2012-03-20 21:44:51 +01:00
|
|
|
//
|
|
|
|
// Audio policy configuration file parsing (audio_policy.conf)
|
|
|
|
//
|
|
|
|
static uint32_t stringToEnum(const struct StringToEnum *table,
|
|
|
|
size_t size,
|
|
|
|
const char *name);
|
2013-11-15 01:30:20 +01:00
|
|
|
static bool stringToBool(const char *value);
|
2012-04-18 18:28:52 +02:00
|
|
|
static audio_output_flags_t parseFlagNames(char *name);
|
2012-03-20 21:44:51 +01:00
|
|
|
static audio_devices_t parseDeviceNames(char *name);
|
|
|
|
void loadSamplingRates(char *name, IOProfile *profile);
|
|
|
|
void loadFormats(char *name, IOProfile *profile);
|
|
|
|
void loadOutChannels(char *name, IOProfile *profile);
|
|
|
|
void loadInChannels(char *name, IOProfile *profile);
|
2012-03-28 20:27:13 +02:00
|
|
|
status_t loadOutput(cnode *root, HwModule *module);
|
|
|
|
status_t loadInput(cnode *root, HwModule *module);
|
2012-03-20 21:44:51 +01:00
|
|
|
void loadHwModule(cnode *root);
|
|
|
|
void loadHwModules(cnode *root);
|
|
|
|
void loadGlobalConfig(cnode *root);
|
|
|
|
status_t loadAudioPolicyConfig(const char *path);
|
2012-04-24 09:21:59 +02:00
|
|
|
void defaultAudioPolicyConfig(void);
|
2012-03-20 21:44:51 +01:00
|
|
|
|
|
|
|
|
2012-02-17 19:55:44 +01:00
|
|
|
AudioPolicyClientInterface *mpClientInterface; // audio policy client interface
|
|
|
|
audio_io_handle_t mPrimaryOutput; // primary output handle
|
2012-06-21 18:55:49 +02:00
|
|
|
// list of descriptors for outputs currently opened
|
|
|
|
DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mOutputs;
|
|
|
|
// copy of mOutputs before setDeviceConnectionState() opens new outputs
|
|
|
|
// reset to mOutputs when updateDevicesAndOutputs() is called.
|
|
|
|
DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mPreviousOutputs;
|
2014-04-18 23:01:12 +02:00
|
|
|
|
|
|
|
// list of input descriptors currently opened
|
|
|
|
DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs;
|
|
|
|
|
2012-03-20 21:44:51 +01:00
|
|
|
audio_devices_t mAvailableOutputDevices; // bit field of all available output devices
|
|
|
|
audio_devices_t mAvailableInputDevices; // bit field of all available input devices
|
2012-08-28 23:32:21 +02:00
|
|
|
// without AUDIO_DEVICE_BIT_IN to allow direct bit
|
|
|
|
// field comparisons
|
2009-12-14 14:18:18 +01:00
|
|
|
int mPhoneState; // current phone state
|
|
|
|
AudioSystem::forced_config mForceUse[AudioSystem::NUM_FORCE_USE]; // current forced use configuration
|
|
|
|
|
|
|
|
StreamDescriptor mStreams[AudioSystem::NUM_STREAM_TYPES]; // stream descriptors for volume control
|
|
|
|
String8 mA2dpDeviceAddress; // A2DP device MAC address
|
|
|
|
String8 mScoDeviceAddress; // SCO device MAC address
|
2014-04-18 23:01:12 +02:00
|
|
|
String8 mUsbOutCardAndDevice; // USB audio ALSA card and device numbers:
|
|
|
|
// card=<card_number>;device=<><device_number>
|
2009-12-14 14:18:18 +01:00
|
|
|
bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected
|
2012-03-08 22:39:13 +01:00
|
|
|
audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
|
2010-05-25 18:30:03 +02:00
|
|
|
float mLastVoiceVolume; // last voice volume value sent to audio HAL
|
2009-12-14 14:18:18 +01:00
|
|
|
|
2010-07-13 14:01:51 +02:00
|
|
|
// Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
|
|
|
|
static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000;
|
|
|
|
// Maximum memory allocated to audio effects in KB
|
|
|
|
static const uint32_t MAX_EFFECTS_MEMORY = 512;
|
|
|
|
uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects
|
|
|
|
uint32_t mTotalEffectsMemory; // current memory used by effects
|
|
|
|
KeyedVector<int, EffectDescriptor *> mEffects; // list of registered audio effects
|
2010-11-02 20:03:04 +01:00
|
|
|
bool mA2dpSuspended; // true if A2DP output is suspended
|
2012-03-20 21:44:51 +01:00
|
|
|
bool mHasA2dp; // true on platforms with support for bluetooth A2DP
|
2012-04-06 18:07:07 +02:00
|
|
|
bool mHasUsb; // true on platforms with support for USB audio
|
2012-08-20 23:40:08 +02:00
|
|
|
bool mHasRemoteSubmix; // true on platforms with support for remote presentation of a submix
|
2012-03-20 21:44:51 +01:00
|
|
|
audio_devices_t mAttachedOutputDevices; // output devices always available on the platform
|
|
|
|
audio_devices_t mDefaultOutputDevice; // output device selected by default at boot time
|
|
|
|
// (must be in mAttachedOutputDevices)
|
2013-11-15 01:30:20 +01:00
|
|
|
bool mSpeakerDrcEnabled;// true on devices that use DRC on the DEVICE_CATEGORY_SPEAKER path
|
|
|
|
// to boost soft sounds, used to adjust volume curves accordingly
|
2012-03-20 21:44:51 +01:00
|
|
|
|
2012-03-28 20:27:13 +02:00
|
|
|
Vector <HwModule *> mHwModules;
|
2010-07-13 14:01:51 +02:00
|
|
|
|
2009-12-14 14:18:18 +01:00
|
|
|
#ifdef AUDIO_POLICY_TEST
|
|
|
|
Mutex mLock;
|
|
|
|
Condition mWaitWorkCV;
|
|
|
|
|
|
|
|
int mCurOutput;
|
|
|
|
bool mDirectOutput;
|
|
|
|
audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS];
|
|
|
|
int mTestInput;
|
|
|
|
uint32_t mTestDevice;
|
|
|
|
uint32_t mTestSamplingRate;
|
|
|
|
uint32_t mTestFormat;
|
|
|
|
uint32_t mTestChannels;
|
|
|
|
uint32_t mTestLatencyMs;
|
|
|
|
#endif //AUDIO_POLICY_TEST
|
2011-01-25 01:05:03 +01:00
|
|
|
|
|
|
|
private:
|
2012-03-08 22:39:13 +01:00
|
|
|
static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
|
2011-01-25 01:05:03 +01:00
|
|
|
int indexInUi);
|
2012-03-15 17:33:34 +01:00
|
|
|
// updates device caching and output for streams that can influence the
|
|
|
|
// routing of notifications
|
|
|
|
void handleNotificationRoutingForStream(AudioSystem::stream_type stream);
|
2012-09-17 22:40:35 +02:00
|
|
|
static bool isVirtualInputDevice(audio_devices_t device);
|
2009-12-14 14:18:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|