49#define CHECK_CU(x) FF_CUDA_CHECK_DL(device_ctx, cu, x)
74#if HAVE_FFNVCODEC_CUARRAY
199#if HAVE_CUDAFUNCTIONS_CUMEMHOSTALLOC
200static void cuda_transfer_buffer_free(
void *opaque, uint8_t *
data)
214static AVBufferRef *cuda_transfer_buffer_alloc(
void *device_ref,
size_t size)
263#if HAVE_FFNVCODEC_CUARRAY
294#if HAVE_FFNVCODEC_CUARRAY
295static unsigned int cuda_array_numchannels_for_pix_fmt(
enum AVPixelFormat fmt)
328#if HAVE_FFNVCODEC_CUARRAY
335 av_log(
ctx,
AV_LOG_ERROR,
"Missing support for cuarray frames. Rebuild with newer ffnvcodec headers.\n");
356#if HAVE_FFNVCODEC_CUARRAY
363 priv->
p.
cuarray_desc.NumChannels = cuda_array_numchannels_for_pix_fmt(
ctx->sw_format);
377 priv->
p.
cuarray_desc.Flags |= CUDA_ARRAY3D_SURFACE_LDST | CUDA_ARRAY3D_VIDEO_ENCODE_DECODE;
396 for (
i =
i - 1;
i >= 0;
i--)
439#if HAVE_FFNVCODEC_CUARRAY
453#if HAVE_FFNVCODEC_CUARRAY
469 CUDA_ARRAY3D_DESCRIPTOR plane_desc = { 0 };
471 CUresult arr_plane_res = cu->cuArrayGetPlane(&plane_array,
desc->array,
i);
473 if (arr_plane_res == CUDA_ERROR_INVALID_VALUE) {
478 res =
CHECK_CU(cu->cuArray3DGetDescriptor(&plane_desc,
desc->array));
481 }
else if (arr_plane_res != CUDA_SUCCESS) {
485 res =
CHECK_CU(cu->cuArray3DGetDescriptor(&plane_desc, plane_array));
491 if (elem_size <= 0) {
496 frame->linesize[
i] = plane_desc.Width * plane_desc.NumChannels * elem_size;
498 if (arr_plane_res == CUDA_ERROR_INVALID_VALUE)
529#if HAVE_FFNVCODEC_CUARRAY
538 if (!
frame->hw_frames_ctx)
553 fmts[0] =
ctx->sw_format;
572 int i,
ret, copy_queued = 0, bottom_up = 0;
602 if (sw_frame ==
src) {
604 ctx->sw_format,
src->width,
src->height);
635 int src_is_nonplanar_cuarray = 0;
636 int dst_is_nonplanar_cuarray = 0;
644 CUDA_MEMCPY2D cpy = {
645 .srcPitch =
src->linesize[
i],
646 .dstPitch =
dst->linesize[
i],
647 .WidthInBytes = bytewidth,
652 cpy.srcMemoryType = CU_MEMORYTYPE_DEVICE;
653 cpy.srcDevice = (CUdeviceptr)
src->data[
i];
655#if HAVE_FFNVCODEC_CUARRAY
657 CUresult cures = cu->cuArrayGetPlane(&
array, (CUarray)
src->data[0],
i);
658 if (cures == CUDA_ERROR_INVALID_VALUE &&
i == 0) {
662 src_is_nonplanar_cuarray = 1;
663 }
else if (cures != CUDA_SUCCESS) {
668 cpy.srcMemoryType = CU_MEMORYTYPE_ARRAY;
669 cpy.srcArray =
array;
675 cpy.srcMemoryType = CU_MEMORYTYPE_HOST;
676 cpy.srcHost =
src->data[
i];
680 cpy.dstMemoryType = CU_MEMORYTYPE_DEVICE;
681 cpy.dstDevice = (CUdeviceptr)
dst->data[
i];
683#if HAVE_FFNVCODEC_CUARRAY
685 CUresult cures = cu->cuArrayGetPlane(&
array, (CUarray)
dst->data[0],
i);
686 if (cures == CUDA_ERROR_INVALID_VALUE &&
i == 0) {
690 dst_is_nonplanar_cuarray = 1;
691 }
else if (cures != CUDA_SUCCESS) {
696 cpy.dstMemoryType = CU_MEMORYTYPE_ARRAY;
697 cpy.dstArray =
array;
703 cpy.dstMemoryType = CU_MEMORYTYPE_HOST;
704 cpy.dstHost =
dst->data[
i];
712 if (src_is_nonplanar_cuarray || dst_is_nonplanar_cuarray)
717 if (!
src->hw_frames_ctx || !
dst->hw_frames_ctx) {
724 if (
ret < 0 && copy_queued)
729 if (bottom_up_dst &&
ret >= 0)
732 ctx->sw_format,
src->width,
src->height);
787 int ret, dev_active = 0;
788 unsigned int dev_flags = 0;
790 const unsigned int desired_flags = CU_CTX_SCHED_BLOCKING_SYNC;
798 &dev_flags, &dev_active));
802 if (dev_active && dev_flags != desired_flags) {
803 av_log(device_ctx,
AV_LOG_ERROR,
"Primary context already active with incompatible flags.\n");
805 }
else if (dev_flags != desired_flags) {
844 int use_primary_ctx = 0, use_current_ctx = 0;
846 use_primary_ctx = strtol(primary_ctx_opt->
value,
NULL, 10);
849 use_current_ctx = strtol(current_ctx_opt->
value,
NULL, 10);
851 if (use_primary_ctx && use_current_ctx) {
852 av_log(device_ctx,
AV_LOG_ERROR,
"Requested both primary and current CUDA context simultaneously.\n");
856 if (primary_ctx_opt && use_primary_ctx) {
859 }
else if (primary_ctx_opt) {
864 if (current_ctx_opt && use_current_ctx) {
867 }
else if (current_ctx_opt) {
881 int ret, device_idx = 0;
888 device_idx = strtol(device,
NULL, 0);
920 const char *src_uuid =
NULL;
922 VkPhysicalDeviceIDProperties vk_idp;
924 int ret,
i, device_count;
931 vk_idp = (VkPhysicalDeviceIDProperties) {
932 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES,
936 switch (src_ctx->
type) {
938#define TYPE PFN_vkGetPhysicalDeviceProperties2
942 VkPhysicalDeviceProperties2 vk_dev_props = {
943 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
946 prop_fn(vkctx->
phys_dev, &vk_dev_props);
947 src_uuid = vk_idp.deviceUUID;
959 "Failed to get UUID of source device.\n");
974 ret =
CHECK_CU(cu->cuDeviceGetCount(&device_count));
979 for (
i = 0;
i < device_count;
i++) {
991 if (memcmp(src_uuid, uuid.bytes, sizeof (uuid.bytes)) == 0) {
1030#if HAVE_CUDAFUNCTIONS_CUMEMHOSTALLOC
1031 .transfer_buffer_alloc = cuda_transfer_buffer_alloc,
1037#if HAVE_FFNVCODEC_CUARRAY
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static AVFormatContext * ctx
static AVDictionary * opts
refcounted data buffer API
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
#define AV_CUDA_USE_CURRENT_CONTEXT
Use current device context instead of creating a new one.
#define AV_CUDA_USE_PRIMARY_CONTEXT
Use primary device context instead of creating a new one.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
AVBufferPool * av_buffer_pool_init2(size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4], const uint8_t *src, enum AVPixelFormat pix_fmt, int width, int height, int align)
Setup the data pointers and linesizes based on the specified image parameters and the provided array.
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
int av_hwframe_get_transfer_buffer(AVBufferRef *hwframe_ctx, AVFrame *frame)
Allocate the buffers of a software frame that data is transferred to or from frames of the given AVHW...
AVHWFrameTransferDirection
@ AV_HWDEVICE_TYPE_VULKAN
static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
static CUarray_format cuda_array_format_for_pix_fmt(enum AVPixelFormat fmt)
static int cuda_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static int cuda_flags_from_opts(AVHWDeviceContext *device_ctx, AVDictionary *opts, int *flags)
static enum AVPixelFormat cuda_frame_hw_format(const AVFrame *frame)
static AVBufferRef * cuda_pool_alloc(void *opaque, size_t size)
static int cuda_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
static void cuda_buffer_free(void *opaque, uint8_t *data)
static int cuda_device_init(AVHWDeviceContext *ctx)
static int cuda_frames_init(AVHWFramesContext *ctx)
static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags)
static void cuda_frames_uninit(AVHWFramesContext *ctx)
const HWContextType ff_hwcontext_type_cuda
static int cuda_device_create(AVHWDeviceContext *device_ctx, const char *device, AVDictionary *opts, int flags)
static int cuda_device_derive(AVHWDeviceContext *device_ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
FFmpeg internal API for CUDA.
static int ff_cuda_cuarray_elem_size(CUarray_format fmt)
Return the element size in bytes for a CUarray_format, or 0 for unknown.
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
API-specific header for AV_HWDEVICE_TYPE_VULKAN.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
#define AV_PIX_FMT_0RGB32
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12MSB
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_CUARRAY
hardware decoding through openharmony
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10MSB
#define AV_PIX_FMT_0BGR32
#define AV_PIX_FMT_YUV444P10
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
CUDA frame descriptor for pool allocation of AV_PIX_FMT_CUARRAY frames.
This struct is allocated as AVHWDeviceContext.hwctx.
AVCUDADeviceContextInternal * internal
This struct is allocated as AVHWFramesContext.hwctx.
CUarray * cuarray_surfaces
If cuarray_num_surfaces is >0, this contains the array of pre-allocated surfaces.
CUDA_ARRAY3D_DESCRIPTOR cuarray_desc
CUDA_ARRAY3D_DESCRIPTOR CUarrays will be initialized with.
int cuarray_num_surfaces
If >0, pre-allocate a fixed pool of surfaces.
CUDA hardware pipeline configuration details.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
This struct describes a set or pool of "hardware" frames (i.e.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
VkPhysicalDevice phys_dev
Physical device.
VkInstance inst
Vulkan instance.
PFN_vkGetInstanceProcAddr get_proc_addr
Pointer to a vkGetInstanceProcAddr loading function.
AVCUDADeviceContextInternal internal
int cuarray_num_surfaces_used
AVBufferPool * pool_internal
#define av_malloc_array(a, b)
static void error(const char *err)
static int array[MAX_W *MAX_W]