1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit '10bca66101b79954512cd9d8ee20c3bc4513adf3'

* commit '10bca66101b79954512cd9d8ee20c3bc4513adf3':
  cmdutils: add a macro to simplify grow_array() calls.

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2012-12-19 22:03:54 +01:00
commit 330983b728
3 changed files with 18 additions and 27 deletions

View File

@ -427,6 +427,9 @@ FILE *get_preset_file(char *filename, size_t filename_size,
*/ */
void *grow_array(void *array, int elem_size, int *size, int new_size); void *grow_array(void *array, int elem_size, int *size, int new_size);
#define GROW_ARRAY(array, nb_elems)\
array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
typedef struct FrameBuffer { typedef struct FrameBuffer {
uint8_t *base[4]; uint8_t *base[4];
uint8_t *data[4]; uint8_t *data[4];

View File

@ -179,8 +179,7 @@ FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost)
exit(1); exit(1);
fg->index = nb_filtergraphs; fg->index = nb_filtergraphs;
fg->outputs = grow_array(fg->outputs, sizeof(*fg->outputs), &fg->nb_outputs, GROW_ARRAY(fg->outputs, fg->nb_outputs);
fg->nb_outputs + 1);
if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0])))) if (!(fg->outputs[0] = av_mallocz(sizeof(*fg->outputs[0]))))
exit(1); exit(1);
fg->outputs[0]->ost = ost; fg->outputs[0]->ost = ost;
@ -188,19 +187,16 @@ FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost)
ost->filter = fg->outputs[0]; ost->filter = fg->outputs[0];
fg->inputs = grow_array(fg->inputs, sizeof(*fg->inputs), &fg->nb_inputs, GROW_ARRAY(fg->inputs, fg->nb_inputs);
fg->nb_inputs + 1);
if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0])))) if (!(fg->inputs[0] = av_mallocz(sizeof(*fg->inputs[0]))))
exit(1); exit(1);
fg->inputs[0]->ist = ist; fg->inputs[0]->ist = ist;
fg->inputs[0]->graph = fg; fg->inputs[0]->graph = fg;
ist->filters = grow_array(ist->filters, sizeof(*ist->filters), GROW_ARRAY(ist->filters, ist->nb_filters);
&ist->nb_filters, ist->nb_filters + 1);
ist->filters[ist->nb_filters - 1] = fg->inputs[0]; ist->filters[ist->nb_filters - 1] = fg->inputs[0];
filtergraphs = grow_array(filtergraphs, sizeof(*filtergraphs), GROW_ARRAY(filtergraphs, nb_filtergraphs);
&nb_filtergraphs, nb_filtergraphs + 1);
filtergraphs[nb_filtergraphs - 1] = fg; filtergraphs[nb_filtergraphs - 1] = fg;
return fg; return fg;
@ -269,15 +265,13 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
ist->decoding_needed++; ist->decoding_needed++;
ist->st->discard = AVDISCARD_NONE; ist->st->discard = AVDISCARD_NONE;
fg->inputs = grow_array(fg->inputs, sizeof(*fg->inputs), GROW_ARRAY(fg->inputs, fg->nb_inputs);
&fg->nb_inputs, fg->nb_inputs + 1);
if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0])))) if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))
exit(1); exit(1);
fg->inputs[fg->nb_inputs - 1]->ist = ist; fg->inputs[fg->nb_inputs - 1]->ist = ist;
fg->inputs[fg->nb_inputs - 1]->graph = fg; fg->inputs[fg->nb_inputs - 1]->graph = fg;
ist->filters = grow_array(ist->filters, sizeof(*ist->filters), GROW_ARRAY(ist->filters, ist->nb_filters);
&ist->nb_filters, ist->nb_filters + 1);
ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1]; ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
} }
@ -772,8 +766,7 @@ int configure_filtergraph(FilterGraph *fg)
} else { } else {
/* wait until output mappings are processed */ /* wait until output mappings are processed */
for (cur = outputs; cur;) { for (cur = outputs; cur;) {
fg->outputs = grow_array(fg->outputs, sizeof(*fg->outputs), GROW_ARRAY(fg->outputs, fg->nb_outputs);
&fg->nb_outputs, fg->nb_outputs + 1);
if (!(fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0])))) if (!(fg->outputs[fg->nb_outputs - 1] = av_mallocz(sizeof(*fg->outputs[0]))))
exit(1); exit(1);
fg->outputs[fg->nb_outputs - 1]->graph = fg; fg->outputs[fg->nb_outputs - 1]->graph = fg;

