oggdemux: Fix seeking before the first frame.
authorMathieu Duponchelle <mathieu.duponchelle@opencreed.com>
Thu, 27 Nov 2014 04:53:20 +0000 (05:53 +0100)
committerMathieu Duponchelle <mathieu.duponchelle@opencreed.com>
Fri, 5 Dec 2014 09:13:57 +0000 (10:13 +0100)
The previous code was setting keytarget to target
to make sure the keyframe found for each pad was
indeed before the target.

Then if target == keytarget, it assumed a keyframe had been
found, which was not the case if target was before the first frame
in the file.

This patch checks that a keyframe was indeed found, and if not
seeks to 0, without bisecting again.

Assuming default gst qa assets in $HOME/gst-validate

seek_before_first_frame.scenario:

description, seek=true, handles-states=true
pause, playback-time=0.0
seek, playback-time=0.0, start=0.0, flags=accurate+flush
seek, playback-time=0.0, start=0.01, flags=accurate+flush
seek, playback-time=0.0, start=0.1, flags=accurate+flush

GST_DEBUG=*theoradec*:2 gst-validate-1.0 playbin \
uri=file://$HOME/gst-validate/gst-qa-assets/medias/ogg/vorbis_theora.0.ogg \
--set-scenario seek_before_first_frame.scenario

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

ext/ogg/gstoggdemux.c

index 2a98e20..b6b7f70 100644 (file)
@@ -2984,6 +2984,7 @@ gst_ogg_demux_do_seek (GstOggDemux * ogg, GstSegment * segment,
   GstFlowReturn ret;
   gint i, pending;
   gint serialno = 0;
+  gboolean found_keyframe = FALSE;
 
   position = segment->position;
 
@@ -3114,6 +3115,7 @@ gst_ogg_demux_do_seek (GstOggDemux * ogg, GstSegment * segment,
       if (keyframe_time < keytarget) {
         serialno = pad->map.serialno;
         keytarget = keyframe_time;
+        found_keyframe = TRUE;
       }
     }
 
@@ -3127,6 +3129,10 @@ gst_ogg_demux_do_seek (GstOggDemux * ogg, GstSegment * segment,
   if (segment->rate < 0.0)
     goto done;
 
+  /* No keyframe found, no need to bisect again, keytarget == target here */
+  if (!found_keyframe)
+    best = 0;
+
   if (keytarget != target) {
     GST_LOG_OBJECT (ogg, "final seek to target %" GST_TIME_FORMAT,
         GST_TIME_ARGS (keytarget));