History

avfilter/af_astats: add slice threading support

Paul B Mahol committed 6 years ago

Commit 715da291 parent 87b4fb61 file · +29 −14Browse files

Unified · Split

libavfilter/af_astats.c+29−14
@@ -539,7 +539,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 538 unmodified lines
539539 }
540540
541541 #define UPDATE_STATS_P(type, update_func, update_float, channel_func) \
542− for (int c = 0; c < channels; c++) { \
542+ for (int c = start; c < end; c++) { \
543543 ChannelStats *p = &s->chstats[c]; \
544544 const type *src = (const type *)data[c]; \
545545 const type * const srcend = src + samples; \
@@ -551,7 +551,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 5 unmodified lines
551551 }
552552
553553 #define UPDATE_STATS_I(type, update_func, update_float, channel_func) \
554− for (int c = 0; c < channels; c++) { \
554+ for (int c = start; c < end; c++) { \
555555 ChannelStats *p = &s->chstats[c]; \
556556 const type *src = (const type *)data[0]; \
557557 const type * const srcend = src + samples * channels; \
@@ -569,21 +569,16 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata) · 11 unmodified lines
569569 UPDATE_STATS_##planar(type, update_minmax(s, p, sample), , p->nmin = p->min normalizer_suffix; p->nmax = p->max normalizer_suffix;); \
570570 }
571571
572−static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
572+static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
573573 {
574− AudioStatsContext *s = inlink->dst->priv;
575− AVDictionary **metadata = &buf->metadata;
574+ AudioStatsContext *s = ctx->priv;
575+ AVFilterLink *inlink = ctx->inputs[0];
576+ AVFrame *buf = arg;
577+ const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data;
576578 const int channels = s->nb_channels;
577579 const int samples = buf->nb_samples;
578− const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data;
579−
580− if (s->reset_count > 0) {
581− if (s->nb_frames >= s->reset_count) {
582− reset_stats(s);
583− s->nb_frames = 0;
584− }
585− s->nb_frames++;
586− }
580+ const int start = (buf->channels * jobnr) / nb_jobs;
581+ const int end = (buf->channels * (jobnr+1)) / nb_jobs;
587582
588583 switch (inlink->format) {
589584 case AV_SAMPLE_FMT_DBLP:
@@ -618,6 +613,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) · 28 unmodified lines
618613 break;
619614 }
620615
616+ return 0;
617+}
618+
619+static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
620+{
621+ AVFilterContext *ctx = inlink->dst;
622+ AudioStatsContext *s = ctx->priv;
623+ AVDictionary **metadata = &buf->metadata;
624+
625+ if (s->reset_count > 0) {
626+ if (s->nb_frames >= s->reset_count) {
627+ reset_stats(s);
628+ s->nb_frames = 0;
629+ }
630+ s->nb_frames++;
631+ }
632+
633+ ctx->internal->execute(ctx, filter_channel, buf, NULL, FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
634+
621635 if (s->metadata)
622636 set_metadata(s, metadata);
623637
@@ -812,4 +826,5 @@ AVFilter ff_af_astats = { · 188 unmodified lines
812826 .uninit = uninit,
813827 .inputs = astats_inputs,
814828 .outputs = astats_outputs,
829+ .flags = AVFILTER_FLAG_SLICE_THREADS,
815830 };

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