FFmpeg
vulkan_video.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVCODEC_VULKAN_VIDEO_H
20 #define AVCODEC_VULKAN_VIDEO_H
21 
22 #include "avcodec.h"
23 #include "libavutil/vulkan.h"
24 
25 #include <vk_video/vulkan_video_codecs_common.h>
26 
27 #define CODEC_VER_MAJ(ver) (ver >> 22)
28 #define CODEC_VER_MIN(ver) ((ver >> 12) & ((1 << 10) - 1))
29 #define CODEC_VER_PAT(ver) (ver & ((1 << 12) - 1))
30 #define CODEC_VER(ver) CODEC_VER_MAJ(ver), CODEC_VER_MIN(ver), CODEC_VER_PAT(ver)
31 
32 typedef struct FFVkVideoSession {
33  VkVideoSessionKHR session;
34  VkDeviceMemory *mem;
35  uint32_t nb_mem;
36 
37  VkSamplerYcbcrConversion yuv_sampler;
38 
42  VkImageView layered_view;
43  VkImageAspectFlags layered_aspect;
44 } FFVkVideoCommon;
45 
46 /**
47  * Get pixfmt from a Vulkan format.
48  */
50 
51 /**
52  * Get aspect bits which include all planes from a VkFormat.
53  */
54 VkImageAspectFlags ff_vk_aspect_bits_from_vkfmt(VkFormat vkf);
55 
56 /**
57  * Get Vulkan's chroma subsampling from a pixfmt descriptor.
58  */
59 VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFmtDescriptor *desc);
60 
61 /**
62  * Get Vulkan's bit depth from an [8:12] integer.
63  */
64 VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth);
65 
66 /**
67  * Chooses a QF and loads it into a context.
68  */
70  VkQueueFlagBits family, VkVideoCodecOperationFlagBitsKHR caps);
71 
72 /**
73  * Convert level from Vulkan to AV.
74  */
75 int ff_vk_h264_level_to_av(StdVideoH264LevelIdc level);
76 int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level);
77 
78 StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc);
79 StdVideoH265LevelIdc ff_vk_h265_level_to_vk(int level_idc);
80 
81 /**
82  * Convert profile from/to AV to Vulkan
83  */
84 StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile);
85 StdVideoH265ProfileIdc ff_vk_h265_profile_to_vk(int profile);
86 int ff_vk_h264_profile_to_av(StdVideoH264ProfileIdc profile);
87 int ff_vk_h265_profile_to_av(StdVideoH264ProfileIdc profile);
88 
89 /**
90  * Creates image views for video frames.
91  */
92 int ff_vk_create_view(FFVulkanContext *s, FFVkVideoCommon *common,
93  VkImageView *view, VkImageAspectFlags *aspect,
94  AVVkFrame *src, VkFormat vkf, int is_dpb);
95 
96 /**
97  * Initialize video session, allocating and binding necessary memory.
98  */
100  FFVkVideoCommon *common,
101  VkVideoSessionCreateInfoKHR *session_create);
102 
103 /**
104  * Free video session and required resources.
105  */
106 void ff_vk_video_common_uninit(FFVulkanContext *s, FFVkVideoCommon *common);
107 
108 #endif /* AVCODEC_VULKAN_VIDEO_H */
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
level
uint8_t level
Definition: svq3.c:205
FFVkVideoSession::layered_view
VkImageView layered_view
Definition: vulkan_video.h:42
ff_vk_h265_profile_to_av
int ff_vk_h265_profile_to_av(StdVideoH264ProfileIdc profile)
Definition: vulkan_video.c:261
FFVkVideoSession::yuv_sampler
VkSamplerYcbcrConversion yuv_sampler
Definition: vulkan_video.h:37
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
level_idc
int level_idc
Definition: h264_levels.c:29
ff_vk_h264_level_to_vk
StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc)
Definition: vulkan_video.c:165
FFVkVideoSession::mem
VkDeviceMemory * mem
Definition: vulkan_video.h:34
FFVkVideoSession
Definition: vulkan_video.h:32
FFVkVideoSession::dpb_hwfc_ref
AVBufferRef * dpb_hwfc_ref
Definition: vulkan_video.h:39
ff_vk_h265_level_to_av
int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level)
Definition: vulkan_video.c:191
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_vk_h265_profile_to_vk
StdVideoH265ProfileIdc ff_vk_h265_profile_to_vk(int profile)
Definition: vulkan_video.c:240
ff_vk_h265_level_to_vk
StdVideoH265LevelIdc ff_vk_h265_level_to_vk(int level_idc)
Definition: vulkan_video.c:210
ff_vk_h264_profile_to_vk
StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile)
Convert profile from/to AV to Vulkan.
Definition: vulkan_video.c:229
FFVkVideoSession::session
VkVideoSessionKHR session
Definition: vulkan_video.h:33
ff_vk_video_qf_init
int ff_vk_video_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkQueueFlagBits family, VkVideoCodecOperationFlagBitsKHR caps)
Chooses a QF and loads it into a context.
Definition: vulkan_video.c:271
FFVkVideoSession::layered_dpb
int layered_dpb
Definition: vulkan_video.h:40
FFVulkanContext
Definition: vulkan.h:268
ff_vk_pix_fmt_from_vkfmt
enum AVPixelFormat ff_vk_pix_fmt_from_vkfmt(VkFormat vkf)
Get pixfmt from a Vulkan format.
Definition: vulkan_video.c:99
ff_vk_aspect_bits_from_vkfmt
VkImageAspectFlags ff_vk_aspect_bits_from_vkfmt(VkFormat vkf)
Get aspect bits which include all planes from a VkFormat.
Definition: vulkan_video.c:107
FFVkVideoSession::layered_frame
AVFrame * layered_frame
Definition: vulkan_video.h:41
ff_vk_video_common_init
int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s, FFVkVideoCommon *common, VkVideoSessionCreateInfoKHR *session_create)
Initialize video session, allocating and binding necessary memory.
Definition: vulkan_video.c:359
AVVkFrame
Definition: hwcontext_vulkan.h:302
vulkan.h
FFVkQueueFamilyCtx
Definition: vulkan.h:102
ff_vk_subsampling_from_av_desc
VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFmtDescriptor *desc)
Get Vulkan's chroma subsampling from a pixfmt descriptor.
Definition: vulkan_video.c:115
VkFormat
enum VkFormat VkFormat
Definition: hwcontext_stub.c:25
ff_vk_create_view
int ff_vk_create_view(FFVulkanContext *s, FFVkVideoCommon *common, VkImageView *view, VkImageAspectFlags *aspect, AVVkFrame *src, VkFormat vkf, int is_dpb)
Creates image views for video frames.
Definition: vulkan_video.c:285
profile
int profile
Definition: mxfenc.c:2233
avcodec.h
FFVkVideoSession::nb_mem
uint32_t nb_mem
Definition: vulkan_video.h:35
ff_vk_h264_profile_to_av
int ff_vk_h264_profile_to_av(StdVideoH264ProfileIdc profile)
Definition: vulkan_video.c:250
AVCodecContext
main external API structure.
Definition: avcodec.h:451
FFVkVideoSession::layered_aspect
VkImageAspectFlags layered_aspect
Definition: vulkan_video.h:43
desc
const char * desc
Definition: libsvtav1.c:79
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ff_vk_depth_from_av_depth
VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth)
Get Vulkan's bit depth from an [8:12] integer.
Definition: vulkan_video.c:128
ff_vk_h264_level_to_av
int ff_vk_h264_level_to_av(StdVideoH264LevelIdc level)
Convert level from Vulkan to AV.
Definition: vulkan_video.c:139
ff_vk_video_common_uninit
void ff_vk_video_common_uninit(FFVulkanContext *s, FFVkVideoCommon *common)
Free video session and required resources.
Definition: vulkan_video.c:329
src
#define src
Definition: vp8dsp.c:248