FFmpeg
Loading...
Searching...
No Matches
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 "codec_id.h"
23#include "decode.h"
24#include "hwaccel_internal.h"
25#include "internal.h"
26
27#include "vulkan_video.h"
28
32 VkQueueFlagBits queue_flags;
33 VkVideoCodecOperationFlagBitsKHR decode_op;
34
35 VkExtensionProperties ext_props;
37
38typedef struct FFVulkanDecodeShared {
43
45
46 VkVideoCapabilitiesKHR caps;
47 VkVideoDecodeCapabilitiesKHR dec_caps;
48
49 /* Software-defined decoder context */
50 void *sd_ctx;
53
54typedef struct FFVulkanDecodeContext {
56 VkVideoSessionParametersKHR *session_params;
57
58 int dedicated_dpb; /* Oddity #1 - separate DPB images */
59 int external_fg; /* Oddity #2 - hardware can't apply film grain */
60
61 /* Workaround for NVIDIA drivers tested with CTS version 1.3.8 for AV1.
62 * The tests were incorrect as the OrderHints were offset by 1. */
64
65 /* Thread-local state below */
68
69 uint32_t *slice_off;
70 unsigned int slice_off_max;
72
73typedef struct FFVulkanDecodePicture {
74 AVFrame *dpb_frame; /* Software-defined decoders only. */
75 FFVkVideoDPBImage *dpb_img; /* DISTINCT-mode reference image */
76
77 struct {
78 VkImageView ref; /* Image representation view (reference) */
79 VkImageView out; /* Image representation view (output-only) */
80 VkImageAspectFlags aspect; /* Image plane mask bits */
81 VkImageAspectFlags aspect_ref; /* Only used for out-of-place decoding */
83
84 VkSemaphore sem;
85 uint64_t sem_value;
86
87 /* Current picture */
88 VkVideoPictureResourceInfoKHR ref;
89 VkVideoReferenceSlotInfoKHR ref_slot;
90
91 /* Picture refs. H264 has the maximum number of refs (36) of any supported codec. */
92 VkVideoPictureResourceInfoKHR refs [36];
93 VkVideoReferenceSlotInfoKHR ref_slots[36];
94
95 /* Main decoding struct */
96 VkVideoDecodeInfoKHR decode_info;
97
98 /* Owner of the output image views aliased by view.out/ref */
100
101 /* Slice data */
104
105 /* Vulkan functions needed for destruction, as no other context is guaranteed to exist */
106 PFN_vkInvalidateMappedMemoryRanges invalidate_memory_ranges;
108
109/**
110 * Initialize decoder.
111 */
113
114/**
115 * Synchronize the contexts between 2 threads.
116 */
118
119/**
120 * Initialize hw_frames_ctx with the parameters needed to decode the stream
121 * using the parameters from avctx.
122 *
123 * NOTE: if avctx->internal->hwaccel_priv_data exists, will partially initialize
124 * the context.
125 */
126int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
127
128/**
129 * Removes current session parameters to recreate them
130 */
131int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s);
132
133/**
134 * Prepare a frame, creates the image view, and sets up the dpb fields.
135 */
137 FFVulkanDecodePicture *vkpic, int is_current,
138 int alloc_dpb);
139
140/**
141 * Add slice data to frame.
142 */
144 const uint8_t *data, size_t size, int add_startcode,
145 uint32_t *nb_slices, const uint32_t **offsets);
146
147/**
148 * Decode a frame.
149 */
152 AVFrame *rpic[], FFVulkanDecodePicture *rvkp[]);
153
154/**
155 * Free a frame and its state.
156 */
158
159/**
160 * Create VkVideoSessionParametersKHR wrapped in an AVBufferRef.
161 */
162int ff_vk_decode_create_params(VkVideoSessionParametersKHR **par_ref, void *logctx, FFVulkanDecodeShared *ctx,
163 const VkVideoSessionParametersCreateInfoKHR *session_params_create);
164
165/**
166 * Free decoder.
167 */
169
170#endif /* AVCODEC_VULKAN_DECODE_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static AVFormatContext * ctx
#define s(width, name)
Definition cbs_vp9.c:198
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
static const int offsets[]
Definition hevc_pel.c:34
#define b
Definition input.c:43
common internal api header.
const char data[16]
Definition mxf.c:149
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition refstruct.c:183
VkVideoSessionParametersKHR * session_params
FFVulkanDecodeShared * shared_ctx
struct HEVCHeaderSet * hevc_headers
unsigned int slice_off_max
FFVulkanExtensions decode_extension
VkVideoCodecOperationFlagBitsKHR decode_op
VkQueueFlagBits queue_flags
VkExtensionProperties ext_props
struct FFVulkanDecodePicture::@321376256110110067000314232201030232256240036361 view
VkVideoReferenceSlotInfoKHR ref_slot
VkVideoPictureResourceInfoKHR refs[36]
VkVideoReferenceSlotInfoKHR ref_slots[36]
VkImageAspectFlags aspect_ref
VkVideoDecodeInfoKHR decode_info
FFVkVideoDPBImage * dpb_img
PFN_vkInvalidateMappedMemoryRanges invalidate_memory_ranges
VkImageAspectFlags aspect
FFVkImageViews * out_views
FFVkExecPool exec_pool
FFVkVideoCommon common
FFVulkanContext s
AVVulkanDeviceQueueFamily * qf
VkVideoDecodeCapabilitiesKHR dec_caps
VkVideoCapabilitiesKHR caps
AVRefStructPool * buf_pool
void(* sd_ctx_free)(struct FFVulkanDecodeShared *ctx)
#define src
Definition vp8dsp.c:248
int size
int ff_vk_decode_frame(AVCodecContext *avctx, AVFrame *pic, FFVulkanDecodePicture *vp, AVFrame *rpic[], FFVulkanDecodePicture *rvkp[])
Decode a frame.
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Synchronize the contexts between 2 threads.
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
int ff_vk_decode_create_params(VkVideoSessionParametersKHR **par_ref, void *logctx, FFVulkanDecodeShared *ctx, const VkVideoSessionParametersCreateInfoKHR *session_params_create)
Create VkVideoSessionParametersKHR wrapped in an AVBufferRef.
int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s)
Removes current session parameters to recreate them.
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...
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.
void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *vp)
Free a frame and its state.
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
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.
uint64_t FFVulkanExtensions