Go to the documentation of this file.
39 #define DETECTION_FRAMES 63
105 double rgb2rgb[3][3]) {
106 double rgb2xyz[3][3], xyz2rgb[3][3];
114 #define OPENCL_SOURCE_NB 3
122 int rgb2rgb_passthrough = 1;
132 switch(
ctx->tonemap) {
139 ctx->param = (1.0f -
ctx->param) /
ctx->param;
151 ctx->target_peak = 1.0f;
183 ctx->scene_threshold);
187 if (
ctx->primaries_out !=
ctx->primaries_in) {
189 rgb2rgb_passthrough = 0;
199 if (rgb2rgb_passthrough)
229 luma_src->
cr, luma_src->
cg, luma_src->
cb);
231 luma_dst->
cr, luma_dst->
cg, luma_dst->
cb);
244 opencl_sources[0] =
header.str;
253 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
254 ctx->ocf.hwctx->device_id,
257 "command queue %d.\n", cle);
259 ctx->kernel = clCreateKernel(
ctx->ocf.program,
"tonemap", &cle);
263 clCreateBuffer(
ctx->ocf.hwctx->context, 0,
268 ctx->initialised = 1;
274 clReleaseMemObject(
ctx->util_mem);
275 if (
ctx->command_queue)
276 clReleaseCommandQueue(
ctx->command_queue);
278 clReleaseKernel(
ctx->kernel);
293 "only p010/nv12 supported now\n");
310 size_t global_work[2];
311 size_t local_work[2];
329 cle = clEnqueueNDRangeKernel(
ctx->command_queue, kernel, 2,
NULL,
330 global_work, local_work,
346 double peak =
ctx->peak;
355 if (!
input->hw_frames_ctx)
373 if (
ctx->primaries != -1)
374 output->color_primaries =
ctx->primaries;
375 if (
ctx->colorspace != -1)
377 if (
ctx->range != -1)
382 ctx->colorspace_in =
input->colorspace;
383 ctx->colorspace_out =
output->colorspace;
384 ctx->primaries_in =
input->color_primaries;
385 ctx->primaries_out =
output->color_primaries;
388 ctx->chroma_loc =
output->chroma_location;
390 if (!
ctx->initialised) {
412 if (err < 0)
goto fail;
419 cle = clFinish(
ctx->command_queue);
431 uint32_t *ptr, *max_total_p, *avg_total_p, *frame_number_p;
432 float peak_detected, avg_detected;
434 ptr = (
void *)clEnqueueMapBuffer(
ctx->command_queue,
ctx->util_mem,
435 CL_TRUE, CL_MAP_READ, 0, map_size,
440 avg_total_p = max_total_p + 1;
441 frame_number_p = avg_total_p + 2;
442 peak_detected = (float)*max_total_p / (
REFERENCE_WHITE * (*frame_number_p));
443 avg_detected = (float)*avg_total_p / (
REFERENCE_WHITE * (*frame_number_p));
445 peak_detected, avg_detected);
446 clEnqueueUnmapMemObject(
ctx->command_queue,
ctx->util_mem, ptr, 0,
455 clFinish(
ctx->command_queue);
467 clReleaseMemObject(
ctx->util_mem);
469 cle = clReleaseKernel(
ctx->kernel);
470 if (cle != CL_SUCCESS)
472 "kernel: %d.\n", cle);
475 if (
ctx->command_queue) {
476 cle = clReleaseCommandQueue(
ctx->command_queue);
477 if (cle != CL_SUCCESS)
479 "command queue: %d.\n", cle);
485 #define OFFSET(x) offsetof(TonemapOpenCLContext, x)
486 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
544 .
name =
"tonemap_opencl",
547 .priv_class = &tonemap_opencl_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
enum AVPixelFormat format
static av_cold int init(AVCodecContext *avctx)
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
AVColorTransferCharacteristic
Color Transfer Characteristic.
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
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])
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static const char * delinearize_funcs[AVCOL_TRC_NB]
static int launch_kernel(AVFilterContext *avctx, cl_kernel kernel, AVFrame *output, AVFrame *input, float peak)
void ff_matrix_invert_3x3(const double in[3][3], double out[3][3])
static int tonemap_opencl_config_output(AVFilterLink *outlink)
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
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
const char * ff_opencl_source_tonemap
This structure describes decoded (raw) audio or video data.
@ AVCOL_TRC_NB
Not part of ABI.
@ AVCOL_RANGE_JPEG
the normal 2^n-1 "JPEG" YUV ranges
static void get_rgb2rgb_matrix(enum AVColorPrimaries in, enum AVColorPrimaries out, double rgb2rgb[3][3])
double ff_determine_signal_peak(AVFrame *in)
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.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
const char * name
Filter name.
A link between two filters.
enum AVColorSpace colorspace colorspace_in colorspace_out
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_tonemap_opencl
const char * av_color_space_name(enum AVColorSpace space)
void * priv
private data for use by the filter
enum AVChromaLocation chroma_loc
#define AV_BPRINT_SIZE_AUTOMATIC
static void tonemap(TonemapContext *s, AVFrame *out, const AVFrame *in, const AVPixFmtDescriptor *desc, int x, int y, double peak)
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.
enum AVColorPrimaries primaries primaries_in primaries_out
static int tonemap_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
const struct LumaCoefficients * ff_get_luma_coefficients(enum AVColorSpace csp)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AVCOL_PRI_NB
Not part of ABI.
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs, double rgb2yuv[3][3])
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVFilterPad outputs[]
static const char * linearize_funcs[AVCOL_TRC_NB]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const char * ff_opencl_source_colorspace_common
static const AVFilterPad tonemap_opencl_outputs[]
static av_cold void tonemap_opencl_uninit(AVFilterContext *avctx)
const char * av_color_range_name(enum AVColorRange range)
void ff_matrix_mul_3x3(double dst[3][3], const double src1[3][3], const double src2[3][3])
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void ff_fill_rgb2xyz_table(const struct PrimaryCoefficients *coeffs, const struct WhitepointCoefficients *wp, double rgb2xyz[3][3])
cl_command_queue command_queue
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
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
enum AVColorRange range range_in range_out
@ AVCOL_PRI_BT2020
ITU-R BT2020.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const AVFilterPad tonemap_opencl_inputs[]
static const float sdr_avg
static const struct PrimaryCoefficients primaries_table[AVCOL_PRI_NB]
void ff_update_hdr_metadata(AVFrame *in, double peak)
static const char * tonemap_func[TONEMAP_MAX]
AVFilterContext * src
source filter
static const uint8_t header[24]
static const struct WhitepointCoefficients whitepoint_table[AVCOL_PRI_NB]
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
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.
@ AVCOL_TRC_BT709
also ITU-R BT1361
AVChromaLocation
Location of chroma samples.
AVFILTER_DEFINE_CLASS(tonemap_opencl)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
enum AVColorTransferCharacteristic trc trc_in trc_out
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
int w
agreed upon image width
AVColorSpace
YUV colorspace type.
static int tonemap_opencl_init(AVFilterContext *avctx)
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.
const char * name
Pad name.
enum TonemapAlgorithm tonemap
@ AVCOL_RANGE_MPEG
the normal 219*2^(n-8) "MPEG" YUV ranges
This struct describes a set or pool of "hardware" frames (i.e.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
@ 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...
void av_bprintf(AVBPrint *buf, const char *fmt,...)
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
int h
agreed upon image height
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
static const AVOption tonemap_opencl_options[]
static int query_formats(AVFilterContext *ctx)
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
static av_cold int uninit(AVCodecContext *avctx)
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
AVColorRange
MPEG vs JPEG YUV range.
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
int ff_opencl_filter_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
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.
AVFilterLink ** outputs
array of pointers to output links