aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/af_sidechaincompress.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2017-08-24 20:34:35 +0200
committerPaul B Mahol <onemda@gmail.com>2017-08-24 20:34:35 +0200
commitf0f48884b02354173747c31d5016eaefe3db6a00 (patch)
tree78991af028baa257a262a035c2feba6586f28d85 /libavfilter/af_sidechaincompress.c
parentf8d0689d3ff56bdeda708a14fad322cef8a219af (diff)
downloadffmpeg-f0f48884b02354173747c31d5016eaefe3db6a00.tar.gz
avfilter/af_sidechaincompress: switch to activate
Diffstat (limited to 'libavfilter/af_sidechaincompress.c')
-rw-r--r--libavfilter/af_sidechaincompress.c112
1 files changed, 58 insertions, 54 deletions
diff --git a/libavfilter/af_sidechaincompress.c b/libavfilter/af_sidechaincompress.c
index d1dfc106e2..f174b70a5b 100644
--- a/libavfilter/af_sidechaincompress.c
+++ b/libavfilter/af_sidechaincompress.c
@@ -32,6 +32,7 @@
#include "audio.h"
#include "avfilter.h"
+#include "filters.h"
#include "formats.h"
#include "hermite.h"
#include "internal.h"
@@ -183,71 +184,76 @@ static void compressor(SidechainCompressContext *s,
}
#if CONFIG_SIDECHAINCOMPRESS_FILTER
-static int filter_frame(AVFilterLink *link, AVFrame *frame)
+static int activate(AVFilterContext *ctx)
{
- AVFilterContext *ctx = link->dst;
SidechainCompressContext *s = ctx->priv;
- AVFilterLink *outlink = ctx->outputs[0];
AVFrame *out = NULL, *in[2] = { NULL };
+ int ret, i, status, nb_samples;
double *dst;
- int nb_samples;
- int i;
+ int64_t pts;
- for (i = 0; i < 2; i++)
- if (link == ctx->inputs[i])
- break;
- av_assert0(i < 2);
- av_audio_fifo_write(s->fifo[i], (void **)frame->extended_data,
- frame->nb_samples);
- av_frame_free(&frame);
+ if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &in[0])) > 0) {
+ av_audio_fifo_write(s->fifo[0], (void **)in[0]->extended_data,
+ in[0]->nb_samples);
+ av_frame_free(&in[0]);
+ }
+ if (ret < 0)
+ return ret;
+ if ((ret = ff_inlink_consume_frame(ctx->inputs[1], &in[1])) > 0) {
+ av_audio_fifo_write(s->fifo[1], (void **)in[1]->extended_data,
+ in[1]->nb_samples);
+ av_frame_free(&in[1]);
+ }
+ if (ret < 0)
+ return ret;
nb_samples = FFMIN(av_audio_fifo_size(s->fifo[0]), av_audio_fifo_size(s->fifo[1]));
- if (!nb_samples)
- return 0;
-
- out = ff_get_audio_buffer(outlink, nb_samples);
- if (!out)
- return AVERROR(ENOMEM);
- for (i = 0; i < 2; i++) {
- in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples);
- if (!in[i]) {
- av_frame_free(&in[0]);
- av_frame_free(&in[1]);
- av_frame_free(&out);
+ if (nb_samples) {
+ out = ff_get_audio_buffer(ctx->outputs[0], nb_samples);
+ if (!out)
return AVERROR(ENOMEM);
+ for (i = 0; i < 2; i++) {
+ in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples);
+ if (!in[i]) {
+ av_frame_free(&in[0]);
+ av_frame_free(&in[1]);
+ av_frame_free(&out);
+ return AVERROR(ENOMEM);
+ }
+ av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples);
}
- av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples);
- }
- dst = (double *)out->data[0];
- out->pts = s->pts;
- s->pts += nb_samples;
+ dst = (double *)out->data[0];
+ out->pts = s->pts;
+ s->pts += nb_samples;
- compressor(s, (double *)in[0]->data[0], dst,
- (double *)in[1]->data[0], nb_samples,
- s->level_in, s->level_sc,
- ctx->inputs[0], ctx->inputs[1]);
+ compressor(s, (double *)in[0]->data[0], dst,
+ (double *)in[1]->data[0], nb_samples,
+ s->level_in, s->level_sc,
+ ctx->inputs[0], ctx->inputs[1]);
- av_frame_free(&in[0]);
- av_frame_free(&in[1]);
+ av_frame_free(&in[0]);
+ av_frame_free(&in[1]);
- return ff_filter_frame(outlink, out);
-}
-
-static int request_frame(AVFilterLink *outlink)
-{
- AVFilterContext *ctx = outlink->src;
- SidechainCompressContext *s = ctx->priv;
- int i;
-
- /* get a frame on each input */
- for (i = 0; i < 2; i++) {
- AVFilterLink *inlink = ctx->inputs[i];
- if (!av_audio_fifo_size(s->fifo[i]))
- return ff_request_frame(inlink);
+ ret = ff_filter_frame(ctx->outputs[0], out);
+ if (ret < 0)
+ return ret;
+ }
+ if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) {
+ ff_outlink_set_status(ctx->outputs[0], status, pts);
+ return 0;
+ } else if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) {
+ ff_outlink_set_status(ctx->outputs[0], status, pts);
+ return 0;
+ } else {
+ if (ff_outlink_frame_wanted(ctx->outputs[0])) {
+ if (!av_audio_fifo_size(s->fifo[0]))
+ ff_inlink_request_frame(ctx->inputs[0]);
+ if (!av_audio_fifo_size(s->fifo[1]))
+ ff_inlink_request_frame(ctx->inputs[1]);
+ }
+ return 0;
}
-
- return 0;
}
static int query_formats(AVFilterContext *ctx)
@@ -325,11 +331,9 @@ static const AVFilterPad sidechaincompress_inputs[] = {
{
.name = "main",
.type = AVMEDIA_TYPE_AUDIO,
- .filter_frame = filter_frame,
},{
.name = "sidechain",
.type = AVMEDIA_TYPE_AUDIO,
- .filter_frame = filter_frame,
},
{ NULL }
};
@@ -339,7 +343,6 @@ static const AVFilterPad sidechaincompress_outputs[] = {
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
.config_props = config_output,
- .request_frame = request_frame,
},
{ NULL }
};
@@ -350,6 +353,7 @@ AVFilter ff_af_sidechaincompress = {
.priv_size = sizeof(SidechainCompressContext),
.priv_class = &sidechaincompress_class,
.query_formats = query_formats,
+ .activate = activate,
.uninit = uninit,
.inputs = sidechaincompress_inputs,
.outputs = sidechaincompress_outputs,