Fixed problems in audio effect volume control.
Fixed the following problems in audio effect volume control in AudioFlinger:
- Make sure that the volumes returned by EffectChain::setVolume_l() are correct even is
no change is detected since last call
- Do not use isEnabled() to validate volume control but mState >= ACTIVE instead as the volume control
must be also active in STOPPING and STOPPED states.
Change-Id: Id62da3164fad500ee8a5efd6cd78c77e8fdcb541
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 7e528af..b38a5c8 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -2948,7 +2948,8 @@
status_t AudioFlinger::PlaybackThread::Track::start()
{
status_t status = NO_ERROR;
- LOGV("start(%d), calling thread %d", mName, IPCThreadState::self()->getCallingPid());
+ LOGV("start(%d), calling thread %d session %d",
+ mName, IPCThreadState::self()->getCallingPid(), mSessionId);
sp<ThreadBase> thread = mThread.promote();
if (thread != 0) {
Mutex::Autolock _l(thread->mLock);
@@ -5366,9 +5367,9 @@
// Send volume indication if EFFECT_FLAG_VOLUME_IND is set and read back altered volume
// if controller flag is set (Note that controller == TRUE => EFFECT_FLAG_VOLUME_CTRL set)
- if (isEnabled() &&
- (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL ||
- (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_IND) {
+ if ((mState >= ACTIVE) &&
+ ((mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL ||
+ (mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_IND)) {
status_t cmdStatus;
uint32_t volume[2];
uint32_t *pVolume = NULL;
@@ -5749,7 +5750,8 @@
AudioFlinger::EffectChain::EffectChain(const wp<ThreadBase>& wThread,
int sessionId)
: mThread(wThread), mSessionId(sessionId), mActiveTrackCnt(0), mOwnInBuffer(false),
- mVolumeCtrlIdx(-1), mLeftVolume(0), mRightVolume(0)
+ mVolumeCtrlIdx(-1), mLeftVolume(0), mRightVolume(0),
+ mNewLeftVolume(0), mNewRightVolume(0)
{
}
@@ -5980,25 +5982,34 @@
// first update volume controller
for (size_t i = size; i > 0; i--) {
- if (mEffects[i - 1]->isEnabled() &&
+ if ((mEffects[i - 1]->state() >= EffectModule::ACTIVE) &&
(mEffects[i - 1]->desc().flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL) {
ctrlIdx = i - 1;
+ hasControl = true;
break;
}
}
if (ctrlIdx == mVolumeCtrlIdx && *left == mLeftVolume && *right == mRightVolume) {
- return false;
+ if (hasControl) {
+ *left = mNewLeftVolume;
+ *right = mNewRightVolume;
+ }
+ return hasControl;
}
+ if (mVolumeCtrlIdx != -1) {
+ hasControl = true;
+ }
mVolumeCtrlIdx = ctrlIdx;
- mLeftVolume = *left;
- mRightVolume = *right;
+ mLeftVolume = newLeft;
+ mRightVolume = newRight;
// second get volume update from volume controller
if (ctrlIdx >= 0) {
mEffects[ctrlIdx]->setVolume(&newLeft, &newRight, true);
- hasControl = true;
+ mNewLeftVolume = newLeft;
+ mNewRightVolume = newRight;
}
// then indicate volume to all other effects in chain.
// Pass altered volume to effects before volume controller