57 int err,
i, main_planes, overlay_planes;
62 main_planes = overlay_planes = 0;
64 main_planes =
FFMAX(main_planes,
67 overlay_planes =
FFMAX(overlay_planes,
70 ctx->nb_planes = main_planes;
74 if (
ctx->x_position %
ctx->x_subsample ||
75 ctx->y_position %
ctx->y_subsample) {
77 "does not match subsampling (%d, %d).\n",
78 ctx->x_position,
ctx->y_position,
79 ctx->x_subsample,
ctx->y_subsample);
82 if (main_planes == overlay_planes) {
84 kernel =
"overlay_no_alpha";
86 kernel =
"overlay_internal_alpha";
87 ctx->alpha_separate = 0;
89 kernel =
"overlay_external_alpha";
90 ctx->alpha_separate = 1;
99 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
100 ctx->ocf.hwctx->device_id,
103 "command queue %d.\n", cle);
105 ctx->kernel = clCreateKernel(
ctx->ocf.program, kernel, &cle);
108 ctx->initialised = 1;
112 if (
ctx->command_queue)
113 clReleaseCommandQueue(
ctx->command_queue);
115 clReleaseKernel(
ctx->kernel);
124 AVFrame *input_main, *input_overlay;
128 size_t global_work[2];
139 if (!
ctx->initialised) {
157 for (plane = 0; plane <
ctx->nb_planes; plane++) {
160 mem = (cl_mem)output->
data[plane];
164 mem = (cl_mem)input_main->
data[plane];
168 mem = (cl_mem)input_overlay->
data[plane];
172 if (
ctx->alpha_separate) {
173 mem = (cl_mem)input_overlay->
data[
ctx->nb_planes];
178 x =
ctx->x_position / (plane == 0 ? 1 :
ctx->x_subsample);
179 y =
ctx->y_position / (plane == 0 ? 1 :
ctx->y_subsample);
186 if (
ctx->alpha_separate) {
187 cl_int alpha_adj_x = plane == 0 ? 1 :
ctx->x_subsample;
188 cl_int alpha_adj_y = plane == 0 ? 1 :
ctx->y_subsample;
201 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
204 "for plane %d: %d.\n", plane, cle);
207 cle = clFinish(
ctx->command_queue);
262 cle = clReleaseKernel(
ctx->kernel);
263 if (cle != CL_SUCCESS)
265 "kernel: %d.\n", cle);
268 if (
ctx->command_queue) {
269 cle = clReleaseCommandQueue(
ctx->command_queue);
270 if (cle != CL_SUCCESS)
272 "command queue: %d.\n", cle);
280#define OFFSET(x) offsetof(OverlayOpenCLContext, x)
281#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
283 {
"x",
"Overlay x position",
285 {
"y",
"Overlay y position",
314 .p.name =
"overlay_opencl",
316 .p.priv_class = &overlay_opencl_class,
const FFFilter ff_vf_overlay_opencl
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
int(* init)(AVBSFContext *ctx)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
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.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
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.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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...
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
int ff_opencl_filter_load_program(AVFilterContext *avctx, const char **program_source_array, int nb_strings)
Load a new OpenCL program from strings in memory.
int ff_opencl_filter_config_input(AVFilterLink *inlink)
Check that the input link contains a suitable hardware frames context and extract the device from it.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx, size_t *work_size, AVFrame *frame, int plane, int block_alignment)
Find the work size needed needed for a given plane of an image.
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
const char * ff_source_overlay_cl
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
uint8_t * data
The data buffer.
int plane
Which of the 4 planes contains the component.
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source 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.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
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)
cl_command_queue command_queue
static AVFormatContext * ctx
static int overlay_opencl_load(AVFilterContext *avctx, enum AVPixelFormat main_format, enum AVPixelFormat overlay_format)
static av_cold int overlay_opencl_init(AVFilterContext *avctx)
static int overlay_opencl_config_output(AVFilterLink *outlink)
static int overlay_opencl_activate(AVFilterContext *avctx)
static const AVFilterPad overlay_opencl_outputs[]
static int overlay_opencl_blend(FFFrameSync *fs)
static av_cold void overlay_opencl_uninit(AVFilterContext *avctx)
static const AVOption overlay_opencl_options[]
static const AVFilterPad overlay_opencl_inputs[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.