[banshee/stable-1.6] [GStreamer] Don't track volume in preferences



commit d0b1e1599581d80c7a044fadf3cb50b7eac33883
Author: Aaron Bockover <abockover novell com>
Date:   Fri May 14 15:11:59 2010 -0400

    [GStreamer] Don't track volume in preferences
    
    Added a new bp_supports_stream_volume API that returns whether or not
    the playbin element supports GST_TYPE_STREAM_VOLUME. If stream volumes
    are supported on the pipeline (which, for example, map to the system
    mixer), then don't load/save the volume from Banshee's preferences and
    instead only load/set volume on the pipeline itself so the application
    volume state is always in sync with the pipeline.
    
    This *should* fix bgo#613725, bgo#612362, and bgo#613726, though there
    may be some sort of inconsistency on some distributions as this fix will
    only apply for GStreamer 0.10.25 or newer (when the
    GST_TYPE_STREAM_VOLUME interface was introduced). If the case is that
    stream volume was supported internally on playbin2 before 0.10.25 adds
    this interface, there's no real way for us to know whether to trust the
    pipeline (system/mixer) volume or our internal software volume state.

 libbanshee/banshee-player-pipeline.c               |    9 ++++
 libbanshee/banshee-player-private.h                |    4 ++
 libbanshee/banshee-player.c                        |   48 +++++++++++--------
 .../Banshee.GStreamer/PlayerEngine.cs              |   27 ++++++++++-
 .../Banshee.Gui.Widgets/ConnectedVolumeButton.cs   |    4 +-
 5 files changed, 66 insertions(+), 26 deletions(-)
---
diff --git a/libbanshee/banshee-player-pipeline.c b/libbanshee/banshee-player-pipeline.c
index 90b968d..d655df3 100644
--- a/libbanshee/banshee-player-pipeline.c
+++ b/libbanshee/banshee-player-pipeline.c
@@ -267,6 +267,15 @@ _bp_pipeline_construct (BansheePlayer *player)
     // source and decoder elements) based on source URI and stream content
     player->playbin = gst_element_factory_make ("playbin2", "playbin");
 
+    player->supports_stream_volume = FALSE;
+#if BANSHEE_CHECK_GST_VERSION(0,10,25)
+    player->supports_stream_volume = gst_element_implements_interface (
+        player->playbin, GST_TYPE_STREAM_VOLUME);
+#endif
+
+    bp_debug ("Stream volume supported: %s",
+        player->supports_stream_volume ? "YES" : "NO");
+
 #ifdef ENABLE_GAPLESS
     // Connect a proxy about-to-finish callback that will generate a next-track-starting callback.
     // This can be removed once playbin2 generates its own next-track signal.
diff --git a/libbanshee/banshee-player-private.h b/libbanshee/banshee-player-private.h
index 1b69d6f..3006201 100644
--- a/libbanshee/banshee-player-private.h
+++ b/libbanshee/banshee-player-private.h
@@ -64,6 +64,9 @@
         (GST_VERSION_MAJOR == (major) && GST_VERSION_MINOR == (minor) && \
             GST_VERSION_MICRO >= (micro)))
 
+#if BANSHEE_CHECK_GST_VERSION(0,10,25)
+#include <gst/interfaces/streamvolume.h>
+#endif
 
 #ifdef WIN32
 // TODO Windows doesn't like the ... varargs
@@ -132,6 +135,7 @@ struct BansheePlayer {
     gboolean buffering;
     gchar *cdda_device;
     gboolean in_gapless_transition;
+    gboolean supports_stream_volume;
     
     // Video State
     BpVideoDisplayContextType video_display_context_type;
diff --git a/libbanshee/banshee-player.c b/libbanshee/banshee-player.c
index cc22981..218aa76 100644
--- a/libbanshee/banshee-player.c
+++ b/libbanshee/banshee-player.c
@@ -31,9 +31,6 @@
 #include "banshee-player-cdda.h"
 #include "banshee-player-missing-elements.h"
 #include "banshee-player-replaygain.h"
-#if BANSHEE_CHECK_GST_VERSION(0,10,25)
-#include <gst/interfaces/streamvolume.h>
-#endif
 
 // ---------------------------------------------------------------------------
 // Private Functions
@@ -296,37 +293,48 @@ bp_supports_gapless (BansheePlayer *player)
 #endif //ENABLE_GAPLESS
 }
 
