[Xfce4-commits] <parole:master> Better pulseaudio support Set the media-role to "video" and sync volume-changes through pulseaudio to parole's volume control

Simon Steinbeiss noreply at xfce.org
Fri Mar 29 11:14:01 CET 2013


Updating branch refs/heads/master
         to 27625e3d4fb76e1245b651db777489af367b73bd (commit)
       from 06c1f7387116d3d34a5e1f9519396f72e92bdc33 (commit)

commit 27625e3d4fb76e1245b651db777489af367b73bd
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Fri Mar 29 11:12:19 2013 +0100

    Better pulseaudio support
    Set the media-role to "video" and sync volume-changes through pulseaudio to parole's volume control

 src/gst/parole-gst.c |   59 ++++++++++++++++++++++++++++++++++++++++++-------
 src/parole-player.c  |   13 +++++++++++
 2 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/src/gst/parole-gst.c b/src/gst/parole-gst.c
index 9b415ec..a28cb24 100644
--- a/src/gst/parole-gst.c
+++ b/src/gst/parole-gst.c
@@ -130,6 +130,8 @@ struct ParoleGstPrivate
     gboolean      buffering;
     gboolean      update_color_balance;
     
+    gdouble	  volume;
+    
     gboolean      use_custom_subtitles;
     gchar*        custom_subtitles;
     
@@ -162,6 +164,7 @@ enum
 enum
 {
     PROP_0,
+    PROP_VOLUME,
     PROP_CONF_OBJ,
     PROP_ENABLE_TAGS
 };
@@ -2116,6 +2119,9 @@ static void parole_gst_get_property (GObject *object,
     
     switch (prop_id)
     {
+	case PROP_VOLUME:
+	    g_value_set_double (value, gst->priv->volume);
+	    break;
 	case PROP_CONF_OBJ:
 	    g_value_set_pointer (value, gst->priv->conf);
 	    break;
@@ -2142,6 +2148,9 @@ static void parole_gst_set_property (GObject *object,
 	case PROP_ENABLE_TAGS:
 	    gst->priv->enable_tags = g_value_get_boolean (value);
 	    break;
+	case PROP_VOLUME:
+	    parole_gst_set_volume (gst, g_value_get_double (value));
+	    break;
 	case PROP_CONF_OBJ:
 	    gst->priv->conf = g_value_get_pointer (value);
 	    
@@ -2161,6 +2170,29 @@ static void parole_gst_set_property (GObject *object,
     }
 }
 
+
+static gboolean
+parole_notify_volume_idle_cb (ParoleGst *gst)
+{
+    gdouble vol;
+
+    vol = gst_stream_volume_get_volume (GST_STREAM_VOLUME (gst->priv->playbin),
+                                      GST_STREAM_VOLUME_FORMAT_CUBIC);
+
+    gst->priv->volume = vol;
+    g_object_notify (G_OBJECT (gst), "volume");
+
+    return FALSE;
+}
+
+static void
+parole_notify_volume_cb (GObject             *object,
+		  GParamSpec          *pspec,
+		  ParoleGst *gst)
+{
+    g_idle_add ((GSourceFunc) parole_notify_volume_idle_cb, gst);
+}
+
 static void
 parole_gst_constructed (GObject *object)
 {
@@ -2245,6 +2277,9 @@ parole_gst_constructed (GObject *object)
 
     g_signal_connect (gst->priv->playbin, "notify::source",
 		      G_CALLBACK (parole_gst_source_notify_cb), gst);
+    
+    g_signal_connect (gst->priv->playbin, "notify::volume",
+		      G_CALLBACK (parole_notify_volume_cb), gst);
 
 
     g_signal_connect (gst->priv->playbin, "about-to-finish",
@@ -2369,6 +2404,13 @@ parole_gst_class_init (ParoleGstClass *klass)
 							   G_PARAM_READWRITE));
     
     g_object_class_install_property (object_class,
+				     PROP_VOLUME,
+				     g_param_spec_double ("volume", NULL, NULL,
+							   0.0, 1.0, 0.0,
+	                                                   G_PARAM_READWRITE |
+                                                           G_PARAM_STATIC_STRINGS));
+    
+    g_object_class_install_property (object_class,
 				     PROP_ENABLE_TAGS,
 				     g_param_spec_boolean ("tags",
 							   NULL, NULL,
@@ -2403,7 +2445,7 @@ parole_gst_init (ParoleGst *gst)
     gst->priv->scale_logo = TRUE;
     gst->priv->use_custom_subtitles = FALSE;
     gst->priv->custom_subtitles = NULL;
-    
+    gst->priv->volume = -1.0;
     gst->priv->conf = NULL;
     
     GTK_WIDGET_SET_FLAGS (GTK_WIDGET (gst), GTK_CAN_FOCUS);
@@ -2624,21 +2666,20 @@ void parole_gst_seek (ParoleGst *gst, gdouble seek)
 				       GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE));
 }
 
-void parole_gst_set_volume (ParoleGst *gst, gdouble value)
+void parole_gst_set_volume (ParoleGst *gst, gdouble volume)
 {
     gst_stream_volume_set_volume (GST_STREAM_VOLUME (gst->priv->playbin),
 				    GST_STREAM_VOLUME_FORMAT_CUBIC,
-				    value);
+				    volume);
+    volume = CLAMP (volume, 0.0, 1.0);
+    gst->priv->volume = volume;
+    
+    g_object_notify (G_OBJECT (gst), "volume");
 }
 						    
 gdouble	parole_gst_get_volume (ParoleGst *gst)
 {
-    gdouble volume;
-    
-    g_object_get (G_OBJECT (gst->priv->playbin),
-		  "volume", &volume,
-		  NULL);
-    return volume;
+    return gst->priv->volume;
 }
 
 ParoleState parole_gst_get_state (ParoleGst *gst)
diff --git a/src/parole-player.c b/src/parole-player.c
index a4bbd3f..e6f436e 100644
--- a/src/parole-player.c
+++ b/src/parole-player.c
@@ -2203,6 +2203,14 @@ void parole_player_repeat_toggled_cb (GtkWidget *widget, ParolePlayer *player)
 }
 
 static void
+parole_property_notify_cb_volume (ParoleGst *gst, GParamSpec *spec, ParolePlayer *player)
+{
+	gdouble volume;
+	volume = parole_gst_get_volume (PAROLE_GST (player->priv->gst));
+	gtk_scale_button_set_value (GTK_SCALE_BUTTON (player->priv->volume), volume);
+}
+
+static void
 parole_player_change_volume (ParolePlayer *player, gdouble value)
 {
     parole_gst_set_volume (PAROLE_GST (player->priv->gst), value);
@@ -2821,6 +2829,8 @@ parole_player_init (ParolePlayer *player)
     
     GtkWidget *content_area;
     
+    g_setenv("PULSE_PROP_media.role", "video", TRUE);
+    
     player->priv = PAROLE_PLAYER_GET_PRIVATE (player);
 
     player->priv->client_id = NULL;
@@ -2895,6 +2905,9 @@ parole_player_init (ParolePlayer *player)
     
     g_signal_connect (G_OBJECT (player->priv->gst), "motion-notify-event",
 		      G_CALLBACK (parole_player_gst_widget_motion_notify_event), player);
+    
+    g_signal_connect (G_OBJECT (player->priv->gst), "notify::volume",
+			G_CALLBACK (parole_property_notify_cb_volume), player);
 
     output = GTK_WIDGET (gtk_builder_get_object (builder, "output"));
     


More information about the Xfce4-commits mailing list