FFmpeg
vulkan_decode.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_DECODE_H
20 #define AVCODEC_VULKAN_DECODE_H
21 
22 #include "decode.h"
23 #include "hwaccel_internal.h"
24 #include "internal.h"
25 
26 #include "vulkan_video.h"
27 
28 typedef struct FFVulkanDecodeProfileData {
29  VkVideoDecodeH264ProfileInfoKHR h264_profile;
30  VkVideoDecodeH265ProfileInfoKHR h265_profile;
32  VkVideoDecodeUsageInfoKHR usage;
33  VkVideoProfileInfoKHR profile;
34  VkVideoProfileListInfoKHR profile_list;
36 
37 typedef struct FFVulkanDecodeShared {
39  FFVkVideoCommon common;
41 
42  VkVideoCapabilitiesKHR caps;
43  VkVideoDecodeCapabilitiesKHR dec_caps;
44 
45  AVBufferRef *dpb_hwfc_ref; /* Only used for dedicated_dpb */
46 
47  AVFrame *layered_frame; /* Only used for layered_dpb */
48  VkImageView layered_view;
49  VkImageAspectFlags layered_aspect;
50 
51  VkVideoSessionParametersKHR empty_session_params;
52 
53  VkSamplerYcbcrConversion yuv_sampler;
55 
56 typedef struct FFVulkanDecodeContext {
60 
61  int dedicated_dpb; /* Oddity #1 - separate DPB images */
62  int layered_dpb; /* Madness #1 - layered DPB images */
63  int external_fg; /* Oddity #2 - hardware can't apply film grain */
64  uint32_t frame_id_alloc_mask; /* For AV1 only */
65 
66  /* Thread-local state below */
69 
70  uint32_t *slice_off;
71  unsigned int slice_off_max;
73 
74 typedef struct FFVulkanDecodePicture {
75  AVFrame *dpb_frame; /* Only used for out-of-place decoding. */
76 
77  VkImageView img_view_ref; /* Image representation view (reference) */
78  VkImageView img_view_out; /* Image representation view (output-only) */
79  VkImageView img_view_dest; /* Set to img_view_out if no layered refs are used */
80  VkImageAspectFlags img_aspect; /* Image plane mask bits */
81  VkImageAspectFlags img_aspect_ref; /* Only used for out-of-place decoding */
82 
83  VkSemaphore sem;
84  uint64_t sem_value;
85 
86  /* Current picture */
87  VkVideoPictureResourceInfoKHR ref;
88  VkVideoReferenceSlotInfoKHR ref_slot;
89 
90  /* Picture refs. H264 has the maximum number of refs (36) of any supported codec. */
91  VkVideoPictureResourceInfoKHR refs [36];
92  VkVideoReferenceSlotInfoKHR ref_slots[36];
93 
94  /* Main decoding struct */
95  VkVideoDecodeInfoKHR decode_info;
96 
97  /* Slice data */
99  size_t slices_size;
100 
101  /* Vulkan functions needed for destruction, as no other context is guaranteed to exist */
102  PFN_vkWaitSemaphores wait_semaphores;
103  PFN_vkDestroyImageView destroy_image_view;
105 
106 /**
107  * Initialize decoder.
108  */
110 
111 /**
112  * Synchronize the contexts between 2 threads.
113  */
115 
116 /**
117  * Initialize hw_frames_ctx with the parameters needed to decode the stream
118  * using the parameters from avctx.
119  *
120  * NOTE: if avctx->internal->hwaccel_priv_data exists, will partially initialize
121  * the context.
122  */
123 int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
124 
125 /**
126  * Removes current session parameters to recreate them
127  */
128 int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s);
129 
130 /**
131  * Prepare a frame, creates the image view, and sets up the dpb fields.
132  */
134  FFVulkanDecodePicture *vkpic, int is_current,
135  int alloc_dpb);
136 
137 /**
138  * Add slice data to frame.
139  */
141  const uint8_t *data, size_t size, int add_startcode,
142  uint32_t *nb_slices, const uint32_t **offsets);
143 
144 /**
145  * Decode a frame.
146  */
148  AVFrame *pic, FFVulkanDecodePicture *vp,
149  AVFrame *rpic[], FFVulkanDecodePicture *rvkp[]);
150 
151 /**
152  * Free a frame and its state.
153  */
155 
156 /**
157  * Get an FFVkBuffer suitable for decoding from.
158  */
160  void *create_pNext, size_t size);
161 
162 /**
163  * Create VkVideoSessionParametersKHR wrapped in an AVBufferRef.
164  */
165 int ff_vk_decode_create_params(AVBufferRef **par_ref, void *logctx, FFVulkanDecodeShared *ctx,
166  const VkVideoSessionParametersCreateInfoKHR *session_params_create);
167 
168 /**
169  * Flush decoder.
170  */
172 
173 /**
174  * Free decoder.
175  */
177 
178 #endif /* AVCODEC_VULKAN_DECODE_H */
FFVulkanDecodeShared::layered_view
VkImageView layered_view
Definition: vulkan_decode.h:48
VkVideoDecodeAV1ProfileInfoMESA
Definition: vulkan_video_codec_av1std_mesa.h:373
FFVulkanDecodePicture::slices_size
size_t slices_size
Definition: vulkan_decode.h:99
FFVulkanDecodeShared::s
FFVulkanContext s
Definition: vulkan_decode.h:38
FFVulkanDecodeProfileData::profile
VkVideoProfileInfoKHR profile
Definition: vulkan_decode.h:33
FFVulkanDecodeProfileData::h265_profile
VkVideoDecodeH265ProfileInfoKHR h265_profile
Definition: vulkan_decode.h:30
FFVulkanDecodeContext::shared_ctx
FFVulkanDecodeShared * shared_ctx
Definition: vulkan_decode.h:57
ff_vk_decode_uninit
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
Definition: vulkan_decode.c:1090
FFVulkanDecodeContext::exec_pool
FFVkExecPool exec_pool
Definition: vulkan_decode.h:59
FFVulkanDecodeContext::hevc_headers_size
size_t hevc_headers_size
Definition: vulkan_decode.h:68
FFVulkanDecodeShared::common
FFVkVideoCommon common
Definition: vulkan_decode.h:39
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
internal.h
FFVulkanDecodeShared::layered_frame
AVFrame * layered_frame
Definition: vulkan_decode.h:47
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:148
FFVulkanDecodeContext::frame_id_alloc_mask
uint32_t frame_id_alloc_mask
Definition: vulkan_decode.h:64
FFVulkanDecodeShared::yuv_sampler
VkSamplerYcbcrConversion yuv_sampler
Definition: vulkan_decode.h:53
ff_vk_get_decode_buffer
int ff_vk_get_decode_buffer(FFVulkanDecodeContext *ctx, AVBufferRef **buf, void *create_pNext, size_t size)
Get an FFVkBuffer suitable for decoding from.
ff_vk_decode_add_slice
int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, const uint8_t *data, size_t size, int add_startcode, uint32_t *nb_slices, const uint32_t **offsets)
Add slice data to frame.
Definition: vulkan_decode.c:239
FFVulkanDecodeContext
Definition: vulkan_decode.h:56
FFVulkanDecodeProfileData::av1_profile
VkVideoDecodeAV1ProfileInfoMESA av1_profile
Definition: vulkan_decode.h:31
FFVulkanDecodeShared::layered_aspect
VkImageAspectFlags layered_aspect
Definition: vulkan_decode.h:49
FFVulkanDecodePicture::ref
VkVideoPictureResourceInfoKHR ref
Definition: vulkan_decode.h:87
FFVulkanDecodeContext::session_params
AVBufferRef * session_params
Definition: vulkan_decode.h:58
ff_vk_decode_create_params
int ff_vk_decode_create_params(AVBufferRef **par_ref, void *logctx, FFVulkanDecodeShared *ctx, const VkVideoSessionParametersCreateInfoKHR *session_params_create)
Create VkVideoSessionParametersKHR wrapped in an AVBufferRef.
Definition: vulkan_decode.c:1061
FFVulkanDecodePicture::sem_value
uint64_t sem_value
Definition: vulkan_decode.h:84
FFVulkanDecodeShared
Definition: vulkan_decode.h:37
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:62
FFVulkanDecodeContext::slice_off
uint32_t * slice_off
Definition: vulkan_decode.h:70
FFVulkanDecodePicture::img_view_out
VkImageView img_view_out
Definition: vulkan_decode.h:78
FFVulkanDecodeProfileData::h264_profile
VkVideoDecodeH264ProfileInfoKHR h264_profile
Definition: vulkan_decode.h:29
FFVulkanDecodePicture::refs
VkVideoPictureResourceInfoKHR refs[36]
Definition: vulkan_decode.h:91
FFVulkanDecodeProfileData::profile_list
VkVideoProfileListInfoKHR profile_list
Definition: vulkan_decode.h:34
FFVulkanDecodePicture::wait_semaphores
PFN_vkWaitSemaphores wait_semaphores
Definition: vulkan_decode.h:102
s
#define s(width, name)
Definition: cbs_vp9.c:198
FFVulkanDecodePicture
Definition: vulkan_decode.h:74
offsets
static const int offsets[]
Definition: hevc_pel.c:34
ctx
AVFormatContext * ctx
Definition: movenc.c:48
decode.h
ff_vk_params_invalidate
int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s)
Removes current session parameters to recreate them.
Definition: vulkan_decode.c:109
ff_vk_update_thread_context
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Synchronize the contexts between 2 threads.
Definition: vulkan_decode.c:68
FFVulkanDecodePicture::img_view_ref
VkImageView img_view_ref
Definition: vulkan_decode.h:77
hwaccel_internal.h
FFVulkanDecodeProfileData::usage
VkVideoDecodeUsageInfoKHR usage
Definition: vulkan_decode.h:32
ff_vk_decode_free_frame
void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *vp)
Free a frame and its state.
Definition: vulkan_decode.c:561
ff_vk_decode_frame
int ff_vk_decode_frame(AVCodecContext *avctx, AVFrame *pic, FFVulkanDecodePicture *vp, AVFrame *rpic[], FFVulkanDecodePicture *rvkp[])
Decode a frame.
Definition: vulkan_decode.c:331
FFVulkanContext
Definition: vulkan.h:229
FFVulkanDecodeShared::dpb_hwfc_ref
AVBufferRef * dpb_hwfc_ref
Definition: vulkan_decode.h:45
FFVulkanDecodeShared::caps
VkVideoCapabilitiesKHR caps
Definition: vulkan_decode.h:42
size
int size
Definition: twinvq_data.h:10344
FFVkQueueFamilyCtx
Definition: vulkan.h:111
FFVulkanDecodePicture::img_aspect_ref
VkImageAspectFlags img_aspect_ref
Definition: vulkan_decode.h:81
FFVulkanDecodeShared::empty_session_params
VkVideoSessionParametersKHR empty_session_params
Definition: vulkan_decode.h:51
FFVulkanDecodeContext::slice_off_max
unsigned int slice_off_max
Definition: vulkan_decode.h:71
HEVCHeaderSet
Definition: vulkan_hevc.c:60
ff_vk_frame_params
int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Initialize hw_frames_ctx with the parameters needed to decode the stream using the parameters from av...
Definition: vulkan_decode.c:1004
FFVulkanDecodeProfileData
Definition: vulkan_decode.h:28
FFVulkanDecodePicture::ref_slot
VkVideoReferenceSlotInfoKHR ref_slot
Definition: vulkan_decode.h:88
FFVulkanDecodePicture::sem
VkSemaphore sem
Definition: vulkan_decode.h:83
FFVulkanDecodeContext::external_fg
int external_fg
Definition: vulkan_decode.h:63
FFVulkanDecodePicture::ref_slots
VkVideoReferenceSlotInfoKHR ref_slots[36]
Definition: vulkan_decode.h:92
FFVkExecPool
Definition: vulkan.h:211
FFVulkanDecodeContext::hevc_headers
struct HEVCHeaderSet * hevc_headers
Definition: vulkan_decode.h:67
ff_vk_decode_prepare_frame
int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, FFVulkanDecodePicture *vkpic, int is_current, int alloc_dpb)
Prepare a frame, creates the image view, and sets up the dpb fields.
Definition: vulkan_decode.c:175
AVCodecContext
main external API structure.
Definition: avcodec.h:445
FFVulkanDecodeContext::dedicated_dpb
int dedicated_dpb
Definition: vulkan_decode.h:61
FFVulkanDecodePicture::dpb_frame
AVFrame * dpb_frame
Definition: vulkan_decode.h:75
vulkan_video.h
FFVulkanDecodePicture::slices_buf
AVBufferRef * slices_buf
Definition: vulkan_decode.h:98
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
ff_vk_decode_init
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
Definition: vulkan_decode.c:1105
ff_vk_decode_flush
void ff_vk_decode_flush(AVCodecContext *avctx)
Flush decoder.
Definition: vulkan_decode.c:301
FFVulkanDecodePicture::img_view_dest
VkImageView img_view_dest
Definition: vulkan_decode.h:79
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
FFVulkanDecodeContext::layered_dpb
int layered_dpb
Definition: vulkan_decode.h:62
FFVulkanDecodeShared::qf
FFVkQueueFamilyCtx qf
Definition: vulkan_decode.h:40
FFVulkanDecodePicture::destroy_image_view
PFN_vkDestroyImageView destroy_image_view
Definition: vulkan_decode.h:103
FFVulkanDecodePicture::decode_info
VkVideoDecodeInfoKHR decode_info
Definition: vulkan_decode.h:95
FFVulkanDecodePicture::img_aspect
VkImageAspectFlags img_aspect
Definition: vulkan_decode.h:80
FFVulkanDecodeShared::dec_caps
VkVideoDecodeCapabilitiesKHR dec_caps
Definition: vulkan_decode.h:43