Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: rcombs <rcombs@rcombs.me>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 6/7] lavfi/vf_unsharp: use ff_filter_get_nb_jobs
Date: Tue, 20 Sep 2022 12:50:20 -0500
Message-ID: <20220920175021.60790-7-rcombs@rcombs.me> (raw)
In-Reply-To: <20220920175021.60790-1-rcombs@rcombs.me>

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-09-20 17:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 17:50 [FFmpeg-devel] [PATCH] lavfi: make job count configurable separately from thread count rcombs
2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 1/7] lavu/cpu: add av_cpu_job_count() rcombs
2022-09-22 13:49   ` Anton Khirnov
2022-09-22 14:56     ` Ronald S. Bultje
2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 2/7] sws: add jobs option, distinct from threads rcombs
2022-09-21  8:37   ` Michael Niedermayer
2022-09-21  9:04     ` Michael Niedermayer
2022-09-21 18:25   ` James Almer
2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 3/7] lavfi: add jobs args rcombs
2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 4/7] ffmpeg: add filter_jobs and filter_complex_jobs args rcombs
2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 5/7] ffplay: add filter_jobs arg rcombs
2022-09-20 17:50 ` rcombs [this message]
2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 7/7] lavfi/vf_scale: set sws job count using ff_filter_get_nb_jobs rcombs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220920175021.60790-7-rcombs@rcombs.me \
    --to=rcombs@rcombs.me \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git