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 "codec_id.h"
23 #include "vulkan.h"
24 
25 #include <vk_video/vulkan_video_codecs_common.h>
28 
29 #define CODEC_VER_MAJ(ver) (ver >> 22)
30 #define CODEC_VER_MIN(ver) ((ver >> 12) & ((1 << 10) - 1))
31 #define CODEC_VER_PAT(ver) (ver & ((1 << 12) - 1))
32 #define CODEC_VER(ver) CODEC_VER_MAJ(ver), CODEC_VER_MIN(ver), CODEC_VER_PAT(ver)
33 
34 typedef struct FFVkCodecMap {
36  VkVideoCodecOperationFlagBitsKHR encode_op;
38  VkVideoCodecOperationFlagBitsKHR decode_op;
39 } FFVkCodecMap;
40 
41 typedef struct FFVkVideoSession {
42  VkVideoSessionKHR session;
43  VkDeviceMemory *mem;
44  uint32_t nb_mem;
45 
47 } FFVkVideoCommon;
48 
49 /**
50  * Index is codec_id.
51  */
53 
54 /**
55  * Get pixfmt from a Vulkan format.
56  */
58 
59 /**
60  * Get aspect bits which include all planes from a VkFormat.
61  */
62 VkImageAspectFlags ff_vk_aspect_bits_from_vkfmt(VkFormat vkf);
63 
64 /**
65  * Get Vulkan's chroma subsampling from a pixfmt descriptor.
66  */
67 VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFmtDescriptor *desc);
68 
69 /**
70  * Get Vulkan's bit depth from an [8:12] integer.
71  */
72 VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth);
73 
74 
75 /**
76  * Convert level from Vulkan to AV.
77  */
78 int ff_vk_h264_level_to_av(StdVideoH264LevelIdc level);
79 int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level);
80 
81 typedef struct FFVkVideoBuffer {
83  uint8_t *mem;
85 
86 /**
87  * Get a mapped FFVkPooledBuffer with a specific guaranteed minimum size
88  * from a pool.
89  */
90 int ff_vk_video_get_buffer(FFVulkanContext *ctx, FFVkVideoCommon *s,
91  AVBufferRef **buf, VkBufferUsageFlags usage,
92  void *create_pNext, size_t size);
93 
94 /**
95  * Initialize video session, allocating and binding necessary memory.
96  */
98  FFVkVideoCommon *common,
99  VkVideoSessionCreateInfoKHR *session_create);
100 
101 /**
102  * Free video session and required resources.
103  */
104 void ff_vk_video_common_uninit(FFVulkanContext *s, FFVkVideoCommon *common);
105 
106 #endif /* AVCODEC_VULKAN_VIDEO_H */
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
level
uint8_t level
Definition: svq3.c:204
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
FFVkVideoBuffer
Definition: vulkan_video.h:81
normalize.log
log
Definition: normalize.py:21
FFVkVideoBuffer::buf
FFVkBuffer buf
Definition: vulkan_video.h:82
FFVkCodecMap::encode_op
VkVideoCodecOperationFlagBitsKHR encode_op
Definition: vulkan_video.h:36
ff_vk_codec_map
const FFVkCodecMap ff_vk_codec_map[AV_CODEC_ID_FIRST_AUDIO]
Index is codec_id.
Definition: vulkan_video.c:23
FFVkVideoSession::mem
VkDeviceMemory * mem
Definition: vulkan_video.h:43
FFVkVideoSession
Definition: vulkan_video.h:41
FFVkCodecMap::encode_extension
FFVulkanExtensions encode_extension
Definition: vulkan_video.h:35
ff_vk_h265_level_to_av
int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level)
Definition: vulkan_video.c:183
codec_id.h
FFVkCodecMap::decode_op
VkVideoCodecOperationFlagBitsKHR decode_op
Definition: vulkan_video.h:38
FFVkCodecMap::decode_extension
FFVulkanExtensions decode_extension
Definition: vulkan_video.h:37
s
#define s(width, name)
Definition: cbs_vp9.c:198
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ff_vk_video_get_buffer
int ff_vk_video_get_buffer(FFVulkanContext *ctx, FFVkVideoCommon *s, AVBufferRef **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size)
Get a mapped FFVkPooledBuffer with a specific guaranteed minimum size from a pool.
Definition: vulkan_video.c:224
FFVkVideoSession::session
VkVideoSessionKHR session
Definition: vulkan_video.h:42
FFVkVideoBuffer::mem
uint8_t * mem
Definition: vulkan_video.h:83
FFVulkanContext
Definition: vulkan.h:229
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:117
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:125
usage
const char * usage
Definition: floatimg_cmp.c:60
vulkan.h
vulkan_video_codec_av1std_mesa.h
ff_vk_video_common_init
int ff_vk_video_common_init(void *log, FFVulkanContext *s, FFVkVideoCommon *common, VkVideoSessionCreateInfoKHR *session_create)
Initialize video session, allocating and binding necessary memory.
Definition: vulkan_video.c:302
size
int size
Definition: twinvq_data.h:10344
FFVkCodecMap
Definition: vulkan_video.h:34
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:133
AV_CODEC_ID_FIRST_AUDIO
@ AV_CODEC_ID_FIRST_AUDIO
A dummy id pointing at the start of audio codecs.
Definition: codec_id.h:329
VkFormat
enum VkFormat VkFormat
Definition: hwcontext_stub.c:25
FFVkVideoSession::nb_mem
uint32_t nb_mem
Definition: vulkan_video.h:44
vulkan_video_codec_av1std_decode_mesa.h
desc
const char * desc
Definition: libsvtav1.c:83
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
FFVulkanExtensions
FFVulkanExtensions
Definition: vulkan_functions.h:29
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:146
FFVkBuffer
Definition: vulkan.h:96
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:157
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:282
FFVkVideoSession::buf_pool
AVBufferPool * buf_pool
Definition: vulkan_video.h:46