46 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
47 #define ALIGN_UP(a, b) (((a) + (b) - 1) & ~((b) - 1))
54 const char *err_string;
58 if (err == CUDA_SUCCESS)
61 cuGetErrorName(err, &err_name);
62 cuGetErrorString(err, &err_string);
65 if (err_name && err_string)
72 #define CHECK_CU(x) check_cu(ctx, (x), #x)
75 CUdeviceptr prev, CUdeviceptr cur, CUdeviceptr next,
87 CUtexObject tex_prev = 0, tex_cur = 0, tex_next = 0;
91 void *
args[] = { &dst, &tex_prev, &tex_cur, &tex_next,
93 &src_width, &src_height, &
parity, &tff,
94 &skip_spatial_check };
96 CUDA_TEXTURE_DESC tex_desc = {
97 .filterMode = CU_TR_FILTER_MODE_POINT,
98 .flags = CU_TRSF_READ_AS_INTEGER,
101 CUDA_RESOURCE_DESC res_desc = {
102 .resType = CU_RESOURCE_TYPE_PITCH2D,
103 .res.pitch2D.format =
format,
104 .res.pitch2D.numChannels =
channels,
105 .res.pitch2D.width = src_width,
106 .res.pitch2D.height = src_height,
110 res_desc.res.pitch2D.devPtr = (CUdeviceptr)prev;
111 err =
CHECK_CU(cuTexObjectCreate(&tex_prev, &res_desc, &tex_desc,
NULL));
112 if (err != CUDA_SUCCESS) {
116 res_desc.res.pitch2D.devPtr = (CUdeviceptr)cur;
117 err =
CHECK_CU(cuTexObjectCreate(&tex_cur, &res_desc, &tex_desc,
NULL));
118 if (err != CUDA_SUCCESS) {
122 res_desc.res.pitch2D.devPtr = (CUdeviceptr)next;
123 err =
CHECK_CU(cuTexObjectCreate(&tex_next, &res_desc, &tex_desc,
NULL));
124 if (err != CUDA_SUCCESS) {
135 CHECK_CU(cuTexObjectDestroy(tex_prev));
137 CHECK_CU(cuTexObjectDestroy(tex_cur));
139 CHECK_CU(cuTexObjectDestroy(tex_next));
154 if (err != CUDA_SUCCESS) {
164 if (comp->
plane < i) {
171 channels = comp->
step / pixel_size;
172 if (pixel_size > 2 || channels > 2) {
176 switch (pixel_size) {
179 format = CU_AD_FORMAT_UNSIGNED_INT8;
183 format = CU_AD_FORMAT_UNSIGNED_INT16;
190 "Deinterlacing plane %d: pixel_size: %d channels: %d\n",
191 comp->
plane, pixel_size, channels);
200 (CUdeviceptr)dst->
data[i],
208 if (err != CUDA_SUCCESS) {
263 "required to associate the processing device.\n");
323 "context for output: %d\n", ret);
336 if (link->w < 3 || link->h < 3) {
345 err =
CHECK_CU(cuCtxPushCurrent(
s->cu_ctx));
346 if (err != CUDA_SUCCESS) {
352 if (err != CUDA_SUCCESS) {
357 err =
CHECK_CU(cuModuleGetFunction(&
s->cu_func_uchar,
s->cu_module,
"yadif_uchar"));
358 if (err != CUDA_SUCCESS) {
363 err =
CHECK_CU(cuModuleGetFunction(&
s->cu_func_uchar2,
s->cu_module,
"yadif_uchar2"));
364 if (err != CUDA_SUCCESS) {
369 err=
CHECK_CU(cuModuleGetFunction(&
s->cu_func_ushort,
s->cu_module,
"yadif_ushort"));
370 if (err != CUDA_SUCCESS) {
375 err =
CHECK_CU(cuModuleGetFunction(&
s->cu_func_ushort2,
s->cu_module,
"yadif_ushort2"));
376 if (err != CUDA_SUCCESS) {
416 .
name =
"yadif_cuda",
419 .priv_class = &yadif_cuda_class,
422 .
inputs = deint_cuda_inputs,
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
int plane
Which of the 4 planes contains the component.
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static const char * format[]
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
BYTE int const BYTE int src_pitch
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)
#define LIBAVUTIL_VERSION_INT
static av_cold void deint_cuda_uninit(AVFilterContext *ctx)
int h
agreed upon image height
int ff_yadif_request_frame(AVFilterLink *link)
const char * av_default_item_name(void *ptr)
Return the context name.
int width
The allocated dimensions of the frames in this pool.
static int config_input(AVFilterLink *inlink)
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
static void filter(AVFilterContext *ctx, AVFrame *dst, int parity, int tff)
AVHWFramesContext * input_frames
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static av_cold int uninit(AVCodecContext *avctx)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
An API-specific header for AV_HWDEVICE_TYPE_CUDA.
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
simple assert() macros that are a bit more flexible than ISO C assert().
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
int w
agreed upon image width
int initial_pool_size
Initial size of the frame pool.
uint8_t nb_components
The number of components each pixel has, (1-4)
static const AVClass yadif_cuda_class
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames...
CUfunction cu_func_uchar2
AVFilterContext * src
source filter
AVCUDADeviceContext * hwctx
static const AVFilterPad inputs[]
HW acceleration through CUDA.
static const AVFilterPad outputs[]
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
CUfunction cu_func_ushort2
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFilter ff_vf_yadif_cuda
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame)
This struct describes a set or pool of "hardware" frames (i.e.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
static const AVFilterPad deint_cuda_outputs[]
const char * name
Filter name.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
AVFilterLink ** outputs
array of pointers to output links
int shift
Number of least significant bits that must be shifted away to get the value.
static enum AVPixelFormat pix_fmts[]
CUfunction cu_func_ushort
#define flags(name, subs,...)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
const AVPixFmtDescriptor * csp
static int config_output(AVFilterLink *link)
AVBufferRef * input_frames_ref
static const AVFilterPad deint_cuda_inputs[]
A reference to a data buffer.
static int check_cu(AVFilterContext *avctx, CUresult err, const char *func)
static int query_formats(AVFilterContext *ctx)
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
const AVOption ff_yadif_options[]
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.
AVFilterContext * dst
dest filter
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static int deint_cuda_query_formats(AVFilterContext *ctx)
int depth
Number of bits in the component.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
AVFilterFormats * out_formats
int step
Number of elements between 2 horizontally consecutive pixels.
#define AV_CEIL_RSHIFT(a, b)