diff mbox series

[FFmpeg-devel,v2,036/162] avcodec/mimic: Reduce size of tables used to initialize VLCs

Message ID 20201120072116.818090-37-andreas.rheinhardt@gmail.com
State Accepted
Commit 34cb6d2360bb603c34eae8f488033bd6b4fbd279
Headers show
Series VLC, esp. init_vlc patches | expand

Checks

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

Commit Message

Andreas Rheinhardt Nov. 20, 2020, 7:19 a.m. UTC
By switching to ff_init_vlc_from_lengths() one can replace a table of
codes of type uint32_t with a table of symbols of type uint8_t saving
space. The old tables also had holes in it (because of the symbols) which
are now superfluous, saving ever more space.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/mimic.c | 55 ++++++++++++++++------------------------------
 1 file changed, 19 insertions(+), 36 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index 0f8103ef85..7a74b99086 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -65,43 +65,25 @@  typedef struct MimicContext {
     int             next_prev_index;
 } MimicContext;
 
-static const uint32_t huffcodes[] = {
-    0x0000000a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
-    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
-    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000b,
-    0x0000001b, 0x00000038, 0x00000078, 0x00000079, 0x0000007a, 0x000000f9,
-    0x000000fa, 0x000003fb, 0x000007f8, 0x000007f9, 0x000007fa, 0x000007fb,
-    0x00000ff8, 0x00000ff9, 0x00000001, 0x00000039, 0x0000007b, 0x000000fb,
-    0x000001f8, 0x000001f9, 0x00000ffa, 0x00000ffb, 0x00001ff8, 0x00001ff9,
-    0x00001ffa, 0x00001ffb, 0x00003ff8, 0x00003ff9, 0x00003ffa, 0x00000000,
-    0x00000004, 0x0000003a, 0x000001fa, 0x00003ffb, 0x00007ff8, 0x00007ff9,
-    0x00007ffa, 0x00007ffb, 0x0000fff8, 0x0000fff9, 0x0000fffa, 0x0000fffb,
-    0x0001fff8, 0x0001fff9, 0x0001fffa, 0x00000000, 0x0000000c, 0x000000f8,
-    0x000001fb, 0x0001fffb, 0x0003fff8, 0x0003fff9, 0x0003fffa, 0x0003fffb,
-    0x0007fff8, 0x0007fff9, 0x0007fffa, 0x0007fffb, 0x000ffff8, 0x000ffff9,
-    0x000ffffa, 0x00000000, 0x0000001a, 0x000003f8, 0x000ffffb, 0x001ffff8,
-    0x001ffff9, 0x001ffffa, 0x001ffffb, 0x003ffff8, 0x003ffff9, 0x003ffffa,
-    0x003ffffb, 0x007ffff8, 0x007ffff9, 0x007ffffa, 0x007ffffb, 0x00000000,
-    0x0000003b, 0x000003f9, 0x00fffff8, 0x00fffff9, 0x00fffffa, 0x00fffffb,
-    0x01fffff8, 0x01fffff9, 0x01fffffa, 0x01fffffb, 0x03fffff8, 0x03fffff9,
-    0x03fffffa, 0x03fffffb, 0x07fffff8, 0x00000000, 0x000003fa, 0x07fffff9,
-    0x07fffffa, 0x07fffffb, 0x0ffffff8, 0x0ffffff9, 0x0ffffffa, 0x0ffffffb,
-    0x1ffffff8, 0x1ffffff9, 0x1ffffffa, 0x1ffffffb, 0x3ffffff8, 0x3ffffff9,
-    0x3ffffffa,
+static const uint8_t huffsyms[] = {
+    0x10, 0x20, 0x30, 0x00, 0x11, 0x40, 0x50, 0x12, 0x13, 0x21, 0x31, 0x60,
+    0x14, 0x15, 0x16, 0x22, 0x41, 0x17, 0x18, 0x23, 0x24, 0x25, 0x32, 0x42,
+    0x51, 0x61, 0x70, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x26, 0x27,
+    0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x33, 0x34, 0x35, 0x36, 0x37,
+    0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x43, 0x44, 0x45, 0x46, 0x47,
+    0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x52, 0x53, 0x54, 0x55, 0x56,
+    0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x62, 0x63, 0x64, 0x65,
+    0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, 0x73,
+    0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E,
 };
 
 static const uint8_t huffbits[] = {
-     4,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-     0,  0,  0,  0,  2,  4,  5,  6,  7,  7,  7,  8,
-     8, 10, 11, 11, 11, 11, 12, 12,  2,  6,  7,  8,
-     9,  9, 12, 12, 13, 13, 13, 13, 14, 14, 14,  0,
-     3,  6,  9, 14, 15, 15, 15, 15, 16, 16, 16, 16,
-    17, 17, 17,  0,  4,  8,  9, 17, 18, 18, 18, 18,
-    19, 19, 19, 19, 20, 20, 20,  0,  5, 10, 20, 21,
-    21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,  0,
-     6, 10, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26,
-    26, 26, 27,  0, 10, 27, 27, 27, 28, 28, 28, 28,
-    29, 29, 29, 29, 30, 30, 30,
+     2,  2,  3,  4,  4,  4,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,
+     8,  8,  9,  9,  9,  9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12,
+    13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17,
+    17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21,
+    22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26,
+    26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30,
 };
 
 static const uint8_t col_zag[64] = {
@@ -142,8 +124,9 @@  static av_cold int mimic_decode_init(AVCodecContext *avctx)
     ctx->prev_index = 0;
     ctx->cur_index  = 15;
 
-    if ((ret = init_vlc(&ctx->vlc, MIMIC_VLC_BITS, FF_ARRAY_ELEMS(huffbits),
-                        huffbits, 1, 1, huffcodes, 4, 4, 0)) < 0) {
+    ret = ff_init_vlc_from_lengths(&ctx->vlc, MIMIC_VLC_BITS, FF_ARRAY_ELEMS(huffbits),
+                                   huffbits, 1, huffsyms, 1, 1, 0, 0, avctx);
+    if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "error initializing vlc table\n");
         return ret;
     }