[FFmpeg-cvslog] avfilter/af_channelsplit: switch to activate()
Paul B Mahol
git at videolan.org
Mon Mar 7 16:30:53 EET 2022
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Mar 7 15:11:32 2022 +0100| [328247076c7e77dea53ab59341ff1d85a1ad43cf] | committer: Paul B Mahol
avfilter/af_channelsplit: switch to activate()
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=328247076c7e77dea53ab59341ff1d85a1ad43cf
---
libavfilter/af_channelsplit.c | 79 +++++++++++++++++++++++++++++++++----------
1 file changed, 61 insertions(+), 18 deletions(-)
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),
More information about the ffmpeg-cvslog
mailing list