summaryrefslogtreecommitdiffstats
path: root/media/libmedia/AudioSystem.cpp
diff options
context:
space:
mode:
authorEric Laurent <>2009-04-02 09:32:43 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-04-02 09:32:43 -0700
commit48f7f5e8359909ddfc6492a79a8b9c44759ca6c3 (patch)
treefb57dec51bcb78959e95b6e48b6eb610b07a32a8 /media/libmedia/AudioSystem.cpp
parentd1d35e0359cc411b04615813ba4ebefbb33d1933 (diff)
downloadframeworks_av-48f7f5e8359909ddfc6492a79a8b9c44759ca6c3.zip
frameworks_av-48f7f5e8359909ddfc6492a79a8b9c44759ca6c3.tar.gz
frameworks_av-48f7f5e8359909ddfc6492a79a8b9c44759ca6c3.tar.bz2
AI 144097: am: CL 144054 am: CL 144053 Fix issue #1751242 A2DP playback fails first time: Invalid buffer size: minFrameCount 10240, frameCount 4800
The problem comes from the fact that AudioSystem::getOutputFrameCount() calls getOutput() to retrieve the active output (A2DP or Hardware) before calling get_audio_flinger(). If it is the first time AudioSystem::getOutputFrameCount() is called in a given process, getOutput() will return a wrong value because gA2dpEnabled has not yet been updated by get_audio_flinger(). The fix consists in calling get_audio_flinger() in getOutput() to be sure that gA2dpEnabled is valid when getOutput() reads it. Original author: elaurent Merged from: //branches/cupcake/... Original author: android-build Merged from: //branches/donutburger/... Automated import of CL 144097
Diffstat (limited to 'media/libmedia/AudioSystem.cpp')
-rw-r--r--media/libmedia/AudioSystem.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index 63dfc3b..a21a7a4 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -258,13 +258,12 @@ int AudioSystem::logToLinear(float volume)
status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType)
{
int output = getOutput(streamType);
+
+ if (output == NUM_AUDIO_OUTPUT_TYPES) return PERMISSION_DENIED;
- if (gOutSamplingRate[output] == 0) {
- const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
- if (af == 0) return PERMISSION_DENIED;
- // gOutSamplingRate is updated by get_audio_flinger()
- }
+ // gOutSamplingRate[] is updated by getOutput() which calls get_audio_flinger()
LOGV("getOutputSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output, gOutSamplingRate[output]);
+
*samplingRate = gOutSamplingRate[output];
return NO_ERROR;
@@ -274,14 +273,13 @@ status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType)
{
int output = getOutput(streamType);
- if (gOutFrameCount[output] == 0) {
- const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
- if (af == 0) return PERMISSION_DENIED;
- // gOutFrameCount is updated by get_audio_flinger()
- }
+ if (output == NUM_AUDIO_OUTPUT_TYPES) return PERMISSION_DENIED;
+
+ // gOutFrameCount[] is updated by getOutput() which calls get_audio_flinger()
LOGV("getOutputFrameCount() streamType %d, output %d, frame count %d", streamType, output, gOutFrameCount[output]);
*frameCount = gOutFrameCount[output];
+
return NO_ERROR;
}
@@ -289,11 +287,9 @@ status_t AudioSystem::getOutputLatency(uint32_t* latency, int streamType)
{
int output = getOutput(streamType);
- if (gOutLatency[output] == 0) {
- const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
- if (af == 0) return PERMISSION_DENIED;
- // gOutLatency is updated by get_audio_flinger()
- }
+ if (output == NUM_AUDIO_OUTPUT_TYPES) return PERMISSION_DENIED;
+
+ // gOutLatency[] is updated by getOutput() which calls get_audio_flinger()
LOGV("getOutputLatency() streamType %d, output %d, latency %d", streamType, output, gOutLatency[output]);
*latency = gOutLatency[output];
@@ -354,7 +350,12 @@ void AudioSystem::setErrorCallback(audio_error_callback cb) {
}
int AudioSystem::getOutput(int streamType)
-{
+{
+ // make sure that gA2dpEnabled is valid by calling get_audio_flinger() which in turn
+ // will call gAudioFlinger->isA2dpEnabled()
+ const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
+ if (af == 0) return NUM_AUDIO_OUTPUT_TYPES;
+
if (streamType == DEFAULT) {
streamType = MUSIC;
}