avfilter/avfilter: Remove unused feature to add pads in the middle

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-08-16 20:48:00 +02:00
parent 1e35744a4c
commit 515e7fbce1
34 changed files with 56 additions and 69 deletions

View File

@ -191,7 +191,7 @@ static av_cold int init(AVFilterContext *ctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
pad.name = name; pad.name = name;
if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_outpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -836,7 +836,7 @@ static av_cold int init(AVFilterContext *ctx)
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,
}; };
ret = ff_insert_inpad(ctx, 0, &pad); ret = ff_append_inpad(ctx, &pad);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -849,7 +849,7 @@ static av_cold int init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ret = ff_insert_inpad(ctx, n + 1, &pad); ret = ff_append_inpad(ctx, &pad);
if (ret < 0) { if (ret < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
@ -862,7 +862,7 @@ static av_cold int init(AVFilterContext *ctx)
.config_props = config_output, .config_props = config_output,
}; };
ret = ff_insert_outpad(ctx, 0, &pad); ret = ff_append_outpad(ctx, &pad);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -873,7 +873,7 @@ static av_cold int init(AVFilterContext *ctx)
.config_props = config_video, .config_props = config_video,
}; };
ret = ff_insert_outpad(ctx, 1, &vpad); ret = ff_append_outpad(ctx, &vpad);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }

View File

@ -1473,7 +1473,7 @@ static av_cold int init(AVFilterContext *ctx)
.config_props = config_output, .config_props = config_output,
}; };
ret = ff_insert_outpad(ctx, 0, &pad); ret = ff_append_outpad(ctx, &pad);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -1484,7 +1484,7 @@ static av_cold int init(AVFilterContext *ctx)
.config_props = config_video, .config_props = config_video,
}; };
ret = ff_insert_outpad(ctx, 1, &vpad); ret = ff_append_outpad(ctx, &vpad);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }

View File

@ -328,7 +328,7 @@ static av_cold int init(AVFilterContext *ctx)
}; };
if (!name) if (!name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -553,7 +553,7 @@ static av_cold int init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -196,7 +196,7 @@ static av_cold int init(AVFilterContext *ctx)
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,
}; };
ret = ff_insert_outpad(ctx, 0, &pad); ret = ff_append_outpad(ctx, &pad);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -206,7 +206,7 @@ static av_cold int init(AVFilterContext *ctx)
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.config_props = config_video, .config_props = config_video,
}; };
ret = ff_insert_outpad(ctx, 1, &vpad); ret = ff_append_outpad(ctx, &vpad);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }

View File

@ -97,9 +97,8 @@ static av_cold int init(AVFilterContext *ctx)
s->map[i] = ret; s->map[i] = ret;
} }
if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_outpad(ctx, &pad)) < 0)
return ret; return ret;
}
} }
fail: fail:

View File

