diff mbox series

[FFmpeg-devel,112/114] avcodec/qdmc: Make tables used to initialize VLCs smaller

Message ID 20201110105836.321916-21-andreas.rheinhardt@gmail.com
State Superseded
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. 10, 2020, 10:58 a.m. UTC
This is possible by switching to ff_init_vlc_from_lengths() which allows
to replace tables of codes of size uint16_t or uint32_t by tables of
symbols of size uint8_t; in case there already were symbols tables the
savings are even bigger.

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

Patch

diff --git a/libavcodec/qdmc.c b/libavcodec/qdmc.c
index f4e507fa60..8b50fbf30a 100644
--- a/libavcodec/qdmc.c
+++ b/libavcodec/qdmc.c
@@ -119,58 +119,36 @@  static const uint8_t noise_bands_selector[] = {
     4, 3, 2, 1, 0, 0, 0,
 };
 
-static const uint8_t noise_value_bits[] = {
-    12, 7, 9, 7, 10, 9, 11, 9, 9, 2, 9, 9, 9, 9,
-    9, 3, 9, 10, 10, 12, 2, 3, 3, 5, 5, 6, 7,
+static const uint8_t noise_value[][2] = {
+    {  1,  2 }, { 10,  7 }, { 26,  9 }, { 22,  9 }, { 24,  9 }, { 14,  9 },
+    {  8,  6 }, {  6,  5 }, {  7,  5 }, {  9,  7 }, { 30,  9 }, { 32, 10 },
+    { 13, 10 }, { 20,  9 }, { 28,  9 }, { 12,  7 }, { 15, 11 }, { 36, 12 },
+    {  0, 12 }, { 34, 10 }, { 18,  9 }, { 11,  9 }, { 16,  9 }, {  5,  3 },
+    {  2,  3 }, {  4,  3 }, {  3,  2 },
 };
 
-static const uint8_t noise_value_symbols[] = {
-    0, 10, 11, 12, 13, 14, 15, 16, 18, 1, 20, 22, 24,
-    26, 28, 2, 30, 32, 34, 36, 3, 4, 5, 6, 7, 8, 9,
+static const uint8_t noise_segment_length[][2] = {
+    {  1,  1 }, {  2,  2 }, {  3,  4 }, {  8,  9 }, {  9, 10 }, {  0, 10 },
+    { 13,  8 }, {  7,  7 }, {  6,  6 }, { 17,  5 }, {  4,  4 }, {  5,  4 },
 };
 
-static const uint16_t noise_value_codes[] = {
-    0xC7A, 0x002, 0x0FA, 0x03A, 0x35A, 0x1C2, 0x07A, 0x1FA,
-    0x17A, 0x000, 0x0DA, 0x142, 0x0C2, 0x042, 0x1DA, 0x001,
-    0x05A, 0x15A, 0x27A, 0x47A, 0x003, 0x005, 0x006, 0x012,
-    0x00A, 0x022, 0x01A,
+static const uint8_t amplitude[][2] = {
+    { 18,  3 }, { 16,  3 }, { 22,  7 }, {  8, 10 }, {  4, 10 }, {  3,  9 },
+    {  2,  8 }, { 23,  8 }, { 10,  8 }, { 11,  7 }, { 21,  5 }, { 20,  4 },
+    {  1,  7 }, {  7, 10 }, {  5, 10 }, {  9,  9 }, {  6, 10 }, { 25, 11 },
+    { 26, 12 }, { 27, 13 }, {  0, 13 }, { 24,  9 }, { 12,  6 }, { 13,  5 },
+    { 14,  4 }, { 19,  3 }, { 15,  3 }, { 17,  2 },
 };
 
-static const uint8_t noise_segment_length_bits[] = {
-    10, 8, 5, 1, 2, 4, 4, 4, 6, 7, 9, 10,
-};
-
-static const uint8_t noise_segment_length_symbols[] = {
-    0, 13, 17, 1, 2, 3, 4, 5, 6, 7, 8, 9,
-};
-
-static const uint16_t noise_segment_length_codes[] = {
-    0x30B, 0x8B, 0x1B, 0x0, 0x1, 0x3, 0x7, 0xF, 0x2b, 0x4B, 0xB, 0x10B,
-};
-
-static const uint8_t freq_diff_bits[] = {
-    18, 2, 4, 4, 5, 4, 4, 5, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 6,
-    7, 6, 6, 6, 7, 7, 7, 7, 7, 8, 9, 9, 8, 9, 11, 11, 12, 12, 13, 12,
-    14, 15, 18, 16, 17,
-};
-
-static const uint32_t freq_diff_codes[] = {
-    0x2AD46, 0x1, 0x0, 0x3, 0xC, 0xA, 0x7, 0x18, 0x12, 0xE, 0x4, 0x16,
-    0xF, 0x1C, 0x8, 0x22, 0x26, 0x2, 0x3B, 0x34, 0x74, 0x1F, 0x14, 0x2B,
-    0x1B, 0x3F, 0x28, 0x54, 0x6, 0x4B, 0xB, 0x68, 0xE8, 0x46, 0xC6, 0x1E8,
-    0x146, 0x346, 0x546, 0x746, 0x1D46, 0xF46, 0xD46, 0x6D46, 0xAD46, 0x2D46,
-    0x1AD46,
-};
-
-static const uint8_t amplitude_bits[] = {
-    13, 7, 8, 9, 10, 10, 10, 10, 10, 9, 8, 7, 6,
-    5, 4, 3, 3, 2, 3, 3, 4, 5, 7, 8, 9, 11, 12, 13,
-};
-
-static const uint16_t amplitude_codes[] = {
-    0x1EC6, 0x6, 0xC2, 0x142, 0x242, 0x246, 0xC6, 0x46, 0x42, 0x146, 0xA2,
-    0x62, 0x26, 0x16, 0xE, 0x5, 0x4, 0x3, 0x0, 0x1, 0xA, 0x12, 0x2, 0x22,
-    0x1C6, 0x2C6, 0x6C6, 0xEC6,
+static const uint8_t freq_diff[][2] = {
+    {  2,  4 }, { 14,  6 }, { 26,  7 }, { 31,  8 }, { 32,  9 }, { 35,  9 },
+    {  7,  5 }, { 10,  5 }, { 22,  7 }, { 27,  7 }, { 19,  7 }, { 20,  7 },
+    {  4,  5 }, { 13,  5 }, { 17,  6 }, { 15,  6 }, {  8,  5 }, {  5,  4 },
+    { 28,  7 }, { 33,  9 }, { 36, 11 }, { 38, 12 }, { 42, 14 }, { 45, 16 },
+    { 44, 18 }, {  0, 18 }, { 46, 17 }, { 43, 15 }, { 40, 13 }, { 37, 11 },
+    { 39, 12 }, { 41, 12 }, { 34,  8 }, { 16,  6 }, { 11,  5 }, {  9,  4 },
+    {  1,  2 }, {  3,  4 }, { 30,  7 }, { 29,  7 }, { 23,  6 }, { 24,  6 },
+    { 18,  6 }, {  6,  4 }, { 12,  5 }, { 21,  6 }, { 25,  6 },
 };
 
 static const uint8_t amplitude_diff_bits[] = {
@@ -209,15 +187,18 @@  static av_cold void qdmc_init_static_data(void)
 {
     int i;
 
-    INIT_VLC_STATIC_LE(&vtable[0], 12, FF_ARRAY_ELEMS(noise_value_bits),
-                       noise_value_bits, 1, 1, noise_value_codes, 2, 2, noise_value_symbols, 1, 1, 4096);
-    INIT_VLC_STATIC_LE(&vtable[1], 10, FF_ARRAY_ELEMS(noise_segment_length_bits),
-                       noise_segment_length_bits, 1, 1, noise_segment_length_codes, 2, 2,
-                       noise_segment_length_symbols, 1, 1, 1024);
-    INIT_VLC_STATIC_LE(&vtable[2], 12, FF_ARRAY_ELEMS(amplitude_bits),
-                       amplitude_bits, 1, 1, amplitude_codes, 2, 2, NULL, 0, 0, 4098);
-    INIT_VLC_STATIC_LE(&vtable[3], 12, FF_ARRAY_ELEMS(freq_diff_bits),
-                       freq_diff_bits, 1, 1, freq_diff_codes, 4, 4, NULL, 0, 0, 4160);
+    INIT_VLC_STATIC_FROM_LENGTHS(&vtable[0], 12, FF_ARRAY_ELEMS(noise_value),
+                                 &noise_value[0][1], 2,
+                                 &noise_value[0][0], 2, 1, 0, INIT_VLC_LE, 4096);
+    INIT_VLC_STATIC_FROM_LENGTHS(&vtable[1], 10, FF_ARRAY_ELEMS(noise_segment_length),
+                                 &noise_segment_length[0][1], 2,
+                                 &noise_segment_length[0][0], 2, 1, 0, INIT_VLC_LE, 1024);
+    INIT_VLC_STATIC_FROM_LENGTHS(&vtable[2], 12, FF_ARRAY_ELEMS(amplitude),
+                                 &amplitude[0][1], 2,
+                                 &amplitude[0][0], 2, 1, 0, INIT_VLC_LE, 4098);
+    INIT_VLC_STATIC_FROM_LENGTHS(&vtable[3], 12, FF_ARRAY_ELEMS(freq_diff),
+                                 &freq_diff[0][1], 2,
+                                 &freq_diff[0][0], 2, 1, 0, INIT_VLC_LE, 4160);
     INIT_VLC_STATIC_LE(&vtable[4], 8, FF_ARRAY_ELEMS(amplitude_diff_bits),
                        amplitude_diff_bits, 1, 1, amplitude_diff_codes, 1, 1, NULL, 0, 0, 256);
     INIT_VLC_STATIC_LE(&vtable[5], 6, FF_ARRAY_ELEMS(phase_diff_bits),