PR #21019 opened by Shulyaka URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21019 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21019.patch
When EAC3 spdif decoding support was added in d3538dd293125e0a8d135ffe229c8b441345d833, the `SPDIF_MAX_OFFSET` was not increased. Also, the spdif is based on blocks with fixed length, each block starts with a sync word. It matters how many sync words we find during probe and whether we find them in expected place. The `SPDIF_MAX_OFFSET` constant is the maximum supported block size. When we find a sync word, we shift the upper boundary of the search area (`probe_end`) by `SPDIF_MAX_OFFSET`, however __this boundary is exclusive (the condition in the loop is "strictly less")__, and when the actual block size matches the max supported block size, then the second sync word appears to be outside of the search area by 1 byte. As a result, we find only one sync word and return an incorrect score (`AVPROBE_SCORE_EXTENSION / 4` instead of `AVPROBE_SCORE_MAX`). The fix increases the `SPDIF_MAX_OFFSET` and gives 1 more byte to the search area to allow finding the subsequent sync word. The existing `fate-spdif-eac3-remux` test passes successfully. >From 9f2e5c7cf8e33f42a33dbaa6943beab3d2514e46 Mon Sep 17 00:00:00 2001 From: Denis Shulyaka <[email protected]> Date: Tue, 25 Nov 2025 22:32:24 +0300 Subject: [PATCH] avformat/spdifdec: Increase max probe offset --- libavformat/spdifdec.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c index dcfe471f45..8287c19ad3 100644 --- a/libavformat/spdifdec.c +++ b/libavformat/spdifdec.c @@ -109,9 +109,8 @@ static int spdif_get_offset_and_codec(AVFormatContext *s, return 0; } -/* Largest offset between bursts we currently handle, i.e. AAC with - samples = 4096 */ -#define SPDIF_MAX_OFFSET 16384 +/* Largest offset between bursts we currently handle, i.e. E-AC-3 */ +#define SPDIF_MAX_OFFSET 24576 static int spdif_probe(const AVProbeData *p) { @@ -122,7 +121,7 @@ static int spdif_probe(const AVProbeData *p) int ff_spdif_probe(const uint8_t *p_buf, int buf_size, enum AVCodecID *codec) { const uint8_t *buf = p_buf; - const uint8_t *probe_end = p_buf + FFMIN(2 * SPDIF_MAX_OFFSET, buf_size - 1); + const uint8_t *probe_end = p_buf + FFMIN(2 * SPDIF_MAX_OFFSET + 1, buf_size - 1); const uint8_t *expected_code = buf + 7; uint32_t state = 0; int sync_codes = 0; @@ -146,7 +145,7 @@ int ff_spdif_probe(const uint8_t *p_buf, int buf_size, enum AVCodecID *codec) break; /* continue probing to find more sync codes */ - probe_end = FFMIN(buf + SPDIF_MAX_OFFSET, p_buf + buf_size - 1); + probe_end = FFMIN(buf + SPDIF_MAX_OFFSET + 1, p_buf + buf_size - 1); /* skip directly to the next sync code */ if (!spdif_get_offset_and_codec(NULL, (buf[2] << 8) | buf[1], @@ -234,10 +233,7 @@ int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt) } st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = codec_id; - if (codec_id == AV_CODEC_ID_EAC3) - ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; - else - ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; + ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS; } else if (codec_id != s->streams[0]->codecpar->codec_id) { avpriv_report_missing_feature(s, "Codec change in IEC 61937"); return AVERROR_PATCHWELCOME; -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
