[FFmpeg-devel] [PATCH] lavfi: use min_perms and rej_perms for out pads.

Nicolas George nicolas.george at normalesup.org
Sun Aug 12 11:08:30 CEST 2012


There are several reasons for doing that:

1. It documents the code for the reader and helps find
   inconsistencies and bugs.

2. For rej_perms, it guarantees the change will be done
   even if the output reference can be created by several
   code paths.

3. It can be used to predict cases where a copy will,
   or will not happen and optimize buffer allocation
   (for example not request a rare direct-rendering buffer
   from a device sink if it will be copied anyway).

Note that a filter is still allowed to manage the permissions
on its own without using these fields.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/avfilter.h |   11 +++++++++--
 libavfilter/video.c    |    7 ++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)


If this patch is meant to go in, then a later task would be to set the
fields on the existing filters.


diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 54a0b97..b5394b0 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -236,22 +236,29 @@ struct AVFilterPad {
     enum AVMediaType type;
 
     /**
+     * Input pads:
      * Minimum required permissions on incoming buffers. Any buffer with
      * insufficient permissions will be automatically copied by the filter
      * system to a new buffer which provides the needed access permissions.
      *
-     * Input pads only.
+     * Output pads:
+     * Guaranteed permissions on outgoing buffers. Any buffer pushed on the
+     * link must have at least these permissions; this fact is checked by
+     * asserts. It can be used to optimize buffer allocation.
      */
     int min_perms;
 
     /**
+     * Input pads:
      * Permissions which are not accepted on incoming buffers. Any buffer
      * which has any of these permissions set will 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.
+     * Output pads:
+     * Permissions which are automatically removed on outgoing buffers. It
+     * can be used to optimize buffer allocation.
      */
     int rej_perms;
 
diff --git a/libavfilter/video.c b/libavfilter/video.c
index eb92edd..b7a8b86 100644
--- a/libavfilter/video.c
+++ b/libavfilter/video.c
@@ -232,8 +232,9 @@ static void clear_link(AVFilterLink *link)
 int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     int (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
+    AVFilterPad *src = link->srcpad;
     AVFilterPad *dst = link->dstpad;
-    int ret, perms = picref->perms;
+    int ret, perms;
     AVFilterCommand *cmd= link->dst->command_queue;
     int64_t pts;
 
@@ -242,6 +243,10 @@ int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     if (!(start_frame = dst->start_frame))
         start_frame = default_start_frame;
 
+    av_assert1((picref->perms & src->min_perms) == src->min_perms);
+    picref->perms &= ~ src->rej_perms;
+    perms = picref->perms;
+
     if (picref->linesize[0] < 0)
         perms |= AV_PERM_NEG_LINESIZES;
     /* prepare to copy the picture if it has insufficient permissions */
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list