Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Alicia Boya García via ffmpeg-devel" <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: "Alicia Boya García" <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] aacdec: Fix pitch corruption in files mistagged as downsampled SBR (PR #20672)
Date: Wed, 08 Oct 2025 18:06:43 -0000
Message-ID: <175994680365.65.16347088280398541930@bf249f23a2c8> (raw)

PR #20672 opened by Alicia Boya García (ntrrgc)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20672
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20672.patch

Once per audio frame ff_aac_sbr_apply() runs the following check to
determine whether the QMF synthesis should operate in downsampled mode:

int downsampled = ac->oc[1].m4ac.ext_sample_rate < sbr->sample_rate;

Normally, sbr->sample_rate is initialized when a EXT_SBR_DATA payload is
parsed. However, it is possible (and unfortunately, common) for a plain
AAC LC file to be wrongly marked as using downsampled SBR via explicit
signaling in DecoderSpecificConfiguration.

For such a bad file, sbr->sample_rate remains uninitialized as zero when
that code runs, causing downsampled to be set to false (which at 44100
Hz for the AAC LC stream, is an unsupported configuration) and the pitch
to be halved during QMF synthesis.

This patch detects when no SBR initialization has ocurred in the
payload, logs a warning and prevents any SBR processing in the frame.

Fixes https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20671


From 5579a18e4ff774de8820f76bed2692a59e36006b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alicia=20Boya=20Garc=C3=ADa?= <aboya@igalia.com>
Date: Wed, 8 Oct 2025 19:31:44 +0200
Subject: [PATCH] aacdec: Fix pitch corruption in files mistagged as
 downsampled SBR

Once per audio frame ff_aac_sbr_apply() runs the following check to
determine whether the QMF synthesis should operate in downsampled mode:

int downsampled = ac->oc[1].m4ac.ext_sample_rate < sbr->sample_rate;

Normally, sbr->sample_rate is initialized when a EXT_SBR_DATA payload is
parsed. However, it is possible (and unfortunately, common) for a plain
AAC LC file to be wrongly marked as using downsampled SBR via explicit
signaling in DecoderSpecificConfiguration.

For such a bad file, sbr->sample_rate remains uninitialized as zero when
that code runs, causing downsampled to be set to false (which at 44100
Hz for the AAC LC stream, is an unsupported configuration) and the pitch
to be halved during QMF synthesis.

This patch detects when no SBR initialization has ocurred in the
payload, logs a warning and prevents any SBR processing in the frame.

Fixes https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20671
---
 libavcodec/aac/aacdec.h      | 1 +
 libavcodec/aacsbr_template.c | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/libavcodec/aac/aacdec.h b/libavcodec/aac/aacdec.h
index b3763fdccc..f1ce21ff89 100644
--- a/libavcodec/aac/aacdec.h
+++ b/libavcodec/aac/aacdec.h
@@ -530,6 +530,7 @@ struct AACDecContext {
     unsigned warned_71_wide;
     int warned_gain_control;
     int warned_he_aac_mono;
+    int warned_sbr_signaled_but_missing;
 
     int is_fixed;
 };
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index 3c39da509d..21a78cf505 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -1680,6 +1680,14 @@ void AAC_RENAME(ff_aac_sbr_apply)(AACDecContext *ac, ChannelElement *che,
 {
     INTFLOAT *L = L_, *R = R_;
     SpectralBandReplication *sbr = get_sbr(che);
+    if (!sbr->sample_rate) {
+        if (!ac->warned_sbr_signaled_but_missing) {
+            av_log(ac->avctx, AV_LOG_WARNING, "Stream has explictly signaled "
+                "SBR but contains no EXT_SBR_DATA\n");
+            ac->warned_sbr_signaled_but_missing = 1;
+        }
+        return;
+    }
     int downsampled = ac->oc[1].m4ac.ext_sample_rate < sbr->sample_rate;
     int ch;
     int nch = (id_aac == TYPE_CPE) ? 2 : 1;
-- 
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-10-08 18:07 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=175994680365.65.16347088280398541930@bf249f23a2c8 \
    --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 http://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/ http://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