changeset 4668:1f1a0e67b961 libavcodec

kill av_mallocz_static() calls in init_rl()
author michael
date Wed, 14 Mar 2007 13:19:19 +0000
parents b3f099adfb36
children d161ec980995
files h261.c h263.c mpeg12.c mpegvideo.c msmpeg4.c rl.h
diffstat 6 files changed, 38 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/h261.c	Wed Mar 14 12:29:32 2007 +0000
+++ b/h261.c	Wed Mar 14 13:19:19 2007 +0000
@@ -58,6 +58,8 @@
     int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
 }H261Context;
 
+static uint8_t static_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3];
+
 void ff_h261_loop_filter(MpegEncContext *s){
     H261Context * h= (H261Context*)s;
     const int linesize  = s->linesize;
@@ -285,7 +287,7 @@
 
     if (!done) {
         done = 1;
-        init_rl(&h261_rl_tcoeff, 1);
+        init_rl(&h261_rl_tcoeff, static_rl_table_store);
     }
 
     s->min_qcoeff= -127;
@@ -392,7 +394,7 @@
         init_vlc(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
                  &h261_cbp_tab[0][1], 2, 1,
                  &h261_cbp_tab[0][0], 2, 1, 1);
-        init_rl(&h261_rl_tcoeff, 1);
+        init_rl(&h261_rl_tcoeff, static_rl_table_store);
         init_vlc_rl(&h261_rl_tcoeff, 1);
     }
 }
--- a/h263.c	Wed Mar 14 12:29:32 2007 +0000
+++ b/h263.c	Wed Mar 14 13:19:19 2007 +0000
@@ -101,6 +101,8 @@
 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
 
+static uint8_t static_rl_table_store[5][2][2*MAX_RUN + MAX_LEVEL + 3];
+
 /* mpeg4
 inter
 max level: 24/6
@@ -2030,9 +2032,9 @@
 
         init_uni_dc_tab();
 
-        init_rl(&rl_inter, 1);
-        init_rl(&rl_intra, 1);
-        init_rl(&rl_intra_aic, 1);
+        init_rl(&rl_inter, static_rl_table_store[0]);
+        init_rl(&rl_intra, static_rl_table_store[1]);
+        init_rl(&rl_intra_aic, static_rl_table_store[2]);
 
         init_uni_mpeg4_rl_tab(&rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
         init_uni_mpeg4_rl_tab(&rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
@@ -2991,11 +2993,11 @@
         init_vlc(&mv_vlc, MV_VLC_BITS, 33,
                  &mvtab[0][1], 2, 1,
                  &mvtab[0][0], 2, 1, 1);
-        init_rl(&rl_inter, 1);
-        init_rl(&rl_intra, 1);
-        init_rl(&rvlc_rl_inter, 1);
-        init_rl(&rvlc_rl_intra, 1);
-        init_rl(&rl_intra_aic, 1);
+        init_rl(&rl_inter, static_rl_table_store[0]);
+        init_rl(&rl_intra, static_rl_table_store[1]);
+        init_rl(&rvlc_rl_inter, static_rl_table_store[3]);
+        init_rl(&rvlc_rl_intra, static_rl_table_store[4]);
+        init_rl(&rl_intra_aic, static_rl_table_store[2]);
         init_vlc_rl(&rl_inter, 1);
         init_vlc_rl(&rl_intra, 1);
         init_vlc_rl(&rvlc_rl_inter, 1);
--- a/mpeg12.c	Wed Mar 14 12:29:32 2007 +0000
+++ b/mpeg12.c	Wed Mar 14 13:19:19 2007 +0000
@@ -108,6 +108,8 @@
 static int8_t mpeg1_max_level[2][64];
 #endif //CONFIG_ENCODERS
 
+static uint8_t static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
+
 static void init_2d_vlc_rl(RLTable *rl, int use_static)
 {
     int i;
@@ -825,9 +827,9 @@
         int i;
 
         done=1;
-        init_rl(&rl_mpeg1, 1);
+        init_rl(&rl_mpeg1, static_rl_table_store[0]);
         if(s->intra_vlc_format)
-            init_rl(&rl_mpeg2, 1);
+            init_rl(&rl_mpeg2, static_rl_table_store[1]);
 
         for(i=0; i<64; i++)
         {
@@ -1075,8 +1077,8 @@
         init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
                  &table_mb_btype[0][1], 2, 1,
                  &table_mb_btype[0][0], 2, 1, 1);
-        init_rl(&rl_mpeg1, 1);
-        init_rl(&rl_mpeg2, 1);
+        init_rl(&rl_mpeg1, static_rl_table_store[0]);
+        init_rl(&rl_mpeg2, static_rl_table_store[1]);
 
         init_2d_vlc_rl(&rl_mpeg1, 1);
         init_2d_vlc_rl(&rl_mpeg2, 1);
--- a/mpegvideo.c	Wed Mar 14 12:29:32 2007 +0000
+++ b/mpegvideo.c	Wed Mar 14 13:19:19 2007 +0000
@@ -1411,14 +1411,14 @@
 
 #endif //CONFIG_ENCODERS
 
-void init_rl(RLTable *rl, int use_static)
+void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3])
 {
     int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1];
     uint8_t index_run[MAX_RUN+1];
     int last, run, level, start, end, i;
 
     /* If table is static, we can quit if rl->max_level[0] is not NULL */
