Sep 12, 2023, 08:14 by d...@lynne.ee:

> As it happens, there's no standard between startup delay for SBR between
> decoders either. libfdkaac uses 5056 samples, but Apple's encoder (via 
> afconvert)
> uses 3136.
>
> Currently, this only fixes libfdk-aac. Would like to have more samples from 
> more
> encoders so I can fix all known cases.
>

Wrong patch attached.

>From c0e5659e5a2d56e883f9e1bb8c6d5bca1059721a Mon Sep 17 00:00:00 2001
From: Lynne <d...@lynne.ee>
Date: Tue, 12 Sep 2023 08:06:40 +0200
Subject: [PATCH 3/3] aacdec: allow to skip sbr start-up delay

---
 libavcodec/aac.h             |  1 +
 libavcodec/aacdec_template.c | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index 285d3b7482..3f67f353b7 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -298,6 +298,7 @@ struct AACContext {
     AVCodecContext *avctx;
     AVFrame *frame;
 
+    int sbr_state_changed;
     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 0e4a274fea..b6c6d19f61 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1207,6 +1207,8 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
                                                 avctx->extradata_size * 8LL,
                                                 1)) < 0)
             return ret;
+
+        ac->sbr_state_changed = ac->oc[1].m4ac.sbr == 1;
     } else {
         int sr, i;
         uint8_t layout_map[MAX_ELEM_ID*4][3];
@@ -3154,6 +3156,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, AVFrame *frame,
     int is_dmono, sce_count = 0;
     int payload_alignment;
     uint8_t che_presence[4][MAX_ELEM_ID] = {{0}};
+    int sbr_state_start = ac->oc[1].m4ac.sbr;
 
     ac->frame = frame;
 
@@ -3346,6 +3349,14 @@ static int aac_decode_frame_int(AVCodecContext *avctx, AVFrame *frame,
             frame->data[0] = frame->data[1];
     }
 
+    ac->sbr_state_changed |= (ac->oc[1].m4ac.sbr != sbr_state_start) && (ac->oc[1].m4ac.sbr == 1);
+
+    if (ac->sbr_state_changed) {
+        avctx->internal->skip_samples = 5056;
+        avctx->internal->skip_samples_add = 1;
+        ac->sbr_state_changed = 0;
+    }
+
     return 0;
 fail:
     pop_output_configuration(ac);
-- 
2.40.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to