From 707fd6c5e2d5bdfa6ff1b87f770c1d0b8e8d0894 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 11:03:41 -0600 Subject: break volume-warning into an abstract base and concrete pulse-based impl --- src/volume-warning-pulse.vala | 208 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 src/volume-warning-pulse.vala (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala new file mode 100644 index 0000000..848fd98 --- /dev/null +++ b/src/volume-warning-pulse.vala @@ -0,0 +1,208 @@ +/* + * -*- Mode:Vala; indent-tabs-mode:t; tab-width:4; encoding:utf8 -*- + * + * Copyright 2015 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +using PulseAudio; + +public class VolumeWarningPulse : VolumeWarning +{ + public VolumeWarningPulse (IndicatorSound.Options options, + PulseAudio.GLibMainLoop pgloop) { + base(options); + _pgloop = pgloop; + pulse_start(); + } + + ~VolumeWarningPulse () + { + pulse_stop(); + } + + protected override void sound_system_set_multimedia_volume(PulseAudio.Volume volume) { + pulse_set_sink_input_volume(volume); + } + + /*** + **** PulseAudio: Tracking the active multimedia sink input + ***/ + + private unowned PulseAudio.GLibMainLoop _pgloop = null; + private PulseAudio.Context _pulse_context = null; + private uint _pulse_reconnect_timer = 0; + private uint32 _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; + private uint32 _warning_sink_input_index = PulseAudio.INVALID_INDEX; + private unowned PulseAudio.CVolume _multimedia_cvolume; + + private bool is_active_multimedia (SinkInputInfo i) + { + if (i.corked != 0) + return false; + + var key = PulseAudio.Proplist.PROP_MEDIA_ROLE; + var media_role = i.proplist.gets(key); + if (media_role != "multimedia") + return false; + + return true; + } + + private void on_sink_input_info (Context c, SinkInputInfo? i, int eol) + { + if (i == null) + return; + + if (is_active_multimedia(i)) { + GLib.message("on_sink_input_info() setting multimedia index to %d, volume to %d", (int)i.index, (int)i.volume.max()); + _multimedia_sink_input_index = i.index; + _multimedia_cvolume = i.volume; + multimedia_volume = i.volume.max(); + multimedia_active = true; + } + else if (i.index == _multimedia_sink_input_index) { + _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; + multimedia_volume = PulseAudio.Volume.INVALID; + multimedia_active = false; + } + } + + private void pulse_update_sink_inputs() + { + _pulse_context.get_sink_input_info_list (on_sink_input_info); + } + + + private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index) + { + if ((t & Context.SubscriptionEventType.FACILITY_MASK) != Context.SubscriptionEventType.SINK_INPUT) + return; + + switch (t & Context.SubscriptionEventType.TYPE_MASK) + { + case Context.SubscriptionEventType.NEW: + case Context.SubscriptionEventType.CHANGE: + GLib.message("-> Context.SubscriptionEventType.CHANGE or NEW"); + c.get_sink_input_info(index, on_sink_input_info); + break; + case Context.SubscriptionEventType.REMOVE: + GLib.message("-> Context.SubscriptionEventType.REMOVE"); + pulse_update_sink_inputs(); + break; + default: + GLib.debug("Sink input event not known."); + break; + } + } + + private void pulse_context_state_callback (Context c) + { + switch (c.get_state ()) { + case Context.State.READY: + c.set_subscribe_callback (context_events_cb); + c.subscribe (PulseAudio.Context.SubscriptionMask.SINK_INPUT); + pulse_update_sink_inputs(); + break; + + case Context.State.FAILED: + case Context.State.TERMINATED: + pulse_reconnect_soon(); + break; + + default: + break; + } + } + + private void pulse_disconnect() + { + if (_pulse_context != null) { + _pulse_context.disconnect (); + _pulse_context = null; + } + } + + private void pulse_reconnect_soon () + { + if (_pulse_reconnect_timer == 0) + _pulse_reconnect_timer = Timeout.add_seconds (2, pulse_reconnect_timeout); + } + + private void pulse_reconnect_soon_cancel() + { + if (_pulse_reconnect_timer != 0) { + Source.remove(_pulse_reconnect_timer); + _pulse_reconnect_timer = 0; + } + } + + private bool pulse_reconnect_timeout () + { + _pulse_reconnect_timer = 0; + pulse_reconnect (); + return Source.REMOVE; + } + + void pulse_reconnect () + { + pulse_disconnect(); + + var props = new Proplist (); + props.sets (Proplist.PROP_APPLICATION_NAME, "Ubuntu Audio Settings"); + props.sets (Proplist.PROP_APPLICATION_ID, "com.canonical.settings.sound"); + props.sets (Proplist.PROP_APPLICATION_ICON_NAME, "multimedia-volume-control"); + props.sets (Proplist.PROP_APPLICATION_VERSION, "0.1"); + + _pulse_context = new PulseAudio.Context (_pgloop.get_api(), null, props); + _pulse_context.set_state_callback (pulse_context_state_callback); + + var server_string = Environment.get_variable("PULSE_SERVER"); + if (_pulse_context.connect(server_string, Context.Flags.NOFAIL, null) < 0) + warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(_pulse_context.errno())); + } + + void pulse_set_sink_input_volume(PulseAudio.Volume volume) + { + var index = _warning_sink_input_index; + + GLib.return_if_fail(_pulse_context != null); + GLib.return_if_fail(index != PulseAudio.INVALID_INDEX); + GLib.return_if_fail(volume != PulseAudio.Volume.INVALID); + + unowned CVolume cvol = CVolume(); + cvol.set(_multimedia_cvolume.channels, volume); + GLib.message("setting multimedia volume to %s", cvol.to_string()); + _pulse_context.set_sink_input_volume(index, cvol, null); + } + + private void pulse_start() + { + pulse_reconnect(); + } + + private void pulse_stop() + { + pulse_reconnect_soon_cancel(); + pulse_disconnect(); + } + + protected override void preshow() + { + _warning_sink_input_index = _multimedia_sink_input_index; + } +} -- cgit v1.2.3 From 64a358c9121164906e71d3c5441fc5f8453bf45e Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 11:43:17 -0600 Subject: in volume-warning-pulse, get/set the sink's volume, not the sink input's --- src/volume-warning-pulse.vala | 79 +++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 25 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 848fd98..9dabfc1 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -36,7 +36,7 @@ public class VolumeWarningPulse : VolumeWarning } protected override void sound_system_set_multimedia_volume(PulseAudio.Volume volume) { - pulse_set_sink_input_volume(volume); + pulse_set_sink_volume(volume); } /*** @@ -46,8 +46,11 @@ public class VolumeWarningPulse : VolumeWarning private unowned PulseAudio.GLibMainLoop _pgloop = null; private PulseAudio.Context _pulse_context = null; private uint _pulse_reconnect_timer = 0; + + private uint32 _warning_sink_index = PulseAudio.INVALID_INDEX; + private uint32 _multimedia_sink_index = PulseAudio.INVALID_INDEX; private uint32 _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; - private uint32 _warning_sink_input_index = PulseAudio.INVALID_INDEX; + private unowned PulseAudio.CVolume _multimedia_cvolume; private bool is_active_multimedia (SinkInputInfo i) @@ -63,19 +66,34 @@ public class VolumeWarningPulse : VolumeWarning return true; } + private void update_multimedia_volume() + { + GLib.return_if_fail(_pulse_context != null; + GLib.return_if_fail(_multimedia_sink_index != PulseAudio.INVALID_INDEX); + + GLib.message("updating multimedia volume"); + _pulse_context.get_sink_info_by_index(_multimedia_sink_index, (c,i) => { + GLib.return_if_fail(i != null); + _multimedia_cvolume = i.volume; + multimedia_volume = i.volume.max(); + }); + } + private void on_sink_input_info (Context c, SinkInputInfo? i, int eol) { if (i == null) return; if (is_active_multimedia(i)) { - GLib.message("on_sink_input_info() setting multimedia index to %d, volume to %d", (int)i.index, (int)i.volume.max()); + GLib.message("on_sink_input_info() setting multimedia sink input index to %d, sink index to %d", (int)i.index, (int)i.sink); + _multimedia_sink_index = i.sink; _multimedia_sink_input_index = i.index; - _multimedia_cvolume = i.volume; - multimedia_volume = i.volume.max(); + multimedia_volume = PulseAudio.Volume.INVALID; // don't let high-volume get set to 'true' until multimedia_volume is updated + update_multimedia_volume(); multimedia_active = true; } else if (i.index == _multimedia_sink_input_index) { + _multimedia_sink_index = PulseAudio.INVALID_INDEX; _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; multimedia_volume = PulseAudio.Volume.INVALID; multimedia_active = false; @@ -88,24 +106,34 @@ public class VolumeWarningPulse : VolumeWarning } - private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index) - { - if ((t & Context.SubscriptionEventType.FACILITY_MASK) != Context.SubscriptionEventType.SINK_INPUT) - return; - - switch (t & Context.SubscriptionEventType.TYPE_MASK) + private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index) + { + switch (t & Context.SubscriptionEventType.FACILITY_MASK) { - case Context.SubscriptionEventType.NEW: - case Context.SubscriptionEventType.CHANGE: - GLib.message("-> Context.SubscriptionEventType.CHANGE or NEW"); - c.get_sink_input_info(index, on_sink_input_info); - break; - case Context.SubscriptionEventType.REMOVE: - GLib.message("-> Context.SubscriptionEventType.REMOVE"); - pulse_update_sink_inputs(); + case Context.SubscriptionEventType.SINK: + if ((index == _multimedia_sink_index) && (index != PulseAudio.INVALID_INDEX)) + update_multimedia_volume(); break; + + case Context.SubscriptionEventType.SINK_INPUT: + switch (t & Context.SubscriptionEventType.TYPE_MASK) + { + case Context.SubscriptionEventType.NEW: + case Context.SubscriptionEventType.CHANGE: + GLib.message("-> Context.SubscriptionEventType.CHANGE or NEW"); + c.get_sink_input_info(index, on_sink_input_info); + break; + case Context.SubscriptionEventType.REMOVE: + GLib.message("-> Context.SubscriptionEventType.REMOVE"); + pulse_update_sink_inputs(); + break; + default: + GLib.debug("Sink input event not known."); + break; + } + break; + default: - GLib.debug("Sink input event not known."); break; } } @@ -115,7 +143,8 @@ public class VolumeWarningPulse : VolumeWarning switch (c.get_state ()) { case Context.State.READY: c.set_subscribe_callback (context_events_cb); - c.subscribe (PulseAudio.Context.SubscriptionMask.SINK_INPUT); + c.subscribe (PulseAudio.Context.SubscriptionMask.SINK | + PulseAudio.Context.SubscriptionMask.SINK_INPUT); pulse_update_sink_inputs(); break; @@ -176,9 +205,9 @@ public class VolumeWarningPulse : VolumeWarning warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(_pulse_context.errno())); } - void pulse_set_sink_input_volume(PulseAudio.Volume volume) + void pulse_set_sink_volume(PulseAudio.Volume volume) { - var index = _warning_sink_input_index; + var index = _warning_sink_index; GLib.return_if_fail(_pulse_context != null); GLib.return_if_fail(index != PulseAudio.INVALID_INDEX); @@ -187,7 +216,7 @@ public class VolumeWarningPulse : VolumeWarning unowned CVolume cvol = CVolume(); cvol.set(_multimedia_cvolume.channels, volume); GLib.message("setting multimedia volume to %s", cvol.to_string()); - _pulse_context.set_sink_input_volume(index, cvol, null); + _pulse_context.set_sink_volume_by_index(index, cvol); } private void pulse_start() @@ -203,6 +232,6 @@ public class VolumeWarningPulse : VolumeWarning protected override void preshow() { - _warning_sink_input_index = _multimedia_sink_input_index; + _warning_sink_index = _multimedia_sink_index; } } -- cgit v1.2.3 From f2fc1297ac47b5885ba3b875b9a4e188f12d68a2 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 12:02:14 -0600 Subject: fix oops in last commit --- src/volume-warning-pulse.vala | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 9dabfc1..9be2359 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -68,10 +68,11 @@ public class VolumeWarningPulse : VolumeWarning private void update_multimedia_volume() { - GLib.return_if_fail(_pulse_context != null; + GLib.return_if_fail(_pulse_context != null); GLib.return_if_fail(_multimedia_sink_index != PulseAudio.INVALID_INDEX); GLib.message("updating multimedia volume"); + _pulse_context.get_sink_info_by_index(_multimedia_sink_index, (c,i) => { GLib.return_if_fail(i != null); _multimedia_cvolume = i.volume; @@ -79,6 +80,21 @@ public class VolumeWarningPulse : VolumeWarning }); } + private void set_multimedia_sink_index(uint32 index) + { + if (index == PulseAudio.INVALID_INDEX) + { + _multimedia_sink_index = PulseAudio.INVALID_INDEX; + multimedia_volume = PulseAudio.Volume.INVALID; + } + else if (_multimedia_sink_index != index) + { + _multimedia_sink_index = index; + multimedia_volume = PulseAudio.Volume.INVALID; + update_multimedia_volume(); + } + } + private void on_sink_input_info (Context c, SinkInputInfo? i, int eol) { if (i == null) @@ -86,16 +102,13 @@ public class VolumeWarningPulse : VolumeWarning if (is_active_multimedia(i)) { GLib.message("on_sink_input_info() setting multimedia sink input index to %d, sink index to %d", (int)i.index, (int)i.sink); - _multimedia_sink_index = i.sink; _multimedia_sink_input_index = i.index; - multimedia_volume = PulseAudio.Volume.INVALID; // don't let high-volume get set to 'true' until multimedia_volume is updated - update_multimedia_volume(); + set_multimedia_sink_index(i.sink); multimedia_active = true; } else if (i.index == _multimedia_sink_input_index) { - _multimedia_sink_index = PulseAudio.INVALID_INDEX; _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; - multimedia_volume = PulseAudio.Volume.INVALID; + set_multimedia_sink_index(PulseAudio.INVALID_INDEX); multimedia_active = false; } } -- cgit v1.2.3 From 902abad6836c6de2411d7514f36a106eee9444ed Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 13:06:58 -0600 Subject: copyediting: use vala whitespace style in new code --- src/volume-warning-pulse.vala | 116 +++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 70 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 9be2359..335c8bf 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -26,16 +26,17 @@ public class VolumeWarningPulse : VolumeWarning public VolumeWarningPulse (IndicatorSound.Options options, PulseAudio.GLibMainLoop pgloop) { base(options); + _pgloop = pgloop; - pulse_start(); + pulse_reconnect(); } - ~VolumeWarningPulse () - { - pulse_stop(); + ~VolumeWarningPulse () { + pulse_reconnect_soon_cancel(); + pulse_disconnect(); } - protected override void sound_system_set_multimedia_volume(PulseAudio.Volume volume) { + protected override void sound_system_set_multimedia_volume (PulseAudio.Volume volume) { pulse_set_sink_volume(volume); } @@ -53,8 +54,8 @@ public class VolumeWarningPulse : VolumeWarning private unowned PulseAudio.CVolume _multimedia_cvolume; - private bool is_active_multimedia (SinkInputInfo i) - { + private bool is_active_multimedia (SinkInputInfo i) { + if (i.corked != 0) return false; @@ -66,61 +67,55 @@ public class VolumeWarningPulse : VolumeWarning return true; } - private void update_multimedia_volume() - { + private void update_multimedia_volume () { + GLib.return_if_fail(_pulse_context != null); GLib.return_if_fail(_multimedia_sink_index != PulseAudio.INVALID_INDEX); - GLib.message("updating multimedia volume"); - _pulse_context.get_sink_info_by_index(_multimedia_sink_index, (c,i) => { GLib.return_if_fail(i != null); + GLib.message("setting multimedia_volume to %s", i.volume.to_string()); _multimedia_cvolume = i.volume; multimedia_volume = i.volume.max(); }); } - private void set_multimedia_sink_index(uint32 index) - { - if (index == PulseAudio.INVALID_INDEX) - { + private void set_multimedia_sink_index(uint32 index) { + + if (index == PulseAudio.INVALID_INDEX) { _multimedia_sink_index = PulseAudio.INVALID_INDEX; multimedia_volume = PulseAudio.Volume.INVALID; - } - else if (_multimedia_sink_index != index) - { + } else if (_multimedia_sink_index != index) { _multimedia_sink_index = index; multimedia_volume = PulseAudio.Volume.INVALID; update_multimedia_volume(); } } - private void on_sink_input_info (Context c, SinkInputInfo? i, int eol) - { + private void on_sink_input_info (Context c, SinkInputInfo? i, int eol) { + if (i == null) return; - if (is_active_multimedia(i)) { - GLib.message("on_sink_input_info() setting multimedia sink input index to %d, sink index to %d", (int)i.index, (int)i.sink); + if (is_active_multimedia (i)) { + GLib.message ("on_sink_input_info() setting multimedia sink input index to %d, sink index to %d", (int)i.index, (int)i.sink); _multimedia_sink_input_index = i.index; - set_multimedia_sink_index(i.sink); + set_multimedia_sink_index (i.sink); multimedia_active = true; } else if (i.index == _multimedia_sink_input_index) { _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; - set_multimedia_sink_index(PulseAudio.INVALID_INDEX); + set_multimedia_sink_index (PulseAudio.INVALID_INDEX); multimedia_active = false; } } - private void pulse_update_sink_inputs() - { + private void pulse_update_sink_inputs () { _pulse_context.get_sink_input_info_list (on_sink_input_info); } - private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index) - { + private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index) { switch (t & Context.SubscriptionEventType.FACILITY_MASK) { case Context.SubscriptionEventType.SINK: @@ -133,15 +128,15 @@ public class VolumeWarningPulse : VolumeWarning { case Context.SubscriptionEventType.NEW: case Context.SubscriptionEventType.CHANGE: - GLib.message("-> Context.SubscriptionEventType.CHANGE or NEW"); - c.get_sink_input_info(index, on_sink_input_info); + GLib.message ("-> Context.SubscriptionEventType.CHANGE or NEW"); + c.get_sink_input_info (index, on_sink_input_info); break; case Context.SubscriptionEventType.REMOVE: - GLib.message("-> Context.SubscriptionEventType.REMOVE"); - pulse_update_sink_inputs(); + GLib.message ("-> Context.SubscriptionEventType.REMOVE"); + pulse_update_sink_inputs (); break; default: - GLib.debug("Sink input event not known."); + GLib.debug ("Sink input event not known."); break; } break; @@ -151,19 +146,18 @@ public class VolumeWarningPulse : VolumeWarning } } - private void pulse_context_state_callback (Context c) - { + private void pulse_context_state_callback (Context c) { switch (c.get_state ()) { case Context.State.READY: c.set_subscribe_callback (context_events_cb); c.subscribe (PulseAudio.Context.SubscriptionMask.SINK | PulseAudio.Context.SubscriptionMask.SINK_INPUT); - pulse_update_sink_inputs(); + pulse_update_sink_inputs (); break; case Context.State.FAILED: case Context.State.TERMINATED: - pulse_reconnect_soon(); + pulse_reconnect_soon (); break; default: @@ -171,37 +165,32 @@ public class VolumeWarningPulse : VolumeWarning } } - private void pulse_disconnect() - { + private void pulse_disconnect () { if (_pulse_context != null) { _pulse_context.disconnect (); _pulse_context = null; } } - private void pulse_reconnect_soon () - { + private void pulse_reconnect_soon () { if (_pulse_reconnect_timer == 0) _pulse_reconnect_timer = Timeout.add_seconds (2, pulse_reconnect_timeout); } - private void pulse_reconnect_soon_cancel() - { + private void pulse_reconnect_soon_cancel () { if (_pulse_reconnect_timer != 0) { - Source.remove(_pulse_reconnect_timer); + Source.remove (_pulse_reconnect_timer); _pulse_reconnect_timer = 0; } } - private bool pulse_reconnect_timeout () - { + private bool pulse_reconnect_timeout () { _pulse_reconnect_timer = 0; pulse_reconnect (); return Source.REMOVE; } - void pulse_reconnect () - { + void pulse_reconnect () { pulse_disconnect(); var props = new Proplist (); @@ -213,38 +202,25 @@ public class VolumeWarningPulse : VolumeWarning _pulse_context = new PulseAudio.Context (_pgloop.get_api(), null, props); _pulse_context.set_state_callback (pulse_context_state_callback); - var server_string = Environment.get_variable("PULSE_SERVER"); - if (_pulse_context.connect(server_string, Context.Flags.NOFAIL, null) < 0) - warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(_pulse_context.errno())); + var server_string = Environment.get_variable ("PULSE_SERVER"); + if (_pulse_context.connect (server_string, Context.Flags.NOFAIL, null) < 0) + GLib.warning ("pa_context_connect() failed: %s\n", PulseAudio.strerror(_pulse_context.errno())); } - void pulse_set_sink_volume(PulseAudio.Volume volume) - { + void pulse_set_sink_volume (PulseAudio.Volume volume) { var index = _warning_sink_index; GLib.return_if_fail(_pulse_context != null); GLib.return_if_fail(index != PulseAudio.INVALID_INDEX); GLib.return_if_fail(volume != PulseAudio.Volume.INVALID); - unowned CVolume cvol = CVolume(); - cvol.set(_multimedia_cvolume.channels, volume); - GLib.message("setting multimedia volume to %s", cvol.to_string()); - _pulse_context.set_sink_volume_by_index(index, cvol); - } - - private void pulse_start() - { - pulse_reconnect(); - } - - private void pulse_stop() - { - pulse_reconnect_soon_cancel(); - pulse_disconnect(); + unowned CVolume cvol = CVolume (); + cvol.set (_multimedia_cvolume.channels, volume); + GLib.message ("setting multimedia volume to %s", cvol.to_string()); + _pulse_context.set_sink_volume_by_index (index, cvol); } - protected override void preshow() - { + protected override void preshow () { _warning_sink_index = _multimedia_sink_index; } } -- cgit v1.2.3 From 0463874601bf826dcd5b976d928e2d53c9517f94 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 13:40:08 -0600 Subject: silence spurious g_warning --- src/volume-warning-pulse.vala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 335c8bf..918595b 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -73,10 +73,11 @@ public class VolumeWarningPulse : VolumeWarning GLib.return_if_fail(_multimedia_sink_index != PulseAudio.INVALID_INDEX); _pulse_context.get_sink_info_by_index(_multimedia_sink_index, (c,i) => { - GLib.return_if_fail(i != null); - GLib.message("setting multimedia_volume to %s", i.volume.to_string()); - _multimedia_cvolume = i.volume; - multimedia_volume = i.volume.max(); + if (i != null) { + GLib.message("setting multimedia_volume to %s", i.volume.to_string()); + _multimedia_cvolume = i.volume; + multimedia_volume = i.volume.max(); + } }); } -- cgit v1.2.3 From a018f6a52faf34212e719772cc45bfbfc4b21daa Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 14:16:16 -0600 Subject: dampen Pulse floods in vol-warning by requerying no more than once per sec --- src/volume-warning-pulse.vala | 87 ++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 26 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 918595b..8314202 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -32,7 +32,9 @@ public class VolumeWarningPulse : VolumeWarning } ~VolumeWarningPulse () { - pulse_reconnect_soon_cancel(); + clear_timer(ref _pulse_reconnect_timer); + clear_timer(ref _update_sink_timer); + clear_timer(ref _update_sink_inputs_timer); pulse_disconnect(); } @@ -47,6 +49,10 @@ public class VolumeWarningPulse : VolumeWarning private unowned PulseAudio.GLibMainLoop _pgloop = null; private PulseAudio.Context _pulse_context = null; private uint _pulse_reconnect_timer = 0; + private uint _update_sink_timer = 0; + private uint _update_sink_inputs_timer = 0; + private GenericSet _pending_sink_inputs = new GenericSet(int_hash, int_equal); + private uint32 _warning_sink_index = PulseAudio.INVALID_INDEX; private uint32 _multimedia_sink_index = PulseAudio.INVALID_INDEX; @@ -54,18 +60,7 @@ public class VolumeWarningPulse : VolumeWarning private unowned PulseAudio.CVolume _multimedia_cvolume; - private bool is_active_multimedia (SinkInputInfo i) { - - if (i.corked != 0) - return false; - - var key = PulseAudio.Proplist.PROP_MEDIA_ROLE; - var media_role = i.proplist.gets(key); - if (media_role != "multimedia") - return false; - - return true; - } + /***/ private void update_multimedia_volume () { @@ -81,6 +76,18 @@ public class VolumeWarningPulse : VolumeWarning }); } + private void update_multimedia_volume_soon () { + + GLib.message("updating multimedia volume soon"); + if (_update_sink_timer == 0) { + _update_sink_timer = Timeout.add_seconds (1, () => { + _update_sink_timer = 0; + update_multimedia_volume (); + return Source.REMOVE; + }); + } + } + private void set_multimedia_sink_index(uint32 index) { if (index == PulseAudio.INVALID_INDEX) { @@ -89,10 +96,25 @@ public class VolumeWarningPulse : VolumeWarning } else if (_multimedia_sink_index != index) { _multimedia_sink_index = index; multimedia_volume = PulseAudio.Volume.INVALID; - update_multimedia_volume(); + update_multimedia_volume_soon(); } } + /***/ + + private bool is_active_multimedia (SinkInputInfo i) { + + if (i.corked != 0) + return false; + + var key = PulseAudio.Proplist.PROP_MEDIA_ROLE; + var media_role = i.proplist.gets(key); + if (media_role != "multimedia") + return false; + + return true; + } + private void on_sink_input_info (Context c, SinkInputInfo? i, int eol) { if (i == null) @@ -111,17 +133,37 @@ public class VolumeWarningPulse : VolumeWarning } } - private void pulse_update_sink_inputs () { + private void update_all_sink_inputs () { _pulse_context.get_sink_input_info_list (on_sink_input_info); } + private void update_sink_input (uint32 index) { + _pulse_context.get_sink_input_info (index, on_sink_input_info); + } + private void update_sink_input_soon (uint32 index) { + + GLib.message("adding %d to queue", (int)index); + _pending_sink_inputs.add(index); + + if (_update_sink_inputs_timer == 0) { + _update_sink_inputs_timer = Timeout.add_seconds (1, () => { + _pending_sink_inputs.foreach((i) => { + GLib.message("flushing input sink queue: index %d", (int)i); + update_sink_input(i); + }); + _pending_sink_inputs.remove_all(); + _update_sink_inputs_timer = 0; + return Source.REMOVE; + }); + } + } private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index) { switch (t & Context.SubscriptionEventType.FACILITY_MASK) { case Context.SubscriptionEventType.SINK: if ((index == _multimedia_sink_index) && (index != PulseAudio.INVALID_INDEX)) - update_multimedia_volume(); + update_multimedia_volume_soon(); break; case Context.SubscriptionEventType.SINK_INPUT: @@ -130,11 +172,11 @@ public class VolumeWarningPulse : VolumeWarning case Context.SubscriptionEventType.NEW: case Context.SubscriptionEventType.CHANGE: GLib.message ("-> Context.SubscriptionEventType.CHANGE or NEW"); - c.get_sink_input_info (index, on_sink_input_info); + update_sink_input_soon(index); break; case Context.SubscriptionEventType.REMOVE: GLib.message ("-> Context.SubscriptionEventType.REMOVE"); - pulse_update_sink_inputs (); + update_all_sink_inputs (); break; default: GLib.debug ("Sink input event not known."); @@ -153,7 +195,7 @@ public class VolumeWarningPulse : VolumeWarning c.set_subscribe_callback (context_events_cb); c.subscribe (PulseAudio.Context.SubscriptionMask.SINK | PulseAudio.Context.SubscriptionMask.SINK_INPUT); - pulse_update_sink_inputs (); + update_all_sink_inputs (); break; case Context.State.FAILED: @@ -178,13 +220,6 @@ public class VolumeWarningPulse : VolumeWarning _pulse_reconnect_timer = Timeout.add_seconds (2, pulse_reconnect_timeout); } - private void pulse_reconnect_soon_cancel () { - if (_pulse_reconnect_timer != 0) { - Source.remove (_pulse_reconnect_timer); - _pulse_reconnect_timer = 0; - } - } - private bool pulse_reconnect_timeout () { _pulse_reconnect_timer = 0; pulse_reconnect (); -- cgit v1.2.3 From 741c2fe564453cbb9a4d9c3acd2ba937e0da67ac Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 14:46:57 -0600 Subject: fix hashset construction error from previous commit --- src/volume-warning-pulse.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 8314202..0d6800a 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -51,7 +51,7 @@ public class VolumeWarningPulse : VolumeWarning private uint _pulse_reconnect_timer = 0; private uint _update_sink_timer = 0; private uint _update_sink_inputs_timer = 0; - private GenericSet _pending_sink_inputs = new GenericSet(int_hash, int_equal); + private GenericSet _pending_sink_inputs = new GenericSet(direct_hash, direct_equal); private uint32 _warning_sink_index = PulseAudio.INVALID_INDEX; -- cgit v1.2.3 From 6b6fdbe3fbc87bc6dfe6398314582faa2677e382 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 15:02:49 -0600 Subject: in volume-warning, shorten the Pulse flood damper's timer one second is too long in practice; shortening to 500 msec --- src/volume-warning-pulse.vala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 0d6800a..e42d59c 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -53,6 +53,7 @@ public class VolumeWarningPulse : VolumeWarning private uint _update_sink_inputs_timer = 0; private GenericSet _pending_sink_inputs = new GenericSet(direct_hash, direct_equal); + private uint soon_interval_msec = 500; private uint32 _warning_sink_index = PulseAudio.INVALID_INDEX; private uint32 _multimedia_sink_index = PulseAudio.INVALID_INDEX; @@ -80,7 +81,7 @@ public class VolumeWarningPulse : VolumeWarning GLib.message("updating multimedia volume soon"); if (_update_sink_timer == 0) { - _update_sink_timer = Timeout.add_seconds (1, () => { + _update_sink_timer = Timeout.add (soon_interval_msec, () => { _update_sink_timer = 0; update_multimedia_volume (); return Source.REMOVE; @@ -146,7 +147,7 @@ public class VolumeWarningPulse : VolumeWarning _pending_sink_inputs.add(index); if (_update_sink_inputs_timer == 0) { - _update_sink_inputs_timer = Timeout.add_seconds (1, () => { + _update_sink_inputs_timer = Timeout.add_seconds (soon_interval_msec, () => { _pending_sink_inputs.foreach((i) => { GLib.message("flushing input sink queue: index %d", (int)i); update_sink_input(i); -- cgit v1.2.3 From ac20336e0f1990e7cf1ee8074d9c1a6143c042e4 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 15:25:00 -0600 Subject: fix tyop --- src/volume-warning-pulse.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index e42d59c..6451cc5 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -147,7 +147,7 @@ public class VolumeWarningPulse : VolumeWarning _pending_sink_inputs.add(index); if (_update_sink_inputs_timer == 0) { - _update_sink_inputs_timer = Timeout.add_seconds (soon_interval_msec, () => { + _update_sink_inputs_timer = Timeout.add (soon_interval_msec, () => { _pending_sink_inputs.foreach((i) => { GLib.message("flushing input sink queue: index %d", (int)i); update_sink_input(i); -- cgit v1.2.3 From 66f5198878b8a244f8bd967074480821be43c69e Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 15:58:45 -0600 Subject: generate less pulse traffic on a sink-input-removed event --- src/volume-warning-pulse.vala | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 6451cc5..09b96d1 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -116,6 +116,12 @@ public class VolumeWarningPulse : VolumeWarning return true; } + private void clear_multimedia () { + _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; + set_multimedia_sink_index (PulseAudio.INVALID_INDEX); + multimedia_active = false; + } + private void on_sink_input_info (Context c, SinkInputInfo? i, int eol) { if (i == null) @@ -128,9 +134,7 @@ public class VolumeWarningPulse : VolumeWarning multimedia_active = true; } else if (i.index == _multimedia_sink_input_index) { - _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; - set_multimedia_sink_index (PulseAudio.INVALID_INDEX); - multimedia_active = false; + clear_multimedia(); } } @@ -163,6 +167,8 @@ public class VolumeWarningPulse : VolumeWarning switch (t & Context.SubscriptionEventType.FACILITY_MASK) { case Context.SubscriptionEventType.SINK: + // if something happens to the sink connected to our mm sink input, + // get its updated info to keep our multimedia volume up-to-date if ((index == _multimedia_sink_index) && (index != PulseAudio.INVALID_INDEX)) update_multimedia_volume_soon(); break; @@ -170,15 +176,23 @@ public class VolumeWarningPulse : VolumeWarning case Context.SubscriptionEventType.SINK_INPUT: switch (t & Context.SubscriptionEventType.TYPE_MASK) { + // if a SinkInput changed, get its updated info + // to keep our multimedia indices up-to-date case Context.SubscriptionEventType.NEW: case Context.SubscriptionEventType.CHANGE: GLib.message ("-> Context.SubscriptionEventType.CHANGE or NEW"); update_sink_input_soon(index); break; + + // if the multimedia sink input was removed, + // reset our mm fields and look for a new mm sink input case Context.SubscriptionEventType.REMOVE: - GLib.message ("-> Context.SubscriptionEventType.REMOVE"); - update_all_sink_inputs (); + if (index == _multimedia_sink_input_index) { + clear_multimedia(); + update_all_sink_inputs (); + } break; + default: GLib.debug ("Sink input event not known."); break; @@ -217,14 +231,13 @@ public class VolumeWarningPulse : VolumeWarning } private void pulse_reconnect_soon () { - if (_pulse_reconnect_timer == 0) - _pulse_reconnect_timer = Timeout.add_seconds (2, pulse_reconnect_timeout); - } - - private bool pulse_reconnect_timeout () { - _pulse_reconnect_timer = 0; - pulse_reconnect (); - return Source.REMOVE; + if (_pulse_reconnect_timer == 0) { + _pulse_reconnect_timer = Timeout.add_seconds (2, () => { + _pulse_reconnect_timer = 0; + pulse_reconnect(); + return Source.REMOVE; + }); + } } void pulse_reconnect () { -- cgit v1.2.3 From 637af434c801d6be5909441217b66afd03f0dcc0 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 16:15:01 -0600 Subject: tidy up vol-warning-pulse's override methods --- src/volume-warning-pulse.vala | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 09b96d1..5b6b632 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -39,9 +39,22 @@ public class VolumeWarningPulse : VolumeWarning } protected override void sound_system_set_multimedia_volume (PulseAudio.Volume volume) { - pulse_set_sink_volume(volume); + var index = _warning_sink_index; + + GLib.return_if_fail(_pulse_context != null); + GLib.return_if_fail(index != PulseAudio.INVALID_INDEX); + GLib.return_if_fail(volume != PulseAudio.Volume.INVALID); + + unowned CVolume cvol = CVolume (); + cvol.set (_multimedia_cvolume.channels, volume); + GLib.message ("setting multimedia volume to %s", cvol.to_string()); + _pulse_context.set_sink_volume_by_index (index, cvol); } + protected override void preshow () { + _warning_sink_index = _multimedia_sink_index; + } + /*** **** PulseAudio: Tracking the active multimedia sink input ***/ @@ -256,21 +269,4 @@ public class VolumeWarningPulse : VolumeWarning if (_pulse_context.connect (server_string, Context.Flags.NOFAIL, null) < 0) GLib.warning ("pa_context_connect() failed: %s\n", PulseAudio.strerror(_pulse_context.errno())); } - - void pulse_set_sink_volume (PulseAudio.Volume volume) { - var index = _warning_sink_index; - - GLib.return_if_fail(_pulse_context != null); - GLib.return_if_fail(index != PulseAudio.INVALID_INDEX); - GLib.return_if_fail(volume != PulseAudio.Volume.INVALID); - - unowned CVolume cvol = CVolume (); - cvol.set (_multimedia_cvolume.channels, volume); - GLib.message ("setting multimedia volume to %s", cvol.to_string()); - _pulse_context.set_sink_volume_by_index (index, cvol); - } - - protected override void preshow () { - _warning_sink_index = _multimedia_sink_index; - } } -- cgit v1.2.3 From c7796f4ddfe0b11ecb76853ba5dca17748c725c1 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 16:16:13 -0600 Subject: remove unnecessary field vol-warning-pulse.multimedia_cvolume --- src/volume-warning-pulse.vala | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 5b6b632..14b3e71 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -46,7 +46,7 @@ public class VolumeWarningPulse : VolumeWarning GLib.return_if_fail(volume != PulseAudio.Volume.INVALID); unowned CVolume cvol = CVolume (); - cvol.set (_multimedia_cvolume.channels, volume); + cvol.set (1, volume); GLib.message ("setting multimedia volume to %s", cvol.to_string()); _pulse_context.set_sink_volume_by_index (index, cvol); } @@ -72,8 +72,6 @@ public class VolumeWarningPulse : VolumeWarning private uint32 _multimedia_sink_index = PulseAudio.INVALID_INDEX; private uint32 _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; - private unowned PulseAudio.CVolume _multimedia_cvolume; - /***/ private void update_multimedia_volume () { @@ -82,11 +80,8 @@ public class VolumeWarningPulse : VolumeWarning GLib.return_if_fail(_multimedia_sink_index != PulseAudio.INVALID_INDEX); _pulse_context.get_sink_info_by_index(_multimedia_sink_index, (c,i) => { - if (i != null) { - GLib.message("setting multimedia_volume to %s", i.volume.to_string()); - _multimedia_cvolume = i.volume; + if (i != null) multimedia_volume = i.volume.max(); - } }); } -- cgit v1.2.3 From 4887db8e4409fa6e83c4ab2b1d5e5429a6956980 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 16:21:25 -0600 Subject: clean up tracer GLib.message() calls --- src/volume-warning-pulse.vala | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 14b3e71..e6e6f21 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -87,7 +87,6 @@ public class VolumeWarningPulse : VolumeWarning private void update_multimedia_volume_soon () { - GLib.message("updating multimedia volume soon"); if (_update_sink_timer == 0) { _update_sink_timer = Timeout.add (soon_interval_msec, () => { _update_sink_timer = 0; @@ -155,15 +154,11 @@ public class VolumeWarningPulse : VolumeWarning private void update_sink_input_soon (uint32 index) { - GLib.message("adding %d to queue", (int)index); _pending_sink_inputs.add(index); if (_update_sink_inputs_timer == 0) { _update_sink_inputs_timer = Timeout.add (soon_interval_msec, () => { - _pending_sink_inputs.foreach((i) => { - GLib.message("flushing input sink queue: index %d", (int)i); - update_sink_input(i); - }); + _pending_sink_inputs.foreach((i) => update_sink_input(i)); _pending_sink_inputs.remove_all(); _update_sink_inputs_timer = 0; return Source.REMOVE; @@ -188,7 +183,6 @@ public class VolumeWarningPulse : VolumeWarning // to keep our multimedia indices up-to-date case Context.SubscriptionEventType.NEW: case Context.SubscriptionEventType.CHANGE: - GLib.message ("-> Context.SubscriptionEventType.CHANGE or NEW"); update_sink_input_soon(index); break; -- cgit v1.2.3 From 7a64a24d4d9a8749b4cccfc6e50d8dc2ce94dc02 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Tue, 29 Dec 2015 16:27:32 -0600 Subject: add docs/comments to vol-warning-pulse --- src/volume-warning-pulse.vala | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index e6e6f21..e7b7585 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -21,6 +21,11 @@ using PulseAudio; +/** + * A VolumeWarning that uses PulseAudio to + * (a) implement sound_system_set_multimedia_volume() and + * (b) keep the multimedia_active and multimedia_volume properties up-to-date + */ public class VolumeWarningPulse : VolumeWarning { public VolumeWarningPulse (IndicatorSound.Options options, @@ -38,12 +43,18 @@ public class VolumeWarningPulse : VolumeWarning pulse_disconnect(); } + protected override void preshow () { + /* showing the dialog can change the sink input index (bug #1484589) + * so cache it here for later use in sound_system_set_multimedia_volume() */ + _target_sink_index = _multimedia_sink_index; + } + protected override void sound_system_set_multimedia_volume (PulseAudio.Volume volume) { - var index = _warning_sink_index; + var index = _target_sink_index; - GLib.return_if_fail(_pulse_context != null); - GLib.return_if_fail(index != PulseAudio.INVALID_INDEX); - GLib.return_if_fail(volume != PulseAudio.Volume.INVALID); + GLib.return_if_fail (_pulse_context != null); + GLib.return_if_fail (index != PulseAudio.INVALID_INDEX); + GLib.return_if_fail (volume != PulseAudio.Volume.INVALID); unowned CVolume cvol = CVolume (); cvol.set (1, volume); @@ -51,10 +62,6 @@ public class VolumeWarningPulse : VolumeWarning _pulse_context.set_sink_volume_by_index (index, cvol); } - protected override void preshow () { - _warning_sink_index = _multimedia_sink_index; - } - /*** **** PulseAudio: Tracking the active multimedia sink input ***/ @@ -68,7 +75,7 @@ public class VolumeWarningPulse : VolumeWarning private uint soon_interval_msec = 500; - private uint32 _warning_sink_index = PulseAudio.INVALID_INDEX; + private uint32 _target_sink_index = PulseAudio.INVALID_INDEX; private uint32 _multimedia_sink_index = PulseAudio.INVALID_INDEX; private uint32 _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; -- cgit v1.2.3 From 49bd2eb793b65f4458af05ac75aff0d0cdfd8f5c Mon Sep 17 00:00:00 2001 From: charles kerr Date: Thu, 31 Dec 2015 11:28:25 -0600 Subject: copyediting: yet more whitespace --- src/volume-warning-pulse.vala | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index e7b7585..9e0664c 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -30,17 +30,17 @@ public class VolumeWarningPulse : VolumeWarning { public VolumeWarningPulse (IndicatorSound.Options options, PulseAudio.GLibMainLoop pgloop) { - base(options); + base (options); _pgloop = pgloop; - pulse_reconnect(); + pulse_reconnect (); } ~VolumeWarningPulse () { - clear_timer(ref _pulse_reconnect_timer); - clear_timer(ref _update_sink_timer); - clear_timer(ref _update_sink_inputs_timer); - pulse_disconnect(); + clear_timer (ref _pulse_reconnect_timer); + clear_timer (ref _update_sink_timer); + clear_timer (ref _update_sink_inputs_timer); + pulse_disconnect (); } protected override void preshow () { @@ -52,13 +52,13 @@ public class VolumeWarningPulse : VolumeWarning protected override void sound_system_set_multimedia_volume (PulseAudio.Volume volume) { var index = _target_sink_index; - GLib.return_if_fail (_pulse_context != null); - GLib.return_if_fail (index != PulseAudio.INVALID_INDEX); - GLib.return_if_fail (volume != PulseAudio.Volume.INVALID); + return_if_fail (_pulse_context != null); + return_if_fail (index != PulseAudio.INVALID_INDEX); + return_if_fail (volume != PulseAudio.Volume.INVALID); unowned CVolume cvol = CVolume (); cvol.set (1, volume); - GLib.message ("setting multimedia volume to %s", cvol.to_string()); + debug ("setting multimedia volume to %s", cvol.to_string ()); _pulse_context.set_sink_volume_by_index (index, cvol); } @@ -83,12 +83,12 @@ public class VolumeWarningPulse : VolumeWarning private void update_multimedia_volume () { - GLib.return_if_fail(_pulse_context != null); - GLib.return_if_fail(_multimedia_sink_index != PulseAudio.INVALID_INDEX); + return_if_fail (_pulse_context != null); + return_if_fail (_multimedia_sink_index != PulseAudio.INVALID_INDEX); - _pulse_context.get_sink_info_by_index(_multimedia_sink_index, (c,i) => { + _pulse_context.get_sink_info_by_index (_multimedia_sink_index, (c,i) => { if (i != null) - multimedia_volume = i.volume.max(); + multimedia_volume = i.volume.max (); }); } @@ -103,7 +103,7 @@ public class VolumeWarningPulse : VolumeWarning } } - private void set_multimedia_sink_index(uint32 index) { + private void set_multimedia_sink_index (uint32 index) { if (index == PulseAudio.INVALID_INDEX) { _multimedia_sink_index = PulseAudio.INVALID_INDEX; @@ -111,7 +111,7 @@ public class VolumeWarningPulse : VolumeWarning } else if (_multimedia_sink_index != index) { _multimedia_sink_index = index; multimedia_volume = PulseAudio.Volume.INVALID; - update_multimedia_volume_soon(); + update_multimedia_volume_soon (); } } @@ -123,7 +123,7 @@ public class VolumeWarningPulse : VolumeWarning return false; var key = PulseAudio.Proplist.PROP_MEDIA_ROLE; - var media_role = i.proplist.gets(key); + var media_role = i.proplist.gets (key); if (media_role != "multimedia") return false; @@ -148,7 +148,7 @@ public class VolumeWarningPulse : VolumeWarning multimedia_active = true; } else if (i.index == _multimedia_sink_input_index) { - clear_multimedia(); + clear_multimedia (); } } @@ -161,12 +161,12 @@ public class VolumeWarningPulse : VolumeWarning private void update_sink_input_soon (uint32 index) { - _pending_sink_inputs.add(index); + _pending_sink_inputs.add (index); if (_update_sink_inputs_timer == 0) { _update_sink_inputs_timer = Timeout.add (soon_interval_msec, () => { - _pending_sink_inputs.foreach((i) => update_sink_input(i)); - _pending_sink_inputs.remove_all(); + _pending_sink_inputs.foreach ((i) => update_sink_input (i)); + _pending_sink_inputs.remove_all (); _update_sink_inputs_timer = 0; return Source.REMOVE; }); @@ -190,14 +190,14 @@ public class VolumeWarningPulse : VolumeWarning // to keep our multimedia indices up-to-date case Context.SubscriptionEventType.NEW: case Context.SubscriptionEventType.CHANGE: - update_sink_input_soon(index); + update_sink_input_soon (index); break; // if the multimedia sink input was removed, // reset our mm fields and look for a new mm sink input case Context.SubscriptionEventType.REMOVE: if (index == _multimedia_sink_input_index) { - clear_multimedia(); + clear_multimedia (); update_all_sink_inputs (); } break; @@ -243,14 +243,14 @@ public class VolumeWarningPulse : VolumeWarning if (_pulse_reconnect_timer == 0) { _pulse_reconnect_timer = Timeout.add_seconds (2, () => { _pulse_reconnect_timer = 0; - pulse_reconnect(); + pulse_reconnect (); return Source.REMOVE; }); } } void pulse_reconnect () { - pulse_disconnect(); + pulse_disconnect (); var props = new Proplist (); props.sets (Proplist.PROP_APPLICATION_NAME, "Ubuntu Audio Settings"); -- cgit v1.2.3 From cbdeea528675b55b634aa9b15f94e64d36c99924 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Thu, 31 Dec 2015 13:05:06 -0600 Subject: simplify some code in volume-warning and volume-warning-pulse --- src/volume-warning-pulse.vala | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 9e0664c..c0a1b1a 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -39,7 +39,7 @@ public class VolumeWarningPulse : VolumeWarning ~VolumeWarningPulse () { clear_timer (ref _pulse_reconnect_timer); clear_timer (ref _update_sink_timer); - clear_timer (ref _update_sink_inputs_timer); + clear_timer (ref _pending_sink_inputs_timer); pulse_disconnect (); } @@ -62,15 +62,11 @@ public class VolumeWarningPulse : VolumeWarning _pulse_context.set_sink_volume_by_index (index, cvol); } - /*** - **** PulseAudio: Tracking the active multimedia sink input - ***/ - private unowned PulseAudio.GLibMainLoop _pgloop = null; private PulseAudio.Context _pulse_context = null; private uint _pulse_reconnect_timer = 0; private uint _update_sink_timer = 0; - private uint _update_sink_inputs_timer = 0; + private uint _pending_sink_inputs_timer = 0; private GenericSet _pending_sink_inputs = new GenericSet(direct_hash, direct_equal); private uint soon_interval_msec = 500; @@ -105,29 +101,21 @@ public class VolumeWarningPulse : VolumeWarning private void set_multimedia_sink_index (uint32 index) { - if (index == PulseAudio.INVALID_INDEX) { - _multimedia_sink_index = PulseAudio.INVALID_INDEX; - multimedia_volume = PulseAudio.Volume.INVALID; - } else if (_multimedia_sink_index != index) { + if (_multimedia_sink_index != index) { _multimedia_sink_index = index; + multimedia_volume = PulseAudio.Volume.INVALID; - update_multimedia_volume_soon (); + if (index != PulseAudio.INVALID_INDEX) + update_multimedia_volume_soon (); } } /***/ private bool is_active_multimedia (SinkInputInfo i) { + return (i.corked == 0) && + (i.proplist.gets(PulseAudio.Proplist.PROP_MEDIA_ROLE) == "multimedia"); - if (i.corked != 0) - return false; - - var key = PulseAudio.Proplist.PROP_MEDIA_ROLE; - var media_role = i.proplist.gets (key); - if (media_role != "multimedia") - return false; - - return true; } private void clear_multimedia () { @@ -163,11 +151,11 @@ public class VolumeWarningPulse : VolumeWarning _pending_sink_inputs.add (index); - if (_update_sink_inputs_timer == 0) { - _update_sink_inputs_timer = Timeout.add (soon_interval_msec, () => { + if (_pending_sink_inputs_timer == 0) { + _pending_sink_inputs_timer = Timeout.add (soon_interval_msec, () => { + _pending_sink_inputs_timer = 0; _pending_sink_inputs.foreach ((i) => update_sink_input (i)); _pending_sink_inputs.remove_all (); - _update_sink_inputs_timer = 0; return Source.REMOVE; }); } @@ -261,7 +249,7 @@ public class VolumeWarningPulse : VolumeWarning _pulse_context = new PulseAudio.Context (_pgloop.get_api(), null, props); _pulse_context.set_state_callback (pulse_context_state_callback); - var server_string = Environment.get_variable ("PULSE_SERVER"); + unowned string server_string = Environment.get_variable ("PULSE_SERVER"); if (_pulse_context.connect (server_string, Context.Flags.NOFAIL, null) < 0) GLib.warning ("pa_context_connect() failed: %s\n", PulseAudio.strerror(_pulse_context.errno())); } -- cgit v1.2.3 From 6513c65a7e6a6e5db6e1f44e87e6e7f138b462e8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 12 Jan 2016 14:04:16 -0600 Subject: in volume-warning-pulse, get/set the sink input's volume rather than the sink's volume, just as volume-control-pulse does --- src/volume-warning-pulse.vala | 57 ++++++------------------------------------- 1 file changed, 7 insertions(+), 50 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index c0a1b1a..3903b01 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -46,11 +46,11 @@ public class VolumeWarningPulse : VolumeWarning protected override void preshow () { /* showing the dialog can change the sink input index (bug #1484589) * so cache it here for later use in sound_system_set_multimedia_volume() */ - _target_sink_index = _multimedia_sink_index; + _target_sink_input_index = _multimedia_sink_input_index; } protected override void sound_system_set_multimedia_volume (PulseAudio.Volume volume) { - var index = _target_sink_index; + var index = _target_sink_input_index; return_if_fail (_pulse_context != null); return_if_fail (index != PulseAudio.INVALID_INDEX); @@ -58,8 +58,8 @@ public class VolumeWarningPulse : VolumeWarning unowned CVolume cvol = CVolume (); cvol.set (1, volume); - debug ("setting multimedia volume to %s", cvol.to_string ()); - _pulse_context.set_sink_volume_by_index (index, cvol); + debug ("setting multimedia (sink_input index %d) volume to %s", (int)index, cvol.to_string ()); + _pulse_context.set_sink_input_volume (index, cvol); } private unowned PulseAudio.GLibMainLoop _pgloop = null; @@ -71,47 +71,11 @@ public class VolumeWarningPulse : VolumeWarning private uint soon_interval_msec = 500; - private uint32 _target_sink_index = PulseAudio.INVALID_INDEX; - private uint32 _multimedia_sink_index = PulseAudio.INVALID_INDEX; + private uint32 _target_sink_input_index = PulseAudio.INVALID_INDEX; private uint32 _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; /***/ - private void update_multimedia_volume () { - - return_if_fail (_pulse_context != null); - return_if_fail (_multimedia_sink_index != PulseAudio.INVALID_INDEX); - - _pulse_context.get_sink_info_by_index (_multimedia_sink_index, (c,i) => { - if (i != null) - multimedia_volume = i.volume.max (); - }); - } - - private void update_multimedia_volume_soon () { - - if (_update_sink_timer == 0) { - _update_sink_timer = Timeout.add (soon_interval_msec, () => { - _update_sink_timer = 0; - update_multimedia_volume (); - return Source.REMOVE; - }); - } - } - - private void set_multimedia_sink_index (uint32 index) { - - if (_multimedia_sink_index != index) { - _multimedia_sink_index = index; - - multimedia_volume = PulseAudio.Volume.INVALID; - if (index != PulseAudio.INVALID_INDEX) - update_multimedia_volume_soon (); - } - } - - /***/ - private bool is_active_multimedia (SinkInputInfo i) { return (i.corked == 0) && (i.proplist.gets(PulseAudio.Proplist.PROP_MEDIA_ROLE) == "multimedia"); @@ -120,7 +84,7 @@ public class VolumeWarningPulse : VolumeWarning private void clear_multimedia () { _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; - set_multimedia_sink_index (PulseAudio.INVALID_INDEX); + multimedia_volume = PulseAudio.Volume.INVALID; multimedia_active = false; } @@ -132,7 +96,7 @@ public class VolumeWarningPulse : VolumeWarning if (is_active_multimedia (i)) { GLib.message ("on_sink_input_info() setting multimedia sink input index to %d, sink index to %d", (int)i.index, (int)i.sink); _multimedia_sink_input_index = i.index; - set_multimedia_sink_index (i.sink); + multimedia_volume = i.volume.max (); multimedia_active = true; } else if (i.index == _multimedia_sink_input_index) { @@ -164,13 +128,6 @@ public class VolumeWarningPulse : VolumeWarning private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index) { switch (t & Context.SubscriptionEventType.FACILITY_MASK) { - case Context.SubscriptionEventType.SINK: - // if something happens to the sink connected to our mm sink input, - // get its updated info to keep our multimedia volume up-to-date - if ((index == _multimedia_sink_index) && (index != PulseAudio.INVALID_INDEX)) - update_multimedia_volume_soon(); - break; - case Context.SubscriptionEventType.SINK_INPUT: switch (t & Context.SubscriptionEventType.TYPE_MASK) { -- cgit v1.2.3 From 5b9b1192a68e6ce4fb5e2e972f92f03862f7ad8b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 12 Jan 2016 14:09:32 -0600 Subject: remove newly-dead variable VolumeWarningPulse._update_sink_timer --- src/volume-warning-pulse.vala | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 3903b01..0f1009d 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -38,7 +38,6 @@ public class VolumeWarningPulse : VolumeWarning ~VolumeWarningPulse () { clear_timer (ref _pulse_reconnect_timer); - clear_timer (ref _update_sink_timer); clear_timer (ref _pending_sink_inputs_timer); pulse_disconnect (); } @@ -65,7 +64,6 @@ public class VolumeWarningPulse : VolumeWarning private unowned PulseAudio.GLibMainLoop _pgloop = null; private PulseAudio.Context _pulse_context = null; private uint _pulse_reconnect_timer = 0; - private uint _update_sink_timer = 0; private uint _pending_sink_inputs_timer = 0; private GenericSet _pending_sink_inputs = new GenericSet(direct_hash, direct_equal); -- cgit v1.2.3 From ab794272cf6c367b9d1414415589cd4079a736f4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 12 Jan 2016 15:07:48 -0600 Subject: change a tracer GLib.message() call to GLib.debug() --- src/volume-warning-pulse.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/volume-warning-pulse.vala') diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 0f1009d..2492cef 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -92,7 +92,7 @@ public class VolumeWarningPulse : VolumeWarning return; if (is_active_multimedia (i)) { - GLib.message ("on_sink_input_info() setting multimedia sink input index to %d, sink index to %d", (int)i.index, (int)i.sink); + GLib.debug ("on_sink_input_info() setting multimedia sink input index to %d, sink index to %d", (int)i.index, (int)i.sink); _multimedia_sink_input_index = i.index; multimedia_volume = i.volume.max (); multimedia_active = true; -- cgit v1.2.3