[FFmpeg-cvslog] avformat: add ff_alloc_extradata() helper

Paul B Mahol git at videolan.org
Sun Oct 13 22:24:48 CEST 2013


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Oct 13 10:19:09 2013 +0000| [3fd79833e266aec2d77cf07092e8b1406fd307d4] | committer: Paul B Mahol

avformat: add ff_alloc_extradata() helper

Signed-off-by: Paul B Mahol <onemda at gmail.com>

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

 libavformat/internal.h |    9 +++++++++
 libavformat/utils.c    |   20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index ceeaa1c..36ee4c0 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -361,4 +361,13 @@ AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precissi
  */
 void ff_generate_avci_extradata(AVStream *st);
 
+/**
+ * Allocate extradata with additional FF_INPUT_BUFFER_PADDING_SIZE at end
+ * which is always set to 0.
+ *
+ * @param size size of extradata
+ * @return 0 if OK, AVERROR_xxx on error
+ */
+int ff_alloc_extradata(AVCodecContext *avctx, int size);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 61405d7..6a7f580 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2678,6 +2678,26 @@ int av_find_stream_info(AVFormatContext *ic)
 }
 #endif
 
+int ff_alloc_extradata(AVCodecContext *avctx, int size)
+{
+    int ret;
+
+    if (size < 0 || size >= INT32_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
+        avctx->extradata_size = 0;
+        return AVERROR(EINVAL);
+    }
+    avctx->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+    if (avctx->extradata) {
+        memset(avctx->extradata + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+        avctx->extradata_size = size;
+        ret = 0;
+    } else {
+        avctx->extradata_size = 0;
+        ret = AVERROR(ENOMEM);
+    }
+    return ret;
+}
+
 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 {
     int i, count, ret = 0, j;



More information about the ffmpeg-cvslog mailing list