Go to the documentation of this file.
33 #define CUDA_FRAME_ALIGNMENT 256
54 #define CHECK_CU(x) FF_CUDA_CHECK_DL(device_ctx, cu, x)
196 fmts[0] =
ctx->sw_format;
224 CUDA_MEMCPY2D cpy = {
225 .srcPitch =
src->linesize[
i],
231 if (
src->hw_frames_ctx) {
232 cpy.srcMemoryType = CU_MEMORYTYPE_DEVICE;
233 cpy.srcDevice = (CUdeviceptr)
src->data[
i];
235 cpy.srcMemoryType = CU_MEMORYTYPE_HOST;
236 cpy.srcHost =
src->data[
i];
240 cpy.dstMemoryType = CU_MEMORYTYPE_DEVICE;
241 cpy.dstDevice = (CUdeviceptr)dst->
data[
i];
243 cpy.dstMemoryType = CU_MEMORYTYPE_HOST;
244 cpy.dstHost = dst->
data[
i];
316 int ret, dev_active = 0;
317 unsigned int dev_flags = 0;
319 const unsigned int desired_flags = CU_CTX_SCHED_BLOCKING_SYNC;
327 &dev_flags, &dev_active));
331 if (dev_active && dev_flags != desired_flags) {
332 av_log(device_ctx,
AV_LOG_ERROR,
"Primary context already active with incompatible flags.\n");
334 }
else if (dev_flags != desired_flags) {
368 int ret, device_idx = 0;
371 device_idx = strtol(device,
NULL, 0);
402 const char *src_uuid =
NULL;
403 int ret,
i, device_count;
406 VkPhysicalDeviceIDProperties vk_idp = {
407 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES,
411 switch (src_ctx->
type) {
415 VkPhysicalDeviceProperties2 vk_dev_props = {
416 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
419 vkGetPhysicalDeviceProperties2(vkctx->
phys_dev, &vk_dev_props);
420 src_uuid = vk_idp.deviceUUID;
430 "Failed to get UUID of source device.\n");
443 ret =
CHECK_CU(cu->cuDeviceGetCount(&device_count));
448 for (
i = 0;
i < device_count;
i++) {
460 if (memcmp(src_uuid, uuid.bytes, sizeof (uuid.bytes)) == 0) {
static void error(const char *err)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
VkPhysicalDevice phys_dev
Physical device.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
#define CUDA_FRAME_ALIGNMENT
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)
uint8_t * data
The data buffer.
This structure describes decoded (raw) audio or video data.
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
@ AV_HWDEVICE_TYPE_VULKAN
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
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_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_0BGR32
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 int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
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.
const HWContextType ff_hwcontext_type_cuda
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 AVBufferRef * cuda_pool_alloc(void *opaque, int size)
#define i(width, name, range_min, range_max)
#define av_malloc_array(a, b)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
AVBufferPool * av_buffer_pool_init2(int size, void *opaque, AVBufferRef *(*alloc)(void *opaque, int size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
AVHWFrameTransferDirection
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
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 FF_ARRAY_ELEMS(a)
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
#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)
static enum AVPixelFormat supported_formats[]
@ 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)
A reference to a data buffer.
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int cuda_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
static int cuda_frames_init(AVHWFramesContext *ctx)
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.