gnome-media r3873 - in trunk: . gst-mixer/src



Author: malureau
Date: Mon Jun  2 18:59:38 2008
New Revision: 3873
URL: http://svn.gnome.org/viewvc/gnome-media?rev=3873&view=rev

Log:
2008-06-02  Marc-Andrà Lureau  <marcandre lureau gmail com>

	* gst-mixer/src/element.c:
	* gst-mixer/src/track.{c,h}:
	* gst-mixer/src/volume.{c,h}:

	Listen to GStreamer bus events for mixers that supports it.
	(Closes #462164)


Modified:
   trunk/ChangeLog
   trunk/gst-mixer/src/element.c
   trunk/gst-mixer/src/track.c
   trunk/gst-mixer/src/track.h
   trunk/gst-mixer/src/volume.c
   trunk/gst-mixer/src/volume.h

Modified: trunk/gst-mixer/src/element.c
==============================================================================
--- trunk/gst-mixer/src/element.c	(original)
+++ trunk/gst-mixer/src/element.c	Mon Jun  2 18:59:38 2008
@@ -148,7 +148,7 @@
        item != NULL; item = item->next) {
     GstMixerTrack *track = item->data;
     GnomeVolumeControlTrack *trkw =
-        g_object_get_data (G_OBJECT (track), "gnome-volume-control-trkw"); 
+        g_object_get_data (G_OBJECT (track), "gnome-volume-control-trkw");
 
     if (get_page_num (track) == page && trkw->visible) {
       visible = TRUE;
@@ -163,6 +163,35 @@
     gtk_widget_hide (t);
 }
 
+static void
+cb_notify_message (GstBus *bus, GstMessage *message, gpointer data)
+{
+  GnomeVolumeControlElement *el = data;
+  GstMixerMessageType type;
+  GnomeVolumeControlTrack *trkw;
+  GstMixerTrack *track = NULL;
+
+  if (GST_MESSAGE_SRC (message) != GST_OBJECT (el->mixer)) {
+    /* not from our mixer - can't update anything anyway */
+    return;
+  }
+
+  /* This code only calls refresh if the first_track changes, because the
+   * refresh code only retrieves the current value from that track anyway */
+  type = gst_mixer_message_get_type (message);
+  if (type == GST_MIXER_MESSAGE_MUTE_TOGGLED) {
+    gst_mixer_message_parse_mute_toggled (message, &track, NULL);
+  }
+  else {
+    gst_mixer_message_parse_volume_changed (message, &track, NULL, NULL);
+  }
+
+  trkw = g_object_get_data (G_OBJECT (track),
+			    "gnome-volume-control-trkw");
+
+  gnome_volume_control_track_update (trkw);
+}
+
 /*
  * Change the element. Basically recreates this object internally.
  */
@@ -196,6 +225,7 @@
   gint i;
   const GList *item;
   GstMixer *mixer;
+  GstBus *bus;
 
   /* remove old pages */
   while (gtk_notebook_get_n_pages (GTK_NOTEBOOK (el)) > 0) {
@@ -211,6 +241,7 @@
 
       trkw = g_object_get_data (G_OBJECT (track),
 				"gnome-volume-control-trkw");
+      g_object_set_data (G_OBJECT (track), "gnome-volume-control-trkw", NULL);
       gnome_volume_control_track_free (trkw);
     }
   }
@@ -221,6 +252,15 @@
   mixer = GST_MIXER (element);
   gst_object_replace ((GstObject **) &el->mixer, GST_OBJECT (element));
 
+  /* Bus for notifications */
+  if (GST_ELEMENT_BUS (mixer) == NULL) {
+    bus = gst_bus_new ();
+    gst_bus_add_signal_watch (bus);
+    g_signal_connect (G_OBJECT (bus), "message::element",
+		      (GCallback) cb_notify_message, el);
+    gst_element_set_bus (GST_ELEMENT (mixer), bus);
+  }
+
   /* content pages */
   for (i = 0; i < 4; i++) {
     content[i].page = gtk_table_new (content[i].width, content[i].height, FALSE);

Modified: trunk/gst-mixer/src/track.c
==============================================================================
--- trunk/gst-mixer/src/track.c	(original)
+++ trunk/gst-mixer/src/track.c	Mon Jun  2 18:59:38 2008
@@ -82,7 +82,7 @@
 {
   return GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_INPUT);
 }
