From 2c3b665379de0358006199de8604e10323c1037a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 28 Nov 2012 21:02:09 +0100 Subject: vf_select: switch to filter_frame The new code reads the input frame when its ready, the previous code did read the input frame during start_frame at which point it may not yet be available. Signed-off-by: Michael Niedermayer --- libavfilter/vf_select.c | 52 +++++++++++-------------------------------------- 1 file changed, 11 insertions(+), 41 deletions(-) (limited to 'libavfilter/vf_select.c') diff --git a/libavfilter/vf_select.c b/libavfilter/vf_select.c index 341361da51..e0e1863d7f 100644 --- a/libavfilter/vf_select.c +++ b/libavfilter/vf_select.c @@ -289,50 +289,27 @@ static int select_frame(AVFilterContext *ctx, AVFilterBufferRef *picref) return res; } -static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) +static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame) { SelectContext *select = inlink->dst->priv; - select->select = select_frame(inlink->dst, picref); + select->select = select_frame(inlink->dst, frame); if (select->select) { - AVFilterBufferRef *buf_out; /* frame was requested through poll_frame */ if (select->cache_frames) { - if (!av_fifo_space(select->pending_frames)) + if (!av_fifo_space(select->pending_frames)) { av_log(inlink->dst, AV_LOG_ERROR, "Buffering limit reached, cannot cache more frames\n"); - else - av_fifo_generic_write(select->pending_frames, &picref, - sizeof(picref), NULL); + avfilter_unref_bufferp(&frame); + } else + av_fifo_generic_write(select->pending_frames, &frame, + sizeof(frame), NULL); return 0; } - buf_out = avfilter_ref_buffer(picref, ~0); - if (!buf_out) - return AVERROR(ENOMEM); - return ff_start_frame(inlink->dst->outputs[0], buf_out); + return ff_filter_frame(inlink->dst->outputs[0], frame); } - return 0; -} - -static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) -{ - SelectContext *select = inlink->dst->priv; - - if (select->select && !select->cache_frames) - return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); - return 0; -} - -static int end_frame(AVFilterLink *inlink) -{ - SelectContext *select = inlink->dst->priv; - - if (select->select) { - if (select->cache_frames) - return 0; - return ff_end_frame(inlink->dst->outputs[0]); - } + avfilter_unref_bufferp(&frame); return 0; } @@ -345,14 +322,9 @@ static int request_frame(AVFilterLink *outlink) if (av_fifo_size(select->pending_frames)) { AVFilterBufferRef *picref; - int ret; av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL); - if ((ret = ff_start_frame(outlink, picref)) < 0 || - (ret = ff_draw_slice(outlink, 0, outlink->h, 1)) < 0 || - (ret = ff_end_frame(outlink)) < 0); - - return ret; + return ff_filter_frame(outlink, picref); } while (!select->select) { @@ -432,9 +404,7 @@ static const AVFilterPad avfilter_vf_select_inputs[] = { .get_video_buffer = ff_null_get_video_buffer, .min_perms = AV_PERM_PRESERVE, .config_props = config_input, - .start_frame = start_frame, - .draw_slice = draw_slice, - .end_frame = end_frame + .filter_frame = filter_frame, }, { NULL } }; -- cgit v1.2.3