Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Shulyaka via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Shulyaka <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] libavformat/spdifdec: Fix SPDIF detection score for EAC3 (PR #21019)
Date: Tue, 25 Nov 2025 19:45:33 -0000
Message-ID: <176409993361.39.10850863896577290677@2cb04c0e5124> (raw)

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 <denis.shulyaka@techno.holdings>
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 -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-11-25 19:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=176409993361.39.10850863896577290677@2cb04c0e5124 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /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