[FFmpeg-devel] [PATCH 12/19] avcodec/vc1_block: Don't duplicate #defines

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Oct 31 01:56:24 EET 2022


VC1 shares some VLCs with MSMPEG-4, but vc1_block.c
simply duplicates the defines instead of including
the appropriate headers; furthermore, use a proper
prefix for these defines: DC_VLC_BITS is also used
by other codecs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/msmpeg4data.h |  2 ++
 libavcodec/msmpeg4dec.c  | 27 ++++++++++++++-------------
 libavcodec/msmpeg4dec.h  |  1 -
 libavcodec/vc1_block.c   | 27 ++++++++++++++++-----------
 libavcodec/wmv2dec.c     |  3 ++-
 5 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/libavcodec/msmpeg4data.h b/libavcodec/msmpeg4data.h
index b2b5bade4d..4f904d7610 100644
--- a/libavcodec/msmpeg4data.h
+++ b/libavcodec/msmpeg4data.h
@@ -48,7 +48,9 @@ typedef struct MVTable {
 } MVTable;
 
 FF_VISIBILITY_PUSH_HIDDEN
+#define MSMP4_MB_INTRA_VLC_BITS 9
 extern VLC ff_msmp4_mb_i_vlc;
+#define MSMP4_DC_VLC_BITS 9
 extern VLC ff_msmp4_dc_luma_vlc[2];
 extern VLC ff_msmp4_dc_chroma_vlc[2];
 
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index bc554ed2eb..a7ba53f68e 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -37,7 +37,6 @@
 #include "mpeg4videodec.h"
 #include "msmpeg4data.h"
 
-#define DC_VLC_BITS 9
 #define V2_INTRA_CBPC_VLC_BITS 3
 #define V2_MB_TYPE_VLC_BITS 7
 #define MV_VLC_BITS 9
@@ -237,7 +236,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
         cbp = code & 0x3f;
     } else {
         s->mb_intra = 1;
-        code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
+        code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MSMP4_MB_INTRA_VLC_BITS, 2);
         /* predict coded block pattern */
         cbp = 0;
         for(i=0;i<6;i++) {
@@ -317,23 +316,23 @@ static av_cold void msmpeg4_decode_init_static(void)
                     mv->table_mv_bits, 1, 1,
                     mv->table_mv_code, 2, 2, 2694);
 
-    INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[0], DC_VLC_BITS, 120,
+    INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[0], MSMP4_DC_VLC_BITS, 120,
                     &ff_table0_dc_lum[0][1], 8, 4,
                     &ff_table0_dc_lum[0][0], 8, 4, 1158);
-    INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[0], DC_VLC_BITS, 120,
+    INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[0], MSMP4_DC_VLC_BITS, 120,
                     &ff_table0_dc_chroma[0][1], 8, 4,
                     &ff_table0_dc_chroma[0][0], 8, 4, 1118);
-    INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[1], DC_VLC_BITS, 120,
+    INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[1], MSMP4_DC_VLC_BITS, 120,
                     &ff_table1_dc_lum[0][1], 8, 4,
                     &ff_table1_dc_lum[0][0], 8, 4, 1476);
-    INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[1], DC_VLC_BITS, 120,
+    INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[1], MSMP4_DC_VLC_BITS, 120,
                     &ff_table1_dc_chroma[0][1], 8, 4,
                     &ff_table1_dc_chroma[0][0], 8, 4, 1216);
 
