FFmpeg
Loading...
Searching...
No Matches
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/refstruct.h"
24#include "libavutil/vulkan.h"
25
26#include <vk_video/vulkan_video_codecs_common.h>
27
28#define CODEC_VER_MAJ(ver) (ver >> 22)
29#define CODEC_VER_MIN(ver) ((ver >> 12) & ((1 << 10) - 1))
30#define CODEC_VER_PAT(ver) (ver & ((1 << 12) - 1))
31#define CODEC_VER(ver) CODEC_VER_MAJ(ver), CODEC_VER_MIN(ver), CODEC_VER_PAT(ver)
32
33/* DEDICATED-mode queue-exclusive DPB image */
34typedef struct FFVkVideoDPBImage {
35 VkImage img;
36 VkDeviceMemory mem;
37 VkImageView view;
38 VkImageAspectFlags aspect;
39 VkImageLayout layout;
41
42/* Internal DPB image pool; av_refstruct_pool_get()/av_refstruct_unref() */
43typedef struct FFVkVideoDPB {
44 /* Creation only; destruction uses the stashed handles below, as the
45 * pool may outlive the context */
47
48 AVRefStructPool *img_pool; /* FFVkVideoDPBImage entries */
49
50 VkDevice dev;
51 const VkAllocationCallbacks *alloc;
52 PFN_vkDestroyImageView destroy_image_view;
53 PFN_vkDestroyImage destroy_image;
54 PFN_vkFreeMemory free_memory;
55
57 VkImageUsageFlags usage;
58 VkImageTiling tiling;
62
63typedef struct FFVkVideoSession {
64 VkVideoSessionKHR session;
65 VkDeviceMemory *mem;
66 uint32_t nb_mem;
67
71 VkImageView layered_view;
72 VkImageAspectFlags layered_aspect;
74
75/**
76 * Get pixfmt from a Vulkan format.
77 */
79
80/**
81 * Get aspect bits which include all planes from a VkFormat.
82 */
83VkImageAspectFlags ff_vk_aspect_bits_from_vkfmt(VkFormat vkf);
84
85/**
86 * Get Vulkan's chroma subsampling from a pixfmt descriptor.
87 */
88VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFmtDescriptor *desc);
89
90/**
91 * Get Vulkan's bit depth from an [8:12] integer.
92 */
93VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth);
94
95/**
96 * Convert level from Vulkan to AV.
97 */
98int ff_vk_h264_level_to_av(StdVideoH264LevelIdc level);
99int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level);
100
101StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc);
102StdVideoH265LevelIdc ff_vk_h265_level_to_vk(int level_idc);
103StdVideoAV1Level ff_vk_av1_level_to_vk(int level);
104
105/**
106 * Convert profile from/to AV to Vulkan
107 */
108StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile);
109StdVideoH265ProfileIdc ff_vk_h265_profile_to_vk(int profile);
110StdVideoAV1Profile ff_vk_av1_profile_to_vk(int profile);
111
112/**
113 * Creates image views for video frames.
114 */
115int ff_vk_create_view(FFVulkanContext *s, VkImageView *view,
116 VkImageAspectFlags *aspect, VkImage img,
117 VkFormat vkf, VkImageUsageFlags usage, int layered);
118
119/**
120 * Initialize the internal DPB image pool.
121 */
123 VkFormat format, VkImageUsageFlags usage,
124 VkImageTiling tiling, void *create_pnext,
125 int width, int height, int nb_layers);
126
127/**
128 * Initialize video session, allocating and binding necessary memory.
129 */
131 FFVkVideoCommon *common,
132 VkVideoSessionCreateInfoKHR *session_create);
133
134/**
135 * Free video session and required resources.
136 */
138
139#endif /* AVCODEC_VULKAN_VIDEO_H */
static const char *const format[]
Definition af_aiir.c:444
Libavcodec external API header.
#define s(width, name)
Definition cbs_vp9.c:198
const char * usage
enum VkFormat VkFormat
const char * desc
Definition libsvtav1.c:83
int profile
Definition mxfenc.c:2299
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
main external API structure.
Definition avcodec.h:443
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition refstruct.c:183
VkImageAspectFlags layered_aspect
VkDeviceMemory * mem
VkVideoSessionKHR session
FFVkVideoDPBImage * layered_img
FFVkVideoDPB * dpb
VkImageView layered_view
VkDeviceMemory mem
VkImageLayout layout
VkImageAspectFlags aspect
VkImageView view
AVRefStructPool * img_pool
FFVulkanContext * s
PFN_vkDestroyImage destroy_image
VkDevice dev
VkImageTiling tiling
VkFormat format
PFN_vkFreeMemory free_memory
const VkAllocationCallbacks * alloc
void * create_pnext
PFN_vkDestroyImageView destroy_image_view
VkImageUsageFlags usage
uint8_t level
Definition svq3.c:208
int level_idc
Definition h264_levels.c:29
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
#define img
void ff_vk_video_common_uninit(FFVulkanContext *s, FFVkVideoCommon *common)
Free video session and required resources.
VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth)
Get Vulkan's bit depth from an [8:12] integer.
VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFmtDescriptor *desc)
Get Vulkan's chroma subsampling from a pixfmt descriptor.
int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level)
int ff_vk_create_view(FFVulkanContext *s, VkImageView *view, VkImageAspectFlags *aspect, VkImage img, VkFormat vkf, VkImageUsageFlags usage, int layered)
Creates image views for video frames.
StdVideoH265ProfileIdc ff_vk_h265_profile_to_vk(int profile)
int ff_vk_h264_level_to_av(StdVideoH264LevelIdc level)
Convert level from Vulkan to AV.
StdVideoH265LevelIdc ff_vk_h265_level_to_vk(int level_idc)
StdVideoAV1Profile ff_vk_av1_profile_to_vk(int profile)
enum AVPixelFormat ff_vk_pix_fmt_from_vkfmt(VkFormat vkf)
Get pixfmt from a Vulkan format.
int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s, FFVkVideoCommon *common, VkVideoSessionCreateInfoKHR *session_create)
Initialize video session, allocating and binding necessary memory.
StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc)
StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile)
Convert profile from/to AV to Vulkan.
VkImageAspectFlags ff_vk_aspect_bits_from_vkfmt(VkFormat vkf)
Get aspect bits which include all planes from a VkFormat.
StdVideoAV1Level ff_vk_av1_level_to_vk(int level)
int ff_vk_video_dpb_init(FFVulkanContext *s, FFVkVideoCommon *common, VkFormat format, VkImageUsageFlags usage, VkImageTiling tiling, void *create_pnext, int width, int height, int nb_layers)
Initialize the internal DPB image pool.