These data are necessary when transmitting HDR over HDMI. Signed-off-by: James Almer <jamr...@gmail.com> --- doc/APIchanges | 3 +++ libavcodec/avcodec.h | 7 +++++++ libavcodec/decode.c | 1 + libavcodec/hevc_sei.c | 15 +++++++++++++++ libavcodec/hevcdec.c | 18 ++++++++++++++++++ libavcodec/hevcdec.h | 5 +++++ libavcodec/version.h | 4 ++-- 7 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges index 4c35f727e6..ace50b2a3d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2017-03-23 API changes, most recent first: +2016-04-06 - xxxxxxx - lavc 58.2.0 - avcodec.h + Add AV_PKT_DATA_CONTENT_LIGHT_LEVEL packet side data. + 2016-04-xx - xxxxxxx - lavu 56.2.0 - mastering_display_metadata.h Add AV_FRAME_DATA_CONTENT_LIGHT_LEVEL value, av_content_light_metadata_alloc() and av_content_light_metadata_create_side_data() API, and AVContentLightMetadata diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index fc1f2a4dfc..1d41badea6 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1075,6 +1075,13 @@ enum AVPacketSideDataType { * of the AVMasteringDisplayMetadata struct. */ AV_PKT_DATA_MASTERING_DISPLAY_METADATA, + + /** + * 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, }; typedef struct AVPacketSideData { diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 4a05b8d089..3ed5cc4fd6 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1030,6 +1030,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) { AV_PKT_DATA_STEREO3D, AV_FRAME_DATA_STEREO3D }, { 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_CONTENT_LIGHT_LEVEL, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL }, }; frame->color_primaries = avctx->color_primaries; diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c index 1105b51493..e41b8262bc 100644 --- a/libavcodec/hevc_sei.c +++ b/libavcodec/hevc_sei.c @@ -99,6 +99,19 @@ static int decode_nal_sei_mastering_display_info(HEVCContext *s) 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) { GetBitContext *gb = &s->HEVClc.gb; @@ -155,6 +168,8 @@ static int decode_nal_sei_prefix(HEVCContext *s, int type, int size) return decode_nal_sei_display_orientation(s); case SEI_TYPE_MASTERING_DISPLAY_INFO: return decode_nal_sei_mastering_display_info(s); + case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: + return decode_nal_sei_content_light_info(s); default: av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type); skip_bits_long(gb, 8 * size); diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 30d9194c60..22ca33a9f7 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -2455,6 +2455,24 @@ static int set_side_data(HEVCContext *s) "min_luminance=%f, max_luminance=%f\n", 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); + } return 0; } diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index cb8bd2e7e5..ffc3fdcac2 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -553,6 +553,11 @@ typedef struct HEVCContext { uint32_t max_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; int ff_hevc_decode_nal_sei(HEVCContext *s); diff --git a/libavcodec/version.h b/libavcodec/version.h index 774230b1ef..63c9a1f634 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,8 +28,8 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 58 -#define LIBAVCODEC_VERSION_MINOR 1 -#define LIBAVCODEC_VERSION_MICRO 1 +#define LIBAVCODEC_VERSION_MINOR 2 +#define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ -- 2.11.1 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel