oggstream: when the last keyframe position is not known, do not use -1
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Wed, 29 Dec 2010 15:27:44 +0000 (15:27 +0000)
committerDavid Schleef <ds@schleef.org>
Thu, 6 Jan 2011 20:34:32 +0000 (12:34 -0800)
Instead, use either 0 or 1, depending on bitstream version, which give
the correct result for streams which aren't cut off at start.
This allows that function to not return negative granpos.

https://bugzilla.gnome.org/show_bug.cgi?id=638276

ext/ogg/gstoggstream.c

index 572f9ca..caa9865 100644 (file)
@@ -255,6 +255,11 @@ granule_to_granulepos_default (GstOggStream * pad, gint64 granule,
   gint64 keyoffset;
 
   if (pad->granuleshift != 0) {
+    /* If we don't know where the previous keyframe is yet, assume it is
+       at 0 or 1, depending on bitstream version. If nothing else, this
+       avoids getting negative granpos back. */
+    if (keyframe_granule < 0)
+      keyframe_granule = pad->theora_has_zero_keyoffset ? 0 : 1;
     keyoffset = granule - keyframe_granule;
     return (keyframe_granule << pad->granuleshift) | keyoffset;
   } else {