summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVaL Doroshchuk <valentyn.doroshchuk@qt.io>2020-02-18 11:16:17 +0100
committerVaL Doroshchuk <valentyn.doroshchuk@qt.io>2020-03-13 13:08:29 +0100
commit9a4ec4b49601e25d7ac0fd4cfd3df47339ff3ddb (patch)
tree4f3e54d10e9744e9c543d0928f45b479adba41c3 /src
parent060e2e7846441a65bfdab5cf0afea008b1bbb13f (diff)
PulseAudio: Discard buffer with outdated volume in QSoundEffect
When the sample is ready, the volume is applied to it and written back to pulse's buffer. When the volume is changed again, need to discard buffer with outdated volume, and rewrite. Change-Id: I51a6ab3ee1a5c799643a43c5628439c2d659f9fc Fixes: QTBUG-79687 Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/multimedia/audio/qsoundeffect_pulse_p.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/multimedia/audio/qsoundeffect_pulse_p.cpp b/src/multimedia/audio/qsoundeffect_pulse_p.cpp
index 0855c1f67..51cdde026 100644
--- a/src/multimedia/audio/qsoundeffect_pulse_p.cpp
+++ b/src/multimedia/audio/qsoundeffect_pulse_p.cpp
@@ -528,6 +528,21 @@ qreal QSoundEffectPrivate::volume() const
return m_volume;
}
+static void volume_stream_flush_callback(pa_stream *s, int success, void *userdata)
+{
+ Q_UNUSED(s);
+ QSoundEffectRef *ref = reinterpret_cast<QSoundEffectRef *>(userdata);
+ QSoundEffectPrivate *self = ref->soundEffect();
+ ref->release();
+ if (!self)
+ return;
+
+ if (!success)
+ qWarning("QSoundEffect(pulseaudio): failed to drain");
+
+ QMetaObject::invokeMethod(self, "prepare", Qt::QueuedConnection);
+}
+
void QSoundEffectPrivate::setVolume(qreal volume)
{
QMutexLocker locker(&m_volumeLock);
@@ -537,6 +552,8 @@ void QSoundEffectPrivate::setVolume(qreal volume)
m_volume = qBound(qreal(0), volume, qreal(1));
locker.unlock();
+ if (!m_playing && m_pulseStream)
+ pa_stream_flush(m_pulseStream, volume_stream_flush_callback, m_ref->getRef());
emit volumeChanged();
}