diff options
Diffstat (limited to 'media/libmedia/AudioSystem.cpp')
-rw-r--r-- | media/libmedia/AudioSystem.cpp | 120 |
1 files changed, 67 insertions, 53 deletions
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp index f7f129c..110a294 100644 --- a/media/libmedia/AudioSystem.cpp +++ b/media/libmedia/AudioSystem.cpp @@ -35,12 +35,13 @@ sp<IAudioFlinger> AudioSystem::gAudioFlinger; sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient; audio_error_callback AudioSystem::gAudioErrorCallback = NULL; // Cached values -DefaultKeyedVector<int, audio_io_handle_t> AudioSystem::gStreamOutputMap(0); + +DefaultKeyedVector<audio_stream_type_t, audio_io_handle_t> AudioSystem::gStreamOutputMap(0); DefaultKeyedVector<audio_io_handle_t, AudioSystem::OutputDescriptor *> AudioSystem::gOutputs(0); -// Cached values for recording queries +// Cached values for recording queries, all protected by gLock uint32_t AudioSystem::gPrevInSamplingRate = 16000; -int AudioSystem::gPrevInFormat = AUDIO_FORMAT_PCM_16_BIT; +audio_format_t AudioSystem::gPrevInFormat = AUDIO_FORMAT_PCM_16_BIT; int AudioSystem::gPrevInChannelCount = 1; size_t AudioSystem::gInBuffSize = 0; @@ -49,7 +50,7 @@ size_t AudioSystem::gInBuffSize = 0; const sp<IAudioFlinger>& AudioSystem::get_audio_flinger() { Mutex::Autolock _l(gLock); - if (gAudioFlinger.get() == 0) { + if (gAudioFlinger == 0) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder; do { @@ -120,7 +121,7 @@ status_t AudioSystem::getMasterMute(bool* mute) return NO_ERROR; } -status_t AudioSystem::setStreamVolume(int stream, float value, int output) +status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value, int output) { if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); @@ -129,7 +130,7 @@ status_t AudioSystem::setStreamVolume(int stream, float value, int output) return NO_ERROR; } -status_t AudioSystem::setStreamMute(int stream, bool mute) +status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute) { if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); @@ -138,7 +139,7 @@ status_t AudioSystem::setStreamMute(int stream, bool mute) return NO_ERROR; } -status_t AudioSystem::getStreamVolume(int stream, float* volume, int output) +status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume, int output) { if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); @@ -147,7 +148,7 @@ status_t AudioSystem::getStreamVolume(int stream, float* volume, int output) return NO_ERROR; } -status_t AudioSystem::getStreamMute(int stream, bool* mute) +status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute) { if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); @@ -156,9 +157,9 @@ status_t AudioSystem::getStreamMute(int stream, bool* mute) return NO_ERROR; } -status_t AudioSystem::setMode(int mode) +status_t AudioSystem::setMode(audio_mode_t mode) { - if (mode >= AUDIO_MODE_CNT) return BAD_VALUE; + if (uint32_t(mode) >= AUDIO_MODE_CNT) return BAD_VALUE; const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); if (af == 0) return PERMISSION_DENIED; return af->setMode(mode); @@ -203,7 +204,12 @@ int AudioSystem::logToLinear(float volume) return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; } -status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType) +// DEPRECATED +status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType) { + return getOutputSamplingRate(samplingRate, (audio_stream_type_t)streamType); +} + +status_t AudioSystem::getOutputSamplingRate(int* samplingRate, audio_stream_type_t streamType) { OutputDescriptor *outputDesc; audio_io_handle_t output; @@ -212,14 +218,14 @@ status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType) streamType = AUDIO_STREAM_MUSIC; } - output = getOutput((audio_stream_type_t)streamType); + output = getOutput(streamType); if (output == 0) { return PERMISSION_DENIED; } gLock.lock(); outputDesc = AudioSystem::gOutputs.valueFor(output); - if (outputDesc == 0) { + if (outputDesc == NULL) { ALOGV("getOutputSamplingRate() no output descriptor for output %d in gOutputs", output); gLock.unlock(); const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); @@ -236,7 +242,12 @@ status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType) return NO_ERROR; } -status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType) +// DEPRECATED +status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType) { + return getOutputFrameCount(frameCount, (audio_stream_type_t)streamType); +} + +status_t AudioSystem::getOutputFrameCount(int* frameCount, audio_stream_type_t streamType) { OutputDescriptor *outputDesc; audio_io_handle_t output; @@ -245,14 +256,14 @@ status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType) streamType = AUDIO_STREAM_MUSIC; } - output = getOutput((audio_stream_type_t)streamType); + output = getOutput(streamType); if (output == 0) { return PERMISSION_DENIED; } gLock.lock(); outputDesc = AudioSystem::gOutputs.valueFor(output); - if (outputDesc == 0) { + if (outputDesc == NULL) { gLock.unlock(); const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); if (af == 0) return PERMISSION_DENIED; @@ -267,7 +278,7 @@ status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType) return NO_ERROR; } -status_t AudioSystem::getOutputLatency(uint32_t* latency, int streamType) +status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType) { OutputDescriptor *outputDesc; audio_io_handle_t output; @@ -276,14 +287,14 @@ status_t AudioSystem::getOutputLatency(uint32_t* latency, int streamType) streamType = AUDIO_STREAM_MUSIC; } - output = getOutput((audio_stream_type_t)streamType); + output = getOutput(streamType); if (output == 0) { return PERMISSION_DENIED; } gLock.lock(); outputDesc = AudioSystem::gOutputs.valueFor(output); - if (outputDesc == 0) { + if (outputDesc == NULL) { gLock.unlock(); const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); if (af == 0) return PERMISSION_DENIED; @@ -298,25 +309,30 @@ status_t AudioSystem::getOutputLatency(uint32_t* latency, int streamType) return NO_ERROR; } -status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, int format, int channelCount, +status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount, size_t* buffSize) { + gLock.lock(); // Do we have a stale gInBufferSize or are we requesting the input buffer size for new values - if ((gInBuffSize == 0) || (sampleRate != gPrevInSamplingRate) || (format != gPrevInFormat) + size_t inBuffSize = gInBuffSize; + if ((inBuffSize == 0) || (sampleRate != gPrevInSamplingRate) || (format != gPrevInFormat) || (channelCount != gPrevInChannelCount)) { + gLock.unlock(); + const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); + if (af == 0) { + return PERMISSION_DENIED; + } + inBuffSize = af->getInputBufferSize(sampleRate, format, channelCount); + gLock.lock(); // save the request params gPrevInSamplingRate = sampleRate; gPrevInFormat = format; gPrevInChannelCount = channelCount; - gInBuffSize = 0; - const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); - if (af == 0) { - return PERMISSION_DENIED; - } - gInBuffSize = af->getInputBufferSize(sampleRate, format, channelCount); + gInBuffSize = inBuffSize; } - *buffSize = gInBuffSize; + gLock.unlock(); + *buffSize = inBuffSize; return NO_ERROR; } @@ -328,7 +344,7 @@ status_t AudioSystem::setVoiceVolume(float value) return af->setVoiceVolume(value); } -status_t AudioSystem::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int stream) +status_t AudioSystem::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, audio_stream_type_t stream) { const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); if (af == 0) return PERMISSION_DENIED; @@ -337,7 +353,7 @@ status_t AudioSystem::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames stream = AUDIO_STREAM_MUSIC; } - return af->getRenderPosition(halFrames, dspFrames, getOutput((audio_stream_type_t)stream)); + return af->getRenderPosition(halFrames, dspFrames, getOutput(stream)); } unsigned int AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) { @@ -389,7 +405,7 @@ void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who) { void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, int ioHandle, void *param2) { ALOGV("ioConfigChanged() event %d", event); OutputDescriptor *desc; - uint32_t stream; + audio_stream_type_t stream; if (ioHandle == 0) return; @@ -397,8 +413,8 @@ void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, int ioHandle, v switch (event) { case STREAM_CONFIG_CHANGED: - if (param2 == 0) break; - stream = *(uint32_t *)param2; + if (param2 == NULL) break; + stream = *(audio_stream_type_t *)param2; ALOGV("ioConfigChanged() STREAM_CONFIG_CHANGED stream %d, output %d", stream, ioHandle); if (gStreamOutputMap.indexOfKey(stream) >= 0) { gStreamOutputMap.replaceValueFor(stream, ioHandle); @@ -409,7 +425,7 @@ void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, int ioHandle, v ALOGV("ioConfigChanged() opening already existing output! %d", ioHandle); break; } - if (param2 == 0) break; + if (param2 == NULL) break; desc = (OutputDescriptor *)param2; OutputDescriptor *outputDesc = new OutputDescriptor(*desc); @@ -438,7 +454,7 @@ void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, int ioHandle, v ALOGW("ioConfigChanged() modifying unknow output! %d", ioHandle); break; } - if (param2 == 0) break; + if (param2 == NULL) break; desc = (OutputDescriptor *)param2; ALOGV("ioConfigChanged() new config for output %d samplingRate %d, format %d channels %d frameCount %d latency %d", @@ -462,7 +478,7 @@ void AudioSystem::setErrorCallback(audio_error_callback cb) { gAudioErrorCallback = cb; } -bool AudioSystem::routedToA2dpOutput(int streamType) { +bool AudioSystem::routedToA2dpOutput(audio_stream_type_t streamType) { switch(streamType) { case AUDIO_STREAM_MUSIC: case AUDIO_STREAM_VOICE_CALL: @@ -484,7 +500,7 @@ sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient const sp<IAudioPolicyService>& AudioSystem::get_audio_policy_service() { gLock.lock(); - if (gAudioPolicyService.get() == 0) { + if (gAudioPolicyService == 0) { sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder; do { @@ -531,21 +547,15 @@ audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t d return aps->getDeviceConnectionState(device, device_address); } -status_t AudioSystem::setPhoneState(int state) +status_t AudioSystem::setPhoneState(audio_mode_t state) { + if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE; const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); if (aps == 0) return PERMISSION_DENIED; return aps->setPhoneState(state); } -status_t AudioSystem::setRingerMode(uint32_t mode, uint32_t mask) -{ - const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); - if (aps == 0) return PERMISSION_DENIED; - return aps->setRingerMode(mode, mask); -} - status_t AudioSystem::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) { const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); @@ -563,7 +573,7 @@ audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usag audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream, uint32_t samplingRate, - uint32_t format, + audio_format_t format, uint32_t channels, audio_policy_output_flags_t flags) { @@ -621,9 +631,9 @@ void AudioSystem::releaseOutput(audio_io_handle_t output) aps->releaseOutput(output); } -audio_io_handle_t AudioSystem::getInput(int inputSource, +audio_io_handle_t AudioSystem::getInput(audio_source_t inputSource, uint32_t samplingRate, - uint32_t format, + audio_format_t format, uint32_t channels, audio_in_acoustics_t acoustics, int sessionId) @@ -663,18 +673,22 @@ status_t AudioSystem::initStreamVolume(audio_stream_type_t stream, return aps->initStreamVolume(stream, indexMin, indexMax); } -status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, int index) +status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, + int index, + audio_devices_t device) { const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); if (aps == 0) return PERMISSION_DENIED; - return aps->setStreamVolumeIndex(stream, index); + return aps->setStreamVolumeIndex(stream, index, device); } -status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream, int *index) +status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream, + int *index, + audio_devices_t device) { const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); if (aps == 0) return PERMISSION_DENIED; - return aps->getStreamVolumeIndex(stream, index); + return aps->getStreamVolumeIndex(stream, index, device); } uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream) @@ -723,7 +737,7 @@ status_t AudioSystem::setEffectEnabled(int id, bool enabled) return aps->setEffectEnabled(id, enabled); } -status_t AudioSystem::isStreamActive(int stream, bool* state, uint32_t inPastMs) +status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs) { const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); if (aps == 0) return PERMISSION_DENIED; |