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;
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",
229 inlink->
w, inlink->
h,
s->w,
s->h,
s->x,
s->y,
s->rgba_color[0],
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++) {
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;
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)
603 .class_name =
"pad_cuda",
622 .p.name =
"pad_cuda",
const FFFilter ff_vf_pad_cuda
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#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)
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.
simple arithmetic expression evaluator
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ 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...
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
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.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
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_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#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.
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.
#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_)
Various defines for YUV<->RGB conversion.
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.
static const char *const var_names[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
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_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
AVCUDADeviceContextInternal * internal
Describe the class of an AVClass context structure.
int plane
Which of the 4 planes contains the component.
int step
Number of elements between 2 horizontally consecutive pixels.
int depth
Number of bits in the component.
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.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
int format
agreed upon media format
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...
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).
int h
output dimensions, a value of 0 will result in the input size
char * w_expr
width expression
char * x_expr
x offset expression
int y
offsets of the input area with respect to the padded area
char * h_expr
height expression
AVCUDADeviceContext * hwctx
char * y_expr
y offset expression
int in_h
width and height for the padded input video
int last_out_h
used to evaluate the prior output width and height with the incoming frame
CUfunction cu_func_uchar2
uint8_t rgba_color[4]
color for the padding area
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.
static enum AVPixelFormat supported_formats[]
static const AVClass cuda_pad_class
static const AVFilterPad cuda_pad_inputs[]
static int cuda_pad_filter_frame(AVFilterLink *inlink, AVFrame *in)
static int cuda_pad_config_props(AVFilterLink *outlink)
static av_cold int cuda_pad_init(AVFilterContext *ctx)
static int cuda_pad_pad(AVFilterContext *ctx, AVFrame *out, const AVFrame *in)
static av_cold int cuda_pad_load_functions(AVFilterContext *ctx)
static const AVFilterPad cuda_pad_outputs[]
static const AVOption cuda_pad_options[]
static int eval_expr(AVFilterContext *ctx)
static av_cold void cuda_pad_uninit(AVFilterContext *ctx)
static int cuda_pad_alloc_out_frames_ctx(AVFilterContext *ctx, AVBufferRef **out_frames_ctx, const int width, const int height)
#define RGB_TO_Y_BT709(r, g, b)
#define RGB_TO_U_BT709(r1, g1, b1, max)
#define RGB_TO_V_BT709(r1, g1, b1, max)