Commit 157e57a1 authored by Steve Lhomme's avatar Steve Lhomme Committed by James Almer

lavc: Add Content Light Level side metadata found in HEVC

These data are necessary when transmitting HDR over HDMI.
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent b378f5bd
...@@ -15,6 +15,9 @@ libavutil: 2015-08-28 ...@@ -15,6 +15,9 @@ libavutil: 2015-08-28
API changes, most recent first: API changes, most recent first:
2016-04-06 - xxxxxxx - lavc 57.92.100 - avcodec.h
Add AV_PKT_DATA_CONTENT_LIGHT_LEVEL packet side data.
2016-04-06 - xxxxxxx - lavu 55.60.100 - mastering_display_metadata.h 2016-04-06 - xxxxxxx - lavu 55.60.100 - mastering_display_metadata.h
Add AV_FRAME_DATA_CONTENT_LIGHT_LEVEL value, av_content_light_metadata_alloc() Add AV_FRAME_DATA_CONTENT_LIGHT_LEVEL value, av_content_light_metadata_alloc()
and av_content_light_metadata_create_side_data() API, and AVContentLightMetadata and av_content_light_metadata_create_side_data() API, and AVContentLightMetadata
......
...@@ -1584,6 +1584,13 @@ enum AVPacketSideDataType { ...@@ -1584,6 +1584,13 @@ enum AVPacketSideDataType {
* to the AVSphericalMapping structure. * to the AVSphericalMapping structure.
*/ */
AV_PKT_DATA_SPHERICAL, AV_PKT_DATA_SPHERICAL,
/**
* Content light level (based on CTA-861.3). This metadata should be
* associated with a video stream and containts data in the form of the
* AVContentLightMetadata struct.
*/
AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
}; };
#define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED #define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED
......
...@@ -374,6 +374,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type) ...@@ -374,6 +374,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type)
case AV_PKT_DATA_METADATA_UPDATE: return "Metadata Update"; case AV_PKT_DATA_METADATA_UPDATE: return "Metadata Update";
case AV_PKT_DATA_MPEGTS_STREAM_ID: return "MPEGTS Stream ID"; case AV_PKT_DATA_MPEGTS_STREAM_ID: return "MPEGTS Stream ID";
case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: return "Mastering display metadata"; case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: return "Mastering display metadata";
case AV_PKT_DATA_CONTENT_LIGHT_LEVEL: return "Content light level metadata";
case AV_PKT_DATA_SPHERICAL: return "Spherical Mapping"; case AV_PKT_DATA_SPHERICAL: return "Spherical Mapping";
} }
return NULL; return NULL;
......
...@@ -102,6 +102,19 @@ static int decode_nal_sei_mastering_display_info(HEVCContext *s) ...@@ -102,6 +102,19 @@ static int decode_nal_sei_mastering_display_info(HEVCContext *s)
return 0; return 0;
} }
static int decode_nal_sei_content_light_info(HEVCContext *s)
{
GetBitContext *gb = &s->HEVClc->gb;
// Max and average light levels
s->max_content_light_level = get_bits_long(gb, 16);
s->max_pic_average_light_level = get_bits_long(gb, 16);
// As this SEI message comes before the first frame that references it,
// initialize the flag to 2 and decrement on IRAP access unit so it
// persists for the coded video sequence (e.g., between two IRAPs)
s-> sei_content_light_present = 2;
return 0;
}
static int decode_nal_sei_frame_packing_arrangement(HEVCContext *s) static int decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
{ {
GetBitContext *gb = &s->HEVClc->gb; GetBitContext *gb = &s->HEVClc->gb;
...@@ -304,6 +317,8 @@ static int decode_nal_sei_prefix(HEVCContext *s, int type, int size) ...@@ -304,6 +317,8 @@ static int decode_nal_sei_prefix(HEVCContext *s, int type, int size)
} }
case SEI_TYPE_MASTERING_DISPLAY_INFO: case SEI_TYPE_MASTERING_DISPLAY_INFO:
return decode_nal_sei_mastering_display_info(s); return decode_nal_sei_mastering_display_info(s);
case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
return decode_nal_sei_content_light_info(s);
case SEI_TYPE_ACTIVE_PARAMETER_SETS: case SEI_TYPE_ACTIVE_PARAMETER_SETS:
active_parameter_sets(s); active_parameter_sets(s);
av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type); av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
......
...@@ -2644,6 +2644,24 @@ static int set_side_data(HEVCContext *s) ...@@ -2644,6 +2644,24 @@ static int set_side_data(HEVCContext *s)
"min_luminance=%f, max_luminance=%f\n", "min_luminance=%f, max_luminance=%f\n",
av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
} }
// Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1
// so the side data persists for the entire coded video sequence.
if (s->sei_content_light_present > 0 &&
IS_IRAP(s) && s->no_rasl_output_flag) {
s->sei_content_light_present--;
}
if (s->sei_content_light_present) {
AVContentLightMetadata *metadata =
av_content_light_metadata_create_side_data(out);
if (!metadata)
return AVERROR(ENOMEM);
metadata->MaxCLL = s->max_content_light_level;
metadata->MaxFALL = s->max_pic_average_light_level;
av_log(s->avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
av_log(s->avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
metadata->MaxCLL, metadata->MaxFALL);
}
if (s->a53_caption) { if (s->a53_caption) {
AVFrameSideData* sd = av_frame_new_side_data(out, AVFrameSideData* sd = av_frame_new_side_data(out,
......
...@@ -596,6 +596,11 @@ typedef struct HEVCContext { ...@@ -596,6 +596,11 @@ typedef struct HEVCContext {
uint32_t max_mastering_luminance; uint32_t max_mastering_luminance;
uint32_t min_mastering_luminance; uint32_t min_mastering_luminance;
/* content light level */
int sei_content_light_present;
uint16_t max_content_light_level;
uint16_t max_pic_average_light_level;
} HEVCContext; } HEVCContext;
int ff_hevc_decode_nal_sei(HEVCContext *s); int ff_hevc_decode_nal_sei(HEVCContext *s);
......
...@@ -771,6 +771,7 @@ int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame) ...@@ -771,6 +771,7 @@ int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
{ AV_PKT_DATA_STEREO3D, AV_FRAME_DATA_STEREO3D }, { AV_PKT_DATA_STEREO3D, AV_FRAME_DATA_STEREO3D },
{ AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE }, { AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
{ AV_PKT_DATA_MASTERING_DISPLAY_METADATA, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA }, { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
{ AV_PKT_DATA_CONTENT_LIGHT_LEVEL, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
}; };
if (pkt) { if (pkt) {
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57 #define LIBAVCODEC_VERSION_MAJOR 57
#define LIBAVCODEC_VERSION_MINOR 91 #define LIBAVCODEC_VERSION_MINOR 92
#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment