46 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
47 #define ALIGN_UP(a, b) (((a) + (b) - 1) & ~((b) - 1))
51 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
54 CUdeviceptr prev, CUdeviceptr cur, CUdeviceptr next,
66 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
67 CUtexObject tex_prev = 0, tex_cur = 0, tex_next = 0;
69 int skip_spatial_check =
s->yadif.mode&2;
71 void *args[] = { &dst, &tex_prev, &tex_cur, &tex_next,
72 &dst_width, &dst_height, &dst_pitch,
73 &src_width, &src_height, &
parity, &tff,
74 &skip_spatial_check };
76 CUDA_TEXTURE_DESC tex_desc = {
77 .filterMode = CU_TR_FILTER_MODE_POINT,
78 .flags = CU_TRSF_READ_AS_INTEGER,
81 CUDA_RESOURCE_DESC res_desc = {
82 .resType = CU_RESOURCE_TYPE_PITCH2D,
83 .res.pitch2D.format =
format,
85 .res.pitch2D.width = src_width,
86 .res.pitch2D.height = src_height,
87 .res.pitch2D.pitchInBytes = src_pitch,
90 res_desc.res.pitch2D.devPtr = (CUdeviceptr)prev;
91 ret =
CHECK_CU(cu->cuTexObjectCreate(&tex_prev, &res_desc, &tex_desc,
NULL));
95 res_desc.res.pitch2D.devPtr = (CUdeviceptr)cur;
96 ret =
CHECK_CU(cu->cuTexObjectCreate(&tex_cur, &res_desc, &tex_desc,
NULL));
100 res_desc.res.pitch2D.devPtr = (CUdeviceptr)next;
101 ret =
CHECK_CU(cu->cuTexObjectCreate(&tex_next, &res_desc, &tex_desc,
NULL));
108 0,
s->stream, args,
NULL));
112 CHECK_CU(cu->cuTexObjectDestroy(tex_prev));
114 CHECK_CU(cu->cuTexObjectDestroy(tex_cur));
116 CHECK_CU(cu->cuTexObjectDestroy(tex_next));
126 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
130 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->cu_ctx));
140 if (
comp->plane <
i) {
146 pixel_size = (
comp->depth +
comp->shift) / 8;
148 if (pixel_size > 2 ||
channels > 2) {
152 switch (pixel_size) {
155 format = CU_AD_FORMAT_UNSIGNED_INT8;
159 format = CU_AD_FORMAT_UNSIGNED_INT16;
166 "Deinterlacing plane %d: pixel_size: %d channels: %d\n",
176 (CUdeviceptr)dst->
data[
i],
194 if (
s->hwctx &&
s->cu_module) {
195 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
196 CHECK_CU(cu->cuCtxPushCurrent(
s->cu_ctx));
197 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
208 s->input_frames =
NULL;
219 &
ctx->inputs[0]->outcfg.formats)) < 0)
222 &
ctx->outputs[0]->incfg.formats)) < 0)
235 "required to associate the processing device.\n");
240 if (!
s->input_frames_ref) {
262 if (!
s->device_ref) {
268 s->cu_ctx =
s->hwctx->cuda_ctx;
269 s->stream =
s->hwctx->stream;
270 cu =
s->hwctx->internal->cuda_dl;
283 output_frames->
sw_format =
s->input_frames->sw_format;
284 output_frames->
width =
ctx->inputs[0]->w;
285 output_frames->
height =
ctx->inputs[0]->h;
296 "context for output: %d\n", ret);
302 link->
w =
ctx->inputs[0]->w;
303 link->
h =
ctx->inputs[0]->h;
309 if (link->
w < 3 || link->
h < 3) {
318 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->cu_ctx));
326 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uchar,
s->cu_module,
"yadif_uchar"));
330 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uchar2,
s->cu_module,
"yadif_uchar2"));
334 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_ushort,
s->cu_module,
"yadif_ushort"));
338 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_ushort2,
s->cu_module,
"yadif_ushort2"));
377 .
name =
"yadif_cuda",
static int query_formats(AVFilterContext *ctx)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.
#define flags(name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
static av_cold int uninit(AVCodecContext *avctx)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
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(AVBufferRef *buf)
Create a new reference to an AVBuffer.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
#define LIBAVUTIL_VERSION_INT
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.
FFmpeg internal API for CUDA.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
@ AV_CLASS_CATEGORY_FILTER
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
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.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int initial_pool_size
Initial size of the frame pool.
int width
The allocated dimensions of the frames in this pool.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
uint8_t nb_components
The number of components each pixel has, (1-4)
Rational number (pair of numerator and denominator).
AVBufferRef * input_frames_ref
AVCUDADeviceContext * hwctx
CUfunction cu_func_uchar2
CUfunction cu_func_ushort2
AVHWFramesContext * input_frames
CUfunction cu_func_ushort
void(* filter)(AVFilterContext *ctx, AVFrame *dstpic, int parity, int tff)
const AVPixFmtDescriptor * csp
static CUresult call_kernel(AVFilterContext *ctx, CUfunction func, CUdeviceptr prev, CUdeviceptr cur, CUdeviceptr next, CUarray_format format, int channels, int src_width, int src_height, int src_pitch, CUdeviceptr dst, int dst_width, int dst_height, int dst_pitch, int parity, int tff)
static void filter(AVFilterContext *ctx, AVFrame *dst, int parity, int tff)
static av_cold void deint_cuda_uninit(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
static int deint_cuda_query_formats(AVFilterContext *ctx)
AVFilter ff_vf_yadif_cuda
static const AVClass yadif_cuda_class
static const AVFilterPad deint_cuda_inputs[]
static int config_output(AVFilterLink *link)
static const AVFilterPad deint_cuda_outputs[]
int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame)
int ff_yadif_request_frame(AVFilterLink *link)
const AVOption ff_yadif_options[]