Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Lynne <dev@lynne.ee>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 2/2] aacdec: correctly skip padding at the start of frames and during seeking
Date: Mon, 30 Oct 2023 06:10:21 +0100 (CET)
Message-ID: <NhyzMEL--3-9@lynne.ee> (raw)
In-Reply-To: <Nhyz9MY--3-9@lynne.ee-NhyzDNG----9>

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]

Presently, our AAC decoder didn't skip any samples, unless the side data
contained skip information.

This uses the newly added ff_decoder_skip_samples function to skip samples
on two levels: base, and additional.
Base is the inherent decoder delay. Most containers already specify it,
hence it is overwritten in that case.
Additional is any extra samples that have to be skipped, in AAC's case,
it's the delay introduced by SBR.

Patch attached.


[-- Attachment #2: 0002-aacdec-correctly-skip-padding-at-the-start-of-frames.patch --]
[-- Type: text/x-diff, Size: 3029 bytes --]

From 82120460459cf90c330ff11fe0ccf4b954736b5c 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: correctly skip padding at the start of frames and
 during seeking

Presently, our AAC decoder didn't skip any samples, unless the side data
contained skip information.

This uses the newly added ff_decoder_skip_samples function to skip samples
on two levels: base, and additional.
Base is the inherent decoder delay. Most containers already specify it,
hence it is overwritten in that case.
Additional is any extra samples that have to be skipped, in AAC's case,
it's the delay introduced by SBR.
---
 libavcodec/aac.h             |  1 +
 libavcodec/aacdec_template.c | 24 +++++++++++++++++++-----
 2 files changed, 20 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 954399f86b..ab3037c0d5 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -532,6 +532,8 @@ static void flush(AVCodecContext *avctx)
             }
         }
     }
+
+    ac->skip_samples = 1;
 }
 
 /**
@@ -1251,6 +1253,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)                                            \
@@ -2419,7 +2422,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;
@@ -2433,10 +2436,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);
 
@@ -3403,6 +3402,21 @@ static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         if (buf[buf_offset])
             break;
 
+    if (ac->skip_samples) {
+        int additional = 0;
+
+        if (ac->oc[1].m4ac.sbr)
+            additional = 3010;
+
+        err = ff_decode_skip_samples(avctx, frame,
+                                     ac->oc[1].m4ac.frame_length_short ? 960 : 1024,
+                                     additional);
+        if (err < 0)
+            return err;
+
+        ac->skip_samples = 0;
+    }
+
     return buf_size > buf_offset ? buf_consumed : buf_size;
 }
 
-- 
2.42.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".

  parent reply	other threads:[~2023-10-30  5:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-30  5:09 [FFmpeg-devel] [PATCH 1/2] decode: add ff_decode_skip_samples function Lynne
     [not found] ` <Nhyz9MY--3-9@lynne.ee-NhyzDNG----9>
2023-10-30  5:10   ` Lynne [this message]
2023-10-30  7:38     ` [FFmpeg-devel] [PATCH 2/2] aacdec: correctly skip padding at the start of frames and during seeking Jean-Baptiste Kempf
     [not found]     ` <7e230234-7cc6-4c31-ae7b-fd86ef616f7a@betaapp.fastmail.com-NhzWMs9----9>
2023-10-30 17:03       ` Lynne
2023-11-04 10:41 ` [FFmpeg-devel] [PATCH 1/2] decode: add ff_decode_skip_samples function Anton Khirnov
2023-11-04 16:22 ` Derek Buitenhuis
2023-11-04 17:32   ` Derek Buitenhuis
2023-11-04 17:41   ` Michael Niedermayer
2023-11-04 20:33   ` Lynne
2023-11-04 23:02   ` Martin Storsjö
2023-11-04 23:27     ` Lynne

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=NhyzMEL--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