00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "avfilter.h"
00027 #include "vsink_buffer.h"
00028
00029 typedef struct {
00030 AVFilterBufferRef *picref;
00031 enum PixelFormat *pix_fmts;
00032 } BufferSinkContext;
00033
00034 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00035 {
00036 BufferSinkContext *buf = ctx->priv;
00037
00038 if (!opaque) {
00039 av_log(ctx, AV_LOG_ERROR, "No opaque field provided, which is required.\n");
00040 return AVERROR(EINVAL);
00041 }
00042
00043 buf->pix_fmts = opaque;
00044 return 0;
00045 }
00046
00047 static av_cold void uninit(AVFilterContext *ctx)
00048 {
00049 BufferSinkContext *buf = ctx->priv;
00050
00051 if (buf->picref)
00052 avfilter_unref_buffer(buf->picref);
00053 buf->picref = NULL;
00054 }
00055
00056 static void end_frame(AVFilterLink *inlink)
00057 {
00058 BufferSinkContext *buf = inlink->dst->priv;
00059
00060 if (buf->picref)
00061 avfilter_unref_buffer(buf->picref);
00062 buf->picref = inlink->cur_buf;
00063 }
00064
00065 static int query_formats(AVFilterContext *ctx)
00066 {
00067 BufferSinkContext *buf = ctx->priv;
00068
00069 avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(buf->pix_fmts));
00070 return 0;
00071 }
00072
00073 int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *ctx,
00074 AVFilterBufferRef **picref, int flags)
00075 {
00076 BufferSinkContext *buf = ctx->priv;
00077 AVFilterLink *inlink = ctx->inputs[0];
00078 int ret;
00079 *picref = NULL;
00080
00081
00082 if (!buf->picref) {
00083 if ((ret = avfilter_request_frame(inlink)) < 0)
00084 return ret;
00085 }
00086
00087 if (!buf->picref)
00088 return AVERROR(EINVAL);
00089
00090 *picref = buf->picref;
00091 if (!(flags & AV_VSINK_BUF_FLAG_PEEK))
00092 buf->picref = NULL;
00093
00094 return 0;
00095 }
00096
00097 AVFilter avfilter_vsink_buffersink = {
00098 .name = "buffersink",
00099 .priv_size = sizeof(BufferSinkContext),
00100 .init = init,
00101 .uninit = uninit,
00102
00103 .query_formats = query_formats,
00104
00105 .inputs = (AVFilterPad[]) {{ .name = "default",
00106 .type = AVMEDIA_TYPE_VIDEO,
00107 .end_frame = end_frame,
00108 .min_perms = AV_PERM_READ, },
00109 { .name = NULL }},
00110 .outputs = (AVFilterPad[]) {{ .name = NULL }},
00111 };