oggdemux: do reverse seeks more accurate
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 12 Jun 2009 11:22:47 +0000 (13:22 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 12 Jun 2009 11:44:26 +0000 (13:44 +0200)
For reverse seeking with the accurate flag set, try to be more precise by
seeking a little bit after the requested position.

ext/ogg/gstoggdemux.c

index 933cb9b..73d6f6d 100644 (file)
@@ -1868,9 +1868,10 @@ gst_ogg_demux_activate_chain (GstOggDemux * ogg, GstOggChain * chain,
  * do seek to time @position, return FALSE or chain and TRUE
  */
 static gboolean
-gst_ogg_demux_do_seek (GstOggDemux * ogg, gint64 position, gboolean accurate,
-    GstOggChain ** rchain)
+gst_ogg_demux_do_seek (GstOggDemux * ogg, GstSegment * segment,
+    gboolean accurate, GstOggChain ** rchain)
 {
+  guint64 position;
   GstOggChain *chain = NULL;
   gint64 begin, end;
   gint64 begintime, endtime;
@@ -1881,6 +1882,8 @@ gst_ogg_demux_do_seek (GstOggDemux * ogg, gint64 position, gboolean accurate,
   GstFlowReturn ret;
   gint i;
 
+  position = segment->last_stop;
+
   /* first find the chain to search in */
   total = ogg->total_time;
   if (ogg->chains->len == 0)
@@ -1896,14 +1899,23 @@ gst_ogg_demux_do_seek (GstOggDemux * ogg, gint64 position, gboolean accurate,
   begin = chain->offset;
   end = chain->end_offset;
   begintime = chain->begin_time;
-  endtime = chain->begin_time + chain->total_time;
+  endtime = begintime + chain->total_time;
   target = position - total + begintime;
   if (accurate) {
-    /* FIXME, seek 4 seconds early to catch keyframes, better implement
-     * keyframe detection. */
-    target = target - (gint64) 4 *GST_SECOND;
+    if (segment->rate > 0.0) {
+      /* FIXME, seek 2 seconds early to catch keyframes, better implement
+       * keyframe detection. */
+      if (target - 2 * GST_SECOND > begintime)
+        target = target - (gint64) 2 *GST_SECOND;
+      else
+        target = begintime;
+    } else {
+      if (target + GST_SECOND < endtime)
+        target = target + (gint64) GST_SECOND;
+      else
+        target = endtime;
+    }
   }
-  target = MAX (target, 0);
   best = begin;
 
   GST_DEBUG_OBJECT (ogg,
@@ -2175,10 +2187,7 @@ gst_ogg_demux_perform_seek (GstOggDemux * ogg, GstEvent * event)
   }
 
   /* for reverse we will already seek accurately */
-  if (rate < 0.0)
-    accurate = FALSE;
-
-  res = gst_ogg_demux_do_seek (ogg, ogg->segment.last_stop, accurate, &chain);
+  res = gst_ogg_demux_do_seek (ogg, &ogg->segment, accurate, &chain);
 
   /* seek failed, make sure we continue the current chain */
   if (!res) {