+P_INVOKE gboolean
+bp_supports_stream_volume (BansheePlayer *player)
+{
+    g_return_val_if_fail (IS_BANSHEE_PLAYER (player), FALSE);
+    return player->supports_stream_volume;
+}
+
 P_INVOKE void
 bp_set_volume (BansheePlayer *player, gdouble volume)
 {
     g_return_if_fail (IS_BANSHEE_PLAYER (player));
     g_return_if_fail (GST_IS_ELEMENT (player->playbin));
 
-#if BANSHEE_CHECK_GST_VERSION(0,10,25)
-    if (gst_element_implements_interface (player->playbin, GST_TYPE_STREAM_VOLUME))
-      gst_stream_volume_set_volume (GST_STREAM_VOLUME (player->playbin), GST_STREAM_VOLUME_FORMAT_CUBIC, volume);
-    else
-      g_object_set (player->playbin, "volume", CLAMP (volume, 0.0, 1.0), NULL);
-#else
-    g_object_set (player->playbin, "volume", CLAMP (volume, 0.0, 1.0), NULL);
-#endif
+    if (bp_supports_stream_volume (player)) {
+        #if BANSHEE_CHECK_GST_VERSION(0,10,25)
+        gst_stream_volume_set_volume (GST_STREAM_VOLUME (player->playbin),
+            GST_STREAM_VOLUME_FORMAT_CUBIC, volume);
+        #endif
+    } else {
+        g_object_set (player->playbin, "volume", CLAMP (volume, 0.0, 1.0), NULL);
+    }
+
     _bp_rgvolume_print_volume (player);
 }
 
 P_INVOKE gdouble
 bp_get_volume (BansheePlayer *player)
 {
+    gdouble volume;
+
     g_return_val_if_fail (IS_BANSHEE_PLAYER (player), 0.0);
     g_return_val_if_fail (GST_IS_ELEMENT (player->playbin), 0.0);
-    gdouble volume;
-#if BANSHEE_CHECK_GST_VERSION(0,10,25)
-    if (gst_element_implements_interface (player->playbin, GST_TYPE_STREAM_VOLUME))
-      volume = gst_stream_volume_get_volume (GST_STREAM_VOLUME (player->playbin), GST_STREAM_VOLUME_FORMAT_CUBIC);
-    else
-      g_object_get (player->playbin, "volume", &volume, NULL);
-#else
-    g_object_get (player->playbin, "volume", &volume, NULL);
-#endif
+
+    if (bp_supports_stream_volume (player)) {
+        #if BANSHEE_CHECK_GST_VERSION(0,10,25)
+        volume = gst_stream_volume_get_volume (GST_STREAM_VOLUME (player->playbin),
+            GST_STREAM_VOLUME_FORMAT_CUBIC);
+        #endif
+    } else {
+        g_object_get (player->playbin, "volume", &volume, NULL);
+    }
+
     return volume;
 }
 
diff --git a/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs b/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
index f17812d..7929f2a 100644
--- a/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
+++ b/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
@@ -78,6 +78,7 @@ namespace Banshee.GStreamer
         private uint GST_STREAM_ERROR = 0;
 
         private HandleRef handle;
+        private bool is_initialized;
 
         private BansheePlayerEosCallback eos_callback;
         private BansheePlayerErrorCallback error_callback;
@@ -182,11 +183,15 @@ namespace Banshee.GStreamer
 
             OnStateChanged (PlayerState.Ready);
 
-            Volume = (ushort)PlayerEngineService.VolumeSchema.Get ();
-
             InstallPreferences ();
             ReplayGainEnabled = ReplayGainEnabledSchema.Get ();
             GaplessEnabled = GaplessEnabledSchema.Get ();
+
+            is_initialized = true;
+
+            if (!bp_supports_stream_volume (handle)) {
+                Volume = (ushort)PlayerEngineService.VolumeSchema.Get ();
+            }
         }
 
         public override void Dispose ()
@@ -195,6 +200,7 @@ namespace Banshee.GStreamer
             base.Dispose ();
             bp_destroy (handle);
             handle = new HandleRef (this, IntPtr.Zero);
+            is_initialized = false;
         }
 
         public override void Close (bool fullShutdown)
@@ -517,9 +523,21 @@ namespace Banshee.GStreamer
         }
 
         public override ushort Volume {
-            get { return (ushort)Math.Round (bp_get_volume (handle) * 100.0); }
+            get {
+                return is_initialized
+                    ? (ushort)Math.Round (bp_get_volume (handle) * 100.0)
+                    : (ushort)0;
+            }
             set {
+                if (!is_initialized) {
+                    return;
+                }
+
                 bp_set_volume (handle, value / 100.0);
+                if (!bp_supports_stream_volume (handle)) {
+                    PlayerEngineService.VolumeSchema.Set ((int)value);
+                }
+
                 OnEventChanged (PlayerEvent.Volume);
             }
         }
@@ -837,6 +855,9 @@ namespace Banshee.GStreamer
         private static extern bool bp_can_seek (HandleRef player);
 
         [DllImport ("libbanshee.dll")]
+        private static extern bool bp_supports_stream_volume (HandleRef player);
+
+        [DllImport ("libbanshee.dll")]
         private static extern bool bp_set_position (HandleRef player, ulong time_ms);
 
         [DllImport ("libbanshee.dll")]
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/ConnectedVolumeButton.cs b/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/ConnectedVolumeButton.cs
index f654244..0671ee3 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/ConnectedVolumeButton.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/ConnectedVolumeButton.cs
@@ -40,7 +40,7 @@ namespace Banshee.Gui.Widgets
         public ConnectedVolumeButton () : base()
         {
             emit_lock = true;
-            Volume = PlayerEngineService.VolumeSchema.Get ();
+            Volume = ServiceManager.PlayerEngine.Volume;
             emit_lock = false;
             ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.Volume);
         }
@@ -59,8 +59,6 @@ namespace Banshee.Gui.Widgets
 
         protected override void OnVolumeChanged ()
         {
-            PlayerEngineService.VolumeSchema.Set (Volume);
-
             if (emit_lock) {
                 return;
             }



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