Go to the documentation of this file.
58 int err,
i, main_planes, overlay_planes;
63 main_planes = overlay_planes = 0;
65 main_planes =
FFMAX(main_planes,
68 overlay_planes =
FFMAX(overlay_planes,
71 ctx->nb_planes = main_planes;
75 if (
ctx->x_position %
ctx->x_subsample ||
76 ctx->y_position %
ctx->y_subsample) {
78 "does not match subsampling (%d, %d).\n",
79 ctx->x_position,
ctx->y_position,
80 ctx->x_subsample,
ctx->y_subsample);
83 if (main_planes == overlay_planes) {
85 kernel =
"overlay_no_alpha";
87 kernel =
"overlay_internal_alpha";
88 ctx->alpha_separate = 0;
90 kernel =
"overlay_external_alpha";
91 ctx->alpha_separate = 1;
100 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
101 ctx->ocf.hwctx->device_id,
104 "command queue %d.\n", cle);
106 ctx->kernel = clCreateKernel(
ctx->ocf.program, kernel, &cle);
109 ctx->initialised = 1;
113 if (
ctx->command_queue)
114 clReleaseCommandQueue(
ctx->command_queue);
116 clReleaseKernel(
ctx->kernel);
125 AVFrame *input_main, *input_overlay;
129 size_t global_work[2];
140 if (!
ctx->initialised) {
147 overlay_fc->sw_format);
173 if (
ctx->alpha_separate) {
174 mem = (cl_mem)input_overlay->
data[
ctx->nb_planes];
179 x =
ctx->x_position / (
plane == 0 ? 1 :
ctx->x_subsample);
180 y =
ctx->y_position / (
plane == 0 ? 1 :
ctx->y_subsample);
187 if (
ctx->alpha_separate) {
188 cl_int alpha_adj_x =
plane == 0 ? 1 :
ctx->x_subsample;
189 cl_int alpha_adj_y =
plane == 0 ? 1 :
ctx->y_subsample;
202 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
205 "for plane %d: %d.\n",
plane, cle);
208 cle = clFinish(
ctx->command_queue);
263 cle = clReleaseKernel(
ctx->kernel);
264 if (cle != CL_SUCCESS)
266 "kernel: %d.\n", cle);
269 if (
ctx->command_queue) {
270 cle = clReleaseCommandQueue(
ctx->command_queue);
271 if (cle != CL_SUCCESS)
273 "command queue: %d.\n", cle);
281 #define OFFSET(x) offsetof(OverlayOpenCLContext, x)
282 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
284 {
"x",
"Overlay x position",
286 {
"y",
"Overlay y position",
317 .
name =
"overlay_opencl",
320 .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.
static av_cold int init(AVCodecContext *avctx)
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 * ff_opencl_source_overlay
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[]
AVFilter ff_vf_overlay_opencl
static const AVFilterPad outputs[]
#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.
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.
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 inputs
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.
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 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...
static int query_formats(AVFilterContext *ctx)
#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.
int ff_opencl_filter_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
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