From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8CE564704A for ; Tue, 25 Jul 2023 19:29:57 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C2E5168C8B0; Tue, 25 Jul 2023 22:29:37 +0300 (EEST) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C7FB68C617 for ; Tue, 25 Jul 2023 22:29:29 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-4fe0eb0ca75so86418e87.2 for ; Tue, 25 Jul 2023 12:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690313369; x=1690918169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=EICs4aiWllUrE9z+bQyR7SVKV2HtyTsFDPFmdh/KejA=; b=S9xXZ2cFJ9VvIhjm+e/U4Y59Cv5MR4LiMO3SL4LyrvPf3lr34QEDMw2Dz6yXBun6tl D6nuH0y6V8HUahEgjgR9Pg/KpOj+E5A8zF2qYsP2OJqF1ZvjPk5AKSAkxHOmVjDq9gF1 Rffa/b3njUlH+1oW5Bqp4Lo2gEY8sHcr9dwBimw7C9tyKX3EJFh4Sk/snuoNSFGTQIPn SX0UoYlA53ImDVM3T7JYMB5wbkK2JYumDZ3P0fjqAnpOUhsW0Q4ST+6ravV95TEJwQX9 qSmsjLClY3SLEfHN5RVbPSJ4HGwxTkwPemvBPR1gE4aYrFx+T1OhcnZ7eQDVG4rhezEq Y3+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690313369; x=1690918169; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EICs4aiWllUrE9z+bQyR7SVKV2HtyTsFDPFmdh/KejA=; b=aToAH0ijrh+w6vp5P14G6XJy7JxCEpCt9d+aVb/lQ26sRkfQIeHMfzeHG0+tMPvzIe RX6Lg+UvsJ8RH51mFwKz5eXqaIQfj/YnAjbfNxTvE+T72JWyRGZhp7aqP4Tm7nKvrZ80 iSJSjWp3er4AnhgVW1R5/1AZW9VOQjGqwdi4WMDltYvx99i+HZ/VidHAMSqyYH392Auq wECSIlk5gHKNw2zcW9ZUl2y/r+A3HW3wvesGVBO3UkBkCTlEFjebesR0qc7qmrcVIrdG LyXz1lbFEi7RyUneC3svqsERC4l/BOD8l2Cq9vaDzpgm8xtidNFFSWDOuSJNTps0DPrI 5jwg== X-Gm-Message-State: ABy/qLZPABLyazEPgk/pb2qZ0mV1nAEuayxqiUme29ZUuKDLGBhbNKyV /kbAfVClbI7SF4AwlDbUxIa9+iNk1Aw= X-Google-Smtp-Source: APBJJlFVkL+SJRwEqugtGiOGSGB+kCDCskTrg2BXyCEfGjxN0swUnwhJpVpj+YyIYkfwiykoBfWvog== X-Received: by 2002:a05:6512:230e:b0:4fb:9e1a:e592 with SMTP id o14-20020a056512230e00b004fb9e1ae592mr10002806lfu.4.1690313368593; Tue, 25 Jul 2023 12:29:28 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id b2-20020a056512218200b004fa77914b55sm2913124lft.140.2023.07.25.12.29.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 12:29:28 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Jul 2023 22:29:10 +0300 Message-ID: <20230725192918.199526-3-jeebjp@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725192918.199526-1-jeebjp@gmail.com> References: <20230725192918.199526-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/3] avcodec: move content light level SEI handling to h2645_sei X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This allows this common H.274 SEI to be parsed from both H.264 as well as HEVC, as well as probably from VVC in the future. Generally attempts to keep the original code as similar as possible. FATE test refererence changes only change the order of side data export within a single frame. Nothing else seems to have changed. --- libavcodec/h2645_sei.c | 33 +++++++++++++++++++++++++ libavcodec/h2645_sei.h | 7 ++++++ libavcodec/h264_slice.c | 1 + libavcodec/hevc_sei.c | 19 -------------- libavcodec/hevc_sei.h | 7 ------ libavcodec/hevcdec.c | 19 +++----------- tests/ref/fate/hevc-hdr-vivid-metadata | 10 ++++---- tests/ref/fate/hevc-hdr10-plus-metadata | 10 ++++---- 8 files changed, 54 insertions(+), 52 deletions(-) diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index b1ec55d35b..cb6be0594b 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -422,6 +422,23 @@ static int decode_nal_sei_mastering_display_info(H2645SEIMasteringDisplay *s, return 0; } +static int decode_nal_sei_content_light_info(H2645SEIContentLight *s, + GetByteContext *gb) +{ + if (bytestream2_get_bytes_left(gb) < 4) + return AVERROR_INVALIDDATA; + + // Max and average light levels + s->max_content_light_level = bytestream2_get_be16u(gb); + s->max_pic_average_light_level = bytestream2_get_be16u(gb); + // 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->present = 2; + + return 0; +} + int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type, enum AVCodecID codec_id, GetBitContext *gb, GetByteContext *gbyte, void *logctx) @@ -445,6 +462,8 @@ int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type, case SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: return decode_nal_sei_mastering_display_info(&h->mastering_display, gbyte); + case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: + return decode_nal_sei_content_light_info(&h->content_light, gbyte); default: return FF_H2645_SEI_MESSAGE_UNHANDLED; } @@ -730,6 +749,19 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); } + if (sei->content_light.present) { + AVContentLightMetadata *metadata = + av_content_light_metadata_create_side_data(frame); + if (!metadata) + return AVERROR(ENOMEM); + metadata->MaxCLL = sei->content_light.max_content_light_level; + metadata->MaxFALL = sei->content_light.max_pic_average_light_level; + + av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); + av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", + metadata->MaxCLL, metadata->MaxFALL); + } + return 0; } @@ -746,4 +778,5 @@ void ff_h2645_sei_reset(H2645SEI *s) s->ambient_viewing_environment.present = 0; s->mastering_display.present = 0; + s->content_light.present = 0; } diff --git a/libavcodec/h2645_sei.h b/libavcodec/h2645_sei.h index 83e1b2ec16..0ebf48011a 100644 --- a/libavcodec/h2645_sei.h +++ b/libavcodec/h2645_sei.h @@ -113,6 +113,12 @@ typedef struct H2645SEIMasteringDisplay { uint32_t min_luminance; } H2645SEIMasteringDisplay; +typedef struct H2645SEIContentLight { + int present; + uint16_t max_content_light_level; + uint16_t max_pic_average_light_level; +} H2645SEIContentLight; + typedef struct H2645SEI { H2645SEIA53Caption a53_caption; H2645SEIAFD afd; @@ -125,6 +131,7 @@ typedef struct H2645SEI { H2645SEIFilmGrainCharacteristics film_grain_characteristics; H2645SEIAmbientViewingEnvironment ambient_viewing_environment; H2645SEIMasteringDisplay mastering_display; + H2645SEIContentLight content_light; } H2645SEI; enum { diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 586ce20bba..e576bcb070 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -440,6 +440,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst, h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build; h->sei.common.mastering_display = h1->sei.common.mastering_display; + h->sei.common.content_light = h1->sei.common.content_light; if (!h->cur_pic_ptr) return 0; diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c index b7b77d4d0c..351e699726 100644 --- a/libavcodec/hevc_sei.c +++ b/libavcodec/hevc_sei.c @@ -49,23 +49,6 @@ static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, return 0; } -static int decode_nal_sei_content_light_info(HEVCSEIContentLight *s, - GetByteContext *gb) -{ - if (bytestream2_get_bytes_left(gb) < 4) - return AVERROR_INVALIDDATA; - - // Max and average light levels - s->max_content_light_level = bytestream2_get_be16u(gb); - s->max_pic_average_light_level = bytestream2_get_be16u(gb); - // 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->present = 2; - - return 0; -} - static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, const HEVCParamSets *ps, void *logctx) { @@ -177,8 +160,6 @@ static int decode_nal_sei_prefix(GetBitContext *gb, GetByteContext *gbyte, return decode_nal_sei_decoded_picture_hash(&s->picture_hash, gbyte); case SEI_TYPE_PIC_TIMING: return decode_nal_sei_pic_timing(s, gb, ps, logctx); - case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: - return decode_nal_sei_content_light_info(&s->content_light, gbyte); case SEI_TYPE_ACTIVE_PARAMETER_SETS: return decode_nal_sei_active_parameter_sets(s, gb, logctx); case SEI_TYPE_TIME_CODE: diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h index 077abdc74a..a23a64ec4f 100644 --- a/libavcodec/hevc_sei.h +++ b/libavcodec/hevc_sei.h @@ -53,12 +53,6 @@ typedef struct HEVCSEIPictureTiming { int picture_struct; } HEVCSEIPictureTiming; -typedef struct HEVCSEIContentLight { - int present; - uint16_t max_content_light_level; - uint16_t max_pic_average_light_level; -} HEVCSEIContentLight; - typedef struct HEVCSEIAlternativeTransfer { int present; int preferred_transfer_characteristics; @@ -88,7 +82,6 @@ typedef struct HEVCSEI { H2645SEI common; HEVCSEIPictureHash picture_hash; HEVCSEIPictureTiming picture_timing; - HEVCSEIContentLight content_light; int active_seq_parameter_set_id; HEVCSEITimeCode timecode; } HEVCSEI; diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 434750965b..1fe91238d4 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -31,7 +31,6 @@ #include "libavutil/display.h" #include "libavutil/film_grain_params.h" #include "libavutil/internal.h" -#include "libavutil/mastering_display_metadata.h" #include "libavutil/md5.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" @@ -2769,21 +2768,9 @@ static int set_side_data(HEVCContext *s) } // 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 && + if (s->sei.common.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->sei.content_light.max_content_light_level; - metadata->MaxFALL = s->sei.content_light.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); + s->sei.common.content_light.present--; } ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, NULL, @@ -3624,7 +3611,7 @@ static int hevc_update_thread_context(AVCodecContext *dst, s->sei.common.display_orientation = s0->sei.common.display_orientation; s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer; s->sei.common.mastering_display = s0->sei.common.mastering_display; - s->sei.content_light = s0->sei.content_light; + s->sei.common.content_light = s0->sei.common.content_light; ret = export_stream_params_from_sei(s); if (ret < 0) diff --git a/tests/ref/fate/hevc-hdr-vivid-metadata b/tests/ref/fate/hevc-hdr-vivid-metadata index cb5db4557f..f3c777a852 100644 --- a/tests/ref/fate/hevc-hdr-vivid-metadata +++ b/tests/ref/fate/hevc-hdr-vivid-metadata @@ -1,10 +1,5 @@ [FRAME] [SIDE_DATA] -side_data_type=Content light level metadata -max_content=0 -max_average=0 -[/SIDE_DATA] -[SIDE_DATA] side_data_type=H.26[45] User Data Unregistered SEI message [/SIDE_DATA] [SIDE_DATA] @@ -21,6 +16,11 @@ min_luminance=50/10000 max_luminance=40000000/10000 [/SIDE_DATA] [SIDE_DATA] +side_data_type=Content light level metadata +max_content=0 +max_average=0 +[/SIDE_DATA] +[SIDE_DATA] side_data_type=HDR Dynamic Metadata CUVA 005.1 2021 (Vivid) system_start_code=1 num_windows=1 diff --git a/tests/ref/fate/hevc-hdr10-plus-metadata b/tests/ref/fate/hevc-hdr10-plus-metadata index cdf308b96a..f226cd8c7b 100644 --- a/tests/ref/fate/hevc-hdr10-plus-metadata +++ b/tests/ref/fate/hevc-hdr10-plus-metadata @@ -1,10 +1,5 @@ [FRAME] [SIDE_DATA] -side_data_type=Content light level metadata -max_content=1000 -max_average=200 -[/SIDE_DATA] -[SIDE_DATA] side_data_type=Mastering display metadata red_x=13250/50000 red_y=34500/50000 @@ -18,6 +13,11 @@ min_luminance=50/10000 max_luminance=10000000/10000 [/SIDE_DATA] [SIDE_DATA] +side_data_type=Content light level metadata +max_content=1000 +max_average=200 +[/SIDE_DATA] +[SIDE_DATA] side_data_type=HDR Dynamic Metadata SMPTE2094-40 (HDR10+) application version=1 num_windows=1 -- 2.41.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".