[FFmpeg-devel] [PATCH 01/41] avformat: add ff_alloc_extradata() helper

Paul B Mahol onemda at gmail.com
Sun Oct 13 14:48:22 CEST 2013


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavformat/internal.h |  2 ++
 libavformat/utils.c    | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index ceeaa1c..2a52a54 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -361,4 +361,6 @@ AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precissi
  */
 void ff_generate_avci_extradata(AVStream *st);
 
+int ff_alloc_extradata(AVCodecContext *c, int size);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 61405d7..c15bd5f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2678,6 +2678,24 @@ int av_find_stream_info(AVFormatContext *ic)
 }
 #endif
 
+int ff_alloc_extradata(AVCodecContext *c, int size)
+{
+    int ret;
+
+    if (size >= INT32_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
+        return AVERROR(EINVAL);
+    c->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+    if (c->extradata) {
+        memset(ret + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+        c->extradata_size = size;
+        ret = 0;
+    } else {
+        c->extradata_size = 0;
+        ret = AVERROR(ENOMEM);
+    }
+    return ret;
+}
+
 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 {
     int i, count, ret = 0, j;
-- 
1.7.11.2



More information about the ffmpeg-devel mailing list