History

avfilter/af_dynaudnorm: switch to activate

Paul B Mahol committed 7 years ago

Commit d7fead81 parent a40bcb51 file · +59 −17Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_dynaudnorm.c+59−17
@@ -34,6 +34,7 @@ · 33 unmodified lines
3434
3535 #include "audio.h"
3636 #include "avfilter.h"
37+#include "filters.h"
3738 #include "internal.h"
3839
3940 typedef struct cqueue {
@@ -67,6 +68,8 @@ typedef struct DynamicAudioNormalizerContext { · 27 unmodified lines
6768
6869 int channels;
6970 int delay;
71+ int eof;
72+ int64_t pts;
7073
7174 cqueue **gain_history_original;
7275 cqueue **gain_history_minimum;
@@ -292,10 +295,7 @@ static int config_input(AVFilterLink *inlink) · 219 unmodified lines
292295
293296 uninit(ctx);
294297
295− s->frame_len =
296− inlink->min_samples =
297− inlink->max_samples =
298− inlink->partial_buf_size = frame_size(inlink->sample_rate, s->frame_len_msec);
298+ s->frame_len = frame_size(inlink->sample_rate, s->frame_len_msec);
299299 av_log(ctx, AV_LOG_DEBUG, "frame len %d\n", s->frame_len);
300300
301301 s->fade_factors[0] = av_malloc_array(s->frame_len, sizeof(*s->fade_factors[0]));
@@ -661,7 +661,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 359 unmodified lines
661661 AVFilterContext *ctx = inlink->dst;
662662 DynamicAudioNormalizerContext *s = ctx->priv;
663663 AVFilterLink *outlink = inlink->dst->outputs[0];
664− int ret = 0;
664+ int ret = 1;
665665
666666 if (!cqueue_empty(s->gain_history_smoothed[0])) {
667667 AVFrame *out = ff_bufqueue_get(&s->queue);
@@ -670,6 +670,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 2 unmodified lines
670670 ret = ff_filter_frame(outlink, out);
671671 }
672672
673+ av_frame_make_writable(in);
673674 analyze_frame(s, in);
674675 ff_bufqueue_add(ctx, &s->queue, in);
675676
@@ -701,34 +702,75 @@ static int flush_buffer(DynamicAudioNormalizerContext *s, AVFilterLink *inlink, · 25 unmodified lines
701702 return filter_frame(inlink, out);
702703 }
703704
704−static int request_frame(AVFilterLink *outlink)
705+static int flush(AVFilterLink *outlink)
705706 {
706707 AVFilterContext *ctx = outlink->src;
707708 DynamicAudioNormalizerContext *s = ctx->priv;
708709 int ret = 0;
709710
710− ret = ff_request_frame(ctx->inputs[0]);
711+ if (!cqueue_empty(s->gain_history_smoothed[0])) {
712+ ret = flush_buffer(s, ctx->inputs[0], outlink);
713+ } else if (s->queue.available) {
714+ AVFrame *out = ff_bufqueue_get(&s->queue);
715+
716+ s->pts = out->pts;
717+ ret = ff_filter_frame(outlink, out);
718+ }
711719
712− if (ret == AVERROR_EOF && !ctx->is_disabled && s->delay) {
713− if (!cqueue_empty(s->gain_history_smoothed[0])) {
714− ret = flush_buffer(s, ctx->inputs[0], outlink);
715− } else if (s->queue.available) {
716− AVFrame *out = ff_bufqueue_get(&s->queue);
720+ return ret;
721+}
717722
718− ret = ff_filter_frame(outlink, out);
723+static int activate(AVFilterContext *ctx)
724+{
725+ AVFilterLink *inlink = ctx->inputs[0];
726+ AVFilterLink *outlink = ctx->outputs[0];
727+ DynamicAudioNormalizerContext *s = ctx->priv;
728+ AVFrame *in = NULL;
729+ int ret = 0, status;
730+ int64_t pts;
731+
732+ FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
733+
734+ if (!s->eof) {
735+ ret = ff_inlink_consume_samples(inlink, s->frame_len, s->frame_len, &in);
736+ if (ret < 0)
737+ return ret;
738+ if (ret > 0) {
739+ ret = filter_frame(inlink, in);
740+ if (ret <= 0)
741+ return ret;
742+ }
743+
744+ if (ff_inlink_queued_samples(inlink) >= s->frame_len) {
745+ ff_filter_set_ready(ctx, 10);
746+ return 0;
719747 }
720748 }
721749
722− return ret;
750+ if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
751+ if (status == AVERROR_EOF)
752+ s->eof = 1;
753+ }
754+
755+ if (s->eof && s->delay > 0)
756+ return flush(outlink);
757+
758+ if (s->eof && s->delay <= 0) {
759+ ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
760+ return 0;
761+ }
762+
763+ if (!s->eof)
764+ FF_FILTER_FORWARD_WANTED(outlink, inlink);
765+
766+ return FFERROR_NOT_READY;
723767 }
724768
725769 static const AVFilterPad avfilter_af_dynaudnorm_inputs[] = {
726770 {
727771 .name = "default",
728772 .type = AVMEDIA_TYPE_AUDIO,
729− .filter_frame = filter_frame,
730773 .config_props = config_input,
731− .needs_writable = 1,
732774 },
733775 { NULL }
734776 };
@@ -737,7 +779,6 @@ static const AVFilterPad avfilter_af_dynaudnorm_outputs[] = { · 2 unmodified lines
737779 {
738780 .name = "default",
739781 .type = AVMEDIA_TYPE_AUDIO,
740− .request_frame = request_frame,
741782 },
742783 { NULL }
743784 };
@@ -749,6 +790,7 @@ AVFilter ff_af_dynaudnorm = { · 5 unmodified lines
749790 .priv_size = sizeof(DynamicAudioNormalizerContext),
750791 .init = init,
751792 .uninit = uninit,
793+ .activate = activate,
752794 .inputs = avfilter_af_dynaudnorm_inputs,
753795 .outputs = avfilter_af_dynaudnorm_outputs,
754796 .priv_class = &dynaudnorm_class,

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