[FFmpeg-soc] [soc]: r285 - in libavfilter: allfilters.h avfilter.c vf_crop.c vf_expand.c vf_passthrough.c vo_sdl.c vsrc_dummy.c

koorogi subversion at mplayerhq.hu
Fri Jun 29 19:07:44 CEST 2007


Author: koorogi
Date: Fri Jun 29 19:07:44 2007
New Revision: 285

Log:
Some simple filters for testing


Added:
   libavfilter/allfilters.h
   libavfilter/vf_crop.c
   libavfilter/vf_expand.c
   libavfilter/vf_passthrough.c
   libavfilter/vo_sdl.c
   libavfilter/vsrc_dummy.c
Modified:
   libavfilter/avfilter.c

Added: libavfilter/allfilters.h
==============================================================================
--- (empty file)
+++ libavfilter/allfilters.h	Fri Jun 29 19:07:44 2007
@@ -0,0 +1,27 @@
+/*
+ * video filters
+ * 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"
+
+extern AVFilter vsrc_dummy;
+extern AVFilter vf_crop;
+extern AVFilter vf_passthrough;
+extern AVFilter vo_sdl;

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Fri Jun 29 19:07:44 2007
@@ -24,6 +24,7 @@
 #include <stdio.h>
 
 #include "avfilter.h"
+#include "allfilters.h"
 
 /** list of registered filters, sorted by name */
 static int filter_count = 0;
@@ -184,6 +185,10 @@ void avfilter_register(AVFilter *filter)
 
 void avfilter_init(void)
 {
+    avfilter_register(&vsrc_dummy);
+    avfilter_register(&vf_crop);
+    avfilter_register(&vf_passthrough);
+    avfilter_register(&vo_sdl);
 }
 
 void avfilter_uninit(void)

Added: libavfilter/vf_crop.c
==============================================================================
--- (empty file)
+++ libavfilter/vf_crop.c	Fri Jun 29 19:07:44 2007
@@ -0,0 +1,138 @@
+/*
+ * Video crop filter
+ * 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 <string.h>
+#include <stdio.h>
+
+#include "avfilter.h"
+
+typedef struct
+{
+    int x, y, w, h;
+} CropContext;
+
+static int init(AVFilterContext *ctx)
+{
+    CropContext *crop = ctx->priv;
+
+    if(ctx->inputs[0]->format != PIX_FMT_RGB24) {
+        av_log(ctx, AV_LOG_FATAL, "unsupported input format\n");
+        return -1;
+    }
+
+    crop->x = 20;
+    crop->y = 15;
+    crop->w = 467;
+    crop->h = 45;
+
+    return 0;
+}
+
+static int set_video_props(AVFilterLink *link)
+{
+    CropContext *crop = link->src->priv;
+
+    link->w = crop->w;
+    link->h = crop->h;
+    link->format = link->src->inputs[0]->format;
+
+    return 0;
+}
+
+static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
+{
+    CropContext *crop = link->dst->priv;
+    AVFilterPicRef *ref2 = avfilter_ref_pic(picref);
+
+    ref2->w = crop->w;
+    ref2->h = crop->h;
+    ref2->data[0] += crop->y * ref2->pic->linesize[0];
+    ref2->data[0] += 3 * crop->x;
+
+    av_log(link->dst, AV_LOG_INFO, "start_frame()\n");
+    avfilter_default_start_frame(link, picref);
+
+    avfilter_start_frame(link->dst->outputs[0], ref2);
+}
+
+static void end_frame(AVFilterLink *link)
+{
+    avfilter_default_end_frame(link);
+
+    av_log(link->dst, AV_LOG_INFO, "end_frame()\n");
+    avfilter_end_frame(link->dst->outputs[0]);
+}
+
+static void draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h)
+{
+    AVFilterContext *ctx = link->dst;
+    AVFilterPic *pic = link->cur_pic->pic;
+    CropContext *crop = ctx->priv;
+
+    uint8_t *src[4];
+    int top = y;
+    int height = h;
+
+    av_log(link->dst, AV_LOG_INFO, "draw_slice()\n");
+
+    if(y >= crop->y + crop->h || y + h <= crop->y) return;
+
+    memcpy(src, data, sizeof(uint8_t *) * 4);
+
+    if(top < crop->y) {
+        height -=  crop->y - top;
+        src[0] += (crop->y - top) * pic->linesize[0];
+        top     =  crop->y;
+    }
+    if(top + height > crop->y + crop->h)
+        height = crop->y + crop->h - top;
+    src[0] += 3 * crop->x;
+
+    avfilter_draw_slice(ctx->outputs[0], src, top - crop->y, height);
+}
+
+/* XXX: maybe make the default implementation do this? */
+static void request_frame(AVFilterLink *link)
+{
+    avfilter_request_frame(link->src->inputs[0]);
+}
+
+AVFilter vf_crop =
+{
+    .name      = "crop",
+    .author    = "Bobby Bingham",
+    .priv_size = sizeof(CropContext),
+
+    .init      = init,
+
+    .inputs    = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .start_frame     = start_frame,
+                                    .draw_slice      = draw_slice,
+                                    .end_frame       = end_frame, },
+                                  { .name = NULL}},
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .request_frame   = request_frame,
+                                    .set_video_props = set_video_props},
+                                  { .name = NULL}},
+};
+

