aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2023-08-13 02:32:09 +0200
committerPaul B Mahol <onemda@gmail.com>2023-08-13 02:33:32 +0200
commit80fdf51b8f84378f430ed0da6919644060509d75 (patch)
tree6f9298d55cc219b433fd4e5a6c4a4a1f934026c5
parent37b483758459afaa919fd92a15fcf9c6cf70c9e4 (diff)
downloadffmpeg-80fdf51b8f84378f430ed0da6919644060509d75.tar.gz
avfilter/af_asdr: add fltp sample format support
-rw-r--r--libavfilter/af_asdr.c64
1 files changed, 36 insertions, 28 deletions
diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
index 5ed2e6382e..7d778b7f6b 100644
--- a/libavfilter/af_asdr.c
+++ b/libavfilter/af_asdr.c
@@ -31,36 +31,42 @@ typedef struct AudioSDRContext {
double *sum_uv;
AVFrame *cache[2];
-} AudioSDRContext;
-
-static int sdr(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
-{
- AudioSDRContext *s = ctx->priv;
- AVFrame *u = s->cache[0];
- AVFrame *v = s->cache[1];
- const int channels = u->ch_layout.nb_channels;
- const int start = (channels * jobnr) / nb_jobs;
- const int end = (channels * (jobnr+1)) / nb_jobs;
- const int nb_samples = u->nb_samples;
-
- for (int ch = start; ch < end; ch++) {
- const double *const us = (double *)u->extended_data[ch];
- const double *const vs = (double *)v->extended_data[ch];
- double sum_uv = 0.;
- double sum_u = 0.;
-
- for (int n = 0; n < nb_samples; n++) {
- sum_u += us[n] * us[n];
- sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
- }
- s->sum_uv[ch] += sum_uv;
- s->sum_u[ch] += sum_u;
- }
+ int (*filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
+} AudioSDRContext;
- return 0;
+#define SDR_FILTER(name, type) \
+static int sdr_##name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)\
+{ \
+ AudioSDRContext *s = ctx->priv; \
+ AVFrame *u = s->cache[0]; \
+ AVFrame *v = s->cache[1]; \
+ const int channels = u->ch_layout.nb_channels; \
+ const int start = (channels * jobnr) / nb_jobs; \
+ const int end = (channels * (jobnr+1)) / nb_jobs; \
+ const int nb_samples = u->nb_samples; \
+ \
+ for (int ch = start; ch < end; ch++) { \
+ const type *const us = (type *)u->extended_data[ch]; \
+ const type *const vs = (type *)v->extended_data[ch]; \
+ double sum_uv = 0.; \
+ double sum_u = 0.; \
+ \
+ for (int n = 0; n < nb_samples; n++) { \
+ sum_u += us[n] * us[n]; \
+ sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]); \
+ } \
+ \
+ s->sum_uv[ch] += sum_uv; \
+ s->sum_u[ch] += sum_u; \
+ } \
+ \
+ return 0; \
}
+SDR_FILTER(fltp, float)
+SDR_FILTER(dblp, double)
+
static int activate(AVFilterContext *ctx)
{
AudioSDRContext *s = ctx->priv;
@@ -84,7 +90,7 @@ static int activate(AVFilterContext *ctx)
}
if (!ctx->is_disabled)
- ff_filter_execute(ctx, sdr, NULL, NULL,
+ ff_filter_execute(ctx, s->filter, NULL, NULL,
FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
av_frame_free(&s->cache[1]);
@@ -120,6 +126,7 @@ static int config_output(AVFilterLink *outlink)
AudioSDRContext *s = ctx->priv;
s->channels = inlink->ch_layout.nb_channels;
+ s->filter = inlink->format == AV_SAMPLE_FMT_FLTP ? sdr_fltp : sdr_dblp;
s->sum_u = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_u));
s->sum_uv = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_uv));
@@ -173,5 +180,6 @@ const AVFilter ff_af_asdr = {
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
FILTER_INPUTS(inputs),
FILTER_OUTPUTS(outputs),
- FILTER_SINGLE_SAMPLEFMT(AV_SAMPLE_FMT_DBLP),
+ FILTER_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP,
+ AV_SAMPLE_FMT_DBLP),
};