29 #define CUDA_FRAME_ALIGNMENT 256
79 cu->cuCtxPushCurrent(hwctx->
cuda_ctx);
81 cu->cuMemFree((CUdeviceptr)data);
83 cu->cuCtxPopCurrent(&dummy);
97 err = cu->cuCtxPushCurrent(hwctx->
cuda_ctx);
98 if (err != CUDA_SUCCESS) {
103 err = cu->cuMemAlloc(&data, size);
104 if (err != CUDA_SUCCESS)
114 cu->cuCtxPopCurrent(&dummy);
205 err = cu->cuCtxPushCurrent(device_hwctx->
cuda_ctx);
206 if (err != CUDA_SUCCESS)
210 CUDA_MEMCPY2D cpy = {
211 .srcMemoryType = CU_MEMORYTYPE_DEVICE,
212 .dstMemoryType = CU_MEMORYTYPE_HOST,
213 .srcDevice = (CUdeviceptr)src->
data[i],
214 .dstHost = dst->
data[i],
221 err = cu->cuMemcpy2DAsync(&cpy, device_hwctx->
stream);
222 if (err != CUDA_SUCCESS) {
228 err = cu->cuStreamSynchronize(device_hwctx->
stream);
229 if (err != CUDA_SUCCESS) {
234 cu->cuCtxPopCurrent(&dummy);
250 err = cu->cuCtxPushCurrent(device_hwctx->
cuda_ctx);
251 if (err != CUDA_SUCCESS)
255 CUDA_MEMCPY2D cpy = {
256 .srcMemoryType = CU_MEMORYTYPE_HOST,
257 .dstMemoryType = CU_MEMORYTYPE_DEVICE,
258 .srcHost = src->
data[i],
259 .dstDevice = (CUdeviceptr)dst->
data[i],
266 err = cu->cuMemcpy2DAsync(&cpy, device_hwctx->
stream);
267 if (err != CUDA_SUCCESS) {
273 err = cu->cuStreamSynchronize(device_hwctx->
stream);
274 if (err != CUDA_SUCCESS) {
279 cu->cuCtxPopCurrent(&dummy);
336 device_idx = strtol(device,
NULL, 0);
344 if (err != CUDA_SUCCESS) {
349 err = cu->cuDeviceGet(&cu_device, device_idx);
350 if (err != CUDA_SUCCESS) {
355 err = cu->cuCtxCreate(&hwctx->
cuda_ctx, CU_CTX_SCHED_BLOCKING_SYNC, cu_device);
356 if (err != CUDA_SUCCESS) {
364 cu->cuCtxPopCurrent(&dummy);
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Memory handling functions.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
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...
int width
The allocated dimensions of the frames in this pool.
static int cuda_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
static int cuda_frames_init(AVHWFramesContext *ctx)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVBufferPool * pool_internal
static enum AVPixelFormat supported_formats[]
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
static int cuda_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
#define AV_PIX_FMT_YUV444P16
static void cuda_buffer_free(void *opaque, uint8_t *data)
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...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
#define AV_PIX_FMT_0BGR32
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.
static int cuda_device_init(AVHWDeviceContext *ctx)
static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
static int cuda_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static AVBufferRef * cuda_pool_alloc(void *opaque, int size)
FFmpeg internal API for CUDA.
HW acceleration through CUDA.
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.
static void error(const char *err)
#define FF_ARRAY_ELEMS(a)
#define CUDA_FRAME_ALIGNMENT
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
static int cuda_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
const HWContextType ff_hwcontext_type_cuda
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
This struct describes a set or pool of "hardware" frames (i.e.
refcounted data buffer API
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
AVHWFramesInternal * internal
Private data used internally by libavutil.
#define flags(name, subs,...)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
A reference to a data buffer.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
AVHWFrameTransferDirection
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
static int cuda_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
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.
#define av_malloc_array(a, b)
static void cuda_device_uninit(AVHWDeviceContext *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.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
#define AV_PIX_FMT_0RGB32