21#include "config_components.h"
54 const char *kernel_name;
62 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
63 ctx->ocf.hwctx->device_id,
66 "command queue %d.\n", cle);
68 if (!strcmp(avctx->
filter->
name,
"erosion_opencl")){
69 kernel_name =
"erosion_global";
70 }
else if (!strcmp(avctx->
filter->
name,
"dilation_opencl")){
71 kernel_name =
"dilation_global";
76 ctx->kernel = clCreateKernel(
ctx->ocf.program, kernel_name, &cle);
84 if (
ctx->command_queue)
85 clReleaseCommandQueue(
ctx->command_queue);
87 clReleaseKernel(
ctx->kernel);
100 ctx->threshold[
i] /= 255.0;
104 for (
i = 0;
i < 8;
i++) {
105 if (
ctx->coordinates & (1 <<
i)) {
109 buffer = clCreateBuffer(
ctx->ocf.hwctx->context,
111 CL_MEM_COPY_HOST_PTR |
112 CL_MEM_HOST_NO_ACCESS,
113 9 *
sizeof(cl_int),
matrix, &cle);
132 size_t global_work[2];
135 size_t origin[3] = {0, 0, 0};
136 size_t region[3] = {0, 0, 1};
145 if (!
ctx->initialised) {
169 if (
ctx->threshold[p] == 0) {
174 cle = clEnqueueCopyImage(
ctx->command_queue,
src,
dst,
175 origin, origin, region, 0,
NULL,
NULL);
189 p, global_work[0], global_work[1]);
191 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
195 "kernel: %d.\n", cle);
199 cle = clFinish(
ctx->command_queue);
215 clFinish(
ctx->command_queue);
226 clReleaseMemObject(
ctx->coord);
229 cle = clReleaseKernel(
ctx->kernel);
230 if (cle != CL_SUCCESS)
232 "kernel: %d.\n", cle);
235 if (
ctx->command_queue) {
236 cle = clReleaseCommandQueue(
ctx->command_queue);
237 if (cle != CL_SUCCESS)
239 "command queue: %d.\n", cle);
262#define OFFSET(x) offsetof(NeighborOpenCLContext, x)
263#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
265#if CONFIG_EROSION_OPENCL_FILTER
267static const AVOption erosion_opencl_options[] = {
279 .p.name =
"erosion_opencl",
281 .p.priv_class = &erosion_opencl_class,
293#if CONFIG_DILATION_OPENCL_FILTER
295static const AVOption dilation_opencl_options[] = {
307 .p.name =
"dilation_opencl",
309 .p.priv_class = &dilation_opencl_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFFilter ff_vf_erosion_opencl
const FFFilter ff_vf_dilation_opencl
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.
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
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.
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.
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_neighbor_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.
#define AV_VIDEO_MAX_PLANES
Maximum number of planes in any pixel format.
@ 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
cl_float threshold[AV_VIDEO_MAX_PLANES]
static AVFormatContext * ctx
static const AVFilterPad neighbor_opencl_outputs[]
static int neighbor_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
static int neighbor_opencl_make_filter_params(AVFilterContext *avctx)
static const AVFilterPad neighbor_opencl_inputs[]
static av_cold void neighbor_opencl_uninit(AVFilterContext *avctx)
static int neighbor_opencl_init(AVFilterContext *avctx)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.