diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c index 1a2519dd32..e0b7839084 100644 --- a/libavfilter/af_channelsplit.c +++ b/libavfilter/af_channelsplit.c @@ -30,6 +30,7 @@ #include "audio.h" #include "avfilter.h" +#include "filters.h" #include "formats.h" #include "internal.h" @@ -131,38 +132,79 @@ static int query_formats(AVFilterContext *ctx) return 0; } -static int filter_frame(AVFilterLink *inlink, AVFrame *buf) +static int filter_frame(AVFilterLink *outlink, AVFrame *buf) { - AVFilterContext *ctx = inlink->dst; + AVFilterContext *ctx = outlink->src; ChannelSplitContext *s = ctx->priv; - int i, ret = 0; + const int i = FF_OUTLINK_IDX(outlink); - for (i = 0; i < ctx->nb_outputs; i++) { - AVFrame *buf_out = av_frame_clone(buf); + AVFrame *buf_out = av_frame_clone(buf); + if (!buf_out) + return AVERROR(ENOMEM); - if (!buf_out) { - ret = AVERROR(ENOMEM); - break; - } + buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[s->map[i]]; + buf_out->channel_layout = + av_channel_layout_extract_channel(buf->channel_layout, s->map[i]); + buf_out->channels = 1; + + return ff_filter_frame(ctx->outputs[i], buf_out); +} + +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); + } - buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[s->map[i]]; - buf_out->channel_layout = - av_channel_layout_extract_channel(buf->channel_layout, s->map[i]); - buf_out->channels = 1; + ret = ff_inlink_consume_frame(inlink, &in); + if (ret < 0) + return ret; + if (ret > 0) { + for (int i = 0; i < ctx->nb_outputs; i++) { + if (ff_outlink_get_status(ctx->outputs[i])) + continue; + + ret = filter_frame(ctx->outputs[i], in); + if (ret < 0) + break; + } - ret = ff_filter_frame(ctx->outputs[i], buf_out); + av_frame_free(&in); if (ret < 0) - break; + return ret; } - av_frame_free(&buf); - 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 const AVFilterPad avfilter_af_channelsplit_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, - .filter_frame = filter_frame, }, }; @@ -172,6 +214,7 @@ const AVFilter ff_af_channelsplit = { .priv_size = sizeof(ChannelSplitContext), .priv_class = &channelsplit_class, .init = init, + .activate = activate, FILTER_INPUTS(avfilter_af_channelsplit_inputs), .outputs = NULL, FILTER_QUERY_FUNC(query_formats),