summaryrefslogtreecommitdiff
path: root/libavcodec/vp3.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-06 10:48:55 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-08 17:51:47 +0100
commit802fc678b262ea5d3523169184a9ec9503bf7807 (patch)
tree2444a0e4deb047af9fcad17be9dac12a4021d76b /libavcodec/vp3.c
parent4cb4345f7895d1a169941df087152bf18f78a2f6 (diff)
avcodec/vp3: Use symbols table for VP3 motion vectors
Expressions like array[get_vlc2()] can be optimized by using a symbols table if the array is always the same for a given VLC. This requirement is fulfilled for the VLC used for VP3 motion vectors. The reason it hasn't been done before is probably that the array in this case contained entries in the range -31..31; but this is no problem with ff_init_vlc_from_lengths(): Just apply an offset of 31 to the symbols before storing them in the table used to initialize VP3 motion vectors and apply an offset of -31 when initializing the actual VLC. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/vp3.c')
-rw-r--r--libavcodec/vp3.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 7d1d2411ab..2f43de757e 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -48,6 +48,7 @@
#include "vp3dsp.h"
#include "xiph.h"
+#define VP3_MV_VLC_BITS 6
#define VP4_MV_VLC_BITS 6
#define SUPERBLOCK_VLC_BITS 6
@@ -946,8 +947,10 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
case MODE_INTER_PLUS_MV:
/* all 6 fragments use the same motion vector */
if (coding_mode == 0) {
- motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
- motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
+ motion_x[0] = get_vlc2(gb, s->motion_vector_vlc.table,
+ VP3_MV_VLC_BITS, 2);
+ motion_y[0] = get_vlc2(gb, s->motion_vector_vlc.table,
+ VP3_MV_VLC_BITS, 2);
} else if (coding_mode == 1) {
motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)];
motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)];
@@ -976,8 +979,10 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
current_fragment = BLOCK_Y * s->fragment_width[0] + BLOCK_X;
if (s->all_fragments[current_fragment].coding_method != MODE_COPY) {
if (coding_mode == 0) {
- motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
- motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
+ motion_x[k] = get_vlc2(gb, s->motion_vector_vlc.table,
+ VP3_MV_VLC_BITS, 2);
+ motion_y[k] = get_vlc2(gb, s->motion_vector_vlc.table,
+ VP3_MV_VLC_BITS, 2);
} else if (coding_mode == 1) {
motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)];
motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)];
@@ -2479,9 +2484,11 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
if (ret < 0)
return ret;
- if ((ret = init_vlc(&s->motion_vector_vlc, 6, 63,
- &motion_vector_vlc_table[0][1], 2, 1,
- &motion_vector_vlc_table[0][0], 2, 1, 0)) < 0)
+ ret = ff_init_vlc_from_lengths(&s->motion_vector_vlc, VP3_MV_VLC_BITS, 63,
+ &motion_vector_vlc_table[0][1], 2,
+ &motion_vector_vlc_table[0][0], 2, 1,
+ -31, 0, avctx);
+ if (ret < 0)
return ret;
#if CONFIG_VP4_DECODER