Go to the documentation of this file.
41 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
42 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
128 double var_values[
VARS_NB], res;
138 (
double)
inlink->sample_aspect_ratio.num /
139 inlink->sample_aspect_ratio.den : 1;
145 ret =
av_expr_parse_and_eval(&res, expr,
var_names, var_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0,
ctx);
159 ret =
av_expr_parse_and_eval(&res, expr,
var_names, var_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0,
ctx);
178 ret =
av_expr_parse_and_eval(&res, expr,
var_names, var_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0,
ctx);
195 ret =
av_expr_parse_and_eval(&res, expr,
var_names, var_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0,
ctx);
203 ret =
av_expr_parse_and_eval(&res, expr,
var_names, var_values,
NULL,
NULL,
NULL,
NULL,
NULL, 0,
ctx);
209 if (
s->x < 0 ||
s->x +
s->in_w >
s->w) {
210 s->x = (
s->w -
s->in_w) / 2;
214 if (
s->y < 0 ||
s->y +
s->in_h >
s->h) {
215 s->y = (
s->h -
s->in_h) / 2;
222 if (
s->w <
s->in_w ||
s->h <
s->in_h) {
228 "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X\n",
230 s->rgba_color[1],
s->rgba_color[2],
s->rgba_color[3]);
247 if (!*out_frames_ctx) {
285 if (
s->hwctx &&
s->cu_module) {
286 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
288 CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
289 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
300 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
301 CUcontext dummy_cu_ctx;
306 extern const unsigned char ff_vf_pad_cuda_ptx_data[];
307 extern const unsigned int ff_vf_pad_cuda_ptx_len;
314 ff_vf_pad_cuda_ptx_data, ff_vf_pad_cuda_ptx_len);
320 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uchar,
s->cu_module,
"pad_uchar"));
326 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uchar2,
s->cu_module,
"pad_uchar2"));
331 CHECK_CU(cu->cuCtxPopCurrent(&dummy_cu_ctx));
347 int format_supported = 0;
366 format_supported = 1;
370 if (!format_supported) {
375 s->parsed_color[0] =
RGB_TO_Y_BT709(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2]);
376 s->parsed_color[1] =
RGB_TO_U_BT709(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2], 0);
377 s->parsed_color[2] =
RGB_TO_V_BT709(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2], 0);
378 s->parsed_color[3] =
s->rgba_color[3];
393 s->last_out_w =
s->w;
394 s->last_out_h =
s->h;
411 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
417 for (
int plane = 0; plane < nb_planes; plane++) {
419 for (
int comp = 1;
comp < pixdesc->nb_components && cur_comp->
plane != plane;
comp++)
420 cur_comp = &pixdesc->comp[
comp];
422 int hsub = (plane == 1 || plane == 2) ? pixdesc->log2_chroma_w : 0;
423 int vsub = (plane == 1 || plane == 2) ? pixdesc->log2_chroma_h : 0;
434 if (x_plane_offset + src_w > dst_w || y_plane_offset + src_h > dst_h) {
436 "ROI out of bounds in plane %d: offset=(%d,%d) in=(%dx%d) "
438 plane, x_plane_offset, y_plane_offset, src_w, src_h, dst_w, dst_h);
442 int dst_linesize =
out->linesize[plane] / cur_comp->
step;
443 int src_linesize = in->
linesize[plane] / cur_comp->
step;
445 CUdeviceptr d_dst = (CUdeviceptr)
out->data[plane];
446 CUdeviceptr d_src = (CUdeviceptr)in->
data[plane];
448 CUfunction cuda_func;
450 if (cur_comp->
step == 1 && cur_comp->
depth == 8)
451 cuda_func =
s->cu_func_uchar;
452 else if(cur_comp->
step == 2 && cur_comp->
depth == 8)
453 cuda_func =
s->cu_func_uchar2;
457 void *kernel_args[] = {
458 &d_dst, &dst_linesize, &dst_w, &dst_h,
459 &d_src, &src_linesize, &src_w, &src_h,
460 &x_plane_offset, &y_plane_offset, &
s->parsed_color[plane]
466 ret =
CHECK_CU(cu->cuLaunchKernel(cuda_func, grid_x, grid_y, 1,
468 0,
s->hwctx->stream, kernel_args,
NULL));
505 if (
s->x == 0 &&
s->y == 0 &&
508 s->last_out_w =
s->w;
509 s->last_out_h =
s->h;
514 if (
s->w !=
s->last_out_w ||
s->h !=
s->last_out_h) {
532 s->last_out_w =
s->w;
533 s->last_out_h =
s->h;
552 ret =
CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPushCurrent(
553 device_hwctx->cuda_ctx));
562 CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&
dummy));
575 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
584 #define OFFSET(x) offsetof(CUDAPadContext, x)
585 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
622 .
p.
name =
"pad_cuda",
int in_h
width and height for the padded input video
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel format.
static const AVFilterPad cuda_pad_outputs[]
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
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.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
char * w_expr
width expression
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int depth
Number of bits in the component.
int h
output dimensions, a value of 0 will result in the input size
int step
Number of elements between 2 horizontally consecutive pixels.
#define AV_LOG_VERBOSE
Detailed information.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
const char * name
Filter name.
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
int width
The allocated dimensions of the frames in this pool.
char * h_expr
height expression
A link between two filters.
static av_cold int cuda_pad_load_functions(AVFilterContext *ctx)
static int eval_expr(AVFilterContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Link properties exposed to filter code, but not external callers.
char * y_expr
y offset expression
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static const AVFilterPad cuda_pad_inputs[]
static const AVOption cuda_pad_options[]
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static int cuda_pad_alloc_out_frames_ctx(AVFilterContext *ctx, AVBufferRef **out_frames_ctx, const int width, const int height)
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int cuda_pad_pad(AVFilterContext *ctx, AVFrame *out, const AVFrame *in)
int y
offsets of the input area with respect to the padded area
#define RGB_TO_Y_BT709(r, g, b)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_CEIL_RSHIFT(a, b)
#define RGB_TO_U_BT709(r1, g1, b1, max)
static const AVClass cuda_pad_class
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_OUTPUTS(array)
static int cuda_pad_config_props(AVFilterLink *outlink)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Rational number (pair of numerator and denominator).
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
int plane
Which of the 4 planes contains the component.
const char * av_default_item_name(void *ptr)
Return the context name.
const FFFilter ff_vf_pad_cuda
uint8_t rgba_color[4]
color for the padding area
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int last_out_h
used to evaluate the prior output width and height with the incoming frame
#define RGB_TO_V_BT709(r1, g1, b1, max)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int format
agreed upon media format
CUfunction cu_func_uchar2
AVFilterContext * src
source filter
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
static int cuda_pad_filter_frame(AVFilterLink *inlink, AVFrame *in)
static enum AVPixelFormat supported_formats[]
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
static const char *const var_names[]
AVCUDADeviceContext * hwctx
#define i(width, name, range_min, range_max)
int w
agreed upon image width
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
@ 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...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int h
agreed upon image height
@ AV_OPT_TYPE_INT
Underlying C type is int.
char * x_expr
x offset expression
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
AVFilter p
The public AVFilter.
A reference to a data buffer.
static av_cold void cuda_pad_uninit(AVFilterContext *ctx)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static av_cold int cuda_pad_init(AVFilterContext *ctx)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)