38#define DETECTION_FRAMES 63
95 double rgb2rgb[3][3]) {
96 double rgb2xyz[3][3],
xyz2rgb[3][3];
101 if (!in_primaries || !out_primaries)
112#define OPENCL_SOURCE_NB 3
120 int rgb2rgb_passthrough = 1;
130 switch(
ctx->tonemap) {
137 ctx->param = (1.0f -
ctx->param) /
ctx->param;
149 ctx->target_peak = 1.0f;
181 ctx->scene_threshold);
185 if (
ctx->primaries_out !=
ctx->primaries_in) {
188 rgb2rgb_passthrough = 0;
198 if (rgb2rgb_passthrough)
243 opencl_sources[0] =
header.str;
252 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
253 ctx->ocf.hwctx->device_id,
256 "command queue %d.\n", cle);
258 ctx->kernel = clCreateKernel(
ctx->ocf.program,
"tonemap", &cle);
262 clCreateBuffer(
ctx->ocf.hwctx->context, 0,
267 ctx->initialised = 1;
273 clReleaseMemObject(
ctx->util_mem);
274 if (
ctx->command_queue)
275 clReleaseCommandQueue(
ctx->command_queue);
277 clReleaseKernel(
ctx->kernel);
292 "only p010/nv12 supported now\n");
309 size_t global_work[2];
310 size_t local_work[2];
328 cle = clEnqueueNDRangeKernel(
ctx->command_queue, kernel, 2,
NULL,
329 global_work, local_work,
345 double peak =
ctx->peak;
372 if (
ctx->primaries != -1)
374 if (
ctx->colorspace != -1)
376 if (
ctx->range != -1)
389 if (!
ctx->initialised) {
411 if (err < 0)
goto fail;
418 cle = clFinish(
ctx->command_queue);
430 uint32_t *ptr, *max_total_p, *avg_total_p, *frame_number_p;
431 float peak_detected, avg_detected;
433 ptr = (
void *)clEnqueueMapBuffer(
ctx->command_queue,
ctx->util_mem,
434 CL_TRUE, CL_MAP_READ, 0, map_size,
439 avg_total_p = max_total_p + 1;
440 frame_number_p = avg_total_p + 2;
444 peak_detected, avg_detected);
445 clEnqueueUnmapMemObject(
ctx->command_queue,
ctx->util_mem, ptr, 0,
454 clFinish(
ctx->command_queue);
466 clReleaseMemObject(
ctx->util_mem);
468 cle = clReleaseKernel(
ctx->kernel);
469 if (cle != CL_SUCCESS)
471 "kernel: %d.\n", cle);
474 if (
ctx->command_queue) {
475 cle = clReleaseCommandQueue(
ctx->command_queue);
476 if (cle != CL_SUCCESS)
478 "command queue: %d.\n", cle);
484#define OFFSET(x) offsetof(TonemapOpenCLContext, x)
485#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
499 {
"matrix",
"set colorspace matrix",
OFFSET(colorspace),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
FLAGS, .unit =
"matrix" },
541 .p.name =
"tonemap_opencl",
543 .p.priv_class = &tonemap_opencl_class,
static const char *const format[]
const FFFilter ff_vf_tonemap_opencl
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.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_AUTOMATIC
static void fn rgb2yuv(uint8_t *_yuv[3], const ptrdiff_t yuv_stride[3], int16_t *rgb[3], ptrdiff_t s, int w, int h, const int16_t rgb2yuv_coeffs[3][3][8], const int16_t yuv_offset[8])
common internal and external API header
int(* init)(AVBSFContext *ctx)
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
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_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const struct AVLumaCoefficients * av_csp_luma_coeffs_from_avcsp(enum AVColorSpace csp)
Retrieves the Luma coefficients necessary to construct a conversion matrix from an enum constant desc...
const AVColorPrimariesDesc * av_csp_primaries_desc_from_id(enum AVColorPrimaries prm)
Retrieves a complete gamut description from an enum constant describing the color primaries.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
void ff_matrix_mul_3x3(double dst[3][3], const double src1[3][3], const double src2[3][3])
void ff_fill_rgb2xyz_table(const AVPrimaryCoefficients *coeffs, const AVWhitepointCoefficients *wp, double rgb2xyz[3][3])
double ff_determine_signal_peak(AVFrame *in)
void ff_matrix_invert_3x3(const double in[3][3], double out[3][3])
void ff_update_hdr_metadata(AVFrame *in, double peak)
void ff_fill_rgb2yuv_table(const AVLumaCoefficients *coeffs, double rgb2yuv[3][3])
#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.
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.
#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_tonemap_cl
const char * ff_source_colorspace_common_cl
const char * av_color_space_name(enum AVColorSpace space)
const char * av_color_range_name(enum AVColorRange range)
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 char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
AVChromaLocation
Location of chroma samples.
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AVCOL_PRI_BT2020
ITU-R BT2020.
AVColorTransferCharacteristic
Color Transfer Characteristic.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
@ AVCOL_TRC_BT709
also ITU-R BT1361
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
static const uint8_t header[24]
uint8_t * data
The data buffer.
Struct that contains both white point location and primaries location, providing the complete descrip...
AVWhitepointCoefficients wp
AVPrimaryCoefficients prim
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 * src
source filter
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
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.
enum AVChromaLocation chroma_location
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
enum AVColorPrimaries color_primaries
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar calculations.
cl_command_queue command_queue
enum AVColorRange range range_in range_out
enum AVColorTransferCharacteristic trc trc_in trc_out
enum AVChromaLocation chroma_loc
enum AVPixelFormat format
enum AVColorPrimaries primaries primaries_in primaries_out
enum AVColorSpace colorspace colorspace_in colorspace_out
static AVFormatContext * ctx
static const float xyz2rgb[3][3]
static void tonemap(TonemapContext *s, AVFrame *out, const AVFrame *in, const AVPixFmtDescriptor *desc, int x, int y, double peak)
static const char *const delinearize_funcs[]
static int launch_kernel(AVFilterContext *avctx, cl_kernel kernel, AVFrame *output, AVFrame *input, float peak)
static const char *const tonemap_func[TONEMAP_MAX]
static const AVOption tonemap_opencl_options[]
static const char *const linearize_funcs[]
static int tonemap_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
static const AVFilterPad tonemap_opencl_outputs[]
static int get_rgb2rgb_matrix(enum AVColorPrimaries in, enum AVColorPrimaries out, double rgb2rgb[3][3])
static int tonemap_opencl_config_output(AVFilterLink *outlink)
static const float sdr_avg
static av_cold void tonemap_opencl_uninit(AVFilterContext *avctx)
static const AVFilterPad tonemap_opencl_inputs[]
static int tonemap_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.