59 const char *kernel_name;
71 "command queue %d.\n", cle);
73 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
74 kernel_name =
"convolution_global";
75 }
else if (!strcmp(avctx->
filter->
name,
"sobel_opencl")) {
76 kernel_name =
"sobel_global";
77 }
else if (!strcmp(avctx->
filter->
name,
"prewitt_opencl")){
78 kernel_name =
"prewitt_global";
79 }
else if (!strcmp(avctx->
filter->
name,
"roberts_opencl")){
80 kernel_name =
"roberts_global";
93 clReleaseKernel(ctx->
kernel);
108 char *p, *
arg, *saveptr =
NULL;
109 float input_matrix[4][49];
111 for (i = 0; i < 4; i++) {
115 for (i = 0; i < 4; i++) {
123 sscanf_err = sscanf(arg,
"%f", &input_matrix[i][ctx->
matrix_sizes[i]]);
124 if (sscanf_err != 1) {
143 for (j = 0; j < 4; j++) {
152 matrix[i] = input_matrix[j][i];
156 CL_MEM_COPY_HOST_PTR |
157 CL_MEM_HOST_NO_ACCESS,
158 matrix_bytes, matrix, &cle);
179 size_t global_work[2];
182 size_t origin[3] = {0, 0, 0};
183 size_t region[3] = {0, 0, 1};
197 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
214 src = (cl_mem) input->
data[p];
215 dst = (cl_mem)output->
data[p];
220 if (!strcmp(avctx->
filter->
name,
"convolution_opencl")) {
234 p, global_work[0], global_work[1]);
240 "kernel: %d.\n", cle);
242 if (!(ctx->
planes & (1 << p))) {
248 origin, origin, region, 0,
NULL,
NULL);
263 p, global_work[0], global_work[1]);
269 "kernel: %d.\n", cle);
302 for (i = 0; i < 4; i++) {
303 clReleaseMemObject(ctx->
matrix[i]);
307 cle = clReleaseKernel(ctx->
kernel);
308 if (cle != CL_SUCCESS)
310 "kernel: %d.\n", cle);
315 if (cle != CL_SUCCESS)
317 "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,
373 .
inputs = convolution_opencl_inputs,
374 .
outputs = convolution_opencl_outputs,
380 #if CONFIG_SOBEL_OPENCL_FILTER 382 static const AVOption sobel_opencl_options[] = {
392 .
name =
"sobel_opencl",
395 .priv_class = &sobel_opencl_class,
399 .
inputs = convolution_opencl_inputs,
400 .
outputs = convolution_opencl_outputs,
406 #if CONFIG_PREWITT_OPENCL_FILTER 408 static const AVOption prewitt_opencl_options[] = {
418 .
name =
"prewitt_opencl",
421 .priv_class = &prewitt_opencl_class,
425 .
inputs = convolution_opencl_inputs,
426 .
outputs = convolution_opencl_outputs,
432 #if CONFIG_ROBERTS_OPENCL_FILTER 434 static const AVOption roberts_opencl_options[] = {
444 .
name =
"roberts_opencl",
447 .priv_class = &roberts_opencl_class,
451 .
inputs = convolution_opencl_inputs,
452 .
outputs = convolution_opencl_outputs,
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
This structure describes decoded (raw) audio or video data.
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.
AVFilter ff_vf_roberts_opencl
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_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
Main libavfilter public API header.
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
int h
agreed upon image height
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
static int convolution_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
AVOpenCLDeviceContext * hwctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
AVFilter ff_vf_prewitt_opencl
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static av_cold int uninit(AVCodecContext *avctx)
cl_device_id device_id
The primary device ID of the device.
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
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
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.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int w
agreed upon image width
static int convolution_opencl_make_filter_params(AVFilterContext *avctx)
static av_cold void convolution_opencl_uninit(AVFilterContext *avctx)
static const AVFilterPad convolution_opencl_outputs[]
static const AVFilterPad outputs[]
#define FF_ARRAY_ELEMS(a)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
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
AVFilter ff_vf_sobel_opencl
const char * name
Filter name.
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
AVFilterLink ** outputs
array of pointers to output links
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
AVFilter ff_vf_convolution_opencl
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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
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 int query_formats(AVFilterContext *ctx)
common internal and external API header
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
static int convolution_opencl_init(AVFilterContext *avctx)
static const AVFilterPad convolution_opencl_inputs[]
AVFilterContext * dst
dest filter
#define AVFILTER_DEFINE_CLASS(fname)
cl_context context
The OpenCL context which will contain all operations and frames on this device.
cl_command_queue command_queue
const char * ff_opencl_source_convolution
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 * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
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
const AVFilter * filter
the AVFilter of which this is an instance
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.