Browse code

cmdutils: add a macro to simplify grow_array() calls.

Anton Khirnov authored on 2012/06/08 04:52:07
Showing 3 changed files
... ...
@@ -77,8 +77,7 @@ FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost)
77 77
         exit(1);
78 78
     fg->index = nb_filtergraphs;
79 79
 
80
-    fg->outputs = grow_array(fg->outputs, sizeof(*fg->outputs), &fg->nb_outputs,
81
-                             fg->nb_outputs + 1);
80
+    GROW_ARRAY(fg->outputs, fg->nb_outputs);
82 81
     if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
83 82
         exit(1);
84 83
     fg->outputs[0]->ost   = ost;
... ...
@@ -86,19 +85,16 @@ FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost)
86 86
 
87 87
     ost->filter = fg->outputs[0];
88 88
 
89
-    fg->inputs = grow_array(fg->inputs, sizeof(*fg->inputs), &fg->nb_inputs,
90
-                            fg->nb_inputs + 1);
89
+    GROW_ARRAY(fg->inputs, fg->nb_inputs);
91 90
     if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
92 91
         exit(1);
93 92
     fg->inputs[0]->ist   = ist;
94 93
     fg->inputs[0]->graph = fg;
95 94
 
96
-    ist->filters = grow_array(ist->filters, sizeof(*ist->filters),
97
-                              &ist->nb_filters, ist->nb_filters + 1);
95
+    GROW_ARRAY(ist->filters, ist->nb_filters);
98 96
     ist->filters[ist->nb_filters - 1] = fg->inputs[0];
99 97
 
100
-    filtergraphs = grow_array(filtergraphs, sizeof(*filtergraphs),
101
-                              &nb_filtergraphs, nb_filtergraphs + 1);
98
+    GROW_ARRAY(filtergraphs, nb_filtergraphs);
102 99
     filtergraphs[nb_filtergraphs - 1] = fg;
103 100
 
104 101
     return fg;
... ...
@@ -164,15 +160,13 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
164 164
     ist->decoding_needed = 1;
165 165
     ist->st->discard = AVDISCARD_NONE;
166 166
 
167
-    fg->inputs = grow_array(fg->inputs, sizeof(*fg->inputs),
168
-                            &fg->nb_inputs, fg->nb_inputs + 1);
167
+    GROW_ARRAY(fg->inputs, fg->nb_inputs);
169 168
     if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
170 169
         exit(1);
171 170
     fg->inputs[fg->nb_inputs - 1]->ist   = ist;
172 171
     fg->inputs[fg->nb_inputs - 1]->graph = fg;
173 172
 
174
-    ist->filters = grow_array(ist->filters, sizeof(*ist->filters),
175
-                              &ist->nb_filters, ist->nb_filters + 1);
173
+    GROW_ARRAY(ist->filters, ist->nb_filters);
176 174
     ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
177 175
 }
178 176
 
... ...
@@ -541,8 +535,7 @@ int configure_filtergraph(FilterGraph *fg)
541 541
     } else {
542 542
         /* wait until output mappings are processed */
543 543
         for (cur = outputs; cur;) {
544
-            fg->outputs = grow_array(fg->outputs, sizeof(*fg->outputs),
545
-                                     &fg->nb_outputs, fg->nb_outputs + 1);
544
+            GROW_ARRAY(fg->outputs, fg->nb_outputs);
546 545
             if (!(fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]))))
547 546
                 exit(1);
548 547
             fg->outputs[fg->nb_outputs - 1]->graph   = fg;
... ...
@@ -210,8 +210,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
210 210
     if (map[0] == '[') {
211 211
         /* this mapping refers to lavfi output */
212 212
         const char *c = map + 1;
213
-        o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps),
214
-                                    &o->nb_stream_maps, o->nb_stream_maps + 1);
213
+        GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
215 214
         m = &o->stream_maps[o->nb_stream_maps - 1];
216 215
         m->linklabel = av_get_token(&c, "]");
217 216
         if (!m->linklabel) {
... ...
@@ -239,8 +238,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
239 239
                 if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
240 240
                             *p == ':' ? p + 1 : p) <= 0)
241 241
                     continue;
242
-                o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps),
243
-                                            &o->nb_stream_maps, o->nb_stream_maps + 1);
242
+                GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
244 243
                 m = &o->stream_maps[o->nb_stream_maps - 1];
245 244
 
246 245
                 m->file_index   = file_idx;
... ...
@@ -268,8 +266,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
268 268
 static int opt_attach(void *optctx, const char *opt, const char *arg)
269 269
 {
270 270
     OptionsContext *o = optctx;
271
-    o->attachments = grow_array(o->attachments, sizeof(*o->attachments),
272
-                                &o->nb_attachments, o->nb_attachments + 1);
271
+    GROW_ARRAY(o->attachments, o->nb_attachments);
273 272
     o->attachments[o->nb_attachments - 1] = arg;
274 273
     return 0;
275 274
 }
... ...
@@ -445,7 +442,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
445 445
         if (!ist)
446 446
             exit(1);
447 447
 
448
-        input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
448
+        GROW_ARRAY(input_streams, nb_input_streams);
449 449
         input_streams[nb_input_streams - 1] = ist;
450 450
 
451 451
         ist->st = st;
... ...
@@ -658,7 +655,7 @@ static int opt_input_file(void *optctx, const char *opt, const char *filename)
658 658
     /* dump the file content */
659 659
     av_dump_format(ic, nb_input_files, filename, 0);
660 660
 
661
-    input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);
661
+    GROW_ARRAY(input_files, nb_input_files);
662 662
     if (!(input_files[nb_input_files - 1] = av_mallocz(sizeof(*input_files[0]))))
663 663
         exit(1);
664 664
 
... ...
@@ -766,8 +763,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
766 766
     if (oc->nb_streams - 1 < o->nb_streamid_map)
767 767
         st->id = o->streamid_map[oc->nb_streams - 1];
768 768
 
769
-    output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams,
770
-                                nb_output_streams + 1);
769
+    GROW_ARRAY(output_streams, nb_output_streams);
771 770
     if (!(ost = av_mallocz(sizeof(*ost))))
772 771
         exit(1);
773 772
     output_streams[nb_output_streams - 1] = ost;
... ...
@@ -1370,7 +1366,7 @@ loop_end:
1370 1370
         avio_close(pb);
1371 1371
     }
1372 1372
 
1373
-    output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);
1373
+    GROW_ARRAY(output_files, nb_output_files);
1374 1374
     if (!(output_files[nb_output_files - 1] = av_mallocz(sizeof(*output_files[0]))))
1375 1375
         exit(1);
1376 1376
 
... ...
@@ -1783,8 +1779,7 @@ static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
1783 1783
 
1784 1784
 static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
1785 1785
 {
1786
-    filtergraphs = grow_array(filtergraphs, sizeof(*filtergraphs),
1787
-                              &nb_filtergraphs, nb_filtergraphs + 1);
1786
+    GROW_ARRAY(filtergraphs, nb_filtergraphs);
1788 1787
     if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
1789 1788
         return AVERROR(ENOMEM);
1790 1789
     filtergraphs[nb_filtergraphs - 1]->index       = nb_filtergraphs - 1;
... ...
@@ -418,6 +418,9 @@ FILE *get_preset_file(char *filename, size_t filename_size,
418 418
  */
419 419
 void *grow_array(void *array, int elem_size, int *size, int new_size);
420 420
 
421
+#define GROW_ARRAY(array, nb_elems)\
422
+    array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
423
+
421 424
 typedef struct FrameBuffer {
422 425
     uint8_t *base[4];
423 426
     uint8_t *data[4];