1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

libavcodec: add Vulkan common video decoding code

This commit is contained in:
Lynne 2023-01-16 07:23:27 +01:00
parent 023ae6103f
commit 1e8fefff93
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464
3 changed files with 1344 additions and 1 deletions

View File

@ -1291,7 +1291,7 @@ SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h
SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_decode.h vaapi_hevc.h vaapi_encode.h
SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h vdpau_internal.h
SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX) += videotoolbox.h vt_internal.h
SKIPHEADERS-$(CONFIG_VULKAN) += vulkan.h vulkan_video.h
SKIPHEADERS-$(CONFIG_VULKAN) += vulkan.h vulkan_video.h vulkan_decode.h
SKIPHEADERS-$(CONFIG_V4L2_M2M) += v4l2_buffers.h v4l2_context.h v4l2_m2m.h
SKIPHEADERS-$(CONFIG_ZLIB) += zlib_wrapper.h

1167
libavcodec/vulkan_decode.c Normal file

File diff suppressed because it is too large Load Diff

176
libavcodec/vulkan_decode.h Normal file
View File

@ -0,0 +1,176 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_VULKAN_DECODE_H
#define AVCODEC_VULKAN_DECODE_H
#include "decode.h"
#include "hwconfig.h"
#include "internal.h"
#include "vulkan_video.h"
typedef struct FFVulkanDecodeProfileData {
VkVideoCapabilitiesKHR caps;
VkVideoDecodeCapabilitiesKHR dec_caps;
VkVideoDecodeH264ProfileInfoKHR h264_profile;
VkVideoDecodeH264ProfileInfoKHR h265_profile;
VkVideoDecodeAV1ProfileInfoMESA av1_profile;
VkVideoDecodeUsageInfoKHR usage;
VkVideoProfileInfoKHR profile;
VkVideoProfileListInfoKHR profile_list;
} FFVulkanDecodeProfileData;
typedef struct FFVulkanDecodeShared {
FFVulkanContext s;
FFVkVideoCommon common;
FFVkExecPool exec_pool;
FFVulkanDecodeProfileData profile_data;
AVBufferRef *dpb_hwfc_ref; /* Only used for dedicated_dpb */
AVFrame *layered_frame; /* Only used for layered_dpb */
VkImageView layered_view;
VkImageAspectFlags layered_aspect;
VkVideoSessionParametersKHR empty_session_params;
VkSamplerYcbcrConversion yuv_sampler;
} FFVulkanDecodeShared;
typedef struct FFVulkanDecodeContext {
AVBufferRef *shared_ref;
AVBufferRef *session_params;
int dedicated_dpb; /* Oddity #1 - separate DPB images */
int layered_dpb; /* Madness #1 - layered DPB images */
/* Thread-local state below */
AVBufferPool *tmp_pool; /* Pool for temporary data, if needed (HEVC) */
size_t tmp_pool_ele_size;
int params_changed;
} FFVulkanDecodeContext;
typedef struct FFVulkanDecodePicture {
AVFrame *dpb_frame; /* Only used for out-of-place decoding. */
VkImageView img_view_ref; /* Image representation view (reference) */
VkImageView img_view_out; /* Image representation view (output-only) */
VkImageView img_view_dest; /* Set to img_view_out if no layered refs are used */
VkImageAspectFlags img_aspect; /* Image plane mask bits */
VkImageAspectFlags img_aspect_ref; /* Only used for out-of-place decoding */
VkSemaphore sem;
uint64_t sem_value;
/* State */
int update_params;
AVBufferRef *session_params;
/* Current picture */
VkVideoPictureResourceInfoKHR ref;
VkVideoReferenceSlotInfoKHR ref_slot;
/* Picture refs. H264 has the maximum number of refs (36) of any supported codec. */
VkVideoPictureResourceInfoKHR refs [36];
VkVideoReferenceSlotInfoKHR ref_slots[36];
/* Main decoding struct */
AVBufferRef *params_buf;
VkVideoDecodeInfoKHR decode_info;
/* Slice data */
AVBufferRef *slices_buf;
size_t slices_size;
uint32_t *slice_off;
unsigned int slice_off_max;
uint32_t nb_slices;
} FFVulkanDecodePicture;
/**
* Initialize decoder.
*/
int ff_vk_decode_init(AVCodecContext *avctx);
/**
* Synchronize the contexts between 2 threads.
*/
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
/**
* Initialize hw_frames_ctx with the parameters needed to decode the stream
* using the parameters from avctx.
*
* NOTE: if avctx->internal->hwaccel_priv_data exists, will partially initialize
* the context.
*/
int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
/**
* Sets FFVulkanDecodeContext.params_changed to 1.
*/
int ff_vk_params_changed(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s);
/**
* Prepare a frame, creates the image view, and sets up the dpb fields.
*/
int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic,
FFVulkanDecodePicture *vkpic, int is_current,
int alloc_dpb);
/**
* Add slice data to frame.
*/
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);
/**
* Decode a frame.
*/
int ff_vk_decode_frame(AVCodecContext *avctx,
AVFrame *pic, FFVulkanDecodePicture *vp,
AVFrame *rpic[], FFVulkanDecodePicture *rvkp[]);
/**
* Free a frame and its state.
*/
void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *vp);
/**
* Get an FFVkBuffer suitable for decoding from.
*/
int ff_vk_get_decode_buffer(FFVulkanDecodeContext *ctx, AVBufferRef **buf,
void *create_pNext, size_t size);
/**
* Free VkVideoSessionParametersKHR.
*/
void ff_vk_decode_free_params(void *opaque, uint8_t *data);
/**
* Flush decoder.
*/
void ff_vk_decode_flush(AVCodecContext *avctx);
/**
* Free decoder.
*/
int ff_vk_decode_uninit(AVCodecContext *avctx);
#endif /* AVCODEC_VULKAN_DECODE_H */