[FFmpeg-soc] [soc]: r948 - in libavfilter: Makefile allfilters.h avfilter.c vf_buffer.c

koorogi subversion at mplayerhq.hu
Sat Aug 18 05:17:53 CEST 2007


Author: koorogi
Date: Sat Aug 18 05:17:52 2007
New Revision: 948

Log:
Add a filter to act as a buffer between filters which may output multiple
frames for a single call to request_filter(), and a following filter which
assumes it will only receive one frame per call.


Added:
   libavfilter/vf_buffer.c
Modified:
   libavfilter/Makefile
   libavfilter/allfilters.h
   libavfilter/avfilter.c

Modified: libavfilter/Makefile
==============================================================================
--- libavfilter/Makefile	(original)
+++ libavfilter/Makefile	Sat Aug 18 05:17:52 2007
@@ -10,6 +10,7 @@ OBJS = avfilter.o \
 # TODO: real conditional compilation
 OBJS-yes = vsrc_dummy.o \
            vsrc_ppm.o \
+		   vf_buffer.o \
            vf_crop.o \
            vf_fps.o \
            vf_overlay.o \

Modified: libavfilter/allfilters.h
==============================================================================
--- libavfilter/allfilters.h	(original)
+++ libavfilter/allfilters.h	Sat Aug 18 05:17:52 2007
@@ -23,6 +23,7 @@
 
 extern AVFilter vsrc_dummy;
 extern AVFilter vsrc_ppm;
+extern AVFilter vf_buffer;
 extern AVFilter vf_crop;
 extern AVFilter vf_fps;
 extern AVFilter vf_graph;

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Sat Aug 18 05:17:52 2007
@@ -267,6 +267,7 @@ void avfilter_init(void)
 {
     avfilter_register(&vsrc_dummy);
     avfilter_register(&vsrc_ppm);
+    avfilter_register(&vf_buffer);
     avfilter_register(&vf_crop);
     avfilter_register(&vf_fps);
     avfilter_register(&vf_graph);

Added: libavfilter/vf_buffer.c
==============================================================================
--- (empty file)
+++ libavfilter/vf_buffer.c	Sat Aug 18 05:17:52 2007
@@ -0,0 +1,141 @@
+/*
+ * Filter to buffer frames
+ * copyright (c) 2007 Bobby Bingham
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avfilter.h"
+
+typedef struct BufPic
+{
+    AVFilterPicRef *pic;
+    struct BufPic  *next;
+} BufPic;
+
+typedef struct
+{
+    BufPic  root;
+    BufPic *last;   ///< last buffered picture
+} BufferContext;
+
+static int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+    BufferContext *buf = ctx->priv;
+    buf->last = &buf->root;
+
+    return 0;
+}
+
+static void uninit(AVFilterContext *ctx)
+{
+    BufferContext *buf = ctx->priv;
+    BufPic *pic, *tmp;
+
+    for(pic = buf->root.next; pic; pic = tmp) {
+        tmp = pic->next;
+        avfilter_unref_pic(pic->pic);
+        av_free(pic);
+    }
+}
+
+static int *query_formats(AVFilterLink *link)
+{
+    return avfilter_make_format_list(31,
+                PIX_FMT_YUV444P,  PIX_FMT_YUV422P,  PIX_FMT_YUV420P,
+                PIX_FMT_YUV411P,  PIX_FMT_YUV410P,
+                PIX_FMT_YUYV422,  PIX_FMT_UYVY422,  PIX_FMT_UYYVYY411,
+                PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
+                PIX_FMT_YUV440P,  PIX_FMT_YUVJ440P,
+                PIX_FMT_RGB32,    PIX_FMT_BGR32,
+                PIX_FMT_RGB32_1,  PIX_FMT_BGR32_1,
+                PIX_FMT_RGB24,    PIX_FMT_BGR24,
+                PIX_FMT_RGB565,   PIX_FMT_BGR565,
+                PIX_FMT_RGB555,   PIX_FMT_BGR555,
+                PIX_FMT_RGB8,     PIX_FMT_BGR8,
+                PIX_FMT_RGB4_BYTE,PIX_FMT_BGR4_BYTE,
+                PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE,
+                PIX_FMT_GRAY8,    PIX_FMT_PAL8);
+}
+
+static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
+{
+    BufferContext *buf = link->dst->priv;
+
+    buf->last->next = av_mallocz(sizeof(BufPic));
+    buf->last = buf->last->next;
+    buf->last->pic = picref;
+}
+
+static void end_frame(AVFilterLink *link)
+{
+}
+
+/* TODO: support forwarding slices as they come if the next filter has
+ * requested a frame and we had none buffered */
+static void draw_slice(AVFilterLink *link, int y, int h)
+{
+}
+
+static int request_frame(AVFilterLink *link)
+{
+    BufferContext *buf = link->src->priv;
+    BufPic *tmp;
+
+    if(!buf->root.next)
+        if(avfilter_request_frame(link->src->inputs[0]))
+            return -1;
+
+    /* by doing this, we give ownership of the reference to the next filter,
+     * so we don't have to worry about dereferencing it ourselves. */
+    avfilter_start_frame(link, buf->root.next->pic);
+    avfilter_draw_slice(link, 0, buf->root.next->pic->h);
+    avfilter_end_frame(link);
+
+    if(buf->last == buf->root.next)
+        buf->last = &buf->root;
+    tmp = buf->root.next->next;
+    av_free(buf->root.next);
+    buf->root.next = tmp;
+
+    return 0;
+}
+
+AVFilter vf_buffer =
+{
+    .name      = "buffer",
+    .author    = "Bobby Bingham",
+
+    .init      = init,
+    .uninit    = uninit,
+
+    .priv_size = sizeof(BufferContext),
+
+    .inputs    = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .start_frame     = start_frame,
+                                    .draw_slice      = draw_slice,
+                                    .query_formats   = query_formats,
+                                    .end_frame       = end_frame,
+                                    .rej_perms       = AV_PERM_REUSE2, },
+                                  { .name = NULL}},
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .request_frame   = request_frame, },
+                                  { .name = NULL}},
+};
+



More information about the FFmpeg-soc mailing list