aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/af_astats.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2020-04-16 17:55:11 +0200
committerPaul B Mahol <onemda@gmail.com>2020-04-17 13:26:44 +0200
commit715da295017e8060ded1e16ce995049ee38dae59 (patch)
treee2238ab9ac299086bcf026a239efb66d08678a40 /libavfilter/af_astats.c
parent87b4fb65a8e89b318a7e3b686a594c3af79f91f0 (diff)
downloadffmpeg-715da295017e8060ded1e16ce995049ee38dae59.tar.gz
avfilter/af_astats: add slice threading support
Diffstat (limited to 'libavfilter/af_astats.c')
-rw-r--r--libavfilter/af_astats.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c
index 75ca4f193f..a685b00a0b 100644
--- a/libavfilter/af_astats.c
+++ b/libavfilter/af_astats.c
@@ -539,7 +539,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
}
#define UPDATE_STATS_P(type, update_func, update_float, channel_func) \
- for (int c = 0; c < channels; c++) { \
+ for (int c = start; c < end; c++) { \
ChannelStats *p = &s->chstats[c]; \
const type *src = (const type *)data[c]; \
const type * const srcend = src + samples; \
@@ -551,7 +551,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
}
#define UPDATE_STATS_I(type, update_func, update_float, channel_func) \
- for (int c = 0; c < channels; c++) { \
+ for (int c = start; c < end; c++) { \
ChannelStats *p = &s->chstats[c]; \
const type *src = (const type *)data[0]; \
const type * const srcend = src + samples * channels; \
@@ -569,21 +569,16 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
UPDATE_STATS_##planar(type, update_minmax(s, p, sample), , p->nmin = p->min normalizer_suffix; p->nmax = p->max normalizer_suffix;); \
}
-static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
+static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
- AudioStatsContext *s = inlink->dst->priv;
- AVDictionary **metadata = &buf->metadata;
+ AudioStatsContext *s = ctx->priv;
+ AVFilterLink *inlink = ctx->inputs[0];
+ AVFrame *buf = arg;
+ const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data;
const int channels = s->nb_channels;
const int samples = buf->nb_samples;
- const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data;
-
- if (s->reset_count > 0) {
- if (s->nb_frames >= s->reset_count) {
- reset_stats(s);
- s->nb_frames = 0;
- }
- s->nb_frames++;
- }
+ const int start = (buf->channels * jobnr) / nb_jobs;
+ const int end = (buf->channels * (jobnr+1)) / nb_jobs;
switch (inlink->format) {
case AV_SAMPLE_FMT_DBLP:
@@ -618,6 +613,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
break;
}
+ return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
+{
+ AVFilterContext *ctx = inlink->dst;
+ AudioStatsContext *s = ctx->priv;
+ AVDictionary **metadata = &buf->metadata;
+
+ if (s->reset_count > 0) {
+ if (s->nb_frames >= s->reset_count) {
+ reset_stats(s);
+ s->nb_frames = 0;
+ }
+ s->nb_frames++;
+ }
+
+ ctx->internal->execute(ctx, filter_channel, buf, NULL, FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+
if (s->metadata)
set_metadata(s, metadata);
@@ -812,4 +826,5 @@ AVFilter ff_af_astats = {
.uninit = uninit,
.inputs = astats_inputs,
.outputs = astats_outputs,
+ .flags = AVFILTER_FLAG_SLICE_THREADS,
};