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 
40  VkImageView layered_view;
41  VkImageAspectFlags layered_aspect;
42 } FFVkVideoCommon;
43 
44 /**
45  * Get pixfmt from a Vulkan format.
46  */
48 
49 /**
50  * Get aspect bits which include all planes from a VkFormat.
51  */
52 VkImageAspectFlags ff_vk_aspect_bits_from_vkfmt(VkFormat vkf);
53 
54 /**
55  * Get Vulkan's chroma subsampling from a pixfmt descriptor.
56  */
57 VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFmtDescriptor *desc);
58 
59 /**
60  * Get Vulkan's bit depth from an [8:12] integer.
61  */
62 VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth);
63 
64 /**
65  * Convert level from Vulkan to AV.
66  */
67 int ff_vk_h264_level_to_av(StdVideoH264LevelIdc level);
68 int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level);
69 
70 StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc);
71 StdVideoH265LevelIdc ff_vk_h265_level_to_vk(int level_idc);
72 StdVideoAV1Level ff_vk_av1_level_to_vk(int level);
73 
74 /**
75  * Convert profile from/to AV to Vulkan
76  */
77 StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile);
78 StdVideoH265ProfileIdc ff_vk_h265_profile_to_vk(int profile);
79 StdVideoAV1Profile ff_vk_av1_profile_to_vk(int profile);
80 
81 /**
82  * Creates image views for video frames.
83  */
84 int ff_vk_create_view(FFVulkanContext *s, FFVkVideoCommon *common,
85  VkImageView *view, VkImageAspectFlags *aspect,
86  AVVkFrame *src, VkFormat vkf, VkImageUsageFlags flags);
87 
88 /**
89  * Initialize video session, allocating and binding necessary memory.
90  */
92  FFVkVideoCommon *common,
93  VkVideoSessionCreateInfoKHR *session_create);
94 
95 /**
96  * Free video session and required resources.
97  */
98 void ff_vk_video_common_uninit(FFVulkanContext *s, FFVkVideoCommon *common);
99 
100 #endif /* AVCODEC_VULKAN_VIDEO_H */
flags
const SwsFlags flags[]
Definition: swscale.c:61
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
level
uint8_t level
Definition: svq3.c:208
FFVkVideoSession::layered_view
VkImageView layered_view
Definition: vulkan_video.h:40
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
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:37
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:271
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:260
FFVkVideoSession::session
VkVideoSessionKHR session
Definition: vulkan_video.h:33
ff_vk_av1_level_to_vk
StdVideoAV1Level ff_vk_av1_level_to_vk(int level)
Definition: vulkan_video.c:229
FFVkVideoSession::layered_dpb
int layered_dpb
Definition: vulkan_video.h:38
FFVulkanContext
Definition: vulkan.h:270
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:39
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:365
ff_vk_av1_profile_to_vk
StdVideoAV1Profile ff_vk_av1_profile_to_vk(int profile)
Definition: vulkan_video.c:281
ff_vk_create_view
int ff_vk_create_view(FFVulkanContext *s, FFVkVideoCommon *common, VkImageView *view, VkImageAspectFlags *aspect, AVVkFrame *src, VkFormat vkf, VkImageUsageFlags flags)
Creates image views for video frames.
Definition: vulkan_video.c:291
AVVkFrame
Definition: hwcontext_vulkan.h:302
vulkan.h
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
profile
int profile
Definition: mxfenc.c:2297
avcodec.h
FFVkVideoSession::nb_mem
uint32_t nb_mem
Definition: vulkan_video.h:35
AVCodecContext
main external API structure.
Definition: avcodec.h:439
FFVkVideoSession::layered_aspect
VkImageAspectFlags layered_aspect
Definition: vulkan_video.h:41
desc
const char * desc
Definition: libsvtav1.c:78
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:337
src
#define src
Definition: vp8dsp.c:248