OSDN Git Service

Fix issue 5381089: problem with A2DP music volume
authorEric Laurent <elaurent@google.com>
Thu, 6 Oct 2011 00:42:25 +0000 (17:42 -0700)
committerEric Laurent <elaurent@google.com>
Thu, 6 Oct 2011 00:42:25 +0000 (17:42 -0700)
This problem only occurs when audio effects are present and
the music volume is applied by one effect engine.
When connecting or disconnecting A2DP, audio effects are moved from
one mixer thread to another. When removed from the source thread,
the effect is stopped but it is not restarted when added to the
destination thread.
This regression was introduced by commit 21b5c47e.

Change-Id: I4cc578d8d760ec65b185032b6fda98c739d331bc

services/audioflinger/AudioFlinger.cpp
services/audioflinger/AudioFlinger.h

index 01f5a6f..ab49f93 100644 (file)
@@ -5550,7 +5550,7 @@ status_t AudioFlinger::moveEffectChain_l(int sessionId,
 
     // remove chain first. This is useful only if reconfiguring effect chain on same output thread,
     // so that a new chain is created with correct parameters when first effect is added. This is
-    // otherwise unecessary as removeEffect_l() will remove the chain when last effect is
+    // otherwise unnecessary as removeEffect_l() will remove the chain when last effect is
     // removed.
     srcThread->removeEffectChain_l(chain);
 
@@ -5563,6 +5563,11 @@ status_t AudioFlinger::moveEffectChain_l(int sessionId,
     while (effect != 0) {
         srcThread->removeEffect_l(effect);
         dstThread->addEffect_l(effect);
+        // removeEffect_l() has stopped the effect if it was active so it must be restarted
+        if (effect->state() == EffectModule::ACTIVE ||
+                effect->state() == EffectModule::STOPPING) {
+            effect->start();
+        }
         // if the move request is not received from audio policy manager, the effect must be
         // re-registered with the new strategy and output
         if (dstChain == 0) {
@@ -6350,6 +6355,12 @@ status_t AudioFlinger::EffectModule::init()
     return status;
 }
 
+status_t AudioFlinger::EffectModule::start()
+{
+    Mutex::Autolock _l(mLock);
+    return start_l();
+}
+
 status_t AudioFlinger::EffectModule::start_l()
 {
     if (mEffectInterface == NULL) {
@@ -7214,7 +7225,10 @@ size_t AudioFlinger::EffectChain::removeEffect_l(const sp<EffectModule>& effect)
             // calling stop here will remove pre-processing effect from the audio HAL.
             // This is safe as we hold the EffectChain mutex which guarantees that we are not in
             // the middle of a read from audio HAL
-            mEffects[i]->stop();
+            if (mEffects[i]->state() == EffectModule::ACTIVE ||
+                    mEffects[i]->state() == EffectModule::STOPPING) {
+                mEffects[i]->stop();
+            }
             if (type == EFFECT_FLAG_TYPE_AUXILIARY) {
                 delete[] effect->inBuffer();
             } else {
index 2e05593..ed9d81e 100644 (file)
@@ -1117,6 +1117,7 @@ private:
         status_t         setDevice(uint32_t device);
         status_t         setVolume(uint32_t *left, uint32_t *right, bool controller);
         status_t         setMode(uint32_t mode);
+        status_t         start();
         status_t         stop();
         void             setSuspended(bool suspended);
         bool             suspended();