Merge lp:~xavi-garcia-mena/indicator-sound/lp-1478506-use-role-volume into lp:indicator-sound/15.10

Proposed by Xavi Garcia
Status: Needs review
Proposed branch: lp:~xavi-garcia-mena/indicator-sound/lp-1478506-use-role-volume
Merge into: lp:indicator-sound/15.10
Diff against target: 95 lines (+45/-11)
1 file modified
src/volume-control-pulse.vala (+45/-11)
To merge this branch: bzr merge lp:~xavi-garcia-mena/indicator-sound/lp-1478506-use-role-volume
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Charles Kerr Pending
Review via email: mp+267985@code.launchpad.net

Commit message

Adding changes to use the current role volume instead of getting it from pulse.

Description of the change

Adding changes to use the current role volume instead of getting it from pulse.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks for working on that, I'm just curious but what's the issue with getting it from pulse? Is pulse giving a wrong information? If so why?

Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

Hi Sebastien,

At that point, and only for the "Maroon in trouble" game, I get 100% volume even it is using the multimedia role and that we had set a different volume for that role previously.
For other apps the volume obtained is correct.

I don't know if it has relation with the fact that the sounds played are very short...

I've opened a bug to see if we can get a response.

https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1485522

Unmerged revisions

501. By Xavi Garcia

Use the current role volume when addng a sink

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/volume-control-pulse.vala'
--- src/volume-control-pulse.vala 2015-08-07 03:11:56 +0000
+++ src/volume-control-pulse.vala 2015-08-13 18:31:15 +0000
@@ -52,6 +52,7 @@
52 * releasing the current active one (restoring back to the previous known role) */52 * releasing the current active one (restoring back to the previous known role) */
53 private Gee.ArrayList<uint32> _sink_input_list = new Gee.ArrayList<uint32> ();53 private Gee.ArrayList<uint32> _sink_input_list = new Gee.ArrayList<uint32> ();
54 private HashMap<uint32, string> _sink_input_hash = new HashMap<uint32, string> ();54 private HashMap<uint32, string> _sink_input_hash = new HashMap<uint32, string> ();
55 private HashMap<string, PulseAudio.Volume> _role_volume_hash = new HashMap<string, PulseAudio.Volume> ();
55 private bool _pulse_use_stream_restore = false;56 private bool _pulse_use_stream_restore = false;
56 private int32 _active_sink_input = -1;57 private int32 _active_sink_input = -1;
57 private string[] _valid_roles = {"multimedia", "alert", "alarm", "phone"};58 private string[] _valid_roles = {"multimedia", "alert", "alarm", "phone"};
@@ -297,6 +298,46 @@
297298
298 return message;299 return message;
299 }300 }
301
302 private async void init_role_volume(string role)
303 {
304 /* Listen for role volume changes from pulse itself (external clients) */
305 try {
306 var builder = new VariantBuilder (new VariantType ("ao"));
307 builder.add ("o", role);
308
309 yield _pconn.call ("org.PulseAudio.Core1", "/org/pulseaudio/core1",
310 "org.PulseAudio.Core1", "ListenForSignal",
311 new Variant ("(sao)", "org.PulseAudio.Ext.StreamRestore1.RestoreEntry.VolumeUpdated", builder),
312 null, DBusCallFlags.NONE, -1);
313 } catch (GLib.Error e) {
314 warning ("unable to listen for pulseaudio dbus signals (%s)", e.message);
315 }
316
317 try {
318 var props_variant = yield _pconn.call ("org.PulseAudio.Ext.StreamRestore1.RestoreEntry",
319 role, "org.freedesktop.DBus.Properties", "Get",
320 new Variant ("(ss)", "org.PulseAudio.Ext.StreamRestore1.RestoreEntry", "Volume"),
321 null, DBusCallFlags.NONE, -1);
322 Variant tmp;
323 props_variant.get ("(v)", out tmp);
324 uint32 type = 0, volume = 0;
325 VariantIter iter = tmp.iterator ();
326 iter.next ("(uu)", &type, &volume);
327
328 _role_volume_hash.set (role, volume);
329 } catch (GLib.Error e) {
330 warning ("unable to get volume for active role %s (%s)", role, e.message);
331 }
332 }
333
334 private async void init_roles_volumes()
335 {
336 init_role_volume(_objp_role_multimedia);
337 init_role_volume(_objp_role_alert);
338 init_role_volume(_objp_role_alarm);
339 init_role_volume(_objp_role_phone);
340 }
300341
301 private async void update_active_sink_input (int32 index)342 private async void update_active_sink_input (int32 index)
302 {343 {
@@ -320,18 +361,9 @@
320 }361 }
321362
322 try {363 try {
323 var props_variant = yield _pconn.call ("org.PulseAudio.Ext.StreamRestore1.RestoreEntry",364 double volume = volume_to_double(_role_volume_hash.get (sink_input_objp));
324 sink_input_objp, "org.freedesktop.DBus.Properties", "Get",
325 new Variant ("(ss)", "org.PulseAudio.Ext.StreamRestore1.RestoreEntry", "Volume"),
326 null, DBusCallFlags.NONE, -1);
327 Variant tmp;
328 props_variant.get ("(v)", out tmp);
329 uint32 type = 0, volume = 0;
330 VariantIter iter = tmp.iterator ();
331 iter.next ("(uu)", &type, &volume);
332
333 var vol = new VolumeControl.Volume();365 var vol = new VolumeControl.Volume();
334 vol.volume = volume_to_double (volume);366 vol.volume = volume;
335 vol.reason = VolumeControl.VolumeReasons.VOLUME_STREAM_CHANGE;367 vol.reason = VolumeControl.VolumeReasons.VOLUME_STREAM_CHANGE;
336 this.volume = vol;368 this.volume = vol;
337 } catch (GLib.Error e) {369 } catch (GLib.Error e) {
@@ -597,6 +629,7 @@
597 null, DBusCallFlags.NONE, -1);629 null, DBusCallFlags.NONE, -1);
598630
599 debug ("Set volume to %f on path %s", vol, active_role_objp);631 debug ("Set volume to %f on path %s", vol, active_role_objp);
632 _role_volume_hash.set (active_role_objp, double_to_volume(vol));
600 } catch (GLib.Error e) {633 } catch (GLib.Error e) {
601 lock (_pa_volume_sig_count) {634 lock (_pa_volume_sig_count) {
602 _pa_volume_sig_count--;635 _pa_volume_sig_count--;
@@ -718,6 +751,7 @@
718751
719 /* Only use stream restore if every used role is available */752 /* Only use stream restore if every used role is available */
720 if (_objp_role_multimedia != null && _objp_role_alert != null && _objp_role_alarm != null && _objp_role_phone != null) {753 if (_objp_role_multimedia != null && _objp_role_alert != null && _objp_role_alarm != null && _objp_role_phone != null) {
754 init_roles_volumes();
721 debug ("Using PulseAudio DBUS Stream Restore module");755 debug ("Using PulseAudio DBUS Stream Restore module");
722 /* Restore volume and update default entry */756 /* Restore volume and update default entry */
723 update_active_sink_input.begin (-1);757 update_active_sink_input.begin (-1);

Subscribers

People subscribed via source and target branches