[FFmpeg-cvslog] avcodec/rv10: Avoid indirection when reading VLC codes

Andreas Rheinhardt git at videolan.org
Sat Jun 21 23:20:20 EEST 2025


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun May 25 17:35:56 2025 +0200| [01d6235faefb5e78e0a8f034525470e77df92d8b] | committer: Andreas Rheinhardt

avcodec/rv10: Avoid indirection when reading VLC codes

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

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

 libavcodec/rv10.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 7f7f7aeba2..9f4dea6141 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -78,16 +78,16 @@ static const uint16_t rv_chrom_len_count[15] = {
     1,  2,  4,  0,  8,  0, 16,  0, 32,  0,  64,  0, 128,  0, 256,
 };
 
-static VLC rv_dc_lum, rv_dc_chrom;
+static VLCElem rv_dc_lum[1472], rv_dc_chrom[992];
 
 int ff_rv_decode_dc(MpegEncContext *s, int n)
 {
     int code;
 
     if (n < 4) {
-        code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2);
+        code = get_vlc2(&s->gb, rv_dc_lum, DC_VLC_BITS, 2);
     } else {
-        code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2);
+        code = get_vlc2(&s->gb, rv_dc_chrom, DC_VLC_BITS, 2);
         if (code < 0) {
             av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
             return -1;
@@ -306,7 +306,8 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
     return s->mb_width * s->mb_height - mb_pos;
 }
 
-static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15],
+static av_cold void rv10_build_vlc(VLCElem vlc[], int table_size,
+                                   const uint16_t len_count[15],
                                    const uint8_t sym_rl[][2], int sym_rl_elems)
 {
     uint16_t syms[MAX_VLC_ENTRIES];
@@ -323,32 +324,26 @@ static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15],
         for (unsigned tmp = nb_lens + len_count[i]; nb_lens < tmp; nb_lens++)
             lens[nb_lens] = i + 2;
     av_assert1(nb_lens == nb_syms);
-    ff_vlc_init_from_lengths(vlc, DC_VLC_BITS, nb_lens, lens, 1,
-                             syms, 2, 2, 0, VLC_INIT_STATIC_OVERLONG, NULL);
+    ff_vlc_init_table_from_lengths(vlc, table_size, DC_VLC_BITS, nb_lens,
+                                   lens, 1, syms, 2, 2, 0, 0);
 }
 
 static av_cold void rv10_init_static(void)
 {
-    static VLCElem table[1472 + 992];
-
-    rv_dc_lum.table             = table;
-    rv_dc_lum.table_allocated   = 1472;
-    rv10_build_vlc(&rv_dc_lum, rv_lum_len_count,
+    rv10_build_vlc(rv_dc_lum, FF_ARRAY_ELEMS(rv_dc_lum), rv_lum_len_count,
                    rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len));
     for (int i = 0; i < 1 << (DC_VLC_BITS - 7 /* Length of skip prefix */); i++) {
         /* All codes beginning with 0x7F have the same length and value.
          * Modifying the table directly saves us the useless subtables. */
-        rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i].sym = 255;
-        rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i].len = 18;
+        rv_dc_lum[(0x7F << (DC_VLC_BITS - 7)) + i].sym = 255;
+        rv_dc_lum[(0x7F << (DC_VLC_BITS - 7)) + i].len = 18;
     }
-    rv_dc_chrom.table           = &table[1472];
-    rv_dc_chrom.table_allocated = 992;
-    rv10_build_vlc(&rv_dc_chrom, rv_chrom_len_count,
+    rv10_build_vlc(rv_dc_chrom, FF_ARRAY_ELEMS(rv_dc_chrom), rv_chrom_len_count,
                    rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len) - 2);
     for (int i = 0; i < 1 << (DC_VLC_BITS - 9 /* Length of skip prefix */); i++) {
         /* Same as above. */
-        rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i].sym = 255;
-        rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i].len = 18;
+        rv_dc_chrom[(0x1FE << (DC_VLC_BITS - 9)) + i].sym = 255;
+        rv_dc_chrom[(0x1FE << (DC_VLC_BITS - 9)) + i].len = 18;
     }
 }
 



More information about the ffmpeg-cvslog mailing list