You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avfilter/vf_xmedian: Split portion of init unique to xmedian off
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -39,7 +39,7 @@ typedef struct XMedianContext {
|
|||||||
int planes;
|
int planes;
|
||||||
float percentile;
|
float percentile;
|
||||||
|
|
||||||
int tmedian;
|
int xmedian;
|
||||||
int radius;
|
int radius;
|
||||||
int index;
|
int index;
|
||||||
int depth;
|
int depth;
|
||||||
@@ -92,15 +92,9 @@ static int query_formats(AVFilterContext *ctx)
|
|||||||
static av_cold int init(AVFilterContext *ctx)
|
static av_cold int init(AVFilterContext *ctx)
|
||||||
{
|
{
|
||||||
XMedianContext *s = ctx->priv;
|
XMedianContext *s = ctx->priv;
|
||||||
int ret;
|
|
||||||
|
|
||||||
s->tmedian = !strcmp(ctx->filter->name, "tmedian");
|
if (!s->xmedian)
|
||||||
|
|
||||||
if (!s->tmedian) {
|
|
||||||
s->radius = s->nb_inputs / 2;
|
|
||||||
} else {
|
|
||||||
s->nb_inputs = s->radius * 2 + 1;
|
s->nb_inputs = s->radius * 2 + 1;
|
||||||
}
|
|
||||||
|
|
||||||
if (s->nb_inputs & 1)
|
if (s->nb_inputs & 1)
|
||||||
s->index = s->radius * 2.f * s->percentile;
|
s->index = s->radius * 2.f * s->percentile;
|
||||||
@@ -110,18 +104,6 @@ static av_cold int init(AVFilterContext *ctx)
|
|||||||
if (!s->frames)
|
if (!s->frames)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
for (int i = 0; i < s->nb_inputs && !s->tmedian; i++) {
|
|
||||||
AVFilterPad pad = { 0 };
|
|
||||||
|
|
||||||
pad.type = AVMEDIA_TYPE_VIDEO;
|
|
||||||
pad.name = av_asprintf("input%d", i);
|
|
||||||
if (!pad.name)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
|
|
||||||
if ((ret = ff_append_inpad_free_name(ctx, &pad)) < 0)
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +252,7 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
FFFrameSyncIn *in;
|
FFFrameSyncIn *in;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
for (int i = 1; i < s->nb_inputs && !s->tmedian; i++) {
|
for (int i = 1; i < s->nb_inputs && s->xmedian; i++) {
|
||||||
if (ctx->inputs[i]->h != height || ctx->inputs[i]->w != width) {
|
if (ctx->inputs[i]->h != height || ctx->inputs[i]->w != width) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "Input %d size (%dx%d) does not match input %d size (%dx%d).\n", i, ctx->inputs[i]->w, ctx->inputs[i]->h, 0, width, height);
|
av_log(ctx, AV_LOG_ERROR, "Input %d size (%dx%d) does not match input %d size (%dx%d).\n", i, ctx->inputs[i]->w, ctx->inputs[i]->h, 0, width, height);
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
@@ -297,7 +279,7 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h);
|
s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h);
|
||||||
s->height[0] = s->height[3] = inlink->h;
|
s->height[0] = s->height[3] = inlink->h;
|
||||||
|
|
||||||
if (s->tmedian)
|
if (!s->xmedian)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
outlink->w = width;
|
outlink->w = width;
|
||||||
@@ -333,7 +315,7 @@ static av_cold void uninit(AVFilterContext *ctx)
|
|||||||
|
|
||||||
ff_framesync_uninit(&s->fs);
|
ff_framesync_uninit(&s->fs);
|
||||||
|
|
||||||
for (int i = 0; i < s->nb_frames && s->frames && s->tmedian; i++)
|
for (int i = 0; i < s->nb_frames && s->frames && !s->xmedian; i++)
|
||||||
av_frame_free(&s->frames[i]);
|
av_frame_free(&s->frames[i]);
|
||||||
av_freep(&s->frames);
|
av_freep(&s->frames);
|
||||||
}
|
}
|
||||||
@@ -362,6 +344,31 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_XMEDIAN_FILTER
|
||||||
|
static av_cold int xmedian_init(AVFilterContext *ctx)
|
||||||
|
{
|
||||||
|
XMedianContext *s = ctx->priv;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
s->xmedian = 1;
|
||||||
|
|
||||||
|
s->radius = s->nb_inputs / 2;
|
||||||
|
|
||||||
|
for (int i = 0; i < s->nb_inputs; i++) {
|
||||||
|
AVFilterPad pad = { 0 };
|
||||||
|
|
||||||
|
pad.type = AVMEDIA_TYPE_VIDEO;
|
||||||
|
pad.name = av_asprintf("input%d", i);
|
||||||
|
if (!pad.name)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
if ((ret = ff_append_inpad_free_name(ctx, &pad)) < 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return init(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(XMedianContext, x)
|
#define OFFSET(x) offsetof(XMedianContext, x)
|
||||||
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
|
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
|
||||||
#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
|
#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
|
||||||
@@ -381,7 +388,6 @@ static const AVFilterPad outputs[] = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CONFIG_XMEDIAN_FILTER
|
|
||||||
FRAMESYNC_DEFINE_CLASS(xmedian, XMedianContext, fs);
|
FRAMESYNC_DEFINE_CLASS(xmedian, XMedianContext, fs);
|
||||||
|
|
||||||
const AVFilter ff_vf_xmedian = {
|
const AVFilter ff_vf_xmedian = {
|
||||||
@@ -392,7 +398,7 @@ const AVFilter ff_vf_xmedian = {
|
|||||||
.query_formats = query_formats,
|
.query_formats = query_formats,
|
||||||
FILTER_OUTPUTS(outputs),
|
FILTER_OUTPUTS(outputs),
|
||||||
.preinit = xmedian_framesync_preinit,
|
.preinit = xmedian_framesync_preinit,
|
||||||
.init = init,
|
.init = xmedian_init,
|
||||||
.uninit = uninit,
|
.uninit = uninit,
|
||||||
.activate = activate,
|
.activate = activate,
|
||||||
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS |
|
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS |
|
||||||
|
Reference in New Issue
Block a user