From 31de680d5649ffc9568172b3904dccd3580d71ae Mon Sep 17 00:00:00 2001 From: Vincent Becker Date: Mon, 3 Sep 2012 14:29:57 +0800 Subject: audio: add mechanism to re-route nullified audio Fixes a race condition whereby two requests attempt to change the audio stream (and interrupt each other). For example, a user space app makes a call through the audio API and before completion, a kernel function such as jack removal is detected and is serviced. In this case, you have a nullified audio route that needs to be re-routed. In order to know a routing update is needed, a boolean member mForceRouting has been introduced to enforce routing for the next attempt to set audio output with a non-null device. Change-Id: Ia0aa2f27fe63c39f0980dec2e1e79dbc26b81e56 Author: Vincent Becker Signed-off-by: Vincent Becker Signed-off-by: Zhi Jin Signed-off-by: Shuo Gao Signed-off-by: Bruce Beare Signed-off-by: Jack Ren Signed-off-by: Robert Beatty --- audio/AudioPolicyManagerBase.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'audio') diff --git a/audio/AudioPolicyManagerBase.cpp b/audio/AudioPolicyManagerBase.cpp index af24dbd..d62e733 100644 --- a/audio/AudioPolicyManagerBase.cpp +++ b/audio/AudioPolicyManagerBase.cpp @@ -2639,7 +2639,22 @@ uint32_t AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, if (device != AUDIO_DEVICE_NONE) { outputDesc->mDevice = device; + + // Force routing if previously asked for this output + if (outputDesc->mForceRouting) { + ALOGV("Force routing to current device as previous device was null for this output"); + force = true; + + // Request consumed. Reset mForceRouting to false + outputDesc->mForceRouting = false; + } } + else { + // Device is null and does not reflect the routing. Save the necessity to force + // re-routing upon next attempt to select a non-null device for this output + outputDesc->mForceRouting = true; + } + muteWaitMs = checkDeviceMuteStrategies(outputDesc, prevDevice, delayMs); // Do not change the routing if: @@ -3254,7 +3269,8 @@ AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor( : mId(0), mSamplingRate(0), mFormat((audio_format_t)0), mChannelMask((audio_channel_mask_t)0), mLatency(0), mFlags((audio_output_flags_t)0), mDevice(AUDIO_DEVICE_NONE), - mOutput1(0), mOutput2(0), mProfile(profile), mDirectOpenCount(0) + mOutput1(0), mOutput2(0), mProfile(profile), mDirectOpenCount(0), + mForceRouting(false) { // clear usage count for all stream types for (int i = 0; i < AudioSystem::NUM_STREAM_TYPES; i++) { -- cgit v1.1