[FFmpeg-cvslog] flvdec: Allow parsing keyframes metadata without seeking in most cases

Martin Storsjö git at videolan.org
Wed Apr 13 02:57:45 CEST 2011


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Tue Apr 12 16:37:54 2011 +0300| [578d6861a753eb0b9d277f7ec17d1502eb2bb35a] | committer: Martin Storsjö

flvdec: Allow parsing keyframes metadata without seeking in most cases

Stop the avio input at a point where amf_parse_object can
continue parsing the end of the object seamlessly, when all
data is available.

If unsupported data is encountered within the keyframes object,
try seeking to the start of the keyframes object - if the seek
back was successful, the caller can continue parsing the rest
of the AMF data.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=578d6861a753eb0b9d277f7ec17d1502eb2bb35a
---

 libavformat/flvdec.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 94159be..e7ec0b1 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -135,7 +135,7 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream
     char str_val[256];
     int64_t *times = NULL;
     int64_t *filepositions = NULL;
-    int ret = 0;
+    int ret = AVERROR(ENOSYS);
     int64_t initial_pos = avio_tell(ioc);
 
     while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
@@ -173,6 +173,12 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream
             num_val = av_int2dbl(avio_rb64(ioc));
             current_array[i] = num_val;
         }
+        if (times && filepositions) {
+            // All done, exiting at a position allowing amf_parse_object
+            // to finish parsing the object
+            ret = 0;
+            break;
+        }
     }
 
     if (timeslen == fileposlen)
@@ -184,7 +190,10 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream
 finish:
     av_freep(&times);
     av_freep(&filepositions);
-    avio_seek(ioc, initial_pos, SEEK_SET);
+    // If we got unexpected data, but successfully reset back to
+    // the start pos, the caller can continue parsing
+    if (ret < 0 && avio_seek(ioc, initial_pos, SEEK_SET) > 0)
+        return 0;
     return ret;
 }
 



More information about the ffmpeg-cvslog mailing list