diff mbox series

[FFmpeg-devel,2/3] lavf/movdec: allow setting the header size in advance

Message ID 20200522054200.74203-2-rcombs@rcombs.me
State New
Headers show
Series [FFmpeg-devel,1/3] lavf/format: handle max probe buffer sizes <2048
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

rcombs May 22, 2020, 5:41 a.m. UTC
This is useful for chained demuxers, to avoid reading past the end of a shared
initialization segment and into the first data segment unnecessarily.
---
 libavformat/isom.h |  1 +
 libavformat/mov.c  | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 41a9c64c11..3479553da6 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -291,6 +291,7 @@  typedef struct MOVContext {
     int decryption_key_len;
     int enable_drefs;
     int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd
+    int64_t header_size;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index e11c9f4457..51d3204582 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7574,6 +7574,9 @@  static int mov_read_header(AVFormatContext *s)
     else
         atom.size = INT64_MAX;
 
+    if (mov->header_size > 0)
+        atom.size = mov->header_size;
+
     /* check MOV header */
     do {
         if (mov->moov_retry)
@@ -7591,6 +7594,9 @@  static int mov_read_header(AVFormatContext *s)
     }
     av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb));
 
+    if (mov->header_size > 0)
+        mov->next_root_atom = mov->header_size;
+
     if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
         if (mov->nb_chapter_tracks > 0 && !mov->ignore_chapters)
             mov_read_chapters(s);
@@ -8162,7 +8168,9 @@  static const AVOption mov_options[] = {
     { "decryption_key", "The media decryption key (hex)", OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM },
     { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), AV_OPT_TYPE_BOOL,
         {.i64 = 0}, 0, 1, FLAGS },
-
+    { "header_size", "size of initial header, ",
+        OFFSET(header_size), AV_OPT_TYPE_INT64, {.i64 = -1},
+        -1, INT64_MAX, FLAGS },
     { NULL },
 };