From: Maryla Ustarroz-Calonge via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Maryla Ustarroz-Calonge <maryla@google.com> Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/libdav1d: move itut-t35 parsing to a separate function Date: Tue, 5 Aug 2025 12:12:39 +0200 Message-ID: <20250805101241.947452-1-maryla@google.com> (raw) This is in preparation to change the switch statement to if/else. Signed-off-by: Maryla Ustarroz-Calonge <maryla@google.com> --- libavcodec/libdav1d.c | 165 ++++++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 77 deletions(-) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index f4cbc927b5..51cc8837b0 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -386,6 +386,91 @@ static int libdav1d_receive_frame_internal(AVCodecContext *c, Dav1dPicture *p) return res; } +static int parse_itut_t35_metadata(Libdav1dContext *dav1d, Dav1dPicture *p, + const Dav1dITUTT35 *itut_t35, AVCodecContext *c, + AVFrame *frame) { + GetByteContext gb; + int provider_code; + int res; + + bytestream2_init(&gb, itut_t35->payload, itut_t35->payload_size); + + provider_code = bytestream2_get_be16(&gb); + switch (provider_code) { + case ITU_T_T35_PROVIDER_CODE_ATSC: { + uint32_t user_identifier = bytestream2_get_be32(&gb); + switch (user_identifier) { + case MKBETAG('G', 'A', '9', '4'): { // closed captions + AVBufferRef *buf = NULL; + + res = ff_parse_a53_cc(&buf, gb.buffer, bytestream2_get_bytes_left(&gb)); + if (res < 0) + return res; + if (!res) + break; + + res = ff_frame_new_side_data_from_buf(c, frame, AV_FRAME_DATA_A53_CC, &buf); + if (res < 0) + return res; + +#if FF_API_CODEC_PROPS +FF_DISABLE_DEPRECATION_WARNINGS + c->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + break; + } + default: // ignore unsupported identifiers + break; + } + break; + } + case ITU_T_T35_PROVIDER_CODE_SMTPE: { + AVDynamicHDRPlus *hdrplus; + int provider_oriented_code = bytestream2_get_be16(&gb); + int application_identifier = bytestream2_get_byte(&gb); + + if (itut_t35->country_code != ITU_T_T35_COUNTRY_CODE_US || + provider_oriented_code != 1 || application_identifier != 4) + break; + + hdrplus = av_dynamic_hdr_plus_create_side_data(frame); + if (!hdrplus) { + res = AVERROR(ENOMEM); + return res; + } + + res = av_dynamic_hdr_plus_from_t35(hdrplus, gb.buffer, + bytestream2_get_bytes_left(&gb)); + if (res < 0) + return res; + break; + } + case ITU_T_T35_PROVIDER_CODE_DOLBY: { + int provider_oriented_code = bytestream2_get_be32(&gb); + if (itut_t35->country_code != ITU_T_T35_COUNTRY_CODE_US || + provider_oriented_code != 0x800) + break; + + res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, gb.buffer_end - gb.buffer, + c->err_recognition); + if (res < 0) { + av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n"); + break; // ignore + } + + res = ff_dovi_attach_side_data(&dav1d->dovi, frame); + if (res < 0) + return res; + break; + } + default: // ignore unsupported provider codes + break; + } + + return 0; +} + static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) { Libdav1dContext *dav1d = c->priv_data; @@ -514,83 +599,9 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) #else const Dav1dITUTT35 *itut_t35 = p->itut_t35; #endif - GetByteContext gb; - int provider_code; - - bytestream2_init(&gb, itut_t35->payload, itut_t35->payload_size); - - provider_code = bytestream2_get_be16(&gb); - switch (provider_code) { - case ITU_T_T35_PROVIDER_CODE_ATSC: { - uint32_t user_identifier = bytestream2_get_be32(&gb); - switch (user_identifier) { - case MKBETAG('G', 'A', '9', '4'): { // closed captions - AVBufferRef *buf = NULL; - - res = ff_parse_a53_cc(&buf, gb.buffer, bytestream2_get_bytes_left(&gb)); - if (res < 0) - goto fail; - if (!res) - break; - - res = ff_frame_new_side_data_from_buf(c, frame, AV_FRAME_DATA_A53_CC, &buf); - if (res < 0) - goto fail; - -#if FF_API_CODEC_PROPS -FF_DISABLE_DEPRECATION_WARNINGS - c->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; -FF_ENABLE_DEPRECATION_WARNINGS -#endif - break; - } - default: // ignore unsupported identifiers - break; - } - break; - } - case ITU_T_T35_PROVIDER_CODE_SMTPE: { - AVDynamicHDRPlus *hdrplus; - int provider_oriented_code = bytestream2_get_be16(&gb); - int application_identifier = bytestream2_get_byte(&gb); - - if (itut_t35->country_code != ITU_T_T35_COUNTRY_CODE_US || - provider_oriented_code != 1 || application_identifier != 4) - break; - - hdrplus = av_dynamic_hdr_plus_create_side_data(frame); - if (!hdrplus) { - res = AVERROR(ENOMEM); - goto fail; - } - - res = av_dynamic_hdr_plus_from_t35(hdrplus, gb.buffer, - bytestream2_get_bytes_left(&gb)); - if (res < 0) - goto fail; - break; - } - case ITU_T_T35_PROVIDER_CODE_DOLBY: { - int provider_oriented_code = bytestream2_get_be32(&gb); - if (itut_t35->country_code != ITU_T_T35_COUNTRY_CODE_US || - provider_oriented_code != 0x800) - break; - - res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, gb.buffer_end - gb.buffer, - c->err_recognition); - if (res < 0) { - av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n"); - break; // ignore - } - - res = ff_dovi_attach_side_data(&dav1d->dovi, frame); - if (res < 0) - goto fail; - break; - } - default: // ignore unsupported provider codes - break; - } + res = parse_itut_t35_metadata(dav1d, p, itut_t35, c, frame); + if (res < 0) + goto fail; #if FF_DAV1D_VERSION_AT_LEAST(6,9) } #endif -- 2.50.1.565.gc32cd1483b-goog _______________________________________________ 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".
next reply other threads:[~2025-08-05 10:12 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-08-05 10:12 Maryla Ustarroz-Calonge via ffmpeg-devel [this message] 2025-08-05 10:12 ` [FFmpeg-devel] [PATCH 2/3] avcodec/itut35: always check the provider code and country code together Maryla Ustarroz-Calonge via ffmpeg-devel 2025-08-05 10:12 ` [FFmpeg-devel] [PATCH 3/3] avcodec/itut35: rename some provider codes Maryla Ustarroz-Calonge via ffmpeg-devel
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250805101241.947452-1-maryla@google.com \ --to=ffmpeg-devel@ffmpeg.org \ --cc=maryla@google.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git