[FFmpeg-cvslog] avcodec/dv: Don't initialize RL VLC for encoder

Andreas Rheinhardt git at videolan.org
Thu May 6 07:16:24 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Tue Dec 29 18:24:40 2020 +0100| [6d484671ecb612c32cbda0fab65f961743aff5f8] | committer: Andreas Rheinhardt

avcodec/dv: Don't initialize RL VLC for encoder

Said RL VLC is only used by the decoder, ergo don't initialize it for
the encoder and move the whole code and the RL VLC table itself to
dvdec.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6d484671ecb612c32cbda0fab65f961743aff5f8
---

 libavcodec/dv.c    | 59 -------------------------------------------
 libavcodec/dv.h    |  4 ---
 libavcodec/dvdec.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 70 insertions(+), 67 deletions(-)

diff --git a/libavcodec/dv.c b/libavcodec/dv.c
index 7c1ec6e0b2..8a4cac859e 100644
--- a/libavcodec/dv.c
+++ b/libavcodec/dv.c
@@ -48,9 +48,6 @@
 #include "put_bits.h"
 #include "simple_idct.h"
 
-/* XXX: also include quantization */
-RL_VLC_ELEM ff_dv_rl_vlc[1664];
-
 static inline void dv_calc_mb_coordinates(const AVDVProfile *d, int chan,
                                           int seq, int slot, uint16_t *tbl)
 {
@@ -198,65 +195,9 @@ int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
 av_cold int ff_dvvideo_init(AVCodecContext *avctx)
 {
     DVVideoContext *s = avctx->priv_data;
-    static int done = 0;
-    int i, j;
-
-    if (!done) {
-        VLC_TYPE vlc_buf[FF_ARRAY_ELEMS(ff_dv_rl_vlc)][2] = { 0 };
-        VLC dv_vlc = { .table = vlc_buf, .table_allocated = FF_ARRAY_ELEMS(vlc_buf) };
-        uint16_t  new_dv_vlc_bits[NB_DV_VLC * 2];
-        uint8_t    new_dv_vlc_len[NB_DV_VLC * 2];
-        uint8_t    new_dv_vlc_run[NB_DV_VLC * 2];
-        int16_t  new_dv_vlc_level[NB_DV_VLC * 2];
-
-        done = 1;
-
-        /* it's faster to include sign bit in a generic VLC parsing scheme */
-        for (i = 0, j = 0; i < NB_DV_VLC; i++, j++) {
-            new_dv_vlc_bits[j]  = ff_dv_vlc_bits[i];
-            new_dv_vlc_len[j]   = ff_dv_vlc_len[i];
-            new_dv_vlc_run[j]   = ff_dv_vlc_run[i];
-            new_dv_vlc_level[j] = ff_dv_vlc_level[i];
-
-            if (ff_dv_vlc_level[i]) {
-                new_dv_vlc_bits[j] <<= 1;
-                new_dv_vlc_len[j]++;
-
-                j++;
-                new_dv_vlc_bits[j]  = (ff_dv_vlc_bits[i] << 1) | 1;
-                new_dv_vlc_len[j]   =  ff_dv_vlc_len[i] + 1;
-                new_dv_vlc_run[j]   =  ff_dv_vlc_run[i];
-                new_dv_vlc_level[j] = -ff_dv_vlc_level[i];
-            }
-        }
-
-        /* NOTE: as a trick, we use the fact the no codes are unused
-         * to accelerate the parsing of partial codes */
-        init_vlc(&dv_vlc, TEX_VLC_BITS, j, new_dv_vlc_len,
-                 1, 1, new_dv_vlc_bits, 2, 2, INIT_VLC_USE_NEW_STATIC);
-        av_assert1(dv_vlc.table_size == 1664);
-
-        for (i = 0; i < dv_vlc.table_size; i++) {
-            int code = dv_vlc.table[i][0];
-            int len  = dv_vlc.table[i][1];
-            int level, run;
-
-            if (len < 0) { // more bits needed
-                run   = 0;
-                level = code;
-            } else {
-                run   = new_dv_vlc_run[code] + 1;
-                level = new_dv_vlc_level[code];
-            }
-            ff_dv_rl_vlc[i].len   = len;
-            ff_dv_rl_vlc[i].level = level;
-            ff_dv_rl_vlc[i].run   = run;
-        }
-    }
 
     s->avctx = avctx;
     avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
 
     return 0;
 }
-
diff --git a/libavcodec/dv.h b/libavcodec/dv.h
index 0205d72347..19290aa382 100644
--- a/libavcodec/dv.h
+++ b/libavcodec/dv.h
@@ -96,10 +96,6 @@ enum dv_pack_type {
  */
 #define DV_MAX_BPM 8
 
-#define TEX_VLC_BITS 10
-
-extern RL_VLC_ELEM ff_dv_rl_vlc[1664];
-
 int ff_dv_init_dynamic_tables(DVVideoContext *s, const AVDVProfile *d);
 
 int ff_dvvideo_init(AVCodecContext *avctx);
diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
index d768326661..da6112ff1f 100644
--- a/libavcodec/dvdec.c
+++ b/libavcodec/dvdec.c
@@ -128,6 +128,70 @@ static const uint16_t dv_iweight_720_c[64] = {
     394, 406, 418, 438, 418, 464, 464, 492,
 };
 
+#define TEX_VLC_BITS 10
+
+/* XXX: also include quantization */
+static RL_VLC_ELEM dv_rl_vlc[1664];
+
+static void dv_init_static(void)
+{
+    VLC_TYPE vlc_buf[FF_ARRAY_ELEMS(dv_rl_vlc)][2] = { 0 };
+    VLC dv_vlc = { .table = vlc_buf, .table_allocated = FF_ARRAY_ELEMS(vlc_buf) };
+    uint16_t  new_dv_vlc_bits[NB_DV_VLC * 2];
+    uint8_t    new_dv_vlc_len[NB_DV_VLC * 2];
+    uint8_t    new_dv_vlc_run[NB_DV_VLC * 2];
+    int16_t  new_dv_vlc_level[NB_DV_VLC * 2];
+    int i, j;
+    static int done = 0;
+
+    if (done)
+        return;
+
+    done = 1;
+
+    /* it's faster to include sign bit in a generic VLC parsing scheme */
+    for (i = 0, j = 0; i < NB_DV_VLC; i++, j++) {
+        new_dv_vlc_bits[j]  = ff_dv_vlc_bits[i];
+        new_dv_vlc_len[j]   = ff_dv_vlc_len[i];
+        new_dv_vlc_run[j]   = ff_dv_vlc_run[i];
+        new_dv_vlc_level[j] = ff_dv_vlc_level[i];
+
+        if (ff_dv_vlc_level[i]) {
+            new_dv_vlc_bits[j] <<= 1;
+            new_dv_vlc_len[j]++;
+
+            j++;
+            new_dv_vlc_bits[j]  = (ff_dv_vlc_bits[i] << 1) | 1;
+            new_dv_vlc_len[j]   =  ff_dv_vlc_len[i] + 1;
+            new_dv_vlc_run[j]   =  ff_dv_vlc_run[i];
+            new_dv_vlc_level[j] = -ff_dv_vlc_level[i];
+        }
+    }
+
+    /* NOTE: as a trick, we use the fact the no codes are unused
+     * to accelerate the parsing of partial codes */
+    init_vlc(&dv_vlc, TEX_VLC_BITS, j, new_dv_vlc_len,
+             1, 1, new_dv_vlc_bits, 2, 2, INIT_VLC_USE_NEW_STATIC);
+    av_assert1(dv_vlc.table_size == 1664);
+
+    for (int i = 0; i < dv_vlc.table_size; i++) {
+        int code = dv_vlc.table[i][0];
+        int len  = dv_vlc.table[i][1];
+        int level, run;
+
+        if (len < 0) { // more bits needed
+            run   = 0;
+            level = code;
+        } else {
+            run   = new_dv_vlc_run[code] + 1;
+            level = new_dv_vlc_level[code];
+        }
+        dv_rl_vlc[i].len   = len;
+        dv_rl_vlc[i].level = level;
+        dv_rl_vlc[i].run   = run;
+    }
+}
+
 static void dv_init_weight_tables(DVVideoContext *ctx, const AVDVProfile *d)
 {
     int j, i, c, s;
@@ -195,6 +259,8 @@ static av_cold int dvvideo_decode_init(AVCodecContext *avctx)
     s->idct_put[0] = s->idsp.idct_put;
     s->idct_put[1] = ff_simple_idct248_put;
 
+    dv_init_static();
+
     return ff_dvvideo_init(avctx);
 }
 
@@ -225,14 +291,14 @@ static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, int16_t *block)
                 pos, SHOW_UBITS(re, gb, 16), re_index);
         /* our own optimized GET_RL_VLC */
         index   = NEG_USR32(re_cache, TEX_VLC_BITS);
-        vlc_len = ff_dv_rl_vlc[index].len;
+        vlc_len = dv_rl_vlc[index].len;
         if (vlc_len < 0) {
             index = NEG_USR32((unsigned) re_cache << TEX_VLC_BITS, -vlc_len) +
-                    ff_dv_rl_vlc[index].level;
+                    dv_rl_vlc[index].level;
             vlc_len = TEX_VLC_BITS - vlc_len;
         }
-        level = ff_dv_rl_vlc[index].level;
-        run   = ff_dv_rl_vlc[index].run;
+        level = dv_rl_vlc[index].level;
+        run   = dv_rl_vlc[index].run;
 
         /* gotta check if we're still within gb boundaries */
         if (re_index + vlc_len > last_index) {



More information about the ffmpeg-cvslog mailing list