[FFmpeg-devel] [PATCH 6/7] lavfi/vf_unsharp: use ff_filter_get_nb_jobs
rcombs
rcombs at rcombs.me
Tue Sep 20 20:50:20 EEST 2022
Improves performance by roughly 15% on M1 Max
---
libavfilter/unsharp.h | 2 +-
libavfilter/vf_unsharp.c | 20 ++++++++++----------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/libavfilter/unsharp.h b/libavfilter/unsharp.h
index 0da6f05036..7af32b0467 100644
--- a/libavfilter/unsharp.h
+++ b/libavfilter/unsharp.h
@@ -54,7 +54,7 @@ typedef struct UnsharpContext {
int nb_planes;
int bitdepth;
int bps;
- int nb_threads;
+ int nb_jobs;
int (* apply_unsharp)(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
int (* unsharp_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
} UnsharpContext;
diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c
index e88e732c9e..9632058daf 100644
--- a/libavfilter/vf_unsharp.c
+++ b/libavfilter/vf_unsharp.c
@@ -166,7 +166,7 @@ static int apply_unsharp_c(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
td.dst_stride = out->linesize[i];
td.src_stride = in->linesize[i];
ff_filter_execute(ctx, s->unsharp_slice, &td, NULL,
- FFMIN(plane_h[i], s->nb_threads));
+ FFMIN(plane_h[i], s->nb_jobs));
}
return 0;
}
@@ -229,12 +229,12 @@ static int init_filter_param(AVFilterContext *ctx, UnsharpFilterParam *fp, const
av_log(ctx, AV_LOG_VERBOSE, "effect:%s type:%s msize_x:%d msize_y:%d amount:%0.2f\n",
effect, effect_type, fp->msize_x, fp->msize_y, fp->amount / 65535.0);
- fp->sr = av_malloc_array((MAX_MATRIX_SIZE - 1) * s->nb_threads, sizeof(uint32_t));
- fp->sc = av_calloc(fp->steps_y * s->nb_threads, 2 * sizeof(*fp->sc));
+ fp->sr = av_malloc_array((MAX_MATRIX_SIZE - 1) * s->nb_jobs, sizeof(uint32_t));
+ fp->sc = av_calloc(fp->steps_y * s->nb_jobs, 2 * sizeof(*fp->sc));
if (!fp->sr || !fp->sc)
return AVERROR(ENOMEM);
- for (z = 0; z < 2 * fp->steps_y * s->nb_threads; z++)
+ for (z = 0; z < 2 * fp->steps_y * s->nb_jobs; z++)
if (!(fp->sc[z] = av_malloc_array(width + 2 * fp->steps_x,
sizeof(*(fp->sc[z])))))
return AVERROR(ENOMEM);
@@ -255,9 +255,9 @@ static int config_input(AVFilterLink *inlink)
s->bps = s->bitdepth > 8 ? 2 : 1;
s->unsharp_slice = s->bitdepth > 8 ? unsharp_slice_16 : unsharp_slice_8;
- // ensure (height / nb_threads) > 4 * steps_y,
+ // ensure (height / nb_jobs) > 4 * steps_y,
// so that we don't have too much overlap between two threads
- s->nb_threads = FFMIN(ff_filter_get_nb_threads(inlink->dst),
+ s->nb_jobs = FFMIN(ff_filter_get_nb_jobs(inlink->dst),
inlink->h / (4 * s->luma.steps_y));
ret = init_filter_param(inlink->dst, &s->luma, "luma", inlink->w);
@@ -270,12 +270,12 @@ static int config_input(AVFilterLink *inlink)
return 0;
}
-static void free_filter_param(UnsharpFilterParam *fp, int nb_threads)
+static void free_filter_param(UnsharpFilterParam *fp, int nb_jobs)
{
int z;
if (fp->sc) {
- for (z = 0; z < 2 * fp->steps_y * nb_threads; z++)
+ for (z = 0; z < 2 * fp->steps_y * nb_jobs; z++)
av_freep(&fp->sc[z]);
av_freep(&fp->sc);
}
@@ -286,8 +286,8 @@ static av_cold void uninit(AVFilterContext *ctx)
{
UnsharpContext *s = ctx->priv;
- free_filter_param(&s->luma, s->nb_threads);
- free_filter_param(&s->chroma, s->nb_threads);
+ free_filter_param(&s->luma, s->nb_jobs);
+ free_filter_param(&s->chroma, s->nb_jobs);
}
static int filter_frame(AVFilterLink *link, AVFrame *in)
--
2.37.2
More information about the ffmpeg-devel
mailing list