53 #define CHECK_CU(x) FF_CUDA_CHECK_DL(device_ctx, cu, x)
213 fmts[0] =
ctx->sw_format;
230 int i, ret, copy_queued = 0;
247 CUDA_MEMCPY2D cpy = {
248 .srcPitch =
src->linesize[
i],
250 .WidthInBytes = bytewidth,
254 if (
src->hw_frames_ctx) {
255 cpy.srcMemoryType = CU_MEMORYTYPE_DEVICE;
256 cpy.srcDevice = (CUdeviceptr)
src->data[
i];
258 cpy.srcMemoryType = CU_MEMORYTYPE_HOST;
259 cpy.srcHost =
src->data[
i];
263 cpy.dstMemoryType = CU_MEMORYTYPE_DEVICE;
264 cpy.dstDevice = (CUdeviceptr)dst->
data[
i];
266 cpy.dstMemoryType = CU_MEMORYTYPE_HOST;
267 cpy.dstHost = dst->
data[
i];
283 if (ret < 0 && copy_queued)
343 int ret, dev_active = 0;
344 unsigned int dev_flags = 0;
346 const unsigned int desired_flags = CU_CTX_SCHED_BLOCKING_SYNC;
354 &dev_flags, &dev_active));
358 if (dev_active && dev_flags != desired_flags) {
359 av_log(device_ctx,
AV_LOG_ERROR,
"Primary context already active with incompatible flags.\n");
361 }
else if (dev_flags != desired_flags) {
395 int ret, device_idx = 0;
398 device_idx = strtol(device,
NULL, 0);
429 const char *src_uuid =
NULL;
430 int ret,
i, device_count;
433 VkPhysicalDeviceIDProperties vk_idp = {
434 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES,
438 switch (src_ctx->
type) {
442 VkPhysicalDeviceProperties2 vk_dev_props = {
443 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
446 vkGetPhysicalDeviceProperties2(vkctx->
phys_dev, &vk_dev_props);
447 src_uuid = vk_idp.deviceUUID;
457 "Failed to get UUID of source device.\n");
470 ret =
CHECK_CU(cu->cuDeviceGetCount(&device_count));
475 for (
i = 0;
i < device_count;
i++) {
479 ret =
CHECK_CU(cu->cuDeviceGet(&dev,
i));
483 ret =
CHECK_CU(cu->cuDeviceGetUuid(&uuid, dev));
487 if (memcmp(src_uuid, uuid.bytes, sizeof (uuid.bytes)) == 0) {
refcounted data buffer API
#define flags(name, subs,...)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
#define AV_CUDA_USE_PRIMARY_CONTEXT
Use primary device context instead of creating a new one.
AVBufferRef * av_buffer_create(uint8_t *data, buffer_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(buffer_size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, buffer_size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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.
AVHWFrameTransferDirection
@ AV_HWDEVICE_TYPE_VULKAN
static enum AVPixelFormat supported_formats[]
static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
static int cuda_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
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 AVBufferRef * cuda_pool_alloc(void *opaque, buffer_size_t size)
static int cuda_device_init(AVHWDeviceContext *ctx)
static int cuda_frames_init(AVHWFramesContext *ctx)
static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags)
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.
API-specific header for AV_HWDEVICE_TYPE_VULKAN.
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 char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
#define AV_PIX_FMT_0RGB32
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_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_0BGR32
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
AVCUDADeviceContextInternal * internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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.
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
VkPhysicalDevice phys_dev
Physical device.
#define av_malloc_array(a, b)
static void error(const char *err)