[FFmpeg-devel] [PATCH 05/39] avcodec/mpeg12enc, speedhqenc: Avoid redundant copies of tables

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Thu Dec 10 13:16:23 EET 2020


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavcodec/mpeg12enc.c  | 12 ++----------
 libavcodec/speedhqenc.c | 12 ++----------
 2 files changed, 4 insertions(+), 20 deletions(-)

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 05fd8c0e00..5cbcb15630 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -60,9 +60,6 @@ static uint8_t uni_mpeg2_ac_vlc_len[64 * 64 * 2];
 static uint32_t mpeg1_lum_dc_uni[512];
 static uint32_t mpeg1_chr_dc_uni[512];
 
-static uint8_t mpeg1_index_run[2][64];
-static int8_t  mpeg1_max_level[2][64];
-
 #define A53_MAX_CC_COUNT 0x1f
 
 static av_cold void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len)
@@ -718,8 +715,8 @@ next_coef:
             MASK_ABS(sign, alevel);
             sign &= 1;
 
-            if (alevel <= mpeg1_max_level[0][run]) {
-                code = mpeg1_index_run[0][run] + alevel - 1;
+            if (alevel <= ff_rl_mpeg1.max_level[0][run]) {
+                code = ff_rl_mpeg1.index_run[0][run] + alevel - 1;
                 /* store the VLC & sign at once */
                 put_bits(&s->pb, table_vlc[code][1] + 1,
                          (table_vlc[code][0] << 1) + sign);
@@ -1042,11 +1039,6 @@ static av_cold void mpeg12_encode_init_static(void)
     ff_rl_init(&ff_rl_mpeg1, mpeg12_static_rl_table_store[0]);
     ff_rl_init(&ff_rl_mpeg2, mpeg12_static_rl_table_store[1]);
 
-    for (int i = 0; i < 64; i++) {
-        mpeg1_max_level[0][i] = ff_rl_mpeg1.max_level[0][i];
-        mpeg1_index_run[0][i] = ff_rl_mpeg1.index_run[0][i];
-    }
-
     init_uni_ac_vlc(&ff_rl_mpeg1, uni_mpeg1_ac_vlc_len);
     init_uni_ac_vlc(&ff_rl_mpeg2, uni_mpeg2_ac_vlc_len);
 
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 3bda2a8453..9807024980 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -46,9 +46,6 @@ static uint16_t mpeg12_vlc_dc_chroma_code_reversed[12];
 static uint32_t speedhq_lum_dc_uni[512];
 static uint32_t speedhq_chr_dc_uni[512];
 
-static uint8_t speedhq_index_run[2][64];
-static int8_t  speedhq_max_level[2][64];
-
 static uint8_t uni_speedhq_ac_vlc_len[64 * 64 * 2];
 
 static uint32_t reverse(uint32_t num, int bits)
@@ -77,11 +74,6 @@ static av_cold void speedhq_init_static_data(void)
 
     ff_rl_init(&ff_rl_speedhq, speedhq_static_rl_table_store);
 
-    for (int i = 0; i < 64; i++) {
-        speedhq_max_level[0][i] = ff_rl_speedhq.max_level[0][i];
-        speedhq_index_run[0][i] = ff_rl_speedhq.index_run[0][i];
-    }
-
     /* build unified dc encoding tables */
     for (int i = -255; i < 256; i++) {
         int adiff, index;
@@ -231,8 +223,8 @@ static void encode_block(MpegEncContext *s, int16_t *block, int n)
             MASK_ABS(sign, alevel);
             sign &= 1;
 
-            if (alevel <= speedhq_max_level[0][run]) {
-                code = speedhq_index_run[0][run] + alevel - 1;
+            if (alevel <= ff_rl_speedhq.max_level[0][run]) {
+                code = ff_rl_speedhq.index_run[0][run] + alevel - 1;
                 /* store the VLC & sign at once */
                 put_bits_le(&s->pb, ff_rl_speedhq.table_vlc[code][1] + 1,
                             ff_rl_speedhq.table_vlc[code][0] + (sign << ff_rl_speedhq.table_vlc[code][1]));
-- 
2.25.1



More information about the ffmpeg-devel mailing list