aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2022-04-13 09:51:30 +0200
committerPaul B Mahol <onemda@gmail.com>2022-04-13 09:54:20 +0200
commitb74f212b7a9eb6f66584c296375407c410a0d5d1 (patch)
tree687d9c4e808add64e635d98115d970623acfe9b5
parent9d40fe20c90bf6008d83aa905ab288709035c4ca (diff)
downloadffmpeg-b74f212b7a9eb6f66584c296375407c410a0d5d1.tar.gz
avfilter/vf_xmedian: simplify changing index variable
-rw-r--r--libavfilter/vf_xmedian.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/libavfilter/vf_xmedian.c b/libavfilter/vf_xmedian.c
index 155e464ba6..96b6721d98 100644
--- a/libavfilter/vf_xmedian.c
+++ b/libavfilter/vf_xmedian.c
@@ -188,6 +188,14 @@ static int median_frames ## name(AVFilterContext *ctx, void *arg, int jobnr, int
MEDIAN_SLICE(8, uint8_t, compare8)
MEDIAN_SLICE(16, uint16_t, compare16)
+static void update_index(XMedianContext *s)
+{
+ if (s->nb_inputs & 1)
+ s->index = s->radius * 2.f * s->percentile;
+ else
+ s->index = av_clip(s->radius * 2.f * s->percentile, 1, s->nb_inputs - 1);
+}
+
static int process_frame(FFFrameSync *fs)
{
AVFilterContext *ctx = fs->parent;
@@ -198,6 +206,8 @@ static int process_frame(FFFrameSync *fs)
ThreadData td;
int i, ret;
+ update_index(s);
+
for (i = 0; i < s->nb_inputs; i++) {
if ((ret = ff_framesync_get_frame(&s->fs, i, &in[i], 0)) < 0)
return ret;
@@ -319,24 +329,6 @@ static int activate(AVFilterContext *ctx)
return ff_framesync_activate(&s->fs);
}
-static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
- char *res, int res_len, int flags)
-{
- XMedianContext *s = ctx->priv;
- int ret;
-
- ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
- if (ret < 0)
- return ret;
-
- if (s->nb_inputs & 1)
- s->index = s->radius * 2.f * s->percentile;
- else
- s->index = av_clip(s->radius * 2.f * s->percentile, 1, s->nb_inputs - 1);
-
- return 0;
-}
-
#if CONFIG_XMEDIAN_FILTER
static av_cold int xmedian_init(AVFilterContext *ctx)
{
@@ -396,7 +388,7 @@ const AVFilter ff_vf_xmedian = {
.activate = activate,
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_SLICE_THREADS |
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
- .process_command = process_command,
+ .process_command = ff_filter_process_command,
};
#endif /* CONFIG_XMEDIAN_FILTER */
@@ -410,6 +402,8 @@ static int tmedian_filter_frame(AVFilterLink *inlink, AVFrame *in)
ThreadData td;
AVFrame *out;
+ update_index(s);
+
if (s->nb_frames < s->nb_inputs) {
s->frames[s->nb_frames] = in;
s->nb_frames++;
@@ -477,7 +471,7 @@ const AVFilter ff_vf_tmedian = {
.init = init,
.uninit = uninit,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
- .process_command = process_command,
+ .process_command = ff_filter_process_command,
};
#endif /* CONFIG_TMEDIAN_FILTER */