From 03a879f644d27ec45a97caa7681e4428f7b341fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 8 Oct 2014 13:40:04 -0500 Subject: Make volume string translatable --- src/volume-control.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index 5a8bbe2..a4c97b6 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -578,13 +578,13 @@ public class VolumeControl : Object public void set_volume (double volume) { if (_volume == 0.0) - _notification.update ("Volume", "", "audio-volume-muted"); + _notification.update (_("Volume"), "", "audio-volume-muted"); if (_volume > 0.0 && _volume <= 0.33) - _notification.update ("Volume", "", "audio-volume-low"); + _notification.update (_("Volume"), "", "audio-volume-low"); if (_volume > 0.33 && _volume <= 0.66) - _notification.update ("Volume", "", "audio-volume-medium"); + _notification.update (_("Volume"), "", "audio-volume-medium"); if (_volume > 0.66 && _volume <= 1.0) - _notification.update ("Volume", "", "audio-volume-high"); + _notification.update (_("Volume"), "", "audio-volume-high"); _notification.set_hint ("value", _volume * 100.0); _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); _notification.show (); -- cgit v1.2.3 From 27e2a3618ac09e9ca3dbbc30ed4d8ebec71feba9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 09:47:01 -0500 Subject: No audio ping if we're doing multimedia, and no notification if we're not on phone --- src/volume-control.vala | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index a4c97b6..17367e8 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -577,17 +577,22 @@ public class VolumeControl : Object public void set_volume (double volume) { - if (_volume == 0.0) - _notification.update (_("Volume"), "", "audio-volume-muted"); - if (_volume > 0.0 && _volume <= 0.33) - _notification.update (_("Volume"), "", "audio-volume-low"); - if (_volume > 0.33 && _volume <= 0.66) - _notification.update (_("Volume"), "", "audio-volume-medium"); - if (_volume > 0.66 && _volume <= 1.0) - _notification.update (_("Volume"), "", "audio-volume-high"); - _notification.set_hint ("value", _volume * 100.0); - _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); - _notification.show (); + /* Using this to detect whether we're on the phone or not */ + if (_pulse_use_stream_restore) { + if (_volume == 0.0) + _notification.update (_("Volume"), "", "audio-volume-muted"); + if (_volume > 0.0 && _volume <= 0.33) + _notification.update (_("Volume"), "", "audio-volume-low"); + if (_volume > 0.33 && _volume <= 0.66) + _notification.update (_("Volume"), "", "audio-volume-medium"); + if (_volume > 0.66 && _volume <= 1.0) + _notification.update (_("Volume"), "", "audio-volume-high"); + _notification.set_hint ("value", _volume * 100.0); + if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") + /* No audio ping if we're playing multimedia */ + _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); + _notification.show (); + } if (set_volume_internal (volume)) { start_local_volume_timer(); -- cgit v1.2.3 From d10cf747faeebb0b363fe80666c82cf659a116ab Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 09:52:40 -0500 Subject: Adding a notifications test case --- tests/manual | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/manual b/tests/manual index 201465c..d9fb7d5 100644 --- a/tests/manual +++ b/tests/manual @@ -22,3 +22,20 @@ Test-case indicator-sound/unity8-items-check
The menu is populated with items
+Test-case indicator-sound/unity8-sound-notifications +
+
Adjust volume using HW keys if available
+
A notification bubble should appear with the sound volume
+
An audibule sound should play at the level of the audio
+
Adjust volume with slider in sound indicator
+
A notification bubble should appear with the sound volume
+
An audibule sound should play at the level of the audio
+
Open a video with sound and play in media player
+
The video should play and the sound should be audible
+
Adjust volume using HW keys if available
+
A notification bubble should appear with the sound volume
+
No notification sound should be heard
+
Adjust volume with slider in sound indicator
+
A notification bubble should appear with the sound volume
+
No notification sound should be heard
+
-- cgit v1.2.3 From 7df37f358ee186e95362c88e9013f7f079d2c8ae Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 11:18:21 -0500 Subject: Test plan test for the greeter mode --- tests/manual | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/manual b/tests/manual index 201465c..039eead 100644 --- a/tests/manual +++ b/tests/manual @@ -22,3 +22,29 @@ Test-case indicator-sound/unity8-items-check
The menu is populated with items
+Test-case indicator-sound/unity8-embedded-greeter +
+
NOTE: Only works with embedded greeter, split greeter will require modifications to this test
+
Ensure System Settings is set to "Show Messages on Greeter"
+
Play a song in the media player
+
The song should be heard
+
There should be an entry in the sound menu with the meta data for the song being played
+
Go to the greeter. This can be done by hitting the lock button twice.
+
Ensure the sound menu has song meta data
+
There should be an entry in the sound menu with the meta data for the song being played
+
Pause the song in the greeter
+
The song should stop playing
+
Resume the song in the greeter
+
The song should continue to play
+
Disable System Settings value "Show Messages on Greeter"
+
Ensure the sound menu has song meta data
+
There should be an entry in the sound menu with the meta data for the song being played
+
Go to the greeter. This can be done by hitting the lock button twice.
+
Ensure the sound menu does not have song meta data
+
There should be an entry for the player but it should have no information on the song being played
+
Pause the song in the greeter
+
The song should stop playing
+
Resume the song in the greeter
+
The song should continue to play
+
+ -- cgit v1.2.3 From 228153f72649485111052f5f13a84fd73f290b94 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 21:52:03 -0500 Subject: Make sure to clear the sound hint --- src/volume-control.vala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index 17367e8..86b976e 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -588,9 +588,12 @@ public class VolumeControl : Object if (_volume > 0.66 && _volume <= 1.0) _notification.update (_("Volume"), "", "audio-volume-high"); _notification.set_hint ("value", _volume * 100.0); - if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") + if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") { /* No audio ping if we're playing multimedia */ _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); + } else { + _notification.set_hint ("sound-file", null); + } _notification.show (); } -- cgit v1.2.3 From 365f0a5af2b6327531f49a0fa3754359063dfea1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 21:54:40 -0500 Subject: Catch the error that show can throw and present a warning --- src/volume-control.vala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index 86b976e..dbc1797 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -594,7 +594,12 @@ public class VolumeControl : Object } else { _notification.set_hint ("sound-file", null); } - _notification.show (); + + try { + _notification.show (); + } catch (GLib.Error e) { + warning("Unable to send volume change notification: %s", e.message); + } } if (set_volume_internal (volume)) { -- cgit v1.2.3 From 70601ef284279d6db7b8add3c50cd0350fdfb707 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 21:58:20 -0500 Subject: Make sure to use the passed parameter for the volume. --- src/volume-control.vala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index dbc1797..e35b3e5 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -579,15 +579,15 @@ public class VolumeControl : Object { /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { - if (_volume == 0.0) + if (volume == 0.0) _notification.update (_("Volume"), "", "audio-volume-muted"); - if (_volume > 0.0 && _volume <= 0.33) + if (volume > 0.0 && volume <= 0.33) _notification.update (_("Volume"), "", "audio-volume-low"); - if (_volume > 0.33 && _volume <= 0.66) + if (volume > 0.33 && volume <= 0.66) _notification.update (_("Volume"), "", "audio-volume-medium"); - if (_volume > 0.66 && _volume <= 1.0) + if (volume > 0.66 && volume <= 1.0) _notification.update (_("Volume"), "", "audio-volume-high"); - _notification.set_hint ("value", _volume * 100.0); + _notification.set_hint ("value", volume * 100.0); if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") { /* No audio ping if we're playing multimedia */ _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); -- cgit v1.2.3 From a0dc1f66614ac40bc527ccad537ff607a4bef642 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 22:06:15 -0500 Subject: Didn't make initial string translated --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index e35b3e5..aee670e 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -88,7 +88,7 @@ public class VolumeControl : Object _volume_cancellable = new Cancellable (); Notify.init ("Volume"); - _notification = new Notify.Notification("Volume", "", "audio-volume-muted"); + _notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted"); _notification.set_hint ("value", 0); _notification.set_hint ("x-canonical-private-synchronous", "true"); _notification.set_hint ("x-canonical-non-shaped-icon", "true"); -- cgit v1.2.3 From 4da707591f393735ed3306421e2c1518eff4d3e5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Oct 2014 22:15:35 -0500 Subject: Ensure we send an integer to the notification service --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index aee670e..0541397 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -587,7 +587,7 @@ public class VolumeControl : Object _notification.update (_("Volume"), "", "audio-volume-medium"); if (volume > 0.66 && volume <= 1.0) _notification.update (_("Volume"), "", "audio-volume-high"); - _notification.set_hint ("value", volume * 100.0); + _notification.set_hint ("value", (int32)(volume * 100.0)); if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") { /* No audio ping if we're playing multimedia */ _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); -- cgit v1.2.3 From eaa8592f4a4ad49cd462a04e2d008ce49d5a3206 Mon Sep 17 00:00:00 2001 From: Ricardo Salveti Date: Fri, 10 Oct 2014 10:43:07 -0500 Subject: Integration test for audio roles --- tests/manual | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/manual b/tests/manual index 201465c..2816984 100644 --- a/tests/manual +++ b/tests/manual @@ -22,3 +22,22 @@ Test-case indicator-sound/unity8-items-check
The menu is populated with items
+Test-case indicator-sound/unity8-audio-roles +
+
Without playing anything (no active audio stream), change the volume on the indicator or with the volume buttons and then try playing one of the following audio streams: camera shutter, ringtone, message notification, dtmf
+
The audio stream should reflect the volume set on the indicator
+
Without playing anything (no active audio stream), change the volume on the indicator or with volume buttons and then try playing one of the following audio streams: music-app, webrowser (youtube)
+
The audio stream should not be affected by the volume set on the indicator when there was no other active stream +
Play a multimedia stream (music-app, webrowser) and change the volume on the indicator when the stream is active
+
The multimedia audio stream should reflect the volume set on the indicator
+
When stopping/closing the multimedia stream, it should automatically show up the volume for the alert role (ringtone, notification, etc)
+
No other role should be affected by the volume level used by the multimedia role
+
Play a alarm stream (clock-app) and change the volume on the indicator when the stream is active
+
The alarm audio stream should reflect the volume set on the indicator
+
When stopping/closing the alarm stream, it should automatically show up the volume for the alert role (ringtone, notification, etc)
+
No other role should be affected by the volume level used by the alarm role
+
Start a voice call using the dialer-app and change the volume on the indicator when the call is active
+
The phone audio stream should reflect the volume set on the indicator
+
When hanging up the voice call it should automatically show up the volume for the alert role (ringtone, notification, etc)
+
No other role should be affected by the volume level used by the phone role
+
-- cgit v1.2.3 From f079f5a27a70a377b8787610f1bef62d8af7fe7c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Oct 2014 12:43:29 -0500 Subject: Make notifications check for high volumes and change based on that --- src/volume-control.vala | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index f9db556..0e5abbb 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -580,22 +580,42 @@ public class VolumeControl : Object { /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { - if (volume == 0.0) - _notification.update (_("Volume"), "", "audio-volume-muted"); + /* Watch for extreme */ + bool extreme_volume = false; + if (volume > 0.75) /* TODO: Also if headphones */ + extreme_volume = true; + + /* Determine Label */ + string volume_label = _("Volume"); + if (extreme_volume) + volume_label = _("High volume"); + + /* Choose an icon */ + string icon = "audio-volume-muted"; if (volume > 0.0 && volume <= 0.33) - _notification.update (_("Volume"), "", "audio-volume-low"); + icon = "audio-volume-low"; if (volume > 0.33 && volume <= 0.66) - _notification.update (_("Volume"), "", "audio-volume-medium"); + icon = "audio-volume-medium"; if (volume > 0.66 && volume <= 1.0) - _notification.update (_("Volume"), "", "audio-volume-high"); + icon = "audio-volume-high"; + + /* Choose a sound */ + string? sound = null; + if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") + sound = "/usr/share/sounds/ubuntu/stereo/message.ogg"; + + /* Check tint */ + string tint = "false"; + if (extreme_volume) + tint = "true"; + + /* Put it all into the notification */ + _notification.update (volume_label, "", icon); _notification.set_hint ("value", (int32)(volume * 100.0)); - if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") { - /* No audio ping if we're playing multimedia */ - _notification.set_hint ("sound-file", "/usr/share/sounds/ubuntu/stereo/message.ogg"); - } else { - _notification.set_hint ("sound-file", null); - } + _notification.set_hint ("sound-file", sound); + _notification.set_hint ("x-canonical-value-bar-tint", tint); + /* Show it */ try { _notification.show (); } catch (GLib.Error e) { -- cgit v1.2.3 From b6081ca691dc5d7cc41b41837378f8045a8741e8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Oct 2014 14:16:59 -0500 Subject: Adding in a manual test for the high volume notification --- tests/manual | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/manual b/tests/manual index d9fb7d5..f69cf14 100644 --- a/tests/manual +++ b/tests/manual @@ -39,3 +39,21 @@ Test-case indicator-sound/unity8-sound-notifications
A notification bubble should appear with the sound volume
No notification sound should be heard
+ +Test-case indicator-sound/unity8-high-volume +
+
Plug headphones into the headphone jack
+
Adjust volume so that it is at the midpoint of volume range
+
The slider should be in the middle of the scale
+
Increase the volume once using HW keys if available
+
A notification bubble should appear with the sound volume
+
The text on the notification should read "Volume"
+
Increase the volume using HW keys until it is roughly 90% of the range
+
A notification bubble should appear with the sound volume
+
The text on the notification should read "High volume"
+
The range on the notification bubble should have a different color signifying the higher volume
+
Decrease the volume using HW keys until it is roughly 50% of the range
+
A notification bubble should appear with the sound volume
+
The text on the notification should read "Volume"
+
The range on the notification bubble should have a standard color
+
-- cgit v1.2.3 From 53edccc48b6b1999457aaa4241bfc8eee413f16c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Oct 2014 16:10:15 -0500 Subject: Turn high volume into a property --- src/volume-control.vala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index 0e5abbb..e09f212 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -79,6 +79,9 @@ public class VolumeControl : Object /** true when a microphone is active **/ public bool active_mic { get; private set; default = false; } + /** true when high volume warnings should be shown */ + public bool high_volume { get; set; } + public VolumeControl () { if (loop == null) @@ -581,13 +584,14 @@ public class VolumeControl : Object /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { /* Watch for extreme */ - bool extreme_volume = false; if (volume > 0.75) /* TODO: Also if headphones */ - extreme_volume = true; + high_volume = true; + else + high_volume = false; /* Determine Label */ string volume_label = _("Volume"); - if (extreme_volume) + if (high_volume) volume_label = _("High volume"); /* Choose an icon */ @@ -606,7 +610,7 @@ public class VolumeControl : Object /* Check tint */ string tint = "false"; - if (extreme_volume) + if (high_volume) tint = "true"; /* Put it all into the notification */ -- cgit v1.2.3 -- cgit v1.2.3 From 88956a3657cc0f0f8f76b2935a7ae46033d5c200 Mon Sep 17 00:00:00 2001 From: Ricardo Salveti Date: Mon, 13 Oct 2014 20:48:06 -0500 Subject: Headphone detection --- src/volume-control.vala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/volume-control.vala b/src/volume-control.vala index e09f212..c9ba42c 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -70,6 +70,8 @@ public class VolumeControl : Object private double _account_service_volume = 0.0; private Notify.Notification _notification; + private bool _active_port_headphone = false; + public signal void volume_changed (double v); public signal void mic_volume_changed (double v); @@ -177,6 +179,19 @@ public class VolumeControl : Object this.notify_property ("is-playing"); } + /* Check if the current active port is headset/headphone */ + /* There is not easy way to check if the port is a headset/headphone besides + * checking for the port name. On touch (with the pulseaudio droid element) + * the headset/headphone port is called 'output-headset' and 'output-headphone'. + * On the desktop this is usually called 'analog-output-headphones' */ + if (i.active_port.name == "output-wired_headset" || + i.active_port.name == "output-wired_headphone" || + i.active_port.name == "analog-output-headphones") { + _active_port_headphone = true; + } else { + _active_port_headphone = false; + } + if (_pulse_use_stream_restore == false && _volume != volume_to_double (i.volume.max ())) { -- cgit v1.2.3 From 9c8f845b511cf8a8a02cb90df5546ff852978ed6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 13 Oct 2014 20:49:19 -0500 Subject: Use the headphone detection --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index c9ba42c..b32146f 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -599,7 +599,7 @@ public class VolumeControl : Object /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { /* Watch for extreme */ - if (volume > 0.75) /* TODO: Also if headphones */ + if (volume > 0.75 && _active_port_headphone) high_volume = true; else high_volume = false; -- cgit v1.2.3 From 7ec3795022cbfff0e1c0c094309a4b67d1dd3b04 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 13 Oct 2014 20:51:07 -0500 Subject: Create actions based on the high volume status --- src/service.vala | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/service.vala b/src/service.vala index 2a65492..92523aa 100644 --- a/src/service.vala +++ b/src/service.vala @@ -49,6 +49,7 @@ public class IndicatorSound.Service: Object { this.actions.add_action (this.create_mute_action ()); this.actions.add_action (this.create_volume_action ()); this.actions.add_action (this.create_mic_volume_action ()); + this.actions.add_action (this.create_high_volume_actions ()); this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); @@ -388,6 +389,36 @@ public class IndicatorSound.Service: Object { return volume_action; } + Action create_high_volume_actions () { + var high_volume_action = new SimpleAction.stateful("high-volume", null, new Variant.boolean (this.volume_control.high_volume)); + + this.volume_control.notify["high_volume"].connect( () => + high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume))); + + /* So this is a bit confusing, putting it here because everywhere else + sucks too. It might create an action and put it into the action group. + Which is sneaky. Better to have the code not duplicated, but no good + place to put code like that. */ + setup_high_volume_menu_action(); + + return high_volume_action; + } + + void setup_high_volume_menu_action () { + this.volume_control.notify["high_volume"].connect(update_high_volume_menu_action); + update_high_volume_menu_action(); + } + + void update_high_volume_menu_action () { + if (this.volume_control.high_volume) { + var menu_action = new SimpleAction("high-volume-menu", null); + menu_action.set_enabled(false); + this.actions.add_action(menu_action); + } else { + this.actions.remove_action("high-volume-menu"); + } + } + void bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/sound", this.actions); -- cgit v1.2.3 From 9e39fba127c95aee79b26d2b88cb80dc279a5011 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 13 Oct 2014 21:32:30 -0500 Subject: Ensure we reevaluate the high volume warning when we switch from headphones or not --- src/volume-control.vala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/volume-control.vala b/src/volume-control.vala index b32146f..ea8e3ac 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -163,6 +163,8 @@ public class VolumeControl : Object private void sink_info_cb_for_props (Context c, SinkInfo? i, int eol) { + bool old_active_port_headphone = this._active_port_headphone; + if (i == null) return; @@ -197,6 +199,8 @@ public class VolumeControl : Object { _volume = volume_to_double (i.volume.max ()); volume_changed (_volume); + } else if (this._active_port_headphone != old_active_port_headphone) { + volume_changed (_volume); } } -- cgit v1.2.3 From 973b4eb057f466ad88e62d25f733ed1700e1ac38 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 07:59:43 -0500 Subject: Use title for the a11y info and the body for the message on sync notifications --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index ea8e3ac..b65cbc8 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -633,7 +633,7 @@ public class VolumeControl : Object tint = "true"; /* Put it all into the notification */ - _notification.update (volume_label, "", icon); + _notification.update (_("Volume"), volume_label, icon); _notification.set_hint ("value", (int32)(volume * 100.0)); _notification.set_hint ("sound-file", sound); _notification.set_hint ("x-canonical-value-bar-tint", tint); -- cgit v1.2.3 From 29576aceb257c868e5871972a1440b8602f2880b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 08:06:55 -0500 Subject: Adding a high volume warning menu item --- src/sound-menu.vala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sound-menu.vala b/src/sound-menu.vala index f245a1f..0094c22 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -25,7 +25,9 @@ public class SoundMenu: Object HIDE_INACTIVE_PLAYERS = 2, HIDE_PLAYERS = 4, GREETER_PLAYERS = 8, - SHOW_SILENT_MODE = 16 + SHOW_SILENT_MODE = 16, + HIGH_VOLUME_WARNING = 32 /* Everyone should get this eventually, but we don't + want it in the desktop initially because of freezes */ } public SoundMenu (string? settings_action, DisplayFlags flags) { @@ -48,6 +50,9 @@ public class SoundMenu: Object "audio-volume-low-zero-panel", "audio-volume-high-panel")); + if ((flags & DisplayFlags.HIGH_VOLUME_WARNING) != 0) + volume_section.append (_("High volume can damage your hearing."), "indicator.high-volume-menu"); + this.menu = new Menu (); this.menu.append_section (null, volume_section); -- cgit v1.2.3 From a2de8d1b337113ced7854683aad0183a841917f1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 08:12:58 -0500 Subject: Add high volume warnings to the phone menu --- src/service.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service.vala b/src/service.vala index 92523aa..3edcba0 100644 --- a/src/service.vala +++ b/src/service.vala @@ -53,9 +53,9 @@ public class IndicatorSound.Service: Object { this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); - this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); + this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS | SoundMenu.DisplayFlags.HIGH_VOLUME_WARNING)); this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE)); - this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS)); + this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.HIGH_VOLUME_WARNING)); this.menus.@foreach ( (profile, menu) => { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); -- cgit v1.2.3 From 52e2c2d3dce6ded517f9666d5d0412d56054d9d9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 09:45:40 -0500 Subject: Ensure that we're always getting a vlue in the list --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index b65cbc8..cf2dacf 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -624,7 +624,7 @@ public class VolumeControl : Object /* Choose a sound */ string? sound = null; - if (_active_sink_input == -1 || _valid_roles[_active_sink_input] != "multimedia") + if (!((_active_sink_input in _sink_input_list) && (_valid_roles[_active_sink_input] == "multimedia"))) sound = "/usr/share/sounds/ubuntu/stereo/message.ogg"; /* Check tint */ -- cgit v1.2.3 From 23b3fd431a312f2b02504b998c697241c30caa0b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 10:00:32 -0500 Subject: Drop the high volume menu action as that wasn't working --- src/service.vala | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/service.vala b/src/service.vala index 3edcba0..93e6a51 100644 --- a/src/service.vala +++ b/src/service.vala @@ -395,30 +395,9 @@ public class IndicatorSound.Service: Object { this.volume_control.notify["high_volume"].connect( () => high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume))); - /* So this is a bit confusing, putting it here because everywhere else - sucks too. It might create an action and put it into the action group. - Which is sneaky. Better to have the code not duplicated, but no good - place to put code like that. */ - setup_high_volume_menu_action(); - return high_volume_action; } - void setup_high_volume_menu_action () { - this.volume_control.notify["high_volume"].connect(update_high_volume_menu_action); - update_high_volume_menu_action(); - } - - void update_high_volume_menu_action () { - if (this.volume_control.high_volume) { - var menu_action = new SimpleAction("high-volume-menu", null); - menu_action.set_enabled(false); - this.actions.add_action(menu_action); - } else { - this.actions.remove_action("high-volume-menu"); - } - } - void bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/sound", this.actions); -- cgit v1.2.3 From 16828d0102efae82bf760097988474e434b884fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 10:07:30 -0500 Subject: Changing tact to change the menu when we want to show the warning --- src/service.vala | 4 ++-- src/sound-menu.vala | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/service.vala b/src/service.vala index 93e6a51..51060d4 100644 --- a/src/service.vala +++ b/src/service.vala @@ -53,9 +53,9 @@ public class IndicatorSound.Service: Object { this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); - this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS | SoundMenu.DisplayFlags.HIGH_VOLUME_WARNING)); + this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE)); - this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.HIGH_VOLUME_WARNING)); + this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS)); this.menus.@foreach ( (profile, menu) => { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); diff --git a/src/sound-menu.vala b/src/sound-menu.vala index 0094c22..e1c4e98 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -25,9 +25,7 @@ public class SoundMenu: Object HIDE_INACTIVE_PLAYERS = 2, HIDE_PLAYERS = 4, GREETER_PLAYERS = 8, - SHOW_SILENT_MODE = 16, - HIGH_VOLUME_WARNING = 32 /* Everyone should get this eventually, but we don't - want it in the desktop initially because of freezes */ + SHOW_SILENT_MODE = 16 } public SoundMenu (string? settings_action, DisplayFlags flags) { @@ -50,9 +48,6 @@ public class SoundMenu: Object "audio-volume-low-zero-panel", "audio-volume-high-panel")); - if ((flags & DisplayFlags.HIGH_VOLUME_WARNING) != 0) - volume_section.append (_("High volume can damage your hearing."), "indicator.high-volume-menu"); - this.menu = new Menu (); this.menu.append_section (null, volume_section); @@ -98,12 +93,31 @@ public class SoundMenu: Object this.mic_volume_shown = true; } else if (!value && this.mic_volume_shown) { + /* TODO: Make smarter */ this.volume_section.remove (this.volume_section.get_n_items () -1); this.mic_volume_shown = false; } } } + public bool show_high_volume_warning { + get { + return this.high_volume_warning_shown; + } + set { + if (value && !this.high_volume_warning_shown) { + var item = new MenuItem(_("High volume can damage your hearing."), null); + volume_section.append_item (item); + this.high_volume_warning_shown = true; + } + else if (!value && this.high_volume_warning_shown) { + /* TODO: Make smarter */ + this.volume_section.remove (this.volume_section.get_n_items () -1); + this.high_volume_warning_shown = false; + } + } + } + public void add_player (MediaPlayer player) { if (this.notify_handlers.contains (player)) return; @@ -146,6 +160,7 @@ public class SoundMenu: Object Menu volume_section; bool mic_volume_shown; bool settings_shown = false; + bool high_volume_warning_shown = false; bool hide_inactive; bool hide_players = false; HashTable notify_handlers; -- cgit v1.2.3 From 8e7cbaadfed452063b2d659bc679746cad5cbb14 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 10:16:15 -0500 Subject: Linking volume control and the menu visibility --- src/service.vala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/service.vala b/src/service.vala index 51060d4..8f58110 100644 --- a/src/service.vala +++ b/src/service.vala @@ -61,6 +61,10 @@ public class IndicatorSound.Service: Object { this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); }); + this.menus.@foreach ( (profile, menu) => { + this.volume_control.bind_property ("high-volume", menu, "show-high-volume-warning", BindingFlags.SYNC_CREATE); + }); + this.sync_preferred_players (); this.settings.changed["interested-media-players"].connect ( () => { this.sync_preferred_players (); -- cgit v1.2.3 From a3de59a992980727e05c58e052be53a8adc5bf08 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 16:02:23 -0500 Subject: Making the removal of items smarter --- src/sound-menu.vala | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/sound-menu.vala b/src/sound-menu.vala index e1c4e98..a9efd74 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -93,8 +93,10 @@ public class SoundMenu: Object this.mic_volume_shown = true; } else if (!value && this.mic_volume_shown) { - /* TODO: Make smarter */ - this.volume_section.remove (this.volume_section.get_n_items () -1); + int location = -1; + while ((location = find_action(this.volume_section, "indicator.mic-volume")) != -1) { + this.volume_section.remove (location); + } this.mic_volume_shown = false; } } @@ -106,18 +108,35 @@ public class SoundMenu: Object } set { if (value && !this.high_volume_warning_shown) { - var item = new MenuItem(_("High volume can damage your hearing."), null); + /* NOTE: Action doesn't really exist, just used to find below when removing */ + var item = new MenuItem(_("High volume can damage your hearing."), "indicator.high-volume-warning-item"); volume_section.append_item (item); this.high_volume_warning_shown = true; } else if (!value && this.high_volume_warning_shown) { - /* TODO: Make smarter */ + int location = -1; + while ((location = find_action(this.volume_section, "indicator.high-volume-warning-item")) != -1) { + this.volume_section.remove (location); + } this.volume_section.remove (this.volume_section.get_n_items () -1); this.high_volume_warning_shown = false; } } } + int find_action (Menu menu, string in_action) { + int n = menu.get_n_items (); + for (int i = 0; i < n; i++) { + string action; + menu.get_item_attribute (0, "action", "s", out action); + if (in_action == action) + return i; + } + + return -1; + } + + public void add_player (MediaPlayer player) { if (this.notify_handlers.contains (player)) return; -- cgit v1.2.3 From d7fbfc4d0babbcd54a3951f5da721153cc194d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirco=20M=C3=BCller?= Date: Tue, 14 Oct 2014 18:27:46 -0500 Subject: Make High-volume text work correctly --- src/volume-control.vala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index 8245c50..5a7e66d 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -612,7 +612,7 @@ public class VolumeControl : Object high_volume = false; /* Determine Label */ - string volume_label = _("Volume"); + string volume_label = ""; if (high_volume) volume_label = _("High volume"); @@ -636,10 +636,13 @@ public class VolumeControl : Object tint = "true"; /* Put it all into the notification */ + _notification.clear_hints (); _notification.update (_("Volume"), volume_label, icon); _notification.set_hint ("value", (int32)(volume * 100.0)); _notification.set_hint ("sound-file", sound); _notification.set_hint ("x-canonical-value-bar-tint", tint); + _notification.set_hint ("x-canonical-private-synchronous", "true"); + _notification.set_hint ("x-canonical-non-shaped-icon", "true"); /* Show it */ try { -- cgit v1.2.3 From 69b9c090d86e46a0af7e74e68ded1d0f5b4c52cd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 22:12:13 -0500 Subject: Check more precisely the valid roles --- src/volume-control.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index 5a7e66d..d666708 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -627,7 +627,8 @@ public class VolumeControl : Object /* Choose a sound */ string? sound = null; - if (!((_active_sink_input in _sink_input_list) && (_valid_roles[_active_sink_input] == "multimedia"))) + if (!((_active_sink_input >= 0) && (_active_sink_input < _valid_roles.length) + && (_valid_roles[_active_sink_input] == "multimedia"))) sound = "/usr/share/sounds/ubuntu/stereo/message.ogg"; /* Check tint */ -- cgit v1.2.3 From 0414b149396497e4c837a126d1945905ceb2623c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 14 Oct 2014 23:38:00 -0500 Subject: Get propery property name --- src/service.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.vala b/src/service.vala index 8f58110..b4c7c44 100644 --- a/src/service.vala +++ b/src/service.vala @@ -396,7 +396,7 @@ public class IndicatorSound.Service: Object { Action create_high_volume_actions () { var high_volume_action = new SimpleAction.stateful("high-volume", null, new Variant.boolean (this.volume_control.high_volume)); - this.volume_control.notify["high_volume"].connect( () => + this.volume_control.notify["high-volume"].connect( () => high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume))); return high_volume_action; -- cgit v1.2.3 From abf10def9f86ccbf5e1bc9f32669ef28353983c6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 15 Oct 2014 08:32:11 -0500 Subject: Remove volume text from manual test --- tests/manual | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/manual b/tests/manual index f69cf14..0df4186 100644 --- a/tests/manual +++ b/tests/manual @@ -47,13 +47,13 @@ Test-case indicator-sound/unity8-high-volume
The slider should be in the middle of the scale
Increase the volume once using HW keys if available
A notification bubble should appear with the sound volume
-
The text on the notification should read "Volume"
+
There should be no text on the notification
Increase the volume using HW keys until it is roughly 90% of the range
A notification bubble should appear with the sound volume
The text on the notification should read "High volume"
The range on the notification bubble should have a different color signifying the higher volume
Decrease the volume using HW keys until it is roughly 50% of the range
A notification bubble should appear with the sound volume
-
The text on the notification should read "Volume"
+
There should be no text on the notification
The range on the notification bubble should have a standard color
-- cgit v1.2.3 From 33998ab08618bb6d513f91b2d49685ede072432b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 15 Oct 2014 08:35:54 -0500 Subject: Found other notification --- src/service.vala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/service.vala b/src/service.vala index b4c7c44..d9a2dd3 100644 --- a/src/service.vala +++ b/src/service.vala @@ -179,6 +179,8 @@ public class IndicatorSound.Service: Object { double v = this.volume_control.get_volume () + volume_step_percentage * delta; this.volume_control.set_volume (v.clamp (0.0, this.max_volume)); + /* TODO: Don't want to mess up the desktop today, but we should remove this + scrolling change and merge that into volume control's notification */ if (this.notification != null) { string icon; if (v <= 0.0) -- cgit v1.2.3 From 46c7d4c1cb1a6552ba205beaf233d66dcd4fc8a7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 15 Oct 2014 08:38:43 -0500 Subject: Make volume icons match the panel icons --- src/volume-control.vala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index d666708..f6f54d2 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -618,11 +618,13 @@ public class VolumeControl : Object /* Choose an icon */ string icon = "audio-volume-muted"; - if (volume > 0.0 && volume <= 0.33) + if (volume <= 0.0) + icon = "audio-volume-muted"; + else if (volume <= 0.3) icon = "audio-volume-low"; - if (volume > 0.33 && volume <= 0.66) + else if (volume <= 0.7) icon = "audio-volume-medium"; - if (volume > 0.66 && volume <= 1.0) + else icon = "audio-volume-high"; /* Choose a sound */ -- cgit v1.2.3 From 0b6434da43e5a5dd280df9014a182fc51cb05423 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 15 Oct 2014 09:43:24 -0500 Subject: Commenting out the sound for now --- src/volume-control.vala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/volume-control.vala b/src/volume-control.vala index f6f54d2..6f48c5d 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -642,7 +642,10 @@ public class VolumeControl : Object _notification.clear_hints (); _notification.update (_("Volume"), volume_label, icon); _notification.set_hint ("value", (int32)(volume * 100.0)); + /* TODO: Removing sound until we can get all the roles cleaned up for + when to play it. We expect this to come back, but in another landing. _notification.set_hint ("sound-file", sound); + */ _notification.set_hint ("x-canonical-value-bar-tint", tint); _notification.set_hint ("x-canonical-private-synchronous", "true"); _notification.set_hint ("x-canonical-non-shaped-icon", "true"); -- cgit v1.2.3 From ea570316012b87f04d1de7aff11d2bebff670b97 Mon Sep 17 00:00:00 2001 From: CI bot Date: Wed, 15 Oct 2014 16:19:13 +0000 Subject: Releasing 12.10.2+14.10.20141015.5~rtm-0ubuntu1 --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index e9e29d1..8d235fe 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +indicator-sound (12.10.2+14.10.20141015.5~rtm-0ubuntu1) 14.09; urgency=low + + [ Ted Gould ] + * Show notifications on volume change (LP: #1378564) + + -- Ubuntu daily release Wed, 15 Oct 2014 16:19:12 +0000 + indicator-sound (12.10.2+14.10.20141010-0ubuntu1) utopic; urgency=low [ Ricardo Salveti de Araujo ] -- cgit v1.2.3 From 5dd9bda0ea449024dbc97e26f92631401048bc57 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 15 Oct 2014 13:24:48 -0500 Subject: Removing the remove code that was supposed to be removed earlier --- src/sound-menu.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sound-menu.vala b/src/sound-menu.vala index a9efd74..05570b9 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -118,7 +118,6 @@ public class SoundMenu: Object while ((location = find_action(this.volume_section, "indicator.high-volume-warning-item")) != -1) { this.volume_section.remove (location); } - this.volume_section.remove (this.volume_section.get_n_items () -1); this.high_volume_warning_shown = false; } } -- cgit v1.2.3 From 1e193a4b99e62b52fb759d00a8745f1c477d965f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 15 Oct 2014 13:52:31 -0500 Subject: Make sure to check the item in the loop --- src/sound-menu.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sound-menu.vala b/src/sound-menu.vala index 05570b9..3881faf 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -127,7 +127,7 @@ public class SoundMenu: Object int n = menu.get_n_items (); for (int i = 0; i < n; i++) { string action; - menu.get_item_attribute (0, "action", "s", out action); + menu.get_item_attribute (i, "action", "s", out action); if (in_action == action) return i; } -- cgit v1.2.3 From 16a72ae6f4c18c621e16e259bc9122cdaf39eb6b Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 16 Oct 2014 15:07:51 +0200 Subject: service.vala: don't call set_volume unnecessarily The allow-amplified-volume setting is bound to a property on the service with the same name. GSettings always sets the target property when the binding is created. The property setter calls set_volume() unconditionally, which lead to a call on every startup of indicator-sound. That wasn't a problem until set_volume() started emitting a notification for volume changes... Fix this by only updating the property when the underlying value has actually changed. --- src/service.vala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/service.vala b/src/service.vala index bd44b0d..0a5725a 100644 --- a/src/service.vala +++ b/src/service.vala @@ -139,6 +139,9 @@ public class IndicatorSound.Service: Object { } set { + if (this.allow_amplified_volume == value) + return; + if (value) { /* from pulse/volume.h: #define PA_VOLUME_UI_MAX (pa_sw_volume_from_dB(+11.0)) */ this.max_volume = (double)PulseAudio.Volume.sw_from_dB(11.0) / PulseAudio.Volume.NORM; -- cgit v1.2.3 From 8cfba863c2ce74c326cb31f13f14a1de801e69f2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 16 Oct 2014 11:12:28 -0500 Subject: No RTM changelog entries in Utopic --- debian/changelog | 7 ------- 1 file changed, 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index e82b0e3..483c78b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,3 @@ -indicator-sound (12.10.2+14.10.20141015.5~rtm-0ubuntu1) 14.09; urgency=low - - [ Ted Gould ] - * Show notifications on volume change (LP: #1378564) - - -- Ubuntu daily release Wed, 15 Oct 2014 16:19:12 +0000 - indicator-sound (12.10.2+14.10.20141010-0ubuntu1) utopic; urgency=low [ Ricardo Salveti de Araujo ] -- cgit v1.2.3 From ebf6a44938610ec386e269d5d5538cbb82a73290 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 22 Oct 2014 12:38:46 -0400 Subject: Silent mode test --- tests/manual | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/manual b/tests/manual index 2816984..05993ed 100644 --- a/tests/manual +++ b/tests/manual @@ -22,6 +22,24 @@ Test-case indicator-sound/unity8-items-check
The menu is populated with items
+Test-case indicator-sound/unity8-silent-mode +
+
NOTE: This test currently doesn't work because of a bug:
+
Open the Sound menu
+
The sound menu includes an item "Silent Mode" which is a check box
+
The checkbox is not checked
+
Enable silent mode
+
Selecting the "Silent Mode" item should cause the box to be checked
+
Open the sound panel in system settings
+
The sound panel includes an item "Silent Mode" which is a check box
+
The checkbox is checked
+
Disable silent mode in system settings
+
The checkbox is not checked
+
Open the Sound menu
+
The sound menu includes an item "Silent Mode" which is a check box
+
The checkbox is not checked
+
+ Test-case indicator-sound/unity8-audio-roles
Without playing anything (no active audio stream), change the volume on the indicator or with the volume buttons and then try playing one of the following audio streams: camera shutter, ringtone, message notification, dtmf
-- cgit v1.2.3 From 6e42c539dd125c3a44c82d135df3f0788d974771 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 22 Oct 2014 12:40:07 -0400 Subject: Adding a bug number to the test --- tests/manual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/manual b/tests/manual index 05993ed..ab18469 100644 --- a/tests/manual +++ b/tests/manual @@ -24,7 +24,7 @@ Test-case indicator-sound/unity8-items-check Test-case indicator-sound/unity8-silent-mode
-
NOTE: This test currently doesn't work because of a bug:
+
NOTE: This test currently doesn't work because of a bug: http://pad.lv/1336715
Open the Sound menu
The sound menu includes an item "Silent Mode" which is a check box
The checkbox is not checked
-- cgit v1.2.3 From 8a25cabee9738ced0da921fcac693495006070af Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 22 Oct 2014 15:52:54 -0400 Subject: Allow for the invalidated properties to be NULL --- src/volume-control.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index ad186a7..e8d35a4 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -689,7 +689,7 @@ public class VolumeControl : Object } /* AccountsService operations */ - private void accountsservice_props_changed_cb (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) + private void accountsservice_props_changed_cb (DBusProxy proxy, Variant changed_properties, string[]? invalidated_properties) { Variant volume_variant = changed_properties.lookup_value ("Volume", new VariantType ("d")); if (volume_variant != null) { -- cgit v1.2.3 From edf067bcf194607f0f51f0152e3ad5eb6d70d0be Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 22 Oct 2014 15:58:32 -0400 Subject: Setup a try/catch on the getting of properties --- src/volume-control.vala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index e8d35a4..5061ae8 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -747,10 +747,14 @@ public class VolumeControl : Object // Get current values and listen for changes _user_proxy.g_properties_changed.connect (accountsservice_props_changed_cb); - var props_variant = yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "GetAll", new Variant ("(s)", _user_proxy.get_interface_name ()), null, DBusCallFlags.NONE, -1); - Variant props; - props_variant.get ("(@a{sv})", out props); - accountsservice_props_changed_cb(_user_proxy, props, null); + try { + var props_variant = yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "GetAll", new Variant ("(s)", _user_proxy.get_interface_name ()), null, DBusCallFlags.NONE, -1); + Variant props; + props_variant.get ("(@a{sv})", out props); + accountsservice_props_changed_cb(_user_proxy, props, null); + } catch (GLib.Error e) { + debug("Unable to get properties for user %s at first try: %s", username, e.message); + } } private void greeter_user_changed (string username) -- cgit v1.2.3 From 9ab88593b90ee51361c4b4789daf11a2f1d08429 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 22 Oct 2014 16:00:18 -0400 Subject: Remove usage of deprecated hint functions --- src/service.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service.vala b/src/service.vala index 2a65492..4298ad7 100644 --- a/src/service.vala +++ b/src/service.vala @@ -69,7 +69,7 @@ public class IndicatorSound.Service: Object { List caps = Notify.get_server_caps (); if (caps.find_custom ("x-canonical-private-synchronous", strcmp) != null) { this.notification = new Notify.Notification ("indicator-sound", "", ""); - this.notification.set_hint_string ("x-canonical-private-synchronous", "indicator-sound"); + this.notification.set_hint ("x-canonical-private-synchronous", "indicator-sound"); } } @@ -186,7 +186,7 @@ public class IndicatorSound.Service: Object { icon = "notification-audio-volume-high"; this.notification.update ("indicator-sound", "", icon); - this.notification.set_hint_int32 ("value", ((int32) (100 * v / this.max_volume)).clamp (-1, 101)); + this.notification.set_hint ("value", ((int32) (100 * v / this.max_volume)).clamp (-1, 101)); try { this.notification.show (); } -- cgit v1.2.3 From e03e82a36d5662c80ad61c6758591ae40d551f6b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Nov 2014 10:46:56 -0600 Subject: Fixing bug number --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 3fb71d9..899fa03 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,7 +2,7 @@ indicator-sound (12.10.2+14.10.20141010-0ubuntu8) UNRELEASED; urgency=medium * Remove various Vala warnings * Show notifications on volume change (LP: #1378564, #1378961) - * Warn on high audio levels when using headphones (LP: #123633, #1373404) + * Warn on high audio levels when using headphones (LP: #1232633, #1373404) * service.vala: don't call set_volume unnecessarily (LP: #1381871) * Integration test for audio roles * Integration test for silent mode -- cgit v1.2.3 From 08bcdc3b069c4c5ce7cb2a769daa8573fce5cd5d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Nov 2014 10:48:22 -0600 Subject: Missed part of a merge --- src/volume-control.vala | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index 295ebf5..6f22dc5 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -604,16 +604,6 @@ public class VolumeControl : Object { /* Using this to detect whether we're on the phone or not */ if (_pulse_use_stream_restore) { -<<<<<<< TREE - if (volume == 0.0) - _notification.update (_("Volume"), "", "audio-volume-muted"); - if (volume > 0.0 && volume <= 0.33) - _notification.update (_("Volume"), "", "audio-volume-low"); - if (volume > 0.33 && volume <= 0.66) - _notification.update (_("Volume"), "", "audio-volume-medium"); - if (volume > 0.66 && volume <= 1.0) - _notification.update (_("Volume"), "", "audio-volume-high"); -======= /* Watch for extreme */ if (volume > 0.75 && _active_port_headphone) high_volume = true; -- cgit v1.2.3 From 2f0aba374502b7ea660fce49f70e3ea972725685 Mon Sep 17 00:00:00 2001 From: CI bot Date: Wed, 5 Nov 2014 17:56:30 +0000 Subject: Releasing 12.10.2+15.04.20141105-0ubuntu1 --- debian/changelog | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 899fa03..93626ad 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ -indicator-sound (12.10.2+14.10.20141010-0ubuntu8) UNRELEASED; urgency=medium +indicator-sound (12.10.2+15.04.20141105-0ubuntu1) vivid; urgency=medium + [ Ted Gould ] * Remove various Vala warnings * Show notifications on volume change (LP: #1378564, #1378961) * Warn on high audio levels when using headphones (LP: #1232633, #1373404) @@ -9,7 +10,7 @@ indicator-sound (12.10.2+14.10.20141010-0ubuntu8) UNRELEASED; urgency=medium * Ensure the greeter menu matches whether song metadata should be shown, and update the metadata based on the new setting. (LP: #1358340) - -- Ted Gould Wed, 05 Nov 2014 10:42:12 -0600 + -- Ubuntu daily release Wed, 05 Nov 2014 17:56:29 +0000 indicator-sound (12.10.2+14.10.20141010-0ubuntu1) utopic; urgency=low -- cgit v1.2.3 From e0eac1c9d9a050dc44d0883f556753f6f8d1a7b6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 2 Dec 2014 18:55:00 -0600 Subject: Moving the notification into the service --- src/service.vala | 62 +++++++++++++++++++++++----- src/volume-control.vala | 105 ++++++++++-------------------------------------- 2 files changed, 74 insertions(+), 93 deletions(-) diff --git a/src/service.vala b/src/service.vala index fd0c08d..1a9034b 100644 --- a/src/service.vala +++ b/src/service.vala @@ -19,6 +19,8 @@ public class IndicatorSound.Service: Object { public Service (MediaPlayerList playerlist) { + sync_notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted"); + this.settings = new Settings ("com.canonical.indicator.sound"); this.sharedsettings = new Settings ("com.ubuntu.sound"); @@ -143,7 +145,7 @@ public class IndicatorSound.Service: Object { } /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */ - this.actions.change_action_state ("volume", this.volume_control.get_volume () / this.max_volume); + this.actions.change_action_state ("volume", this.volume_control.volume / this.max_volume); } } @@ -168,6 +170,7 @@ public class IndicatorSound.Service: Object { bool syncing_preferred_players = false; AccountsServiceUser? accounts_service = null; bool export_to_accounts_service = false; + private Notify.Notification sync_notification; /* Maximum volume as a scaling factor between the volume action's state and the value in * this.volume_control. See create_volume_action(). @@ -179,8 +182,8 @@ public class IndicatorSound.Service: Object { void activate_scroll_action (SimpleAction action, Variant? param) { int delta = param.get_int32(); /* positive for up, negative for down */ - double v = this.volume_control.get_volume () + volume_step_percentage * delta; - this.volume_control.set_volume (v.clamp (0.0, this.max_volume)); + double v = this.volume_control.volume + volume_step_percentage * delta; + this.volume_control.volume = v.clamp (0.0, this.max_volume); /* TODO: Don't want to mess up the desktop today, but we should remove this scrolling change and merge that into volume control's notification */ @@ -238,7 +241,7 @@ public class IndicatorSound.Service: Object { } void update_root_icon () { - double volume = this.volume_control.get_volume (); + double volume = this.volume_control.volume; string icon; if (this.volume_control.mute) icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel"; @@ -268,6 +271,44 @@ public class IndicatorSound.Service: Object { root_action.set_state (builder.end()); } + void update_sync_notification () { + /* Determine Label */ + string volume_label = ""; + if (volume_control.high_volume) + volume_label = _("High volume"); + + /* Choose an icon */ + string icon = "audio-volume-muted"; + if (volume_control.volume <= 0.0) + icon = "audio-volume-muted"; + else if (volume_control.volume <= 0.3) + icon = "audio-volume-low"; + else if (volume_control.volume <= 0.7) + icon = "audio-volume-medium"; + else + icon = "audio-volume-high"; + + /* Check tint */ + string tint = "false"; + if (volume_control.high_volume) + tint = "true"; + + /* Put it all into the notification */ + sync_notification.clear_hints (); + sync_notification.update (_("Volume"), volume_label, icon); + sync_notification.set_hint ("value", (int32)(volume_control.volume * 100.0)); + sync_notification.set_hint ("x-canonical-value-bar-tint", tint); + sync_notification.set_hint ("x-canonical-private-synchronous", "true"); + sync_notification.set_hint ("x-canonical-non-shaped-icon", "true"); + + /* Show it */ + try { + sync_notification.show (); + } catch (GLib.Error e) { + warning("Unable to send volume change notification: %s", e.message); + } + } + Action create_silent_mode_action () { bool silentNow = false; if (this.accounts_service != null) { @@ -349,6 +390,7 @@ public class IndicatorSound.Service: Object { volume_action.set_state (new Variant.double (volume / this.max_volume)); this.update_root_icon (); + this.update_sync_notification (); } Action create_volume_action () { @@ -359,20 +401,20 @@ public class IndicatorSound.Service: Object { * volume_control.set_volume(). */ - double volume = this.volume_control.get_volume () / this.max_volume; + double volume = this.volume_control.volume / this.max_volume; var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (volume)); volume_action.change_state.connect ( (action, val) => { double v = val.get_double () * this.max_volume; - volume_control.set_volume (v.clamp (0.0, this.max_volume)); + volume_control.volume = v.clamp (0.0, this.max_volume); }); /* activating this action changes the volume by the amount given in the parameter */ volume_action.activate.connect ( (action, param) => { int delta = param.get_int32 (); - double v = volume_control.get_volume () + volume_step_percentage * delta; - volume_control.set_volume (v.clamp (0.0, this.max_volume)); + double v = volume_control.volume + volume_step_percentage * delta; + volume_control.volume = v.clamp (0.0, this.max_volume); }); this.volume_control.volume_changed.connect (volume_changed); @@ -383,10 +425,10 @@ public class IndicatorSound.Service: Object { } Action create_mic_volume_action () { - var volume_action = new SimpleAction.stateful ("mic-volume", null, new Variant.double (this.volume_control.get_mic_volume ())); + var volume_action = new SimpleAction.stateful ("mic-volume", null, new Variant.double (this.volume_control.mic_volume)); volume_action.change_state.connect ( (action, val) => { - volume_control.set_mic_volume (val.get_double ()); + volume_control.mic_volume = val.get_double (); }); this.volume_control.mic_volume_changed.connect ( (volume) => { diff --git a/src/volume-control.vala b/src/volume-control.vala index 6f22dc5..d9a734c 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -68,7 +68,6 @@ public class VolumeControl : Object private uint _accountservice_volume_timer = 0; private bool _send_next_local_volume = false; private double _account_service_volume = 0.0; - private Notify.Notification _notification; private bool _active_port_headphone = false; public signal void volume_changed (double v); @@ -91,12 +90,6 @@ public class VolumeControl : Object _mute_cancellable = new Cancellable (); _volume_cancellable = new Cancellable (); - Notify.init ("Volume"); - _notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted"); - _notification.set_hint ("value", 0); - _notification.set_hint ("x-canonical-private-synchronous", "true"); - _notification.set_hint ("x-canonical-non-shaped-icon", "true"); - setup_accountsservice.begin (); this.reconnect_to_pulse (); @@ -594,74 +587,15 @@ public class VolumeControl : Object set_volume_active_role.begin (); else context.get_server_info (server_info_cb_for_set_volume); + + high_volume = volume > 0.75 && _active_port_headphone; + return true; } else { return false; } } - public void set_volume (double volume) - { - /* Using this to detect whether we're on the phone or not */ - if (_pulse_use_stream_restore) { - /* Watch for extreme */ - if (volume > 0.75 && _active_port_headphone) - high_volume = true; - else - high_volume = false; - - /* Determine Label */ - string volume_label = ""; - if (high_volume) - volume_label = _("High volume"); - - /* Choose an icon */ - string icon = "audio-volume-muted"; - if (volume <= 0.0) - icon = "audio-volume-muted"; - else if (volume <= 0.3) - icon = "audio-volume-low"; - else if (volume <= 0.7) - icon = "audio-volume-medium"; - else - icon = "audio-volume-high"; - - /* Choose a sound */ - string? sound = null; - if (!((_active_sink_input >= 0) && (_active_sink_input < _valid_roles.length) - && (_valid_roles[_active_sink_input] == "multimedia"))) - sound = "/usr/share/sounds/ubuntu/stereo/message.ogg"; - - /* Check tint */ - string tint = "false"; - if (high_volume) - tint = "true"; - - /* Put it all into the notification */ - _notification.clear_hints (); - _notification.update (_("Volume"), volume_label, icon); - _notification.set_hint ("value", (int32)(volume * 100.0)); - /* TODO: Removing sound until we can get all the roles cleaned up for - when to play it. We expect this to come back, but in another landing. - _notification.set_hint ("sound-file", sound); - */ - _notification.set_hint ("x-canonical-value-bar-tint", tint); - _notification.set_hint ("x-canonical-private-synchronous", "true"); - _notification.set_hint ("x-canonical-non-shaped-icon", "true"); - - /* Show it */ - try { - _notification.show (); - } catch (GLib.Error e) { - warning("Unable to send volume change notification: %s", e.message); - } - } - - if (set_volume_internal (volume)) { - start_local_volume_timer(); - } - } - void set_mic_volume_success_cb (Context c, int success) { if ((bool)success) @@ -676,23 +610,28 @@ public class VolumeControl : Object } } - public void set_mic_volume (double volume) - { - return_if_fail (context.get_state () == Context.State.READY); - - _mic_volume = volume; - - context.get_server_info (set_mic_volume_get_server_info_cb); + public double volume { + get { + return _volume; + } + set { + if (set_volume_internal (value)) { + start_local_volume_timer(); + } + } } - public double get_volume () - { - return _volume; - } + public double mic_volume { + get { + return _mic_volume; + } + set { + return_if_fail (context.get_state () == Context.State.READY); - public double get_mic_volume () - { - return _mic_volume; + _mic_volume = value; + + context.get_server_info (set_mic_volume_get_server_info_cb); + } } /* PulseAudio Dbus (Stream Restore) logic */ -- cgit v1.2.3 From f6505dfead05c0e341d7ece63510e621a45e0325 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 09:12:01 -0600 Subject: Remove the sync notification on scroll setting --- data/com.canonical.indicator.sound.gschema.xml | 9 ----- src/service.vala | 47 ++++++++------------------ 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/data/com.canonical.indicator.sound.gschema.xml b/data/com.canonical.indicator.sound.gschema.xml index 102a1db..a346c0d 100644 --- a/data/com.canonical.indicator.sound.gschema.xml +++ b/data/com.canonical.indicator.sound.gschema.xml @@ -32,15 +32,6 @@ On start up volume should not be muted. - - true - Initial setting for showing notify-osd notification on scroll volume-change - - When using the mouse scroll-wheel over the indicator-sound icon, the volume changes. - Enabling this setting, every scroll volume-change a notify-osd bubble with the - updated volume value will be shown (if supported by your notification daemon). - - true Whether or not to show the sound indicator in the menu bar. diff --git a/src/service.vala b/src/service.vala index 1a9034b..c74b2eb 100644 --- a/src/service.vala +++ b/src/service.vala @@ -72,14 +72,6 @@ public class IndicatorSound.Service: Object { this.sync_preferred_players (); }); - if (settings.get_boolean ("show-notify-osd-on-scroll")) { - List caps = Notify.get_server_caps (); - if (caps.find_custom ("x-canonical-private-synchronous", strcmp) != null) { - this.notification = new Notify.Notification ("indicator-sound", "", ""); - this.notification.set_hint ("x-canonical-private-synchronous", "indicator-sound"); - } - } - sharedsettings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET); } @@ -166,7 +158,6 @@ public class IndicatorSound.Service: Object { uint player_action_update_id; bool mute_blocks_sound; uint sound_was_blocked_timeout_id; - Notify.Notification notification; bool syncing_preferred_players = false; AccountsServiceUser? accounts_service = null; bool export_to_accounts_service = false; @@ -184,29 +175,6 @@ public class IndicatorSound.Service: Object { double v = this.volume_control.volume + volume_step_percentage * delta; this.volume_control.volume = v.clamp (0.0, this.max_volume); - - /* TODO: Don't want to mess up the desktop today, but we should remove this - scrolling change and merge that into volume control's notification */ - if (this.notification != null) { - string icon; - if (v <= 0.0) - icon = "notification-audio-volume-off"; - else if (v <= 0.3) - icon = "notification-audio-volume-low"; - else if (v <= 0.7) - icon = "notification-audio-volume-medium"; - else - icon = "notification-audio-volume-high"; - - this.notification.update ("indicator-sound", "", icon); - this.notification.set_hint ("value", ((int32) (100 * v / this.max_volume)).clamp (-1, 101)); - try { - this.notification.show (); - } - catch (Error e) { - warning ("unable to show notification: %s", e.message); - } - } } void activate_desktop_settings (SimpleAction action, Variant? param) { @@ -271,7 +239,22 @@ public class IndicatorSound.Service: Object { root_action.set_state (builder.end()); } + /* TODO: Update these if the notification server leaves the bus and restarts */ + private bool check_sync_notification = false; + private bool support_sync_notification = false; + void update_sync_notification () { + if (!check_sync_notification) { + List caps = Notify.get_server_caps (); + if (caps.find_custom ("x-canonical-private-synchronous", strcmp) != null) { + support_sync_notification = true; + } + check_sync_notification = true; + } + + if (!support_sync_notification) + return; + /* Determine Label */ string volume_label = ""; if (volume_control.high_volume) -- cgit v1.2.3 From 57982f343b03175c20a4b51ccb5c853588613935 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 09:52:32 -0600 Subject: Add an action to track whether the indicator is shown so that we can not show notifications if it is open --- src/service.vala | 5 +++++ src/sound-menu.vala | 1 + 2 files changed, 6 insertions(+) diff --git a/src/service.vala b/src/service.vala index c74b2eb..48b0cbe 100644 --- a/src/service.vala +++ b/src/service.vala @@ -146,6 +146,7 @@ public class IndicatorSound.Service: Object { { "scroll", activate_scroll_action, "i", null, null }, { "desktop-settings", activate_desktop_settings, null, null, null }, { "phone-settings", activate_phone_settings, null, null, null }, + { "indicator-shown", null, null, "@b false", null }, }; MainLoop loop; @@ -255,6 +256,10 @@ public class IndicatorSound.Service: Object { if (!support_sync_notification) return; + var shown_action = actions.lookup_action ("indicator-shown") as SimpleAction; + if (shown_action != null && shown_action.get_state().get_boolean()) + return; + /* Determine Label */ string volume_label = ""; if (volume_control.high_volume) diff --git a/src/sound-menu.vala b/src/sound-menu.vala index 3881faf..96dd143 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -60,6 +60,7 @@ public class SoundMenu: Object root_item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); root_item.set_attribute ("x-canonical-scroll-action", "s", "indicator.scroll"); root_item.set_attribute ("x-canonical-secondary-action", "s", "indicator.mute"); + root_item.set_attribute ("submenu-action", "s", "indicator.indicator-shown"); root_item.set_submenu (this.menu); this.root = new Menu (); -- cgit v1.2.3 From 31cef82276a7f6b36b9128abc770d1b6b07fffe5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 10:32:44 -0600 Subject: Hide notification when the menu is shown --- src/service.vala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/service.vala b/src/service.vala index 48b0cbe..dbf7d35 100644 --- a/src/service.vala +++ b/src/service.vala @@ -73,6 +73,18 @@ public class IndicatorSound.Service: Object { }); sharedsettings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET); + + /* Hide the notification when the menu is shown */ + var shown_action = actions.lookup_action ("indicator-shown") as SimpleAction; + shown_action.change_state.connect ((state) => { + if (state.get_boolean()) { + try { + sync_notification.close(); + } catch (Error e) { + warning("Unable to close synchronous volume notification: %s", e.message); + } + } + }); } ~Service() { -- cgit v1.2.3 From 119ae3decb89f0066dd5abf53d0ab1bef49c15c8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 11:43:41 -0600 Subject: Ensuring that if high volume changes we also show a notification (i.e. the headphones were plugged in) --- src/service.vala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/service.vala b/src/service.vala index dbf7d35..1f9b880 100644 --- a/src/service.vala +++ b/src/service.vala @@ -51,7 +51,7 @@ public class IndicatorSound.Service: Object { this.actions.add_action (this.create_mute_action ()); this.actions.add_action (this.create_volume_action ()); this.actions.add_action (this.create_mic_volume_action ()); - this.actions.add_action (this.create_high_volume_actions ()); + this.actions.add_action (this.create_high_volume_action ()); this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); @@ -440,11 +440,13 @@ public class IndicatorSound.Service: Object { return volume_action; } - Action create_high_volume_actions () { + Action create_high_volume_action () { var high_volume_action = new SimpleAction.stateful("high-volume", null, new Variant.boolean (this.volume_control.high_volume)); - this.volume_control.notify["high-volume"].connect( () => - high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume))); + this.volume_control.notify["high-volume"].connect( () => { + high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume)); + update_sync_notification(); + }); return high_volume_action; } -- cgit v1.2.3 From 66cd2203d5fcee99d3264bc6f23c8d4683c299bf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 16:30:23 -0600 Subject: Switch from having custom signals for volume changing to using the property change signals. --- src/service.vala | 24 +++++++++++------------- src/volume-control.vala | 19 ++++++++----------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/service.vala b/src/service.vala index 1f9b880..c7e29e7 100644 --- a/src/service.vala +++ b/src/service.vala @@ -383,16 +383,6 @@ public class IndicatorSound.Service: Object { return mute_action; } - void volume_changed (double volume) { - var volume_action = this.actions.lookup_action ("volume") as SimpleAction; - - /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */ - volume_action.set_state (new Variant.double (volume / this.max_volume)); - - this.update_root_icon (); - this.update_sync_notification (); - } - Action create_volume_action () { /* The action's state is between be in [0.0, 1.0] instead of [0.0, * max_volume], so that we don't need to update the slider menu item @@ -417,7 +407,15 @@ public class IndicatorSound.Service: Object { volume_control.volume = v.clamp (0.0, this.max_volume); }); - this.volume_control.volume_changed.connect (volume_changed); + this.volume_control.notify["volume"].connect (() => { + var vol_action = this.actions.lookup_action ("volume") as SimpleAction; + + /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */ + vol_action.set_state (new Variant.double (this.volume_control.volume / this.max_volume)); + + this.update_root_icon (); + this.update_sync_notification (); + }); this.volume_control.bind_property ("ready", volume_action, "enabled", BindingFlags.SYNC_CREATE); @@ -431,8 +429,8 @@ public class IndicatorSound.Service: Object { volume_control.mic_volume = val.get_double (); }); - this.volume_control.mic_volume_changed.connect ( (volume) => { - volume_action.set_state (new Variant.double (volume)); + this.volume_control.notify["mic-volume"].connect ( () => { + volume_action.set_state (new Variant.double (this.volume_control.mic_volume)); }); this.volume_control.bind_property ("ready", volume_action, "enabled", BindingFlags.SYNC_CREATE); diff --git a/src/volume-control.vala b/src/volume-control.vala index d9a734c..22212d5 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -70,9 +70,6 @@ public class VolumeControl : Object private double _account_service_volume = 0.0; private bool _active_port_headphone = false; - public signal void volume_changed (double v); - public signal void mic_volume_changed (double v); - /** true when connected to the pulse server */ public bool ready { get; set; } @@ -190,10 +187,10 @@ public class VolumeControl : Object _volume != volume_to_double (i.volume.max ())) { _volume = volume_to_double (i.volume.max ()); - volume_changed (_volume); + this.notify_property("volume"); start_local_volume_timer(); } else if (this._active_port_headphone != old_active_port_headphone) { - volume_changed (_volume); + this.notify_property("volume"); } } @@ -205,7 +202,7 @@ public class VolumeControl : Object if (_mic_volume != volume_to_double (i.volume.values[0])) { _mic_volume = volume_to_double (i.volume.values[0]); - mic_volume_changed (_mic_volume); + this.notify_property ("mic-volume"); } } @@ -261,7 +258,7 @@ public class VolumeControl : Object if (volume != cvolume) { /* Someone else changed the volume for this role, reflect on the indicator */ _volume = volume_to_double (volume); - volume_changed (_volume); + this.notify_property("volume"); start_local_volume_timer(); } } @@ -304,7 +301,7 @@ public class VolumeControl : Object iter.next ("(uu)", &type, &volume); _volume = volume_to_double (volume); - volume_changed (_volume); + this.notify_property("volume"); start_local_volume_timer(); } catch (GLib.Error e) { warning ("unable to get volume for active role %s (%s)", sink_input_objp, e.message); @@ -521,7 +518,7 @@ public class VolumeControl : Object private void set_volume_success_cb (Context c, int success) { if ((bool)success) - volume_changed (_volume); + this.notify_property("volume"); } private void sink_info_set_volume_cb (Context c, SinkInfo? i, int eol) @@ -567,7 +564,7 @@ public class VolumeControl : Object new Variant ("(ssv)", "org.PulseAudio.Ext.StreamRestore1.RestoreEntry", "Volume", volume), null, DBusCallFlags.NONE, -1); - volume_changed (_volume); + this.notify_property("volume"); } catch (GLib.Error e) { lock (_pa_volume_sig_count) { _pa_volume_sig_count--; @@ -599,7 +596,7 @@ public class VolumeControl : Object void set_mic_volume_success_cb (Context c, int success) { if ((bool)success) - mic_volume_changed (_mic_volume); + this.notify_property ("mic-volume"); } void set_mic_volume_get_server_info_cb (PulseAudio.Context c, PulseAudio.ServerInfo? i) { -- cgit v1.2.3 From 91b54a8a59cd51813d750efbe01203b7fe1d0e3c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Dec 2014 11:24:48 -0600 Subject: Encapsulate high volume better --- src/volume-control.vala | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/volume-control.vala b/src/volume-control.vala index 22212d5..193e621 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -77,7 +77,11 @@ public class VolumeControl : Object public bool active_mic { get; private set; default = false; } /** true when high volume warnings should be shown */ - public bool high_volume { get; set; } + public bool high_volume { + get { + return this._volume > 0.75 && _active_port_headphone; + } + } public VolumeControl () { @@ -152,7 +156,7 @@ public class VolumeControl : Object private void sink_info_cb_for_props (Context c, SinkInfo? i, int eol) { - bool old_active_port_headphone = this._active_port_headphone; + bool old_high_volume = this.high_volume; if (i == null) return; @@ -189,8 +193,10 @@ public class VolumeControl : Object _volume = volume_to_double (i.volume.max ()); this.notify_property("volume"); start_local_volume_timer(); - } else if (this._active_port_headphone != old_active_port_headphone) { - this.notify_property("volume"); + } + + if (this.high_volume != old_high_volume) { + this.notify_property("high-volume"); } } @@ -579,13 +585,18 @@ public class VolumeControl : Object return false; if (_volume != volume) { + var old_high_volume = this.high_volume; + _volume = volume; if (_pulse_use_stream_restore) set_volume_active_role.begin (); else context.get_server_info (server_info_cb_for_set_volume); - high_volume = volume > 0.75 && _active_port_headphone; + this.notify_property("volume"); + + if (this.high_volume != old_high_volume) + this.notify_property("high-volume"); return true; } else { -- cgit v1.2.3 From a35e1d48e54ac59aecbf61aaba5e9dfb0cf151e0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 21 Jan 2015 17:10:22 -0600 Subject: Checkpoint, nothing works --- tests/pa-mock.c | 299 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 tests/pa-mock.c diff --git a/tests/pa-mock.c b/tests/pa-mock.c new file mode 100644 index 0000000..6f4e6ad --- /dev/null +++ b/tests/pa-mock.c @@ -0,0 +1,299 @@ + +#include + +#ifdef G_LOG_DOMAIN +#undef G_LOG_DOMAIN +#endif +#define G_LOG_DOMAIN "PA-Mock" + +G_DEFINE_QUARK("pa-mock-state-cb-list", state_cb); +typedef struct { + pa_context_notify_cb_t cb; + gpointer user_data; +} state_cb_t; + +/* ******************************* + * context.h + * *******************************/ + +static void +context_weak_cb (gpointer user_data, GObject * oldobj) +{ + g_debug("Finalizing context: %p", oldobj); +} + +pa_context * +pa_context_new_with_proplist (pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist) +{ + GObject * gctx = g_object_new(G_TYPE_OBJECT); + pa_context * ctx = (pa_context *)gctx; + + g_debug("Creating new context: %p", ctx); + g_object_weak_ref(gctx, context_weak_cb, NULL); + + return ctx; +} + +void +pa_context_unref (pa_context *c) { + g_return_if_fail(G_IS_OBJECT(c)); + g_object_unref(G_OBJECT(c)); +} + +void +pa_context_ref (pa_context *c) { + g_return_if_fail(G_IS_OBJECT(c)); + g_object_ref(G_OBJECT(c)); +} + +int +pa_context_connect (pa_context *c, const char *server, pa_context_flags_t flags, const pa_spawn_api *api) +{ + g_return_if_fail(G_IS_OBJECT(c)); + g_debug("Context Connect"); + return 0; +} + +void +pa_context_disconnect (pa_context *c) +{ + g_return_if_fail(G_IS_OBJECT(c)); + g_debug("Context Disconnect"); +} + +int +pa_context_errno (pa_context *c) +{ + g_return_val_if_fail(G_IS_OBJECT(c), -1); + + return 0; +} + +static void +state_cb_list_destroy (gpointer data) +{ + GList * statelist = (GList *)data; + g_list_free_full(statelist, g_free); +} + +void +pa_context_set_state_callback (pa_context *c, pa_context_notify_cb_t cb, void *userdata) +{ + g_return_if_fail(G_IS_OBJECT(c)); + g_return_if_fail(cb != NULL); + + state_cb_t * state_cb = g_new0(state_cb_t, 1); + state_cb->cb = cb; + state_cb->userdata = userdata; + + GList * statelist = g_object_get_qdata(G_OBJECT(c), state_cb_quark); + statelist = g_list_append(statelist, state_cb); + g_object_set_qdata_full(G_OBJECT(c), state_cb_quark, state_cb, state_cb_list_destroy); +} + +pa_context_state_t +pa_context_get_state (pa_context *c) +{ + g_return_if_fail(G_IS_OBJECT(c)); + + return PA_CONTEXT_READY; +} + +/* ******************************* + * introspect.h + * *******************************/ + +typedef struct { + pa_server_info_cb_t cb; + gpointer userdata; + pa_context * context; +} get_server_info_t; + +static void +get_server_info_free (gpointer data) +{ + get_server_info_t * info = (get_server_info_t *)data; + g_object_unref(info->context); + g_free(info); +} + +static gboolean +get_server_info_cb (gpointer data) +{ + pa_server_info server = { + .user_name = "user", + .host_name = "host", + .server_version = "1.2.3", + .server_name = "server", + .sample_spec = , + .default_sink_name = "default-sink", + .default_source_name = "default-source", + .cookie = 1234, + .channel_map = { + .channels = 0 + } + }; + get_server_info_t * info = (get_server_info_t *)data; + + info->cb(info->context, &server, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_get_server_info (pa_context *c, pa_server_info_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), NULL); + g_return_val_if_fail(cb != NULL, NULL); + + get_server_info_t * info = g_new(get_server_info_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = g_objet_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_server_info_cb, + info, + get_server_info_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_sink_info_cb_t cb; + gpointer userdata; + pa_context * context; + uint32_t index; +} get_sink_info_t; + +static void +get_sink_info_free (gpointer data) +{ + get_sink_info_t * info = (get_sink_info_t *)data; + g_object_unref(info->context); + g_free(info); +} + +static gboolean +get_info_info_cb (gpointer data) +{ + pa_sink_info sink = { + .name = "default-sink", + .index = 0, + .description = "Default Sink", + .channel_map = { + .channels = 0 + } + }; + get_sink_info_t * info = (get_sink_info_t *)data; + + info->cb(info->context, &sink, 1, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_get_sink_info_by_name (pa_context *c, const gchar * name, pa_sink_info_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), NULL); + g_return_val_if_fail(g_strcmp0(name, "default-sink") == 0, NULL); + g_return_val_if_fail(cb != NULL, NULL); + + get_sink_info_t * info = g_new(get_sink_info_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = g_objet_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_sink_info_cb, + info, + get_sink_info_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +pa_operation* +pa_context_get_sink_info_list (pa_context *c, pa_sink_info_cb_t cb, void *userdata) +{ + /* Only have one today, so this is the same */ + return pa_context_get_sink_info_by_name(c, "default-sink", cb, userdata); +} + + +pa_context_get_sink_input_info +pa_context_get_source_info_by_name +pa_context_get_source_output_info +pa_context_get_state + +pa_context_set_sink_mute_by_index +pa_context_set_sink_volume_by_index +pa_context_set_source_volume_by_name +pa_context_set_subscribe_callback +pa_context_subscribe + +pa_cvolume_init +pa_cvolume_max +pa_cvolume_scale +pa_cvolume_set + +/* ******************************* + * glib-mainloop.h + * *******************************/ + +struct pa_glib_mainloop { + GMainContext * context; +}; + +struct pa_mainloop_api mock_mainloop = { 0 }; + +pa_mainloop_api * +pa_glib_mainloop_get_api (pa_glib_mainloop * g) +{ + return &mock_mainloop; +} + +pa_glib_mainloop * +pa_glib_mainloop_new (GMainContext * c) +{ + pa_glib_mainloop * loop = g_new0(pa_glib_mainloop, 1); + + if (c == NULL) + loop->context = g_main_context_default(); + else + loop->context = c; + + g_main_context_ref(loop->context); + return loop; +} + +void +pa_glib_mainloop_free (pa_glib_mainloop * g) +{ + g_main_context_unref(g->context); + g_free(g); +} + +/* ******************************* + * operation.h + * *******************************/ + +void +pa_operation_unref (pa_operation * operation) +{ + g_return_if_fail(G_IS_OBJECT(operation)); + g_object_unref(G_OBJECT(operation)); +} + +pa_proplist_free +pa_proplist_gets +pa_proplist_new +pa_proplist_sets + +pa_strerror + +pa_sw_volume_from_dB + -- cgit v1.2.3 From b7b3a850299741e61c88e0471fdb797ae77c70cc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 26 Jan 2015 15:26:28 -0600 Subject: Checkpoint, need some refactoring --- tests/pa-mock.c | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 235 insertions(+), 18 deletions(-) diff --git a/tests/pa-mock.c b/tests/pa-mock.c index 6f4e6ad..906e3de 100644 --- a/tests/pa-mock.c +++ b/tests/pa-mock.c @@ -7,15 +7,18 @@ #define G_LOG_DOMAIN "PA-Mock" G_DEFINE_QUARK("pa-mock-state-cb-list", state_cb); -typedef struct { - pa_context_notify_cb_t cb; - gpointer user_data; -} state_cb_t; +G_DEFINE_QUARK("pa-mock-subscribe-callback", subscribe_cb); +G_DEFINE_QUARK("pa-mock-subscribe-mask", subscribe_mask); /* ******************************* * context.h * *******************************/ +typedef struct { + pa_context_notify_cb_t cb; + gpointer user_data; +} state_cb_t; + static void context_weak_cb (gpointer user_data, GObject * oldobj) { @@ -223,22 +226,128 @@ pa_context_get_sink_info_list (pa_context *c, pa_sink_info_cb_t cb, void *userda return pa_context_get_sink_info_by_name(c, "default-sink", cb, userdata); } +typedef struct { + pa_sink_info_cb_t cb; + gpointer userdata; + pa_context * context; +} get_sink_input_info_t; + +static void +get_sink_info_free (gpointer data) +{ + get_sink_input_info_t * info = (get_sink_info_t *)data; + pa_context_unref(info->context); + g_free(info); +} + +static gboolean +get_sink_info_cb (gpointer data) +{ + pa_sink_input_info sink = { + .name = "default-sink" + }; + get_sink_input_info_t * info = (get_sink_input_info_t *)data; + + info->cb(info->context, &sink, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation * +pa_context_get_sink_input_info (pa_context *c, pa_sink_input_info_cb_t cb, void * userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), NULL); + g_return_val_if_fail(cb != NULL, NULL); + + get_sink_input_info_t * info = g_new(get_sink_input_info_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = g_objet_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_sink_input_info_cb, + info, + get_sink_input_info_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} -pa_context_get_sink_input_info +#if 0 pa_context_get_source_info_by_name pa_context_get_source_output_info -pa_context_get_state pa_context_set_sink_mute_by_index pa_context_set_sink_volume_by_index pa_context_set_source_volume_by_name -pa_context_set_subscribe_callback -pa_context_subscribe +#endif + +/* ******************************* + * subscribe.h + * *******************************/ + +typedef struct { + pa_context_subscribe_cb_t cb; + gointer userdata; + GObject * context; + pa_subscription_mask_t mask; +} subscribe_mask_t; + +static void +subscribe_mask_free (gpointer data) +{ + subscribe_mask_t * mask_data = (subscribe_mask_t *)data; + g_object_unref(mask_data->context); + g_free(mask_data); +} + +static gboolean +subscribe_mask_cb (gpointer data) +{ + subscribe_mask_t * mask_data = (subscribe_mask_t *)data; + g_object_set_qdata(mask_data->context, subscribe_mask_quark, GINT_TO_POINTER(mask_data->mask)); + mask_data->cb(mask_data->context, 1, mask_data->userdata); + return G_SOURCE_REMOVE; +} + +pa_operation * +pa_context_subscribe (pa_context * c, pa_subscription_mask_t mask, pa_context_success_cb_t callback, void * userdata) +{ + g_return_if_fail(G_IS_OBJECT(c)); + + subscribe_mask_t * data = g_new0(subscribe_mask_t, 1); + data->cb = callback; + data->userdata = userdata; + data->context = g_object_ref(G_OBJECT(c)); + data->mask = mask; -pa_cvolume_init -pa_cvolume_max -pa_cvolume_scale -pa_cvolume_set + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + subscribe_mask_cb, + data, + subscribe_mask_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_context_subscribe_cb_t cb; + gointer userdata; +} subscribe_cb_t; + +void +pa_context_set_subscribe_callback (pa_context * c, pa_context_subscribe_cb_t callback, void * userdata) +{ + g_return_if_fail(G_IS_OBJECT(c)); + + subscribe_cb_t * sub = g_new0(subscribe_cb_t, 1); + sub->cb = callback; + sub->userdata = userdata; + + g_object_set_qdata_full(c, subscribe_cb_quark, sub, g_free); +} /* ******************************* * glib-mainloop.h @@ -288,12 +397,120 @@ pa_operation_unref (pa_operation * operation) g_object_unref(G_OBJECT(operation)); } -pa_proplist_free -pa_proplist_gets -pa_proplist_new -pa_proplist_sets +/* ******************************* + * proplist.h + * *******************************/ + +pa_proplist * +pa_proplist_new (void) +{ + return (pa_proplist *)g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); +} + +void +pa_proplist_free (pa_proplist * p) +{ + g_return_if_fail(p != NULL); + g_hash_table_destroy((GHashTable *)p); +} + +const char * +pa_proplist_gets (pa_proplist * p, const char * key) +{ + g_return_val_if_fail(p != NULL, NULL); + g_return_val_if_fail(key != NULL, NULL); + return g_hash_table_lookup((GHashTable *)p, key); +} + +int +pa_proplist_sets (pa_proplist *p, const char * key, const char * value) +{ + g_return_val_if_fail(p != NULL, -1); + g_return_val_if_fail(key != NULL, -1); + g_return_val_if_fail(value != NULL, -1); -pa_strerror + g_hash_table_insert((GHashTable *)p, g_strdup(key), g_strdup(value)); + return 0; +} -pa_sw_volume_from_dB +/* ******************************* + * error.h + * *******************************/ + +const char * +pa_strerror (int error) +{ + return "This is error text"; +} + +/* ******************************* + * volume.h + * *******************************/ + +pa_volume_t +pa_sw_volume_from_dB (double f) +{ + double linear = pow(10.0, f / 20.0); + return (pa_volume_t) PA_CLAMP_VOLUME((uint64_t) lround(cbrt(linear) * PA_VOLUME_NORM)); +} + +pa_cvolume * +pa_cvolume_init (pa_cvolume * cvol) +{ + g_return_val_if_fail(cvol != NULL, NULL); + + cvol->channels = 0; + + unsigned int i; + for (i = 0; i < PA_CHANNELS_MAX; i++) + cvol->values[i] = PA_VOLUME_INVALID; + + return cvol; +} + +pa_cvolume * +pa_cvolume_set (pa_cvolume * cvol, unsigned channels, pa_volume_t volume) +{ + g_return_val_if_fail(cvol != NULL, NULL); + g_return_val_if_fail(channels > 0, NULL); + g_return_val_if_fail(channels <= PA_CHANNELS_MAX, NULL); + + cvol->channels = channels; + + unsigned int i; + for (i = 0; i < channels; i++) + cvol->values[i] = PA_CLAMP_VOLUME(volume); + + return cvol; +} + +pa_volume_t +pa_cvolume_max (const pa_cvolume * cvol) +{ + g_return_val_if_fail(cvol != NULL, NULL); + pa_volume_t max = PA_VOLUME_MUTED; + + unsigned int i; + for (i = 0; i < cvol->channels; i++) + max = MAX(max, cvol->values[i]); + + return max; +} + +pa_cvolume * +pa_cvolume_scale (pa_cvolume * cvol, pa_volume_t max) +{ + g_return_val_if_fail(cvol != NULL, NULL); + + pa_volume_t originalmax = pa_cvolume_max(cvol); + + if (originalmax <= PA_VOLUME_MUTED) + return pa_cvolume_set(cvol, cvol->channels, max); + + unsigned int i; + for (i = 0; i < channels; i++) + cvol->values[i] = PA_CLAMP_VOLUME( (cvol->values[i] * max) / originalmax ); + + return cvol; +} -- cgit v1.2.3 From 7200c1ba22c4c8155af58784b1dacdc0a06cf93a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 26 Jan 2015 16:16:41 -0600 Subject: All the code 'written' --- tests/pa-mock.c | 247 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 240 insertions(+), 7 deletions(-) diff --git a/tests/pa-mock.c b/tests/pa-mock.c index 906e3de..20fced9 100644 --- a/tests/pa-mock.c +++ b/tests/pa-mock.c @@ -274,14 +274,247 @@ pa_context_get_sink_input_info (pa_context *c, pa_sink_input_info_cb_t cb, void return oper; } -#if 0 -pa_context_get_source_info_by_name -pa_context_get_source_output_info +typedef struct { + pa_source_info_cb_t cb; + gpointer userdata; + pa_context * context; +} get_source_info_t; -pa_context_set_sink_mute_by_index -pa_context_set_sink_volume_by_index -pa_context_set_source_volume_by_name -#endif +static void +get_source_info_free (gpointer data) +{ + get_source_info_t * info = (get_source_info_t *)data; + g_object_unref(info->context); + g_free(info); +} + +static gboolean +get_source_info_cb (gpointer data) +{ + pa_source_info source = { + .name = "default-source" + }; + get_source_info_t * info = (get_source_info_t *)data; + + info->cb(info->context, &source, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_get_source_info_by_name (pa_context *c, const char * name, pa_source_info_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), NULL); + g_return_val_if_fail(cb != NULL, NULL); + + get_source_info_t * info = g_new(get_source_info_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = g_objet_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_source_info_cb, + info, + get_source_info_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_source_output_info_cb_t cb; + gpointer userdata; + pa_context * context; +} get_source_output_t; + +static void +get_source_output_free (gpointer data) +{ + get_source_output_t * info = (get_source_output_t *)data; + g_object_unref(info->context); + g_free(info); +} + +static gboolean +get_source_output_cb (gpointer data) +{ + pa_source_output_info source = { + .name = "default-source" + }; + get_source_output_t * info = (get_source_output_t *)data; + + info->cb(info->context, &source, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_get_source_output_info (pa_context *c, uint32_t idx, pa_source_output_info_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), NULL); + g_return_val_if_fail(cb != NULL, NULL); + + get_source_output_t * info = g_new(get_source_output_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = g_objet_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_source_output_cb, + info, + get_source_output_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_context_success_cb_t cb; + gpointer userdata; + int mute; +} set_sink_mute_t; + +static void +set_sink_mute_free (gpointer data) +{ + set_sink_mute_t * mute = (set_sink_mute_t *)data; + g_object_unref(mute->context); + g_free(mute); +} + +static gboolean +set_sink_mute_cb (gpointer data) +{ + set_sink_mute_t * mute = (set_sink_mute_t *)data; + + mute->cb(mute->context, 1, mute->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_set_sink_mute_by_index (pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), NULL); + g_return_val_if_fail(cb != NULL, NULL); + + set_sink_mute_t * data = g_new(set_sink_mute_t, 1); + data->cb = cb; + data->userdata = userdata; + data->context = g_objet_ref(c); + data->mute = mute; + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + set_sink_mute_cb, + data, + set_sink_mute_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_context_success_cb_t cb; + gpointer userdata; + pa_cvolume cvol; +} set_sink_volume_t; + +static void +set_sink_volume_free (gpointer data) +{ + set_sink_volume_t * vol = (set_sink_volume_t *)data; + g_object_unref(vol->context); + g_free(vol); +} + +static gboolean +set_sink_volume_cb (gpointer data) +{ + set_sink_volume_t * vol = (set_sink_volume_t *)data; + + vol->cb(vol->context, 1, vol->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_set_sink_volume_by_index (pa_context *c, uint32_t idx, const pa_cvolume * cvol, pa_context_success_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), NULL); + g_return_val_if_fail(cb != NULL, NULL); + + set_sink_volume_t * data = g_new(set_sink_volume_t, 1); + data->cb = cb; + data->userdata = userdata; + data->context = g_objet_ref(c); + data->cvol.channels = cvol->channels; + + int i; + for (i = 0; i < cvol->channels; i++) + data->cvol.values[i] = cvol->values[i]; + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + set_sink_volume_cb, + data, + set_sink_volume_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_context_success_cb_t cb; + gpointer userdata; + pa_cvolume cvol; +} set_source_volume_t; + +static void +set_source_volume_free (gpointer data) +{ + set_source_volume_t * vol = (set_source_volume_t *)data; + g_object_unref(vol->context); + g_free(vol); +} + +static gboolean +set_source_volume_cb (gpointer data) +{ + set_source_volume_t * vol = (set_source_volume_t *)data; + + vol->cb(vol->context, 1, vol->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_set_source_volume_by_name (pa_context *c, const char * name, const pa_cvolume * cvol, pa_context_success_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), NULL); + g_return_val_if_fail(cb != NULL, NULL); + + set_source_volume_t * data = g_new(set_source_volume_t, 1); + data->cb = cb; + data->userdata = userdata; + data->context = g_objet_ref(c); + data->cvol.channels = cvol->channels; + + int i; + for (i = 0; i < cvol->channels; i++) + data->cvol.values[i] = cvol->values[i]; + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + set_source_volume_cb, + data, + set_source_volume_free); + + GObject * goper = g_object_new(G_TYPE_OBJECT); + pa_operation * oper = (pa_operation *)goper; + return oper; +} /* ******************************* * subscribe.h -- cgit v1.2.3 From d788cd8f6910a8ff17454cc54175815a122f0c63 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 26 Jan 2015 16:53:28 -0600 Subject: IT COMPILES! --- tests/CMakeLists.txt | 15 +++++++ tests/pa-mock.c | 119 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 90 insertions(+), 44 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ae68c45..5c37ea3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -82,6 +82,21 @@ target_link_libraries( include_directories(${CMAKE_CURRENT_BINARY_DIR}) +########################### +# Pulse Mock +########################### + +add_library( + pulse-mock + SHARED + pa-mock.c +) + +target_link_libraries( + pulse-mock + ${SOUNDSERVICE_LIBRARIES} +) + ########################### # Name Watch Test ########################### diff --git a/tests/pa-mock.c b/tests/pa-mock.c index 20fced9..b995712 100644 --- a/tests/pa-mock.c +++ b/tests/pa-mock.c @@ -1,5 +1,8 @@ -#include +#include +#include +#include +#include #ifdef G_LOG_DOMAIN #undef G_LOG_DOMAIN @@ -16,7 +19,7 @@ G_DEFINE_QUARK("pa-mock-subscribe-mask", subscribe_mask); typedef struct { pa_context_notify_cb_t cb; - gpointer user_data; + gpointer userdata; } state_cb_t; static void @@ -28,7 +31,7 @@ context_weak_cb (gpointer user_data, GObject * oldobj) pa_context * pa_context_new_with_proplist (pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist) { - GObject * gctx = g_object_new(G_TYPE_OBJECT); + GObject * gctx = g_object_new(G_TYPE_OBJECT, NULL); pa_context * ctx = (pa_context *)gctx; g_debug("Creating new context: %p", ctx); @@ -43,10 +46,11 @@ pa_context_unref (pa_context *c) { g_object_unref(G_OBJECT(c)); } -void +pa_context * pa_context_ref (pa_context *c) { g_return_if_fail(G_IS_OBJECT(c)); g_object_ref(G_OBJECT(c)); + return c; } int @@ -89,9 +93,9 @@ pa_context_set_state_callback (pa_context *c, pa_context_notify_cb_t cb, void *u state_cb->cb = cb; state_cb->userdata = userdata; - GList * statelist = g_object_get_qdata(G_OBJECT(c), state_cb_quark); + GList * statelist = g_object_get_qdata(G_OBJECT(c), state_cb_quark()); statelist = g_list_append(statelist, state_cb); - g_object_set_qdata_full(G_OBJECT(c), state_cb_quark, state_cb, state_cb_list_destroy); + g_object_set_qdata_full(G_OBJECT(c), state_cb_quark(), state_cb, state_cb_list_destroy); } pa_context_state_t @@ -128,7 +132,6 @@ get_server_info_cb (gpointer data) .host_name = "host", .server_version = "1.2.3", .server_name = "server", - .sample_spec = , .default_sink_name = "default-sink", .default_source_name = "default-source", .cookie = 1234, @@ -152,14 +155,14 @@ pa_context_get_server_info (pa_context *c, pa_server_info_cb_t cb, void *userdat get_server_info_t * info = g_new(get_server_info_t, 1); info->cb = cb; info->userdata = userdata; - info->context = g_objet_ref(c); + info->context = g_object_ref(c); g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, get_server_info_cb, info, get_server_info_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } @@ -180,7 +183,7 @@ get_sink_info_free (gpointer data) } static gboolean -get_info_info_cb (gpointer data) +get_sink_info_cb (gpointer data) { pa_sink_info sink = { .name = "default-sink", @@ -207,14 +210,14 @@ pa_context_get_sink_info_by_name (pa_context *c, const gchar * name, pa_sink_inf get_sink_info_t * info = g_new(get_sink_info_t, 1); info->cb = cb; info->userdata = userdata; - info->context = g_objet_ref(c); + info->context = g_object_ref(c); g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, get_sink_info_cb, info, get_sink_info_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } @@ -227,34 +230,34 @@ pa_context_get_sink_info_list (pa_context *c, pa_sink_info_cb_t cb, void *userda } typedef struct { - pa_sink_info_cb_t cb; + pa_sink_input_info_cb_t cb; gpointer userdata; pa_context * context; } get_sink_input_info_t; static void -get_sink_info_free (gpointer data) +get_sink_input_info_free (gpointer data) { - get_sink_input_info_t * info = (get_sink_info_t *)data; + get_sink_input_info_t * info = (get_sink_input_info_t *)data; pa_context_unref(info->context); g_free(info); } static gboolean -get_sink_info_cb (gpointer data) +get_sink_input_info_cb (gpointer data) { pa_sink_input_info sink = { .name = "default-sink" }; get_sink_input_info_t * info = (get_sink_input_info_t *)data; - info->cb(info->context, &sink, info->userdata); + info->cb(info->context, &sink, 0, info->userdata); return G_SOURCE_REMOVE; } pa_operation * -pa_context_get_sink_input_info (pa_context *c, pa_sink_input_info_cb_t cb, void * userdata) +pa_context_get_sink_input_info (pa_context *c, uint32_t idx, pa_sink_input_info_cb_t cb, void * userdata) { g_return_val_if_fail(G_IS_OBJECT(c), NULL); g_return_val_if_fail(cb != NULL, NULL); @@ -262,14 +265,14 @@ pa_context_get_sink_input_info (pa_context *c, pa_sink_input_info_cb_t cb, void get_sink_input_info_t * info = g_new(get_sink_input_info_t, 1); info->cb = cb; info->userdata = userdata; - info->context = g_objet_ref(c); + info->context = g_object_ref(c); g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, get_sink_input_info_cb, info, get_sink_input_info_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } @@ -296,7 +299,7 @@ get_source_info_cb (gpointer data) }; get_source_info_t * info = (get_source_info_t *)data; - info->cb(info->context, &source, info->userdata); + info->cb(info->context, &source, 0, info->userdata); return G_SOURCE_REMOVE; } @@ -310,14 +313,14 @@ pa_context_get_source_info_by_name (pa_context *c, const char * name, pa_source_ get_source_info_t * info = g_new(get_source_info_t, 1); info->cb = cb; info->userdata = userdata; - info->context = g_objet_ref(c); + info->context = g_object_ref(c); g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, get_source_info_cb, info, get_source_info_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } @@ -344,7 +347,7 @@ get_source_output_cb (gpointer data) }; get_source_output_t * info = (get_source_output_t *)data; - info->cb(info->context, &source, info->userdata); + info->cb(info->context, &source, 0, info->userdata); return G_SOURCE_REMOVE; } @@ -358,14 +361,14 @@ pa_context_get_source_output_info (pa_context *c, uint32_t idx, pa_source_output get_source_output_t * info = g_new(get_source_output_t, 1); info->cb = cb; info->userdata = userdata; - info->context = g_objet_ref(c); + info->context = g_object_ref(c); g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, get_source_output_cb, info, get_source_output_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } @@ -373,6 +376,7 @@ pa_context_get_source_output_info (pa_context *c, uint32_t idx, pa_source_output typedef struct { pa_context_success_cb_t cb; gpointer userdata; + pa_context * context; int mute; } set_sink_mute_t; @@ -403,7 +407,7 @@ pa_context_set_sink_mute_by_index (pa_context *c, uint32_t idx, int mute, pa_con set_sink_mute_t * data = g_new(set_sink_mute_t, 1); data->cb = cb; data->userdata = userdata; - data->context = g_objet_ref(c); + data->context = g_object_ref(c); data->mute = mute; g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, @@ -411,7 +415,7 @@ pa_context_set_sink_mute_by_index (pa_context *c, uint32_t idx, int mute, pa_con data, set_sink_mute_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } @@ -419,6 +423,7 @@ pa_context_set_sink_mute_by_index (pa_context *c, uint32_t idx, int mute, pa_con typedef struct { pa_context_success_cb_t cb; gpointer userdata; + pa_context * context; pa_cvolume cvol; } set_sink_volume_t; @@ -449,7 +454,7 @@ pa_context_set_sink_volume_by_index (pa_context *c, uint32_t idx, const pa_cvolu set_sink_volume_t * data = g_new(set_sink_volume_t, 1); data->cb = cb; data->userdata = userdata; - data->context = g_objet_ref(c); + data->context = g_object_ref(c); data->cvol.channels = cvol->channels; int i; @@ -461,7 +466,7 @@ pa_context_set_sink_volume_by_index (pa_context *c, uint32_t idx, const pa_cvolu data, set_sink_volume_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } @@ -469,6 +474,7 @@ pa_context_set_sink_volume_by_index (pa_context *c, uint32_t idx, const pa_cvolu typedef struct { pa_context_success_cb_t cb; gpointer userdata; + pa_context * context; pa_cvolume cvol; } set_source_volume_t; @@ -499,7 +505,7 @@ pa_context_set_source_volume_by_name (pa_context *c, const char * name, const pa set_source_volume_t * data = g_new(set_source_volume_t, 1); data->cb = cb; data->userdata = userdata; - data->context = g_objet_ref(c); + data->context = g_object_ref(c); data->cvol.channels = cvol->channels; int i; @@ -511,7 +517,7 @@ pa_context_set_source_volume_by_name (pa_context *c, const char * name, const pa data, set_source_volume_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } @@ -521,9 +527,9 @@ pa_context_set_source_volume_by_name (pa_context *c, const char * name, const pa * *******************************/ typedef struct { - pa_context_subscribe_cb_t cb; - gointer userdata; - GObject * context; + pa_context_success_cb_t cb; + gpointer userdata; + pa_context * context; pa_subscription_mask_t mask; } subscribe_mask_t; @@ -539,7 +545,7 @@ static gboolean subscribe_mask_cb (gpointer data) { subscribe_mask_t * mask_data = (subscribe_mask_t *)data; - g_object_set_qdata(mask_data->context, subscribe_mask_quark, GINT_TO_POINTER(mask_data->mask)); + g_object_set_qdata(G_OBJECT(mask_data->context), subscribe_mask_quark(), GINT_TO_POINTER(mask_data->mask)); mask_data->cb(mask_data->context, 1, mask_data->userdata); return G_SOURCE_REMOVE; } @@ -560,14 +566,14 @@ pa_context_subscribe (pa_context * c, pa_subscription_mask_t mask, pa_context_su data, subscribe_mask_free); - GObject * goper = g_object_new(G_TYPE_OBJECT); + GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); pa_operation * oper = (pa_operation *)goper; return oper; } typedef struct { pa_context_subscribe_cb_t cb; - gointer userdata; + gpointer userdata; } subscribe_cb_t; void @@ -579,7 +585,7 @@ pa_context_set_subscribe_callback (pa_context * c, pa_context_subscribe_cb_t cal sub->cb = callback; sub->userdata = userdata; - g_object_set_qdata_full(c, subscribe_cb_quark, sub, g_free); + g_object_set_qdata_full(G_OBJECT(c), subscribe_cb_quark(), sub, g_free); } /* ******************************* @@ -684,7 +690,16 @@ pa_volume_t pa_sw_volume_from_dB (double f) { double linear = pow(10.0, f / 20.0); - return (pa_volume_t) PA_CLAMP_VOLUME((uint64_t) lround(cbrt(linear) * PA_VOLUME_NORM)); + + pa_volume_t calculated = lround(cbrt(linear) * PA_VOLUME_NORM); + + if (G_UNLIKELY(calculated > PA_VOLUME_MAX)) { + return PA_VOLUME_MAX; + } else if (G_UNLIKELY(calculated < PA_VOLUME_MUTED)) { + return PA_VOLUME_MUTED; + } else { + return calculated; + } } pa_cvolume * @@ -711,8 +726,15 @@ pa_cvolume_set (pa_cvolume * cvol, unsigned channels, pa_volume_t volume) cvol->channels = channels; unsigned int i; - for (i = 0; i < channels; i++) - cvol->values[i] = PA_CLAMP_VOLUME(volume); + for (i = 0; i < channels; i++) { + if (G_UNLIKELY(volume > PA_VOLUME_MAX)) { + cvol->values[i] = PA_VOLUME_MAX; + } else if (G_UNLIKELY(volume < PA_VOLUME_MUTED)) { + cvol->values[i] = PA_VOLUME_MUTED; + } else { + cvol->values[i] = volume; + } + } return cvol; } @@ -741,8 +763,17 @@ pa_cvolume_scale (pa_cvolume * cvol, pa_volume_t max) return pa_cvolume_set(cvol, cvol->channels, max); unsigned int i; - for (i = 0; i < channels; i++) - cvol->values[i] = PA_CLAMP_VOLUME( (cvol->values[i] * max) / originalmax ); + for (i = 0; i < cvol->channels; i++) { + pa_volume_t calculated = (cvol->values[i] * max) / originalmax; + + if (G_UNLIKELY(calculated > PA_VOLUME_MAX)) { + cvol->values[i] = PA_VOLUME_MAX; + } else if (G_UNLIKELY(calculated < PA_VOLUME_MUTED)) { + cvol->values[i] = PA_VOLUME_MUTED; + } else { + cvol->values[i] = calculated; + } + } return cvol; } -- cgit v1.2.3 From 26c4b845af442fd7968863929f4f62c8721fb687 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 27 Jan 2015 11:42:26 -0600 Subject: Linking and starting and failing! --- src/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 21 ++++++++--- tests/volume-control-test.cc | 83 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 tests/volume-control-test.cc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c18726c..b6f006a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -163,7 +163,6 @@ add_library( target_link_libraries( indicator-sound-service-lib - ${PULSEAUDIO_LIBRARIES} ${SOUNDSERVICE_LIBRARIES} ) @@ -187,6 +186,7 @@ set_target_properties( target_link_libraries( indicator-sound-service-bin indicator-sound-service-lib + ${PULSEAUDIO_LIBRARIES} ) ########################### diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5c37ea3..a9ec204 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -92,11 +92,6 @@ add_library( pa-mock.c ) -target_link_libraries( - pulse-mock - ${SOUNDSERVICE_LIBRARIES} -) - ########################### # Name Watch Test ########################### @@ -130,6 +125,22 @@ add_test(accounts-service-user-test-player accounts-service-user-test --gtest_filter=AccountsServiceUserTest.SetMediaPlayer ) +########################### +# Volume Control +########################### + +include_directories(${CMAKE_SOURCE_DIR}/src) +add_executable (volume-control-test volume-control-test.cc) +target_link_libraries ( + volume-control-test + indicator-sound-service-lib + pulse-mock + gtest + ${TEST_LIBRARIES} +) + +add_test(volume-control-test volume-control-test) + ########################### # Sound Menu ########################### diff --git a/tests/volume-control-test.cc b/tests/volume-control-test.cc new file mode 100644 index 0000000..9970241 --- /dev/null +++ b/tests/volume-control-test.cc @@ -0,0 +1,83 @@ +/* + * Copyright © 2014 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: + * Ted Gould + */ + +#include +#include +#include + +extern "C" { +#include "indicator-sound-service.h" +} + +class VolumeControlTest : public ::testing::Test +{ + + protected: + DbusTestService * service = NULL; + GDBusConnection * session = NULL; + + virtual void SetUp() { + service = dbus_test_service_new(NULL); + dbus_test_service_start_tasks(service); + + session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); + ASSERT_NE(nullptr, session); + g_dbus_connection_set_exit_on_close(session, FALSE); + g_object_add_weak_pointer(G_OBJECT(session), (gpointer *)&session); + } + + virtual void TearDown() { + g_clear_object(&service); + + g_object_unref(session); + + unsigned int cleartry = 0; + while (session != NULL && cleartry < 100) { + loop(100); + cleartry++; + } + + ASSERT_EQ(nullptr, session); + } + + static gboolean timeout_cb (gpointer user_data) { + GMainLoop * loop = static_cast(user_data); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + void loop (unsigned int ms) { + GMainLoop * loop = g_main_loop_new(NULL, FALSE); + g_timeout_add(ms, timeout_cb, loop); + g_main_loop_run(loop); + g_main_loop_unref(loop); + } +}; + +TEST_F(VolumeControlTest, BasicObject) { + VolumeControl * control = volume_control_new(); + + /* Setup the PA backend */ + loop(100); + + /* Ready */ + EXPECT_TRUE(volume_control_get_ready(control)); + + g_clear_object(&control); +} -- cgit v1.2.3 From 4b73db41e3a3507f67ba2ead8da004b63d2e995a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 27 Jan 2015 14:29:12 -0600 Subject: Enough state logic to get is 'going' --- tests/pa-mock.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/tests/pa-mock.c b/tests/pa-mock.c index b995712..bc4fb95 100644 --- a/tests/pa-mock.c +++ b/tests/pa-mock.c @@ -12,6 +12,15 @@ G_DEFINE_QUARK("pa-mock-state-cb-list", state_cb); G_DEFINE_QUARK("pa-mock-subscribe-callback", subscribe_cb); G_DEFINE_QUARK("pa-mock-subscribe-mask", subscribe_mask); +G_DEFINE_QUARK("pa-mock-current-state", state); +G_DEFINE_QUARK("pa-mock-future-state", state_future); + +/* ******************************* + * Prototypes + * *******************************/ + +static void set_state (pa_context * c, pa_context_state_t state); +static void queue_state (pa_context * context, pa_context_state_t state); /* ******************************* * context.h @@ -37,6 +46,8 @@ pa_context_new_with_proplist (pa_mainloop_api *mainloop, const char *name, pa_pr g_debug("Creating new context: %p", ctx); g_object_weak_ref(gctx, context_weak_cb, NULL); + set_state(ctx, PA_CONTEXT_UNCONNECTED); + return ctx; } @@ -58,6 +69,7 @@ pa_context_connect (pa_context *c, const char *server, pa_context_flags_t flags, { g_return_if_fail(G_IS_OBJECT(c)); g_debug("Context Connect"); + queue_state(c, PA_CONTEXT_READY); return 0; } @@ -66,6 +78,7 @@ pa_context_disconnect (pa_context *c) { g_return_if_fail(G_IS_OBJECT(c)); g_debug("Context Disconnect"); + queue_state(c, PA_CONTEXT_UNCONNECTED); } int @@ -76,6 +89,49 @@ pa_context_errno (pa_context *c) return 0; } +static void +set_state_cb (gpointer pcbdata, gpointer pcontext) +{ + pa_context * context = (pa_context *)pcontext; + state_cb_t * cbdata = (state_cb_t *)pcbdata; + + cbdata->cb(context, cbdata->userdata); +} + +static void +set_state (pa_context * c, pa_context_state_t state) +{ + pa_context_state_t oldstate = pa_context_get_state(c); + if (oldstate == state) + return; + + g_object_set_qdata(G_OBJECT(c), state_quark(), GINT_TO_POINTER(state)); + GList * statelist = g_object_get_qdata(G_OBJECT(c), state_cb_quark()); + g_list_foreach(statelist, set_state_cb, c); +} + +static gboolean +queue_state_cb (gpointer pcontext) +{ + pa_context * context = (pa_context *)pcontext; + pa_context_state_t state = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(context), state_future_quark())); + + set_state(context, state); + + return G_SOURCE_REMOVE; +} + +static void +queue_state (pa_context * context, pa_context_state_t state) +{ + g_object_set_qdata(G_OBJECT(context), state_future_quark(), GINT_TO_POINTER(state)); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + queue_state_cb, + g_object_ref(context), + g_object_unref); +} + static void state_cb_list_destroy (gpointer data) { @@ -95,7 +151,7 @@ pa_context_set_state_callback (pa_context *c, pa_context_notify_cb_t cb, void *u GList * statelist = g_object_get_qdata(G_OBJECT(c), state_cb_quark()); statelist = g_list_append(statelist, state_cb); - g_object_set_qdata_full(G_OBJECT(c), state_cb_quark(), state_cb, state_cb_list_destroy); + g_object_set_qdata_full(G_OBJECT(c), state_cb_quark(), statelist, state_cb_list_destroy); } pa_context_state_t @@ -103,7 +159,7 @@ pa_context_get_state (pa_context *c) { g_return_if_fail(G_IS_OBJECT(c)); - return PA_CONTEXT_READY; + return GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(c), state_quark())); } /* ******************************* @@ -185,13 +241,17 @@ get_sink_info_free (gpointer data) static gboolean get_sink_info_cb (gpointer data) { + pa_sink_port_info active_port = { + .name = "speaker" + }; pa_sink_info sink = { .name = "default-sink", .index = 0, .description = "Default Sink", .channel_map = { .channels = 0 - } + }, + .active_port = &active_port }; get_sink_info_t * info = (get_sink_info_t *)data; @@ -393,7 +453,8 @@ set_sink_mute_cb (gpointer data) { set_sink_mute_t * mute = (set_sink_mute_t *)data; - mute->cb(mute->context, 1, mute->userdata); + if (mute->cb != NULL) + mute->cb(mute->context, 1, mute->userdata); return G_SOURCE_REMOVE; } @@ -402,7 +463,6 @@ pa_operation* pa_context_set_sink_mute_by_index (pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) { g_return_val_if_fail(G_IS_OBJECT(c), NULL); - g_return_val_if_fail(cb != NULL, NULL); set_sink_mute_t * data = g_new(set_sink_mute_t, 1); data->cb = cb; @@ -546,7 +606,8 @@ subscribe_mask_cb (gpointer data) { subscribe_mask_t * mask_data = (subscribe_mask_t *)data; g_object_set_qdata(G_OBJECT(mask_data->context), subscribe_mask_quark(), GINT_TO_POINTER(mask_data->mask)); - mask_data->cb(mask_data->context, 1, mask_data->userdata); + if (mask_data->cb != NULL) + mask_data->cb(mask_data->context, 1, mask_data->userdata); return G_SOURCE_REMOVE; } @@ -720,7 +781,7 @@ pa_cvolume * pa_cvolume_set (pa_cvolume * cvol, unsigned channels, pa_volume_t volume) { g_return_val_if_fail(cvol != NULL, NULL); - g_return_val_if_fail(channels > 0, NULL); + g_warn_if_fail(channels > 0); g_return_val_if_fail(channels <= PA_CHANNELS_MAX, NULL); cvol->channels = channels; -- cgit v1.2.3 From ed54228025cc86f6affca2eafe61d83d234351d4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Jan 2015 09:41:22 -0600 Subject: Create a base object and move the state stuff over to it --- tests/CMakeLists.txt | 2 +- tests/pa-mock.c | 841 -------------------------------------------------- tests/pa-mock.cpp | 857 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 858 insertions(+), 842 deletions(-) delete mode 100644 tests/pa-mock.c create mode 100644 tests/pa-mock.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a9ec204..fb93aca 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -89,7 +89,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_library( pulse-mock SHARED - pa-mock.c + pa-mock.cpp ) ########################### diff --git a/tests/pa-mock.c b/tests/pa-mock.c deleted file mode 100644 index bc4fb95..0000000 --- a/tests/pa-mock.c +++ /dev/null @@ -1,841 +0,0 @@ - -#include -#include -#include -#include - -#ifdef G_LOG_DOMAIN -#undef G_LOG_DOMAIN -#endif -#define G_LOG_DOMAIN "PA-Mock" - -G_DEFINE_QUARK("pa-mock-state-cb-list", state_cb); -G_DEFINE_QUARK("pa-mock-subscribe-callback", subscribe_cb); -G_DEFINE_QUARK("pa-mock-subscribe-mask", subscribe_mask); -G_DEFINE_QUARK("pa-mock-current-state", state); -G_DEFINE_QUARK("pa-mock-future-state", state_future); - -/* ******************************* - * Prototypes - * *******************************/ - -static void set_state (pa_context * c, pa_context_state_t state); -static void queue_state (pa_context * context, pa_context_state_t state); - -/* ******************************* - * context.h - * *******************************/ - -typedef struct { - pa_context_notify_cb_t cb; - gpointer userdata; -} state_cb_t; - -static void -context_weak_cb (gpointer user_data, GObject * oldobj) -{ - g_debug("Finalizing context: %p", oldobj); -} - -pa_context * -pa_context_new_with_proplist (pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist) -{ - GObject * gctx = g_object_new(G_TYPE_OBJECT, NULL); - pa_context * ctx = (pa_context *)gctx; - - g_debug("Creating new context: %p", ctx); - g_object_weak_ref(gctx, context_weak_cb, NULL); - - set_state(ctx, PA_CONTEXT_UNCONNECTED); - - return ctx; -} - -void -pa_context_unref (pa_context *c) { - g_return_if_fail(G_IS_OBJECT(c)); - g_object_unref(G_OBJECT(c)); -} - -pa_context * -pa_context_ref (pa_context *c) { - g_return_if_fail(G_IS_OBJECT(c)); - g_object_ref(G_OBJECT(c)); - return c; -} - -int -pa_context_connect (pa_context *c, const char *server, pa_context_flags_t flags, const pa_spawn_api *api) -{ - g_return_if_fail(G_IS_OBJECT(c)); - g_debug("Context Connect"); - queue_state(c, PA_CONTEXT_READY); - return 0; -} - -void -pa_context_disconnect (pa_context *c) -{ - g_return_if_fail(G_IS_OBJECT(c)); - g_debug("Context Disconnect"); - queue_state(c, PA_CONTEXT_UNCONNECTED); -} - -int -pa_context_errno (pa_context *c) -{ - g_return_val_if_fail(G_IS_OBJECT(c), -1); - - return 0; -} - -static void -set_state_cb (gpointer pcbdata, gpointer pcontext) -{ - pa_context * context = (pa_context *)pcontext; - state_cb_t * cbdata = (state_cb_t *)pcbdata; - - cbdata->cb(context, cbdata->userdata); -} - -static void -set_state (pa_context * c, pa_context_state_t state) -{ - pa_context_state_t oldstate = pa_context_get_state(c); - if (oldstate == state) - return; - - g_object_set_qdata(G_OBJECT(c), state_quark(), GINT_TO_POINTER(state)); - GList * statelist = g_object_get_qdata(G_OBJECT(c), state_cb_quark()); - g_list_foreach(statelist, set_state_cb, c); -} - -static gboolean -queue_state_cb (gpointer pcontext) -{ - pa_context * context = (pa_context *)pcontext; - pa_context_state_t state = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(context), state_future_quark())); - - set_state(context, state); - - return G_SOURCE_REMOVE; -} - -static void -queue_state (pa_context * context, pa_context_state_t state) -{ - g_object_set_qdata(G_OBJECT(context), state_future_quark(), GINT_TO_POINTER(state)); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - queue_state_cb, - g_object_ref(context), - g_object_unref); -} - -static void -state_cb_list_destroy (gpointer data) -{ - GList * statelist = (GList *)data; - g_list_free_full(statelist, g_free); -} - -void -pa_context_set_state_callback (pa_context *c, pa_context_notify_cb_t cb, void *userdata) -{ - g_return_if_fail(G_IS_OBJECT(c)); - g_return_if_fail(cb != NULL); - - state_cb_t * state_cb = g_new0(state_cb_t, 1); - state_cb->cb = cb; - state_cb->userdata = userdata; - - GList * statelist = g_object_get_qdata(G_OBJECT(c), state_cb_quark()); - statelist = g_list_append(statelist, state_cb); - g_object_set_qdata_full(G_OBJECT(c), state_cb_quark(), statelist, state_cb_list_destroy); -} - -pa_context_state_t -pa_context_get_state (pa_context *c) -{ - g_return_if_fail(G_IS_OBJECT(c)); - - return GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(c), state_quark())); -} - -/* ******************************* - * introspect.h - * *******************************/ - -typedef struct { - pa_server_info_cb_t cb; - gpointer userdata; - pa_context * context; -} get_server_info_t; - -static void -get_server_info_free (gpointer data) -{ - get_server_info_t * info = (get_server_info_t *)data; - g_object_unref(info->context); - g_free(info); -} - -static gboolean -get_server_info_cb (gpointer data) -{ - pa_server_info server = { - .user_name = "user", - .host_name = "host", - .server_version = "1.2.3", - .server_name = "server", - .default_sink_name = "default-sink", - .default_source_name = "default-source", - .cookie = 1234, - .channel_map = { - .channels = 0 - } - }; - get_server_info_t * info = (get_server_info_t *)data; - - info->cb(info->context, &server, info->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation* -pa_context_get_server_info (pa_context *c, pa_server_info_cb_t cb, void *userdata) -{ - g_return_val_if_fail(G_IS_OBJECT(c), NULL); - g_return_val_if_fail(cb != NULL, NULL); - - get_server_info_t * info = g_new(get_server_info_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_server_info_cb, - info, - get_server_info_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_sink_info_cb_t cb; - gpointer userdata; - pa_context * context; - uint32_t index; -} get_sink_info_t; - -static void -get_sink_info_free (gpointer data) -{ - get_sink_info_t * info = (get_sink_info_t *)data; - g_object_unref(info->context); - g_free(info); -} - -static gboolean -get_sink_info_cb (gpointer data) -{ - pa_sink_port_info active_port = { - .name = "speaker" - }; - pa_sink_info sink = { - .name = "default-sink", - .index = 0, - .description = "Default Sink", - .channel_map = { - .channels = 0 - }, - .active_port = &active_port - }; - get_sink_info_t * info = (get_sink_info_t *)data; - - info->cb(info->context, &sink, 1, info->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation* -pa_context_get_sink_info_by_name (pa_context *c, const gchar * name, pa_sink_info_cb_t cb, void *userdata) -{ - g_return_val_if_fail(G_IS_OBJECT(c), NULL); - g_return_val_if_fail(g_strcmp0(name, "default-sink") == 0, NULL); - g_return_val_if_fail(cb != NULL, NULL); - - get_sink_info_t * info = g_new(get_sink_info_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_sink_info_cb, - info, - get_sink_info_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -pa_operation* -pa_context_get_sink_info_list (pa_context *c, pa_sink_info_cb_t cb, void *userdata) -{ - /* Only have one today, so this is the same */ - return pa_context_get_sink_info_by_name(c, "default-sink", cb, userdata); -} - -typedef struct { - pa_sink_input_info_cb_t cb; - gpointer userdata; - pa_context * context; -} get_sink_input_info_t; - -static void -get_sink_input_info_free (gpointer data) -{ - get_sink_input_info_t * info = (get_sink_input_info_t *)data; - pa_context_unref(info->context); - g_free(info); -} - -static gboolean -get_sink_input_info_cb (gpointer data) -{ - pa_sink_input_info sink = { - .name = "default-sink" - }; - get_sink_input_info_t * info = (get_sink_input_info_t *)data; - - info->cb(info->context, &sink, 0, info->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation * -pa_context_get_sink_input_info (pa_context *c, uint32_t idx, pa_sink_input_info_cb_t cb, void * userdata) -{ - g_return_val_if_fail(G_IS_OBJECT(c), NULL); - g_return_val_if_fail(cb != NULL, NULL); - - get_sink_input_info_t * info = g_new(get_sink_input_info_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_sink_input_info_cb, - info, - get_sink_input_info_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_source_info_cb_t cb; - gpointer userdata; - pa_context * context; -} get_source_info_t; - -static void -get_source_info_free (gpointer data) -{ - get_source_info_t * info = (get_source_info_t *)data; - g_object_unref(info->context); - g_free(info); -} - -static gboolean -get_source_info_cb (gpointer data) -{ - pa_source_info source = { - .name = "default-source" - }; - get_source_info_t * info = (get_source_info_t *)data; - - info->cb(info->context, &source, 0, info->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation* -pa_context_get_source_info_by_name (pa_context *c, const char * name, pa_source_info_cb_t cb, void *userdata) -{ - g_return_val_if_fail(G_IS_OBJECT(c), NULL); - g_return_val_if_fail(cb != NULL, NULL); - - get_source_info_t * info = g_new(get_source_info_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_source_info_cb, - info, - get_source_info_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_source_output_info_cb_t cb; - gpointer userdata; - pa_context * context; -} get_source_output_t; - -static void -get_source_output_free (gpointer data) -{ - get_source_output_t * info = (get_source_output_t *)data; - g_object_unref(info->context); - g_free(info); -} - -static gboolean -get_source_output_cb (gpointer data) -{ - pa_source_output_info source = { - .name = "default-source" - }; - get_source_output_t * info = (get_source_output_t *)data; - - info->cb(info->context, &source, 0, info->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation* -pa_context_get_source_output_info (pa_context *c, uint32_t idx, pa_source_output_info_cb_t cb, void *userdata) -{ - g_return_val_if_fail(G_IS_OBJECT(c), NULL); - g_return_val_if_fail(cb != NULL, NULL); - - get_source_output_t * info = g_new(get_source_output_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_source_output_cb, - info, - get_source_output_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_context_success_cb_t cb; - gpointer userdata; - pa_context * context; - int mute; -} set_sink_mute_t; - -static void -set_sink_mute_free (gpointer data) -{ - set_sink_mute_t * mute = (set_sink_mute_t *)data; - g_object_unref(mute->context); - g_free(mute); -} - -static gboolean -set_sink_mute_cb (gpointer data) -{ - set_sink_mute_t * mute = (set_sink_mute_t *)data; - - if (mute->cb != NULL) - mute->cb(mute->context, 1, mute->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation* -pa_context_set_sink_mute_by_index (pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) -{ - g_return_val_if_fail(G_IS_OBJECT(c), NULL); - - set_sink_mute_t * data = g_new(set_sink_mute_t, 1); - data->cb = cb; - data->userdata = userdata; - data->context = g_object_ref(c); - data->mute = mute; - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - set_sink_mute_cb, - data, - set_sink_mute_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_context_success_cb_t cb; - gpointer userdata; - pa_context * context; - pa_cvolume cvol; -} set_sink_volume_t; - -static void -set_sink_volume_free (gpointer data) -{ - set_sink_volume_t * vol = (set_sink_volume_t *)data; - g_object_unref(vol->context); - g_free(vol); -} - -static gboolean -set_sink_volume_cb (gpointer data) -{ - set_sink_volume_t * vol = (set_sink_volume_t *)data; - - vol->cb(vol->context, 1, vol->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation* -pa_context_set_sink_volume_by_index (pa_context *c, uint32_t idx, const pa_cvolume * cvol, pa_context_success_cb_t cb, void *userdata) -{ - g_return_val_if_fail(G_IS_OBJECT(c), NULL); - g_return_val_if_fail(cb != NULL, NULL); - - set_sink_volume_t * data = g_new(set_sink_volume_t, 1); - data->cb = cb; - data->userdata = userdata; - data->context = g_object_ref(c); - data->cvol.channels = cvol->channels; - - int i; - for (i = 0; i < cvol->channels; i++) - data->cvol.values[i] = cvol->values[i]; - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - set_sink_volume_cb, - data, - set_sink_volume_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_context_success_cb_t cb; - gpointer userdata; - pa_context * context; - pa_cvolume cvol; -} set_source_volume_t; - -static void -set_source_volume_free (gpointer data) -{ - set_source_volume_t * vol = (set_source_volume_t *)data; - g_object_unref(vol->context); - g_free(vol); -} - -static gboolean -set_source_volume_cb (gpointer data) -{ - set_source_volume_t * vol = (set_source_volume_t *)data; - - vol->cb(vol->context, 1, vol->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation* -pa_context_set_source_volume_by_name (pa_context *c, const char * name, const pa_cvolume * cvol, pa_context_success_cb_t cb, void *userdata) -{ - g_return_val_if_fail(G_IS_OBJECT(c), NULL); - g_return_val_if_fail(cb != NULL, NULL); - - set_source_volume_t * data = g_new(set_source_volume_t, 1); - data->cb = cb; - data->userdata = userdata; - data->context = g_object_ref(c); - data->cvol.channels = cvol->channels; - - int i; - for (i = 0; i < cvol->channels; i++) - data->cvol.values[i] = cvol->values[i]; - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - set_source_volume_cb, - data, - set_source_volume_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -/* ******************************* - * subscribe.h - * *******************************/ - -typedef struct { - pa_context_success_cb_t cb; - gpointer userdata; - pa_context * context; - pa_subscription_mask_t mask; -} subscribe_mask_t; - -static void -subscribe_mask_free (gpointer data) -{ - subscribe_mask_t * mask_data = (subscribe_mask_t *)data; - g_object_unref(mask_data->context); - g_free(mask_data); -} - -static gboolean -subscribe_mask_cb (gpointer data) -{ - subscribe_mask_t * mask_data = (subscribe_mask_t *)data; - g_object_set_qdata(G_OBJECT(mask_data->context), subscribe_mask_quark(), GINT_TO_POINTER(mask_data->mask)); - if (mask_data->cb != NULL) - mask_data->cb(mask_data->context, 1, mask_data->userdata); - return G_SOURCE_REMOVE; -} - -pa_operation * -pa_context_subscribe (pa_context * c, pa_subscription_mask_t mask, pa_context_success_cb_t callback, void * userdata) -{ - g_return_if_fail(G_IS_OBJECT(c)); - - subscribe_mask_t * data = g_new0(subscribe_mask_t, 1); - data->cb = callback; - data->userdata = userdata; - data->context = g_object_ref(G_OBJECT(c)); - data->mask = mask; - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - subscribe_mask_cb, - data, - subscribe_mask_free); - - GObject * goper = g_object_new(G_TYPE_OBJECT, NULL); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_context_subscribe_cb_t cb; - gpointer userdata; -} subscribe_cb_t; - -void -pa_context_set_subscribe_callback (pa_context * c, pa_context_subscribe_cb_t callback, void * userdata) -{ - g_return_if_fail(G_IS_OBJECT(c)); - - subscribe_cb_t * sub = g_new0(subscribe_cb_t, 1); - sub->cb = callback; - sub->userdata = userdata; - - g_object_set_qdata_full(G_OBJECT(c), subscribe_cb_quark(), sub, g_free); -} - -/* ******************************* - * glib-mainloop.h - * *******************************/ - -struct pa_glib_mainloop { - GMainContext * context; -}; - -struct pa_mainloop_api mock_mainloop = { 0 }; - -pa_mainloop_api * -pa_glib_mainloop_get_api (pa_glib_mainloop * g) -{ - return &mock_mainloop; -} - -pa_glib_mainloop * -pa_glib_mainloop_new (GMainContext * c) -{ - pa_glib_mainloop * loop = g_new0(pa_glib_mainloop, 1); - - if (c == NULL) - loop->context = g_main_context_default(); - else - loop->context = c; - - g_main_context_ref(loop->context); - return loop; -} - -void -pa_glib_mainloop_free (pa_glib_mainloop * g) -{ - g_main_context_unref(g->context); - g_free(g); -} - -/* ******************************* - * operation.h - * *******************************/ - -void -pa_operation_unref (pa_operation * operation) -{ - g_return_if_fail(G_IS_OBJECT(operation)); - g_object_unref(G_OBJECT(operation)); -} - -/* ******************************* - * proplist.h - * *******************************/ - -pa_proplist * -pa_proplist_new (void) -{ - return (pa_proplist *)g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); -} - -void -pa_proplist_free (pa_proplist * p) -{ - g_return_if_fail(p != NULL); - g_hash_table_destroy((GHashTable *)p); -} - -const char * -pa_proplist_gets (pa_proplist * p, const char * key) -{ - g_return_val_if_fail(p != NULL, NULL); - g_return_val_if_fail(key != NULL, NULL); - return g_hash_table_lookup((GHashTable *)p, key); -} - -int -pa_proplist_sets (pa_proplist *p, const char * key, const char * value) -{ - g_return_val_if_fail(p != NULL, -1); - g_return_val_if_fail(key != NULL, -1); - g_return_val_if_fail(value != NULL, -1); - - g_hash_table_insert((GHashTable *)p, g_strdup(key), g_strdup(value)); - return 0; -} - -/* ******************************* - * error.h - * *******************************/ - -const char * -pa_strerror (int error) -{ - return "This is error text"; -} - -/* ******************************* - * volume.h - * *******************************/ - -pa_volume_t -pa_sw_volume_from_dB (double f) -{ - double linear = pow(10.0, f / 20.0); - - pa_volume_t calculated = lround(cbrt(linear) * PA_VOLUME_NORM); - - if (G_UNLIKELY(calculated > PA_VOLUME_MAX)) { - return PA_VOLUME_MAX; - } else if (G_UNLIKELY(calculated < PA_VOLUME_MUTED)) { - return PA_VOLUME_MUTED; - } else { - return calculated; - } -} - -pa_cvolume * -pa_cvolume_init (pa_cvolume * cvol) -{ - g_return_val_if_fail(cvol != NULL, NULL); - - cvol->channels = 0; - - unsigned int i; - for (i = 0; i < PA_CHANNELS_MAX; i++) - cvol->values[i] = PA_VOLUME_INVALID; - - return cvol; -} - -pa_cvolume * -pa_cvolume_set (pa_cvolume * cvol, unsigned channels, pa_volume_t volume) -{ - g_return_val_if_fail(cvol != NULL, NULL); - g_warn_if_fail(channels > 0); - g_return_val_if_fail(channels <= PA_CHANNELS_MAX, NULL); - - cvol->channels = channels; - - unsigned int i; - for (i = 0; i < channels; i++) { - if (G_UNLIKELY(volume > PA_VOLUME_MAX)) { - cvol->values[i] = PA_VOLUME_MAX; - } else if (G_UNLIKELY(volume < PA_VOLUME_MUTED)) { - cvol->values[i] = PA_VOLUME_MUTED; - } else { - cvol->values[i] = volume; - } - } - - return cvol; -} - -pa_volume_t -pa_cvolume_max (const pa_cvolume * cvol) -{ - g_return_val_if_fail(cvol != NULL, NULL); - pa_volume_t max = PA_VOLUME_MUTED; - - unsigned int i; - for (i = 0; i < cvol->channels; i++) - max = MAX(max, cvol->values[i]); - - return max; -} - -pa_cvolume * -pa_cvolume_scale (pa_cvolume * cvol, pa_volume_t max) -{ - g_return_val_if_fail(cvol != NULL, NULL); - - pa_volume_t originalmax = pa_cvolume_max(cvol); - - if (originalmax <= PA_VOLUME_MUTED) - return pa_cvolume_set(cvol, cvol->channels, max); - - unsigned int i; - for (i = 0; i < cvol->channels; i++) { - pa_volume_t calculated = (cvol->values[i] * max) / originalmax; - - if (G_UNLIKELY(calculated > PA_VOLUME_MAX)) { - cvol->values[i] = PA_VOLUME_MAX; - } else if (G_UNLIKELY(calculated < PA_VOLUME_MUTED)) { - cvol->values[i] = PA_VOLUME_MUTED; - } else { - cvol->values[i] = calculated; - } - } - - return cvol; -} - diff --git a/tests/pa-mock.cpp b/tests/pa-mock.cpp new file mode 100644 index 0000000..5b433fe --- /dev/null +++ b/tests/pa-mock.cpp @@ -0,0 +1,857 @@ + +#include +#include +#include + +#include +#include +#include +#include + +#ifdef G_LOG_DOMAIN +#undef G_LOG_DOMAIN +#endif +#define G_LOG_DOMAIN "PA-Mock" + +G_DEFINE_QUARK("pa-mock-state-cb-list", state_cb); +G_DEFINE_QUARK("pa-mock-subscribe-callback", subscribe_cb); +G_DEFINE_QUARK("pa-mock-subscribe-mask", subscribe_mask); +G_DEFINE_QUARK("pa-mock-current-state", state); +G_DEFINE_QUARK("pa-mock-future-state", state_future); + +/* Core class of the PA Mock state */ +class PAMockContext { +public: + /* Accounting */ + std::atomic refcnt; + + /* State stuff */ + std::vector> stateCallbacks; + pa_context_state_t currentState; + pa_context_state_t futureState; + + /* Event stuff */ + std::vector> eventCallbacks; + pa_subscription_mask_t mask; + + PAMockContext () + : refcnt(1) + , currentState(PA_CONTEXT_UNCONNECTED) + , futureState(PA_CONTEXT_UNCONNECTED) + , mask(PA_SUBSCRIPTION_MASK_NULL) + { + g_debug("Creating Context: %p", this); + } + + ~PAMockContext () { + g_debug("Destroying Context: %p", this); + } + + /* Ref counting */ + void ref () { + refcnt++; + } + + void unref () { + refcnt--; + if (refcnt == 0) + delete this; + } + + /* C/C++ boundry */ + operator pa_context *() { + return reinterpret_cast(this); + } + + /* State Stuff */ + void setState (pa_context_state_t state) + { + if (state == currentState) + return; + + currentState = state; + for (auto callback : stateCallbacks) { + callback(); + } + } + + void idleOnce (std::function idleFunc) { + auto allocated = new std::function(idleFunc); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + [](gpointer data) -> gboolean { + std::function * pidleFunc = reinterpret_cast *>(data); + (*pidleFunc)(); + return G_SOURCE_REMOVE; + }, + allocated, + [](gpointer data) -> void { + std::function * pidleFunc = reinterpret_cast *>(data); + delete pidleFunc; + }); + } + + void queueState (pa_context_state_t state) + { + idleOnce([this, state](){ + setState(state); + }); + } + + pa_context_state_t getState (void) + { + return currentState; + } + + void addStateCallback (std::function &callback) + { + stateCallbacks.push_back(callback); + } +}; + +struct pa_context { + operator PAMockContext * () { + return reinterpret_cast(this); + } +}; + +/* ******************************* + * context.h + * *******************************/ + +pa_context * +pa_context_new_with_proplist (pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist) +{ + return *(new PAMockContext()); +} + +void +pa_context_unref (pa_context *c) { + reinterpret_cast(c)->unref(); +} + +pa_context * +pa_context_ref (pa_context *c) { + reinterpret_cast(c)->ref(); + return c; +} + +int +pa_context_connect (pa_context *c, const char *server, pa_context_flags_t flags, const pa_spawn_api *api) +{ + reinterpret_cast(c)->queueState(PA_CONTEXT_READY); + return 0; +} + +void +pa_context_disconnect (pa_context *c) +{ + reinterpret_cast(c)->queueState(PA_CONTEXT_UNCONNECTED); +} + +int +pa_context_errno (pa_context *c) +{ + return 0; +} + +void +pa_context_set_state_callback (pa_context *c, pa_context_notify_cb_t cb, void *userdata) +{ + std::function cppcb([c, cb, userdata]() { + cb(c, userdata); + }); + reinterpret_cast(c)->addStateCallback(cppcb); +} + +pa_context_state_t +pa_context_get_state (pa_context *c) +{ + return reinterpret_cast(c)->getState(); +} + +/* ******************************* + * introspect.h + * *******************************/ + +typedef struct { + pa_server_info_cb_t cb; + gpointer userdata; + pa_context * context; +} get_server_info_t; + +static void +get_server_info_free (gpointer data) +{ + get_server_info_t * info = (get_server_info_t *)data; + g_object_unref(info->context); + g_free(info); +} + +static gboolean +get_server_info_cb (gpointer data) +{ + pa_server_info server{ + .user_name = "user", + .host_name = "host", + .server_version = "1.2.3", + .server_name = "server", + .sample_spec = { + .format = PA_SAMPLE_U8, + .rate = 44100, + .channels = 1 + }, + .default_sink_name = "default-sink", + .default_source_name = "default-source", + .cookie = 1234, + .channel_map = { + .channels = 0 + } + }; + get_server_info_t * info = (get_server_info_t *)data; + + info->cb(info->context, &server, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_get_server_info (pa_context *c, pa_server_info_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + g_return_val_if_fail(cb != nullptr, nullptr); + + get_server_info_t * info = g_new(get_server_info_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = (pa_context *)g_object_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_server_info_cb, + info, + get_server_info_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_sink_info_cb_t cb; + gpointer userdata; + pa_context * context; + uint32_t index; +} get_sink_info_t; + +static void +get_sink_info_free (gpointer data) +{ + get_sink_info_t * info = (get_sink_info_t *)data; + g_object_unref(info->context); + g_free(info); +} + +static gboolean +get_sink_info_cb (gpointer data) +{ + #if 0 + pa_sink_port_info active_port = { + .name = "speaker" + }; + #endif + pa_sink_info sink = {0}; + #if 0 + .name = "default-sink", + .index = 0, + .description = "Default Sink", + .channel_map = { + .channels = 0 + }, + .active_port = &active_port + }; + #endif + get_sink_info_t * info = (get_sink_info_t *)data; + + info->cb(info->context, &sink, 1, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_get_sink_info_by_name (pa_context *c, const gchar * name, pa_sink_info_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + g_return_val_if_fail(g_strcmp0(name, "default-sink") == 0, nullptr); + g_return_val_if_fail(cb != nullptr, nullptr); + + get_sink_info_t * info = g_new(get_sink_info_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = (pa_context *)g_object_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_sink_info_cb, + info, + get_sink_info_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +pa_operation* +pa_context_get_sink_info_list (pa_context *c, pa_sink_info_cb_t cb, void *userdata) +{ + /* Only have one today, so this is the same */ + return pa_context_get_sink_info_by_name(c, "default-sink", cb, userdata); +} + +typedef struct { + pa_sink_input_info_cb_t cb; + gpointer userdata; + pa_context * context; +} get_sink_input_info_t; + +static void +get_sink_input_info_free (gpointer data) +{ + get_sink_input_info_t * info = (get_sink_input_info_t *)data; + pa_context_unref(info->context); + g_free(info); +} + +static gboolean +get_sink_input_info_cb (gpointer data) +{ + pa_sink_input_info sink = { 0 }; + + get_sink_input_info_t * info = (get_sink_input_info_t *)data; + + info->cb(info->context, &sink, 0, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation * +pa_context_get_sink_input_info (pa_context *c, uint32_t idx, pa_sink_input_info_cb_t cb, void * userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + g_return_val_if_fail(cb != nullptr, nullptr); + + get_sink_input_info_t * info = g_new(get_sink_input_info_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = (pa_context *)g_object_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_sink_input_info_cb, + info, + get_sink_input_info_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_source_info_cb_t cb; + gpointer userdata; + pa_context * context; +} get_source_info_t; + +static void +get_source_info_free (gpointer data) +{ + get_source_info_t * info = (get_source_info_t *)data; + g_object_unref(info->context); + g_free(info); +} + +static gboolean +get_source_info_cb (gpointer data) +{ + pa_source_info source = { + .name = "default-source" + }; + get_source_info_t * info = (get_source_info_t *)data; + + info->cb(info->context, &source, 0, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_get_source_info_by_name (pa_context *c, const char * name, pa_source_info_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + g_return_val_if_fail(cb != nullptr, nullptr); + + get_source_info_t * info = g_new(get_source_info_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = (pa_context *)g_object_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_source_info_cb, + info, + get_source_info_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_source_output_info_cb_t cb; + gpointer userdata; + pa_context * context; +} get_source_output_t; + +static void +get_source_output_free (gpointer data) +{ + get_source_output_t * info = (get_source_output_t *)data; + g_object_unref(info->context); + g_free(info); +} + +static gboolean +get_source_output_cb (gpointer data) +{ + pa_source_output_info source = {0}; + source.name = "default source"; + + get_source_output_t * info = (get_source_output_t *)data; + + info->cb(info->context, &source, 0, info->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_get_source_output_info (pa_context *c, uint32_t idx, pa_source_output_info_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + g_return_val_if_fail(cb != nullptr, nullptr); + + get_source_output_t * info = g_new(get_source_output_t, 1); + info->cb = cb; + info->userdata = userdata; + info->context = (pa_context *)g_object_ref(c); + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + get_source_output_cb, + info, + get_source_output_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_context_success_cb_t cb; + gpointer userdata; + pa_context * context; + int mute; +} set_sink_mute_t; + +static void +set_sink_mute_free (gpointer data) +{ + set_sink_mute_t * mute = (set_sink_mute_t *)data; + g_object_unref(mute->context); + g_free(mute); +} + +static gboolean +set_sink_mute_cb (gpointer data) +{ + set_sink_mute_t * mute = (set_sink_mute_t *)data; + + if (mute->cb != nullptr) + mute->cb(mute->context, 1, mute->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_set_sink_mute_by_index (pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + + set_sink_mute_t * data = g_new(set_sink_mute_t, 1); + data->cb = cb; + data->userdata = userdata; + data->context = pa_context_ref(c); + data->mute = mute; + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + set_sink_mute_cb, + data, + set_sink_mute_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_context_success_cb_t cb; + gpointer userdata; + pa_context * context; + pa_cvolume cvol; +} set_sink_volume_t; + +static void +set_sink_volume_free (gpointer data) +{ + set_sink_volume_t * vol = (set_sink_volume_t *)data; + g_object_unref(vol->context); + g_free(vol); +} + +static gboolean +set_sink_volume_cb (gpointer data) +{ + set_sink_volume_t * vol = (set_sink_volume_t *)data; + + vol->cb(vol->context, 1, vol->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_set_sink_volume_by_index (pa_context *c, uint32_t idx, const pa_cvolume * cvol, pa_context_success_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + g_return_val_if_fail(cb != nullptr, nullptr); + + set_sink_volume_t * data = g_new(set_sink_volume_t, 1); + data->cb = cb; + data->userdata = userdata; + data->context = pa_context_ref(c); + data->cvol.channels = cvol->channels; + + int i; + for (i = 0; i < cvol->channels; i++) + data->cvol.values[i] = cvol->values[i]; + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + set_sink_volume_cb, + data, + set_sink_volume_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_context_success_cb_t cb; + gpointer userdata; + pa_context * context; + pa_cvolume cvol; +} set_source_volume_t; + +static void +set_source_volume_free (gpointer data) +{ + set_source_volume_t * vol = (set_source_volume_t *)data; + g_object_unref(vol->context); + g_free(vol); +} + +static gboolean +set_source_volume_cb (gpointer data) +{ + set_source_volume_t * vol = (set_source_volume_t *)data; + + vol->cb(vol->context, 1, vol->userdata); + + return G_SOURCE_REMOVE; +} + +pa_operation* +pa_context_set_source_volume_by_name (pa_context *c, const char * name, const pa_cvolume * cvol, pa_context_success_cb_t cb, void *userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + g_return_val_if_fail(cb != nullptr, nullptr); + + set_source_volume_t * data = g_new(set_source_volume_t, 1); + data->cb = cb; + data->userdata = userdata; + data->context = pa_context_ref(c); + data->cvol.channels = cvol->channels; + + int i; + for (i = 0; i < cvol->channels; i++) + data->cvol.values[i] = cvol->values[i]; + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + set_source_volume_cb, + data, + set_source_volume_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +/* ******************************* + * subscribe.h + * *******************************/ + +typedef struct { + pa_context_success_cb_t cb; + gpointer userdata; + pa_context * context; + pa_subscription_mask_t mask; +} subscribe_mask_t; + +static void +subscribe_mask_free (gpointer data) +{ + subscribe_mask_t * mask_data = (subscribe_mask_t *)data; + g_object_unref(mask_data->context); + g_free(mask_data); +} + +static gboolean +subscribe_mask_cb (gpointer data) +{ + subscribe_mask_t * mask_data = (subscribe_mask_t *)data; + g_object_set_qdata(G_OBJECT(mask_data->context), subscribe_mask_quark(), GINT_TO_POINTER(mask_data->mask)); + if (mask_data->cb != nullptr) + mask_data->cb(mask_data->context, 1, mask_data->userdata); + return G_SOURCE_REMOVE; +} + +pa_operation * +pa_context_subscribe (pa_context * c, pa_subscription_mask_t mask, pa_context_success_cb_t callback, void * userdata) +{ + g_return_val_if_fail(G_IS_OBJECT(c), nullptr); + + subscribe_mask_t * data = g_new0(subscribe_mask_t, 1); + data->cb = callback; + data->userdata = userdata; + data->context = pa_context_ref(c); + data->mask = mask; + + g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, + subscribe_mask_cb, + data, + subscribe_mask_free); + + GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); + pa_operation * oper = (pa_operation *)goper; + return oper; +} + +typedef struct { + pa_context_subscribe_cb_t cb; + gpointer userdata; +} subscribe_cb_t; + +void +pa_context_set_subscribe_callback (pa_context * c, pa_context_subscribe_cb_t callback, void * userdata) +{ + g_return_if_fail(G_IS_OBJECT(c)); + + subscribe_cb_t * sub = g_new0(subscribe_cb_t, 1); + sub->cb = callback; + sub->userdata = userdata; + + g_object_set_qdata_full(G_OBJECT(c), subscribe_cb_quark(), sub, g_free); +} + +/* ******************************* + * glib-mainloop.h + * *******************************/ + +struct pa_glib_mainloop { + GMainContext * context; +}; + +struct pa_mainloop_api mock_mainloop = { 0 }; + +pa_mainloop_api * +pa_glib_mainloop_get_api (pa_glib_mainloop * g) +{ + return &mock_mainloop; +} + +pa_glib_mainloop * +pa_glib_mainloop_new (GMainContext * c) +{ + pa_glib_mainloop * loop = g_new0(pa_glib_mainloop, 1); + + if (c == nullptr) + loop->context = g_main_context_default(); + else + loop->context = c; + + g_main_context_ref(loop->context); + return loop; +} + +void +pa_glib_mainloop_free (pa_glib_mainloop * g) +{ + g_main_context_unref(g->context); + g_free(g); +} + +/* ******************************* + * operation.h + * *******************************/ + +void +pa_operation_unref (pa_operation * operation) +{ + g_return_if_fail(G_IS_OBJECT(operation)); + g_object_unref(G_OBJECT(operation)); +} + +/* ******************************* + * proplist.h + * *******************************/ + +pa_proplist * +pa_proplist_new (void) +{ + return (pa_proplist *)g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); +} + +void +pa_proplist_free (pa_proplist * p) +{ + g_return_if_fail(p != nullptr); + g_hash_table_destroy((GHashTable *)p); +} + +const char * +pa_proplist_gets (pa_proplist * p, const char * key) +{ + g_return_val_if_fail(p != nullptr, nullptr); + g_return_val_if_fail(key != nullptr, nullptr); + return (const char *)g_hash_table_lookup((GHashTable *)p, key); +} + +int +pa_proplist_sets (pa_proplist *p, const char * key, const char * value) +{ + g_return_val_if_fail(p != nullptr, -1); + g_return_val_if_fail(key != nullptr, -1); + g_return_val_if_fail(value != nullptr, -1); + + g_hash_table_insert((GHashTable *)p, g_strdup(key), g_strdup(value)); + return 0; +} + +/* ******************************* + * error.h + * *******************************/ + +const char * +pa_strerror (int error) +{ + return "This is error text"; +} + +/* ******************************* + * volume.h + * *******************************/ + +pa_volume_t +pa_sw_volume_from_dB (double f) +{ + double linear = pow(10.0, f / 20.0); + + pa_volume_t calculated = lround(cbrt(linear) * PA_VOLUME_NORM); + + if (G_UNLIKELY(calculated > PA_VOLUME_MAX)) { + return PA_VOLUME_MAX; + } else if (G_UNLIKELY(calculated < PA_VOLUME_MUTED)) { + return PA_VOLUME_MUTED; + } else { + return calculated; + } +} + +pa_cvolume * +pa_cvolume_init (pa_cvolume * cvol) +{ + g_return_val_if_fail(cvol != nullptr, nullptr); + + cvol->channels = 0; + + unsigned int i; + for (i = 0; i < PA_CHANNELS_MAX; i++) + cvol->values[i] = PA_VOLUME_INVALID; + + return cvol; +} + +pa_cvolume * +pa_cvolume_set (pa_cvolume * cvol, unsigned channels, pa_volume_t volume) +{ + g_return_val_if_fail(cvol != nullptr, nullptr); + g_warn_if_fail(channels > 0); + g_return_val_if_fail(channels <= PA_CHANNELS_MAX, nullptr); + + cvol->channels = channels; + + unsigned int i; + for (i = 0; i < channels; i++) { + if (G_UNLIKELY(volume > PA_VOLUME_MAX)) { + cvol->values[i] = PA_VOLUME_MAX; + } else if (G_UNLIKELY(volume < PA_VOLUME_MUTED)) { + cvol->values[i] = PA_VOLUME_MUTED; + } else { + cvol->values[i] = volume; + } + } + + return cvol; +} + +pa_volume_t +pa_cvolume_max (const pa_cvolume * cvol) +{ + g_return_val_if_fail(cvol != nullptr, PA_VOLUME_MUTED); + pa_volume_t max = PA_VOLUME_MUTED; + + unsigned int i; + for (i = 0; i < cvol->channels; i++) + max = MAX(max, cvol->values[i]); + + return max; +} + +pa_cvolume * +pa_cvolume_scale (pa_cvolume * cvol, pa_volume_t max) +{ + g_return_val_if_fail(cvol != nullptr, nullptr); + + pa_volume_t originalmax = pa_cvolume_max(cvol); + + if (originalmax <= PA_VOLUME_MUTED) + return pa_cvolume_set(cvol, cvol->channels, max); + + unsigned int i; + for (i = 0; i < cvol->channels; i++) { + pa_volume_t calculated = (cvol->values[i] * max) / originalmax; + + if (G_UNLIKELY(calculated > PA_VOLUME_MAX)) { + cvol->values[i] = PA_VOLUME_MAX; + } else if (G_UNLIKELY(calculated < PA_VOLUME_MUTED)) { + cvol->values[i] = PA_VOLUME_MUTED; + } else { + cvol->values[i] = calculated; + } + } + + return cvol; +} + -- cgit v1.2.3 From 701b0a3df9c394814d8144e720cb63d9aa3efb0c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Jan 2015 16:22:19 -0600 Subject: Refactor out common code --- tests/pa-mock.cpp | 532 ++++++++++++------------------------------------------ 1 file changed, 113 insertions(+), 419 deletions(-) diff --git a/tests/pa-mock.cpp b/tests/pa-mock.cpp index 5b433fe..990b10f 100644 --- a/tests/pa-mock.cpp +++ b/tests/pa-mock.cpp @@ -13,12 +13,6 @@ #endif #define G_LOG_DOMAIN "PA-Mock" -G_DEFINE_QUARK("pa-mock-state-cb-list", state_cb); -G_DEFINE_QUARK("pa-mock-subscribe-callback", subscribe_cb); -G_DEFINE_QUARK("pa-mock-subscribe-mask", subscribe_mask); -G_DEFINE_QUARK("pa-mock-current-state", state); -G_DEFINE_QUARK("pa-mock-future-state", state_future); - /* Core class of the PA Mock state */ class PAMockContext { public: @@ -32,13 +26,13 @@ public: /* Event stuff */ std::vector> eventCallbacks; - pa_subscription_mask_t mask; + pa_subscription_mask_t eventMask; PAMockContext () : refcnt(1) , currentState(PA_CONTEXT_UNCONNECTED) , futureState(PA_CONTEXT_UNCONNECTED) - , mask(PA_SUBSCRIPTION_MASK_NULL) + , eventMask(PA_SUBSCRIPTION_MASK_NULL) { g_debug("Creating Context: %p", this); } @@ -107,11 +101,16 @@ public: { stateCallbacks.push_back(callback); } -}; -struct pa_context { - operator PAMockContext * () { - return reinterpret_cast(this); + /* Event Stuff */ + void setMask (pa_subscription_mask_t mask) + { + eventMask = mask; + } + + void addEventCallback (std::function &callback) + { + eventCallbacks.push_back(callback); } }; @@ -174,129 +173,68 @@ pa_context_get_state (pa_context *c) * introspect.h * *******************************/ -typedef struct { - pa_server_info_cb_t cb; - gpointer userdata; - pa_context * context; -} get_server_info_t; - -static void -get_server_info_free (gpointer data) -{ - get_server_info_t * info = (get_server_info_t *)data; - g_object_unref(info->context); - g_free(info); -} - -static gboolean -get_server_info_cb (gpointer data) -{ - pa_server_info server{ - .user_name = "user", - .host_name = "host", - .server_version = "1.2.3", - .server_name = "server", - .sample_spec = { - .format = PA_SAMPLE_U8, - .rate = 44100, - .channels = 1 - }, - .default_sink_name = "default-sink", - .default_source_name = "default-source", - .cookie = 1234, - .channel_map = { - .channels = 0 - } - }; - get_server_info_t * info = (get_server_info_t *)data; - - info->cb(info->context, &server, info->userdata); - - return G_SOURCE_REMOVE; -} - -pa_operation* -pa_context_get_server_info (pa_context *c, pa_server_info_cb_t cb, void *userdata) +static pa_operation * +dummy_operation (void) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - g_return_val_if_fail(cb != nullptr, nullptr); - - get_server_info_t * info = g_new(get_server_info_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = (pa_context *)g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_server_info_cb, - info, - get_server_info_free); - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); pa_operation * oper = (pa_operation *)goper; return oper; } -typedef struct { - pa_sink_info_cb_t cb; - gpointer userdata; - pa_context * context; - uint32_t index; -} get_sink_info_t; - -static void -get_sink_info_free (gpointer data) -{ - get_sink_info_t * info = (get_sink_info_t *)data; - g_object_unref(info->context); - g_free(info); -} - -static gboolean -get_sink_info_cb (gpointer data) +pa_operation* +pa_context_get_server_info (pa_context *c, pa_server_info_cb_t cb, void *userdata) { - #if 0 - pa_sink_port_info active_port = { - .name = "speaker" - }; - #endif - pa_sink_info sink = {0}; - #if 0 - .name = "default-sink", - .index = 0, - .description = "Default Sink", - .channel_map = { - .channels = 0 - }, - .active_port = &active_port - }; - #endif - get_sink_info_t * info = (get_sink_info_t *)data; + reinterpret_cast(c)->idleOnce( + [c, cb, userdata]() { + if (cb == nullptr) + return; - info->cb(info->context, &sink, 1, info->userdata); + pa_server_info server{ + .user_name = "user", + .host_name = "host", + .server_version = "1.2.3", + .server_name = "server", + .sample_spec = { + .format = PA_SAMPLE_U8, + .rate = 44100, + .channels = 1 + }, + .default_sink_name = "default-sink", + .default_source_name = "default-source", + .cookie = 1234, + .channel_map = { + .channels = 0 + } + }; + + cb(c, &server, userdata); + }); - return G_SOURCE_REMOVE; + return dummy_operation(); } pa_operation* pa_context_get_sink_info_by_name (pa_context *c, const gchar * name, pa_sink_info_cb_t cb, void *userdata) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - g_return_val_if_fail(g_strcmp0(name, "default-sink") == 0, nullptr); - g_return_val_if_fail(cb != nullptr, nullptr); + reinterpret_cast(c)->idleOnce( + [c, name, cb, userdata]() { + if (cb == nullptr) + return; - get_sink_info_t * info = g_new(get_sink_info_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = (pa_context *)g_object_ref(c); + pa_sink_port_info active_port = {0}; + active_port.name = "speaker"; - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_sink_info_cb, - info, - get_sink_info_free); + pa_sink_info sink = {0}; + sink.name = "default-sink"; + sink.index = 0; + sink.description = "Default Sink"; + sink.channel_map.channels = 0; + sink.active_port = &active_port; - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); - pa_operation * oper = (pa_operation *)goper; - return oper; + cb(c, &sink, 1, userdata); + }); + + return dummy_operation(); } pa_operation* @@ -306,363 +244,119 @@ pa_context_get_sink_info_list (pa_context *c, pa_sink_info_cb_t cb, void *userda return pa_context_get_sink_info_by_name(c, "default-sink", cb, userdata); } -typedef struct { - pa_sink_input_info_cb_t cb; - gpointer userdata; - pa_context * context; -} get_sink_input_info_t; - -static void -get_sink_input_info_free (gpointer data) -{ - get_sink_input_info_t * info = (get_sink_input_info_t *)data; - pa_context_unref(info->context); - g_free(info); -} - -static gboolean -get_sink_input_info_cb (gpointer data) -{ - pa_sink_input_info sink = { 0 }; - - get_sink_input_info_t * info = (get_sink_input_info_t *)data; - - info->cb(info->context, &sink, 0, info->userdata); - - return G_SOURCE_REMOVE; -} - pa_operation * pa_context_get_sink_input_info (pa_context *c, uint32_t idx, pa_sink_input_info_cb_t cb, void * userdata) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - g_return_val_if_fail(cb != nullptr, nullptr); - - get_sink_input_info_t * info = g_new(get_sink_input_info_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = (pa_context *)g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_sink_input_info_cb, - info, - get_sink_input_info_free); - - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_source_info_cb_t cb; - gpointer userdata; - pa_context * context; -} get_source_info_t; + reinterpret_cast(c)->idleOnce( + [c, idx, cb, userdata]() { + if (cb == nullptr) + return; -static void -get_source_info_free (gpointer data) -{ - get_source_info_t * info = (get_source_info_t *)data; - g_object_unref(info->context); - g_free(info); -} + pa_sink_input_info sink = { 0 }; -static gboolean -get_source_info_cb (gpointer data) -{ - pa_source_info source = { - .name = "default-source" - }; - get_source_info_t * info = (get_source_info_t *)data; - - info->cb(info->context, &source, 0, info->userdata); + cb(c, &sink, 1, userdata); + }); - return G_SOURCE_REMOVE; + return dummy_operation(); } pa_operation* pa_context_get_source_info_by_name (pa_context *c, const char * name, pa_source_info_cb_t cb, void *userdata) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - g_return_val_if_fail(cb != nullptr, nullptr); - - get_source_info_t * info = g_new(get_source_info_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = (pa_context *)g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_source_info_cb, - info, - get_source_info_free); - - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_source_output_info_cb_t cb; - gpointer userdata; - pa_context * context; -} get_source_output_t; - -static void -get_source_output_free (gpointer data) -{ - get_source_output_t * info = (get_source_output_t *)data; - g_object_unref(info->context); - g_free(info); -} - -static gboolean -get_source_output_cb (gpointer data) -{ - pa_source_output_info source = {0}; - source.name = "default source"; + reinterpret_cast(c)->idleOnce( + [c, name, cb, userdata]() { + if (cb == nullptr) + return; - get_source_output_t * info = (get_source_output_t *)data; + pa_source_info source = { + .name = "default-source" + }; - info->cb(info->context, &source, 0, info->userdata); + cb(c, &source, 1, userdata); + }); - return G_SOURCE_REMOVE; + return dummy_operation(); } pa_operation* pa_context_get_source_output_info (pa_context *c, uint32_t idx, pa_source_output_info_cb_t cb, void *userdata) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - g_return_val_if_fail(cb != nullptr, nullptr); - - get_source_output_t * info = g_new(get_source_output_t, 1); - info->cb = cb; - info->userdata = userdata; - info->context = (pa_context *)g_object_ref(c); - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - get_source_output_cb, - info, - get_source_output_free); - - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_context_success_cb_t cb; - gpointer userdata; - pa_context * context; - int mute; -} set_sink_mute_t; - -static void -set_sink_mute_free (gpointer data) -{ - set_sink_mute_t * mute = (set_sink_mute_t *)data; - g_object_unref(mute->context); - g_free(mute); -} + reinterpret_cast(c)->idleOnce( + [c, idx, cb, userdata]() { + if (cb == nullptr) + return; -static gboolean -set_sink_mute_cb (gpointer data) -{ - set_sink_mute_t * mute = (set_sink_mute_t *)data; + pa_source_output_info source = {0}; + source.name = "default source"; - if (mute->cb != nullptr) - mute->cb(mute->context, 1, mute->userdata); + cb(c, &source, 1, userdata); + }); - return G_SOURCE_REMOVE; + return dummy_operation(); } pa_operation* pa_context_set_sink_mute_by_index (pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - - set_sink_mute_t * data = g_new(set_sink_mute_t, 1); - data->cb = cb; - data->userdata = userdata; - data->context = pa_context_ref(c); - data->mute = mute; - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - set_sink_mute_cb, - data, - set_sink_mute_free); - - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_context_success_cb_t cb; - gpointer userdata; - pa_context * context; - pa_cvolume cvol; -} set_sink_volume_t; - -static void -set_sink_volume_free (gpointer data) -{ - set_sink_volume_t * vol = (set_sink_volume_t *)data; - g_object_unref(vol->context); - g_free(vol); -} - -static gboolean -set_sink_volume_cb (gpointer data) -{ - set_sink_volume_t * vol = (set_sink_volume_t *)data; - - vol->cb(vol->context, 1, vol->userdata); + reinterpret_cast(c)->idleOnce( + [c, idx, mute, cb, userdata]() { + if (cb != nullptr) + cb(c, 1, userdata); + }); - return G_SOURCE_REMOVE; + return dummy_operation(); } pa_operation* pa_context_set_sink_volume_by_index (pa_context *c, uint32_t idx, const pa_cvolume * cvol, pa_context_success_cb_t cb, void *userdata) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - g_return_val_if_fail(cb != nullptr, nullptr); - - set_sink_volume_t * data = g_new(set_sink_volume_t, 1); - data->cb = cb; - data->userdata = userdata; - data->context = pa_context_ref(c); - data->cvol.channels = cvol->channels; - - int i; - for (i = 0; i < cvol->channels; i++) - data->cvol.values[i] = cvol->values[i]; - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - set_sink_volume_cb, - data, - set_sink_volume_free); - - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); - pa_operation * oper = (pa_operation *)goper; - return oper; -} - -typedef struct { - pa_context_success_cb_t cb; - gpointer userdata; - pa_context * context; - pa_cvolume cvol; -} set_source_volume_t; - -static void -set_source_volume_free (gpointer data) -{ - set_source_volume_t * vol = (set_source_volume_t *)data; - g_object_unref(vol->context); - g_free(vol); -} - -static gboolean -set_source_volume_cb (gpointer data) -{ - set_source_volume_t * vol = (set_source_volume_t *)data; - - vol->cb(vol->context, 1, vol->userdata); + reinterpret_cast(c)->idleOnce( + [c, idx, cvol, cb, userdata]() { + if (cb != nullptr) + cb(c, 1, userdata); + }); - return G_SOURCE_REMOVE; + return dummy_operation(); } pa_operation* pa_context_set_source_volume_by_name (pa_context *c, const char * name, const pa_cvolume * cvol, pa_context_success_cb_t cb, void *userdata) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - g_return_val_if_fail(cb != nullptr, nullptr); - - set_source_volume_t * data = g_new(set_source_volume_t, 1); - data->cb = cb; - data->userdata = userdata; - data->context = pa_context_ref(c); - data->cvol.channels = cvol->channels; - - int i; - for (i = 0; i < cvol->channels; i++) - data->cvol.values[i] = cvol->values[i]; - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - set_source_volume_cb, - data, - set_source_volume_free); + reinterpret_cast(c)->idleOnce( + [c, name, cvol, cb, userdata]() { + if (cb != nullptr) + cb(c, 1, userdata); + }); - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); - pa_operation * oper = (pa_operation *)goper; - return oper; + return dummy_operation(); } /* ******************************* * subscribe.h * *******************************/ -typedef struct { - pa_context_success_cb_t cb; - gpointer userdata; - pa_context * context; - pa_subscription_mask_t mask; -} subscribe_mask_t; - -static void -subscribe_mask_free (gpointer data) -{ - subscribe_mask_t * mask_data = (subscribe_mask_t *)data; - g_object_unref(mask_data->context); - g_free(mask_data); -} - -static gboolean -subscribe_mask_cb (gpointer data) -{ - subscribe_mask_t * mask_data = (subscribe_mask_t *)data; - g_object_set_qdata(G_OBJECT(mask_data->context), subscribe_mask_quark(), GINT_TO_POINTER(mask_data->mask)); - if (mask_data->cb != nullptr) - mask_data->cb(mask_data->context, 1, mask_data->userdata); - return G_SOURCE_REMOVE; -} - pa_operation * pa_context_subscribe (pa_context * c, pa_subscription_mask_t mask, pa_context_success_cb_t callback, void * userdata) { - g_return_val_if_fail(G_IS_OBJECT(c), nullptr); - - subscribe_mask_t * data = g_new0(subscribe_mask_t, 1); - data->cb = callback; - data->userdata = userdata; - data->context = pa_context_ref(c); - data->mask = mask; - - g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, - subscribe_mask_cb, - data, - subscribe_mask_free); + reinterpret_cast(c)->idleOnce( + [c, mask, callback, userdata]() { + reinterpret_cast(c)->setMask(mask); + if (callback != nullptr) + callback(c, 1, userdata); + }); - GObject * goper = (GObject *)g_object_new(G_TYPE_OBJECT, nullptr); - pa_operation * oper = (pa_operation *)goper; - return oper; + return dummy_operation(); } -typedef struct { - pa_context_subscribe_cb_t cb; - gpointer userdata; -} subscribe_cb_t; - void pa_context_set_subscribe_callback (pa_context * c, pa_context_subscribe_cb_t callback, void * userdata) { - g_return_if_fail(G_IS_OBJECT(c)); - - subscribe_cb_t * sub = g_new0(subscribe_cb_t, 1); - sub->cb = callback; - sub->userdata = userdata; + std::function cppcb([c, callback, userdata](pa_subscription_event_type_t event, uint32_t index) { + if (callback != nullptr) + callback(c, event, index, userdata); + }); - g_object_set_qdata_full(G_OBJECT(c), subscribe_cb_quark(), sub, g_free); + reinterpret_cast(c)->addEventCallback(cppcb); } /* ******************************* -- cgit v1.2.3 From d744a701bebec0b95b7640db1cbe6444632770b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Jan 2015 16:24:05 -0600 Subject: Adding a copyright header --- tests/pa-mock.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/pa-mock.cpp b/tests/pa-mock.cpp index 990b10f..8ca2374 100644 --- a/tests/pa-mock.cpp +++ b/tests/pa-mock.cpp @@ -1,3 +1,21 @@ +/* + * 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: + * Ted Gould + */ #include #include -- cgit v1.2.3