Cortado patch to optionally zero basetime

"Benjamin M. Schwartz" <[email protected]> Wed, 07 Jul 2010 23:13:55 -0400
Newsgroups gmane.comp.multimedia.ogg.theora.devel
Message-ID <[email protected]>
This patch adds an applet option to Cortado.  The option is off by
default, meaning that the default behavior of Cortado should not change at
all.  If the option is activated, Cortado will display all times relative
to the ogg file's basetime (i.e. first granule).

This patch was written in response to a request from SeƱor Ellery, who
noted that files ripped from the middle of a stream do not start from time
zero when played in Cortado.

I believe that this functionality is best left as an option because some
users, for example in live streams, may prefer the existing functionality,
where the displayed time is the time since the start of recording, rather
than the start of the current player's playback.

The patch is slightly tested, and appears to work.

--Ben

_______________________________________________
theora-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/theora-dev
0001-Add-a-new-option-ignoreBasetime-so-that-users-can-fo.patch (text/x-patch, 4.9 KB)
From 128a22b6c12e33613b7c2b1c60da6fca0b8d32af Mon Sep 17 00:00:00 2001
From: Benjamin M. Schwartz <[email protected]>
Date: Wed, 7 Jul 2010 23:04:49 -0400
Subject: [PATCH] Add a new option, ignoreBasetime, so that users can force the initial time to be 0:00:00 even if the stream starts at a high granulepos.

---
 README                              |    7 +++++++
 src/com/fluendo/player/Cortado.java |    5 +++++
 src/com/fluendo/player/Status.java  |   22 +++++++++++++++++-----
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/README b/README
index 328527b..1121311 100644
--- a/README
+++ b/README
@@ -151,6 +151,13 @@ parameters:
               square pixels. true or false.
               Defaults to false
 
+  ignoreBasetime: boolean
+              Ignore the ogg file's basetime (initial granule or granpos) when
+              displaying times in the seek bar.  Instead, for display purposes,
+              always treat the first sample as occurring at time zero.
+              true or false.
+              Defaults to false
+
   video:      boolean
               Use video. When not using video, this property will not create
               resources to play a video stream. true or false.
diff --git a/src/com/fluendo/player/Cortado.java b/src/com/fluendo/player/Cortado.java
index bbf4198..13bac2b 100644
--- a/src/com/fluendo/player/Cortado.java
+++ b/src/com/fluendo/player/Cortado.java
@@ -41,6 +41,7 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
     private boolean showSubtitles;
     private boolean keepAspect;
     private boolean ignoreAspect;
+    private boolean ignoreBasetime;
     private boolean autoPlay;
     private int bufferSize;
     private String userId;
@@ -123,6 +124,8 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
                 "Use aspect ratio of video (default true)"},
             {"ignoreAspect", "boolean",
                 "Ignore the aspect ratio as signalled by the video, always assume square pixels (default false)"},
+            {"ignoreBasetime", "boolean", "Ignore the ogg file's basetime, and instead always display time as " + 
+                "starting at zero (default false)"},
             {"bufferSize", "int",
                 "The size of the prebuffer in Kbytes (default 100)"},
             {"bufferLow", "int", "Percent of empty buffer (default 10)"},
@@ -250,6 +253,7 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
         showSubtitles = getBoolParam("showSubtitles", true);
         keepAspect = getBoolParam("keepAspect", true);
         ignoreAspect = getBoolParam("ignoreAspect", false);
+        ignoreBasetime = getBoolParam("ignoreBasetime", false);
         bufferSize = getIntParam("bufferSize", 200);
         bufferLow = getIntParam("bufferLow", 10);
         bufferHigh = getIntParam("bufferHigh", 70);
@@ -303,6 +307,7 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
         status.setShowSpeaker(showSpeaker);
         status.setShowSubtitles(showSubtitles);
         status.setHaveAudio(audio);
+        status.setIgnoreBasetime(ignoreBasetime);
         status.setHaveSubtitles(false); // by default
         status.setHavePercent(true);
         /* assume live stream unless specified */
diff --git a/src/com/fluendo/player/Status.java b/src/com/fluendo/player/Status.java
index 3f0c3f8..d086fe9 100644
--- a/src/com/fluendo/player/Status.java
+++ b/src/com/fluendo/player/Status.java
@@ -48,6 +48,7 @@ public class Status extends Component implements MouseListener,
     private boolean showSpeaker;
     private boolean showSubtitles;
     private boolean clearedScreen;
+    private boolean ignoreBasetime = false;
 
     private static final int NONE = -1;
     private static final int BUTTON1 = 0;
@@ -268,14 +269,21 @@ public class Status extends Component implements MouseListener,
     }
 
     private void paintTime(Graphics g) {
-        long hour, min, sec;
+        long t=time, hour, min, sec;
         int end;
-
-        if (time < 0)
+        // time is an integer, but startTime is a double.  Subtracting them
+        // will leave some remainder (less than one second) uncorrected. I see
+        // no way to resolve that without changing time to be a double as well.
+        // The remainder means that although the initial time will be 0, it may
+        // change to 1 in less than a second.
+        if (ignoreBasetime)
+            t -= (long)startTime;
+
+        if (t < 0)
             return;
 
-        sec = time % 60;
-        min = time / 60;
+        sec = t % 60;
+        min = t / 60;
         hour = min / 60;
         min %= 60;
 
@@ -423,6 +431,10 @@ public class Status extends Component implements MouseListener,
         }
     }
 
+    public void setIgnoreBasetime(boolean ignore) {
+        ignoreBasetime = ignore;
+    }
+
     public void setStartTime(double seconds) {
         startTime = seconds >= 0 ? seconds : 0;
         component.repaint();
-- 
1.7.0.4
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkw1QnQACgkQUJT6e6HFtqQ35wCeO2Hg/XuUS0KajyXPLlYZSZ2x
+GkAnjipZ8IZevIRx4rCakINQC5aKwpf
=N/4e
-----END PGP SIGNATURE-----