diff mbox series

[FFmpeg-devel,54/61] avcodec/aacps_common: Switch to ff_vlc_init_tables_from_lengths()

Message ID GV1P250MB0737C583F586A6457DEC64748FC3A@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 774611a349f687ba2cd26cc1e3c11eaa38aab484
Headers show
Series [FFmpeg-devel,01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC | expand

Commit Message

Andreas Rheinhardt Sept. 26, 2023, 10:17 p.m. UTC
It allows to replace codes of type uint16_t or uint32_t
by symbols of type uint8_t.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/aacps_common.c |  28 ++----
 libavcodec/aacpsdata.c    | 204 +++++++++++++++++---------------------
 2 files changed, 102 insertions(+), 130 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/aacps_common.c b/libavcodec/aacps_common.c
index 281eaa12e7..653fc38da3 100644
--- a/libavcodec/aacps_common.c
+++ b/libavcodec/aacps_common.c
@@ -288,13 +288,8 @@  err:
     return bits_left;
 }
 
-#define PS_INIT_VLC_STATIC(num, nb_bits, size)                          \
-    vlc_ps[num] = ff_vlc_init_tables(&state, nb_bits, ps_tmp[num].table_size / ps_tmp[num].elem_size,    \
-                                     ps_tmp[num].ps_bits, 1, 1,                                          \
-                                     ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, 0);
-
 #define PS_VLC_ROW(name) \
