diff --git a/Changelog b/Changelog index 79e08009df..7dcec3c06e 100644 --- a/Changelog +++ b/Changelog @@ -23,6 +23,7 @@ version : - lut2 filter - yuvtestsrc filter - vaguedenoiser filter +- added threads option per filter instance version 3.1: diff --git a/libavfilter/vf_atadenoise.c b/libavfilter/vf_atadenoise.c index 07da792a84..bf75d53d92 100644 --- a/libavfilter/vf_atadenoise.c +++ b/libavfilter/vf_atadenoise.c @@ -357,7 +357,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) ctx->internal->execute(ctx, s->filter_slice, &td, NULL, FFMIN3(s->planeheight[1], s->planeheight[2], - ctx->graph->nb_threads)); + ff_filter_get_nb_threads(ctx))); av_frame_copy_props(out, in); } else { out = av_frame_clone(in); diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c index a121267fad..2731ec81bf 100644 --- a/libavfilter/vf_blend.c +++ b/libavfilter/vf_blend.c @@ -393,7 +393,7 @@ static AVFrame *blend_frame(AVFilterContext *ctx, AVFrame *top_buf, .w = outw, .h = outh, .param = param, .plane = plane, .inlink = inlink }; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outh, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outh, ff_filter_get_nb_threads(ctx))); } if (!s->tblend) diff --git a/libavfilter/vf_bwdif.c b/libavfilter/vf_bwdif.c index 595b82586c..b691983611 100644 --- a/libavfilter/vf_bwdif.c +++ b/libavfilter/vf_bwdif.c @@ -278,7 +278,7 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, td.h = h; td.plane = i; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ff_filter_get_nb_threads(ctx))); } if (!bwdif->inter_field) { bwdif->inter_field = 1; diff --git a/libavfilter/vf_chromakey.c b/libavfilter/vf_chromakey.c index 3309748013..88414783bc 100644 --- a/libavfilter/vf_chromakey.c +++ b/libavfilter/vf_chromakey.c @@ -108,7 +108,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) AVFilterContext *avctx = link->dst; int res; - if (res = avctx->internal->execute(avctx, do_chromakey_slice, frame, NULL, FFMIN(frame->height, avctx->graph->nb_threads))) + if (res = avctx->internal->execute(avctx, do_chromakey_slice, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(avctx)))) return res; return ff_filter_frame(avctx->outputs[0], frame); diff --git a/libavfilter/vf_colorkey.c b/libavfilter/vf_colorkey.c index 2f670d97e7..3d65e59d42 100644 --- a/libavfilter/vf_colorkey.c +++ b/libavfilter/vf_colorkey.c @@ -85,7 +85,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) if (res = av_frame_make_writable(frame)) return res; - if (res = avctx->internal->execute(avctx, do_colorkey_slice, frame, NULL, FFMIN(frame->height, avctx->graph->nb_threads))) + if (res = avctx->internal->execute(avctx, do_colorkey_slice, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(avctx)))) return res; return ff_filter_frame(avctx->outputs[0], frame); diff --git a/libavfilter/vf_colormatrix.c b/libavfilter/vf_colormatrix.c index 15fb680e4a..d237baa7b9 100644 --- a/libavfilter/vf_colormatrix.c +++ b/libavfilter/vf_colormatrix.c @@ -474,16 +474,16 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) if (in->format == AV_PIX_FMT_YUV444P) ctx->internal->execute(ctx, process_slice_yuv444p, &td, NULL, - FFMIN(in->height, ctx->graph->nb_threads)); + FFMIN(in->height, ff_filter_get_nb_threads(ctx))); else if (in->format == AV_PIX_FMT_YUV422P) ctx->internal->execute(ctx, process_slice_yuv422p, &td, NULL, - FFMIN(in->height, ctx->graph->nb_threads)); + FFMIN(in->height, ff_filter_get_nb_threads(ctx))); else if (in->format == AV_PIX_FMT_YUV420P) ctx->internal->execute(ctx, process_slice_yuv420p, &td, NULL, - FFMIN(in->height / 2, ctx->graph->nb_threads)); + FFMIN(in->height / 2, ff_filter_get_nb_threads(ctx))); else ctx->internal->execute(ctx, process_slice_uyvy422, &td, NULL, - FFMIN(in->height, ctx->graph->nb_threads)); + FFMIN(in->height, ff_filter_get_nb_threads(ctx))); av_frame_free(&in); return ff_filter_frame(outlink, out); diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c index 37e77d1295..e4022f89b8 100644 --- a/libavfilter/vf_colorspace.c +++ b/libavfilter/vf_colorspace.c @@ -947,7 +947,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) return res; } else { ctx->internal->execute(ctx, convert, &td, NULL, - FFMIN((in->height + 1) >> 1, ctx->graph->nb_threads)); + FFMIN((in->height + 1) >> 1, ff_filter_get_nb_threads(ctx))); } av_frame_free(&in); diff --git a/libavfilter/vf_curves.c b/libavfilter/vf_curves.c index fef9a0efbb..69ec1084bb 100644 --- a/libavfilter/vf_curves.c +++ b/libavfilter/vf_curves.c @@ -647,7 +647,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) td.in = in; td.out = out; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outlink->h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); if (out != in) av_frame_free(&in); diff --git a/libavfilter/vf_datascope.c b/libavfilter/vf_datascope.c index 3c82a0e34e..76134c2780 100644 --- a/libavfilter/vf_datascope.c +++ b/libavfilter/vf_datascope.c @@ -328,7 +328,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } td.in = in; td.out = out, td.yoff = xmaxlen, td.xoff = ymaxlen; - ctx->internal->execute(ctx, s->filter, &td, NULL, FFMIN(ctx->graph->nb_threads, FFMAX(outlink->w / 20, 1))); + ctx->internal->execute(ctx, s->filter, &td, NULL, FFMIN(ff_filter_get_nb_threads(ctx), FFMAX(outlink->w / 20, 1))); av_frame_free(&in); return ff_filter_frame(outlink, out); diff --git a/libavfilter/vf_dctdnoiz.c b/libavfilter/vf_dctdnoiz.c index 6957f19aea..62763bf349 100644 --- a/libavfilter/vf_dctdnoiz.c +++ b/libavfilter/vf_dctdnoiz.c @@ -507,9 +507,9 @@ static int config_input(AVFilterLink *inlink) inlink->h - s->pr_height); max_slice_h = s->pr_height / ((s->bsize - 1) * 2); - s->nb_threads = FFMIN3(MAX_THREADS, ctx->graph->nb_threads, max_slice_h); + s->nb_threads = FFMIN3(MAX_THREADS, ff_filter_get_nb_threads(ctx), max_slice_h); av_log(ctx, AV_LOG_DEBUG, "threads: [max=%d hmax=%d user=%d] => %d\n", - MAX_THREADS, max_slice_h, ctx->graph->nb_threads, s->nb_threads); + MAX_THREADS, max_slice_h, ff_filter_get_nb_threads(ctx), s->nb_threads); s->p_linesize = linesize = FFALIGN(s->pr_width, 32); for (i = 0; i < 2; i++) { diff --git a/libavfilter/vf_deband.c b/libavfilter/vf_deband.c index 01728b191f..3a1cfb8fbf 100644 --- a/libavfilter/vf_deband.c +++ b/libavfilter/vf_deband.c @@ -267,7 +267,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) td.in = in; td.out = out; ctx->internal->execute(ctx, s->deband, &td, NULL, FFMIN3(s->planeheight[1], s->planeheight[2], - ctx->graph->nb_threads)); + ff_filter_get_nb_threads(ctx))); av_frame_free(&in); return ff_filter_frame(outlink, out); diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index cf77d8723c..0496645c97 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -347,19 +347,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) if (s->factor < UINT16_MAX) { if (s->alpha) { ctx->internal->execute(ctx, filter_slice_alpha, frame, NULL, - FFMIN(frame->height, ctx->graph->nb_threads)); + FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); } else if (s->is_packed_rgb && !s->black_fade) { ctx->internal->execute(ctx, filter_slice_rgb, frame, NULL, - FFMIN(frame->height, ctx->graph->nb_threads)); + FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); } else { /* luma, or rgb plane in case of black */ ctx->internal->execute(ctx, filter_slice_luma, frame, NULL, - FFMIN(frame->height, ctx->graph->nb_threads)); + FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); if (frame->data[1] && frame->data[2]) { /* chroma planes */ ctx->internal->execute(ctx, filter_slice_chroma, frame, NULL, - FFMIN(frame->height, ctx->graph->nb_threads)); + FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); } } } diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c index 3e502e3261..cf20c193f7 100644 --- a/libavfilter/vf_hflip.c +++ b/libavfilter/vf_hflip.c @@ -174,7 +174,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) memcpy(out->data[1], in->data[1], AVPALETTE_SIZE); td.in = in, td.out = out; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outlink->h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); av_frame_free(&in); return ff_filter_frame(outlink, out); diff --git a/libavfilter/vf_hqx.c b/libavfilter/vf_hqx.c index d1e360f95a..5f63b2a3f9 100644 --- a/libavfilter/vf_hqx.c +++ b/libavfilter/vf_hqx.c @@ -502,7 +502,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) td.in = in; td.out = out; td.rgbtoyuv = hqx->rgbtoyuv; - ctx->internal->execute(ctx, hqx->func, &td, NULL, FFMIN(inlink->h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, hqx->func, &td, NULL, FFMIN(inlink->h, ff_filter_get_nb_threads(ctx))); av_frame_free(&in); return ff_filter_frame(outlink, out); diff --git a/libavfilter/vf_lenscorrection.c b/libavfilter/vf_lenscorrection.c index 9db483dd36..239fe195bd 100644 --- a/libavfilter/vf_lenscorrection.c +++ b/libavfilter/vf_lenscorrection.c @@ -193,7 +193,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } td.correction = rect->correction[plane]; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ff_filter_get_nb_threads(ctx))); } av_frame_free(&in); diff --git a/libavfilter/vf_lut3d.c b/libavfilter/vf_lut3d.c index 2b8e0272b0..b136cda21d 100644 --- a/libavfilter/vf_lut3d.c +++ b/libavfilter/vf_lut3d.c @@ -531,7 +531,7 @@ static AVFrame *apply_lut(AVFilterLink *inlink, AVFrame *in) td.in = in; td.out = out; - ctx->internal->execute(ctx, lut3d->interp, &td, NULL, FFMIN(outlink->h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, lut3d->interp, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); if (out != in) av_frame_free(&in); diff --git a/libavfilter/vf_noise.c b/libavfilter/vf_noise.c index fa3863ed9d..abdf04708b 100644 --- a/libavfilter/vf_noise.c +++ b/libavfilter/vf_noise.c @@ -272,7 +272,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) } td.in = inpicref; td.out = out; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(n->height[0], ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(n->height[0], ff_filter_get_nb_threads(ctx))); emms_c(); if (inpicref != out) diff --git a/libavfilter/vf_perspective.c b/libavfilter/vf_perspective.c index 2b5afcea35..287db68845 100644 --- a/libavfilter/vf_perspective.c +++ b/libavfilter/vf_perspective.c @@ -478,7 +478,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) .h = s->height[plane], .hsub = hsub, .vsub = vsub }; - ctx->internal->execute(ctx, s->perspective, &td, NULL, FFMIN(td.h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, s->perspective, &td, NULL, FFMIN(td.h, ff_filter_get_nb_threads(ctx))); } av_frame_free(&frame); diff --git a/libavfilter/vf_removegrain.c b/libavfilter/vf_removegrain.c index 8ef097403a..bc45076baa 100644 --- a/libavfilter/vf_removegrain.c +++ b/libavfilter/vf_removegrain.c @@ -619,7 +619,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) td.in = in; td.out = out; td.plane = i; ctx->internal->execute(ctx, filter_slice, &td, NULL, - FFMIN(s->planeheight[i], ctx->graph->nb_threads)); + FFMIN(s->planeheight[i], ff_filter_get_nb_threads(ctx))); src = in->data[i] + (s->planeheight[i] - 1) * in->linesize[i]; dst = out->data[i] + (s->planeheight[i] - 1) * out->linesize[i]; diff --git a/libavfilter/vf_rotate.c b/libavfilter/vf_rotate.c index b37685a6c6..42e725aca9 100644 --- a/libavfilter/vf_rotate.c +++ b/libavfilter/vf_rotate.c @@ -553,7 +553,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) .plane = plane, .c = c, .s = s }; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outh, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outh, ff_filter_get_nb_threads(ctx))); } av_frame_free(&in); diff --git a/libavfilter/vf_selectivecolor.c b/libavfilter/vf_selectivecolor.c index 33716ec5f5..a5cb533bc0 100644 --- a/libavfilter/vf_selectivecolor.c +++ b/libavfilter/vf_selectivecolor.c @@ -471,7 +471,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) td.in = in; td.out = out; ctx->internal->execute(ctx, funcs[s->is_16bit][direct][s->correction_method], - &td, NULL, FFMIN(inlink->h, ctx->graph->nb_threads)); + &td, NULL, FFMIN(inlink->h, ff_filter_get_nb_threads(ctx))); if (!direct) av_frame_free(&in); diff --git a/libavfilter/vf_signalstats.c b/libavfilter/vf_signalstats.c index 6796af8079..22a1db196f 100644 --- a/libavfilter/vf_signalstats.c +++ b/libavfilter/vf_signalstats.c @@ -185,7 +185,7 @@ static int config_props(AVFilterLink *outlink) s->fs = inlink->w * inlink->h; s->cfs = s->chromaw * s->chromah; - s->nb_jobs = FFMAX(1, FFMIN(inlink->h, ctx->graph->nb_threads)); + s->nb_jobs = FFMAX(1, FFMIN(inlink->h, ff_filter_get_nb_threads(ctx))); s->jobs_rets = av_malloc_array(s->nb_jobs, sizeof(*s->jobs_rets)); if (!s->jobs_rets) return AVERROR(ENOMEM); @@ -602,7 +602,7 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in) } ctx->internal->execute(ctx, compute_sat_hue_metrics8, &td_huesat, - NULL, FFMIN(s->chromah, ctx->graph->nb_threads)); + NULL, FFMIN(s->chromah, ff_filter_get_nb_threads(ctx))); // Calculate luma histogram and difference with previous frame or field. for (j = 0; j < link->h; j++) { @@ -820,7 +820,7 @@ static int filter_frame16(AVFilterLink *link, AVFrame *in) } ctx->internal->execute(ctx, compute_sat_hue_metrics16, &td_huesat, - NULL, FFMIN(s->chromah, ctx->graph->nb_threads)); + NULL, FFMIN(s->chromah, ff_filter_get_nb_threads(ctx))); // Calculate luma histogram and difference with previous frame or field. memset(s->histy, 0, (1 << s->depth) * sizeof(*s->histy)); diff --git a/libavfilter/vf_stereo3d.c b/libavfilter/vf_stereo3d.c index 2036c9432c..3e23890208 100644 --- a/libavfilter/vf_stereo3d.c +++ b/libavfilter/vf_stereo3d.c @@ -935,7 +935,7 @@ copy: td.ileft = ileft; td.iright = iright; td.out = out; ctx->internal->execute(ctx, filter_slice, &td, NULL, - FFMIN(s->out.height, ctx->graph->nb_threads)); + FFMIN(s->out.height, ff_filter_get_nb_threads(ctx))); } break; } diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c index 9555ff20c8..28226c3cfd 100644 --- a/libavfilter/vf_transpose.c +++ b/libavfilter/vf_transpose.c @@ -250,7 +250,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } td.in = in, td.out = out; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outlink->h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); av_frame_free(&in); return ff_filter_frame(outlink, out); } diff --git a/libavfilter/vf_w3fdif.c b/libavfilter/vf_w3fdif.c index e6f6628abe..cde17d246a 100644 --- a/libavfilter/vf_w3fdif.c +++ b/libavfilter/vf_w3fdif.c @@ -170,7 +170,7 @@ static int config_input(AVFilterLink *inlink) s->planeheight[0] = s->planeheight[3] = inlink->h; s->nb_planes = av_pix_fmt_count_planes(inlink->format); - s->nb_threads = ctx->graph->nb_threads; + s->nb_threads = ff_filter_get_nb_threads(ctx); s->work_line = av_calloc(s->nb_threads, sizeof(*s->work_line)); if (!s->work_line) return AVERROR(ENOMEM); diff --git a/libavfilter/vf_xbr.c b/libavfilter/vf_xbr.c index c92e9a8230..9893e0cc80 100644 --- a/libavfilter/vf_xbr.c +++ b/libavfilter/vf_xbr.c @@ -367,7 +367,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) td.in = in; td.out = out; td.rgbtoyuv = s->rgbtoyuv; - ctx->internal->execute(ctx, s->func, &td, NULL, FFMIN(inlink->h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, s->func, &td, NULL, FFMIN(inlink->h, ff_filter_get_nb_threads(ctx))); out->width = outlink->w; out->height = outlink->h; diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 8e6522cf3f..694ac44999 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -242,7 +242,7 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, td.h = h; td.plane = i; - ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ctx->graph->nb_threads)); + ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ff_filter_get_nb_threads(ctx))); } emms_c();