[FFmpeg-devel] [PATCH 05/17] avcodec/mpeg12enc: Avoid unnecessary indirection

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sun Oct 23 22:35:58 EEST 2022


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/mpeg12data.c | 8 ++++----
 libavcodec/mpeg12enc.c  | 4 ++--
 libavcodec/mpeg12vlc.h  | 5 +++++
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mpeg12data.c b/libavcodec/mpeg12data.c
index e301310b9f..398f70dd8a 100644
--- a/libavcodec/mpeg12data.c
+++ b/libavcodec/mpeg12data.c
@@ -64,7 +64,7 @@ const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12] = {
     2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
 };
 
-static const uint16_t mpeg1_vlc[113][2] = {
+const uint16_t ff_mpeg1_vlc_table[MPEG12_RL_NB_ELEMS + 2][2] = {
  { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
  { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },
  { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 },
@@ -97,7 +97,7 @@ static const uint16_t mpeg1_vlc[113][2] = {
  { 0x2, 2 }, /* EOB */
 };
 
-static const uint16_t mpeg2_vlc[113][2] = {
+const uint16_t ff_mpeg2_vlc_table[MPEG12_RL_NB_ELEMS + 2][2] = {
   {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
   {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
   {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
@@ -167,7 +167,7 @@ static const int8_t mpeg1_run[111] = {
 RLTable ff_rl_mpeg1 = {
     111,
     111,
-    mpeg1_vlc,
+    ff_mpeg1_vlc_table,
     mpeg1_run,
     mpeg1_level,
 };
@@ -175,7 +175,7 @@ RLTable ff_rl_mpeg1 = {
 RLTable ff_rl_mpeg2 = {
     111,
     111,
-    mpeg2_vlc,
+    ff_mpeg2_vlc_table,
     mpeg1_run,
     mpeg1_level,
 };
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index c3df924b64..5d991ac99e 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -709,7 +709,7 @@ static void mpeg1_encode_block(MpegEncContext *s, int16_t *block, int n)
 {
     int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign;
     int code, component;
-    const uint16_t (*table_vlc)[2] = ff_rl_mpeg1.table_vlc;
+    const uint16_t (*table_vlc)[2] = ff_mpeg1_vlc_table;
 
     last_index = s->block_last_index[n];
 
@@ -722,7 +722,7 @@ static void mpeg1_encode_block(MpegEncContext *s, int16_t *block, int n)
         s->last_dc[component] = dc;
         i = 1;
         if (s->intra_vlc_format)
-            table_vlc = ff_rl_mpeg2.table_vlc;
+            table_vlc = ff_mpeg2_vlc_table;
     } else {
         /* encode the first coefficient: needs to be done here because
          * it is handled slightly differently */
diff --git a/libavcodec/mpeg12vlc.h b/libavcodec/mpeg12vlc.h
index d0083f1124..c810697370 100644
--- a/libavcodec/mpeg12vlc.h
+++ b/libavcodec/mpeg12vlc.h
@@ -53,9 +53,14 @@ void ff_mpeg12_init_vlcs(void);
 #define INIT_2D_VLC_RL(rl, rl_vlc, flags)\
     ff_init_2d_vlc_rl(&rl, rl_vlc, FF_ARRAY_ELEMS(rl_vlc), flags)
 
+#define MPEG12_RL_NB_ELEMS 111
+
 extern RLTable ff_rl_mpeg1;
 extern RLTable ff_rl_mpeg2;
 
+extern const uint16_t ff_mpeg1_vlc_table[MPEG12_RL_NB_ELEMS + 2][2];
+extern const uint16_t ff_mpeg2_vlc_table[MPEG12_RL_NB_ELEMS + 2][2];
+
 extern RL_VLC_ELEM ff_mpeg1_rl_vlc[];
 extern RL_VLC_ELEM ff_mpeg2_rl_vlc[];
 
-- 
2.34.1



More information about the ffmpeg-devel mailing list