summaryrefslogtreecommitdiff
path: root/libavfilter/af_afreqshift.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2020-11-22 10:44:49 +0100
committerPaul B Mahol <onemda@gmail.com>2020-11-22 10:46:18 +0100
commit0066bf4d1a552744947d4534a140ef01607708a6 (patch)
tree7ec204ed64ef36c3ad68f13d040c9b8ac4a78a7e /libavfilter/af_afreqshift.c
parentd29a9b8891d30d22a27c8e0ac84f0339797cb1f9 (diff)
avfilter/af_afreqshift: add timeline and slice threading support
Diffstat (limited to 'libavfilter/af_afreqshift.c')
-rw-r--r--libavfilter/af_afreqshift.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/libavfilter/af_afreqshift.c b/libavfilter/af_afreqshift.c
index e83575813d..a61c15a97e 100644
--- a/libavfilter/af_afreqshift.c
+++ b/libavfilter/af_afreqshift.c
@@ -273,12 +273,40 @@ static int config_input(AVFilterLink *inlink)
return 0;
}
+typedef struct ThreadData {
+ AVFrame *in, *out;
+} ThreadData;
+
+static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+{
+ AFreqShift *s = ctx->priv;
+ ThreadData *td = arg;
+ AVFrame *out = td->out;
+ AVFrame *in = td->in;
+ const int start = (in->channels * jobnr) / nb_jobs;
+ const int end = (in->channels * (jobnr+1)) / nb_jobs;
+
+ for (int ch = start; ch < end; ch++) {
+ s->filter_channel(ctx, in->nb_samples,
+ in->sample_rate,
+ (const double *)in->extended_data[ch],
+ (double *)out->extended_data[ch],
+ (double *)s->i1->extended_data[ch],
+ (double *)s->o1->extended_data[ch],
+ (double *)s->i2->extended_data[ch],
+ (double *)s->o2->extended_data[ch]);
+ }
+
+ return 0;
+}
+
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
{
AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0];
AFreqShift *s = ctx->priv;
AVFrame *out;
+ ThreadData td;
if (av_frame_is_writable(in)) {
out = in;
@@ -291,16 +319,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
av_frame_copy_props(out, in);
}
- for (int ch = 0; ch < in->channels; ch++) {
- s->filter_channel(ctx, in->nb_samples,
- in->sample_rate,
- (const double *)in->extended_data[ch],
- (double *)out->extended_data[ch],
- (double *)s->i1->extended_data[ch],
- (double *)s->o1->extended_data[ch],
- (double *)s->i2->extended_data[ch],
- (double *)s->o2->extended_data[ch]);
- }
+ td.in = in; td.out = out;
+ ctx->internal->execute(ctx, filter_channels, &td, NULL, FFMIN(inlink->channels,
+ ff_filter_get_nb_threads(ctx)));
s->in_samples += in->nb_samples;
@@ -357,6 +378,8 @@ AVFilter ff_af_afreqshift = {
.inputs = inputs,
.outputs = outputs,
.process_command = ff_filter_process_command,
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
+ AVFILTER_FLAG_SLICE_THREADS,
};
static const AVOption aphaseshift_options[] = {
@@ -376,4 +399,6 @@ AVFilter ff_af_aphaseshift = {
.inputs = inputs,
.outputs = outputs,
.process_command = ff_filter_process_command,
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
+ AVFILTER_FLAG_SLICE_THREADS,
};