History

avfilter/af_asubboost: add timeline and slice threading support

Paul B Mahol committed 5 years ago

Commit ee8ecc21 parent 052a5991 file · +49 −23Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_asubboost.c+49−23
@@ -37,7 +37,7 @@ typedef struct ASubBoostContext { · 36 unmodified lines
3737 double a0, a1, a2;
3838 double b0, b1, b2;
3939
40− int write_pos;
40+ int *write_pos;
4141 int buffer_samples;
4242
4343 AVFrame *w;
@@ -105,44 +105,42 @@ static int config_input(AVFilterLink *inlink) · 61 unmodified lines
105105
106106 s->buffer = ff_get_audio_buffer(inlink, inlink->sample_rate / 10);
107107 s->w = ff_get_audio_buffer(inlink, 2);
108− if (!s->buffer || !s->w)
108+ s->write_pos = av_calloc(inlink->channels, sizeof(*s->write_pos));
109+ if (!s->buffer || !s->w || !s->write_pos)
109110 return AVERROR(ENOMEM);
110111
111112 return get_coeffs(ctx);
112113 }
113114
114−static int filter_frame(AVFilterLink *inlink, AVFrame *in)
115+typedef struct ThreadData {
116+ AVFrame *in, *out;
117+} ThreadData;
118+
119+static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
115120 {
116− AVFilterContext *ctx = inlink->dst;
117− AVFilterLink *outlink = ctx->outputs[0];
118121 ASubBoostContext *s = ctx->priv;
119− const double wet = s->wet_gain, dry = s->dry_gain, feedback = s->feedback, decay = s->decay;
122+ ThreadData *td = arg;
123+ AVFrame *out = td->out;
124+ AVFrame *in = td->in;
125+ const double wet = ctx->is_disabled ? 0. : s->wet_gain;
126+ const double dry = ctx->is_disabled ? 1. : s->dry_gain;
127+ const double feedback = s->feedback, decay = s->decay;
120128 const double b0 = s->b0;
121129 const double b1 = s->b1;
122130 const double b2 = s->b2;
123131 const double a1 = -s->a1;
124132 const double a2 = -s->a2;
125− int write_pos;
126− AVFrame *out;
133+ const int start = (in->channels * jobnr) / nb_jobs;
134+ const int end = (in->channels * (jobnr+1)) / nb_jobs;
135+ const int buffer_samples = s->buffer_samples;
127136
128− if (av_frame_is_writable(in)) {
129− out = in;
130− } else {
131− out = ff_get_audio_buffer(outlink, in->nb_samples);
132− if (!out) {
133− av_frame_free(&in);
134− return AVERROR(ENOMEM);
135− }
136− av_frame_copy_props(out, in);
137− }
138−
139− for (int ch = 0; ch < in->channels; ch++) {
137+ for (int ch = start; ch < end; ch++) {
140138 const double *src = (const double *)in->extended_data[ch];
141139 double *dst = (double *)out->extended_data[ch];
142140 double *buffer = (double *)s->buffer->extended_data[ch];
143141 double *w = (double *)s->w->extended_data[ch];
142+ int write_pos = s->write_pos[ch];
144143
145− write_pos = s->write_pos;
146144 for (int n = 0; n < in->nb_samples; n++) {
147145 double out_sample;
148146
@@ -153,12 +151,37 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 4 unmodified lines
153151 buffer[write_pos] = buffer[write_pos] * decay + out_sample * feedback;
154152 dst[n] = src[n] * dry + buffer[write_pos] * wet;
155153
156− if (++write_pos >= s->buffer_samples)
154+ if (++write_pos >= buffer_samples)
157155 write_pos = 0;
158156 }
157+
158+ s->write_pos[ch] = write_pos;
159+ }
160+
161+ return 0;
162+}
163+
164+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
165+{
166+ AVFilterContext *ctx = inlink->dst;
167+ AVFilterLink *outlink = ctx->outputs[0];
168+ ThreadData td;
169+ AVFrame *out;
170+
171+ if (av_frame_is_writable(in)) {
172+ out = in;
173+ } else {
174+ out = ff_get_audio_buffer(outlink, in->nb_samples);
175+ if (!out) {
176+ av_frame_free(&in);
177+ return AVERROR(ENOMEM);
178+ }
179+ av_frame_copy_props(out, in);
159180 }
160181
161− s->write_pos = write_pos;
182+ td.in = in; td.out = out;
183+ ctx->internal->execute(ctx, filter_channels, &td, NULL, FFMIN(inlink->channels,
184+ ff_filter_get_nb_threads(ctx)));
162185
163186 if (out != in)
164187 av_frame_free(&in);
@@ -171,6 +194,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 6 unmodified lines
171194
172195 av_frame_free(&s->buffer);
173196 av_frame_free(&s->w);
197+ av_freep(&s->write_pos);
174198 }
175199
176200 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
@@ -229,4 +253,6 @@ AVFilter ff_af_asubboost = { · 52 unmodified lines
229253 .inputs = inputs,
230254 .outputs = outputs,
231255 .process_command = process_command,
256+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL |
257+ AVFILTER_FLAG_SLICE_THREADS,
232258 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t