From: Lynne <dev@lynne.ee> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 2/2] aacdec: fix single-sample delay for SBR streams Date: Mon, 4 Dec 2023 08:52:06 +0100 (CET) Message-ID: <Nkno0wK--3-9@lynne.ee> (raw) In-Reply-To: <NknnrNO--3-9@lynne.ee-Nknnuzj----9> [-- Attachment #1: Type: text/plain, Size: 268 bytes --] Our SBR implementation introduces a single sample of latency into the output, which is currently never skipped. This delay is separate from any container skip value and always present, as it is from an additional part of the decoding process. Fixes Trac issue #9667 [-- Attachment #2: 0002-aacdec-fix-single-sample-delay-for-SBR-streams.patch --] [-- Type: text/x-diff, Size: 2778 bytes --] From 5b9d971b108677d54bc3aac317669007462dbcc9 Mon Sep 17 00:00:00 2001 From: Lynne <dev@lynne.ee> Date: Mon, 30 Oct 2023 05:40:22 +0100 Subject: [PATCH 2/2] aacdec: fix single-sample delay for SBR streams Our SBR implementation introduces a single sample of latency into the output, which is currently never skipped. This delay is separate from any container skip value and always present, as it is from an additional part of the decoding process. Fixes Trac issue #9667 --- libavcodec/aac.h | 1 + libavcodec/aacdec_template.c | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libavcodec/aac.h b/libavcodec/aac.h index 285d3b7482..06ae2222cf 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -298,6 +298,7 @@ struct AACContext { AVCodecContext *avctx; AVFrame *frame; + int skip_samples; int is_saved; ///< Set if elements have stored overlap from previous frame. DynamicRangeControl che_drc; diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 2b3509c85f..a82cd69a60 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -529,6 +529,8 @@ static void flush(AVCodecContext *avctx) } } } + + ac->skip_samples = 1; } /** @@ -1222,6 +1224,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } + ac->skip_samples = 1; ac->random_state = 0x1f2e3d4c; #define MDCT_INIT(s, fn, len, sval) \ @@ -2390,7 +2393,7 @@ static int decode_dynamic_range(DynamicRangeControl *che_drc, static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { uint8_t buf[256]; - int i, major, minor; + int i; if (len < 13+7*8) goto unknown; @@ -2404,10 +2407,6 @@ static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { if (ac->avctx->debug & FF_DEBUG_PICT_INFO) av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf); - if (sscanf(buf, "libfaac %d.%d", &major, &minor) == 2){ - ac->avctx->internal->skip_samples = 1024; - } - unknown: skip_bits_long(gb, len); @@ -3374,6 +3373,20 @@ static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, if (buf[buf_offset]) break; + if (ac->skip_samples) { + int skip = 0; + + /* Our SBR implementation introduces a sample of delay into the output. */ + if (ac->oc[1].m4ac.sbr) + skip = 1; + + err = ff_decode_skip_samples(avctx, frame, skip); + if (err < 0) + return err; + + ac->skip_samples = 0; + } + return buf_size > buf_offset ? buf_consumed : buf_size; } -- 2.43.0 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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 prev parent reply other threads:[~2023-12-04 7:52 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-04 7:51 [FFmpeg-devel] [PATCH 1/2] decode: add ff_decode_skip_samples function Lynne [not found] ` <NknnrNO--3-9@lynne.ee-Nknnuzj----9> 2023-12-04 7:52 ` Lynne [this message] 2023-12-05 1:47 ` [FFmpeg-devel] [PATCH 2/2] aacdec: fix single-sample delay for SBR streams Michael Niedermayer
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=Nkno0wK--3-9@lynne.ee \ --to=dev@lynne.ee \ --cc=ffmpeg-devel@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