@ -652,7 +652,7 @@ static av_cold int init(AVFilterContext *ctx)
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,
.config_props = config_input, .config_props = config_input,
}; };
if ((ret = ff_insert_inpad(ctx, 0, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
if (!s->map) { if (!s->map) {
@ -670,7 +670,7 @@ static av_cold int init(AVFilterContext *ctx)
}; };
if (!name) if (!name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i + 1, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -194,7 +194,7 @@ static av_cold int join_init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -639,7 +639,7 @@ static av_cold int init(AVFilterContext *ctx)
pad.filter_frame = filter_frame; pad.filter_frame = filter_frame;
pad.config_props = config_input; pad.config_props = config_input;
if (ff_insert_inpad(ctx, ctx->nb_inputs, &pad) < 0) { if (ff_append_inpad(ctx, &pad) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }

View File

@ -464,7 +464,7 @@ static av_cold int init(AVFilterContext *ctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
pad.filter_frame = filter_frame; pad.filter_frame = filter_frame;
if (ff_insert_inpad(ctx, ctx->nb_inputs, &pad) < 0) { if (ff_append_inpad(ctx, &pad) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }

View File

@ -355,7 +355,7 @@ static av_cold int init(AVFilterContext *ctx)
.name = "out0", .name = "out0",
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,
}; };
ret = ff_insert_outpad(ctx, 0, &pad); ret = ff_append_outpad(ctx, &pad);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -365,7 +365,7 @@ static av_cold int init(AVFilterContext *ctx)
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.config_props = config_video_output, .config_props = config_video_output,
}; };
ret = ff_insert_outpad(ctx, 1, &pad); ret = ff_append_outpad(ctx, &pad);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }

View File

@ -319,7 +319,7 @@ static av_cold int init(AVFilterContext *ctx)
else else
pad.get_buffer.audio = get_audio_buffer; pad.get_buffer.audio = get_audio_buffer;
pad.name = av_asprintf("in%d:%c%d", seg, "va"[type], str); pad.name = av_asprintf("in%d:%c%d", seg, "va"[type], str);
if ((ret = ff_insert_inpad(ctx, ctx->nb_inputs, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }
@ -334,7 +334,7 @@ static av_cold int init(AVFilterContext *ctx)
.config_props = config_output, .config_props = config_output,
}; };
pad.name = av_asprintf("out:%c%d", "va"[type], str); pad.name = av_asprintf("out:%c%d", "va"[type], str);
if ((ret = ff_insert_outpad(ctx, ctx->nb_outputs, &pad)) < 0) { if ((ret = ff_append_outpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -101,18 +101,16 @@ void ff_command_queue_pop(AVFilterContext *filter)
av_free(c); av_free(c);
} }
int ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, int ff_append_pad(unsigned *count,
AVFilterPad **pads, AVFilterLink ***links, AVFilterPad **pads, AVFilterLink ***links,
AVFilterPad *newpad) AVFilterPad *newpad)
{ {
AVFilterLink **newlinks; AVFilterLink **newlinks;
AVFilterPad *newpads; AVFilterPad *newpads;
unsigned i; unsigned idx = *count;
idx = FFMIN(idx, *count); newpads = av_realloc_array(*pads, idx + 1, sizeof(*newpads));
newlinks = av_realloc_array(*links, idx + 1, sizeof(*newlinks));
newpads = av_realloc_array(*pads, *count + 1, sizeof(AVFilterPad));
newlinks = av_realloc_array(*links, *count + 1, sizeof(AVFilterLink*));
if (newpads) if (newpads)
*pads = newpads; *pads = newpads;
if (newlinks) if (newlinks)
@ -120,15 +118,10 @@ int ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
if (!newpads || !newlinks) if (!newpads || !newlinks)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
memmove(*pads + idx + 1, *pads + idx, sizeof(AVFilterPad) * (*count - idx));
memmove(*links + idx + 1, *links + idx, sizeof(AVFilterLink*) * (*count - idx));
memcpy(*pads + idx, newpad, sizeof(AVFilterPad)); memcpy(*pads + idx, newpad, sizeof(AVFilterPad));
(*links)[idx] = NULL; (*links)[idx] = NULL;
(*count)++; (*count)++;
for (i = idx + 1; i < *count; i++)
if ((*links)[i])
(*(unsigned *)((uint8_t *) (*links)[i] + padidx_off))++;
return 0; return 0;
} }

View File

@ -552,7 +552,7 @@ static av_cold int init(AVFilterContext *ctx)
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.config_props = config_video_output, .config_props = config_video_output,
}; };
ret = ff_insert_outpad(ctx, 0, &pad); ret = ff_append_outpad(ctx, &pad);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
@ -561,7 +561,7 @@ static av_cold int init(AVFilterContext *ctx)
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,
.config_props = config_audio_output, .config_props = config_audio_output,
}; };
ret = ff_insert_outpad(ctx, ebur128->do_video, &pad); ret = ff_append_outpad(ctx, &pad);
if (ret < 0) if (ret < 0)
return ret; return ret;

View File

@ -173,7 +173,7 @@ static av_cold int init(AVFilterContext *ctx)
default: default:
av_assert0(0); av_assert0(0);
} }
if ((ret = ff_insert_inpad(ctx, i, &inpad)) < 0) { if ((ret = ff_append_inpad(ctx, &inpad)) < 0) {
av_freep(&inpad.name); av_freep(&inpad.name);
return ret; return ret;
} }

