FFmpeg  4.2.2
Data Structures | Macros | Functions
opencl.h File Reference
#include "libavutil/bprint.h"
#include "libavutil/buffer.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_opencl.h"
#include "libavutil/pixfmt.h"
#include "avfilter.h"

Go to the source code of this file.

Data Structures

struct  OpenCLFilterContext
 

Macros

#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
 
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
 set argument to specific Kernel. More...
 
#define CL_FAIL_ON_ERROR(errcode, ...)
 A helper macro to handle OpenCL errors. More...
 
#define CL_RELEASE_KERNEL(k)
 release an OpenCL Kernel More...
 
#define CL_RELEASE_MEMORY(m)
 release an OpenCL Memory Object More...
 
#define CL_RELEASE_QUEUE(q)
 release an OpenCL Command Queue More...
 

Functions

int ff_opencl_filter_query_formats (AVFilterContext *avctx)
 Return that all inputs and outputs support only AV_PIX_FMT_OPENCL. More...
 
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. More...
 
int ff_opencl_filter_config_output (AVFilterLink *outlink)
 Create a suitable hardware frames context for the output. More...
 
int ff_opencl_filter_init (AVFilterContext *avctx)
 Initialise an OpenCL filter context. More...
 
void ff_opencl_filter_uninit (AVFilterContext *avctx)
 Uninitialise an OpenCL filter context. More...
 
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. More...
 
int ff_opencl_filter_load_program_from_file (AVFilterContext *avctx, const char *filename)
 Load a new OpenCL program from a file. More...
 
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. More...
 
void ff_opencl_print_const_matrix_3x3 (AVBPrint *buf, const char *name_str, double mat[3][3])
 Print a 3x3 matrix into a buffer as __constant array, which could be included in an OpenCL program. More...
 

Macro Definition Documentation

◆ CL_USE_DEPRECATED_OPENCL_1_2_APIS

#define CL_USE_DEPRECATED_OPENCL_1_2_APIS

Definition at line 26 of file opencl.h.

◆ CL_SET_KERNEL_ARG

#define CL_SET_KERNEL_ARG (   kernel,
  arg_num,
  type,
  arg 
)
Value:
cle = clSetKernelArg(kernel, arg_num, sizeof(type), arg); \
if (cle != CL_SUCCESS) { \
av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " \
"argument %d: error %d.\n", arg_num, cle); \
err = AVERROR(EIO); \
goto fail; \
}
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
const char * arg
Definition: jacosubdec.c:66
#define fail()
Definition: checkasm.h:120
cl_device_type type

set argument to specific Kernel.

This macro relies on usage of local label "fail" and variables: avctx, cle and err.

Definition at line 56 of file opencl.h.

Referenced by avgblur_opencl_filter_frame(), convolution_opencl_filter_frame(), filter_frame(), launch_kernel(), neighbor_opencl_filter_frame(), nlmeans_plane(), overlay_opencl_blend(), transpose_opencl_filter_frame(), and unsharp_opencl_filter_frame().

◆ CL_FAIL_ON_ERROR

#define CL_FAIL_ON_ERROR (   errcode,
  ... 
)
Value:
do { \
if (cle != CL_SUCCESS) { \
av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
err = errcode; \
goto fail; \
} \
} while(0)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define fail()
Definition: checkasm.h:120

A helper macro to handle OpenCL errors.

It will assign errcode to variable err, log error msg, and jump to fail label on error.

Definition at line 69 of file opencl.h.

Referenced by avgblur_opencl_filter_frame(), avgblur_opencl_init(), colorkey_opencl_init(), convolution_opencl_filter_frame(), convolution_opencl_init(), filter_frame(), launch_kernel(), neighbor_opencl_filter_frame(), neighbor_opencl_init(), nlmeans_opencl_filter_frame(), nlmeans_opencl_init(), nlmeans_plane(), overlay_opencl_blend(), overlay_opencl_load(), program_opencl_run(), tonemap_opencl_filter_frame(), tonemap_opencl_init(), transpose_opencl_filter_frame(), transpose_opencl_init(), unsharp_opencl_filter_frame(), unsharp_opencl_init(), and unsharp_opencl_make_filter_params().

