[FFmpeg-devel] Seeking to out-of-bounds timestamps

Wolfram Gloger wmglo
Mon Jun 22 17:05:02 CEST 2009


> Does everyone agree with this?
> 
> av_gen_search() does _not_ implement these restrictions
> currently.

Since nobody disagreed so far, here is a patch implementing
this for av_gen_search().  Seek regression data will change
of course, but I have a followup patch for nutdec.c (also
appended) which is IMHO needed also -- if that is accepted
I will send the patch for seek.regression.ref.

Another strong argument for accepting this patch should be
the fact that av_index_search_timestamp() already implements
the "out-of-bounds timestamp -> return -1" semantics.

Regards,
Wolfram.

Patch for av_gen_search():

diff -ur trunk/libavformat/utils.c ffmpeg-seek/libavformat/utils.c
--- trunk/libavformat/utils.c	2009-06-20 17:53:57.000000000 +0200
+++ ffmpeg-seek/libavformat/utils.c	2009-06-22 16:52:05.000000000 +0200
@@ -1426,8 +1426,17 @@
         }
     }
 
-    pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;
-    ts  = (flags & AVSEEK_FLAG_BACKWARD) ?  ts_min :  ts_max;
+    if (flags & AVSEEK_FLAG_BACKWARD) {
+        if (target_ts < ts_min)
+            return -1;
+        pos = pos_min;
+        ts  =  ts_min;
+    } else {
+        if (target_ts > ts_max)
+            return -1;
+        pos = pos_max;
+        ts  =  ts_max;
+    }
 #ifdef DEBUG_SEEK
     pos_min = pos;
     ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);

Patch for nut seeking to avoid an assertion failure:

diff -ur trunk/libavformat/nutdec.c ffmpeg-seek/libavformat/nutdec.c
--- trunk/libavformat/nutdec.c	2009-06-20 17:53:57.000000000 +0200
+++ ffmpeg-seek/libavformat/nutdec.c	2009-06-22 16:53:42.000000000 +0200
@@ -875,6 +875,8 @@
                 pos= pos2;
             //FIXME dir but I think it does not matter
         }
+        if (pos < 0)
+            return -1;
         dummy.pos= pos;
         sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL);
 



More information about the ffmpeg-devel mailing list