[rhythmbox] Use Cubic volume when StreamVolume interface is available



commit 58edf8249e83706e0166e98d05b609ea36c89080
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Oct 25 17:30:22 2009 +1000

    Use Cubic volume when StreamVolume interface is available
    
    Fixes Rhythmbox's sound not matching the volume levels advertised
    in pavucontrol and gnome-volume-control.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=598955

 backends/gstreamer/rb-player-gst-xfade.c |   35 +++++++++++++++++++++++++++++-
 backends/gstreamer/rb-player-gst.c       |   26 +++++++++++++++++++++-
 configure.ac                             |    2 +-
 3 files changed, 60 insertions(+), 3 deletions(-)
---
diff --git a/backends/gstreamer/rb-player-gst-xfade.c b/backends/gstreamer/rb-player-gst-xfade.c
index 101ba0c..0ad557d 100644
--- a/backends/gstreamer/rb-player-gst-xfade.c
+++ b/backends/gstreamer/rb-player-gst-xfade.c
@@ -158,6 +158,9 @@
 #include <gst/gst.h>
 #include <gst/controller/gstcontroller.h>
 #include <gst/base/gstbasetransform.h>
+#if GST_CHECK_VERSION(0,10,25)
+#include <gst/interfaces/streamvolume.h>
+#endif
 #include <gst/pbutils/pbutils.h>
 
 #include "rb-player.h"
@@ -2622,7 +2625,20 @@ tick_timeout (RBPlayerGstXFade *player)
 static gboolean
 emit_volume_changed_idle (RBPlayerGstXFade *player)
 {
-	_rb_player_emit_volume_changed (RB_PLAYER (player), player->priv->cur_volume);
+	double vol;
+
+#if GST_CHECK_VERSION(0,10,25)
+	if (gst_element_implements_interface (player->priv->volume_handler, GST_TYPE_STREAM_VOLUME)) {
+		vol = gst_stream_volume_get_volume (GST_STREAM_VOLUME (player->priv->volume_handler),
+						    GST_STREAM_VOLUME_FORMAT_CUBIC);
+	} else {
+		vol = player->priv->cur_volume;
+	}
+#else
+	vol = player->priv->cur_volume;
+#endif
+
+	_rb_player_emit_volume_changed (RB_PLAYER (player), vol);
 	return FALSE;
 }
 
@@ -3700,7 +3716,18 @@ rb_player_gst_xfade_set_volume (RBPlayer *iplayer, float volume)
 		gdouble v = (gdouble)volume;
 
 		/* maybe use a controller here for smoother changes? */
+#if GST_CHECK_VERSION(0,10,25)
+		if (gst_element_implements_interface (player->priv->volume_handler,
+						      GST_TYPE_STREAM_VOLUME)) {
+			rb_debug ("setting volume to %f using stream volume interface", v);
+			gst_stream_volume_set_volume (GST_STREAM_VOLUME (player->priv->volume_handler),
+						      GST_STREAM_VOLUME_FORMAT_CUBIC, v);
+		} else {
+			g_object_set (player->priv->volume_handler, "volume", v, NULL);
+		}
+#else
 		g_object_set (player->priv->volume_handler, "volume", v, NULL);
+#endif
 		player->priv->volume_applied = player->priv->volume_changed;
 	}
 	player->priv->cur_volume = volume;
@@ -3712,6 +3739,12 @@ rb_player_gst_xfade_get_volume (RBPlayer *iplayer)
 {
 	RBPlayerGstXFade *player = RB_PLAYER_GST_XFADE (iplayer);
 
+#if GST_CHECK_VERSION(0,10,25)
+	if (gst_element_implements_interface (player->priv->volume_handler, GST_TYPE_STREAM_VOLUME))
+		return gst_stream_volume_get_volume (GST_STREAM_VOLUME (player->priv->volume_handler),
+						     GST_STREAM_VOLUME_FORMAT_CUBIC);
+#endif
+
 	return player->priv->cur_volume;
 }
 
diff --git a/backends/gstreamer/rb-player-gst.c b/backends/gstreamer/rb-player-gst.c
index 21246a1..e3740ca 100644
--- a/backends/gstreamer/rb-player-gst.c
+++ b/backends/gstreamer/rb-player-gst.c
@@ -36,6 +36,9 @@
 #include <glib/gi18n.h>
 #include <gdk/gdk.h>
 #include <gst/tag/tag.h>
+#if GST_CHECK_VERSION(0,10,25)
+#include <gst/interfaces/streamvolume.h>
+#endif
 #include <gst/pbutils/pbutils.h>
 
 #include "rb-debug.h"
@@ -155,7 +158,20 @@ about_to_finish_cb (GstElement *playbin, RBPlayerGst *player)
 static gboolean
 emit_volume_changed_idle (RBPlayerGst *player)
 {
-	_rb_player_emit_volume_changed (RB_PLAYER (player), player->priv->cur_volume);
+	double vol;
+
+#if GST_CHECK_VERSION(0,10,25)
+	if (gst_element_implements_interface (player->priv->playbin, GST_TYPE_STREAM_VOLUME)) {
+		vol = gst_stream_volume_get_volume (GST_STREAM_VOLUME (player->priv->playbin),
+						    GST_STREAM_VOLUME_FORMAT_CUBIC);
+	} else {
+		vol = player->priv->cur_volume;
+	}
+#else
+	vol = player->priv->cur_volume;
+#endif
+
+	_rb_player_emit_volume_changed (RB_PLAYER (player), vol);
 	return FALSE;
 }
 
@@ -720,7 +736,15 @@ set_playbin_volume (RBPlayerGst *player, float volume)
 	 * we still get another one anyway.
 	 */
 	g_signal_handlers_block_by_func (player->priv->playbin, volume_notify_cb, player);
+#if GST_CHECK_VERSION(0,10,25)
+	if (gst_element_implements_interface (player->priv->playbin, GST_TYPE_STREAM_VOLUME))
+		gst_stream_volume_set_volume (GST_STREAM_VOLUME (player->priv->playbin),
+					      GST_STREAM_VOLUME_FORMAT_CUBIC, volume);
+	else
+		g_object_set (player->priv->playbin, "volume", volume, NULL);
+#else
 	g_object_set (player->priv->playbin, "volume", volume, NULL);
+#endif
 	g_signal_handlers_unblock_by_func (player->priv->playbin, volume_notify_cb, player);
 }
 
diff --git a/configure.ac b/configure.ac
index db6ed1f..54b5f88 100644
--- a/configure.ac
+++ b/configure.ac
@@ -247,7 +247,7 @@ PKG_CHECK_MODULES(GSTREAMER_0_10, \
 	gstreamer-plugins-base-0.10 >= $GST_0_10_REQS)
 
 RHYTHMBOX_CFLAGS="$RHYTHMBOX_CFLAGS $GSTREAMER_0_10_CFLAGS"
-RHYTHMBOX_LIBS="$RHYTHMBOX_LIBS $GSTREAMER_0_10_LIBS"
+RHYTHMBOX_LIBS="$RHYTHMBOX_LIBS $GSTREAMER_0_10_LIBS -lgstinterfaces-0.10"
 
 dnl DAAP (iTunes Music Shares)
 AC_ARG_ENABLE(daap,



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