[FFmpeg-devel] [PATCH 0/7] ffmpeg: add a grow_array() helper function

Aurelien Jacobs aurel
Fri Aug 13 20:28:12 CEST 2010


Ooops... I slightly messed up this patch serie.
I forgot the first patch which adds a grow_array() function which is
then used by all the following patches. Here it is.
The rest of the serie changes each *[MAX_STREAMS] arrays from ffmpeg.c
into a dynamically allocated array.

Aurel


diff --git a/ffmpeg.c b/ffmpeg.c
index aec1f79..28ce27f 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -646,6 +646,23 @@ static int ffmpeg_exit(int ret)
     return ret;
 }
 
+static void *grow_array(void *array, int elem_size, int *size, int new_size)
+{
+    if (*size < new_size) {
+        uint8_t *tmp = av_realloc(array, new_size*elem_size);
+        if (!tmp) {
+            fprintf(stderr, "Could not alloc buffer\n");
+            ffmpeg_exit(1);
+        }
+        memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
+        *size = new_size;
+        return tmp;
+    }
+    return array;
+}
+#define GROW_ARRAY(array, size)  \
+    array = grow_array(array, sizeof(*array), &nb_##array, size)
+
 static void choose_sample_fmt(AVStream *st, AVCodec *codec)
 {
     if(codec && codec->sample_fmts){



More information about the ffmpeg-devel mailing list