Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -37,7 +37,7 @@ typedef struct ASubBoostContext { · 36 unmodified lines | |||
| 37 | double a0, a1, a2; | 37 | double a0, a1, a2; |
| 38 | double b0, b1, b2; | 38 | double b0, b1, b2; |
| 39 | 39 | ||
| 40 | int write_pos; | 40 | int *write_pos; |
| 41 | int buffer_samples; | 41 | int buffer_samples; |
| 42 | 42 | ||
| 43 | AVFrame *w; | 43 | AVFrame *w; |
| @@ -105,44 +105,42 @@ static int config_input(AVFilterLink *inlink) · 61 unmodified lines | |||
| 105 | 105 | ||
| 106 | s->buffer = ff_get_audio_buffer(inlink, inlink->sample_rate / 10); | 106 | s->buffer = ff_get_audio_buffer(inlink, inlink->sample_rate / 10); |
| 107 | s->w = ff_get_audio_buffer(inlink, 2); | 107 | 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) | ||
| 109 | return AVERROR(ENOMEM); | 110 | return AVERROR(ENOMEM); |
| 110 | 111 | ||
| 111 | return get_coeffs(ctx); | 112 | return get_coeffs(ctx); |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 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) | ||
| 115 | { | 120 | { |
| 116 | AVFilterContext *ctx = inlink->dst; | ||
| 117 | AVFilterLink *outlink = ctx->outputs[0]; | ||
| 118 | ASubBoostContext *s = ctx->priv; | 121 | 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; | ||
| 120 | const double b0 = s->b0; | 128 | const double b0 = s->b0; |
| 121 | const double b1 = s->b1; | 129 | const double b1 = s->b1; |
| 122 | const double b2 = s->b2; | 130 | const double b2 = s->b2; |
| 123 | const double a1 = -s->a1; | 131 | const double a1 = -s->a1; |
| 124 | const double a2 = -s->a2; | 132 | const double a2 = -s->a2; |
| 125 | int write_pos; | 133 | const int start = (in->channels * jobnr) / nb_jobs; |
| 126 | AVFrame *out; | 134 | const int end = (in->channels * (jobnr+1)) / nb_jobs; |
| 135 | const int buffer_samples = s->buffer_samples; | ||
| 127 | 136 | ||
| 128 | if (av_frame_is_writable(in)) { | 137 | for (int ch = start; ch < end; ch++) { |
| 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++) { | ||
| 140 | const double *src = (const double *)in->extended_data[ch]; | 138 | const double *src = (const double *)in->extended_data[ch]; |
| 141 | double *dst = (double *)out->extended_data[ch]; | 139 | double *dst = (double *)out->extended_data[ch]; |
| 142 | double *buffer = (double *)s->buffer->extended_data[ch]; | 140 | double *buffer = (double *)s->buffer->extended_data[ch]; |
| 143 | double *w = (double *)s->w->extended_data[ch]; | 141 | double *w = (double *)s->w->extended_data[ch]; |
| 142 | int write_pos = s->write_pos[ch]; | ||
| 144 | 143 | ||
| 145 | write_pos = s->write_pos; | ||
| 146 | for (int n = 0; n < in->nb_samples; n++) { | 144 | for (int n = 0; n < in->nb_samples; n++) { |
| 147 | double out_sample; | 145 | double out_sample; |
| 148 | 146 | ||
| @@ -153,12 +151,37 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 4 unmodified lines | |||
| 153 | buffer[write_pos] = buffer[write_pos] * decay + out_sample * feedback; | 151 | buffer[write_pos] = buffer[write_pos] * decay + out_sample * feedback; |
| 154 | dst[n] = src[n] * dry + buffer[write_pos] * wet; | 152 | dst[n] = src[n] * dry + buffer[write_pos] * wet; |
| 155 | 153 | ||
| 156 | if (++write_pos >= s->buffer_samples) | 154 | if (++write_pos >= buffer_samples) |
| 157 | write_pos = 0; | 155 | write_pos = 0; |
| 158 | } | 156 | } |
| 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); | ||
| 159 | } | 180 | } |
| 160 | 181 | ||
| 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))); | ||
| 162 | 185 | ||
| 163 | if (out != in) | 186 | if (out != in) |
| 164 | av_frame_free(&in); | 187 | av_frame_free(&in); |
| @@ -171,6 +194,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 6 unmodified lines | |||
| 171 | 194 | ||
| 172 | av_frame_free(&s->buffer); | 195 | av_frame_free(&s->buffer); |
| 173 | av_frame_free(&s->w); | 196 | av_frame_free(&s->w); |
| 197 | av_freep(&s->write_pos); | ||
| 174 | } | 198 | } |
| 175 | 199 | ||
| 176 | static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, | 200 | static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, |
| @@ -229,4 +253,6 @@ AVFilter ff_af_asubboost = { · 52 unmodified lines | |||
| 229 | .inputs = inputs, | 253 | .inputs = inputs, |
| 230 | .outputs = outputs, | 254 | .outputs = outputs, |
| 231 | .process_command = process_command, | 255 | .process_command = process_command, |
| 256 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | | ||
| 257 | AVFILTER_FLAG_SLICE_THREADS, | ||
| 232 | }; | 258 | }; |