[FFmpeg-devel] [PATCH 2/4] fftools/ffmpeg_(filter|opt): Use dedicated pointer for array elem access
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Fri Dec 3 20:28:26 EET 2021
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
fftools/ffmpeg_filter.c | 56 +++++++++++++++++++++++------------------
fftools/ffmpeg_opt.c | 14 +++++++----
2 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 75194fe66e..04253a9b21 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -159,29 +159,33 @@ DEF_CHOOSE_FORMAT(channel_layouts, uint64_t, channel_layout, channel_layouts, 0,
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
{
FilterGraph *fg = av_mallocz(sizeof(*fg));
+ OutputFilter *ofilter;
+ InputFilter *ifilter;
if (!fg)
exit_program(1);
fg->index = nb_filtergraphs;
ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
- fg->outputs[0]->ost = ost;
- fg->outputs[0]->graph = fg;
- fg->outputs[0]->format = -1;
+ ofilter = fg->outputs[0];
+ ofilter->ost = ost;
+ ofilter->graph = fg;
+ ofilter->format = -1;
- ost->filter = fg->outputs[0];
+ ost->filter = ofilter;
ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
- fg->inputs[0]->ist = ist;
- fg->inputs[0]->graph = fg;
- fg->inputs[0]->format = -1;
+ ifilter = fg->inputs[0];
+ ifilter->ist = ist;
+ ifilter->graph = fg;
+ ifilter->format = -1;
- fg->inputs[0]->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
- if (!fg->inputs[0]->frame_queue)
+ ifilter->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
+ if (!ifilter->frame_queue)
exit_program(1);
GROW_ARRAY(ist->filters, ist->nb_filters);
- ist->filters[ist->nb_filters - 1] = fg->inputs[0];
+ ist->filters[ist->nb_filters - 1] = ifilter;
GROW_ARRAY(filtergraphs, nb_filtergraphs);
filtergraphs[nb_filtergraphs - 1] = fg;
@@ -210,6 +214,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
{
InputStream *ist = NULL;
enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);
+ InputFilter *ifilter;
int i;
// TODO: support other filter types
@@ -277,18 +282,19 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
ist->st->discard = AVDISCARD_NONE;
ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs);
- fg->inputs[fg->nb_inputs - 1]->ist = ist;
- fg->inputs[fg->nb_inputs - 1]->graph = fg;
- fg->inputs[fg->nb_inputs - 1]->format = -1;
- fg->inputs[fg->nb_inputs - 1]->type = ist->st->codecpar->codec_type;
- fg->inputs[fg->nb_inputs - 1]->name = describe_filter_link(fg, in, 1);
-
- fg->inputs[fg->nb_inputs - 1]->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
- if (!fg->inputs[fg->nb_inputs - 1]->frame_queue)
+ ifilter = fg->inputs[fg->nb_inputs - 1];
+ ifilter->ist = ist;
+ ifilter->graph = fg;
+ ifilter->format = -1;
+ ifilter->type = ist->st->codecpar->codec_type;
+ ifilter->name = describe_filter_link(fg, in, 1);
+
+ ifilter->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
+ if (!ifilter->frame_queue)
exit_program(1);
GROW_ARRAY(ist->filters, ist->nb_filters);
- ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];
+ ist->filters[ist->nb_filters - 1] = ifilter;
}
int init_complex_filtergraph(FilterGraph *fg)
@@ -312,15 +318,17 @@ int init_complex_filtergraph(FilterGraph *fg)
init_input_filter(fg, cur);
for (cur = outputs; cur;) {
+ OutputFilter *ofilter;
ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
+ ofilter = fg->outputs[fg->nb_outputs - 1];
- fg->outputs[fg->nb_outputs - 1]->graph = fg;
- fg->outputs[fg->nb_outputs - 1]->out_tmp = cur;
- fg->outputs[fg->nb_outputs - 1]->type = avfilter_pad_get_type(cur->filter_ctx->output_pads,
+ ofilter->graph = fg;
+ ofilter->out_tmp = cur;
+ ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads,
cur->pad_idx);
- fg->outputs[fg->nb_outputs - 1]->name = describe_filter_link(fg, cur, 0);
+ ofilter->name = describe_filter_link(fg, cur, 0);
cur = cur->next;
- fg->outputs[fg->nb_outputs - 1]->out_tmp->next = NULL;
+ ofilter->out_tmp->next = NULL;
}
fail:
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index ffba7010e3..6f971bc922 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -3256,10 +3256,12 @@ 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)
{
+ FilterGraph *fg;
ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
- filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1;
- filtergraphs[nb_filtergraphs - 1]->graph_desc = av_strdup(arg);
- if (!filtergraphs[nb_filtergraphs - 1]->graph_desc)
+ fg = filtergraphs[nb_filtergraphs - 1];
+ fg->index = nb_filtergraphs - 1;
+ fg->graph_desc = av_strdup(arg);
+ if (!fg->graph_desc)
return AVERROR(ENOMEM);
input_stream_potentially_available = 1;
@@ -3269,13 +3271,15 @@ static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
{
+ FilterGraph *fg;
uint8_t *graph_desc = read_file(arg);
if (!graph_desc)
return AVERROR(EINVAL);
ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
- filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1;
- filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc;
+ fg = filtergraphs[nb_filtergraphs - 1];
+ fg->index = nb_filtergraphs - 1;
+ fg->graph_desc = graph_desc;
input_stream_potentially_available = 1;
--
2.32.0
More information about the ffmpeg-devel
mailing list