History

avcodec: move content light level SEI handling to h2645_sei

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.

Jan Ekström committed 3 years ago

Commit 43e63ff1 parent 33358b88 files · +54 −52Browse files

Unified · Split

8 files
  1. libavcodec/h2645_sei.c +33 −0
  2. libavcodec/h2645_sei.h +7 −0
  3. libavcodec/h264_slice.c +1 −0
  4. libavcodec/hevc_sei.c +0 −19
  5. libavcodec/hevc_sei.h +0 −7
  6. libavcodec/hevcdec.c +3 −16
  7. tests/ref/fate/hevc-hdr-vivid-metadata +5 −5
  8. tests/ref/fate/hevc-hdr10-plus-metadata +5 −5
libavcodec/h2645_sei.c+33−0
@@ -422,6 +422,23 @@ static int decode_nal_sei_mastering_display_info(H2645SEIMasteringDisplay *s, · 421 unmodified lines
422422 return 0;
423423 }
424424
425+static int decode_nal_sei_content_light_info(H2645SEIContentLight *s,
426+ GetByteContext *gb)
427+{
428+ if (bytestream2_get_bytes_left(gb) < 4)
429+ return AVERROR_INVALIDDATA;
430+
431+ // Max and average light levels
432+ s->max_content_light_level = bytestream2_get_be16u(gb);
433+ s->max_pic_average_light_level = bytestream2_get_be16u(gb);
434+ // As this SEI message comes before the first frame that references it,
435+ // initialize the flag to 2 and decrement on IRAP access unit so it
436+ // persists for the coded video sequence (e.g., between two IRAPs)
437+ s->present = 2;
438+
439+ return 0;
440+}
441+
425442 int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type,
426443 enum AVCodecID codec_id, GetBitContext *gb,
427444 GetByteContext *gbyte, void *logctx)
@@ -445,6 +462,8 @@ int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type, · 17 unmodified lines
445462 case SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
446463 return decode_nal_sei_mastering_display_info(&h->mastering_display,
447464 gbyte);
465+ case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
466+ return decode_nal_sei_content_light_info(&h->content_light, gbyte);
448467 default:
449468 return FF_H2645_SEI_MESSAGE_UNHANDLED;
450469 }
@@ -730,6 +749,19 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, · 279 unmodified lines
730749 av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
731750 }
732751
752+ if (sei->content_light.present) {
753+ AVContentLightMetadata *metadata =
754+ av_content_light_metadata_create_side_data(frame);
755+ if (!metadata)
756+ return AVERROR(ENOMEM);
757+ metadata->MaxCLL = sei->content_light.max_content_light_level;
758+ metadata->MaxFALL = sei->content_light.max_pic_average_light_level;
759+
760+ av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
761+ av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
762+ metadata->MaxCLL, metadata->MaxFALL);
763+ }
764+
733765 return 0;
734766 }
735767
@@ -746,4 +778,5 @@ void ff_h2645_sei_reset(H2645SEI *s) · 10 unmodified lines
746778
747779 s->ambient_viewing_environment.present = 0;
748780 s->mastering_display.present = 0;
781+ s->content_light.present = 0;
749782 }
libavcodec/h2645_sei.h+7−0
@@ -113,6 +113,12 @@ typedef struct H2645SEIMasteringDisplay { · 112 unmodified lines
113113 uint32_t min_luminance;
114114 } H2645SEIMasteringDisplay;
115115
116+typedef struct H2645SEIContentLight {
117+ int present;
118+ uint16_t max_content_light_level;
119+ uint16_t max_pic_average_light_level;
120+} H2645SEIContentLight;
121+
116122 typedef struct H2645SEI {
117123 H2645SEIA53Caption a53_caption;
118124 H2645SEIAFD afd;
@@ -125,6 +131,7 @@ typedef struct H2645SEI { · 6 unmodified lines
125131 H2645SEIFilmGrainCharacteristics film_grain_characteristics;
126132 H2645SEIAmbientViewingEnvironment ambient_viewing_environment;
127133 H2645SEIMasteringDisplay mastering_display;
134+ H2645SEIContentLight content_light;
128135 } H2645SEI;
129136
130137 enum {
libavcodec/h264_slice.c+1−0
@@ -440,6 +440,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst, · 439 unmodified lines
440440
441441 h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build;
442442 h->sei.common.mastering_display = h1->sei.common.mastering_display;
443+ h->sei.common.content_light = h1->sei.common.content_light;
443444
444445 if (!h->cur_pic_ptr)
445446 return 0;
libavcodec/hevc_sei.c+0−19
@@ -49,23 +49,6 @@ static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, · 48 unmodified lines
4949 return 0;
5050 }
5151
52−static int decode_nal_sei_content_light_info(HEVCSEIContentLight *s,
53− GetByteContext *gb)
54−{
55− if (bytestream2_get_bytes_left(gb) < 4)
56− return AVERROR_INVALIDDATA;
57−
58− // Max and average light levels
59− s->max_content_light_level = bytestream2_get_be16u(gb);
60− s->max_pic_average_light_level = bytestream2_get_be16u(gb);
61− // As this SEI message comes before the first frame that references it,
62− // initialize the flag to 2 and decrement on IRAP access unit so it
63− // persists for the coded video sequence (e.g., between two IRAPs)
64− s->present = 2;
65−
66− return 0;
67−}
68−
6952 static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb,
7053 const HEVCParamSets *ps, void *logctx)
7154 {
@@ -177,8 +160,6 @@ static int decode_nal_sei_prefix(GetBitContext *gb, GetByteContext *gbyte, · 105 unmodified lines
177160 return decode_nal_sei_decoded_picture_hash(&s->picture_hash, gbyte);
178161 case SEI_TYPE_PIC_TIMING:
179162 return decode_nal_sei_pic_timing(s, gb, ps, logctx);
180− case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
181− return decode_nal_sei_content_light_info(&s->content_light, gbyte);
182163 case SEI_TYPE_ACTIVE_PARAMETER_SETS:
183164 return decode_nal_sei_active_parameter_sets(s, gb, logctx);
184165 case SEI_TYPE_TIME_CODE:
libavcodec/hevc_sei.h+0−7
@@ -53,12 +53,6 @@ typedef struct HEVCSEIPictureTiming { · 52 unmodified lines
5353 int picture_struct;
5454 } HEVCSEIPictureTiming;
5555
56−typedef struct HEVCSEIContentLight {
57− int present;
58− uint16_t max_content_light_level;
59− uint16_t max_pic_average_light_level;
60−} HEVCSEIContentLight;
61−
6256 typedef struct HEVCSEIAlternativeTransfer {
6357 int present;
6458 int preferred_transfer_characteristics;
@@ -88,7 +82,6 @@ typedef struct HEVCSEI { · 23 unmodified lines
8882 H2645SEI common;
8983 HEVCSEIPictureHash picture_hash;
9084 HEVCSEIPictureTiming picture_timing;
91− HEVCSEIContentLight content_light;
9285 int active_seq_parameter_set_id;
9386 HEVCSEITimeCode timecode;
9487 } HEVCSEI;
libavcodec/hevcdec.c+3−16
@@ -31,7 +31,6 @@ · 30 unmodified lines
3131 #include "libavutil/display.h"
3232 #include "libavutil/film_grain_params.h"
3333 #include "libavutil/internal.h"
34−#include "libavutil/mastering_display_metadata.h"
3534 #include "libavutil/md5.h"
3635 #include "libavutil/opt.h"
3736 #include "libavutil/pixdesc.h"
@@ -2769,21 +2768,9 @@ static int set_side_data(HEVCContext *s) · 2731 unmodified lines
27692768 }
27702769 // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1
27712770 // so the side data persists for the entire coded video sequence.
2772− if (s->sei.content_light.present > 0 &&
2771+ if (s->sei.common.content_light.present > 0 &&
27732772 IS_IRAP(s) && s->no_rasl_output_flag) {
2774− s->sei.content_light.present--;
2775− }
2776− if (s->sei.content_light.present) {
2777− AVContentLightMetadata *metadata =
2778− av_content_light_metadata_create_side_data(out);
2779− if (!metadata)
2780− return AVERROR(ENOMEM);
2781− metadata->MaxCLL = s->sei.content_light.max_content_light_level;
2782− metadata->MaxFALL = s->sei.content_light.max_pic_average_light_level;
2783−
2784− av_log(s->avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
2785− av_log(s->avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
2786− metadata->MaxCLL, metadata->MaxFALL);
2773+ s->sei.common.content_light.present--;
27872774 }
27882775
27892776 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, · 834 unmodified lines
36243611 s->sei.common.display_orientation = s0->sei.common.display_orientation;
36253612 s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer;
36263613 s->sei.common.mastering_display = s0->sei.common.mastering_display;
3627− s->sei.content_light = s0->sei.content_light;
3614+ s->sei.common.content_light = s0->sei.common.content_light;
36283615
36293616 ret = export_stream_params_from_sei(s);
36303617 if (ret < 0)
tests/ref/fate/hevc-hdr-vivid-metadata+5−5
@@ -1,10 +1,5 @@
11 [FRAME]
22 [SIDE_DATA]
3−side_data_type=Content light level metadata
4−max_content=0
5−max_average=0
6−[/SIDE_DATA]
7−[SIDE_DATA]
83 side_data_type=H.26[45] User Data Unregistered SEI message
94 [/SIDE_DATA]
105 [SIDE_DATA]
@@ -21,6 +16,11 @@ min_luminance=50/10000 · 10 unmodified lines
2116 max_luminance=40000000/10000
2217 [/SIDE_DATA]
2318 [SIDE_DATA]
19+side_data_type=Content light level metadata
20+max_content=0
21+max_average=0
22+[/SIDE_DATA]
23+[SIDE_DATA]
2424 side_data_type=HDR Dynamic Metadata CUVA 005.1 2021 (Vivid)
2525 system_start_code=1
2626 num_windows=1
tests/ref/fate/hevc-hdr10-plus-metadata+5−5
@@ -1,10 +1,5 @@
11 [FRAME]
22 [SIDE_DATA]
3−side_data_type=Content light level metadata
4−max_content=1000
5−max_average=200
6−[/SIDE_DATA]
7−[SIDE_DATA]
83 side_data_type=Mastering display metadata
94 red_x=13250/50000
105 red_y=34500/50000
@@ -18,6 +13,11 @@ min_luminance=50/10000 · 7 unmodified lines
1813 max_luminance=10000000/10000
1914 [/SIDE_DATA]
2015 [SIDE_DATA]
16+side_data_type=Content light level metadata
17+max_content=1000
18+max_average=200
19+[/SIDE_DATA]
20+[SIDE_DATA]
2121 side_data_type=HDR Dynamic Metadata SMPTE2094-40 (HDR10+)
2222 application version=1
2323 num_windows=1

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t