41 #define DETECTION_FRAMES 63
122 double rgb2rgb[3][3]) {
123 double rgb2xyz[3][3], xyz2rgb[3][3];
131 #define OPENCL_SOURCE_NB 3
139 int rgb2rgb_passthrough = 1;
140 double rgb2rgb[3][3];
192 av_bprintf(&header,
"__constant const float tone_param = %.4ff;\n",
194 av_bprintf(&header,
"__constant const float desat_param = %.4ff;\n",
196 av_bprintf(&header,
"__constant const float target_peak = %.4ff;\n",
199 av_bprintf(&header,
"__constant const float scene_threshold = %.4ff;\n",
206 rgb2rgb_passthrough = 0;
209 av_bprintf(&header,
"#define FULL_RANGE_IN\n");
212 av_bprintf(&header,
"#define FULL_RANGE_OUT\n");
216 if (rgb2rgb_passthrough)
217 av_bprintf(&header,
"#define RGB2RGB_PASSTHROUGH\n");
219 av_bprintf(&header,
"__constant float rgb2rgb[9] = {\n");
220 av_bprintf(&header,
" %.4ff, %.4ff, %.4ff,\n",
221 rgb2rgb[0][0], rgb2rgb[0][1], rgb2rgb[0][2]);
222 av_bprintf(&header,
" %.4ff, %.4ff, %.4ff,\n",
223 rgb2rgb[1][0], rgb2rgb[1][1], rgb2rgb[1][2]);
224 av_bprintf(&header,
" %.4ff, %.4ff, %.4ff};\n",
225 rgb2rgb[2][0], rgb2rgb[2][1], rgb2rgb[2][2]);
228 av_bprintf(&header,
"#define rgb_matrix %s\n",
230 av_bprintf(&header,
"#define yuv_matrix %s\n",
233 luma_src = luma_coefficients[ctx->colorspace_in];
235 av_bprintf(&header,
"constant float3 luma_src = {%.4ff, %.4ff, %.4ff};\n",
236 luma_src.
cr, luma_src.
cg, luma_src.
cb);
237 av_bprintf(&header,
"constant float3 luma_dst = {%.4ff, %.4ff, %.4ff};\n",
238 luma_dst.
cr, luma_dst.
cg, luma_dst.
cb);
241 av_bprintf(&header,
"#define delinearize %s\n",
245 av_bprintf(&header,
"#define ootf_impl ootf_hlg\n");
248 av_bprintf(&header,
"#define inverse_ootf_impl inverse_ootf_hlg\n");
251 opencl_sources[0] = header.str;
264 "command queue %d.\n", cle);
284 clReleaseKernel(ctx->
kernel);
299 "only p010/nv12 supported now\n");
316 size_t global_work[2];
317 size_t local_work[2];
336 global_work, local_work,
352 double peak = ctx->
peak;
379 if (ctx->primaries != -1)
381 if (ctx->colorspace != -1)
383 if (ctx->range != -1)
418 if (err < 0)
goto fail;
437 uint32_t *ptr, *max_total_p, *avg_total_p, *frame_number_p;
438 float peak_detected, avg_detected;
441 CL_TRUE, CL_MAP_READ, 0, map_size,
446 avg_total_p = max_total_p + 1;
447 frame_number_p = avg_total_p + 2;
448 peak_detected = (float)*max_total_p / (
REFERENCE_WHITE * (*frame_number_p));
449 avg_detected = (float)*avg_total_p / (
REFERENCE_WHITE * (*frame_number_p));
451 peak_detected, avg_detected);
475 cle = clReleaseKernel(ctx->
kernel);
476 if (cle != CL_SUCCESS)
478 "kernel: %d.\n", cle);
483 if (cle != CL_SUCCESS)
485 "command queue: %d.\n", cle);
491 #define OFFSET(x) offsetof(TonemapOpenCLContext, x)
492 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
550 .
name =
"tonemap_opencl",
553 .priv_class = &tonemap_opencl_class,
557 .
inputs = tonemap_opencl_inputs,
558 .
outputs = tonemap_opencl_outputs,
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
void av_bprintf(AVBPrint *buf, const char *fmt,...)
static const char * format[]
This structure describes decoded (raw) audio or video data.
static int tonemap_opencl_config_output(AVFilterLink *outlink)
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_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.
#define AV_LOG_WARNING
Something somehow does not look correct.
Main libavfilter public API header.
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
static void get_rgb2rgb_matrix(enum AVColorPrimaries in, enum AVColorPrimaries out, double rgb2rgb[3][3])
int h
agreed upon image height
static const char * delinearize_funcs[AVCOL_TRC_NB]
enum AVChromaLocation chroma_loc
static int launch_kernel(AVFilterContext *avctx, cl_kernel kernel, AVFrame *output, AVFrame *input, float peak)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
enum AVColorSpace colorspace colorspace_in colorspace_out
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
static const struct LumaCoefficients luma_coefficients[AVCOL_SPC_NB]
AVColorTransferCharacteristic
Color Transfer Characteristic.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
const char * av_color_space_name(enum AVColorSpace space)
AVOpenCLDeviceContext * hwctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
const char * name
Pad name.
#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.
static av_cold int uninit(AVCodecContext *avctx)
AVColorSpace
YUV colorspace type.
const char * av_color_range_name(enum AVColorRange range)
enum AVColorPrimaries primaries primaries_in primaries_out
cl_device_id device_id
The primary device ID of the device.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVFilter ff_vf_tonemap_opencl
static struct PrimaryCoefficients primaries_table[AVCOL_PRI_NB]
AVColorRange
MPEG vs JPEG YUV range.
static const uint8_t header[24]
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
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 av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
static const AVFilterPad tonemap_opencl_inputs[]
void * priv
private data for use by the filter
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVColorSpace colorspace
YUV colorspace type.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
simple assert() macros that are a bit more flexible than ISO C assert().
static struct WhitepointCoefficients whitepoint_table[AVCOL_PRI_NB]
enum TonemapAlgorithm tonemap
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
enum AVPixelFormat output_format
static int tonemap_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
int w
agreed upon image width
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
static const float sdr_avg
ITU-R BT2020 non-constant luminance system.
static const char * linearize_funcs[AVCOL_TRC_NB]
static const char * rgb_coff[AVCOL_SPC_NB]
static int tonemap_opencl_init(AVFilterContext *avctx)
AVFilterContext * src
source filter
static const char * tonemap_func[TONEMAP_MAX]
static const AVFilterPad tonemap_opencl_outputs[]
enum AVColorTransferCharacteristic trc trc_in trc_out
static const AVFilterPad inputs[]
static av_cold void tonemap_opencl_uninit(AVFilterContext *avctx)
static const AVFilterPad outputs[]
the normal 2^n-1 "JPEG" YUV ranges
void ff_update_hdr_metadata(AVFrame *in, double peak)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define AV_BPRINT_SIZE_AUTOMATIC
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
uint8_t * data
The data buffer.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
This struct describes a set or pool of "hardware" frames (i.e.
void ff_matrix_invert_3x3(const double in[3][3], double out[3][3])
AVFILTER_DEFINE_CLASS(tonemap_opencl)
const char * name
Filter name.
const char * ff_opencl_source_colorspace_common
enum AVChromaLocation chroma_location
AVFilterLink ** outputs
array of pointers to output links
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
static int query_formats(AVFilterContext *ctx)
common internal and external API header
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
ARIB STD-B67, known as "Hybrid log-gamma".
void ff_matrix_mul_3x3(double dst[3][3], const double src1[3][3], const double src2[3][3])
AVFilterContext * dst
dest filter
cl_context context
The OpenCL context which will contain all operations and frames on this device.
static const char * yuv_coff[AVCOL_SPC_NB]
static const AVOption tonemap_opencl_options[]
enum AVColorPrimaries color_primaries
ITU-R BT2020 for 10-bit system.
const char * ff_opencl_source_tonemap
AVChromaLocation
Location of chroma samples.
enum AVColorTransferCharacteristic color_trc
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.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
enum AVColorRange range range_in range_out
double ff_determine_signal_peak(AVFrame *in)
static void tonemap(TonemapContext *s, AVFrame *out, const AVFrame *in, const AVPixFmtDescriptor *desc, int x, int y, double peak)
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
enum AVPixelFormat format