Added: libavfilter/vf_expand.c
==============================================================================
--- (empty file)
+++ libavfilter/vf_expand.c	Fri Jun 29 19:07:44 2007
@@ -0,0 +1,24 @@
+#include "avfilter.h"
+
+typedef struct
+{
+    unsigned expw, exph;
+} priv_t;
+
+AVFrame *get_buffer(AVFilterContext *ctx, unsigned w, unsigned h, int fmt)
+{
+    priv_t *p = ctx->priv;
+    AVFrame *buf;
+
+    if((buf = ctx->out->dst->filt->get_buffer(p->expw, p->exph, fmt))) {
+    }
+
+    return buf;
+}
+
+AVFilter vf_expand =
+{
+    .name = "expand",
+    .author = "Bobby Bingham",
+    .get_buffer = get_buffer,
+};

Added: libavfilter/vf_passthrough.c
==============================================================================
--- (empty file)
+++ libavfilter/vf_passthrough.c	Fri Jun 29 19:07:44 2007
@@ -0,0 +1,72 @@
+/*
+ * Video passthrough filter
+ * 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 <string.h>
+#include <stdio.h>
+
+#include "avfilter.h"
+
+static int set_video_props(AVFilterLink *link)
+{
+    link->w      = link->src->inputs[0]->w;
+    link->h      = link->src->inputs[0]->h;
+    link->format = link->src->inputs[0]->format;
+    return 0;
+}
+
+static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
+{
+    avfilter_start_frame(link->dst->outputs[0], picref);
+}
+
+static void end_frame(AVFilterLink *link)
+{
+    avfilter_end_frame(link->dst->outputs[0]);
+}
+
+static void draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h)
+{
+    avfilter_draw_slice(link->dst->outputs[0], data, y, h);
+}
+
+static void request_frame(AVFilterLink *link)
+{
+    avfilter_request_frame(link->src->inputs[0]);
+}
+
+AVFilter vf_passthrough =
+{
+    .name      = "passthrough",
+    .author    = "Bobby Bingham",
+
+    .inputs    = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .start_frame     = start_frame,
+                                    .draw_slice      = draw_slice,
+                                    .end_frame       = end_frame, },
+                                  { .name = NULL}},
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .request_frame   = request_frame,
+                                    .set_video_props = set_video_props},
+                                  { .name = NULL}},
+};
+

Added: libavfilter/vo_sdl.c
==============================================================================
--- (empty file)
+++ libavfilter/vo_sdl.c	Fri Jun 29 19:07:44 2007
@@ -0,0 +1,124 @@
+/*
+ * SDL video output filter
+ * 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
+ */
+
+/* TODO: right now only rgb24 supported for testing.  add more formats */
+
+#include <SDL/SDL.h>
+
+#include "avfilter.h"
+
+typedef struct
+{
+    SDL_Surface *surface;
+} SDLContext;
+
+static int init(AVFilterContext *ctx)
+{
+    SDLContext *sdl = ctx->priv;
+
+    if(ctx->inputs[0]->format != PIX_FMT_RGB24) {
+        av_log(ctx, AV_LOG_FATAL, "unsupported input format\n");
+        return -1;
+    }
+
+    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE)) {
+        av_log(ctx, AV_LOG_FATAL, "unable to initialize SDL: %s\n",
+               SDL_GetError());
+        return -1;
+    }
+
+    sdl->surface = SDL_SetVideoMode(ctx->inputs[0]->w,
+                                    ctx->inputs[0]->h,
+                                    24, SDL_HWSURFACE | SDL_DOUBLEBUF);
+
+    return 0;
+}
+
+static void uninit(AVFilterContext *ctx)
+{
+    SDL_QuitSubSystem(SDL_INIT_VIDEO);
+}
+
+static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
+{
+    SDLContext *sdl = link->dst->priv;
+    avfilter_default_start_frame(link, picref);
+    SDL_LockSurface(sdl->surface);
+
+    av_log(link->dst, AV_LOG_INFO, "start_frame()\n");
+}
+
+static void draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h)
+{
+    AVFilterPicRef *picref = link->cur_pic;
+    SDLContext *sdl = link->dst->priv;
+
+    uint8_t *src = data[0];
+    uint8_t *dst = &((uint8_t *)sdl->surface->pixels)[y * sdl->surface->pitch];
+    int copysize = 3 * link->w;
+
+    int i;
+
+    for(i = 0; i < h; i ++) {
+        memcpy(dst, src, copysize);
+        src += picref->pic->linesize[0];
+        dst += sdl->surface->pitch;
+    }
+
+    av_log(link->dst, AV_LOG_INFO, "draw_slice()\n");
+}
+
+static void end_frame(AVFilterLink *link)
+{
+    SDLContext *sdl = link->dst->priv;
+    SDL_UnlockSurface(sdl->surface);
+    avfilter_default_end_frame(link);
+
+    av_log(link->dst, AV_LOG_INFO, "end_frame()\n");
+}
+
+/* XXX: this is a hack.  should provide a proper vout interface */
+void sdl_display(AVFilterContext *ctx)
+{
+    SDLContext *sdl = ctx->priv;
+
+    SDL_Flip(sdl->surface);
+    avfilter_request_frame(ctx->inputs[0]);
+}
+
+AVFilter vo_sdl =
+{
+    .name      = "sdl",
+    .author    = "Bobby Bingham",
+    .priv_size = sizeof(SDLContext),
+
+    .init      = init,
+    .uninit    = uninit,
+
+    .inputs    = (AVFilterPad[]) {{ .name        = "default",
+                                    .type        = AV_PAD_VIDEO,
+                                    .start_frame = start_frame,
+                                    .end_frame   = end_frame,
+                                    .draw_slice  = draw_slice, },
+                                  { .name = NULL}},
+    .outputs   = (AVFilterPad[]) {{ .name = NULL}},
+};
+

