File 0003-StreamRestore-Cache-values-in-writeChanges-until-rec.patch of Package plasma5-pa

From e04fe22e5e5afcffa1f4684114eb0b780f89c558 Mon Sep 17 00:00:00 2001
From: David Rosca <nowrep@gmail.com>
Date: Mon, 20 Feb 2017 10:00:30 +0100
Subject: [PATCH 3/4] StreamRestore: Cache values in writeChanges until
 receiving change from pa

pa_ext_stream_restore have only one function to change all its
properties, so we need to cache values between clients changing
StreamRestore properties and pulseaudio actually signaling the property
was changed.

Fixes correctly muting Notification Sounds stream in KCM when moving
slider to 0 value, because in that moment the KCM first sets volume to 0
and then immediately mute to true.

Differential Revision: https://phabricator.kde.org/D4674
---
 src/streamrestore.cpp | 39 ++++++++++++++++++++++++++++++---------
 src/streamrestore.h   |  8 ++++++++
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/src/streamrestore.cpp b/src/streamrestore.cpp
index bc534da..f04b75a 100644
--- a/src/streamrestore.cpp
+++ b/src/streamrestore.cpp
@@ -38,6 +38,7 @@ StreamRestore::StreamRestore(quint32 index, const QVariantMap &properties, QObje
 
 void StreamRestore::update(const pa_ext_stream_restore_info *info)
 {
+    m_cache.valid = false;
     const QString infoName = QString::fromUtf8(info->name);
     if (m_name != infoName) {
         m_name = infoName;
@@ -80,7 +81,11 @@ QString StreamRestore::device() const
 
 void StreamRestore::setDevice(const QString &device)
 {
-    writeChanges(m_volume, m_channelMap, m_muted, device);
+    if (m_cache.valid) {
+        writeChanges(m_cache.volume, m_cache.channelMap, m_cache.muted, device);
+    } else {
+        writeChanges(m_volume, m_channelMap, m_muted, device);
+    }
 }
 
 qint64 StreamRestore::volume() const
@@ -90,11 +95,16 @@ qint64 StreamRestore::volume() const
 
 void StreamRestore::setVolume(qint64 volume)
 {
-    pa_cvolume vol = m_volume;
+    pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume;
     for (int i = 0; i < vol.channels; ++i) {
         vol.values[i] = volume;
     }
-    writeChanges(vol, m_channelMap, m_muted, m_device);
+
+    if (m_cache.valid) {
+        writeChanges(vol, m_cache.channelMap, m_cache.muted, m_cache.device);
+    } else {
+        writeChanges(vol, m_channelMap, m_muted, m_device);
+    }
 }
 
 bool StreamRestore::isMuted() const
@@ -104,11 +114,11 @@ bool StreamRestore::isMuted() const
 
 void StreamRestore::setMuted(bool muted)
 {
-    if (m_muted == muted) {
-        return;
+    if (m_cache.valid) {
+        writeChanges(m_cache.volume, m_cache.channelMap, muted, m_cache.device);
+    } else {
+        writeChanges(m_volume, m_channelMap, muted, m_device);
     }
-
-    writeChanges(m_volume, m_channelMap, muted, m_device);
 }
 
 bool StreamRestore::hasVolume() const
@@ -139,9 +149,14 @@ QList<qint64> StreamRestore::channelVolumes() const
 void StreamRestore::setChannelVolume(int channel, qint64 volume)
 {
     Q_ASSERT(channel >= 0 && channel < m_volume.channels);
-    pa_cvolume vol = m_volume;
+    pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume;
     vol.values[channel] = volume;
-    writeChanges(vol, m_channelMap, m_muted, m_device);
+
+    if (m_cache.valid) {
+        writeChanges(vol, m_cache.channelMap, m_cache.muted, m_cache.device);
+    } else {
+        writeChanges(vol, m_channelMap, m_muted, m_device);
+    }
 }
 
 quint32 StreamRestore::deviceIndex() const
@@ -167,6 +182,12 @@ void StreamRestore::writeChanges(const pa_cvolume &volume, const pa_channel_map
     info.device = deviceData.isEmpty() ? nullptr : deviceData.constData();
     info.mute = muted;
 
+    m_cache.valid = true;
+    m_cache.volume = volume;
+    m_cache.channelMap = channelMap;
+    m_cache.muted = muted;
+    m_cache.device = device;
+
     context()->streamRestoreWrite(&info);
 }
 
diff --git a/src/streamrestore.h b/src/streamrestore.h
index 63bf466..fb8c974 100644
--- a/src/streamrestore.h
+++ b/src/streamrestore.h
@@ -86,6 +86,14 @@ private:
     pa_channel_map m_channelMap;
     QStringList m_channels;
     bool m_muted;
+
+    struct {
+        bool valid = false;
+        pa_cvolume volume;
+        pa_channel_map channelMap;
+        bool muted;
+        QString device;
+    } m_cache;
 };
 
 } // QPulseAudio
-- 
2.12.0

openSUSE Build Service is sponsored by