From: Paul B Mahol <onemda@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avfilter/split: switch to activate() Date: Tue, 1 Mar 2022 14:27:20 +0100 Message-ID: <20220301132720.86396-1-onemda@gmail.com> (raw) Signed-off-by: Paul B Mahol <onemda@gmail.com> --- Fix possible hangs if (a)split filter is used in graph and one of outputs ends earlier than others. Then filter may never receive EOF from input provided by (a)split filter. See ticket #9152 for commands how to reproduce issue. --- libavfilter/split.c | 68 +++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/libavfilter/split.c b/libavfilter/split.c index 6b9b656708..98b51f976e 100644 --- a/libavfilter/split.c +++ b/libavfilter/split.c @@ -63,28 +63,62 @@ static av_cold int split_init(AVFilterContext *ctx) return 0; } -static int filter_frame(AVFilterLink *inlink, AVFrame *frame) +static int activate(AVFilterContext *ctx) { - AVFilterContext *ctx = inlink->dst; - int i, ret = AVERROR_EOF; + AVFilterLink *inlink = ctx->inputs[0]; + AVFrame *in; + int status, ret; + int64_t pts; - for (i = 0; i < ctx->nb_outputs; i++) { - AVFrame *buf_out; + for (int i = 0; i < ctx->nb_outputs; i++) { + FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[i], ctx); + } - if (ff_outlink_get_status(ctx->outputs[i])) - continue; - buf_out = av_frame_clone(frame); - if (!buf_out) { - ret = AVERROR(ENOMEM); - break; + ret = ff_inlink_consume_frame(inlink, &in); + if (ret < 0) + return ret; + if (ret > 0) { + for (int i = 0; i < ctx->nb_outputs; i++) { + AVFrame *buf_out; + + if (ff_outlink_get_status(ctx->outputs[i])) + continue; + buf_out = av_frame_clone(in); + if (!buf_out) { + ret = AVERROR(ENOMEM); + break; + } + + ret = ff_filter_frame(ctx->outputs[i], buf_out); + if (ret < 0) + break; } - ret = ff_filter_frame(ctx->outputs[i], buf_out); + av_frame_free(&in); if (ret < 0) - break; + 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; } - av_frame_free(&frame); - return ret; + + 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; } #define OFFSET(x) offsetof(SplitContext, x) @@ -100,7 +134,6 @@ static const AVFilterPad avfilter_vf_split_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, - .filter_frame = filter_frame, }, }; @@ -110,6 +143,7 @@ const AVFilter ff_vf_split = { .priv_size = sizeof(SplitContext), .priv_class = &split_class, .init = split_init, + .activate = activate, FILTER_INPUTS(avfilter_vf_split_inputs), .outputs = NULL, .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS | AVFILTER_FLAG_METADATA_ONLY, @@ -119,7 +153,6 @@ static const AVFilterPad avfilter_af_asplit_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, - .filter_frame = filter_frame, }, }; @@ -129,6 +162,7 @@ const AVFilter ff_af_asplit = { .priv_class = &split_class, .priv_size = sizeof(SplitContext), .init = split_init, + .activate = activate, FILTER_INPUTS(avfilter_af_asplit_inputs), .outputs = NULL, .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS | AVFILTER_FLAG_METADATA_ONLY, -- 2.33.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2022-03-01 13:25 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-01 13:27 Paul B Mahol [this message] 2022-03-03 18:30 ` Nicolas George 2022-03-03 20:58 ` Paul B Mahol 2022-03-04 13:13 ` Nicolas George 2022-03-04 22:49 ` Paul B Mahol 2022-03-05 11:04 ` Nicolas George 2022-03-05 12:56 ` Paul B Mahol 2022-03-05 19:37 ` Nicolas George 2022-03-06 14:08 ` Nicolas George
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220301132720.86396-1-onemda@gmail.com \ --to=onemda@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git