Added: libavfilter/vsrc_dummy.c
==============================================================================
--- (empty file)
+++ libavfilter/vsrc_dummy.c	Fri Jun 29 19:07:44 2007
@@ -0,0 +1,79 @@
+/*
+ * Dummy 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"
+
+#define RED     0x20
+#define GREEN   0x60
+#define BLUE    0xC0
+
+static int set_video_props(AVFilterLink *link)
+{
+    link->w = 640;
+    link->h = 480;
+    link->format = PIX_FMT_RGB24;
+
+    return 0;
+}
+
+static void request_frame(AVFilterLink *link)
+{
+    AVFilterPicRef *pic;
+
+    int x, y;
+    uint8_t *row, *cur;
+
+    pic = avfilter_get_video_buffer(link, AV_PERM_WRITE);
+    avfilter_start_frame(link, avfilter_ref_pic(pic));
+
+    row = pic->data[0];
+    for(y = 0; y < pic->h; y ++) {
+        cur = row;
+        for(x = 0; x < pic->w; x ++) {
+            *cur ++ = BLUE;
+            *cur ++ = GREEN;
+            *cur ++ = RED;
+        }
+        row += pic->pic->linesize[0];
+    }
+
+    avfilter_draw_slice(link, pic->data, 0, pic->h);
+
+    avfilter_end_frame(link);
+    avfilter_unref_pic(pic);
+}
+
+AVFilter vsrc_dummy =
+{
+    .name      = "dummy",
+    .author    = "Bobby Bingham",
+    .priv_size = 0,
+
+    .inputs    = (AVFilterPad[]) {{ .name = NULL }},
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = AV_PAD_VIDEO,
+                                    .request_frame   = request_frame,
+                                    .set_video_props = set_video_props, },
+                                  { .name = NULL}},
+};
+



More information about the FFmpeg-soc mailing list