◆ CL_RELEASE_KERNEL

#define CL_RELEASE_KERNEL (   k)
Value:
do { \
if (k) { \
cle = clReleaseKernel(k); \
if (cle != CL_SUCCESS) \
av_log(avctx, AV_LOG_ERROR, "Failed to release " \
"OpenCL kernel: %d.\n", cle); \
} \
} while(0)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176

release an OpenCL Kernel

Definition at line 79 of file opencl.h.

Referenced by nlmeans_opencl_init(), and nlmeans_opencl_uninit().

◆ CL_RELEASE_MEMORY

#define CL_RELEASE_MEMORY (   m)
Value:
do { \
if (m) { \
cle = clReleaseMemObject(m); \
if (cle != CL_SUCCESS) \
av_log(avctx, AV_LOG_ERROR, "Failed to release " \
"OpenCL memory: %d.\n", cle); \
} \
} while(0)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176

release an OpenCL Memory Object

Definition at line 92 of file opencl.h.

Referenced by nlmeans_opencl_init(), and nlmeans_opencl_uninit().

◆ CL_RELEASE_QUEUE

#define CL_RELEASE_QUEUE (   q)
Value:
do { \
if (q) { \
cle = clReleaseCommandQueue(q); \
if (cle != CL_SUCCESS) \
av_log(avctx, AV_LOG_ERROR, "Failed to release " \
"OpenCL command queue: %d.\n", cle); \
} \
} while(0)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176

release an OpenCL Command Queue

Definition at line 105 of file opencl.h.

Referenced by nlmeans_opencl_init(), and nlmeans_opencl_uninit().

Function Documentation

◆ ff_opencl_filter_query_formats()

int ff_opencl_filter_query_formats ( AVFilterContext avctx)

Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.

Definition at line 28 of file opencl.c.

◆ ff_opencl_filter_config_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.

Definition at line 60 of file opencl.c.

Referenced by program_opencl_init().

◆ ff_opencl_filter_config_output()

int ff_opencl_filter_config_output ( AVFilterLink outlink)

Create a suitable hardware frames context for the output.

Definition at line 96 of file opencl.c.

Referenced by overlay_opencl_config_output(), program_opencl_config_output(), tonemap_opencl_config_output(), and transpose_opencl_config_output().

◆ ff_opencl_filter_init()

int ff_opencl_filter_init ( AVFilterContext avctx)

Initialise an OpenCL filter context.

Definition at line 147 of file opencl.c.

Referenced by overlay_opencl_init(), and program_opencl_init().

◆ ff_opencl_filter_uninit()

void ff_opencl_filter_uninit ( AVFilterContext avctx)

◆ ff_opencl_filter_load_program()

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.

Creates a new program and compiles it for the current device. Will log any build errors if compilation fails.

Definition at line 171 of file opencl.c.

Referenced by avgblur_opencl_init(), colorkey_opencl_init(), convolution_opencl_init(), ff_opencl_filter_load_program_from_file(), neighbor_opencl_init(), nlmeans_opencl_init(), overlay_opencl_load(), tonemap_opencl_init(), transpose_opencl_init(), and unsharp_opencl_init().

◆ ff_opencl_filter_load_program_from_file()

int ff_opencl_filter_load_program_from_file ( AVFilterContext avctx,
const char *  filename 
)

Load a new OpenCL program from a file.

Same as ff_opencl_filter_load_program(), but from a file.

Definition at line 219 of file opencl.c.

Referenced by program_opencl_load().

◆ ff_opencl_filter_work_size_from_image()

int ff_opencl_filter_work_size_from_image ( AVFilterContext avctx,
size_t *  work_size,
AVFrame frame,
int  plane,
int  block_alignment 
)

◆ ff_opencl_print_const_matrix_3x3()

void ff_opencl_print_const_matrix_3x3 ( AVBPrint *  buf,
const char *  name_str,
double  mat[3][3] 
)

Print a 3x3 matrix into a buffer as __constant array, which could be included in an OpenCL program.

Definition at line 341 of file opencl.c.

Referenced by tonemap_opencl_init().