[rygel] renderer-gst: Use duration from meta-data



commit 850ade94c4bca4c465ecacee1fff83b474641cd0
Author: Jens Georg <mail jensge org>
Date:   Sat Jun 14 14:41:29 2014 +0200

    renderer-gst: Use duration from meta-data
    
    Until we get the proper duration from the pipeline, use the one supplied in
    the meta-data if available.
    
    Signed-off-by: Jens Georg <mail jensge org>

 .../rygel-playbin-player.vala                      |   26 +++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/src/librygel-renderer-gst/rygel-playbin-player.vala 
b/src/librygel-renderer-gst/rygel-playbin-player.vala
index 875d00e..bc4a6c2 100644
--- a/src/librygel-renderer-gst/rygel-playbin-player.vala
+++ b/src/librygel-renderer-gst/rygel-playbin-player.vala
@@ -193,6 +193,7 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
             this.playbin.set_state (State.READY);
             this.playbin.uri = value;
             if (value != "") {
+                this.guess_duration ();
                 switch (this._playback_state) {
                     case "NO_MEDIA_PRESENT":
                         this._playback_state = "STOPPED";
@@ -236,6 +237,7 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
         }
 
         set {
+            this._parsed_duration = 0;
             this._metadata = value;
         }
     }
@@ -295,6 +297,7 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
         }
     }
 
+    private int64 _parsed_duration;
     public int64 duration {
         get {
             int64 dur = 0;
@@ -302,7 +305,7 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
             if (this.playbin.query_duration (Format.TIME, out dur)) {
                 return dur / Gst.USECOND;
             } else {
-                return 0;
+                return _parsed_duration;
             }
         }
     }
@@ -642,4 +645,25 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
         bus.add_signal_watch ();
         bus.message.connect (this.bus_handler);
     }
+
+    private void guess_duration () {
+        var reader = new DIDLLiteParser ();
+
+        // Try to guess duration from meta-data.
+        reader.object_available.connect ( (object) => {
+            var resources = object.get_resources ();
+            foreach (var resource in resources) {
+                if (this._uri == resource.uri && resource.duration > 0) {
+                    this._parsed_duration = resource.duration * TimeSpan.SECOND;
+                    this.notify_property ("duration");
+                }
+            }
+        });
+
+        try {
+            reader.parse_didl (this._metadata);
+        } catch (Error error) {
+            debug ("Failed to parse meta-data: %s", error.message);
+        }
+    }
 }


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