#include "libavutil/eval.h"
#include "libavutil/fifo.h"
+#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
#include "avfilter.h"
#include "internal.h"
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) {
/* 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;
}
- return ff_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0));
+ 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;
}
if (av_fifo_size(select->pending_frames)) {
AVFilterBufferRef *picref;
+
av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL);
- ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
- ff_draw_slice(outlink, 0, outlink->h, 1);
- ff_end_frame(outlink);
- avfilter_unref_buffer(picref);
- return 0;
+ return ff_filter_frame(outlink, picref);
}
while (!select->select) {
select->pending_frames = NULL;
}
+static const AVFilterPad avfilter_vf_select_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .get_video_buffer = ff_null_get_video_buffer,
+ .config_props = config_input,
+ .filter_frame = filter_frame,
+ },
+ { NULL }
+};
+
+static const AVFilterPad avfilter_vf_select_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .poll_frame = poll_frame,
+ .request_frame = request_frame,
+ },
+ { NULL }
+};
+
AVFilter avfilter_vf_select = {
.name = "select",
.description = NULL_IF_CONFIG_SMALL("Select frames to pass in output."),
.priv_size = sizeof(SelectContext),
- .inputs = (const AVFilterPad[]) {{ .name = "default",
- .type = AVMEDIA_TYPE_VIDEO,
- .get_video_buffer = ff_null_get_video_buffer,
- .config_props = config_input,
- .start_frame = start_frame,
- .draw_slice = draw_slice,
- .end_frame = end_frame },
- { .name = NULL }},
- .outputs = (const AVFilterPad[]) {{ .name = "default",
- .type = AVMEDIA_TYPE_VIDEO,
- .poll_frame = poll_frame,
- .request_frame = request_frame, },
- { .name = NULL}},
+ .inputs = avfilter_vf_select_inputs,
+ .outputs = avfilter_vf_select_outputs,
};