PR #22489 opened by James Almer (jamrial) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22489 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22489.patch
>From a22bbcbdb2aa0067592a4efe67ca195a4b6120b5 Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Thu, 12 Mar 2026 20:32:34 -0300 Subject: [PATCH 1/3] avcodec/h2645_sei: refactor decode_registered_user_data() A switch statement is better than a bunch of if elses. More so when at least two of them are for the same country code. Signed-off-by: James Almer <[email protected]> --- libavcodec/h2645_sei.c | 120 +++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 46 deletions(-) diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index f3ce3da9eb..798c17aa9f 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -161,7 +161,10 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, /* itu_t_t35_payload_byte follows */ provider_code = bytestream2_get_be16u(gb); - if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_ATSC) { + switch (country_code) { + case ITU_T_T35_COUNTRY_CODE_US: + switch (provider_code) { + case ITU_T_T35_PROVIDER_CODE_ATSC: { uint32_t user_identifier; if (bytestream2_get_bytes_left(gb) < 4) @@ -179,53 +182,15 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, user_identifier); break; } - } else if (country_code == ITU_T_T35_COUNTRY_CODE_UK && provider_code == ITU_T_T35_PROVIDER_CODE_VNOVA) { - if (bytestream2_get_bytes_left(gb) < 2) - return AVERROR_INVALIDDATA; - - bytestream2_skipu(gb, 1); // user_data_type_code - return decode_registered_user_data_lcevc(&h->lcevc, gb); - } + break; + } #if CONFIG_HEVC_SEI - else if (country_code == ITU_T_T35_COUNTRY_CODE_CN && provider_code == ITU_T_T35_PROVIDER_CODE_HDR_VIVID) { - const uint16_t cuva_provider_oriented_code = 0x0005; - uint16_t provider_oriented_code; - - if (!IS_HEVC(codec_id)) - goto unsupported_provider_code; - - if (bytestream2_get_bytes_left(gb) < 2) - return AVERROR_INVALIDDATA; - - provider_oriented_code = bytestream2_get_be16u(gb); - if (provider_oriented_code == cuva_provider_oriented_code) { - return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb); - } - } else if(country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_SAMSUNG) { - // A/341 Amendment - 2094-40 - const uint16_t smpte2094_40_provider_oriented_code = 0x0001; - const uint8_t smpte2094_40_application_identifier = 0x04; - uint16_t provider_oriented_code; - uint8_t application_identifier; - - if (!IS_HEVC(codec_id)) - goto unsupported_provider_code; - - if (bytestream2_get_bytes_left(gb) < 3) - return AVERROR_INVALIDDATA; - - provider_oriented_code = bytestream2_get_be16u(gb); - application_identifier = bytestream2_get_byteu(gb); - if (provider_oriented_code == smpte2094_40_provider_oriented_code && - application_identifier == smpte2094_40_application_identifier) { - return decode_registered_user_data_dynamic_hdr_plus(&h->dynamic_hdr_plus, gb); - } - } else if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_AOM) { + case ITU_T_T35_PROVIDER_CODE_AOM: { const uint16_t aom_grain_provider_oriented_code = 0x0001; uint16_t provider_oriented_code; if (!IS_HEVC(codec_id)) - goto unsupported_provider_code; + break; if (bytestream2_get_bytes_left(gb) < 2) return AVERROR_INVALIDDATA; @@ -236,14 +201,77 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, gb->buffer, bytestream2_get_bytes_left(gb)); } + break; + } + case ITU_T_T35_PROVIDER_CODE_SAMSUNG: { + // A/341 Amendment - 2094-40 + const uint16_t smpte2094_40_provider_oriented_code = 0x0001; + const uint8_t smpte2094_40_application_identifier = 0x04; + uint16_t provider_oriented_code; + uint8_t application_identifier; + + if (!IS_HEVC(codec_id)) + break; + + if (bytestream2_get_bytes_left(gb) < 3) + return AVERROR_INVALIDDATA; + + provider_oriented_code = bytestream2_get_be16u(gb); + application_identifier = bytestream2_get_byteu(gb); + if (provider_oriented_code == smpte2094_40_provider_oriented_code && + application_identifier == smpte2094_40_application_identifier) { + return decode_registered_user_data_dynamic_hdr_plus(&h->dynamic_hdr_plus, gb); + } + break; + } +#endif + default: + break; + } + break; + case ITU_T_T35_COUNTRY_CODE_UK: + switch (provider_code) { + case ITU_T_T35_PROVIDER_CODE_VNOVA: + if (bytestream2_get_bytes_left(gb) < 2) + return AVERROR_INVALIDDATA; + + bytestream2_skipu(gb, 1); // user_data_type_code + return decode_registered_user_data_lcevc(&h->lcevc, gb); + default: + break; + } + break; +#if CONFIG_HEVC_SEI + case ITU_T_T35_COUNTRY_CODE_CN: { + const uint16_t cuva_provider_oriented_code = 0x0005; + uint16_t provider_oriented_code; + + switch (provider_code) { + case ITU_T_T35_PROVIDER_CODE_HDR_VIVID: + if (!IS_HEVC(codec_id)) + break; + + if (bytestream2_get_bytes_left(gb) < 2) + return AVERROR_INVALIDDATA; + + provider_oriented_code = bytestream2_get_be16u(gb); + if (provider_oriented_code == cuva_provider_oriented_code) { + return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb); + } + break; + default: + break; + } + break; } #endif - else { - unsupported_provider_code: + default: + break; + } + av_log(logctx, AV_LOG_VERBOSE, "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d, provider_code = %d)\n", country_code, provider_code); - } return 0; } -- 2.52.0 >From 94a043353e744cdeb301f7763dca4d9717048f75 Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Thu, 12 Mar 2026 20:39:57 -0300 Subject: [PATCH 2/3] avcodec/h2645_sei: reindent after the previous change Signed-off-by: James Almer <[email protected]> --- libavcodec/h2645_sei.c | 114 ++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index 798c17aa9f..a6bdb8b817 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -165,63 +165,63 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, case ITU_T_T35_COUNTRY_CODE_US: switch (provider_code) { case ITU_T_T35_PROVIDER_CODE_ATSC: { - uint32_t user_identifier; + uint32_t user_identifier; - if (bytestream2_get_bytes_left(gb) < 4) - return AVERROR_INVALIDDATA; + if (bytestream2_get_bytes_left(gb) < 4) + return AVERROR_INVALIDDATA; - user_identifier = bytestream2_get_be32u(gb); - switch (user_identifier) { - case MKBETAG('D', 'T', 'G', '1'): // afd_data - 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: - av_log(logctx, AV_LOG_VERBOSE, - "Unsupported User Data Registered ITU-T T35 SEI message (atsc user_identifier = 0x%04x)\n", - user_identifier); - break; - } + user_identifier = bytestream2_get_be32u(gb); + switch (user_identifier) { + case MKBETAG('D', 'T', 'G', '1'): // afd_data + 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: + av_log(logctx, AV_LOG_VERBOSE, + "Unsupported User Data Registered ITU-T T35 SEI message (atsc user_identifier = 0x%04x)\n", + user_identifier); + break; + } break; } #if CONFIG_HEVC_SEI case ITU_T_T35_PROVIDER_CODE_AOM: { - const uint16_t aom_grain_provider_oriented_code = 0x0001; - uint16_t provider_oriented_code; + const uint16_t aom_grain_provider_oriented_code = 0x0001; + uint16_t provider_oriented_code; - if (!IS_HEVC(codec_id)) - break; + if (!IS_HEVC(codec_id)) + break; - if (bytestream2_get_bytes_left(gb) < 2) - return AVERROR_INVALIDDATA; + if (bytestream2_get_bytes_left(gb) < 2) + return AVERROR_INVALIDDATA; - provider_oriented_code = bytestream2_get_byteu(gb); - if (provider_oriented_code == aom_grain_provider_oriented_code) { - return ff_aom_parse_film_grain_sets(&h->aom_film_grain, - gb->buffer, - bytestream2_get_bytes_left(gb)); - } + provider_oriented_code = bytestream2_get_byteu(gb); + if (provider_oriented_code == aom_grain_provider_oriented_code) { + return ff_aom_parse_film_grain_sets(&h->aom_film_grain, + gb->buffer, + bytestream2_get_bytes_left(gb)); + } break; } case ITU_T_T35_PROVIDER_CODE_SAMSUNG: { - // A/341 Amendment - 2094-40 - const uint16_t smpte2094_40_provider_oriented_code = 0x0001; - const uint8_t smpte2094_40_application_identifier = 0x04; - uint16_t provider_oriented_code; - uint8_t application_identifier; + // A/341 Amendment - 2094-40 + const uint16_t smpte2094_40_provider_oriented_code = 0x0001; + const uint8_t smpte2094_40_application_identifier = 0x04; + uint16_t provider_oriented_code; + uint8_t application_identifier; - if (!IS_HEVC(codec_id)) - break; + if (!IS_HEVC(codec_id)) + break; - if (bytestream2_get_bytes_left(gb) < 3) - return AVERROR_INVALIDDATA; + if (bytestream2_get_bytes_left(gb) < 3) + return AVERROR_INVALIDDATA; - provider_oriented_code = bytestream2_get_be16u(gb); - application_identifier = bytestream2_get_byteu(gb); - if (provider_oriented_code == smpte2094_40_provider_oriented_code && - application_identifier == smpte2094_40_application_identifier) { - return decode_registered_user_data_dynamic_hdr_plus(&h->dynamic_hdr_plus, gb); - } + provider_oriented_code = bytestream2_get_be16u(gb); + application_identifier = bytestream2_get_byteu(gb); + if (provider_oriented_code == smpte2094_40_provider_oriented_code && + application_identifier == smpte2094_40_application_identifier) { + return decode_registered_user_data_dynamic_hdr_plus(&h->dynamic_hdr_plus, gb); + } break; } #endif @@ -232,11 +232,11 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, case ITU_T_T35_COUNTRY_CODE_UK: switch (provider_code) { case ITU_T_T35_PROVIDER_CODE_VNOVA: - if (bytestream2_get_bytes_left(gb) < 2) - return AVERROR_INVALIDDATA; + if (bytestream2_get_bytes_left(gb) < 2) + return AVERROR_INVALIDDATA; - bytestream2_skipu(gb, 1); // user_data_type_code - return decode_registered_user_data_lcevc(&h->lcevc, gb); + bytestream2_skipu(gb, 1); // user_data_type_code + return decode_registered_user_data_lcevc(&h->lcevc, gb); default: break; } @@ -248,16 +248,16 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, switch (provider_code) { case ITU_T_T35_PROVIDER_CODE_HDR_VIVID: - if (!IS_HEVC(codec_id)) - break; + if (!IS_HEVC(codec_id)) + break; - if (bytestream2_get_bytes_left(gb) < 2) - return AVERROR_INVALIDDATA; + if (bytestream2_get_bytes_left(gb) < 2) + return AVERROR_INVALIDDATA; - provider_oriented_code = bytestream2_get_be16u(gb); - if (provider_oriented_code == cuva_provider_oriented_code) { - return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb); - } + provider_oriented_code = bytestream2_get_be16u(gb); + if (provider_oriented_code == cuva_provider_oriented_code) { + return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb); + } break; default: break; @@ -269,9 +269,9 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, break; } - av_log(logctx, AV_LOG_VERBOSE, - "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d, provider_code = %d)\n", - country_code, provider_code); + av_log(logctx, AV_LOG_VERBOSE, + "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d, provider_code = %d)\n", + country_code, provider_code); return 0; } -- 2.52.0 >From ca14b4021a23ba154996ea9b27ea9d104568f7bb Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Thu, 12 Mar 2026 20:43:23 -0300 Subject: [PATCH 3/3] avcodec/h2645_sei: fix parsing payloads for UK country_code The correct syntax after country_code is: t35_uk_country_code_second_octet b(8) t35_uk_manufacturer_code_first_octet b(8) t35_uk_manufacturer_code_second_octet b(8) Signed-off-by: James Almer <[email protected]> --- libavcodec/h2645_sei.c | 12 ++++++++++-- libavcodec/itut35.h | 4 +--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index a6bdb8b817..332371e5c0 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -159,10 +159,11 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, } /* itu_t_t35_payload_byte follows */ - provider_code = bytestream2_get_be16u(gb); switch (country_code) { case ITU_T_T35_COUNTRY_CODE_US: + provider_code = bytestream2_get_be16u(gb); + switch (provider_code) { case ITU_T_T35_PROVIDER_CODE_ATSC: { uint32_t user_identifier; @@ -230,12 +231,17 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, } break; case ITU_T_T35_COUNTRY_CODE_UK: + bytestream2_skipu(gb, 1); // t35_uk_country_code_second_octet + if (bytestream2_get_bytes_left(gb) < 2) + return AVERROR_INVALIDDATA; + + provider_code = bytestream2_get_be16u(gb); + switch (provider_code) { case ITU_T_T35_PROVIDER_CODE_VNOVA: if (bytestream2_get_bytes_left(gb) < 2) return AVERROR_INVALIDDATA; - bytestream2_skipu(gb, 1); // user_data_type_code return decode_registered_user_data_lcevc(&h->lcevc, gb); default: break; @@ -246,6 +252,8 @@ static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, const uint16_t cuva_provider_oriented_code = 0x0005; uint16_t provider_oriented_code; + provider_code = bytestream2_get_be16u(gb); + switch (provider_code) { case ITU_T_T35_PROVIDER_CODE_HDR_VIVID: if (!IS_HEVC(codec_id)) diff --git a/libavcodec/itut35.h b/libavcodec/itut35.h index b8987d0b01..84ea86f3dd 100644 --- a/libavcodec/itut35.h +++ b/libavcodec/itut35.h @@ -30,10 +30,8 @@ // - CN providers #define ITU_T_T35_PROVIDER_CODE_HDR_VIVID 0x0004 // - UK providers -// V-Nova should be 0x5000 according to UK Register of Manufacturer Codes // https://www.cix.co.uk/~bpechey/H221/h221code.htm -// but FFmpeg has been using 0x0050 -#define ITU_T_T35_PROVIDER_CODE_VNOVA 0x0050 +#define ITU_T_T35_PROVIDER_CODE_VNOVA 0x5000 // - US providers #define ITU_T_T35_PROVIDER_CODE_ATSC 0x0031 #define ITU_T_T35_PROVIDER_CODE_DOLBY 0x003B -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
