37#define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
41#define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
110 if (
s->hwctx &&
s->cu_module) {
112 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
113 CHECK_CU(cu->cuCtxPushCurrent(
s->cu_ctx));
114 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
155 s->frames_ctx = out_ref;
172 int out_width,
int out_height)
198 out_width, out_height,
format);
203 s->cu_stream =
s->hwctx->stream;
214 extern const unsigned char ff_vf_transpose_cuda_ptx_data[];
215 extern const unsigned int ff_vf_transpose_cuda_ptx_len;
221 CUcontext
dummy, cuda_ctx;
234 "w:%d h:%d -> w:%d h:%d (passthrough mode)\n",
235 inlink->
w, inlink->
h, inlink->
w, inlink->
h);
246 outlink->
w = inlink->
h;
247 outlink->
h = inlink->
w;
251 outlink->
w = inlink->
w;
252 outlink->
h = inlink->
h;
266 cuda_ctx =
s->cu_ctx =
s->hwctx->cuda_ctx;
267 cu =
s->hwctx->internal->cuda_dl;
269 ret =
CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
274 ff_vf_transpose_cuda_ptx_data, ff_vf_transpose_cuda_ptx_len);
278 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uchar,
s->cu_module,
"Transpose_Cuda_uchar"));
282 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_ushort,
s->cu_module,
"Transpose_Cuda_ushort"));
286 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uchar2,
s->cu_module,
"Transpose_Cuda_uchar2"));
290 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_ushort2,
s->cu_module,
"Transpose_Cuda_ushort2"));
294 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uchar4,
s->cu_module,
"Transpose_Cuda_uchar4"));
299 "w:%d h:%d dir:%d -> w:%d h:%d\n",
300 inlink->
w, inlink->
h,
s->dir, outlink->
w, outlink->
h);
309 CUarray_format cu_format,
324 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
325 CUtexObject src0_tex = 0, src1_tex = 0;
328 void *kernel_args[] = {
329 &dst0, &dst1, &dst_width, &dst_height, &dst_pitch,
330 &src0_tex, &src1_tex, &
s->dir,
333 CUDA_TEXTURE_DESC tex_desc = {
334 .addressMode = { CU_TR_ADDRESS_MODE_CLAMP,
335 CU_TR_ADDRESS_MODE_CLAMP },
336 .filterMode = is_422_uv ? CU_TR_FILTER_MODE_LINEAR
337 : CU_TR_FILTER_MODE_POINT,
340 CUDA_RESOURCE_DESC res_desc = {
341 .resType = CU_RESOURCE_TYPE_PITCH2D,
342 .res.pitch2D.format = cu_format,
343 .res.pitch2D.numChannels =
channels,
344 .res.pitch2D.pitchInBytes = src_pitch,
345 .res.pitch2D.width = src_width,
346 .res.pitch2D.height = src_height
349 res_desc.res.pitch2D.devPtr = (CUdeviceptr)
src0;
350 ret =
CHECK_CU(cu->cuTexObjectCreate(&src0_tex, &res_desc, &tex_desc,
NULL));
355 res_desc.res.pitch2D.devPtr = (CUdeviceptr)
src1;
356 ret =
CHECK_CU(cu->cuTexObjectCreate(&src1_tex, &res_desc, &tex_desc,
NULL));
361 ret =
CHECK_CU(cu->cuLaunchKernel(cu_func,
366 CHECK_CU(cu->cuTexObjectDestroy(src0_tex));
368 CHECK_CU(cu->cuTexObjectDestroy(src1_tex));
379 for (
int c = 0;
c <
s->pix_desc->nb_components;
c++) {
381 const int p =
comp->plane;
383 int is_planar_u, is_planar_v, is_422_uv;
387 pix_size = (
comp->depth + 7) / 8;
392 is_planar_u = p == 1 &&
channels == 1;
393 is_planar_v = p == 2 &&
channels == 1;
394 is_422_uv = p &&
s->pix_desc->log2_chroma_w == 1 && !
s->pix_desc->log2_chroma_h;
396 if (
comp->plane <
c || is_planar_v) {
405 channels == 2 ?
s->cu_func_uchar2 :
s->cu_func_uchar;
406 format = CU_AD_FORMAT_UNSIGNED_INT8;
410 format = CU_AD_FORMAT_UNSIGNED_INT16;
417 (CUdeviceptr)
out->data[p],
418 (CUdeviceptr)(is_planar_u ?
out->data[p+1] :
NULL),
422 (CUdeviceptr)in->
data[p],
423 (CUdeviceptr)(is_planar_u ? in->
data[p+1] :
NULL),
452 s->frame->width = outlink->
w;
453 s->frame->height = outlink->
h;
486 cu =
s->hwctx->internal->cuda_dl;
488 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->cu_ctx));
512 return s->passthrough ?
517#define OFFSET(x) offsetof(TransposeCUDAContext, x)
518#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
558 .p.name =
"transpose_cuda",
560 .p.priv_class = &cudatranspose_class,
static const char *const format[]
const FFFilter ff_vf_transpose_cuda
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
FFmpeg internal API for CUDA.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_cuda_load_module(void *avctx, AVCUDADeviceContext *hwctx, CUmodule *cu_module, const unsigned char *data, const unsigned int length)
Loads a CUDA module and applies any decompression, if necessary.
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_0RGB32
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12MSB
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_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ 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_YUV444P10MSB
#define AV_PIX_FMT_0BGR32
#define AV_PIX_FMT_YUV444P10
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int width
The allocated dimensions of the frames in this pool.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Link properties exposed to filter code, but not external callers.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
int passthrough
PassthroughType, landscape passthrough mode enabled.
const AVPixFmtDescriptor * pix_desc
CUfunction cu_func_ushort
AVCUDADeviceContext * hwctx
CUfunction cu_func_uchar2
CUfunction cu_func_ushort2
CUfunction cu_func_uchar4
static AVFormatContext * ctx
@ TRANSPOSE_PT_TYPE_PORTRAIT
@ TRANSPOSE_PT_TYPE_LANDSCAPE
static enum AVPixelFormat supported_formats[]
static av_cold int init_hwframe_ctx(TransposeCUDAContext *s, AVBufferRef *device_ctx, int width, int height, enum AVPixelFormat sw_format)
static AVFrame * cudatranspose_get_video_buffer(AVFilterLink *inlink, int w, int h)
static av_cold void cudatranspose_uninit(AVFilterContext *ctx)
static int cudatranspose_transpose(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
static const AVOption cudatranspose_options[]
static int cudatranspose_rotate(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
static CUresult call_kernel(AVFilterContext *ctx, CUfunction cu_func, CUarray_format cu_format, int channels, int is_422_uv, CUdeviceptr dst0, CUdeviceptr dst1, int dst_width, int dst_height, int dst_pitch, CUdeviceptr src0, CUdeviceptr src1, int src_width, int src_height, int src_pitch)
static av_cold int cudatranspose_init(AVFilterContext *ctx)
static int cudatranspose_filter_frame(AVFilterLink *link, AVFrame *in)
static int init_processing_chain(AVFilterContext *ctx, int out_width, int out_height)
static int format_is_supported(enum AVPixelFormat fmt)
static const AVFilterPad cudatranspose_inputs[]
static int cudatranspose_config_props(AVFilterLink *outlink)
static const AVFilterPad cudatranspose_outputs[]
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)