View File

@ -137,7 +137,7 @@ static av_cold int init(AVFilterContext *ctx, enum AVMediaType type)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_outpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -192,7 +192,7 @@ static av_cold int init(AVFilterContext *ctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
pad.type = ctx->filter->inputs[0].type; pad.type = ctx->filter->inputs[0].type;
pad.request_frame = request_frame; pad.request_frame = request_frame;
if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_outpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -167,10 +167,10 @@ static int parse_definition(AVFilterContext *ctx, int nb_pads, int is_input, int
av_log(ctx, AV_LOG_DEBUG, "Add %s pad %s\n", padtype, pad.name); av_log(ctx, AV_LOG_DEBUG, "Add %s pad %s\n", padtype, pad.name);
if (is_input) { if (is_input) {
ret = ff_insert_inpad(ctx, i, &pad); ret = ff_append_inpad(ctx, &pad);
} else { } else {
pad.config_props = config_output; pad.config_props = config_output;
ret = ff_insert_outpad(ctx, i, &pad); ret = ff_append_outpad(ctx, &pad);
} }
if (ret < 0) { if (ret < 0) {

View File

@ -226,34 +226,29 @@ void ff_tlog_link(void *ctx, AVFilterLink *link, int end);
/** /**
* Insert a new pad. * Insert a new pad.
* *
* @param idx Insertion point. Pad is inserted at the end if this point
* is beyond the end of the list of pads.
* @param count Pointer to the number of pads in the list * @param count Pointer to the number of pads in the list
* @param padidx_off Offset within an AVFilterLink structure to the element
* to increment when inserting a new pad causes link
* numbering to change
* @param pads Pointer to the pointer to the beginning of the list of pads * @param pads Pointer to the pointer to the beginning of the list of pads
* @param links Pointer to the pointer to the beginning of the list of links * @param links Pointer to the pointer to the beginning of the list of links
* @param newpad The new pad to add. A copy is made when adding. * @param newpad The new pad to add. A copy is made when adding.
* @return >= 0 in case of success, a negative AVERROR code on error * @return >= 0 in case of success, a negative AVERROR code on error
*/ */
int ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, int ff_append_pad(unsigned *count,
AVFilterPad **pads, AVFilterLink ***links, AVFilterPad **pads, AVFilterLink ***links,
AVFilterPad *newpad); AVFilterPad *newpad);
/** Insert a new input pad for the filter. */ /** Insert a new input pad for the filter. */
static inline int ff_insert_inpad(AVFilterContext *f, unsigned index, static inline int ff_append_inpad(AVFilterContext *f,
AVFilterPad *p) AVFilterPad *p)
{ {
return ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad), return ff_append_pad(&f->nb_inputs,
&f->input_pads, &f->inputs, p); &f->input_pads, &f->inputs, p);
} }
/** Insert a new output pad for the filter. */ /** Insert a new output pad for the filter. */
static inline int ff_insert_outpad(AVFilterContext *f, unsigned index, static inline int ff_append_outpad(AVFilterContext *f,
AVFilterPad *p) AVFilterPad *p)
{ {
return ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad), return ff_append_pad(&f->nb_outputs,
&f->output_pads, &f->outputs, p); &f->output_pads, &f->outputs, p);
} }

View File

