[FFmpeg-cvslog] avcodec/mpeg12dec: Use VLC symbol table

Andreas Rheinhardt git at videolan.org
Thu Jun 20 19:59:41 EEST 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Jun  3 05:07:44 2024 +0200| [010951239c6de2d32d6572d1390cdaf8f6c63452] | committer: Andreas Rheinhardt

avcodec/mpeg12dec: Use VLC symbol table

Possible by using MB_TYPE_CODEC_SPECIFIC for MB_TYPE_ZERO_MV
and due to the MB_TYPE_*_MV flags fitting into an int16_t.

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

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

 libavcodec/mpeg12.c    | 42 +++++++++++++++++++++++++++++++++---------
 libavcodec/mpeg12dec.c | 28 ----------------------------
 libavcodec/mpeg12dec.h |  2 ++
 3 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 62d7fd1814..444ea83f3c 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -31,14 +31,12 @@
 #include "libavutil/avassert.h"
 #include "libavutil/thread.h"
 
-#include "avcodec.h"
 #include "mpegvideo.h"
-#include "mpeg12.h"
 #include "mpeg12codecs.h"
 #include "mpeg12data.h"
 #include "mpeg12dec.h"
+#include "mpegutils.h"
 #include "rl.h"
-#include "startcode.h"
 
 static const uint8_t table_mb_ptype[7][2] = {
     { 3, 5 }, // 0x01 MB_INTRA
@@ -64,6 +62,30 @@ static const uint8_t table_mb_btype[11][2] = {
     { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT
 };
 
+static const int16_t ptype2mb_type[7] = {
+                    MB_TYPE_INTRA,
+                    MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+                    MB_TYPE_FORWARD_MV,
+                    MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
+    MB_TYPE_QUANT | MB_TYPE_INTRA,
+    MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+    MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
+};
+
+static const int16_t btype2mb_type[11] = {
+                    MB_TYPE_INTRA,
+                    MB_TYPE_BACKWARD_MV,
+                    MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
+                    MB_TYPE_FORWARD_MV,
+                    MB_TYPE_FORWARD_MV  | MB_TYPE_CBP,
+                    MB_TYPE_BIDIR_MV,
+                    MB_TYPE_BIDIR_MV    | MB_TYPE_CBP,
+    MB_TYPE_QUANT | MB_TYPE_INTRA,
+    MB_TYPE_QUANT | MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
+    MB_TYPE_QUANT | MB_TYPE_FORWARD_MV  | MB_TYPE_CBP,
+    MB_TYPE_QUANT | MB_TYPE_BIDIR_MV    | MB_TYPE_CBP,
+};
+
 av_cold void ff_init_2d_vlc_rl(const uint16_t table_vlc[][2], RL_VLC_ELEM rl_vlc[],
                                const int8_t table_run[], const uint8_t table_level[],
                                int n, unsigned static_size, int flags)
@@ -146,12 +168,14 @@ static av_cold void mpeg12_init_vlcs(void)
                           &ff_mpeg12_mbPatTable[0][1], 2, 1,
                           &ff_mpeg12_mbPatTable[0][0], 2, 1, 0);
 
-    VLC_INIT_STATIC_TABLE(ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
-                          &table_mb_ptype[0][1], 2, 1,
-                          &table_mb_ptype[0][0], 2, 1, 0);
-    VLC_INIT_STATIC_TABLE(ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
-                          &table_mb_btype[0][1], 2, 1,
-                          &table_mb_btype[0][0], 2, 1, 0);
+    VLC_INIT_STATIC_SPARSE_TABLE(ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
+                                 &table_mb_ptype[0][1], 2, 1,
+                                 &table_mb_ptype[0][0], 2, 1,
+                                 ptype2mb_type, 2, 2, 0);
+    VLC_INIT_STATIC_SPARSE_TABLE(ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
+                                 &table_mb_btype[0][1], 2, 1,
+                                 &table_mb_btype[0][0], 2, 1,
+                                 btype2mb_type, 2, 2, 0);
 
     ff_init_2d_vlc_rl(ff_mpeg1_vlc_table, ff_mpeg1_rl_vlc, ff_mpeg12_run,
                       ff_mpeg12_level, MPEG12_RL_NB_ELEMS,
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 601106138e..e0e9a8fb1e 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -93,32 +93,6 @@ typedef struct Mpeg1Context {
     int64_t timecode_frame_start;  /*< GOP timecode frame start number, in non drop frame format */
 } Mpeg1Context;
 
-#define MB_TYPE_ZERO_MV   0x20000000
-
-static const uint32_t ptype2mb_type[7] = {
-                    MB_TYPE_INTRA,
-                    MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
-                    MB_TYPE_FORWARD_MV,
-                    MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
-    MB_TYPE_QUANT | MB_TYPE_INTRA,
-    MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
-    MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
-};
-
-static const uint32_t btype2mb_type[11] = {
-                    MB_TYPE_INTRA,
-                    MB_TYPE_BACKWARD_MV,
-                    MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
-                    MB_TYPE_FORWARD_MV,
-                    MB_TYPE_FORWARD_MV  | MB_TYPE_CBP,
-                    MB_TYPE_BIDIR_MV,
-                    MB_TYPE_BIDIR_MV    | MB_TYPE_CBP,
-    MB_TYPE_QUANT | MB_TYPE_INTRA,
-    MB_TYPE_QUANT | MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
-    MB_TYPE_QUANT | MB_TYPE_FORWARD_MV  | MB_TYPE_CBP,
-    MB_TYPE_QUANT | MB_TYPE_BIDIR_MV    | MB_TYPE_CBP,
-};
-
 /* as H.263, but only 17 codes */
 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
 {
@@ -483,7 +457,6 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
                    "Invalid mb type in P-frame at %d %d\n", s->mb_x, s->mb_y);
             return AVERROR_INVALIDDATA;
         }
-        mb_type = ptype2mb_type[mb_type];
         break;
     case AV_PICTURE_TYPE_B:
         mb_type = get_vlc2(&s->gb, ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 1);
@@ -492,7 +465,6 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
                    "Invalid mb type in B-frame at %d %d\n", s->mb_x, s->mb_y);
             return AVERROR_INVALIDDATA;
         }
-        mb_type = btype2mb_type[mb_type];
         break;
     }
     ff_tlog(s->avctx, "mb_type=%x\n", mb_type);
diff --git a/libavcodec/mpeg12dec.h b/libavcodec/mpeg12dec.h
index 4641179149..79809b7c3e 100644
--- a/libavcodec/mpeg12dec.h
+++ b/libavcodec/mpeg12dec.h
@@ -25,6 +25,8 @@
 #include "get_bits.h"
 #include "mpeg12vlc.h"
 
+#define MB_TYPE_ZERO_MV   MB_TYPE_CODEC_SPECIFIC
+
 static inline int decode_dc(GetBitContext *gb, int component)
 {
     int code, diff;



More information about the ffmpeg-cvslog mailing list