Go to the documentation of this file.
64 if (
ctx->src_display) {
72 const int luma_den = 10000;
73 ctx->in_metadata.max_display_mastering_luminance =
75 ctx->in_metadata.min_display_mastering_luminance =
77 ctx->in_metadata.max_display_mastering_luminance);
80 "Mastering Display Metadata(in luminance):\n");
82 "min_luminance=%u, max_luminance=%u\n",
83 ctx->in_metadata.min_display_mastering_luminance,
84 ctx->in_metadata.max_display_mastering_luminance);
89 const int mapping[3] = {1, 2, 0};
90 const int chroma_den = 50000;
92 for (
i = 0;
i < 3;
i++) {
93 const int j = mapping[
i];
94 ctx->in_metadata.display_primaries_x[
i] =
98 ctx->in_metadata.display_primaries_y[
i] =
104 ctx->in_metadata.white_point_x =
107 ctx->in_metadata.white_point_y =
112 "Mastering Display Metadata(in primaries):\n");
114 "G(%u,%u) B(%u,%u) R(%u,%u) WP(%u,%u)\n",
115 ctx->in_metadata.display_primaries_x[0],
116 ctx->in_metadata.display_primaries_y[0],
117 ctx->in_metadata.display_primaries_x[1],
118 ctx->in_metadata.display_primaries_y[1],
119 ctx->in_metadata.display_primaries_x[2],
120 ctx->in_metadata.display_primaries_y[2],
121 ctx->in_metadata.white_point_x,
122 ctx->in_metadata.white_point_y);
131 if (
ctx->src_light) {
138 ctx->in_metadata.max_content_light_level = light_meta->
MaxCLL;
139 ctx->in_metadata.max_pic_average_light_level = light_meta->
MaxFALL;
142 "Mastering Content Light Level (in):\n");
144 "MaxCLL(%u) MaxFALL(%u)\n",
145 ctx->in_metadata.max_content_light_level,
146 ctx->in_metadata.max_pic_average_light_level);
161 const int mapping[3] = {1, 2, 0};
162 const int chroma_den = 50000;
163 const int luma_den = 10000;
174 const int j = mapping[
i];
197 "Mastering display colour volume(out):\n");
199 "G(%u,%u) B(%u,%u) R(%u,%u) WP(%u,%u)\n",
200 ctx->out_metadata.display_primaries_x[0],
201 ctx->out_metadata.display_primaries_y[0],
202 ctx->out_metadata.display_primaries_x[1],
203 ctx->out_metadata.display_primaries_y[1],
204 ctx->out_metadata.display_primaries_x[2],
205 ctx->out_metadata.display_primaries_y[2],
206 ctx->out_metadata.white_point_x,
207 ctx->out_metadata.white_point_y);
209 "max_display_mastering_luminance=%u, min_display_mastering_luminance=%u\n",
210 ctx->out_metadata.max_display_mastering_luminance,
211 ctx->out_metadata.min_display_mastering_luminance);
221 hdr_meta_lt->
MaxCLL =
FFMIN(
ctx->out_metadata.max_content_light_level, 65535);
222 hdr_meta_lt->
MaxFALL =
FFMIN(
ctx->out_metadata.max_pic_average_light_level, 65535);
225 "Content light level information(out):\n");
227 "MaxCLL(%u) MaxFALL(%u)\n",
228 ctx->out_metadata.max_content_light_level,
229 ctx->out_metadata.max_pic_average_light_level);
239 VAProcFilterParameterBufferHDRToneMapping *hdrtm_param;
242 (
void**)&hdrtm_param);
243 if (vas != VA_STATUS_SUCCESS) {
245 "buffer (%d): %d (%s).\n",
250 memcpy(hdrtm_param->data.metadata, &
ctx->in_metadata,
sizeof(VAHdrMetaDataHDR10));
253 if (vas != VA_STATUS_SUCCESS) {
255 "%d (%s).\n", vas, vaErrorStr(vas));
267 VAProcFilterParameterBufferHDRToneMapping hdrtm_param;
268 VAProcFilterCapHighDynamicRange hdr_cap[VAProcHighDynamicRangeMetadataTypeCount];
272 memset(&hdrtm_param, 0,
sizeof(hdrtm_param));
273 memset(&
ctx->in_metadata, 0,
sizeof(
ctx->in_metadata));
275 num_query_caps = VAProcHighDynamicRangeMetadataTypeCount;
276 vas = vaQueryVideoProcFilterCaps(vpp_ctx->
hwctx->
display,
278 VAProcFilterHighDynamicRangeToneMapping,
279 &hdr_cap, &num_query_caps);
280 if (vas != VA_STATUS_SUCCESS) {
282 "context: %d (%s).\n", vas, vaErrorStr(vas));
286 for (
i = 0;
i < num_query_caps;
i++) {
287 if (hdr_cap[
i].metadata_type != VAProcHighDynamicRangeMetadataNone)
291 if (
i >= num_query_caps) {
296 if (
ctx->mastering_display) {
297 for (
i = 0;
i < num_query_caps;
i++) {
298 if (VA_TONE_MAPPING_HDR_TO_HDR & hdr_cap[
i].caps_flag)
301 if (
i >= num_query_caps) {
303 "VAAPI driver doesn't support HDR to HDR\n");
307 for (
i = 0;
i < num_query_caps;
i++) {
308 if (VA_TONE_MAPPING_HDR_TO_SDR & hdr_cap[
i].caps_flag)
311 if (
i >= num_query_caps) {
313 "VAAPI driver doesn't support HDR to SDR\n");
318 hdrtm_param.type = VAProcFilterHighDynamicRangeToneMapping;
319 hdrtm_param.data.metadata_type = VAProcHighDynamicRangeMetadataHDR10;
320 hdrtm_param.data.metadata = &
ctx->in_metadata;
321 hdrtm_param.data.metadata_size =
sizeof(VAHdrMetaDataHDR10);
324 VAProcFilterParameterBufferType,
325 &hdrtm_param,
sizeof(hdrtm_param), 1);
335 VASurfaceID input_surface, output_surface;
337 VAProcPipelineParameterBuffer params;
340 VAHdrMetaData out_hdr_metadata;
359 input_surface = (VASurfaceID)(uintptr_t)input_frame->
data[3];
370 output_surface = (VASurfaceID)(uintptr_t)
output_frame->data[3];
373 memset(¶ms, 0,
sizeof(params));
382 if (!
ctx->mastering_display) {
398 if (
ctx->mastering_display) {
409 if (
ctx->mastering_display) {
410 out_hdr_metadata.metadata_type = VAProcHighDynamicRangeMetadataHDR10;
411 out_hdr_metadata.metadata = &
ctx->out_metadata;
412 out_hdr_metadata.metadata_size =
sizeof(VAHdrMetaDataHDR10);
413 params.output_hdr_metadata = &out_hdr_metadata;
448 if (
ctx->output_format_string) {
451 if (
ctx->mastering_display) {
453 av_log(avctx,
AV_LOG_VERBOSE,
"Output format not set, use default format P010 for HDR to HDR tone mapping.\n");
456 av_log(avctx,
AV_LOG_VERBOSE,
"Output format not set, use default format NV12 for HDR to SDR tone mapping.\n");
460 #define STRING_OPTION(var_name, func_name, default_value) do { \
461 if (ctx->var_name ## _string) { \
462 int var = av_ ## func_name ## _from_name(ctx->var_name ## _string); \
464 av_log(avctx, AV_LOG_ERROR, "Invalid %s.\n", #var_name); \
465 return AVERROR(EINVAL); \
467 ctx->var_name = var; \
469 ctx->var_name = default_value; \
477 if (
ctx->mastering_display) {
478 if (10 != sscanf(
ctx->mastering_display,
479 "%hu %hu|%hu %hu|%hu %hu|%hu %hu|%u %u",
480 &
ctx->out_metadata.display_primaries_x[0],
481 &
ctx->out_metadata.display_primaries_y[0],
482 &
ctx->out_metadata.display_primaries_x[1],
483 &
ctx->out_metadata.display_primaries_y[1],
484 &
ctx->out_metadata.display_primaries_x[2],
485 &
ctx->out_metadata.display_primaries_y[2],
486 &
ctx->out_metadata.white_point_x,
487 &
ctx->out_metadata.white_point_y,
488 &
ctx->out_metadata.min_display_mastering_luminance,
489 &
ctx->out_metadata.max_display_mastering_luminance)) {
491 "Option mastering-display input invalid\n");
495 if (!
ctx->content_light) {
496 ctx->out_metadata.max_content_light_level = 0;
497 ctx->out_metadata.max_pic_average_light_level = 0;
498 }
else if (2 != sscanf(
ctx->content_light,
500 &
ctx->out_metadata.max_content_light_level,
501 &
ctx->out_metadata.max_pic_average_light_level)) {
503 "Option content-light input invalid\n");
511 #define OFFSET(x) offsetof(HDRVAAPIContext, x)
512 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
515 {
"matrix",
"Output color matrix coefficient set",
517 { .str =
NULL }, .flags =
FLAGS, .unit =
"matrix" },
518 {
"m",
"Output color matrix coefficient set",
520 { .str =
NULL }, .flags =
FLAGS, .unit =
"matrix" },
521 {
"primaries",
"Output color primaries set",
523 { .str =
NULL }, .flags =
FLAGS, .unit =
"primaries" },
524 {
"p",
"Output color primaries set",
526 { .str =
NULL }, .flags =
FLAGS, .unit =
"primaries" },
527 {
"transfer",
"Output color transfer characteristics set",
529 { .str =
NULL }, .flags =
FLAGS, .unit =
"transfer" },
530 {
"t",
"Output color transfer characteristics set",
532 { .str =
NULL }, .flags =
FLAGS, .unit =
"transfer" },
533 {
"display",
"set mastering display colour volume",
536 {
"light",
"set content light level information",
563 .
name =
"tonemap_vaapi",
571 .priv_class = &tonemap_vaapi_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
enum AVColorTransferCharacteristic color_trc
void ff_vaapi_vpp_pipeline_uninit(AVFilterContext *avctx)
void ff_vaapi_vpp_ctx_init(AVFilterContext *avctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
enum AVColorSpace color_matrix
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.
int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, AVFrame *output_frame)
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
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.
unsigned MaxCLL
Max content light level (cd/m^2).
#define FILTER_INPUTS(array)
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).
static int tonemap_vaapi_save_metadata(AVFilterContext *avctx, AVFrame *input_frame)
char * color_primaries_string
#define AV_LOG_VERBOSE
Detailed information.
VADisplay display
The VADisplay handle, to be filled by the user.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
const char * name
Filter name.
A link between two filters.
int ff_vaapi_vpp_query_formats(const AVFilterContext *avctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVFrameSideData * src_light
int(* build_filter_params)(AVFilterContext *avctx)
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
void * priv
private data for use by the filter
enum AVColorPrimaries color_primaries
enum AVColorTransferCharacteristic color_transfer
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVPixelFormat output_format
int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, int type, const void *data, size_t size, int count)
AVVAAPIDeviceContext * hwctx
char * color_transfer_string
#define FILTER_OUTPUTS(array)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
void ff_vaapi_vpp_ctx_uninit(AVFilterContext *avctx)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
int(* init)(AVBSFContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVFILTER_DEFINE_CLASS(tonemap_vaapi)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
static int tonemap_vaapi_build_filter_params(AVFilterContext *avctx)
static const AVOption tonemap_vaapi_options[]
const AVFilter ff_vf_tonemap_vaapi
@ AVCOL_TRC_BT709
also ITU-R BT1361
VAHdrMetaDataHDR10 out_metadata
static void uninit(AVBSFContext *ctx)
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
#define STRING_OPTION(var_name, func_name, default_value)
#define i(width, name, range_min, range_max)
AVColorSpace
YUV colorspace type.
VABufferID filter_buffers[VAProcFilterCount]
static const AVFilterPad tonemap_vaapi_outputs[]
#define FILTER_QUERY_FUNC2(func)
const char * name
Pad name.
static int tonemap_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
@ 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...
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
char * output_format_string
int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
AVFrameSideData * src_display
void(* pipeline_uninit)(AVFilterContext *avctx)
static av_cold int tonemap_vaapi_init(AVFilterContext *avctx)
VAHdrMetaDataHDR10 in_metadata
Structure to hold side data for an AVFrame.
unsigned MaxFALL
Max average light level per frame (cd/m^2).
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
static int tonemap_vaapi_set_filter_params(AVFilterContext *avctx, AVFrame *input_frame)
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
static int tonemap_vaapi_update_sidedata(AVFilterContext *avctx, AVFrame *output_frame)
char * color_matrix_string
static const AVFilterPad tonemap_vaapi_inputs[]
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.
int ff_vaapi_vpp_init_params(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, const AVFrame *input_frame, AVFrame *output_frame)
AVFilterLink ** outputs
array of pointers to output links