Set volume for output when effect is enabled/disabled.
Even though effect module has "EFFECT_FLAG_VOLUME_CTRL" flag,
there is some case where volume setting is not sent to offload thread.
That leads to sudden increase of audio volume or too low volume.
This change is to support delegation of volume control completely
for offload audio effect.
Bug: 37443095
Test: Enable/Disable Audio effects during offload playback
Change-Id: I7033071edc99fadc519efd7adc895dc10f7b9d86
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index dcad866..4ca50d7 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -2286,6 +2286,11 @@
return mStreamTypes[stream].volume;
}
+void AudioFlinger::PlaybackThread::setVolumeForOutput_l(float left, float right) const
+{
+ mOutput->stream->setVolume(left, right);
+}
+
// addTrack_l() must be called with ThreadBase::mLock held
status_t AudioFlinger::PlaybackThread::addTrack_l(const sp<Track>& track)
{
@@ -5142,20 +5147,20 @@
mLeftVolFloat = left;
mRightVolFloat = right;
- // Convert volumes from float to 8.24
- uint32_t vl = (uint32_t)(left * (1 << 24));
- uint32_t vr = (uint32_t)(right * (1 << 24));
-
// Delegate volume control to effect in track effect chain if needed
// only one effect chain can be present on DirectOutputThread, so if
// there is one, the track is connected to it
if (!mEffectChains.isEmpty()) {
- mEffectChains[0]->setVolume_l(&vl, &vr);
- left = (float)vl / (1 << 24);
- right = (float)vr / (1 << 24);
+ // if effect chain exists, volume is handled by it.
+ // Convert volumes from float to 8.24
+ uint32_t vl = (uint32_t)(left * (1 << 24));
+ uint32_t vr = (uint32_t)(right * (1 << 24));
+ // Direct/Offload effect chains set output volume in setVolume_l().
+ (void)mEffectChains[0]->setVolume_l(&vl, &vr);
+ } else {
+ // otherwise we directly set the volume.
+ setVolumeForOutput_l(left, right);
}
- status_t result = mOutput->stream->setVolume(left, right);
- ALOGE_IF(result != OK, "Error when setting output stream volume: %d", result);
}
}
}