21#include "config_components.h"
62 const char *kernel_name;
70 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
71 ctx->ocf.hwctx->device_id,
74 "command queue %d.\n", cle);
76 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
77 kernel_name =
"convolution_global";
78 }
else if (!strcmp(avctx->
filter->
name,
"sobel_opencl")) {
79 kernel_name =
"sobel_global";
80 }
else if (!strcmp(avctx->
filter->
name,
"prewitt_opencl")){
81 kernel_name =
"prewitt_global";
82 }
else if (!strcmp(avctx->
filter->
name,
"roberts_opencl")){
83 kernel_name =
"roberts_global";
87 ctx->kernel = clCreateKernel(
ctx->ocf.program, kernel_name, &cle);
95 if (
ctx->command_queue)
96 clReleaseCommandQueue(
ctx->command_queue);
98 clReleaseKernel(
ctx->kernel);
113 char *p, *
arg, *saveptr =
NULL;
114 float input_matrix[4][49];
116 for (
i = 0;
i < 4;
i++) {
117 ctx->biases[
i] =
ctx->biases[
i] / 255.0;
120 for (
i = 0;
i < 4;
i++) {
121 p =
ctx->matrix_str[
i];
122 while (
ctx->matrix_sizes[
i] < 49) {
128 sscanf_err = sscanf(
arg,
"%f", &input_matrix[
i][
ctx->matrix_sizes[
i]]);
129 if (sscanf_err != 1) {
133 ctx->matrix_sizes[
i]++;
135 if (
ctx->matrix_sizes[
i] == 9) {
137 }
else if (
ctx->matrix_sizes[
i] == 25) {
139 }
else if (
ctx->matrix_sizes[
i] == 49) {
148 for (j = 0; j < 4; j++) {
149 matrix_bytes =
sizeof(
float)*
ctx->matrix_sizes[j];
156 for (
i = 0;
i <
ctx->matrix_sizes[j];
i++)
159 buffer = clCreateBuffer(
ctx->ocf.hwctx->context,
161 CL_MEM_COPY_HOST_PTR |
162 CL_MEM_HOST_NO_ACCESS,
163 matrix_bytes,
matrix, &cle);
184 size_t global_work[2];
187 size_t origin[3] = {0, 0, 0};
188 size_t region[3] = {0, 0, 1};
197 if (!
ctx->initialised) {
202 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
225 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
239 p, global_work[0], global_work[1]);
241 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
245 "kernel: %d.\n", cle);
247 if (!(
ctx->planes & (1 << p))) {
252 cle = clEnqueueCopyImage(
ctx->command_queue,
src,
dst,
253 origin, origin, region, 0,
NULL,
NULL);
268 p, global_work[0], global_work[1]);
270 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
274 "kernel: %d.\n", cle);
279 cle = clFinish(
ctx->command_queue);
295 clFinish(
ctx->command_queue);
307 for (
i = 0;
i < 4;
i++) {
308 clReleaseMemObject(
ctx->matrix[
i]);
312 cle = clReleaseKernel(
ctx->kernel);
313 if (cle != CL_SUCCESS)
315 "kernel: %d.\n", cle);
318 if (
ctx->command_queue) {
319 cle = clReleaseCommandQueue(
ctx->command_queue);
320 if (cle != CL_SUCCESS)
322 "command queue: %d.\n", cle);
345#define OFFSET(x) offsetof(ConvolutionOpenCLContext, x)
346#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
348#if CONFIG_CONVOLUTION_OPENCL_FILTER
350static const AVOption convolution_opencl_options[] = {
369 .p.name =
"convolution_opencl",
371 .p.priv_class = &convolution_opencl_class,
384#if CONFIG_SOBEL_OPENCL_FILTER
386static const AVOption sobel_opencl_options[] = {
396 .p.name =
"sobel_opencl",
398 .p.priv_class = &sobel_opencl_class,
411#if CONFIG_PREWITT_OPENCL_FILTER
413static const AVOption prewitt_opencl_options[] = {
423 .p.name =
"prewitt_opencl",
425 .p.priv_class = &prewitt_opencl_class,
438#if CONFIG_ROBERTS_OPENCL_FILTER
440static const AVOption roberts_opencl_options[] = {
450 .p.name =
"roberts_opencl",
452 .p.priv_class = &roberts_opencl_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFFilter ff_vf_roberts_opencl
const FFFilter ff_vf_prewitt_opencl
const FFFilter ff_vf_convolution_opencl
const FFFilter ff_vf_sobel_opencl
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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)
common internal and external API header
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ 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 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_ERROR
Something went wrong and cannot losslessly be recovered.
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().
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(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.
static const struct @257111027162314367033347246032313251342043035002 planes[]
Memory handling functions.
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_convolution_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.
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
#define FF_ARRAY_ELEMS(a)
const AVFilter * filter
the AVFilter of which this is an instance
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 * dst
dest filter
A filter pad used for either input or output.
const char * name
Filter name.
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,...
cl_command_queue command_queue
static int convolution_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
static int convolution_opencl_make_filter_params(AVFilterContext *avctx)
static av_cold void convolution_opencl_uninit(AVFilterContext *avctx)
static int convolution_opencl_init(AVFilterContext *avctx)
static const AVFilterPad convolution_opencl_inputs[]
static const AVFilterPad convolution_opencl_outputs[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.