[FFmpeg-cvslog] avcodec/aacdec_common: Avoid superfluous VLC structures for SBR VLCs

Andreas Rheinhardt git at videolan.org
Tue Oct 31 23:19:52 EET 2023


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Sep 25 00:54:01 2023 +0200| [0b4e69cc87a01b92788b63e423620a5dfdf88f4b] | committer: Andreas Rheinhardt

avcodec/aacdec_common: Avoid superfluous VLC structures for SBR VLCs

For all VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0b4e69cc87a01b92788b63e423620a5dfdf88f4b
---

 libavcodec/aacdec_common.c   | 35 +++++++++++++++++++----------------
 libavcodec/aacdectab.h       |  2 +-
 libavcodec/aacsbr_template.c | 24 ++++++++++++------------
 3 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index cbd2a9ccd2..295ea87dce 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -352,15 +352,16 @@ static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = {
     0xff,
 };
 
-VLC ff_aac_sbr_vlc[10];
+const VLCElem *ff_aac_sbr_vlc[10];
 
 static av_cold void aacdec_common_init(void)
 {
-#define SBR_INIT_VLC_STATIC(num, size) \
-    VLC_INIT_STATIC(&ff_aac_sbr_vlc[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size,     \
+#define SBR_INIT_VLC_STATIC(num) \
+    ff_aac_sbr_vlc[num] = \
+        ff_vlc_init_tables_sparse(&state, 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size,     \
                     sbr_tmp[num].sbr_bits ,                      1,                      1, \
                     sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \
-                    size)
+                    NULL, 0, 0, 0)
 #define SBR_VLC_ROW(name) \
     { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
     static const struct {
@@ -379,8 +380,10 @@ static av_cold void aacdec_common_init(void)
         SBR_VLC_ROW(t_huffman_noise_bal_3_0dB),
     };
 
-    static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 +
-                           294 + 306 + 268 + 510 + 366 + 462];
+    static VLCElem vlc_buf[(304 + 270 + 550 + 300 + 328 +
+                            294 + 306 + 268 + 510 + 366 + 462) +
+                           (1098 + 1092 + 768 + 1026 + 1058 +
+                            1052 +  544 + 544 +  592 + 512)];
     VLCInitState state = VLC_INIT_STATE(vlc_buf);
 
     for (unsigned i = 0; i < 11; i++) {
@@ -403,16 +406,16 @@ static av_cold void aacdec_common_init(void)
                           sizeof(ff_aac_scalefactor_code[0]), 0);
 
     // SBR VLC table initialization
-    SBR_INIT_VLC_STATIC(0, 1098);
-    SBR_INIT_VLC_STATIC(1, 1092);
-    SBR_INIT_VLC_STATIC(2, 768);
-    SBR_INIT_VLC_STATIC(3, 1026);
-    SBR_INIT_VLC_STATIC(4, 1058);
-    SBR_INIT_VLC_STATIC(5, 1052);
-    SBR_INIT_VLC_STATIC(6, 544);
-    SBR_INIT_VLC_STATIC(7, 544);
-    SBR_INIT_VLC_STATIC(8, 592);
-    SBR_INIT_VLC_STATIC(9, 512);
+    SBR_INIT_VLC_STATIC(0);
+    SBR_INIT_VLC_STATIC(1);
+    SBR_INIT_VLC_STATIC(2);
+    SBR_INIT_VLC_STATIC(3);
+    SBR_INIT_VLC_STATIC(4);
+    SBR_INIT_VLC_STATIC(5);
+    SBR_INIT_VLC_STATIC(6);
+    SBR_INIT_VLC_STATIC(7);
+    SBR_INIT_VLC_STATIC(8);
+    SBR_INIT_VLC_STATIC(9);
 }
 
 av_cold void ff_aacdec_common_init_once(void)
diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h
index 02e0d8a48e..7079b061fc 100644
--- a/libavcodec/aacdectab.h
+++ b/libavcodec/aacdectab.h
@@ -38,7 +38,7 @@
 FF_VISIBILITY_PUSH_HIDDEN
 void ff_aacdec_common_init_once(void);
 
-extern VLC ff_aac_sbr_vlc[10];
+extern const VLCElem *ff_aac_sbr_vlc[10];
 
 extern VLCElem ff_vlc_scalefactors[];
 extern const VLCElem *ff_vlc_spectral[11];
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index 26be2739d3..a82be8a8d5 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -811,29 +811,29 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
     if (sbr->bs_coupling && ch) {
         if (ch_data->bs_amp_res) {
             bits   = 5;
-            t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_3_0DB].table;
+            t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_3_0DB];
             t_lav  = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB];
-            f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB].table;
+            f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB];
             f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
         } else {
             bits   = 6;
-            t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_1_5DB].table;
+            t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_1_5DB];
             t_lav  = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB];
-            f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_1_5DB].table;
+            f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_1_5DB];
             f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB];
         }
     } else {
         if (ch_data->bs_amp_res) {
             bits   = 6;
-            t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_3_0DB].table;
+            t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_3_0DB];
             t_lav  = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB];
-            f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB].table;
+            f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB];
             f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
         } else {
             bits   = 7;
-            t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_1_5DB].table;
+            t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_1_5DB];
             t_lav  = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB];
-            f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_1_5DB].table;
+            f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_1_5DB];
             f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB];
         }
     }
@@ -896,14 +896,14 @@ static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitCo
     int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
 
     if (sbr->bs_coupling && ch) {
-        t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_BAL_3_0DB].table;
+        t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_BAL_3_0DB];
         t_lav  = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB];
-        f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB].table;
+        f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB];
         f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
     } else {
-        t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_3_0DB].table;
+        t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_3_0DB];
         t_lav  = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB];
-        f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB].table;
+        f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB];
         f_lav  = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
     }
 



More information about the ffmpeg-cvslog mailing list