40#define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, ctx->hwctx->internal->cuda_dl, x)
41#define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
136 return (
int)d & ~((1 << chroma_sub) - 1);
151 s->y_position =
s->var_values[
VAR_Y];
165 "Error when evaluating the expression '%s' for %s\n",
179 switch(format_main) {
195 int x_position,
int y_position,
196 uint8_t* main_data,
int main_linesize,
197 int main_width,
int main_height,
198 uint8_t* overlay_data,
int overlay_linesize,
199 int overlay_width,
int overlay_height,
200 uint8_t* alpha_data,
int alpha_linesize,
201 int alpha_adj_x,
int alpha_adj_y) {
203 CudaFunctions *cu =
ctx->hwctx->internal->cuda_dl;
205 void* kernel_args[] = {
206 &x_position, &y_position,
207 &main_data, &main_linesize,
208 &overlay_data, &overlay_linesize,
209 &overlay_width, &overlay_height,
210 &alpha_data, &alpha_linesize,
211 &alpha_adj_x, &alpha_adj_y,
218 0,
ctx->cu_stream, kernel_args,
NULL));
234 CudaFunctions *cu =
ctx->hwctx->internal->cuda_dl;
235 CUcontext
dummy, cuda_ctx =
ctx->hwctx->cuda_ctx;
237 AVFrame *input_main, *input_overlay;
239 ctx->cu_ctx = cuda_ctx;
260 ret =
CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
287 ctx->x_position,
ctx->y_position,
292 input_overlay->
data[3], input_overlay->
linesize[3], 1, 1);
296 switch(
ctx->in_format_overlay) {
299 ctx->x_position,
ctx->y_position / 2,
309 ctx->x_position / 2 ,
ctx->y_position / 2,
313 input_overlay->
width / 2, input_overlay->
height / 2,
314 input_overlay->
data[3], input_overlay->
linesize[3], 2, 2);
317 ctx->x_position / 2 ,
ctx->y_position / 2,
321 input_overlay->
width / 2, input_overlay->
height / 2,
322 input_overlay->
data[3], input_overlay->
linesize[3], 2, 2);
354 if ((ret =
set_expr(&
s->x_pexpr,
s->x_expr,
"x",
ctx)) < 0 ||
361 s->var_values[
VAR_X],
s->x_position,
362 s->var_values[
VAR_Y],
s->y_position);
388 if (
ctx->hwctx &&
ctx->cu_module) {
390 CudaFunctions *cu =
ctx->hwctx->internal->cuda_dl;
417 extern const unsigned char ff_vf_overlay_cuda_ptx_data[];
418 extern const unsigned int ff_vf_overlay_cuda_ptx_len;
433 CUcontext
dummy, cuda_ctx;
452 if (!frames_ctx_overlay) {
475 if (!
ctx->hw_device_ctx)
479 cuda_ctx =
ctx->hwctx->cuda_ctx;
482 ctx->cu_stream =
ctx->hwctx->stream;
490 cu =
ctx->hwctx->internal->cuda_dl;
492 err =
CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
503 err =
CHECK_CU(cu->cuModuleGetFunction(&
ctx->cu_func,
ctx->cu_module,
"Overlay_Cuda"));
522#define OFFSET(x) offsetof(OverlayCUDAContext, x)
523#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
528 {
"eof_action",
"Action to take when encountering EOF from secondary input ",
537 {
"shortest",
"force termination when the shortest input terminates",
OFFSET(
fs.opt_shortest),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
FLAGS },
565 .p.name =
"overlay_cuda",
567 .p.priv_class = &overlay_cuda_class,
575 .preinit = overlay_cuda_framesync_preinit,
static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx)
const FFFilter ff_vf_overlay_cuda
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
int(* init)(AVBSFContext *ctx)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
simple arithmetic expression evaluator
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
#define FRAMESYNC_DEFINE_CLASS(name, context, field)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
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...
#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(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#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.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define AV_NOPTS_VALUE
Undefined timestamp value.
FFmpeg internal API for CUDA.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#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 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[]
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.
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.
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.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
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.
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
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.
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.
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.
enum AVPixelFormat in_format_main
enum AVPixelFormat in_format_overlay
AVBufferRef * hw_device_ctx
double var_values[VAR_VARS_NB]
AVCUDADeviceContext * hwctx
static int config_input_overlay(AVFilterLink *inlink)
static int overlay_cuda_config_output(AVFilterLink *outlink)
Configure output.
static enum AVPixelFormat supported_main_formats[]
static int config_input_overlay(AVFilterLink *inlink)
static int overlay_cuda_call_kernel(OverlayCUDAContext *ctx, int x_position, int y_position, uint8_t *main_data, int main_linesize, int main_width, int main_height, uint8_t *overlay_data, int overlay_linesize, int overlay_width, int overlay_height, uint8_t *alpha_data, int alpha_linesize, int alpha_adj_x, int alpha_adj_y)
Call overlay kernell for a plane.
static const AVOption overlay_cuda_options[]
static int format_is_supported(const enum AVPixelFormat formats[], enum AVPixelFormat fmt)
Helper to find out if provided format is supported by filter.
static const AVFilterPad overlay_cuda_inputs[]
static int overlay_cuda_blend(FFFrameSync *fs)
Perform blend overlay picture over main picture.
static enum AVPixelFormat supported_overlay_formats[]
static av_cold void overlay_cuda_uninit(AVFilterContext *avctx)
Uninitialize overlay_cuda.
static const AVFilterPad overlay_cuda_outputs[]
static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void *log_ctx)
static int overlay_cuda_activate(AVFilterContext *avctx)
Activate overlay_cuda.
static av_cold int overlay_cuda_init(AVFilterContext *avctx)
Initialize overlay_cuda.
static int formats_match(const enum AVPixelFormat format_main, const enum AVPixelFormat format_overlay)
Helper checks if we can process main and overlay pixel formats.
static void eval_expr(AVFilterContext *ctx)
static int normalize_xy(double d, int chroma_sub)