[FFmpeg-devel] [PATCH] lavu: add VKAPI hwcontext implementation

James Almer jamrial at gmail.com
Fri Mar 12 03:03:23 EET 2021


On 3/11/2021 7:09 PM, suji.velupillai at broadcom.com wrote:
> From: Suji Velupillai <suji.velupillai at broadcom.com>
> 
> Initial commit to add VKAPI hardware accelerator implementation.
> The depedency component vkil source code can be obtained from github
> https://github.com/Broadcom/vkil
> 
> Signed-off-by: Suji Velupillai <suji.velupillai at broadcom.com>
> ---
>   configure                      |   8 +-
>   doc/APIchanges                 |   4 +
>   libavutil/Makefile             |   2 +
>   libavutil/hwcontext.c          |   4 +
>   libavutil/hwcontext.h          |   1 +
>   libavutil/hwcontext_internal.h |   1 +
>   libavutil/hwcontext_vkapi.c    | 522 +++++++++++++++++++++++++++++++++
>   libavutil/hwcontext_vkapi.h    | 104 +++++++
>   libavutil/pixdesc.c            |   4 +
>   libavutil/pixfmt.h             |   6 +
>   10 files changed, 655 insertions(+), 1 deletion(-)
>   create mode 100644 libavutil/hwcontext_vkapi.c
>   create mode 100644 libavutil/hwcontext_vkapi.h

[...]

> diff --git a/doc/APIchanges b/doc/APIchanges
> index 13350c0db0..ccab2e6465 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,10 @@ libavutil:     2017-10-21
>   
>   API changes, most recent first:
>   
> +2021-03-11 - xxxxxxxxxx - lavu yy.yy.yyy - hwcontext.h
> +  Add AV_PIX_FMT_VKAPI
> +  Add AV_HWDEVICE_TYPE_VKAPI and implementation.

Should ideally also mention the structs in hwcontext_vkapi.h in some form.

> +
>   2021-03-10 - xxxxxxxxxx - lavf 58.72.100 - avformat.h
>     Change AVBufferRef related AVStream function and struct size
>     parameter and fields type to size_t at next major bump.
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index 27bafe9e12..4044b133a3 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -45,6 +45,7 @@ HEADERS = adler32.h                                                     \
>             hwcontext_vaapi.h                                             \
>             hwcontext_videotoolbox.h                                      \
>             hwcontext_vdpau.h                                             \
> +          hwcontext_vkapi.h                                             \

Add this header to the SKIPHEADERS list below in this file.

>             hwcontext_vulkan.h                                            \
>             imgutils.h                                                    \
>             intfloat.h                                                    \
> @@ -185,6 +186,7 @@ OBJS-$(CONFIG_QSV)                      += hwcontext_qsv.o
>   OBJS-$(CONFIG_VAAPI)                    += hwcontext_vaapi.o
>   OBJS-$(CONFIG_VIDEOTOOLBOX)             += hwcontext_videotoolbox.o
>   OBJS-$(CONFIG_VDPAU)                    += hwcontext_vdpau.o
> +OBJS-$(CONFIG_VKAPI)                    += hwcontext_vkapi.o
>   OBJS-$(CONFIG_VULKAN)                   += hwcontext_vulkan.o
>   
>   OBJS += $(COMPAT_OBJS:%=../compat/%)

[...]

