diff options
Diffstat (limited to 'include/hardware_legacy/AudioPolicyManagerBase.h')
| -rw-r--r-- | include/hardware_legacy/AudioPolicyManagerBase.h | 144 |
1 files changed, 101 insertions, 43 deletions
diff --git a/include/hardware_legacy/AudioPolicyManagerBase.h b/include/hardware_legacy/AudioPolicyManagerBase.h index d864b0a..1459e7e 100644 --- a/include/hardware_legacy/AudioPolicyManagerBase.h +++ b/include/hardware_legacy/AudioPolicyManagerBase.h @@ -20,11 +20,14 @@ #include <utils/Timers.h> #include <utils/Errors.h> #include <utils/KeyedVector.h> +#include <utils/SortedVector.h> #include <hardware_legacy/AudioPolicyInterface.h> namespace android_audio_legacy { using android::KeyedVector; + using android::DefaultKeyedVector; + using android::SortedVector; // ---------------------------------------------------------------------------- @@ -53,6 +56,20 @@ namespace android_audio_legacy { // and provided in a shared library libaudiopolicy.so. // ---------------------------------------------------------------------------- +// the output_profile_s structure describes the capabilities of an output 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 is suitable for a given use case, +// open/close it accordingly and connect/disconnect audio tracks to/from it. +typedef struct output_profile_s { + uint32_t* mSamplingRates; // supported sampling rates (terminated by 0) + audio_channel_mask_t* mChannelMasks; // supported channel masks (terminated by 0) + audio_format_t* mFormats; // supported audio formats (terminated by 0) + audio_devices_t mSupportedDevices; // supported devices (devices this output can be + // routed to) + audio_policy_output_flags_t mFlags; // attribute flags (e.g primary output, + // direct output...) +} output_profile_t; + class AudioPolicyManagerBase: public AudioPolicyInterface #ifdef AUDIO_POLICY_TEST , public Thread @@ -70,7 +87,6 @@ public: virtual AudioSystem::device_connection_state getDeviceConnectionState(AudioSystem::audio_devices device, const char *device_address); virtual void setPhoneState(int state); - virtual void setRingerMode(uint32_t mode, uint32_t mask); 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); @@ -93,22 +109,28 @@ public: uint32_t format, uint32_t channels, AudioSystem::audio_in_acoustics acoustics); + // indicates to the audio policy manager that the input starts being used. virtual status_t startInput(audio_io_handle_t input); + // 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); virtual void initStreamVolume(AudioSystem::stream_type stream, int indexMin, int indexMax); - virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, int index); - virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, int *index); + 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); // return the strategy corresponding to a given stream type virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream); // return the enabled output devices for the given stream type - virtual uint32_t getDevicesForStream(AudioSystem::stream_type stream); + virtual audio_devices_t getDevicesForStream(AudioSystem::stream_type stream); virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc); virtual status_t registerEffect(effect_descriptor_t *desc, @@ -130,6 +152,7 @@ protected: STRATEGY_PHONE, STRATEGY_SONIFICATION, STRATEGY_DTMF, + STRATEGY_ENFORCED_AUDIBLE, NUM_STRATEGIES }; @@ -170,16 +193,17 @@ protected: class AudioOutputDescriptor { public: - AudioOutputDescriptor(); + AudioOutputDescriptor(const output_profile_t *profile); status_t dump(int fd); - uint32_t device(); + audio_devices_t device(); void changeRefCount(AudioSystem::stream_type, int delta); uint32_t refCount(); uint32_t strategyRefCount(routing_strategy strategy); bool isUsedByStrategy(routing_strategy strategy) { return (strategyRefCount(strategy) != 0);} bool isDuplicated() { return (mOutput1 != NULL && mOutput2 != NULL); } + audio_devices_t supportedDevices(); audio_io_handle_t mId; // output handle uint32_t mSamplingRate; // @@ -187,13 +211,14 @@ protected: uint32_t mChannels; // output configuration uint32_t mLatency; // AudioSystem::output_flags mFlags; // - uint32_t mDevice; // current device this output is routed to + audio_devices_t mDevice; // current device this output is routed to uint32_t mRefCount[AudioSystem::NUM_STREAM_TYPES]; // number of streams of each type using this output nsecs_t mStopTime[AudioSystem::NUM_STREAM_TYPES]; 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 + const output_profile_t *mProfile; }; // descriptor for audio inputs. Used to maintain current configuration of each opened audio input @@ -209,23 +234,23 @@ protected: uint32_t mFormat; // input configuration uint32_t mChannels; // AudioSystem::audio_in_acoustics mAcoustics; // - uint32_t mDevice; // current device this input is routed to + audio_devices_t mDevice; // current device this input is routed to uint32_t mRefCount; // number of AudioRecord clients using this output - int mInputSource; // input source selected by application (mediarecorder.h) + int mInputSource; // input source selected by application (mediarecorder.h) }; // stream descriptor used for volume control class StreamDescriptor { public: - StreamDescriptor() - : mIndexMin(0), mIndexMax(1), mIndexCur(1), mCanBeMuted(true) {} + StreamDescriptor(); - void dump(char* buffer, size_t size); + int getVolumeIndex(audio_devices_t device); + void dump(int fd); int mIndexMin; // min volume index int mIndexMax; // max volume index - int mIndexCur; // current volume index + KeyedVector<audio_devices_t, int> mIndexCur; // current volume index per device bool mCanBeMuted; // true is the stream can be muted const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT]; @@ -249,6 +274,7 @@ protected: // return the strategy corresponding to a given stream type static routing_strategy getStrategy(AudioSystem::stream_type stream); + // return appropriate device for streams handled by the specified strategy according to current // phone state, connected devices... // if fromCache is true, the device is returned from mDeviceForStrategy[], otherwise it is determined @@ -259,65 +285,93 @@ protected: // "future" device selection (fromCache == false) when called from a context // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND // before updateDeviceForStrategy() is called. - virtual uint32_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true); + virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true); + // change the route of the specified output - void setOutputDevice(audio_io_handle_t output, uint32_t device, bool force = false, int delayMs = 0); + void setOutputDevice(audio_io_handle_t output, + audio_devices_t device, + bool force = false, + int delayMs = 0); + // select input device corresponding to requested audio source - virtual uint32_t getDeviceForInputSource(int inputSource); + virtual audio_devices_t getDeviceForInputSource(int inputSource); + // return io handle of active input or 0 if no input is active audio_io_handle_t getActiveInput(); + // initialize volume curves for each strategy and device category void initializeVolumeCurves(); + // compute the actual volume for a given stream according to the requested index and a particular // device - virtual float computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device); + virtual float computeVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device); + // check that volume change is permitted, compute and send new volume to audio hardware - status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, uint32_t device, int delayMs = 0, bool force = false); + status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false); + // apply all stream volumes to the specified output and device - void applyStreamVolumes(audio_io_handle_t output, uint32_t device, int delayMs = 0, bool force = false); + void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false); + // Mute or unmute all streams handled by the specified strategy on the specified output void setStrategyMute(routing_strategy strategy, bool on, audio_io_handle_t output, int delayMs = 0); + // Mute or unmute the stream on the specified output void setStreamMute(int stream, bool on, audio_io_handle_t output, int delayMs = 0); + // 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); + // true is current platform implements a back microphone virtual bool hasBackMicrophone() const { return false; } + // true if device is in a telephony or VoIP call virtual bool isInCall(); + // true if given state represents a device in a telephony or VoIP call virtual bool isStateInCall(int state); -#ifdef WITH_A2DP - // true is current platform supports suplication of notifications and ringtones over A2DP output - virtual bool a2dpUsedForSonification() const { return true; } - status_t handleA2dpConnection(AudioSystem::audio_devices device, - const char *device_address); - status_t handleA2dpDisconnection(AudioSystem::audio_devices device, - const char *device_address); - void closeA2dpOutputs(); - // checks and if necessary changes output (a2dp, duplicated or hardware) used for all strategies. - // must be called every time a condition that affects the output choice for a given strategy is - // changed: connected device, phone state, force use... + // 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. + audio_io_handle_t checkOutputForDevice(audio_devices_t device, + AudioSystem::device_connection_state state); + + // close an output and its companion duplicating output. + void closeOutput(audio_io_handle_t output); + + // 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... // Must be called before updateDeviceForStrategy() void checkOutputForStrategy(routing_strategy strategy); + // Same as checkOutputForStrategy() but for a all strategies in order of priority void checkOutputForAllStrategies(); + // manages A2DP output suspend/restore according to phone state and BT SCO usage void checkA2dpSuspend(); -#endif + + // returns the A2DP output handle if it is open or 0 otherwise + audio_io_handle_t getA2dpOutput(); + // 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 - uint32_t getNewDevice(audio_io_handle_t output, bool fromCache = true); + + audio_devices_t getNewDevice(audio_io_handle_t output, bool fromCache = true); // 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() + void updateDeviceForStrategy(); + // true if current platform requires a specific output to be opened for this particular // set of parameters. This function is called by getOutput() and is implemented by platform // specific audio policy manager. @@ -327,6 +381,7 @@ protected: uint32_t channels, AudioSystem::output_flags flags, uint32_t device); + virtual uint32_t getMaxEffectsCpuLoad(); virtual uint32_t getMaxEffectsMemory(); #ifdef AUDIO_POLICY_TEST @@ -338,26 +393,29 @@ protected: status_t setEffectEnabled(EffectDescriptor *pDesc, bool enabled); // returns the category the device belongs to with regard to volume curve management - static device_category getDeviceCategory(uint32_t device); + static device_category getDeviceCategory(audio_devices_t device); - AudioPolicyClientInterface *mpClientInterface; // audio policy client interface - audio_io_handle_t mHardwareOutput; // hardware output handler - audio_io_handle_t mA2dpOutput; // A2DP output handler - audio_io_handle_t mDuplicatedOutput; // duplicated output handler: outputs to hardware and A2DP. + // extract one device relevant for volume control from multiple device selection + static audio_devices_t getDeviceForVolume(audio_devices_t device); + + SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device); + bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1, + SortedVector<audio_io_handle_t>& outputs2); - KeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mOutputs; // list of output descriptors - KeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs; // list of input descriptors - uint32_t mAvailableOutputDevices; // bit field of all available output devices + AudioPolicyClientInterface *mpClientInterface; // audio policy client interface + audio_io_handle_t mPrimaryOutput; // primary output handle + DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mOutputs; // list of output descriptors + DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs; // list of input descriptors + audio_devices_t mAvailableOutputDevices; // bit field of all available output devices uint32_t mAvailableInputDevices; // bit field of all available input devices int mPhoneState; // current phone state - uint32_t mRingerMode; // current ringer mode 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 bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected - uint32_t mDeviceForStrategy[NUM_STRATEGIES]; + audio_devices_t mDeviceForStrategy[NUM_STRATEGIES]; float mLastVoiceVolume; // last voice volume value sent to audio HAL // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units @@ -385,7 +443,7 @@ protected: #endif //AUDIO_POLICY_TEST private: - static float volIndexToAmpl(uint32_t device, const StreamDescriptor& streamDesc, + static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc, int indexInUi); }; |