-    { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
+    { name ## _tab, FF_ARRAY_ELEMS(name ## _tab) }
 
 av_cold void ff_ps_init_common(void)
 {
@@ -303,8 +298,8 @@  av_cold void ff_ps_init_common(void)
     VLCInitState state = VLC_INIT_STATE(vlc_buf);
     // Syntax initialization
     static const struct {
-        const void *ps_codes, *ps_bits;
-        const unsigned int table_size, elem_size;
+        const uint8_t (*vlc_tab)[2];
+        const unsigned int table_elems;
     } ps_tmp[] = {
         PS_VLC_ROW(huff_iid_df1),
         PS_VLC_ROW(huff_iid_dt1),
@@ -318,14 +313,11 @@  av_cold void ff_ps_init_common(void)
         PS_VLC_ROW(huff_opd_dt),
     };
 
-    PS_INIT_VLC_STATIC(0, 9, 1544);
-    PS_INIT_VLC_STATIC(1, 9,  832);
-    PS_INIT_VLC_STATIC(2, 9, 1024);
-    PS_INIT_VLC_STATIC(3, 9, 1036);
-    PS_INIT_VLC_STATIC(4, 9,  544);
-    PS_INIT_VLC_STATIC(5, 9,  544);
-    PS_INIT_VLC_STATIC(6, 5,   32);
-    PS_INIT_VLC_STATIC(7, 5,   32);
-    PS_INIT_VLC_STATIC(8, 5,   32);
-    PS_INIT_VLC_STATIC(9, 5,   32);
+    for (int i = 0; i < FF_ARRAY_ELEMS(vlc_ps); i++) {
+        vlc_ps[i] =
+            ff_vlc_init_tables_from_lengths(&state, i <= 5 ? 9 : 5, ps_tmp[i].table_elems,
+                                            &ps_tmp[i].vlc_tab[0][1], 2,
+                                            &ps_tmp[i].vlc_tab[0][0], 2, 1,
+                                            0, 0);
+    }
 }
diff --git a/libavcodec/aacpsdata.c b/libavcodec/aacpsdata.c
index 7a1f490060..8241346b0d 100644
--- a/libavcodec/aacpsdata.c
+++ b/libavcodec/aacpsdata.c
@@ -19,118 +19,98 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-static const uint8_t huff_iid_df1_bits[] = {
-    18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 16, 16, 15, 14, 14,
-    13, 12, 12, 11, 10, 10,  8,  7,  6,  5,  4,  3,  1,  3,  4,  5,  6,  7,
-     8,  9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16, 17, 17, 18, 17, 18, 18,
-    18, 18, 18, 18, 18, 18, 18,
-};
-
-static const uint32_t huff_iid_df1_codes[] = {
-    0x01FEB4, 0x01FEB5, 0x01FD76, 0x01FD77, 0x01FD74, 0x01FD75, 0x01FE8A,
-    0x01FE8B, 0x01FE88, 0x00FE80, 0x01FEB6, 0x00FE82, 0x00FEB8, 0x007F42,
-    0x007FAE, 0x003FAF, 0x001FD1, 0x001FE9, 0x000FE9, 0x0007EA, 0x0007FB,
-    0x0003FB, 0x0001FB, 0x0001FF, 0x00007C, 0x00003C, 0x00001C, 0x00000C,
-    0x000000, 0x000001, 0x000001, 0x000002, 0x000001, 0x00000D, 0x00001D,
-    0x00003D, 0x00007D, 0x0000FC, 0x0001FC, 0x0003FC, 0x0003F4, 0x0007EB,
-    0x000FEA, 0x001FEA, 0x001FD6, 0x003FD0, 0x007FAF, 0x007F43, 0x00FEB9,
-    0x00FE83, 0x01FEB7, 0x00FE81, 0x01FE89, 0x01FE8E, 0x01FE8F, 0x01FE8C,
-    0x01FE8D, 0x01FEB2, 0x01FEB3, 0x01FEB0, 0x01FEB1,
-};
-
-static const uint8_t huff_iid_dt1_bits[] = {
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 13,
-    13, 13, 12, 12, 11, 10,  9,  9,  7,  6,  5,  3,  1,  2,  5,  6,  7,  8,
-     9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16,
-};
-
-static const uint16_t huff_iid_dt1_codes[] = {
-    0x004ED4, 0x004ED5, 0x004ECE, 0x004ECF, 0x004ECC, 0x004ED6, 0x004ED8,
-    0x004F46, 0x004F60, 0x002718, 0x002719, 0x002764, 0x002765, 0x00276D,
-    0x0027B1, 0x0013B7, 0x0013D6, 0x0009C7, 0x0009E9, 0x0009ED, 0x0004EE,
-    0x0004F7, 0x000278, 0x000139, 0x00009A, 0x00009F, 0x000020, 0x000011,
-    0x00000A, 0x000003, 0x000001, 0x000000, 0x00000B, 0x000012, 0x000021,
-    0x00004C, 0x00009B, 0x00013A, 0x000279, 0x000270, 0x0004EF, 0x0004E2,
-    0x0009EA, 0x0009D8, 0x0013D7, 0x0013D0, 0x0027B2, 0x0027A2, 0x00271A,
-    0x00271B, 0x004F66, 0x004F67, 0x004F61, 0x004F47, 0x004ED9, 0x004ED7,
-    0x004ECD, 0x004ED2, 0x004ED3, 0x004ED0, 0x004ED1,
-};
-
-static const uint8_t huff_iid_df0_bits[] = {
-    17, 17, 17, 17, 16, 15, 13, 10,  9,  7,  6,  5,  4,  3,  1,  3,  4,  5,
-     6,  6,  8, 11, 13, 14, 14, 15, 17, 18, 18,
-};
-
-static const uint32_t huff_iid_df0_codes[] = {
-    0x01FFFB, 0x01FFFC, 0x01FFFD, 0x01FFFA, 0x00FFFC, 0x007FFC, 0x001FFD,
-    0x0003FE, 0x0001FE, 0x00007E, 0x00003C, 0x00001D, 0x00000D, 0x000005,
-    0x000000, 0x000004, 0x00000C, 0x00001C, 0x00003D, 0x00003E, 0x0000FE,
-    0x0007FE, 0x001FFC, 0x003FFC, 0x003FFD, 0x007FFD, 0x01FFFE, 0x03FFFE,
-    0x03FFFF,
-};
-
-static const uint8_t huff_iid_dt0_bits[] = {
-    19, 19, 19, 20, 20, 20, 17, 15, 12, 10,  8,  6,  4,  2,  1,  3,  5,  7,
-     9, 11, 13, 14, 17, 19, 20, 20, 20, 20, 20,
-};
-
-static const uint32_t huff_iid_dt0_codes[] = {
-    0x07FFF9, 0x07FFFA, 0x07FFFB, 0x0FFFF8, 0x0FFFF9, 0x0FFFFA, 0x01FFFD,
-    0x007FFE, 0x000FFE, 0x0003FE, 0x0000FE, 0x00003E, 0x00000E, 0x000002,
-    0x000000, 0x000006, 0x00001E, 0x00007E, 0x0001FE, 0x0007FE, 0x001FFE,
-    0x003FFE, 0x01FFFC, 0x07FFF8, 0x0FFFFB, 0x0FFFFC, 0x0FFFFD, 0x0FFFFE,
-    0x0FFFFF,
-};
-
-static const uint8_t huff_icc_df_bits[] = {
-    14, 14, 12, 10, 7, 5, 3, 1, 2, 4, 6, 8, 9, 11, 13,
-};
-
-static const uint16_t huff_icc_df_codes[] = {
-    0x3FFF, 0x3FFE, 0x0FFE, 0x03FE, 0x007E, 0x001E, 0x0006, 0x0000,
-    0x0002, 0x000E, 0x003E, 0x00FE, 0x01FE, 0x07FE, 0x1FFE,
-};
-
-static const uint8_t huff_icc_dt_bits[] = {
-    14, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14,
-};
-
-static const uint16_t huff_icc_dt_codes[] = {
-    0x3FFE, 0x1FFE, 0x07FE, 0x01FE, 0x007E, 0x001E, 0x0006, 0x0000,
-    0x0002, 0x000E, 0x003E, 0x00FE, 0x03FE, 0x0FFE, 0x3FFF,
-};
-
-static const uint8_t huff_ipd_df_bits[] = {
-    1, 3, 4, 4, 4, 4, 4, 4,
-};
-
-static const uint8_t huff_ipd_df_codes[] = {
-    0x01, 0x00, 0x06, 0x04, 0x02, 0x03, 0x05, 0x07,
-};
-
-static const uint8_t huff_ipd_dt_bits[] = {
-    1, 3, 4, 5, 5, 4, 4, 3,
-};
-
-static const uint8_t huff_ipd_dt_codes[] = {
-    0x01, 0x02, 0x02, 0x03, 0x02, 0x00, 0x03, 0x03,
-};
-
-static const uint8_t huff_opd_df_bits[] = {
-    1, 3, 4, 4, 5, 5, 4, 3,
-};
-
-static const uint8_t huff_opd_df_codes[] = {
-    0x01, 0x01, 0x06, 0x04, 0x0F, 0x0E, 0x05, 0x00,
-};
-
-static const uint8_t huff_opd_dt_bits[] = {
-    1, 3, 4, 5, 5, 4, 4, 3,
-};
-
-static const uint8_t huff_opd_dt_codes[] = {
-    0x01, 0x02, 0x01, 0x07, 0x06, 0x00, 0x02, 0x03,
+#include <stdint.h>
+
+static const uint8_t huff_iid_df1_tab[][2] = {
+    /* huff_iid_df1 - 61 entries */
+    {  28,   4 }, {  32,   4 }, {  29,   3 }, {  31,   3 }, {  27,   5 },
+    {  33,   5 }, {  26,   6 }, {  34,   6 }, {  25,   7 }, {  35,   7 },
+    {  24,   8 }, {  36,   8 }, {  37,   9 }, {  40,  11 }, {  19,  12 },
+    {  41,  12 }, {  22,  10 }, {  38,  10 }, {   9,  17 }, {  51,  17 },
+    {  11,  17 }, {  49,  17 }, {  13,  16 }, {  47,  16 }, {  16,  14 },
+    {  18,  13 }, {  42,  13 }, {  44,  14 }, {  12,  17 }, {  48,  17 },
+    {   4,  18 }, {   5,  18 }, {   2,  18 }, {   3,  18 }, {  15,  15 },
+    {  21,  11 }, {  39,  11 }, {  45,  15 }, {   8,  18 }, {  52,  18 },
+    {   6,  18 }, {   7,  18 }, {  55,  18 }, {  56,  18 }, {  53,  18 },
+    {  54,  18 }, {  17,  14 }, {  43,  14 }, {  59,  18 }, {  60,  18 },
+    {  57,  18 }, {  58,  18 }, {   0,  18 }, {   1,  18 }, {  10,  18 },
+    {  50,  18 }, {  14,  16 }, {  46,  16 }, {  20,  12 }, {  23,  10 },
+    {  30,   1 },
+};
+
+static const uint8_t huff_iid_dt1_tab[][2] = {
+    /* huff_iid_dt1 - 61 entries */
+    {  31,   2 }, {  26,   7 }, {  34,   7 }, {  27,   6 }, {  33,   6 },
+    {  35,   8 }, {  24,   9 }, {  36,   9 }, {  39,  11 }, {  41,  12 },
+    {   9,  15 }, {  10,  15 }, {  48,  15 }, {  49,  15 }, {  17,  13 },
+    {  23,  10 }, {  37,  10 }, {  43,  13 }, {  11,  15 }, {  12,  15 },
+    {   4,  16 }, {  56,  16 }, {   2,  16 }, {   3,  16 }, {  59,  16 },
+    {  60,  16 }, {  57,  16 }, {  58,  16 }, {   0,  16 }, {   1,  16 },
+    {   5,  16 }, {  55,  16 }, {   6,  16 }, {  54,  16 }, {  13,  15 },
+    {  15,  14 }, {  20,  12 }, {  40,  12 }, {  22,  11 }, {  38,  11 },
+    {  45,  14 }, {  47,  15 }, {   7,  16 }, {  53,  16 }, {  18,  13 },
+    {  42,  13 }, {  16,  14 }, {  44,  14 }, {   8,  16 }, {  52,  16 },
+    {  14,  15 }, {  46,  15 }, {  50,  16 }, {  51,  16 }, {  19,  13 },
+    {  21,  12 }, {  25,   9 }, {  28,   5 }, {  32,   5 }, {  29,   3 },
+    {  30,   1 },
+};
+
+static const uint8_t huff_iid_df0_tab[][2] = {
+    /* huff_iid_df0 - 29 entries */
+    {  14,   1 }, {  15,   3 }, {  13,   3 }, {  16,   4 }, {  12,   4 },
+    {  17,   5 }, {  11,   5 }, {  10,   6 }, {  18,   6 }, {  19,   6 },
+    {   9,   7 }, {  20,   8 }, {   8,   9 }, {   7,  10 }, {  21,  11 },
+    {  22,  13 }, {   6,  13 }, {  23,  14 }, {  24,  14 }, {   5,  15 },
+    {  25,  15 }, {   4,  16 }, {   3,  17 }, {   0,  17 }, {   1,  17 },
+    {   2,  17 }, {  26,  17 }, {  27,  18 }, {  28,  18 },
+};
+
+static const uint8_t huff_iid_dt0_tab[][2] = {
+    /* huff_iid_dt0 - 29 entries */
+    {  14,   1 }, {  13,   2 }, {  15,   3 }, {  12,   4 }, {  16,   5 },
+    {  11,   6 }, {  17,   7 }, {  10,   8 }, {  18,   9 }, {   9,  10 },
+    {  19,  11 }, {   8,  12 }, {  20,  13 }, {  21,  14 }, {   7,  15 },
+    {  22,  17 }, {   6,  17 }, {  23,  19 }, {   0,  19 }, {   1,  19 },
+    {   2,  19 }, {   3,  20 }, {   4,  20 }, {   5,  20 }, {  24,  20 },
+    {  25,  20 }, {  26,  20 }, {  27,  20 }, {  28,  20 },
+};
+
+static const uint8_t huff_icc_df_tab[][2] = {
+    /* huff_icc_df - 15 entries */
+    {   7,   1 }, {   8,   2 }, {   6,   3 }, {   9,   4 }, {   5,   5 },
+    {  10,   6 }, {   4,   7 }, {  11,   8 }, {  12,   9 }, {   3,  10 },
+    {  13,  11 }, {   2,  12 }, {  14,  13 }, {   1,  14 }, {   0,  14 },
+};
+
+static const uint8_t huff_icc_dt_tab[][2] = {
+    /* huff_icc_dt - 15 entries */
+    {   7,   1 }, {   8,   2 }, {   6,   3 }, {   9,   4 }, {   5,   5 },
+    {  10,   6 }, {   4,   7 }, {  11,   8 }, {   3,   9 }, {  12,  10 },
+    {   2,  11 }, {  13,  12 }, {   1,  13 }, {   0,  14 }, {  14,  14 },
+};
+
+static const uint8_t huff_ipd_df_tab[][2] = {
+    /* huff_ipd_df - 8 entries */
+    {   1,   3 }, {   4,   4 }, {   5,   4 }, {   3,   4 }, {   6,   4 },
+    {   2,   4 }, {   7,   4 }, {   0,   1 },
+};
+
+static const uint8_t huff_ipd_dt_tab[][2] = {
+    /* huff_ipd_dt - 8 entries */
+    {   5,   4 }, {   4,   5 }, {   3,   5 }, {   2,   4 }, {   6,   4 },
+    {   1,   3 }, {   7,   3 }, {   0,   1 },
+};
+
+static const uint8_t huff_opd_df_tab[][2] = {
+    /* huff_opd_df - 8 entries */
+    {   7,   3 }, {   1,   3 }, {   3,   4 }, {   6,   4 }, {   2,   4 },
+    {   5,   5 }, {   4,   5 }, {   0,   1 },
+};
+
+static const uint8_t huff_opd_dt_tab[][2] = {
+    /* huff_opd_dt - 8 entries */
+    {   5,   4 }, {   2,   4 }, {   6,   4 }, {   4,   5 }, {   3,   5 },
+    {   1,   3 }, {   7,   3 }, {   0,   1 },
 };
 
 static const int8_t huff_offset[] = {