aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/af_acrossover.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2022-03-07 14:24:09 +0100
committerPaul B Mahol <onemda@gmail.com>2022-03-07 15:29:39 +0100
commita1f2e42ebf4c5af0f0975947fa40aa8679b82052 (patch)
treed5f52cd9c60781404c63daf0bfdb00154bda009a /libavfilter/af_acrossover.c
parent7238541d3969f3ddfede80e01da7a82ad7d69190 (diff)
downloadffmpeg-a1f2e42ebf4c5af0f0975947fa40aa8679b82052.tar.gz
avfilter/af_acrossover: switch to activate()
Diffstat (limited to 'libavfilter/af_acrossover.c')
-rw-r--r--libavfilter/af_acrossover.c68
1 files changed, 56 insertions, 12 deletions
diff --git a/libavfilter/af_acrossover.c b/libavfilter/af_acrossover.c
index 9c00e1ddc2..ec5b021a30 100644
--- a/libavfilter/af_acrossover.c
+++ b/libavfilter/af_acrossover.c
@@ -33,6 +33,7 @@
#include "audio.h"
#include "avfilter.h"
+#include "filters.h"
#include "formats.h"
#include "internal.h"
@@ -73,7 +74,6 @@ typedef struct AudioCrossoverContext {
AVFrame *xover;
- AVFrame *input_frame;
AVFrame *frames[MAX_BANDS];
int (*filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
@@ -354,7 +354,7 @@ BIQUAD_PROCESS(dblp, double)
static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
{ \
AudioCrossoverContext *s = ctx->priv; \
- AVFrame *in = s->input_frame; \
+ AVFrame *in = arg; \
AVFrame **frames = s->frames; \
const int start = (in->channels * jobnr) / nb_jobs; \
const int end = (in->channels * (jobnr+1)) / nb_jobs; \
@@ -480,11 +480,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVFilterContext *ctx = inlink->dst;
AudioCrossoverContext *s = ctx->priv;
AVFrame **frames = s->frames;
- int i, ret = 0;
+ int ret = 0;
- for (i = 0; i < ctx->nb_outputs; i++) {
+ for (int i = 0; i < ctx->nb_outputs; i++) {
frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);
-
if (!frames[i]) {
ret = AVERROR(ENOMEM);
break;
@@ -496,11 +495,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
if (ret < 0)
goto fail;
- s->input_frame = in;
- ff_filter_execute(ctx, s->filter_channels, NULL, NULL,
+ ff_filter_execute(ctx, s->filter_channels, in, NULL,
FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
- for (i = 0; i < ctx->nb_outputs; i++) {
+ for (int i = 0; i < ctx->nb_outputs; i++) {
+ if (ff_outlink_get_status(ctx->outputs[i])) {
+ av_frame_free(&frames[i]);
+ continue;
+ }
+
ret = ff_filter_frame(ctx->outputs[i], frames[i]);
frames[i] = NULL;
if (ret < 0)
@@ -508,14 +511,55 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
fail:
- for (i = 0; i < ctx->nb_outputs; i++)
+ for (int i = 0; i < ctx->nb_outputs; i++)
av_frame_free(&frames[i]);
- av_frame_free(&in);
- s->input_frame = NULL;
return ret;
}
+static int activate(AVFilterContext *ctx)
+{
+ AVFilterLink *inlink = ctx->inputs[0];
+ int status, ret;
+ AVFrame *in;
+ int64_t pts;
+
+ for (int i = 0; i < ctx->nb_outputs; i++) {
+ FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[i], ctx);
+ }
+
+ ret = ff_inlink_consume_frame(inlink, &in);
+ if (ret < 0)
+ return ret;
+ if (ret > 0) {
+ ret = filter_frame(inlink, in);
+ av_frame_free(&in);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
+ for (int i = 0; i < ctx->nb_outputs; i++) {
+ if (ff_outlink_get_status(ctx->outputs[i]))
+ continue;
+ ff_outlink_set_status(ctx->outputs[i], status, pts);
+ }
+ return 0;
+ }
+
+ for (int i = 0; i < ctx->nb_outputs; i++) {
+ if (ff_outlink_get_status(ctx->outputs[i]))
+ continue;
+
+ if (ff_outlink_frame_wanted(ctx->outputs[i])) {
+ ff_inlink_request_frame(inlink);
+ return 0;
+ }
+ }
+
+ return FFERROR_NOT_READY;
+}
+
static av_cold void uninit(AVFilterContext *ctx)
{
AudioCrossoverContext *s = ctx->priv;
@@ -528,7 +572,6 @@ static const AVFilterPad inputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
- .filter_frame = filter_frame,
.config_props = config_input,
},
};
@@ -539,6 +582,7 @@ const AVFilter ff_af_acrossover = {
.priv_size = sizeof(AudioCrossoverContext),
.priv_class = &acrossover_class,
.init = init,
+ .activate = activate,
.uninit = uninit,
FILTER_INPUTS(inputs),
.outputs = NULL,