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
1=== modified file 'src/volume-control-pulse.vala'
2--- src/volume-control-pulse.vala 2015-08-07 03:11:56 +0000
3+++ src/volume-control-pulse.vala 2015-08-13 18:31:15 +0000
4@@ -52,6 +52,7 @@
5 * releasing the current active one (restoring back to the previous known role) */
6 private Gee.ArrayList<uint32> _sink_input_list = new Gee.ArrayList<uint32> ();
7 private HashMap<uint32, string> _sink_input_hash = new HashMap<uint32, string> ();
8+ private HashMap<string, PulseAudio.Volume> _role_volume_hash = new HashMap<string, PulseAudio.Volume> ();
9 private bool _pulse_use_stream_restore = false;
10 private int32 _active_sink_input = -1;
11 private string[] _valid_roles = {"multimedia", "alert", "alarm", "phone"};
12@@ -297,6 +298,46 @@
13
14 return message;
15 }
16+
17+ private async void init_role_volume(string role)
18+ {
19+ /* Listen for role volume changes from pulse itself (external clients) */
20+ try {
21+ var builder = new VariantBuilder (new VariantType ("ao"));
22+ builder.add ("o", role);
23+
24+ yield _pconn.call ("org.PulseAudio.Core1", "/org/pulseaudio/core1",
25+ "org.PulseAudio.Core1", "ListenForSignal",
26+ new Variant ("(sao)", "org.PulseAudio.Ext.StreamRestore1.RestoreEntry.VolumeUpdated", builder),
27+ null, DBusCallFlags.NONE, -1);
28+ } catch (GLib.Error e) {
29+ warning ("unable to listen for pulseaudio dbus signals (%s)", e.message);
30+ }
31+
32+ try {
33+ var props_variant = yield _pconn.call ("org.PulseAudio.Ext.StreamRestore1.RestoreEntry",
34+ role, "org.freedesktop.DBus.Properties", "Get",
35+ new Variant ("(ss)", "org.PulseAudio.Ext.StreamRestore1.RestoreEntry", "Volume"),
36+ null, DBusCallFlags.NONE, -1);
37+ Variant tmp;
38+ props_variant.get ("(v)", out tmp);
39+ uint32 type = 0, volume = 0;
40+ VariantIter iter = tmp.iterator ();
41+ iter.next ("(uu)", &type, &volume);
42+
43+ _role_volume_hash.set (role, volume);
44+ } catch (GLib.Error e) {
45+ warning ("unable to get volume for active role %s (%s)", role, e.message);
46+ }
47+ }
48+
49+ private async void init_roles_volumes()
50+ {
51+ init_role_volume(_objp_role_multimedia);
52+ init_role_volume(_objp_role_alert);
53+ init_role_volume(_objp_role_alarm);
54+ init_role_volume(_objp_role_phone);
55+ }
56
57 private async void update_active_sink_input (int32 index)
58 {
59@@ -320,18 +361,9 @@
60 }
61
62 try {
63- var props_variant = yield _pconn.call ("org.PulseAudio.Ext.StreamRestore1.RestoreEntry",
64- sink_input_objp, "org.freedesktop.DBus.Properties", "Get",
65- new Variant ("(ss)", "org.PulseAudio.Ext.StreamRestore1.RestoreEntry", "Volume"),
66- null, DBusCallFlags.NONE, -1);
67- Variant tmp;
68- props_variant.get ("(v)", out tmp);
69- uint32 type = 0, volume = 0;
70- VariantIter iter = tmp.iterator ();
71- iter.next ("(uu)", &type, &volume);
72-
73+ double volume = volume_to_double(_role_volume_hash.get (sink_input_objp));
74 var vol = new VolumeControl.Volume();
75- vol.volume = volume_to_double (volume);
76+ vol.volume = volume;
77 vol.reason = VolumeControl.VolumeReasons.VOLUME_STREAM_CHANGE;
78 this.volume = vol;
79 } catch (GLib.Error e) {
80@@ -597,6 +629,7 @@
81 null, DBusCallFlags.NONE, -1);
82
83 debug ("Set volume to %f on path %s", vol, active_role_objp);
84+ _role_volume_hash.set (active_role_objp, double_to_volume(vol));
85 } catch (GLib.Error e) {
86 lock (_pa_volume_sig_count) {
87 _pa_volume_sig_count--;
88@@ -718,6 +751,7 @@
89
90 /* Only use stream restore if every used role is available */
91 if (_objp_role_multimedia != null && _objp_role_alert != null && _objp_role_alarm != null && _objp_role_phone != null) {
92+ init_roles_volumes();
93 debug ("Using PulseAudio DBUS Stream Restore module");
94 /* Restore volume and update default entry */
95 update_active_sink_input.begin (-1);

Subscribers

People subscribed via source and target branches