> diff --git a/libavutil/hwcontext_vkapi.h b/libavutil/hwcontext_vkapi.h
> new file mode 100644
> index 0000000000..096602b42e
> --- /dev/null
> +++ b/libavutil/hwcontext_vkapi.h
> @@ -0,0 +1,104 @@
> +/*
> + * Copyright (c) 2018 Broadcom
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#ifndef AVUTIL_HWCONTEXT_VKAPI_H
> +#define AVUTIL_HWCONTEXT_VKAPI_H
> +
> +#include <vkil_api.h>
> +
> +#define VKAPI_METADATA_PLANE 4
> +
> +/**
> + * @file
> + * API-specific header for AV_HWDEVICE_TYPE_VKAPI.
> + */
> +
> +/**
> + * Allocated as AVHWDeviceContext.hwctx
> + */
> +typedef struct VKAPIDeviceContext {

As this is an installed header, all structs and defines must have the AV 
prefix.

> +    /**
> +     * Holds pointers to hardware specific functions
> +     */
> +    vkil_api *ilapi;
> +    /**
> +     * Internal functions definitions
> +     */
> +    /**
> +     * Get the hwprops reference from the AVFrame:data[3]
> +     */
> +    int (*frame_ref_hwprops)(const AVFrame *frame, void *phw_surface_desc);
> +    /**
> +     * Set the hwprops into AVFrame:data[3]
> +     */
> +    int (*frame_set_hwprops)(AVFrame *frame, const vkil_buffer_surface *hw_surface_desc);
> +    /**
> +     * Get the hwprops from AVFrame:data[3]
> +     */
> +    int (*frame_get_hwprops)(const AVFrame *frame, vkil_buffer_surface *hw_surface_desc);
> +    /**
> +     * Check if format is in an array
> +     */
> +    int (*fmt_is_in)(int fmt, const int *fmts);
> +    /**
> +     * Convert AVPixelFormat to VKAPI equivalent pixel format
> +     */
> +    int (*av2vk_fmt)(enum AVPixelFormat pixel_format);
> +    /**
> +     * Get no of buffer count reference in the hardware pool
> +     */
> +    int (*get_pool_occupancy)(AVHWFramesContext *ctx);
> +} VKAPIDeviceContext;
> +
> +/**
> + * Contains color information for hardware
> + */
> +typedef struct VKAPIColorContext {
> +    enum AVColorRange range;
> +    enum AVColorPrimaries primaries;
> +    enum AVColorTransferCharacteristic trc;
> +    enum AVColorSpace space;
> +    enum AVChromaLocation chroma_location;
> +} VKAPIColorContext;
> +
> +/**
> + * Allocated as AVHWFramesContext.hwctx
> + */
> +typedef struct VKAPIFramesContext {
> +    /**
> +     * Handle to a hardware frame context
> +     */
> +    uint32_t handle;
> +    /**
> +     * Hardware component port associated to the frame context
> +     */
> +    uint32_t port_id;
> +    uint32_t extra_port_id;
> +    /**
> +     * Color information
> +     */
> +    VKAPIColorContext color;
> +    /**
> +     * ilcontext associated to the frame context
> +     */
> +    vkil_context *ilctx;
> +} VKAPIFramesContext;
> +
> +#endif /* AVUTIL_HWCONTEXT_VKAPI_H */
> diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
> index 2a919461a5..1d2f242e57 100644
> --- a/libavutil/pixdesc.c
> +++ b/libavutil/pixdesc.c
> @@ -2391,6 +2391,10 @@ static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
>           },
>           .flags = AV_PIX_FMT_FLAG_PLANAR,
>       },
> +    [AV_PIX_FMT_VKAPI] = {
> +        .name = "vkapi",
> +        .flags = AV_PIX_FMT_FLAG_HWACCEL,
> +    },
>       [AV_PIX_FMT_VULKAN] = {
>           .name = "vulkan",
>           .flags = AV_PIX_FMT_FLAG_HWACCEL,
> diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
> index 46ef211add..3ae607a3d6 100644
> --- a/libavutil/pixfmt.h
> +++ b/libavutil/pixfmt.h
> @@ -348,6 +348,12 @@ enum AVPixelFormat {
>       AV_PIX_FMT_NV24,      ///< planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V)
>       AV_PIX_FMT_NV42,      ///< as above, but U and V bytes are swapped
>   
> +    /**
> +     * VKAPI hardware acceleration.
> +     * data[3] contains a pointer to the vkil_buffer_surface structure
> +     */
> +    AV_PIX_FMT_VKAPI,

New values must always be added at the end, right before AV_PIX_FMT_NB, 
to not break ABI.

> +
>       /**
>        * Vulkan hardware images.
>        *
> 



More information about the ffmpeg-devel mailing list