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

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Aug 31 20:27:17 CEST 2014


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

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index cb00baf..769bed7 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -70,22 +70,22 @@ 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 vlc;
+    init_vlc(&vlc, TEX_VLC_BITS, rl->n + 2, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, 0);
+    av_assert0(vlc.table_size <= static_size);
+    if (vlc.table_size != static_size)
+        av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc.table_size, static_size);
+
+    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
@@ -110,6 +110,7 @@ static av_cold void init_2d_vlc_rl(RLTable *rl, const VLC *vlc)
         rl->rl_vlc[0][i].level = level;
         rl->rl_vlc[0][i].run   = run;
     }
+    ff_free_vlc(&vlc);
 }
 
 av_cold void ff_mpeg12_common_init(MpegEncContext *s)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 748dbc8..94e000f 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1618,9 +1618,14 @@ 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 vlc;
+    init_vlc(&vlc, 9, rl->n + 1, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, 0);
+    av_assert0(vlc.table_size <= static_size);
+    if (vlc.table_size != static_size)
+        av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc.table_size, static_size);
 
     for (q = 0; q < 32; q++) {
         int qmul = q * 2;
@@ -1630,9 +1635,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
@@ -1656,6 +1661,7 @@ av_cold void ff_init_vlc_rl(RLTable *rl, const VLC *vlc)
             rl->rl_vlc[q][i].run   = run;
         }
     }
+    ff_free_vlc(&vlc);
 }
 
 static void release_unused_pictures(MpegEncContext *s)
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