@ -56,7 +56,7 @@ static av_cold int split_init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_outpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -306,7 +306,7 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
pad.config_props = movie_config_output_props; pad.config_props = movie_config_output_props;
pad.request_frame = movie_request_frame; pad.request_frame = movie_request_frame;
if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_outpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -941,7 +941,7 @@ static av_cold int init(AVFilterContext *ctx)
pad.name = "source"; pad.name = "source";
pad.config_props = config_input; pad.config_props = config_input;
if ((ret = ff_insert_inpad(ctx, 0, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
if (s->ref) { if (s->ref) {
@ -949,7 +949,7 @@ static av_cold int init(AVFilterContext *ctx)
pad.name = "reference"; pad.name = "reference";
pad.config_props = NULL; pad.config_props = NULL;
if ((ret = ff_insert_inpad(ctx, 1, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
} }

View File

@ -310,13 +310,13 @@ static av_cold int decimate_init(AVFilterContext *ctx)
}; };
int ret; int ret;
if ((ret = ff_insert_inpad(ctx, INPUT_MAIN, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
if (dm->ppsrc) { if (dm->ppsrc) {
pad.name = "clean_src"; pad.name = "clean_src";
pad.config_props = NULL; pad.config_props = NULL;
if ((ret = ff_insert_inpad(ctx, INPUT_CLEANSRC, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
} }

View File

@ -352,7 +352,7 @@ static av_cold int init(AVFilterContext *ctx)
pad.type = AVMEDIA_TYPE_VIDEO; pad.type = AVMEDIA_TYPE_VIDEO;
pad.config_props = config_output; pad.config_props = config_output;
if ((ret = ff_insert_outpad(ctx, ctx->nb_outputs, &pad)) < 0) { if ((ret = ff_append_outpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -970,13 +970,13 @@ static av_cold int fieldmatch_init(AVFilterContext *ctx)
}; };
int ret; int ret;
if ((ret = ff_insert_inpad(ctx, INPUT_MAIN, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
if (fm->ppsrc) { if (fm->ppsrc) {
pad.name = "clean_src"; pad.name = "clean_src";
pad.config_props = NULL; pad.config_props = NULL;
if ((ret = ff_insert_inpad(ctx, INPUT_CLEANSRC, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
} }

View File

@ -442,7 +442,7 @@ static av_cold int init(AVFilterContext *ctx)
pad.name = "source"; pad.name = "source";
pad.config_props = config_input; pad.config_props = config_input;
if ((ret = ff_insert_inpad(ctx, 0, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
if (s->guidance == ON) { if (s->guidance == ON) {
@ -450,7 +450,7 @@ static av_cold int init(AVFilterContext *ctx)
pad.name = "guidance"; pad.name = "guidance";
pad.config_props = NULL; pad.config_props = NULL;
if ((ret = ff_insert_inpad(ctx, 1, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
} }

View File

@ -96,7 +96,7 @@ static av_cold int init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0){ if ((ret = ff_append_inpad(ctx, &pad)) < 0){
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -125,7 +125,7 @@ static av_cold int init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -790,7 +790,7 @@ static av_cold int init(AVFilterContext *ctx)
pad.name = "main"; pad.name = "main";
pad.config_props = config_input; pad.config_props = config_input;
if ((ret = ff_insert_inpad(ctx, 0, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
if (!s->inplace) { if (!s->inplace) {
@ -798,7 +798,7 @@ static av_cold int init(AVFilterContext *ctx)
pad.name = "alpha"; pad.name = "alpha";
pad.config_props = NULL; pad.config_props = NULL;
if ((ret = ff_insert_inpad(ctx, 1, &pad)) < 0) if ((ret = ff_append_inpad(ctx, &pad)) < 0)
return ret; return ret;
} }

View File

@ -287,7 +287,7 @@ static av_cold int program_opencl_init(AVFilterContext *avctx)
input.config_props = &ff_opencl_filter_config_input; input.config_props = &ff_opencl_filter_config_input;
err = ff_insert_inpad(avctx, i, &input); err = ff_append_inpad(avctx, &input);
if (err < 0) { if (err < 0) {
av_freep(&input.name); av_freep(&input.name);
return err; return err;

View File

@ -664,7 +664,7 @@ static av_cold int init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -123,7 +123,7 @@ static av_cold int init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }

View File

@ -118,7 +118,7 @@ static av_cold int init(AVFilterContext *ctx)
if (!pad.name) if (!pad.name)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) { if ((ret = ff_append_inpad(ctx, &pad)) < 0) {
av_freep(&pad.name); av_freep(&pad.name);
return ret; return ret;
} }