diff mbox series

[FFmpeg-devel,211/217] avcodec/bink: Don't waste space for VLC table

Message ID 20201202042244.519127-77-andreas.rheinhardt@gmail.com
State Accepted
Commit 56df06dd8346687d6d9b7321f2af41e4fd614ee3
Headers show
Series [FFmpeg-devel,01/45] avcodec/a64multienc: Fix memleak upon init failure
Related show

Checks

Context Check Description
andriy/x86 warning Failed to apply patch

Commit Message

Andreas Rheinhardt Dec. 2, 2020, 4:22 a.m. UTC
The Bink video decoder uses VLCs; the longest codes of these VLCs have
different lengths, yet they are all so small that each VLC is read in
one go, so that the number of elements in the VLC table actually used by
each table is 1 << nb_bits, where nb_bits is the length of the longest
code. Yet when determining the size of the VLC table nb_bits has been
overestimated as the number of bits of the longest code in all VLCs,
making said table unnecessary big (2048 vs 976 elements).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/bink.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index f1fa9c0071..04c104be48 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -1311,11 +1311,12 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
 
 static av_cold void bink_init_vlcs(void)
 {
-    for (int i = 0; i < 16; i++) {
-        static VLC_TYPE table[16 * 128][2];
+    for (int i = 0, offset = 0; i < 16; i++) {
+        static VLC_TYPE table[976][2];
         const int maxbits = bink_tree_lens[i][15];
-        bink_trees[i].table = table + i*128;
+        bink_trees[i].table           = table + offset;
         bink_trees[i].table_allocated = 1 << maxbits;
+        offset                       += bink_trees[i].table_allocated;
         init_vlc(&bink_trees[i], maxbits, 16,
                  bink_tree_lens[i], 1, 1,
                  bink_tree_bits[i], 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);