-    INIT_VLC_STATIC(&v2_dc_lum_vlc, DC_VLC_BITS, 512,
+    INIT_VLC_STATIC(&v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 512,
                     &ff_v2_dc_lum_table[0][1], 8, 4,
                     &ff_v2_dc_lum_table[0][0], 8, 4, 1472);
-    INIT_VLC_STATIC(&v2_dc_chroma_vlc, DC_VLC_BITS, 512,
+    INIT_VLC_STATIC(&v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 512,
                     &ff_v2_dc_chroma_table[0][1], 8, 4,
                     &ff_v2_dc_chroma_table[0][0], 8, 4, 1506);
 
@@ -355,7 +354,7 @@ static av_cold void msmpeg4_decode_init_static(void)
         offset += ff_mb_non_intra_vlc[i].table_size;
     }
 
-    INIT_VLC_STATIC(&ff_msmp4_mb_i_vlc, MB_INTRA_VLC_BITS, 64,
+    INIT_VLC_STATIC(&ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 64,
                     &ff_msmp4_mb_i_table[0][1], 4, 2,
                     &ff_msmp4_mb_i_table[0][0], 4, 2, 536);
 
@@ -591,9 +590,9 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
 
     if(s->msmpeg4_version<=2){
         if (n < 4) {
-            level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3);
+            level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, MSMP4_DC_VLC_BITS, 3);
         } else {
-            level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3);
+            level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, MSMP4_DC_VLC_BITS, 3);
         }
         if (level < 0) {
             av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
@@ -603,9 +602,11 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
         level-=256;
     }else{  //FIXME optimize use unified tables & index
         if (n < 4) {
-            level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+            level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table,
+                             MSMP4_DC_VLC_BITS, 3);
         } else {
-            level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+            level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table,
+                             MSMP4_DC_VLC_BITS, 3);
         }
 
         if (level == DC_MAX) {
diff --git a/libavcodec/msmpeg4dec.h b/libavcodec/msmpeg4dec.h
index 19b5c12c6c..ad41eea9d4 100644
--- a/libavcodec/msmpeg4dec.h
+++ b/libavcodec/msmpeg4dec.h
@@ -27,7 +27,6 @@
 
 #define INTER_INTRA_VLC_BITS 3
 #define MB_NON_INTRA_VLC_BITS 9
-#define MB_INTRA_VLC_BITS 9
 
 extern VLC ff_mb_non_intra_vlc[4];
 extern VLC ff_inter_intra_vlc;
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index ef8ce40e68..9293c509cb 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -37,9 +37,6 @@
 #include "vc1acdata.h"
 #include "vc1data.h"
 
-#define MB_INTRA_VLC_BITS 9
-#define DC_VLC_BITS 9
-
 // offset tables for interlaced picture MVDATA decoding
 static const uint8_t offset_table[2][9] = {
     {  0,  1,  2,  4,  8, 16, 32,  64, 128 },
@@ -596,9 +593,11 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
 
     /* Get DC differential */
     if (n < 4) {
-        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table,
+                          MSMP4_DC_VLC_BITS, 3);
     } else {
-        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table,
+                          MSMP4_DC_VLC_BITS, 3);
     }
     if (dcdiff) {
         const int m = (v->pq == 1 || v->pq == 2) ? 3 - v->pq : 0;
@@ -740,9 +739,11 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
 
     /* Get DC differential */
     if (n < 4) {
-        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table,
+                          MSMP4_DC_VLC_BITS, 3);
     } else {
-        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table,
+                          MSMP4_DC_VLC_BITS, 3);
     }
     if (dcdiff) {
         const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
@@ -940,9 +941,11 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
 
     /* Get DC differential */
     if (n < 4) {
-        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table,
+                          MSMP4_DC_VLC_BITS, 3);
     } else {
-        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
+        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table,
+                          MSMP4_DC_VLC_BITS, 3);
     }
     if (dcdiff) {
         const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
@@ -2588,7 +2591,8 @@ static void vc1_decode_i_blocks(VC1Context *v)
             }
 
             // do actual MB decoding and displaying
-            cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
+            cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table,
+                           MSMP4_MB_INTRA_VLC_BITS, 2);
             v->s.ac_pred = get_bits1(&v->s.gb);
 
             for (k = 0; k < 6; k++) {
@@ -2723,7 +2727,8 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
                 return 0;
             }
 
-            cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
+            cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table,
+                           MSMP4_MB_INTRA_VLC_BITS, 2);
             if (v->acpred_is_raw)
                 v->s.ac_pred = get_bits1(&v->s.gb);
             else
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 2daf6c70e8..1209b1902d 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -482,7 +482,8 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
         s->mb_intra = 1;
         if (get_bits_left(&s->gb) <= 0)
             return AVERROR_INVALIDDATA;
-        code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
+        code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table,
+                        MSMP4_MB_INTRA_VLC_BITS, 2);
         /* predict coded block pattern */
         cbp = 0;
         for (i = 0; i < 6; i++) {
-- 
2.34.1



More information about the ffmpeg-devel mailing list