diff mbox series

[FFmpeg-devel,1/5] avcodec/mobiclip: Reduce size of VLCs, inline constants

Message ID 20201024110500.5424-1-andreas.rheinhardt@gmail.com
State Accepted
Commit c4229ad0749faa26a86b998deda1754e04ce77bb
Headers show
Series [FFmpeg-devel,1/5] avcodec/mobiclip: Reduce size of VLCs, inline constants
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Oct. 24, 2020, 11:04 a.m. UTC
The longest motion vector VLC for mobiclip is six bits long, so using
eight bits for the VLC table is wasteful. Furthermore, the length can be
inlined.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/mobiclip.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer Oct. 24, 2020, 12:35 p.m. UTC | #1
On Sat, Oct 24, 2020 at 01:04:56PM +0200, Andreas Rheinhardt wrote:
> The longest motion vector VLC for mobiclip is six bits long, so using
> eight bits for the VLC table is wasteful. Furthermore, the length can be
> inlined.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/mobiclip.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

probably ok

[...]
diff mbox series

Patch

diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c
index 48467614ab..8d37243d87 100644
--- a/libavcodec/mobiclip.c
+++ b/libavcodec/mobiclip.c
@@ -31,6 +31,8 @@ 
 #include "golomb.h"
 #include "internal.h"
 
+#define MOBI_MV_VLC_BITS 6
+
 static const uint8_t zigzag4x4_tab[] =
 {
     0x00, 0x04, 0x01, 0x02, 0x05, 0x08, 0x0C, 0x09, 0x06, 0x03, 0x07, 0x0A,
@@ -364,14 +366,14 @@  static av_cold int mobiclip_init(AVCodecContext *avctx)
     }
 
     for (int j = 0; j < 16; j++) {
-        ret = ff_init_vlc_sparse(&s->mv_vlc[0][j], 8, mv_len[j],
+        ret = ff_init_vlc_sparse(&s->mv_vlc[0][j], MOBI_MV_VLC_BITS, mv_len[j],
                                  mv_bits_mods[j],  sizeof(*mv_bits_mods[j]),  sizeof(*mv_bits_mods[j]),
                                  mv_codes_mods[j], sizeof(*mv_codes_mods[j]), sizeof(*mv_codes_mods[j]),
                                  mv_syms_mods[j],  sizeof(*mv_syms_mods[j]),  sizeof(*mv_syms_mods[j]), 0);
         if (ret < 0)
             return ret;
 
-        ret = ff_init_vlc_sparse(&s->mv_vlc[1][j], 8, mv_len[j],
+        ret = ff_init_vlc_sparse(&s->mv_vlc[1][j], MOBI_MV_VLC_BITS, mv_len[j],
                                  mv_bits[j],  sizeof(*mv_bits[j]),  sizeof(*mv_bits[j]),
                                  mv_codes[j], sizeof(*mv_codes[j]), sizeof(*mv_codes[j]),
                                  mv_syms[j],  sizeof(*mv_syms[j]),  sizeof(*mv_syms[j]), 0);
@@ -1259,7 +1261,7 @@  static int predict_motion(AVCodecContext *avctx,
             int ret, idx2;
 
             idx2 = get_vlc2(gb, s->mv_vlc[s->moflex][tidx].table,
-                            s->mv_vlc[s->moflex][tidx].bits, 1);
+                            MOBI_MV_VLC_BITS, 1);
             if (idx2 < 0)
                 return AVERROR_INVALIDDATA;
 
@@ -1335,7 +1337,7 @@  static int mobiclip_decode(AVCodecContext *avctx, void *data,
                 motion[x / 16 + 2].y = 0;
 
                 idx = get_vlc2(gb, s->mv_vlc[s->moflex][0].table,
-                                   s->mv_vlc[s->moflex][0].bits, 1);
+                                   MOBI_MV_VLC_BITS, 1);
                 if (idx < 0)
                     return AVERROR_INVALIDDATA;