diff mbox series

[FFmpeg-devel,v2,128/162] avcodec/intrax8: Avoid code duplication when initializing VLCs

Message ID 20201120073327.820745-29-andreas.rheinhardt@gmail.com
State New
Headers show
Series VLC, esp. init_vlc patches
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 20, 2020, 7:32 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/intrax8.c | 46 ++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
index 2a93e5efd7..9a2984c15b 100644
--- a/libavcodec/intrax8.c
+++ b/libavcodec/intrax8.c
@@ -31,6 +31,8 @@ 
 #include "intrax8dsp.h"
 #include "mpegutils.h"
 
+#define VLC_BUFFER_SIZE 28150
+
 #define MAX_TABLE_DEPTH(table_bits, max_bits) \
     ((max_bits + table_bits - 1) / table_bits)
 
@@ -46,21 +48,27 @@  static VLC j_ac_vlc[2][2][8];  // [quant < 13], [intra / inter], [select]
 static VLC j_dc_vlc[2][8];     // [quant], [select]
 static VLC j_orient_vlc[2][4]; // [quant], [select]
 
+static av_cold void x8_init_vlc(VLC *vlc, int nb_bits, int nb_codes,
+                                int *offset, const uint16_t table[][2])
+{
+    static VLC_TYPE vlc_buf[VLC_BUFFER_SIZE][2];
+
+    vlc->table           = &vlc_buf[*offset];
+    vlc->table_allocated = VLC_BUFFER_SIZE - *offset;
+    init_vlc(vlc, nb_bits, nb_codes, &table[0][1], 4, 2,
+             &table[0][0], 4, 2, INIT_VLC_STATIC_OVERLONG);
+    *offset += vlc->table_size;
+}
+
 static av_cold void x8_vlc_init(void)
 {
     int i;
     int offset = 0;
 
-    static VLC_TYPE table[28150][2];
-
 // set ac tables
 #define init_ac_vlc(dst, src)                                                 \
     do {                                                                      \
-        dst.table           = &table[offset];                                 \
-        dst.table_allocated = FF_ARRAY_ELEMS(table) - offset;                 \
-        init_vlc(&dst, AC_VLC_BITS, 77, &src[1], 4, 2, &src[0], 4, 2,         \
-                 INIT_VLC_STATIC_OVERLONG);                                   \
-        offset             += dst.table_size;                                 \
+        x8_init_vlc(&dst, AC_VLC_BITS, 77, &offset, &src);                    \
     } while(0)
 
     for (i = 0; i < 8; i++) {
@@ -74,11 +82,7 @@  static av_cold void x8_vlc_init(void)
 // set dc tables
 #define init_dc_vlc(dst, src)                                                 \
     do {                                                                      \
-        dst.table           = &table[offset];                                 \
-        dst.table_allocated = FF_ARRAY_ELEMS(table) - offset;                 \
-        init_vlc(&dst, DC_VLC_BITS, 34, &src[1], 4, 2, &src[0], 4, 2,         \
-                 INIT_VLC_STATIC_OVERLONG);                                   \
-        offset             += dst.table_size;                                 \
+        x8_init_vlc(&dst, DC_VLC_BITS, 34, &offset, &src);                    \
     } while(0)
 
     for (i = 0; i < 8; i++) {
@@ -88,22 +92,14 @@  static av_cold void x8_vlc_init(void)
 #undef init_dc_vlc
 
 // set orient tables
-#define init_or_vlc(dst, src)                                                 \
-    do {                                                                      \
-        dst.table           = &table[offset];                                 \
-        dst.table_allocated = FF_ARRAY_ELEMS(table) - offset;                 \
-        init_vlc(&dst, OR_VLC_BITS, 12, &src[1], 4, 2, &src[0], 4, 2,         \
-                 INIT_VLC_STATIC_OVERLONG);                                   \
-        offset             += dst.table_size;                                 \
-    } while(0)
-
     for (i = 0; i < 2; i++)
-        init_or_vlc(j_orient_vlc[0][i], x8_orient_highquant_table[i][0]);
+        x8_init_vlc(&j_orient_vlc[0][i], OR_VLC_BITS, 12,
+                    &offset, x8_orient_highquant_table[i]);
     for (i = 0; i < 4; i++)
-        init_or_vlc(j_orient_vlc[1][i], x8_orient_lowquant_table[i][0]);
-#undef init_or_vlc
+        x8_init_vlc(&j_orient_vlc[1][i], OR_VLC_BITS, 12,
+                    &offset, x8_orient_lowquant_table[i]);
 
-    av_assert2(offset == FF_ARRAY_ELEMS(table));
+    av_assert2(offset == VLC_BUFFER_SIZE);
 }
 
 static void x8_reset_vlc_tables(IntraX8Context *w)