Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -31,36 +31,42 @@ typedef struct AudioSDRContext { · 30 unmodified lines | |||
| 31 | double *sum_uv; | 31 | double *sum_uv; |
| 32 | 32 | ||
| 33 | AVFrame *cache[2]; | 33 | AVFrame *cache[2]; |
| 34 | } AudioSDRContext; | ||
| 35 | |||
| 36 | static int sdr(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | ||
| 37 | { | ||
| 38 | AudioSDRContext *s = ctx->priv; | ||
| 39 | AVFrame *u = s->cache[0]; | ||
| 40 | AVFrame *v = s->cache[1]; | ||
| 41 | const int channels = u->ch_layout.nb_channels; | ||
| 42 | const int start = (channels * jobnr) / nb_jobs; | ||
| 43 | const int end = (channels * (jobnr+1)) / nb_jobs; | ||
| 44 | const int nb_samples = u->nb_samples; | ||
| 45 | |||
| 46 | for (int ch = start; ch < end; ch++) { | ||
| 47 | const double *const us = (double *)u->extended_data[ch]; | ||
| 48 | const double *const vs = (double *)v->extended_data[ch]; | ||
| 49 | double sum_uv = 0.; | ||
| 50 | double sum_u = 0.; | ||
| 51 | |||
| 52 | for (int n = 0; n < nb_samples; n++) { | ||
| 53 | sum_u += us[n] * us[n]; | ||
| 54 | sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]); | ||
| 55 | } | ||
| 56 | 34 | ||
| 57 | s->sum_uv[ch] += sum_uv; | 35 | int (*filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); |
| 58 | s->sum_u[ch] += sum_u; | 36 | } AudioSDRContext; |
| 59 | } | ||
| 60 | 37 | ||
| 61 | return 0; | 38 | #define SDR_FILTER(name, type) \ |
| 39 | static int sdr_##name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)\ | ||
| 40 | { \ | ||
| 41 | AudioSDRContext *s = ctx->priv; \ | ||
| 42 | AVFrame *u = s->cache[0]; \ | ||
| 43 | AVFrame *v = s->cache[1]; \ | ||
| 44 | const int channels = u->ch_layout.nb_channels; \ | ||
| 45 | const int start = (channels * jobnr) / nb_jobs; \ | ||
| 46 | const int end = (channels * (jobnr+1)) / nb_jobs; \ | ||
| 47 | const int nb_samples = u->nb_samples; \ | ||
| 48 | \ | ||
| 49 | for (int ch = start; ch < end; ch++) { \ | ||
| 50 | const type *const us = (type *)u->extended_data[ch]; \ | ||
| 51 | const type *const vs = (type *)v->extended_data[ch]; \ | ||
| 52 | double sum_uv = 0.; \ | ||
| 53 | double sum_u = 0.; \ | ||
| 54 | \ | ||
| 55 | for (int n = 0; n < nb_samples; n++) { \ | ||
| 56 | sum_u += us[n] * us[n]; \ | ||
| 57 | sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]); \ | ||
| 58 | } \ | ||
| 59 | \ | ||
| 60 | s->sum_uv[ch] += sum_uv; \ | ||
| 61 | s->sum_u[ch] += sum_u; \ | ||
| 62 | } \ | ||
| 63 | \ | ||
| 64 | return 0; \ | ||
| 62 | } | 65 | } |
| 63 | 66 | ||
| 67 | SDR_FILTER(fltp, float) | ||
| 68 | SDR_FILTER(dblp, double) | ||
| 69 | |||
| 64 | static int activate(AVFilterContext *ctx) | 70 | static int activate(AVFilterContext *ctx) |
| 65 | { | 71 | { |
| 66 | AudioSDRContext *s = ctx->priv; | 72 | AudioSDRContext *s = ctx->priv; |
| @@ -84,7 +90,7 @@ static int activate(AVFilterContext *ctx) · 17 unmodified lines | |||
| 84 | } | 90 | } |
| 85 | 91 | ||
| 86 | if (!ctx->is_disabled) | 92 | if (!ctx->is_disabled) |
| 87 | ff_filter_execute(ctx, sdr, NULL, NULL, | 93 | ff_filter_execute(ctx, s->filter, NULL, NULL, |
| 88 | FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx))); | 94 | FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx))); |
| 89 | 95 | ||
| 90 | av_frame_free(&s->cache[1]); | 96 | av_frame_free(&s->cache[1]); |
| @@ -120,6 +126,7 @@ static int config_output(AVFilterLink *outlink) · 29 unmodified lines | |||
| 120 | AudioSDRContext *s = ctx->priv; | 126 | AudioSDRContext *s = ctx->priv; |
| 121 | 127 | ||
| 122 | s->channels = inlink->ch_layout.nb_channels; | 128 | s->channels = inlink->ch_layout.nb_channels; |
| 129 | s->filter = inlink->format == AV_SAMPLE_FMT_FLTP ? sdr_fltp : sdr_dblp; | ||
| 123 | 130 | ||
| 124 | s->sum_u = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_u)); | 131 | s->sum_u = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_u)); |
| 125 | s->sum_uv = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_uv)); | 132 | s->sum_uv = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_uv)); |
| @@ -173,5 +180,6 @@ const AVFilter ff_af_asdr = { · 47 unmodified lines | |||
| 173 | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, | 180 | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, |
| 174 | FILTER_INPUTS(inputs), | 181 | FILTER_INPUTS(inputs), |
| 175 | FILTER_OUTPUTS(outputs), | 182 | FILTER_OUTPUTS(outputs), |
| 176 | FILTER_SINGLE_SAMPLEFMT(AV_SAMPLE_FMT_DBLP), | 183 | FILTER_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP, |
| 184 | AV_SAMPLE_FMT_DBLP), | ||
| 177 | }; | 185 | }; |