pulsemixer: Implement MIXER_FLAG_AUTO_NOTIFICATIONS
authorJan Schmidt <thaytan@noraisin.net>
Fri, 29 Oct 2010 21:50:14 +0000 (22:50 +0100)
committerJan Schmidt <jan.schmidt@oracle.com>
Sat, 11 Dec 2010 05:08:40 +0000 (16:08 +1100)
Add the mixer flag and send notifications when either the volume or muted
status changes.

    https://bugzilla.gnome.org/show_bug.cgi?id=618389

ext/pulse/pulsemixerctrl.c
ext/pulse/pulsemixerctrl.h

index be5b536..220c8d0 100644 (file)
@@ -61,6 +61,8 @@ gst_pulsemixer_ctrl_sink_info_cb (pa_context * context, const pa_sink_info * i,
     int eol, void *userdata)
 {
   GstPulseMixerCtrl *c = userdata;
+  gboolean vol_chg = FALSE;
+  gboolean old_mute;
 
   /* Called from the background thread! */
 
@@ -90,8 +92,10 @@ gst_pulsemixer_ctrl_sink_info_cb (pa_context * context, const pa_sink_info * i,
   c->description = g_strdup (i->description);
   c->index = i->index;
   c->channel_map = i->channel_map;
+  vol_chg = !pa_cvolume_equal (&c->volume, &i->volume);
   c->volume = i->volume;
-  c->muted = ! !i->mute;
+  old_mute = c->muted;
+  c->muted = !!i->mute;
   c->type = GST_PULSEMIXER_SINK;
 
   if (c->track) {
@@ -104,6 +108,19 @@ gst_pulsemixer_ctrl_sink_info_cb (pa_context * context, const pa_sink_info * i,
 
   c->operation_success = TRUE;
   pa_threaded_mainloop_signal (c->mainloop, 0);
+
+  if (vol_chg && c->track) {
+    gint volumes[PA_CHANNELS_MAX];
+    gint i;
+    for (i = 0; i < c->volume.channels; i++)
+      volumes[i] = (gint) (c->volume.values[i]);
+    GST_LOG_OBJECT (c->object, "Sending volume change notification");
+    gst_mixer_volume_changed (GST_MIXER (c->object), c->track, volumes);
+  }
+  if ((c->muted != old_mute) && c->track) {
+    GST_LOG_OBJECT (c->object, "Sending mute toggled notification");
+    gst_mixer_mute_toggled (GST_MIXER (c->object), c->track, c->muted);
+  }
 }
 
 static void
@@ -111,6 +128,8 @@ gst_pulsemixer_ctrl_source_info_cb (pa_context * context,
     const pa_source_info * i, int eol, void *userdata)
 {
   GstPulseMixerCtrl *c = userdata;
+  gboolean vol_chg = FALSE;
+  gboolean old_mute;
 
   /* Called from the background thread! */
 
@@ -140,8 +159,10 @@ gst_pulsemixer_ctrl_source_info_cb (pa_context * context,
   c->description = g_strdup (i->description);
   c->index = i->index;
   c->channel_map = i->channel_map;
+  vol_chg = !pa_cvolume_equal (&c->volume, &i->volume);
   c->volume = i->volume;
-  c->muted = ! !i->mute;
+  old_mute = c->muted;
+  c->muted = !!i->mute;
   c->type = GST_PULSEMIXER_SOURCE;
 
   if (c->track) {
@@ -154,6 +175,19 @@ gst_pulsemixer_ctrl_source_info_cb (pa_context * context,
 
   c->operation_success = TRUE;
   pa_threaded_mainloop_signal (c->mainloop, 0);
+
+  if (vol_chg && c->track) {
+    gint volumes[PA_CHANNELS_MAX];
+    gint i;
+    for (i = 0; i < c->volume.channels; i++)
+      volumes[i] = (gint) (c->volume.values[i]);
+    GST_LOG_OBJECT (c->object, "Sending volume change notification");
+    gst_mixer_volume_changed (GST_MIXER (c->object), c->track, volumes);
+  }
+  if ((c->muted != old_mute) && c->track) {
+    GST_LOG_OBJECT (c->object, "Sending mute toggled notification");
+    gst_mixer_mute_toggled (GST_MIXER (c->object), c->track, c->muted);
+  }
 }
 
 static void
@@ -195,7 +229,7 @@ gst_pulsemixer_ctrl_success_cb (pa_context * context, int success,
 {
   GstPulseMixerCtrl *c = (GstPulseMixerCtrl *) userdata;
 
-  c->operation_success = ! !success;
+  c->operation_success = !!success;
   pa_threaded_mainloop_signal (c->mainloop, 0);
 }
 
@@ -395,6 +429,8 @@ gst_pulsemixer_ctrl_new (GObject * object, const gchar * server,
     const gchar * device, GstPulseMixerType type)
 {
   GstPulseMixerCtrl *c = NULL;
+  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE ((object),
+          GST_TYPE_MIXER), c);
 
   GST_DEBUG_OBJECT (object, "new mixer ctrl for %s", device);
   c = g_new (GstPulseMixerCtrl, 1);
@@ -596,3 +632,9 @@ gst_pulsemixer_ctrl_set_mute (GstPulseMixerCtrl * c, GstMixerTrack * track,
 
   pa_threaded_mainloop_unlock (c->mainloop);
 }
+
+GstMixerFlags
+gst_pulsemixer_ctrl_get_mixer_flags (GstPulseMixerCtrl * mixer)
+{
+  return GST_MIXER_FLAG_AUTO_NOTIFICATIONS;
+}
index e6b67ad..c1d1e85 100644 (file)
@@ -90,6 +90,7 @@ void gst_pulsemixer_ctrl_set_mute (GstPulseMixerCtrl * mixer,
     GstMixerTrack * track, gboolean mute);
 void gst_pulsemixer_ctrl_set_record (GstPulseMixerCtrl * mixer,
     GstMixerTrack * track, gboolean record);
+GstMixerFlags gst_pulsemixer_ctrl_get_mixer_flags (GstPulseMixerCtrl * mixer);
 
 #define GST_IMPLEMENT_PULSEMIXER_CTRL_METHODS(Type, interface_as_function)     \
 static const GList*                                                             \
@@ -146,6 +147,16 @@ interface_as_function ## _set_mute (GstMixer * mixer, GstMixerTrack * track,
                                                                                 \
   gst_pulsemixer_ctrl_set_mute (this->mixer, track, mute);                      \
 }                                                                               \
+static GstMixerFlags                                                            \
+interface_as_function ## _get_mixer_flags (GstMixer * mixer)                    \
+{                                                                               \
+  Type *this = (Type*) mixer;                                                   \
+                                                                                \
+  g_return_val_if_fail (this != NULL, GST_MIXER_FLAG_NONE);                     \
+  g_return_val_if_fail (this->mixer != NULL, GST_MIXER_FLAG_NONE);              \
+                                                                                \
+  return gst_pulsemixer_ctrl_get_mixer_flags (this->mixer);                          \
+} \
 static void                                                                     \
 interface_as_function ## _mixer_interface_init (GstMixerClass * klass)          \
 {                                                                               \
@@ -156,6 +167,7 @@ interface_as_function ## _mixer_interface_init (GstMixerClass * klass)
   klass->get_volume  = interface_as_function ## _get_volume;                    \
   klass->set_mute    = interface_as_function ## _set_mute;                      \
   klass->set_record  = interface_as_function ## _set_record;                    \
+  klass->get_mixer_flags = interface_as_function ## _get_mixer_flags; \
 }
 
 G_END_DECLS