[FFmpeg-soc] [soc]: r348 - in libavfilter: avfilter.c avfilter.h vf_crop.c vf_rgb2bgr.c

koorogi subversion at mplayerhq.hu
Sun Jul 8 18:48:15 CEST 2007


Author: koorogi
Date: Sun Jul  8 18:48:15 2007
New Revision: 348

Log:
Adjust the default start_frame() and end_frame() implementations to simplify
the implementation of simple filters.


Modified:
   libavfilter/avfilter.c
   libavfilter/avfilter.h
   libavfilter/vf_crop.c
   libavfilter/vf_rgb2bgr.c

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Sun Jul  8 18:48:15 2007
@@ -64,13 +64,28 @@ AVFilterPicRef *avfilter_default_get_vid
 
 void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
 {
+    AVFilterLink *out = link->dst->outputs[0];
+
     link->cur_pic = picref;
+
+    if(out) {
+        out->outpic  = avfilter_get_video_buffer(out, AV_PERM_WRITE);
+        avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0));
+    }
 }
 
 void avfilter_default_end_frame(AVFilterLink *link)
 {
+    AVFilterLink *out = link->dst->outputs[0];
+
     avfilter_unref_pic(link->cur_pic);
     link->cur_pic = NULL;
+
+    if(out) {
+        avfilter_unref_pic(out->outpic);
+        out->outpic = NULL;
+        avfilter_end_frame(out);
+    }
 }
 
 AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref, int pmask)

Modified: libavfilter/avfilter.h
==============================================================================
--- libavfilter/avfilter.h	(original)
+++ libavfilter/avfilter.h	Sun Jul  8 18:48:15 2007
@@ -196,6 +196,7 @@ struct AVFilterLink
     enum PixelFormat format;
 
     AVFilterPicRef *cur_pic;
+    AVFilterPicRef *outpic;
 };
 
 /** Link two filters together */

Modified: libavfilter/vf_crop.c
==============================================================================
--- libavfilter/vf_crop.c	(original)
+++ libavfilter/vf_crop.c	Sun Jul  8 18:48:15 2007
@@ -87,14 +87,15 @@ static void start_frame(AVFilterLink *li
     ref2->data[0] += crop->cx * 3;
 
     av_log(link->dst, AV_LOG_INFO, "start_frame()\n");
-    avfilter_default_start_frame(link, picref);
+    link->cur_pic = picref;
 
     avfilter_start_frame(link->dst->outputs[0], ref2);
 }
 
 static void end_frame(AVFilterLink *link)
 {
-    avfilter_default_end_frame(link);
+    avfilter_unref_pic(link->cur_pic);
+    link->cur_pic = NULL;
 
     av_log(link->dst, AV_LOG_INFO, "end_frame()\n");
     avfilter_end_frame(link->dst->outputs[0]);

Modified: libavfilter/vf_rgb2bgr.c
==============================================================================
--- libavfilter/vf_rgb2bgr.c	(original)
+++ libavfilter/vf_rgb2bgr.c	Sun Jul  8 18:48:15 2007
@@ -24,10 +24,6 @@
 
 #include "avfilter.h"
 
-typedef struct {
-    AVFilterPicRef *out;
-} RGBContext;
-
 static int *query_in_formats(AVFilterLink *link)
 {
     return avfilter_make_format_list(2, PIX_FMT_RGB24, PIX_FMT_BGR24);
@@ -45,35 +41,15 @@ static int *query_out_formats(AVFilterLi
     return avfilter_make_format_list(1, format);
 }
 
-static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
-{
-    RGBContext *rgb = link->dst->priv;
-
-    rgb->out = avfilter_get_video_buffer(link->dst->outputs[0], AV_PERM_WRITE);
-    avfilter_default_start_frame(link, picref);
-    avfilter_start_frame(link->dst->outputs[0], avfilter_ref_pic(rgb->out, ~0));
-}
-
-static void end_frame(AVFilterLink *link)
-{
-    RGBContext *rgb = link->dst->priv;
-
-    avfilter_unref_pic(rgb->out);
-    rgb->out = NULL;
-
-    avfilter_default_end_frame(link);
-    avfilter_end_frame(link->dst->outputs[0]);
-}
-
 static void draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h)
 {
-    RGBContext *rgb = link->dst->priv;
+    AVFilterPicRef *outpic = link->dst->outputs[0]->outpic;
     uint8_t *out[4];
     uint8_t *row[2], *cur[2];
     int i, j;
 
     row[0] = data[0];
-    row[1] = out[0] = &rgb->out->data[0][y * rgb->out->linesize[0]];
+    row[1] = out[0] = &outpic->data[0][y * outpic->linesize[0]];
     out[1] = out[2] = out[3] = 0;
     for(i = 0; i < h; i ++) {
         cur[0] = row[0];
@@ -87,7 +63,7 @@ static void draw_slice(AVFilterLink *lin
             cur[1] += 3;
         }
         row[0] += link->cur_pic->linesize[0];
-        row[1] += rgb->out->     linesize[0];
+        row[1] += outpic->       linesize[0];
     }
     avfilter_draw_slice(link->dst->outputs[0], out, y, h);
 }
@@ -104,10 +80,8 @@ AVFilter vf_rgb2bgr =
 
     .inputs    = (AVFilterPad[]) {{ .name            = "default",
                                     .type            = AV_PAD_VIDEO,
-                                    .start_frame     = start_frame,
                                     .draw_slice      = draw_slice,
-                                    .query_formats   = query_in_formats,
-                                    .end_frame       = end_frame, },
+                                    .query_formats   = query_in_formats, },
                                   { .name = NULL}},
     .outputs   = (AVFilterPad[]) {{ .name            = "default",
                                     .type            = AV_PAD_VIDEO,



More information about the FFmpeg-soc mailing list