[FFmpeg-devel] [PATCH] rl.h: Use on-stack temporary VLC tables instead of having them static.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Sep 1 20:59:43 CEST 2014


Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
 libavcodec/mpeg12.c    | 21 ++++++++++-----------
 libavcodec/mpegvideo.c | 12 ++++++++----
 libavcodec/rl.h        |  8 ++------
 3 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index cb00baf..37f6fe4 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -70,22 +70,21 @@ static const uint8_t table_mb_btype[11][2] = {
 #define INIT_2D_VLC_RL(rl, static_size)\
 {\
     static RL_VLC_ELEM rl_vlc_table[static_size];\
-    VLC tmp_vlc;\
-    INIT_VLC_STATIC(&tmp_vlc, TEX_VLC_BITS, rl.n + 2,\
-                    &rl.table_vlc[0][1], 4, 2,\
-                    &rl.table_vlc[0][0], 4, 2, static_size);\
-\
     rl.rl_vlc[0] = rl_vlc_table;\
-    init_2d_vlc_rl(&rl, &tmp_vlc);\
+    init_2d_vlc_rl(&rl, static_size);\
 }
 
-static av_cold void init_2d_vlc_rl(RLTable *rl, const VLC *vlc)
+static av_cold void init_2d_vlc_rl(RLTable *rl, unsigned static_size)
 {
     int i;
-
-    for (i = 0; i < vlc->table_size; i++) {
-        int code = vlc->table[i][0];
-        int len  = vlc->table[i][1];
+    VLC_TYPE table[1500][2] = {{0}};
+    VLC vlc = { .table = table, .table_allocated = static_size };
+    av_assert0(static_size <= FF_ARRAY_ELEMS(table));
+    init_vlc(&vlc, TEX_VLC_BITS, rl->n + 2, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC);
+
+    for (i = 0; i < vlc.table_size; i++) {
+        int code = vlc.table[i][0];
+        int len  = vlc.table[i][1];
         int level, run;
 
         if (len == 0) { // illegal code
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 748dbc8..85cb41d 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1618,9 +1618,13 @@ av_cold void ff_init_rl(RLTable *rl,
     }
 }
 
-av_cold void ff_init_vlc_rl(RLTable *rl, const VLC *vlc)
+av_cold void ff_init_vlc_rl(RLTable *rl, unsigned static_size)
 {
     int i, q;
+    VLC_TYPE table[1500][2] = {{0}};
+    VLC vlc = { .table = table, .table_allocated = static_size };
+    av_assert0(static_size <= FF_ARRAY_ELEMS(table));
+    init_vlc(&vlc, 9, rl->n + 1, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC);
 
     for (q = 0; q < 32; q++) {
         int qmul = q * 2;
@@ -1630,9 +1634,9 @@ av_cold void ff_init_vlc_rl(RLTable *rl, const VLC *vlc)
             qmul = 1;
             qadd = 0;
         }
-        for (i = 0; i < vlc->table_size; i++) {
-            int code = vlc->table[i][0];
-            int len  = vlc->table[i][1];
+        for (i = 0; i < vlc.table_size; i++) {
+            int code = vlc.table[i][0];
+            int len  = vlc.table[i][1];
             int level, run;
 
             if (len == 0) { // illegal code
diff --git a/libavcodec/rl.h b/libavcodec/rl.h
index 3cef366..2897ec5 100644
--- a/libavcodec/rl.h
+++ b/libavcodec/rl.h
@@ -53,22 +53,18 @@ typedef struct RLTable {
  *                     the level and run tables, if this is NULL av_malloc() will be used
  */
 void ff_init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3]);
-void ff_init_vlc_rl(RLTable *rl, const VLC *vlc);
+void ff_init_vlc_rl(RLTable *rl, unsigned static_size);
 
 #define INIT_VLC_RL(rl, static_size)\
 {\
     int q;\
     static RL_VLC_ELEM rl_vlc_table[32][static_size];\
-    VLC tmp_vlc;\
-    INIT_VLC_STATIC(&tmp_vlc, 9, rl.n + 1,\
-             &rl.table_vlc[0][1], 4, 2,\
-             &rl.table_vlc[0][0], 4, 2, static_size);\
 \
     if(!rl.rl_vlc[0]){\
         for(q=0; q<32; q++)\
             rl.rl_vlc[q]= rl_vlc_table[q];\
 \
-        ff_init_vlc_rl(&rl, &tmp_vlc);\
+        ff_init_vlc_rl(&rl, static_size);\
     }\
 }
 
-- 
2.1.0



More information about the ffmpeg-devel mailing list