View File

@ -244,8 +244,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
if (map[0] == '[') { if (map[0] == '[') {
/* this mapping refers to lavfi output */ /* this mapping refers to lavfi output */
const char *c = map + 1; const char *c = map + 1;
o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps), GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
&o->nb_stream_maps, o->nb_stream_maps + 1);
m = &o->stream_maps[o->nb_stream_maps - 1]; m = &o->stream_maps[o->nb_stream_maps - 1];
m->linklabel = av_get_token(&c, "]"); m->linklabel = av_get_token(&c, "]");
if (!m->linklabel) { if (!m->linklabel) {
@ -273,8 +272,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i], if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
*p == ':' ? p + 1 : p) <= 0) *p == ':' ? p + 1 : p) <= 0)
continue; continue;
o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps), GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
&o->nb_stream_maps, o->nb_stream_maps + 1);
m = &o->stream_maps[o->nb_stream_maps - 1]; m = &o->stream_maps[o->nb_stream_maps - 1];
m->file_index = file_idx; m->file_index = file_idx;
@ -302,8 +300,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
static int opt_attach(void *optctx, const char *opt, const char *arg) static int opt_attach(void *optctx, const char *opt, const char *arg)
{ {
OptionsContext *o = optctx; OptionsContext *o = optctx;
o->attachments = grow_array(o->attachments, sizeof(*o->attachments), GROW_ARRAY(o->attachments, o->nb_attachments);
&o->nb_attachments, o->nb_attachments + 1);
o->attachments[o->nb_attachments - 1] = arg; o->attachments[o->nb_attachments - 1] = arg;
return 0; return 0;
} }
@ -565,7 +562,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
if (!ist) if (!ist)
exit(1); exit(1);
input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1); GROW_ARRAY(input_streams, nb_input_streams);
input_streams[nb_input_streams - 1] = ist; input_streams[nb_input_streams - 1] = ist;
ist->st = st; ist->st = st;
@ -820,7 +817,7 @@ static int opt_input_file(void *optctx, const char *opt, const char *filename)
/* dump the file content */ /* dump the file content */
av_dump_format(ic, nb_input_files, filename, 0); av_dump_format(ic, nb_input_files, filename, 0);
input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1); GROW_ARRAY(input_files, nb_input_files);
if (!(input_files[nb_input_files - 1] = av_mallocz(sizeof(*input_files[0])))) if (!(input_files[nb_input_files - 1] = av_mallocz(sizeof(*input_files[0]))))
exit(1); exit(1);
@ -928,8 +925,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
if (oc->nb_streams - 1 < o->nb_streamid_map) if (oc->nb_streams - 1 < o->nb_streamid_map)
st->id = o->streamid_map[oc->nb_streams - 1]; st->id = o->streamid_map[oc->nb_streams - 1];
output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams, GROW_ARRAY(output_streams, nb_output_streams);
nb_output_streams + 1);
if (!(ost = av_mallocz(sizeof(*ost)))) if (!(ost = av_mallocz(sizeof(*ost))))
exit(1); exit(1);
output_streams[nb_output_streams - 1] = ost; output_streams[nb_output_streams - 1] = ost;
@ -1667,7 +1663,7 @@ loop_end:
avio_close(pb); avio_close(pb);
} }
output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1); GROW_ARRAY(output_files, nb_output_files);
if (!(output_files[nb_output_files - 1] = av_mallocz(sizeof(*output_files[0])))) if (!(output_files[nb_output_files - 1] = av_mallocz(sizeof(*output_files[0]))))
exit(1); exit(1);
@ -2160,8 +2156,7 @@ static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
static int opt_filter_complex(void *optctx, const char *opt, const char *arg) static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
{ {
filtergraphs = grow_array(filtergraphs, sizeof(*filtergraphs), GROW_ARRAY(filtergraphs, nb_filtergraphs);
&nb_filtergraphs, nb_filtergraphs + 1);
if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0])))) if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1; filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1;