StreamRestore: Cache values in writeChanges until receiving change from pa
ClosedPublic

Authored by drosca on Feb 20 2017, 9:05 AM.

Details

Summary

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.

Test Plan

Changing notification sounds volume with slider works correctlu now

Diff Detail

Repository
R115 Plasma Audio Volume Applet
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
drosca created this revision.Feb 20 2017, 9:05 AM
Restricted Application added a project: Plasma. · View Herald TranscriptFeb 20 2017, 9:05 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript

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.

Sorry to be a noob, why does that make it broke?

why does that make it broke?

From QML side, we call:

stream.setVolume(0);
stream.setMuted(true);

and on the C++ side it turns to

// Lets say the current state of C++ object is: muted = false, vol = 20
setVolume(0) -> writeChanges(vol = 0, ..., muted = false, ...);
setMuted(true) -> writeChanges(vol = 20, ..., muted = true);

The problem is that on the C++ side, we only hold values received from pulseaudio, not intermediate values set from the QML side.

src/streamrestore.cpp
154–159

You can see here what the problem is, I forgot to add the same logic here (it doesn't use cache).

drosca updated this revision to Diff 11525.Feb 20 2017, 10:56 AM

Use cache everywhere

davidedmundson accepted this revision.Feb 21 2017, 10:27 AM

Ok, I understand the problem. Solution works.

Reading this I have an alternative proposal that might make the code simpler:

Instead of building pa_ext_stream_restore_info on the stack in ::writeChanges and building it from the arguments, can you make that a member variable and remove the arguments to writeChanges()
Then setVolume/setMute updates these member vars and calls write. If ::update also updates this member var, then you don't need any if statements in setVolume

or you can ship this.

This revision is now accepted and ready to land.Feb 21 2017, 10:27 AM

That would work too, but then we won't know which properties were actually changed in StreamRestore::update and would need to emit changed signals for all properties.

It would make the code more clean, but we would lost this optimization (even though is probably just micro-optimization at best). Because this code will not change (unless pa_ext_stream_restore_info is significantly changed, which is unlikely), it works and I don't want to rewrite it I'll ship this.

This revision was automatically updated to reflect the committed changes.