Go to the documentation of this file.
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) {
146 overlay_fc->sw_format);
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 .
name =
"overlay_opencl",
317 .priv_class = &overlay_opencl_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
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
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
AVFILTER_DEFINE_CLASS(overlay_opencl)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
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.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
static int overlay_opencl_load(AVFilterContext *avctx, enum AVPixelFormat main_format, enum AVPixelFormat overlay_format)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
cl_command_queue command_queue
This structure describes decoded (raw) audio or video data.
static int overlay_opencl_activate(AVFilterContext *avctx)
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.
const char * name
Filter name.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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.
void * priv
private data for use by the filter
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int overlay_opencl_blend(FFFrameSync *fs)
static const AVFilterPad overlay_opencl_inputs[]
int(* init)(AVBSFContext *ctx)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_cold int overlay_opencl_init(AVFilterContext *avctx)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define FILTER_INPUTS(array)
const AVFilter ff_vf_overlay_opencl
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.
#define fs(width, name, subs,...)
uint8_t nb_components
The number of components each pixel has, (1-4)
filter_frame For filters that do not use the activate() callback
int plane
Which of the 4 planes contains the component.
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a source
static int overlay_opencl_config_output(AVFilterLink *outlink)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
AVFilterContext * src
source filter
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.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
const char * ff_source_overlay_cl
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static const AVOption overlay_opencl_options[]
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
static av_cold void overlay_opencl_uninit(AVFilterContext *avctx)
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
int h
agreed upon image height
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
static av_cold int uninit(AVCodecContext *avctx)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
static const AVFilterPad overlay_opencl_outputs[]
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
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.
AVFilterLink ** outputs
array of pointers to output links