Go to the documentation of this file.
22 #include "config_components.h"
66 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
67 ctx->ocf.hwctx->device_id,
70 "command queue %d.\n", cle);
72 ctx->kernel_horiz = clCreateKernel(
ctx->ocf.program,
"avgblur_horiz", &cle);
76 ctx->kernel_vert = clCreateKernel(
ctx->ocf.program,
"avgblur_vert", &cle);
84 if (
ctx->command_queue)
85 clReleaseCommandQueue(
ctx->command_queue);
86 if (
ctx->kernel_horiz)
87 clReleaseKernel(
ctx->kernel_horiz);
89 clReleaseKernel(
ctx->kernel_vert);
100 if (
s->radiusV <= 0) {
101 s->radiusV =
s->radiusH;
124 "filter params: %d.\n", err);
128 s->radius[
Y] =
s->luma_param.radius;
129 s->radius[
U] =
s->radius[
V] =
s->chroma_param.radius;
130 s->radius[
A] =
s->alpha_param.radius;
132 s->power[
Y] =
s->luma_param.power;
133 s->power[
U] =
s->power[
V] =
s->chroma_param.power;
134 s->power[
A] =
s->alpha_param.power;
137 if (
s->power[
i] == 0) {
155 size_t global_work[2];
157 int err, p, radius_x, radius_y,
i;
163 if (!
input->hw_frames_ctx)
166 if (!
ctx->initialised) {
171 if (!strcmp(avctx->
filter->
name,
"avgblur_opencl")) {
175 }
else if (!strcmp(avctx->
filter->
name,
"boxblur_opencl")) {
197 inter = (cl_mem)intermediate->
data[p];
202 radius_x =
ctx->radiusH;
203 radius_y =
ctx->radiusV;
205 if (!(
ctx->planes & (1 << p))) {
210 for (
i = 0;
i <
ctx->power[p];
i++) {
213 if (!strcmp(avctx->
filter->
name,
"avgblur_opencl")) {
215 }
else if (!strcmp(avctx->
filter->
name,
"boxblur_opencl")) {
220 i == 0 ? intermediate :
output, p, 0);
226 p, global_work[0], global_work[1]);
228 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel_horiz, 2,
NULL,
232 "kernel: %d.\n", cle);
235 i == 0 ?
output : intermediate, p, 0);
240 if (!strcmp(avctx->
filter->
name,
"avgblur_opencl")) {
242 }
else if (!strcmp(avctx->
filter->
name,
"boxblur_opencl")) {
246 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel_vert, 2,
NULL,
250 "kernel: %d.\n", cle);
254 cle = clFinish(
ctx->command_queue);
271 clFinish(
ctx->command_queue);
284 if (
ctx->kernel_horiz) {
285 cle = clReleaseKernel(
ctx->kernel_horiz);
286 if (cle != CL_SUCCESS)
288 "kernel: %d.\n", cle);
291 if (
ctx->kernel_vert) {
292 cle = clReleaseKernel(
ctx->kernel_vert);
293 if (cle != CL_SUCCESS)
295 "kernel: %d.\n", cle);
298 if (
ctx->command_queue) {
299 cle = clReleaseCommandQueue(
ctx->command_queue);
300 if (cle != CL_SUCCESS)
302 "command queue: %d.\n", cle);
328 #define OFFSET(x) offsetof(AverageBlurOpenCLContext, x)
329 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
331 #if CONFIG_AVGBLUR_OPENCL_FILTER
333 static const AVOption avgblur_opencl_options[] = {
344 .
name =
"avgblur_opencl",
347 .priv_class = &avgblur_opencl_class,
359 #if CONFIG_BOXBLUR_OPENCL_FILTER
361 static const AVOption boxblur_opencl_options[] = {
364 {
"luma_power",
"How many times should the boxblur be applied to luma",
OFFSET(luma_param.power),
AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags =
FLAGS },
365 {
"lp",
"How many times should the boxblur be applied to luma",
OFFSET(luma_param.power),
AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags =
FLAGS },
369 {
"chroma_power",
"How many times should the boxblur be applied to chroma",
OFFSET(chroma_param.power),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags =
FLAGS },
370 {
"cp",
"How many times should the boxblur be applied to chroma",
OFFSET(chroma_param.power),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags =
FLAGS },
374 {
"alpha_power",
"How many times should the boxblur be applied to alpha",
OFFSET(alpha_param.power),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags =
FLAGS },
375 {
"ap",
"How many times should the boxblur be applied to alpha",
OFFSET(alpha_param.power),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags =
FLAGS },
383 .
name =
"boxblur_opencl",
386 .priv_class = &boxblur_opencl_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int radius[AV_VIDEO_MAX_PLANES]
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.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
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
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
#define AV_VIDEO_MAX_PLANES
Maximum number of planes in any pixel format.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int boxblur_opencl_make_filter_params(AVFilterLink *inlink)
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
static int avgblur_opencl_init(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.
static const struct @466 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.
int ff_boxblur_eval_filter_params(AVFilterLink *inlink, FilterParam *luma_param, FilterParam *chroma_param, FilterParam *alpha_param)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int power[AV_VIDEO_MAX_PLANES]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FILTER_OUTPUTS(array)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
#define AVFILTER_DEFINE_CLASS(fname)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static const AVFilterPad avgblur_opencl_outputs[]
int(* init)(AVBSFContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
const AVFilter ff_vf_boxblur_opencl
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
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.
static void uninit(AVBSFContext *ctx)
const AVFilter ff_vf_avgblur_opencl
#define i(width, name, range_min, range_max)
int w
agreed upon image width
const char * name
Pad name.
static const AVFilterPad avgblur_opencl_inputs[]
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
static av_cold void avgblur_opencl_uninit(AVFilterContext *avctx)
static int avgblur_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
static int avgblur_opencl_make_filter_params(AVFilterLink *inlink)
int h
agreed upon image height
@ AV_OPT_TYPE_INT
Underlying C type is int.
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
const char * ff_source_avgblur_cl
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
cl_command_queue command_queue
const AVFilter * filter
the AVFilter of which this is an instance
@ 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 FILTER_SINGLE_PIXFMT(pix_fmt_)
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