- 
+
 
 static void
 cb_toggle_changed (GtkToggleButton *button,
@@ -116,26 +116,28 @@
  * Timeout to check for changes in mixer outside ourselves.
  */
 
-static gboolean
-cb_check (gpointer data)
+void
+gnome_volume_control_track_update (GnomeVolumeControlTrack *trkw)
 {
-  GnomeVolumeControlTrack *trkw = data;
   gboolean mute, record;
   gboolean vol_is_zero = FALSE, slider_is_zero = FALSE;
 
+  g_return_if_fail (trkw != NULL);
+
   /* trigger an update of the mixer state */
   if (!GST_IS_MIXER_OPTIONS (trkw->track)) {
     gint *dummy = g_new (gint, MAX (trkw->track->num_channels, 1));
     gst_mixer_get_volume (trkw->mixer, trkw->track, dummy);
     g_free (dummy);
   }
-  
+
   mute = GST_MIXER_TRACK_HAS_FLAG (trkw->track,
 				GST_MIXER_TRACK_MUTE) ? TRUE : FALSE;
   record = GST_MIXER_TRACK_HAS_FLAG (trkw->track,
 				GST_MIXER_TRACK_RECORD) ? TRUE : FALSE;
 
   if (trkw->sliderbox) {
+    gnome_volume_control_volume_update (trkw->sliderbox);
     gnome_volume_control_volume_ask (
       GNOME_VOLUME_CONTROL_VOLUME (trkw->sliderbox),
       &vol_is_zero, &slider_is_zero);
@@ -168,6 +170,13 @@
   /* FIXME:
    * - options.
    */
+}
+
+
+static gboolean
+cb_check (gpointer data)
+{
+  gnome_volume_control_track_update (data);
 
   return TRUE;
 }
@@ -189,6 +198,10 @@
   gchar *ulabel = NULL;
   gchar *str = NULL;
   gint i;
+  gboolean need_timeout = TRUE;
+
+  need_timeout = ((gst_mixer_get_mixer_flags (GST_MIXER (mixer)) &
+		   GST_MIXER_FLAG_AUTO_NOTIFICATIONS) == 0);
 
   /* start */
   ctrl = g_new0 (GnomeVolumeControlTrack, 1);
@@ -200,7 +213,8 @@
   ctrl->visible = TRUE;
   ctrl->table = table;
   ctrl->pos = tab_pos;
-  ctrl->id = g_timeout_add (200, cb_check, ctrl);
+  if (need_timeout)
+    ctrl->id = g_timeout_add (200, cb_check, ctrl);
 
   /* find image from label string (optional) */
   if (g_object_class_find_property (G_OBJECT_GET_CLASS (track), "untranslated-label"))
@@ -430,8 +444,8 @@
   g_signal_connect (ctrl->toggle, "toggled",
 		    G_CALLBACK (cb_toggle_changed), ctrl);
   gtk_widget_show (ctrl->toggle);
-                                                                                
-  return ctrl;  
+
+  return ctrl;
 }
 
 GnomeVolumeControlTrack *

Modified: trunk/gst-mixer/src/track.h
==============================================================================
--- trunk/gst-mixer/src/track.h	(original)
+++ trunk/gst-mixer/src/track.h	Mon Jun  2 18:59:38 2008
@@ -101,6 +101,8 @@
 void	gnome_volume_control_track_show		(GnomeVolumeControlTrack *track,
 						 gboolean  visible);
 
+void    gnome_volume_control_track_update       (GnomeVolumeControlTrack *trkw);
+
 G_END_DECLS
 
 #endif /* __GVC_TRACK_H__ */

Modified: trunk/gst-mixer/src/volume.c
==============================================================================
--- trunk/gst-mixer/src/volume.c	(original)
+++ trunk/gst-mixer/src/volume.c	Mon Jun  2 18:59:38 2008
@@ -165,6 +165,10 @@
   gint *volumes, n;
   gchar *msg, *chan;
   GList *items;
+  gboolean need_timeout = TRUE;
+
+  need_timeout = ((gst_mixer_get_mixer_flags (GST_MIXER (mixer)) &
+		   GST_MIXER_FLAG_AUTO_NOTIFICATIONS) == 0);
 
   /* volume */
   vol = g_object_new (GNOME_VOLUME_CONTROL_TYPE_VOLUME, NULL);
@@ -230,7 +234,8 @@
   g_free (volumes);
 
   /* GStreamer signals */
-  vol->id = g_timeout_add (100, cb_check, vol);
+  if (need_timeout)
+    vol->id = g_timeout_add (100, cb_check, vol);
 
   return GTK_WIDGET (vol);
 }
@@ -496,21 +501,18 @@
   }
 }
 
-/*
- * Timeout to check for volume changes.
- */
 
-static gboolean
-cb_check (gpointer data)
+void
+gnome_volume_control_volume_update (GnomeVolumeControlVolume *vol)
 {
-  GnomeVolumeControlVolume *vol = data;
   gint *volumes, n;
   gboolean real_zero, slider_zero;
   GList *scales;
 
   /* don't do callbacks */
   if (vol->locked)
-    return TRUE;
+    return;
+
   vol->locked = TRUE;
 
   volumes = g_new (gint, vol->track->num_channels);
@@ -520,7 +522,7 @@
 					     GST_MIXER_TRACK_MUTE)) {
     g_free (volumes);
     vol->locked = FALSE;
-    return TRUE;
+    return;
   }
 
   /* did we change? */
@@ -535,12 +537,22 @@
     /* should we release lock? */
     if (volumes[n] != volumes[0]) {
       gnome_volume_control_button_set_active (
-          GNOME_VOLUME_CONTROL_BUTTON (vol->button), FALSE);
+	GNOME_VOLUME_CONTROL_BUTTON (vol->button), FALSE);
     }
   }
 
   g_free (volumes);
   vol->locked = FALSE;
+}
+
+/*
+ * Timeout to check for volume changes.
+ */
+
+static gboolean
+cb_check (gpointer data)
+{
+  gnome_volume_control_volume_update (data);
 
   return TRUE;
 }

Modified: trunk/gst-mixer/src/volume.h
==============================================================================
--- trunk/gst-mixer/src/volume.h	(original)
+++ trunk/gst-mixer/src/volume.h	Mon Jun  2 18:59:38 2008
@@ -76,6 +76,7 @@
 void		gnome_volume_control_volume_ask (GnomeVolumeControlVolume *volume,
 						 gboolean * real_zero,
 						 gboolean * slider_zero);
+void		gnome_volume_control_volume_update (GnomeVolumeControlVolume *volume);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]