Re: [FFmpeg-devel] [PATCH 100/114] avcodec/vp3: Use symbols table for VP3 motion vectors

2020-11-15 Thread Peter Ross
On Sun, Nov 15, 2020 at 06:37:25AM +0100, Andreas Rheinhardt wrote:
> Peter Ross:
> > On Tue, Nov 10, 2020 at 11:58:22AM +0100, Andreas Rheinhardt wrote:
> >> 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 
> >> ---
> >>  libavcodec/vp3.c | 20 ---
> >>  libavcodec/vp3data.h | 46 +++-
> >>  2 files changed, 24 insertions(+), 42 deletions(-)
> >>
> >> diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> >> index 7037d03a98..f288a53fe1 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
> > 
> > or just use '#define MV_VLC_BITS 6'
> > 
> This patch has to modify all the lines that use the motion_vector_vlc
> VLC table, so using a named constant can be easily done while at it;
> this is no longer true when also changing VP4. Furthermore, there is no
> a-priori reason why it should forever be so that both of these are six
> (the longest VP3 MV code is only eight bits long, which is not
> excessive; I pondered changing it, but decided that it is outside the
> remit of this patchset).

I agree with your reasoning. Cheers,

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 100/114] avcodec/vp3: Use symbols table for VP3 motion vectors

2020-11-14 Thread Andreas Rheinhardt
Peter Ross:
> On Tue, Nov 10, 2020 at 11:58:22AM +0100, Andreas Rheinhardt wrote:
>> 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 
>> ---
>>  libavcodec/vp3.c | 20 ---
>>  libavcodec/vp3data.h | 46 +++-
>>  2 files changed, 24 insertions(+), 42 deletions(-)
>>
>> diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
>> index 7037d03a98..f288a53fe1 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
> 
> or just use '#define MV_VLC_BITS 6'
> 
This patch has to modify all the lines that use the motion_vector_vlc
VLC table, so using a named constant can be easily done while at it;
this is no longer true when also changing VP4. Furthermore, there is no
a-priori reason why it should forever be so that both of these are six
(the longest VP3 MV code is only eight bits long, which is not
excessive; I pondered changing it, but decided that it is outside the
remit of this patchset). But if you want to, I can use one constant for
both.

- Andreas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 100/114] avcodec/vp3: Use symbols table for VP3 motion vectors

2020-11-14 Thread Peter Ross
On Tue, Nov 10, 2020 at 11:58:22AM +0100, Andreas Rheinhardt wrote:
> 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 
> ---
>  libavcodec/vp3.c | 20 ---
>  libavcodec/vp3data.h | 46 +++-
>  2 files changed, 24 insertions(+), 42 deletions(-)
> 
> diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> index 7037d03a98..f288a53fe1 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

or just use '#define MV_VLC_BITS 6'

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 100/114] avcodec/vp3: Use symbols table for VP3 motion vectors

2020-11-10 Thread Andreas Rheinhardt
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 
---
 libavcodec/vp3.c | 20 ---
 libavcodec/vp3data.h | 46 +++-
 2 files changed, 24 insertions(+), 42 deletions(-)

diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 7037d03a98..f288a53fe1 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)];
@@ -2477,9 +2482,10 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
 if (ret < 0)
 return ret;
 
-if ((ret = init_vlc(>motion_vector_vlc, 6, 63,
-_vector_vlc_table[0][1], 2, 1,
-_vector_vlc_table[0][0], 2, 1, 0)) < 0)
+ret = ff_init_vlc_from_lengths(>motion_vector_vlc, VP3_MV_VLC_BITS, 63,
+   _vector_vlc_table[0][1], 2,
+   _vector_vlc_table[0][0], 2, 1, -31, 
0);
+if (ret < 0)
 return ret;
 
 #if CONFIG_VP4_DECODER
diff --git a/libavcodec/vp3data.h b/libavcodec/vp3data.h
index eb516a0add..901850bd75 100644
--- a/libavcodec/vp3data.h
+++ b/libavcodec/vp3data.h
@@ -112,41 +112,17 @@ static const uint8_t mode_code_vlc_len[8] = {
 };
 
 static const uint8_t motion_vector_vlc_table[63][2] = {
-{0, 3 },
-{1, 3 },
-{2, 3 },
-
-{6, 4 }, {7, 4 },
-
-{8, 4 }, {9, 4 },
-
-{   40, 6 }, {   41, 6 }, {   42, 6 }, {   43, 6 },
-{   44, 6 }, {   45, 6 }, {   46, 6 }, {   47, 6 },
-
-{   96, 7 }, {   97, 7 }, {   98, 7 }, {   99, 7 },
-{  100, 7 }, {  101, 7 }, {  102, 7 }, {  103, 7 },
-{  104, 7 }, {  105, 7 }, {  106, 7 }, {  107, 7 },
-{  108, 7 }, {  109, 7 }, {  110, 7 }, {  111, 7 },
-
-{ 0xE0, 8 }, { 0xE1, 8 }, { 0xE2, 8 }, { 0xE3, 8 },
-{ 0xE4, 8 }, { 0xE5, 8 }, { 0xE6, 8 }, { 0xE7, 8 },
-{ 0xE8, 8 }, { 0xE9, 8 }, { 0xEA, 8 }, { 0xEB, 8 },
-{ 0xEC, 8 }, { 0xED, 8 }, { 0xEE, 8 }, { 0xEF, 8 },
-
-{ 0xF0, 8 }, { 0xF1, 8 }, { 0xF2, 8 }, { 0xF3, 8 },
-{ 0xF4, 8 }, { 0xF5, 8 }, { 0xF6, 8 }, { 0xF7, 8 },
-{ 0xF8, 8 }, { 0xF9, 8 }, { 0xFA, 8 }, { 0xFB, 8 },
-{ 0xFC, 8 }, { 0xFD, 8 }, { 0xFE, 8 }, { 0xFF, 8 }
-};
-
-static const int8_t motion_vector_table[63] = {
-