-    if(use_static && rl->max_level[0])
+    if(static_store && rl->max_level[0])
         return;
 
     /* compute max_level[], max_run[] and index_run[] */
@@ -1444,18 +1444,18 @@
             if (run > max_run[level])
                 max_run[level] = run;
         }
-        if(use_static)
-            rl->max_level[last] = av_mallocz_static(MAX_RUN + 1);
+        if(static_store)
+            rl->max_level[last] = static_store[last];
         else
             rl->max_level[last] = av_malloc(MAX_RUN + 1);
         memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
-        if(use_static)
-            rl->max_run[last] = av_mallocz_static(MAX_LEVEL + 1);
+        if(static_store)
+            rl->max_run[last] = static_store[last] + MAX_RUN + 1;
         else
             rl->max_run[last] = av_malloc(MAX_LEVEL + 1);
         memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
-        if(use_static)
-            rl->index_run[last] = av_mallocz_static(MAX_RUN + 1);
+        if(static_store)
+            rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2;
         else
             rl->index_run[last] = av_malloc(MAX_RUN + 1);
         memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
--- a/msmpeg4.c	Wed Mar 14 12:29:32 2007 +0000
+++ b/msmpeg4.c	Wed Mar 14 13:19:19 2007 +0000
@@ -91,6 +91,8 @@
 static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
 #endif //CONFIG_ENCODERS
 
+static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3];
+
 static void common_init(MpegEncContext * s)
 {
     static int inited=0;
@@ -186,7 +188,7 @@
         init_mv_table(&mv_tables[0]);
         init_mv_table(&mv_tables[1]);
         for(i=0;i<NB_RL_TABLES;i++)
-            init_rl(&rl_table[i], 1);
+            init_rl(&rl_table[i], static_rl_table_store[i]);
 
         for(i=0; i<NB_RL_TABLES; i++){
             int level;
@@ -1051,7 +1053,7 @@
         done = 1;
 
         for(i=0;i<NB_RL_TABLES;i++) {
-            init_rl(&rl_table[i], 1);
+            init_rl(&rl_table[i], static_rl_table_store[i]);
             init_vlc_rl(&rl_table[i], 1);
         }
         for(i=0;i<2;i++) {
--- a/rl.h	Wed Mar 14 12:29:32 2007 +0000
+++ b/rl.h	Wed Mar 14 13:19:19 2007 +0000
@@ -20,7 +20,12 @@
     RL_VLC_ELEM *rl_vlc[32];       ///< decoding only
 } RLTable;
 
-void init_rl(RLTable *rl, int use_static);
+/**
+ *
+ * @param static_store static uint8_t array[2][2*MAX_RUN + MAX_LEVEL + 3] which will hold
+ *                     the level and run tables, if this is NULL av_malloc() will be used
+ */
+void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3]);
 void init_vlc_rl(RLTable *rl, int use_static);
 
 static inline int get_rl_index(const RLTable *rl, int last, int run, int level)