deps/media-playback: Use metadata for HDR EETF

Used in situations where source luminance is greater than HDR nominal
peak setting to avoid clipping by applying BT.2408 maxRGB EETF.
master
jpark37 2022-05-22 01:21:33 -07:00 committed by Jim
parent 11da542a0d
commit 54f09fe6a7
3 changed files with 35 additions and 0 deletions

View File

@ -15,7 +15,9 @@
*/
#include "decode.h"
#include "media.h"
#include <libavutil/mastering_display_metadata.h>
#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(58, 4, 100)
#define USE_NEW_HARDWARE_CODEC_METHOD
@ -121,6 +123,34 @@ fail:
return ret;
}
static uint16_t get_max_luminance(const AVStream *stream)
{
uint32_t max_luminance = 0;
for (int i = 0; i < stream->nb_side_data; i++) {
const AVPacketSideData *const sd = &stream->side_data[i];
switch (sd->type) {
case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: {
const AVMasteringDisplayMetadata *mastering =
(AVMasteringDisplayMetadata *)sd->data;
if (mastering->has_luminance) {
max_luminance =
(uint32_t)(av_q2d(mastering
->max_luminance) +
0.5);
}
break;
}
case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:
return (uint16_t)((AVContentLightMetadata *)sd->data)
->MaxCLL;
}
}
return max_luminance;
}
bool mp_decode_init(mp_media_t *m, enum AVMediaType type, bool hw)
{
struct mp_decode *d = type == AVMEDIA_TYPE_VIDEO ? &m->v : &m->a;
@ -143,6 +173,9 @@ bool mp_decode_init(mp_media_t *m, enum AVMediaType type, bool hw)
id = stream->codec->codec_id;
#endif
if (type == AVMEDIA_TYPE_VIDEO)
d->max_luminance = get_max_luminance(stream);
if (id == AV_CODEC_ID_VP8 || id == AV_CODEC_ID_VP9) {
AVDictionaryEntry *tag = NULL;
tag = av_dict_get(stream->metadata, "alpha_mode", tag,

View File

@ -67,6 +67,7 @@ struct mp_decode {
bool frame_ready;
bool eof;
bool hw;
uint16_t max_luminance;
AVPacket *orig_pkt;
AVPacket *pkt;

View File

@ -455,6 +455,7 @@ static void mp_media_next_video(mp_media_t *m, bool preload)
frame->width = f->width;
frame->height = f->height;
frame->max_luminance = d->max_luminance;
frame->flip = flip;
frame->flags |= m->is_linear_alpha ? OBS_SOURCE_FRAME_LINEAR_ALPHA : 0;
switch (f->color_trc) {