[libav-devel] [PATCH 1/8] lavfi: Add support for modifying hardware frame pool sizes

wm4 nfxjfg at googlemail.com
Sat Jan 27 00:34:39 CET 2018


On Fri, 26 Jan 2018 23:13:36 +0000
Mark Thompson <sw at jkqxz.net> wrote:

> AVFilterContext.extra_hw_frames functions identically to the field of
> the same name in AVCodecContext.
> ---
>  doc/APIchanges         |  3 +++
>  libavfilter/avfilter.c | 23 +++++++++++++++++++++++
>  libavfilter/avfilter.h | 13 +++++++++++++
>  libavfilter/internal.h | 16 ++++++++++++++++
>  4 files changed, 55 insertions(+)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 0bde3a052..645ac231a 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,9 @@ libavutil:     2017-03-23
>  
>  API changes, most recent first:
>  
> +2018-xx-xx - xxxxxxx - lavfi 7.x+1.0 - avfilter.h
> +  Add AVFilterContext.extra_hw_frames.
> +
>  2017-xx-xx - xxxxxxx - lavc 58.8.0 - avcodec.h
>    Add const to AVCodecContext.hwaccel.
>  
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 83c1a7c20..2c4a385ea 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 6df69dbbb..c8f861076 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -311,6 +311,19 @@ 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.
> +     */
> +    int extra_hw_frames;

Should clarify _when_ this field can be set (I assume before the filter
graph is configured).


More information about the libav-devel mailing list