Go to the documentation of this file.
21 #include "config_components.h"
61 const char *kernel_name;
69 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
70 ctx->ocf.hwctx->device_id,
73 "command queue %d.\n", cle);
75 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
76 kernel_name =
"convolution_global";
77 }
else if (!strcmp(avctx->
filter->
name,
"sobel_opencl")) {
78 kernel_name =
"sobel_global";
79 }
else if (!strcmp(avctx->
filter->
name,
"prewitt_opencl")){
80 kernel_name =
"prewitt_global";
81 }
else if (!strcmp(avctx->
filter->
name,
"roberts_opencl")){
82 kernel_name =
"roberts_global";
84 ctx->kernel = clCreateKernel(
ctx->ocf.program, kernel_name, &cle);
92 if (
ctx->command_queue)
93 clReleaseCommandQueue(
ctx->command_queue);
95 clReleaseKernel(
ctx->kernel);
110 char *p, *
arg, *saveptr =
NULL;
111 float input_matrix[4][49];
113 for (
i = 0;
i < 4;
i++) {
114 ctx->biases[
i] =
ctx->biases[
i] / 255.0;
117 for (
i = 0;
i < 4;
i++) {
118 p =
ctx->matrix_str[
i];
119 while (
ctx->matrix_sizes[
i] < 49) {
125 sscanf_err = sscanf(
arg,
"%f", &input_matrix[
i][
ctx->matrix_sizes[
i]]);
126 if (sscanf_err != 1) {
130 ctx->matrix_sizes[
i]++;
132 if (
ctx->matrix_sizes[
i] == 9) {
134 }
else if (
ctx->matrix_sizes[
i] == 25) {
136 }
else if (
ctx->matrix_sizes[
i] == 49) {
145 for (j = 0; j < 4; j++) {
146 matrix_bytes =
sizeof(
float)*
ctx->matrix_sizes[j];
153 for (
i = 0;
i <
ctx->matrix_sizes[j];
i++)
156 buffer = clCreateBuffer(
ctx->ocf.hwctx->context,
158 CL_MEM_COPY_HOST_PTR |
159 CL_MEM_HOST_NO_ACCESS,
160 matrix_bytes,
matrix, &cle);
181 size_t global_work[2];
184 size_t origin[3] = {0, 0, 0};
185 size_t region[3] = {0, 0, 1};
191 if (!
input->hw_frames_ctx)
194 if (!
ctx->initialised) {
199 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
217 dst = (cl_mem)
output->data[p];
222 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
236 p, global_work[0], global_work[1]);
238 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
242 "kernel: %d.\n", cle);
244 if (!(
ctx->planes & (1 << p))) {
249 cle = clEnqueueCopyImage(
ctx->command_queue,
src, dst,
250 origin, origin, region, 0,
NULL,
NULL);
265 p, global_work[0], global_work[1]);
267 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
271 "kernel: %d.\n", cle);
276 cle = clFinish(
ctx->command_queue);
292 clFinish(
ctx->command_queue);
304 for (
i = 0;
i < 4;
i++) {
305 clReleaseMemObject(
ctx->matrix[
i]);
309 cle = clReleaseKernel(
ctx->kernel);
310 if (cle != CL_SUCCESS)
312 "kernel: %d.\n", cle);
315 if (
ctx->command_queue) {
316 cle = clReleaseCommandQueue(
ctx->command_queue);
317 if (cle != CL_SUCCESS)
319 "command queue: %d.\n", cle);
342 #define OFFSET(x) offsetof(ConvolutionOpenCLContext, x)
343 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
345 #if CONFIG_CONVOLUTION_OPENCL_FILTER
347 static const AVOption convolution_opencl_options[] = {
366 .
name =
"convolution_opencl",
369 .priv_class = &convolution_opencl_class,
381 #if CONFIG_SOBEL_OPENCL_FILTER
383 static const AVOption sobel_opencl_options[] = {
393 .
name =
"sobel_opencl",
396 .priv_class = &sobel_opencl_class,
408 #if CONFIG_PREWITT_OPENCL_FILTER
410 static const AVOption prewitt_opencl_options[] = {
420 .
name =
"prewitt_opencl",
423 .priv_class = &prewitt_opencl_class,
435 #if CONFIG_ROBERTS_OPENCL_FILTER
437 static const AVOption roberts_opencl_options[] = {
447 .
name =
"roberts_opencl",
450 .priv_class = &roberts_opencl_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
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.
static int convolution_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
#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.
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
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.
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
static av_always_inline float scale(float x, float s)
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
static const AVFilterPad convolution_opencl_inputs[]
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static const AVFilterPad convolution_opencl_outputs[]
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
int(* init)(AVBSFContext *ctx)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FILTER_INPUTS(array)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
cl_command_queue command_queue
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const char * ff_source_convolution_cl
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
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.
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static const struct @363 planes[]
const char * name
Pad name.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
const AVFilter ff_vf_roberts_opencl
const AVFilter ff_vf_convolution_opencl
int h
agreed upon image height
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
const AVFilter ff_vf_sobel_opencl
static int convolution_opencl_init(AVFilterContext *avctx)
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
static int convolution_opencl_make_filter_params(AVFilterContext *avctx)
#define FILTER_OUTPUTS(array)
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
static av_cold void convolution_opencl_uninit(AVFilterContext *avctx)
static av_cold int uninit(AVCodecContext *avctx)
const AVFilter * filter
the AVFilter of which this is an instance
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 AVFilter ff_vf_prewitt_opencl
AVFilterLink ** outputs
array of pointers to output links