From a5bba606a01fa8638e3f566ada730cd29f8dbc3f Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sat, 2 Jul 2022 14:20:36 +0200 Subject: [PATCH] avcodec/h2645_sei: Also support Active Format Descriptor for HEVC It is valid for HEVC; in fact, the ATSC-HEVC spec [1] simply refers to the relevant H.264 spec. It is also trivial to implement now: Just move applying AFD to ff_h2645_sei_to_frame() and stop ignoring AFD when parsing a HEVC SEI containing it. A FATE-test for this has been added. [1]: https://www.atsc.org/atsc-documents/a3412017-video-hevc/ Signed-off-by: Andreas Rheinhardt --- libavcodec/h2645_sei.c | 15 ++- libavcodec/h2645_sei.h | 6 +- libavcodec/h264_slice.c | 10 -- tests/fate/hevc.mak | 3 + tests/ref/fate/hevc-afd-tc-sei | 204 +++++++++++++++++++++++++++++++++ 5 files changed, 221 insertions(+), 17 deletions(-) create mode 100644 tests/ref/fate/hevc-afd-tc-sei diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index 0596bd5e84..0e201a20a4 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -95,7 +95,7 @@ static int decode_registered_user_data_dynamic_hdr_vivid(HEVCSEIDynamicHDRVivid } #endif -static int decode_registered_user_data_afd(H264SEIAFD *h, GetByteContext *gb) +static int decode_registered_user_data_afd(H2645SEIAFD *h, GetByteContext *gb) { int flag; @@ -157,13 +157,10 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, user_identifier = bytestream2_get_be32u(gb); switch (user_identifier) { case MKBETAG('D', 'T', 'G', '1'): // afd_data - if (!IS_H264(codec_id)) - goto unsupported; return decode_registered_user_data_afd(&h->afd, gb); case MKBETAG('G', 'A', '9', '4'): // closed captions return decode_registered_user_data_closed_caption(&h->a53_caption, gb); default: - unsupported: av_log(logctx, AV_LOG_VERBOSE, "Unsupported User Data Registered ITU-T T35 SEI message (atsc user_identifier = 0x%04x)\n", user_identifier); @@ -537,6 +534,16 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, } sei->unregistered.nb_buf_ref = 0; + if (sei->afd.present) { + AVFrameSideData *sd = av_frame_new_side_data(frame, AV_FRAME_DATA_AFD, + sizeof(uint8_t)); + + if (sd) { + *sd->data = sei->afd.active_format_description; + sei->afd.present = 0; + } + } + return 0; } diff --git a/libavcodec/h2645_sei.h b/libavcodec/h2645_sei.h index 4713b89e1f..eb00107abb 100644 --- a/libavcodec/h2645_sei.h +++ b/libavcodec/h2645_sei.h @@ -34,10 +34,10 @@ typedef struct H2645SEIA53Caption { AVBufferRef *buf_ref; } H2645SEIA53Caption; -typedef struct H264SEIAFD { +typedef struct H2645SEIAFD { int present; uint8_t active_format_description; -} H264SEIAFD; +} H2645SEIAFD; typedef struct HEVCSEIDynamicHDRPlus { AVBufferRef *info; @@ -99,7 +99,7 @@ typedef struct H2645SEIFilmGrainCharacteristics { typedef struct H2645SEI { H2645SEIA53Caption a53_caption; - H264SEIAFD afd; //< H.264 only + H2645SEIAFD afd; HEVCSEIDynamicHDRPlus dynamic_hdr_plus; //< HEVC only HEVCSEIDynamicHDRVivid dynamic_hdr_vivid; //< HEVC only H2645SEIUnregistered unregistered; diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 0ebd77c341..02f647dfe0 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1226,16 +1226,6 @@ static int h264_export_frame_props(H264Context *h) } } - if (h->sei.common.afd.present) { - AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_AFD, - sizeof(uint8_t)); - - if (sd) { - *sd->data = h->sei.common.afd.active_format_description; - h->sei.common.afd.present = 0; - } - } - ret = ff_h2645_sei_to_frame(out, &h->sei.common, AV_CODEC_ID_H264, h->avctx); if (ret < 0) return ret; diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak index 6c1e7447ad..20c2e5ba9c 100644 --- a/tests/fate/hevc.mak +++ b/tests/fate/hevc.mak @@ -237,6 +237,9 @@ FATE_HEVC_FFPROBE-$(call DEMDEC, HEVC, HEVC) += fate-hevc-paired-fields fate-hevc-monochrome-crop: CMD = probeframes -show_entries frame=width,height:stream=width,height $(TARGET_SAMPLES)/hevc/hevc-monochrome.hevc FATE_HEVC_FFPROBE-$(call PARSERDEMDEC, HEVC, HEVC, HEVC) += fate-hevc-monochrome-crop +fate-hevc-afd-tc-sei: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -bitexact -show_entries frame_side_data_list -select_streams v $(TARGET_SAMPLES)/mpegts/loewe.ts +FATE_HEVC_FFPROBE-$(call PARSERDEMDEC, HEVC, HEVC, HEVC) += fate-hevc-afd-tc-sei + fate-hevc-hdr10-plus-metadata: CMD = probeframes -show_entries frame=side_data_list $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc FATE_HEVC_FFPROBE-$(call DEMDEC, HEVC, HEVC) += fate-hevc-hdr10-plus-metadata diff --git a/tests/ref/fate/hevc-afd-tc-sei b/tests/ref/fate/hevc-afd-tc-sei new file mode 100644 index 0000000000..27eb3fc8d7 --- /dev/null +++ b/tests/ref/fate/hevc-afd-tc-sei @@ -0,0 +1,204 @@ +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME] +[FRAME] +[SIDE_DATA] +side_data_type=Active format description +active_format=8 +[/SIDE_DATA] +[SIDE_DATA] +side_data_type=SMPTE 12-1 timecode +[TIMECODE] +value=00:00:00:00 +[/TIMECODE] +[/SIDE_DATA] +[/FRAME]