[banshee] [GStreamer] Don't track volume in preferences



commit 9fbf2085d8a867906e8e7615aed01096f2be6b51
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 1d877c4..c95208f 100644
--- a/libbanshee/banshee-player-pipeline.c
+++ b/libbanshee/banshee-player-pipeline.c
@@ -292,6 +292,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 66ee2a7..cca6b63 100644
--- a/libbanshee/banshee-player-private.h
+++ b/libbanshee/banshee-player-private.h
@@ -69,6 +69,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
 #define bp_debug(x) banshee_log_debug ("player", x)
@@ -145,6 +148,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 4b3ade5..406bf94 100644
--- a/libbanshee/banshee-player.c
+++ b/libbanshee/banshee-player.c
@@ -33,9 +33,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
@@ -256,37 +253,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;
+    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);
-#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 0ae25b3..a2a428c 100644
--- a/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
+++ b/src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs
@@ -88,6 +88,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;
@@ -188,11 +189,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 ()
@@ -201,6 +206,7 @@ namespace Banshee.GStreamer
             base.Dispose ();
             bp_destroy (handle);
             handle = new HandleRef (this, IntPtr.Zero);
+            is_initialized = false;
         }
 
         public override void Close (bool fullShutdown)
@@ -546,9 +552,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);
             }
         }
@@ -862,6 +880,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]