changeset 2014:de75a5a81f28 libavformat

add support for seeking to a keyframe instead of a random frame
author aurel
date Mon, 09 Apr 2007 17:03:20 +0000
parents fc0b19650faa
children a698d9aa78f2
files matroska.c
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/matroska.c	Mon Apr 09 17:00:09 2007 +0000
+++ b/matroska.c	Mon Apr 09 17:03:20 2007 +0000
@@ -343,6 +343,10 @@
     /* The index for seeking. */
     int num_indexes;
     MatroskaDemuxIndex *index;
+
+    /* What to skip before effectively reading a packet. */
+    int skip_to_keyframe;
+    AVStream *skip_to_stream;
 } MatroskaDemuxContext;
 
 /*
@@ -2436,6 +2440,13 @@
     size -= 1;
     if (is_keyframe == -1)
         is_keyframe = flags & 1 ? PKT_FLAG_KEY : 0;
+
+    if (matroska->skip_to_keyframe) {
+        if (!is_keyframe || st != matroska->skip_to_stream)
+            return res;
+        matroska->skip_to_keyframe = 0;
+    }
+
     switch ((flags & 0x06) >> 1) {
         case 0x0: /* no lacing */
             laces = 1;
@@ -2782,6 +2793,8 @@
 
     /* do the seek */
     url_fseek(&s->pb, st->index_entries[index].pos, SEEK_SET);
+    matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY);
+    matroska->skip_to_stream = st;
     matroska->num_packets = 0;
     matroska->peek_id = 0;
     return 0;