[rygel/rygel-0-20] renderer: Fix seeking behavior when using REL_TIME



commit 5753d43f8be1324ea178b24c88973ee3a1777a50
Author: Milan Plzik <milan plzik gmail com>
Date:   Wed Sep 11 00:33:18 2013 +0200

    renderer: Fix seeking behavior when using REL_TIME
    
    Signed-off-by: Milan Plzik <milan plzik streamunlimited com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686628

 src/librygel-renderer/rygel-av-transport.vala |   16 ++++++++++++++-
 src/librygel-renderer/rygel-time-utils.vala   |   26 ++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/src/librygel-renderer/rygel-av-transport.vala b/src/librygel-renderer/rygel-av-transport.vala
index ccf93a9..ebd945e 100644
--- a/src/librygel-renderer/rygel-av-transport.vala
+++ b/src/librygel-renderer/rygel-av-transport.vala
@@ -592,7 +592,6 @@ internal class Rygel.AVTransport : Service {
                         out target);
         switch (unit) {
         case "ABS_TIME":
-        case "REL_TIME":
             debug ("Seeking to %s.", target);
 
             if (!this.player.seek (TimeUtils.time_from_string (target))) {
@@ -604,6 +603,21 @@ internal class Rygel.AVTransport : Service {
             action.return ();
 
             return;
+        case "REL_TIME":
+            debug ("Relative seek to %s.", target);
+
+            var seek_target = this.player.position +
+                              TimeUtils.time_from_string (target);
+
+            if (!this.player.seek (seek_target)) {
+                action.return_error (710, _("Seek mode not supported"));
+
+                return;
+            }
+
+            action.return ();
+
+            return;
         case "TRACK_NR":
             debug ("Setting track to %s.", target);
             var track = int.parse (target);
diff --git a/src/librygel-renderer/rygel-time-utils.vala b/src/librygel-renderer/rygel-time-utils.vala
index aeffc0f..b7865f3 100644
--- a/src/librygel-renderer/rygel-time-utils.vala
+++ b/src/librygel-renderer/rygel-time-utils.vala
@@ -26,20 +26,40 @@
 internal abstract class Rygel.TimeUtils {
     public static int64 time_from_string (string str) {
         uint64 hours, minutes, seconds;
+        string time_str = str;
+        int sign = 1;
 
-        str.scanf ("%llu:%2llu:%2llu%*s", out hours, out minutes, out seconds);
+        switch (str[0]) {
+            case '-':
+                sign = -1;
+                time_str = str.substring(1);
+                break;
+            case '+':
+                time_str = str.substring(1);
+                break;
+            default:
+                break;
+        }
 
-        return (int64)(hours * 3600 + minutes * 60 + seconds) * TimeSpan.SECOND;
+        time_str.scanf ("%llu:%2llu:%2llu%*s", out hours, out minutes, out seconds);
+
+        return sign*(int64)(hours * 3600 + minutes * 60 + seconds) * TimeSpan.SECOND;
     }
 
     public static string time_to_string (int64 time) {
         uint64 hours, minutes, seconds;
+        string sign = "";
+
+        if (time < 0) {
+            sign = "-";
+            time = - time;
+        };
 
         hours   = time / TimeSpan.SECOND / 3600;
         seconds = time / TimeSpan.SECOND % 3600;
         minutes = seconds / 60;
         seconds = seconds % 60;
 
-        return "%llu:%.2llu:%.2llu".printf (hours, minutes, seconds);
+        return "%s%llu:%.2llu:%.2llu".printf (sign, hours, minutes, seconds);
     }
 }


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