Unified · Split
| @@ -34,6 +34,7 @@ · 33 unmodified lines | |||
| 34 | 34 | ||
| 35 | #include "audio.h" | 35 | #include "audio.h" |
| 36 | #include "avfilter.h" | 36 | #include "avfilter.h" |
| 37 | #include "filters.h" | ||
| 37 | #include "internal.h" | 38 | #include "internal.h" |
| 38 | 39 | ||
| 39 | typedef struct cqueue { | 40 | typedef struct cqueue { |
| @@ -67,6 +68,8 @@ typedef struct DynamicAudioNormalizerContext { · 27 unmodified lines | |||
| 67 | 68 | ||
| 68 | int channels; | 69 | int channels; |
| 69 | int delay; | 70 | int delay; |
| 71 | int eof; | ||
| 72 | int64_t pts; | ||
| 70 | 73 | ||
| 71 | cqueue **gain_history_original; | 74 | cqueue **gain_history_original; |
| 72 | cqueue **gain_history_minimum; | 75 | cqueue **gain_history_minimum; |
| @@ -292,10 +295,7 @@ static int config_input(AVFilterLink *inlink) · 219 unmodified lines | |||
| 292 | 295 | ||
| 293 | uninit(ctx); | 296 | uninit(ctx); |
| 294 | 297 | ||
| 295 | s->frame_len = | 298 | s->frame_len = frame_size(inlink->sample_rate, s->frame_len_msec); |
| 296 | inlink->min_samples = | ||
| 297 | inlink->max_samples = | ||
| 298 | inlink->partial_buf_size = frame_size(inlink->sample_rate, s->frame_len_msec); | ||
| 299 | av_log(ctx, AV_LOG_DEBUG, "frame len %d\n", s->frame_len); | 299 | av_log(ctx, AV_LOG_DEBUG, "frame len %d\n", s->frame_len); |
| 300 | 300 | ||
| 301 | s->fade_factors[0] = av_malloc_array(s->frame_len, sizeof(*s->fade_factors[0])); | 301 | 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 | |||
| 661 | AVFilterContext *ctx = inlink->dst; | 661 | AVFilterContext *ctx = inlink->dst; |
| 662 | DynamicAudioNormalizerContext *s = ctx->priv; | 662 | DynamicAudioNormalizerContext *s = ctx->priv; |
| 663 | AVFilterLink *outlink = inlink->dst->outputs[0]; | 663 | AVFilterLink *outlink = inlink->dst->outputs[0]; |
| 664 | int ret = 0; | 664 | int ret = 1; |
| 665 | 665 | ||
| 666 | if (!cqueue_empty(s->gain_history_smoothed[0])) { | 666 | if (!cqueue_empty(s->gain_history_smoothed[0])) { |
| 667 | AVFrame *out = ff_bufqueue_get(&s->queue); | 667 | AVFrame *out = ff_bufqueue_get(&s->queue); |
| @@ -670,6 +670,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 2 unmodified lines | |||
| 670 | ret = ff_filter_frame(outlink, out); | 670 | ret = ff_filter_frame(outlink, out); |
| 671 | } | 671 | } |
| 672 | 672 | ||
| 673 | av_frame_make_writable(in); | ||
| 673 | analyze_frame(s, in); | 674 | analyze_frame(s, in); |
| 674 | ff_bufqueue_add(ctx, &s->queue, in); | 675 | ff_bufqueue_add(ctx, &s->queue, in); |
| 675 | 676 | ||
| @@ -701,34 +702,75 @@ static int flush_buffer(DynamicAudioNormalizerContext *s, AVFilterLink *inlink, · 25 unmodified lines | |||
| 701 | return filter_frame(inlink, out); | 702 | return filter_frame(inlink, out); |
| 702 | } | 703 | } |
| 703 | 704 | ||
| 704 | static int request_frame(AVFilterLink *outlink) | 705 | static int flush(AVFilterLink *outlink) |
| 705 | { | 706 | { |
| 706 | AVFilterContext *ctx = outlink->src; | 707 | AVFilterContext *ctx = outlink->src; |
| 707 | DynamicAudioNormalizerContext *s = ctx->priv; | 708 | DynamicAudioNormalizerContext *s = ctx->priv; |
| 708 | int ret = 0; | 709 | int ret = 0; |
| 709 | 710 | ||
| 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 | } | ||
| 711 | 719 | ||
| 712 | if (ret == AVERROR_EOF && !ctx->is_disabled && s->delay) { | 720 | return ret; |
| 713 | if (!cqueue_empty(s->gain_history_smoothed[0])) { | 721 | } |
| 714 | ret = flush_buffer(s, ctx->inputs[0], outlink); | ||
| 715 | } else if (s->queue.available) { | ||
| 716 | AVFrame *out = ff_bufqueue_get(&s->queue); | ||
| 717 | 722 | ||
| 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; | ||
| 719 | } | 747 | } |
| 720 | } | 748 | } |
| 721 | 749 | ||
| 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; | ||
| 723 | } | 767 | } |
| 724 | 768 | ||
| 725 | static const AVFilterPad avfilter_af_dynaudnorm_inputs[] = { | 769 | static const AVFilterPad avfilter_af_dynaudnorm_inputs[] = { |
| 726 | { | 770 | { |
| 727 | .name = "default", | 771 | .name = "default", |
| 728 | .type = AVMEDIA_TYPE_AUDIO, | 772 | .type = AVMEDIA_TYPE_AUDIO, |
| 729 | .filter_frame = filter_frame, | ||
| 730 | .config_props = config_input, | 773 | .config_props = config_input, |
| 731 | .needs_writable = 1, | ||
| 732 | }, | 774 | }, |
| 733 | { NULL } | 775 | { NULL } |
| 734 | }; | 776 | }; |
| @@ -737,7 +779,6 @@ static const AVFilterPad avfilter_af_dynaudnorm_outputs[] = { · 2 unmodified lines | |||
| 737 | { | 779 | { |
| 738 | .name = "default", | 780 | .name = "default", |
| 739 | .type = AVMEDIA_TYPE_AUDIO, | 781 | .type = AVMEDIA_TYPE_AUDIO, |
| 740 | .request_frame = request_frame, | ||
| 741 | }, | 782 | }, |
| 742 | { NULL } | 783 | { NULL } |
| 743 | }; | 784 | }; |
| @@ -749,6 +790,7 @@ AVFilter ff_af_dynaudnorm = { · 5 unmodified lines | |||
| 749 | .priv_size = sizeof(DynamicAudioNormalizerContext), | 790 | .priv_size = sizeof(DynamicAudioNormalizerContext), |
| 750 | .init = init, | 791 | .init = init, |
| 751 | .uninit = uninit, | 792 | .uninit = uninit, |
| 793 | .activate = activate, | ||
| 752 | .inputs = avfilter_af_dynaudnorm_inputs, | 794 | .inputs = avfilter_af_dynaudnorm_inputs, |
| 753 | .outputs = avfilter_af_dynaudnorm_outputs, | 795 | .outputs = avfilter_af_dynaudnorm_outputs, |
| 754 | .priv_class = &dynaudnorm_class, | 796 | .priv_class = &dynaudnorm_class, |