|
|
|
@ -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, |
|
|
|
|