28 #define CUDA_FRAME_ALIGNMENT 256
51 cuCtxPopCurrent(&dummy);
64 err = cuCtxPushCurrent(hwctx->
cuda_ctx);
70 err = cuMemAlloc(&data, size);
81 cuCtxPopCurrent(&dummy);
109 size = aligned_width * ctx->
height * 3 / 2;
112 size = aligned_width * ctx->
height * 3;
142 frame->
data[1] = frame->
data[2] + aligned_width * ctx->
height / 4;
144 frame->
linesize[1] = aligned_width / 2;
145 frame->
linesize[2] = aligned_width / 2;
195 err = cuCtxPushCurrent(device_hwctx->
cuda_ctx);
200 CUDA_MEMCPY2D cpy = {
201 .srcMemoryType = CU_MEMORYTYPE_DEVICE,
202 .dstMemoryType = CU_MEMORYTYPE_HOST,
204 .dstHost = dst->
data[i],
211 err = cuMemcpy2D(&cpy);
218 cuCtxPopCurrent(&dummy);
233 err = cuCtxPushCurrent(device_hwctx->
cuda_ctx);
238 CUDA_MEMCPY2D cpy = {
239 .srcMemoryType = CU_MEMORYTYPE_HOST,
240 .dstMemoryType = CU_MEMORYTYPE_DEVICE,
241 .srcHost = src->
data[i],
249 err = cuMemcpy2D(&cpy);
256 cuCtxPopCurrent(&dummy);
277 device_idx = strtol(device,
NULL, 0);
285 err = cuDeviceGet(&cu_device, device_idx);
291 err = cuCtxCreate(&hwctx->
cuda_ctx, CU_CTX_SCHED_BLOCKING_SYNC, cu_device);
297 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.
static enum AVSampleFormat formats[]
int width
The allocated dimensions of the frames in this pool.
static int cuda_frames_init(AVHWFramesContext *ctx)
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)
An API-specific header for AV_HWDEVICE_TYPE_CUDA.
static void cuda_buffer_free(void *opaque, uint8_t *data)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
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...
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_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)
static void cuda_device_free(AVHWDeviceContext *ctx)
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.
#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...
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.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
This struct is allocated as AVHWDeviceContext.hwctx.
This struct describes a set or pool of "hardware" frames (i.e.
refcounted data buffer API
AVHWFramesInternal * internal
Private data used internally by libavutil.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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)
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)
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.