Go to the documentation of this file.
49 #define CHECK_CU(x) FF_CUDA_CHECK_DL(device_ctx, cu, x)
74 #if HAVE_FFNVCODEC_CUARRAY
225 #if HAVE_FFNVCODEC_CUARRAY
256 #if HAVE_FFNVCODEC_CUARRAY
257 static unsigned int cuda_array_numchannels_for_pix_fmt(
enum AVPixelFormat fmt)
290 #if HAVE_FFNVCODEC_CUARRAY
297 av_log(
ctx,
AV_LOG_ERROR,
"Missing support for cuarray frames. Rebuild with newer ffnvcodec headers.\n");
318 #if HAVE_FFNVCODEC_CUARRAY
325 priv->
p.
cuarray_desc.NumChannels = cuda_array_numchannels_for_pix_fmt(
ctx->sw_format);
339 priv->
p.
cuarray_desc.Flags |= CUDA_ARRAY3D_SURFACE_LDST | CUDA_ARRAY3D_VIDEO_ENCODE_DECODE;
358 for (
i =
i - 1;
i >= 0;
i--)
401 #if HAVE_FFNVCODEC_CUARRAY
415 #if HAVE_FFNVCODEC_CUARRAY
431 CUDA_ARRAY3D_DESCRIPTOR plane_desc = { 0 };
433 CUresult arr_plane_res = cu->cuArrayGetPlane(&plane_array,
desc->array,
i);
435 if (arr_plane_res == CUDA_ERROR_INVALID_VALUE) {
440 res =
CHECK_CU(cu->cuArray3DGetDescriptor(&plane_desc,
desc->array));
443 }
else if (arr_plane_res != CUDA_SUCCESS) {
447 res =
CHECK_CU(cu->cuArray3DGetDescriptor(&plane_desc, plane_array));
453 if (elem_size <= 0) {
458 frame->linesize[
i] = plane_desc.Width * plane_desc.NumChannels * elem_size;
460 if (arr_plane_res == CUDA_ERROR_INVALID_VALUE)
491 #if HAVE_FFNVCODEC_CUARRAY
500 if (!
frame->hw_frames_ctx)
515 fmts[0] =
ctx->sw_format;
532 int i,
ret, copy_queued = 0;
567 int src_is_nonplanar_cuarray = 0;
568 int dst_is_nonplanar_cuarray = 0;
570 CUDA_MEMCPY2D cpy = {
571 .srcPitch =
src->linesize[
i],
572 .dstPitch =
dst->linesize[
i],
578 cpy.srcMemoryType = CU_MEMORYTYPE_DEVICE;
579 cpy.srcDevice = (CUdeviceptr)
src->data[
i];
581 #if HAVE_FFNVCODEC_CUARRAY
583 CUresult cures = cu->cuArrayGetPlane(&
array, (CUarray)
src->data[0],
i);
584 if (cures == CUDA_ERROR_INVALID_VALUE &&
i == 0) {
588 src_is_nonplanar_cuarray = 1;
589 }
else if (cures != CUDA_SUCCESS) {
594 cpy.srcMemoryType = CU_MEMORYTYPE_ARRAY;
595 cpy.srcArray =
array;
601 cpy.srcMemoryType = CU_MEMORYTYPE_HOST;
602 cpy.srcHost =
src->data[
i];
606 cpy.dstMemoryType = CU_MEMORYTYPE_DEVICE;
607 cpy.dstDevice = (CUdeviceptr)
dst->data[
i];
609 #if HAVE_FFNVCODEC_CUARRAY
611 CUresult cures = cu->cuArrayGetPlane(&
array, (CUarray)
dst->data[0],
i);
612 if (cures == CUDA_ERROR_INVALID_VALUE &&
i == 0) {
616 dst_is_nonplanar_cuarray = 1;
617 }
else if (cures != CUDA_SUCCESS) {
622 cpy.dstMemoryType = CU_MEMORYTYPE_ARRAY;
623 cpy.dstArray =
array;
629 cpy.dstMemoryType = CU_MEMORYTYPE_HOST;
630 cpy.dstHost =
dst->data[
i];
638 if (src_is_nonplanar_cuarray || dst_is_nonplanar_cuarray)
642 if (!
dst->hw_frames_ctx) {
649 if (
ret < 0 && copy_queued)
705 int ret, dev_active = 0;
706 unsigned int dev_flags = 0;
708 const unsigned int desired_flags = CU_CTX_SCHED_BLOCKING_SYNC;
716 &dev_flags, &dev_active));
720 if (dev_active && dev_flags != desired_flags) {
721 av_log(device_ctx,
AV_LOG_ERROR,
"Primary context already active with incompatible flags.\n");
723 }
else if (dev_flags != desired_flags) {
762 int use_primary_ctx = 0, use_current_ctx = 0;
764 use_primary_ctx = strtol(primary_ctx_opt->
value,
NULL, 10);
767 use_current_ctx = strtol(current_ctx_opt->
value,
NULL, 10);
769 if (use_primary_ctx && use_current_ctx) {
770 av_log(device_ctx,
AV_LOG_ERROR,
"Requested both primary and current CUDA context simultaneously.\n");
774 if (primary_ctx_opt && use_primary_ctx) {
777 }
else if (primary_ctx_opt) {
782 if (current_ctx_opt && use_current_ctx) {
785 }
else if (current_ctx_opt) {
799 int ret, device_idx = 0;
806 device_idx = strtol(device,
NULL, 0);
838 const char *src_uuid =
NULL;
840 VkPhysicalDeviceIDProperties vk_idp;
842 int ret,
i, device_count;
849 vk_idp = (VkPhysicalDeviceIDProperties) {
850 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES,
854 switch (src_ctx->
type) {
856 #define TYPE PFN_vkGetPhysicalDeviceProperties2
860 VkPhysicalDeviceProperties2 vk_dev_props = {
861 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
864 prop_fn(vkctx->
phys_dev, &vk_dev_props);
865 src_uuid = vk_idp.deviceUUID;
877 "Failed to get UUID of source device.\n");
892 ret =
CHECK_CU(cu->cuDeviceGetCount(&device_count));
897 for (
i = 0;
i < device_count;
i++) {
909 if (memcmp(src_uuid, uuid.bytes, sizeof (uuid.bytes)) == 0) {
952 #if HAVE_FFNVCODEC_CUARRAY
static void error(const char *err)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVBufferPool * pool_internal
VkPhysicalDevice phys_dev
Physical device.
static int ff_cuda_cuarray_elem_size(CUarray_format fmt)
Return the element size in bytes for a CUarray_format, or 0 for unknown.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel format.
static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int cuda_device_derive(AVHWDeviceContext *device_ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
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)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUV444P10MSB
This structure describes decoded (raw) audio or video data.
AVCUDADeviceContextInternal internal
PFN_vkGetInstanceProcAddr get_proc_addr
Pointer to a vkGetInstanceProcAddr loading function.
#define AV_PIX_FMT_YUV420P10
VkInstance inst
Vulkan instance.
#define AV_LOG_VERBOSE
Detailed information.
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
#define AV_PIX_FMT_YUV444P12MSB
@ AV_HWDEVICE_TYPE_VULKAN
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
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.
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.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
#define AV_PIX_FMT_YUV444P10
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
CUarray * cuarray_surfaces
If cuarray_num_surfaces is >0, this contains the array of pre-allocated surfaces.
#define FF_ARRAY_ELEMS(a)
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
#define flags(name, subs,...)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
#define AV_PIX_FMT_0BGR32
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int cuarray_num_surfaces
If >0, pre-allocate a fixed pool of surfaces.
static AVFormatContext * ctx
static int cuda_device_init(AVHWDeviceContext *ctx)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
static AVDictionary * opts
#define AV_CUDA_USE_CURRENT_CONTEXT
Use current device context instead of creating a new one.
#define AV_PIX_FMT_YUV422P10
static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
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.
AVCUDADeviceContextInternal * internal
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.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define i(width, name, range_min, range_max)
const HWContextType ff_hwcontext_type_cuda
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
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.
static enum AVPixelFormat cuda_frame_hw_format(const AVFrame *frame)
#define AV_LOG_INFO
Standard information.
This struct is allocated as AVHWFramesContext.hwctx.
CUDA frame descriptor for pool allocation of AV_PIX_FMT_CUARRAY frames.
@ AV_PIX_FMT_CUARRAY
hardware decoding through openharmony
#define av_malloc_array(a, b)
@ 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...
static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
void * av_calloc(size_t nmemb, size_t size)
AVHWFrameTransferDirection
static CUarray_format cuda_array_format_for_pix_fmt(enum AVPixelFormat fmt)
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
static int array[MAX_W *MAX_W]
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
@ 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...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define AV_PIX_FMT_0RGB32
static void cuda_buffer_free(void *opaque, uint8_t *data)
#define AV_CUDA_USE_PRIMARY_CONTEXT
Use primary device context instead of creating a new one.
static int cuda_device_create(AVHWDeviceContext *device_ctx, const char *device, AVDictionary *opts, int flags)
int cuarray_num_surfaces_used
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
A reference to a data buffer.
static AVBufferRef * cuda_pool_alloc(void *opaque, size_t size)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
CUDA hardware pipeline configuration details.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
static int cuda_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
static int cuda_frames_init(AVHWFramesContext *ctx)
static void cuda_frames_uninit(AVHWFramesContext *ctx)
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
CUDA_ARRAY3D_DESCRIPTOR cuarray_desc
CUDA_ARRAY3D_DESCRIPTOR CUarrays will be initialized with.