[FFmpeg-cvslog] avfilter/af_asoftclip: add slice threading support
Paul B Mahol
git at videolan.org
Sun Feb 9 11:55:10 EET 2020
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Feb 9 10:47:43 2020 +0100| [d8429981832109746130d6614d73a40680e22eab] | committer: Paul B Mahol
avfilter/af_asoftclip: add slice threading support
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d8429981832109746130d6614d73a40680e22eab
---
libavfilter/af_asoftclip.c | 48 +++++++++++++++++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 9 deletions(-)
diff --git a/libavfilter/af_asoftclip.c b/libavfilter/af_asoftclip.c
index a42b56dff4..ad3846a7fb 100644
--- a/libavfilter/af_asoftclip.c
+++ b/libavfilter/af_asoftclip.c
@@ -42,7 +42,7 @@ typedef struct ASoftClipContext {
double param;
void (*filter)(struct ASoftClipContext *s, void **dst, const void **src,
- int nb_samples, int channels);
+ int nb_samples, int channels, int start, int end);
} ASoftClipContext;
#define OFFSET(x) offsetof(ASoftClipContext, x)
@@ -97,11 +97,12 @@ static int query_formats(AVFilterContext *ctx)
static void filter_flt(ASoftClipContext *s,
void **dptr, const void **sptr,
- int nb_samples, int channels)
+ int nb_samples, int channels,
+ int start, int end)
{
float param = s->param;
- for (int c = 0; c < channels; c++) {
+ for (int c = start; c < end; c++) {
const float *src = sptr[c];
float *dst = dptr[c];
@@ -153,11 +154,12 @@ static void filter_flt(ASoftClipContext *s,
static void filter_dbl(ASoftClipContext *s,
void **dptr, const void **sptr,
- int nb_samples, int channels)
+ int nb_samples, int channels,
+ int start, int end)
{
double param = s->param;
- for (int c = 0; c < channels; c++) {
+ for (int c = start; c < end; c++) {
const double *src = sptr[c];
double *dst = dptr[c];
@@ -222,12 +224,35 @@ static int config_input(AVFilterLink *inlink)
return 0;
}
+typedef struct ThreadData {
+ AVFrame *in, *out;
+ int nb_samples;
+ int channels;
+} ThreadData;
+
+static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+{
+ ASoftClipContext *s = ctx->priv;
+ ThreadData *td = arg;
+ AVFrame *out = td->out;
+ AVFrame *in = td->in;
+ const int channels = td->channels;
+ const int nb_samples = td->nb_samples;
+ const int start = (channels * jobnr) / nb_jobs;
+ const int end = (channels * (jobnr+1)) / nb_jobs;
+
+ s->filter(s, (void **)out->extended_data, (const void **)in->extended_data,
+ nb_samples, channels, start, end);
+
+ return 0;
+}
+
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
{
AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0];
- ASoftClipContext *s = ctx->priv;
int nb_samples, channels;
+ ThreadData td;
AVFrame *out;
if (av_frame_is_writable(in)) {
@@ -249,8 +274,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
channels = 1;
}
- s->filter(s, (void **)out->extended_data, (const void **)in->extended_data,
- nb_samples, channels);
+ td.in = in;
+ td.out = out;
+ td.nb_samples = nb_samples;
+ td.channels = channels;
+ ctx->internal->execute(ctx, filter_channels, &td, NULL, FFMIN(channels,
+ ff_filter_get_nb_threads(ctx)));
if (out != in)
av_frame_free(&in);
@@ -284,5 +313,6 @@ AVFilter ff_af_asoftclip = {
.priv_class = &asoftclip_class,
.inputs = inputs,
.outputs = outputs,
- .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
+ AVFILTER_FLAG_SLICE_THREADS,
};
More information about the ffmpeg-cvslog
mailing list