[FFmpeg-soc] [soc]: r342 - in libavfilter: Makefile allfilters.h avfilter.c vsrc_ppm.c

koorogi subversion at mplayerhq.hu
Sun Jul 8 18:06:30 CEST 2007


Author: koorogi
Date: Sun Jul  8 18:06:30 2007
New Revision: 342

Log:
Add a simple video source filter which loads a PPM file and outputs it as
the videos frames.  Useful for testing PRESERVE buffers, and soon automatic
colorspace conversion.


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

Modified: libavfilter/Makefile
==============================================================================
--- libavfilter/Makefile	(original)
+++ libavfilter/Makefile	Sun Jul  8 18:06:30 2007
@@ -4,6 +4,7 @@ LIBS = ../libavcodec/libavcodec.a ../lib
 
 OBJECTS = avfilter.o          \
           vsrc_dummy.o        \
+		  vsrc_ppm.o          \
 		  vo_sdl.o            \
 		  vf_crop.o           \
 		  vf_passthrough.o    \

Modified: libavfilter/allfilters.h
==============================================================================
--- libavfilter/allfilters.h	(original)
+++ libavfilter/allfilters.h	Sun Jul  8 18:06:30 2007
@@ -22,6 +22,7 @@
 #include "avfilter.h"
 
 extern AVFilter vsrc_dummy;
+extern AVFilter vsrc_ppm;
 extern AVFilter vf_crop;
 extern AVFilter vf_passthrough;
 extern AVFilter vf_slicify;

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Sun Jul  8 18:06:30 2007
@@ -236,6 +236,7 @@ void avfilter_register(AVFilter *filter)
 void avfilter_init(void)
 {
     avfilter_register(&vsrc_dummy);
+    avfilter_register(&vsrc_ppm);
     avfilter_register(&vf_crop);
     avfilter_register(&vf_passthrough);
     avfilter_register(&vf_slicify);

Added: libavfilter/vsrc_ppm.c
==============================================================================
--- (empty file)
+++ libavfilter/vsrc_ppm.c	Sun Jul  8 18:06:30 2007
@@ -0,0 +1,125 @@
+/*
+ * PPM file video source filter for testing
+ * 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 <stdio.h>
+
+#include "avfilter.h"
+
+typedef struct {
+    int w, h;
+    FILE *in;
+    AVFilterPicRef *pic;
+} PPMContext;
+
+static int init(AVFilterContext *ctx, const char *args)
+{
+    PPMContext *ppm = ctx->priv;
+    FILE *in;
+    int max, x, y;
+
+    if(!args) return -1;
+    if(!(ppm->in = fopen(args, "r"))) return -1;
+
+    if(fscanf(ppm->in, "P6 %d %d %d ", &ppm->w, &ppm->h, &max) < 3)
+        goto fail;
+    if(ppm->w < 1 || ppm->h < 1 || max != 255)
+        goto fail;
+
+    return 0;
+
+fail:
+    fclose(ppm->in);
+    ppm->in = NULL;
+    return -1;
+}
+
+static int *query_formats(AVFilterLink *link)
+{
+    return avfilter_make_format_list(1, PIX_FMT_BGR24);
+}
+
+static int config_props(AVFilterLink *link)
+{
+    PPMContext *ppm = link->src->priv;
+
+    link->w = ppm->w;
+    link->h = ppm->h;
+
+    return 0;
+}
+
+static void request_frame(AVFilterLink *link)
+{
+    PPMContext *ppm = link->src->priv;
+    AVFilterPicRef *out;
+
+    int x, y;
+    uint8_t *row, *cur;
+
+    if(!ppm->pic) {
+        ppm->pic = avfilter_get_video_buffer(link,
+                        AV_PERM_WRITE | AV_PERM_PRESERVE | AV_PERM_REUSE);
+
+        row = ppm->pic->data[0];
+        for(y = 0; y < ppm->h; y ++) {
+            fread(row, 3, ppm->w, ppm->in);
+            row += ppm->pic->linesize[0];
+        }
+
+        fclose(ppm->in);
+        ppm->in = NULL;
+    }
+
+    out = avfilter_ref_pic(ppm->pic);
+    out->perms &= ~AV_PERM_WRITE;
+    avfilter_start_frame(link, out);
+    avfilter_draw_slice(link, out->data, 0, out->h);
+    avfilter_end_frame(link);
+}
+
+static void uninit(AVFilterContext *ctx)
+{
+    PPMContext *ppm = ctx->priv;
+
+    if(ppm->pic)
+        avfilter_unref_pic(ppm->pic);
+    if(ppm->in)
+        fclose(ppm->in);
+}
+
+AVFilter vsrc_ppm =
+{
+    .name      = "ppm",
+    .author    = "Bobby Bingham",
+    .priv_size = sizeof(PPMContext),
+
+    .init      = init,
+    .uninit    = uninit,
+
+    .inputs    = (AVFilterPad[]) {{ .name = NULL }},
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .request_frame   = request_frame,
+                                    .query_formats   = query_formats,
+                                    .config_props    = config_props, },
+                                  { .name = NULL}},
+};
+



More information about the FFmpeg-soc mailing list