[FFmpeg-soc] [soc]: r915 - in libavfilter: avfilter.c avfilter.h defaults.c vf_crop.c vf_overlay.c vf_rgb2bgr.c vf_vflip.c

koorogi subversion at mplayerhq.hu
Fri Aug 17 18:40:27 CEST 2007


Author: koorogi
Date: Fri Aug 17 18:40:26 2007
New Revision: 915

Log:
Allow filters to set the requirements on permissions for incoming buffers.


Modified:
   libavfilter/avfilter.c
   libavfilter/avfilter.h
   libavfilter/defaults.c
   libavfilter/vf_crop.c
   libavfilter/vf_overlay.c
   libavfilter/vf_rgb2bgr.c
   libavfilter/vf_vflip.c

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Fri Aug 17 18:40:26 2007
@@ -82,13 +82,12 @@ int avfilter_link(AVFilterContext *src, 
         return -1;
 
     src->outputs[srcpad] =
-    dst->inputs[dstpad]  = link = av_malloc(sizeof(AVFilterLink));
+    dst->inputs[dstpad]  = link = av_mallocz(sizeof(AVFilterLink));
 
     link->src     = src;
     link->dst     = dst;
     link->srcpad  = srcpad;
     link->dstpad  = dstpad;
-    link->cur_pic = NULL;
     link->format  = -1;
 
     return 0;
@@ -167,13 +166,34 @@ void avfilter_start_frame(AVFilterLink *
     if(!start_frame)
         start_frame = avfilter_default_start_frame;
 
-    start_frame(link, picref);
+    /* prepare to copy the picture if it has insufficient permissions */
+    if((link_dpad(link).min_perms & picref->perms) != link_dpad(link).min_perms ||
+        link_dpad(link).rej_perms & picref->perms) {
+        av_log(link->dst, AV_LOG_INFO,
+                "frame copy needed (have perms %x, need %x, reject %x)\n",
+                picref->perms,
+                link_dpad(link).min_perms, link_dpad(link).rej_perms);
+
+        link->cur_pic = avfilter_default_get_video_buffer(link, link_dpad(link).min_perms);
+        link->srcpic = picref;
+    }
+    else
+        link->cur_pic = picref;
+
+    start_frame(link, link->cur_pic);
 }
 
 void avfilter_end_frame(AVFilterLink *link)
 {
     void (*end_frame)(AVFilterLink *);
 
+    /* unreference the source picture if we're feeding the destination filter
+     * a copied version dues to permission issues */
+    if(link->srcpic) {
+        avfilter_unref_pic(link->srcpic);
+        link->srcpic = NULL;
+    }
+
     end_frame = link_dpad(link).end_frame;
     if(!end_frame)
         end_frame = avfilter_default_end_frame;
@@ -183,6 +203,38 @@ void avfilter_end_frame(AVFilterLink *li
 
 void avfilter_draw_slice(AVFilterLink *link, int y, int h)
 {
+    uint8_t *src[4], *dst[4];
+    int i, j, hsub, vsub;
+
+    /* copy the slice if needed for permission reasons */
+    if(link->srcpic) {
+        avcodec_get_chroma_sub_sample(link->format, &hsub, &vsub);
+
+        src[0] = link->srcpic-> data[0] + y * link->srcpic-> linesize[0];
+        dst[0] = link->cur_pic->data[0] + y * link->cur_pic->linesize[0];
+        for(i = 1; i < 4; i ++) {
+            if(link->srcpic->data[i]) {
+                src[i] = link->srcpic-> data[i] + (y >> vsub) * link->srcpic-> linesize[i];
+                dst[i] = link->cur_pic->data[i] + (y >> vsub) * link->cur_pic->linesize[i];
+            } else
+                src[i] = dst[i] = NULL;
+        }
+        for(j = 0; j < h; j ++) {
+            memcpy(dst[0], src[0], link->cur_pic->linesize[0]);
+            src[0] += link->srcpic ->linesize[0];
+            dst[0] += link->cur_pic->linesize[0];
+        }
+        for(i = 1; i < 4; i ++) {
+            if(!src[i]) continue;
+
+            for(j = 0; j < h >> vsub; j ++) {
+                memcpy(dst[i], src[i], link->cur_pic->linesize[i]);
+                src[i] += link->srcpic ->linesize[i];
+                dst[i] += link->cur_pic->linesize[i];
+            }
+        }
+    }
+
     if(!link_dpad(link).draw_slice)
         return;
 

Modified: libavfilter/avfilter.h
==============================================================================
--- libavfilter/avfilter.h	(original)
+++ libavfilter/avfilter.h	Fri Aug 17 18:40:26 2007
@@ -118,6 +118,25 @@ struct AVFilterPad
 #define AV_PAD_VIDEO 0      ///< video pad
 
     /**
+     * Minimum required permissions on incoming buffers.  Any buffers with
+     * insufficient permissions will be automatically copied by the filter
+     * system to a new buffer which provides the needed access permissions.
+     *
+     * Input pads only.
+     */
+    int min_perms;
+
+    /**
+     * Permissions which are not accepted on incoming buffers.  Any buffer
+     * which has any of these permissions set be automatically copied by the
+     * filter system to a new buffer which does not have those permissions.
+     * This can be used to easily disallow buffers with AV_PERM_REUSE.
+     *
+     * Input pads only.
+     */
+    int rej_perms;
+
+    /**
      * Callback to get a list of supported formats.  The returned list should
      * be terminated by -1 (see avfilter_make_format_list for an easy way to
      * create such a list).
@@ -272,6 +291,15 @@ struct AVFilterLink
     int h;                      ///< agreed upon image height
     enum PixelFormat format;    ///< agreed upon image colorspace
 
+    /**
+     * The picture reference currently being sent across the link by the source
+     * filter.  This is used internally by the filter system to allow
+     * automatic copying of pictures which d not have sufficient permissions
+     * for the destination.  This should not be accessed directly by the
+     * filters.
+     */
+    AVFilterPicRef *srcpic;
+
     AVFilterPicRef *cur_pic;
     AVFilterPicRef *outpic;
 };

Modified: libavfilter/defaults.c
==============================================================================
--- libavfilter/defaults.c	(original)
+++ libavfilter/defaults.c	Fri Aug 17 18:40:26 2007
@@ -59,8 +59,6 @@ void avfilter_default_start_frame(AVFilt
     if(link->dst->output_count)
         out = link->dst->outputs[0];
 
-    link->cur_pic = picref;
-
     if(out) {
         out->outpic      = avfilter_get_video_buffer(out, AV_PERM_WRITE);
         out->outpic->pts = picref->pts;

Modified: libavfilter/vf_crop.c
==============================================================================
--- libavfilter/vf_crop.c	(original)
+++ libavfilter/vf_crop.c	Fri Aug 17 18:40:26 2007
@@ -136,8 +136,6 @@ static void start_frame(AVFilterLink *li
         }
     }
 
-    link->cur_pic = picref;
-
     avfilter_start_frame(link->dst->outputs[0], ref2);
 }
 

Modified: libavfilter/vf_overlay.c
==============================================================================
--- libavfilter/vf_overlay.c	(original)
+++ libavfilter/vf_overlay.c	Fri Aug 17 18:40:26 2007
@@ -231,14 +231,18 @@ AVFilter vf_overlay =
                                     .draw_slice      = draw_slice,
                                     .query_formats   = query_formats_main,
                                     .config_props    = config_input_main,
-                                    .end_frame       = end_frame, },
+                                    .end_frame       = end_frame,
+                                    .min_perms       = AV_PERM_READ,
+                                    .rej_perms       = AV_PERM_REUSE, },
                                   { .name            = "sub",
                                     .type            = AV_PAD_VIDEO,
                                     .start_frame     = start_frame,
                                     .draw_slice      = draw_slice,
                                     .query_formats   = query_formats_sub,
                                     .config_props    = config_input_sub,
-                                    .end_frame       = end_frame, },
+                                    .end_frame       = end_frame,
+                                    .min_perms       = AV_PERM_READ,
+                                    .rej_perms       = AV_PERM_REUSE, },
                                   { .name = NULL}},
     .outputs   = (AVFilterPad[]) {{ .name            = "default",
                                     .type            = AV_PAD_VIDEO,

Modified: libavfilter/vf_rgb2bgr.c
==============================================================================
--- libavfilter/vf_rgb2bgr.c	(original)
+++ libavfilter/vf_rgb2bgr.c	Fri Aug 17 18:40:26 2007
@@ -75,7 +75,8 @@ AVFilter vf_rgb2bgr =
     .inputs    = (AVFilterPad[]) {{ .name            = "default",
                                     .type            = AV_PAD_VIDEO,
                                     .draw_slice      = draw_slice,
-                                    .query_formats   = query_in_formats, },
+                                    .query_formats   = query_in_formats,
+                                    .min_perms       = AV_PERM_READ, },
                                   { .name = NULL}},
     .outputs   = (AVFilterPad[]) {{ .name            = "default",
                                     .type            = AV_PAD_VIDEO,

Modified: libavfilter/vf_vflip.c
==============================================================================
--- libavfilter/vf_vflip.c	(original)
+++ libavfilter/vf_vflip.c	Fri Aug 17 18:40:26 2007
@@ -73,8 +73,6 @@ static void start_frame(AVFilterLink *li
         }
     }
 
-    link->cur_pic = picref;
-
     avfilter_start_frame(link->dst->outputs[0], ref2);
 }
 



More information about the FFmpeg-soc mailing list