[FFmpeg-cvslog] lavfi: Add support for increasing hardware frame pool sizes

Mark Thompson git at videolan.org
Tue Feb 13 00:28:45 EET 2018


ffmpeg | branch: master | Mark Thompson <sw at jkqxz.net> | Mon Mar 27 21:10:53 2017 +0100| [6d86cef06ba36c0ed591e14a2382e9630059fc5d] | committer: Mark Thompson

lavfi: Add support for increasing hardware frame pool sizes

AVFilterContext.extra_hw_frames functions identically to the field of
the same name in AVCodecContext.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6d86cef06ba36c0ed591e14a2382e9630059fc5d
---

 doc/APIchanges         |  3 +++
 libavfilter/avfilter.c | 23 +++++++++++++++++++++++
 libavfilter/avfilter.h | 16 ++++++++++++++++
 libavfilter/internal.h | 17 +++++++++++++++++
 libavfilter/version.h  |  2 +-
 5 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index d62f7674f3..d385d73b0c 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2017-03-23
 
 API changes, most recent first:
 
+2018-02-xx - xxxxxxx - lavfi 7.1.0 - avfilter.h
+  Add AVFilterContext.extra_hw_frames.
+
 2018-02-xx - xxxxxxx - lavc 58.9.0 - avcodec.h
   Add AVCodecContext.extra_hw_frames.
 
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 83c1a7c20d..2c4a385ea9 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -368,6 +368,8 @@ static const AVOption avfilter_options[] = {
     { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
         { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
         { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .unit = "thread_type" },
+    { "extra_hw_frames", "Number of extra hardware frames to allocate for the user",
+        OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
     { NULL },
 };
 
@@ -707,3 +709,24 @@ const AVClass *avfilter_get_class(void)
 {
     return &avfilter_class;
 }
+
+int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
+                             int default_pool_size)
+{
+    AVHWFramesContext *frames;
+
+    // Must already be set by caller.
+    av_assert0(link->hw_frames_ctx);
+
+    frames = (AVHWFramesContext*)link->hw_frames_ctx->data;
+
+    if (frames->initial_pool_size == 0) {
+        // Dynamic allocation is necessarily supported.
+    } else if (avctx->extra_hw_frames >= 0) {
+        frames->initial_pool_size += avctx->extra_hw_frames;
+    } else {
+        frames->initial_pool_size = default_pool_size;
+    }
+
+    return 0;
+}
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 6df69dbbbf..46dbadfcdc 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -311,6 +311,22 @@ struct AVFilterContext {
      * hardware context information.
      */
     AVBufferRef *hw_device_ctx;
+
+    /**
+     * Sets the number of extra hardware frames which the filter will
+     * allocate on its output links for use in following filters or by
+     * the caller.
+     *
+     * Some hardware filters require all frames that they will use for
+     * output to be defined in advance before filtering starts.  For such
+     * filters, any hardware frame pools used for output must therefore be
+     * of fixed size.  The extra frames set here are on top of any number
+     * that the filter needs internally in order to operate normally.
+     *
+     * This field must be set before the graph containing this filter is
+     * configured.
+     */
+    int extra_hw_frames;
 };
 
 /**
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index a377f9b2ba..dd021e00a1 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -226,4 +226,21 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter
  */
 #define FF_FILTER_FLAG_HWFRAME_AWARE (1 << 0)
 
+/**
+ * Perform any additional setup required for hardware frames.
+ *
+ * link->hw_frames_ctx must be set before calling this function.
+ * Inside link->hw_frames_ctx, the fields format, sw_format, width and
+ * height must be set.  If dynamically allocated pools are not supported,
+ * then initial_pool_size must also be set, to the minimum hardware frame
+ * pool size necessary for the filter to work (taking into account any
+ * frames which need to stored for use in operations as appropriate).  If
+ * default_pool_size is nonzero, then it will be used as the pool size if
+ * no other modification takes place (this can be used to preserve
+ * compatibility).
+ */
+int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
+                             int default_pool_size);
+
+
 #endif /* AVFILTER_INTERNAL_H */
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 62fc97dd27..00e9bf7a99 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  7
-#define LIBAVFILTER_VERSION_MINOR  0
+#define LIBAVFILTER_VERSION_MINOR  1
 #define LIBAVFILTER_VERSION_MICRO  0
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list