[FFmpeg-devel] [PATCH 087/114] avcodec/vc1: Avoid code duplication when initializing VLCs

Jerome Borsboom jerome.borsboom at carpalis.nl
Wed Nov 18 16:08:05 EET 2020


I don't think it is a good idea to change the format of the table to 
something different than the tables in the SMPTE VC-1 documentation. 
People fluent in this documentation have a hard time correlating the new 
tables to the 'official' ones.

---
Regards,
Jerome

> This has been achieved by switching those VLCs that still used
> ff_init_vlc_sparse() to ff_init_vlc_lengths() even though the codes
> tables used uint8_t in these cases. But it allows to use one auxiliary
> function to initialize the VLCs and by using tables that interleave
> symbols and lengths said function only needs one parameter for the
> tables, not two. The only table that uses an uint16_t symbols table
> still has to be treated specially for this reason.
> 
> The offsets table has been removed as a byproduct of these changes.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavcodec/vc1.c     | 158 +++++++++++++++---------------------------
>  libavcodec/vc1data.c | 159 +++++++++++++++++++++----------------------
>  libavcodec/vc1data.h |  21 ++----
>  3 files changed, 138 insertions(+), 200 deletions(-)
> 
...
>  
>  /* 4MV Block pattern VLC tables */
> -const uint8_t ff_vc1_4mv_block_pattern_codes[4][16] = {
> -    { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27,  0, 28,  1,  2,  2 },
> -    {  8, 18, 19,  4, 20,  5, 30, 11, 21, 31,  6, 12,  7, 13, 14,  0 },
> -    { 15,  6,  7,  2,  8,  3, 28,  9, 10, 29,  4, 11,  5, 12, 13,  0 },
> -    {  0, 11, 12,  4, 13,  5, 30, 16, 14, 31,  6, 17,  7, 18, 19, 10 }
> -};
> -const uint8_t ff_vc1_4mv_block_pattern_bits[4][16] = {
> -    { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2 },
> -    { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2 },
> -    { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3 },
> -    { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4 }
> +const uint8_t ff_vc1_4mv_block_pattern_tabs[4][16][2] = {
> +    {
> +        { 0x0B, 3 }, { 0x0D, 3 }, { 0x0E, 3 }, { 0x04, 5 }, { 0x08, 5 },
> +        { 0x00, 5 }, { 0x06, 5 }, { 0x0F, 2 }, { 0x09, 5 }, { 0x03, 5 },
> +        { 0x05, 5 }, { 0x0A, 5 }, { 0x0C, 5 }, { 0x01, 6 }, { 0x02, 6 },
> +        { 0x07, 4 },
> +    },
> +    {
> +        { 0x0F, 2 }, { 0x03, 4 }, { 0x05, 4 }, { 0x0A, 4 }, { 0x0C, 4 },
> +        { 0x00, 4 }, { 0x01, 5 }, { 0x02, 5 }, { 0x04, 5 }, { 0x08, 5 },
> +        { 0x07, 4 }, { 0x0B, 4 }, { 0x0D, 4 }, { 0x0E, 4 }, { 0x06, 5 },
> +        { 0x09, 5 },
> +    },
> +    {
> +        { 0x0F, 3 }, { 0x03, 4 }, { 0x05, 4 }, { 0x0A, 4 }, { 0x0C, 4 },
> +        { 0x01, 4 }, { 0x02, 4 }, { 0x04, 4 }, { 0x07, 4 }, { 0x08, 4 },
> +        { 0x0B, 4 }, { 0x0D, 4 }, { 0x0E, 4 }, { 0x06, 5 }, { 0x09, 5 },
> +        { 0x00, 4 },
> +    },
> +    {
> +        { 0x00, 2 }, { 0x03, 4 }, { 0x05, 4 }, { 0x0A, 4 }, { 0x0C, 4 },
> +        { 0x07, 5 }, { 0x0B, 5 }, { 0x0D, 5 }, { 0x0E, 5 }, { 0x0F, 4 },
> +        { 0x01, 4 }, { 0x02, 4 }, { 0x04, 4 }, { 0x08, 4 }, { 0x06, 5 },
> +        { 0x09, 5 },
> +    },
>  };
>  
>  /* 2MV Block pattern VLC tables */
> -const uint8_t ff_vc1_2mv_block_pattern_codes[4][4] = {
> -    { 2, 1, 0, 3 }, { 1, 0, 2, 3 }, { 2, 0, 3, 1 }, { 1, 3, 2, 0 }
> -};
> -
> -const uint8_t ff_vc1_2mv_block_pattern_bits[4][4] = {
> -    { 2, 2, 2, 2 }, { 1, 2, 3, 3 }, { 3, 2, 3, 1 }, { 1, 3, 3, 2 }
> +const uint8_t ff_vc1_2mv_block_pattern_tabs[4][4][2] = {
> +    { { 0x02, 2 }, { 0x01, 2 }, { 0x00, 2 }, { 0x03, 2 } },
> +    { { 0x01, 2 }, { 0x02, 3 }, { 0x03, 3 }, { 0x00, 1 } },
> +    { { 0x01, 2 }, { 0x00, 3 }, { 0x02, 3 }, { 0x03, 1 } },
> +    { { 0x03, 2 }, { 0x02, 3 }, { 0x01, 3 }, { 0x00, 1 } },
>  };
>  
>  /* Interlaced frame picture 4MV MBMODE VLC tables (tables 160-163) */
> @@ -350,46 +349,42 @@ const uint8_t ff_vc1_intfr_non4mv_mbmode_tabs[4][9][2] = {
>  
>  /* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) */
>  /* mixed-MV */
> -const uint8_t ff_vc1_if_mmv_mbmode_codes[8][8] = {
> -    { 16, 17,  3,  3,  0,  5,  9,  2 },
> -    {  8,  9,  3,  6,  7,  0,  5,  2 },
> -    { 16, 17,  5,  3,  0,  3,  9,  2 },
> -    { 56, 57, 15,  4,  5,  6, 29,  0 },
> -    { 52, 53, 27, 14, 15,  2, 12,  0 },
> -    { 56, 57, 29,  5,  6,  0, 15,  4 },
> -    { 16, 17,  6,  7,  0,  1,  9,  5 },
> -    { 56, 57,  0,  5,  6, 29,  4, 15 }
> -};
> -const uint8_t ff_vc1_if_mmv_mbmode_bits[8][8] = {
> -    { 6, 6, 2, 3, 2, 4, 5, 2 },
> -    { 5, 5, 3, 3, 3, 2, 4, 2 },
> -    { 6, 6, 4, 3, 2, 2, 5, 2 },
> -    { 6, 6, 4, 3, 3, 3, 5, 1 },
> -    { 6, 6, 5, 4, 4, 2, 4, 1 },
> -    { 6, 6, 5, 3, 3, 1, 4, 3 },
> -    { 5, 5, 3, 3, 2, 2, 4, 3 },
> -    { 6, 6, 1, 3, 3, 5, 3, 4 }
> +const uint8_t ff_vc1_if_mmv_mbmode_tabs[8][8][2] = {
> +    { { 0x04, 2 }, { 0x00, 6 }, { 0x01, 6 }, { 0x06, 5 },
> +      { 0x05, 4 }, { 0x03, 3 }, { 0x07, 2 }, { 0x02, 2 } },
> +    { { 0x05, 2 }, { 0x00, 5 }, { 0x01, 5 }, { 0x06, 4 },
> +      { 0x02, 3 }, { 0x07, 2 }, { 0x03, 3 }, { 0x04, 3 } },
> +    { { 0x04, 2 }, { 0x00, 6 }, { 0x01, 6 }, { 0x06, 5 },
> +      { 0x02, 4 }, { 0x03, 3 }, { 0x07, 2 }, { 0x05, 2 } },
> +    { { 0x07, 1 }, { 0x03, 3 }, { 0x04, 3 }, { 0x05, 3 },
> +      { 0x00, 6 }, { 0x01, 6 }, { 0x06, 5 }, { 0x02, 4 } },
> +    { { 0x07, 1 }, { 0x05, 2 }, { 0x06, 4 }, { 0x00, 6 },
> +      { 0x01, 6 }, { 0x02, 5 }, { 0x03, 4 }, { 0x04, 4 } },
> +    { { 0x05, 1 }, { 0x07, 3 }, { 0x03, 3 }, { 0x04, 3 },
> +      { 0x00, 6 }, { 0x01, 6 }, { 0x02, 5 }, { 0x06, 4 } },
> +    { { 0x04, 2 }, { 0x05, 2 }, { 0x00, 5 }, { 0x01, 5 },
> +      { 0x06, 4 }, { 0x07, 3 }, { 0x02, 3 }, { 0x03, 3 } },
> +    { { 0x02, 1 }, { 0x06, 3 }, { 0x03, 3 }, { 0x04, 3 },
> +      { 0x00, 6 }, { 0x01, 6 }, { 0x05, 5 }, { 0x07, 4 } },
>  };
>  /* 1MV */
> -const uint8_t ff_vc1_if_1mv_mbmode_codes[8][6] = {
> -    {  0,  1,  1,  1,  1,  1 },
> -    {  0,  1,  1,  1,  1,  1 },
> -    { 16, 17,  3,  0,  9,  5 },
> -    { 20, 21,  3, 11,  0,  4 },
> -    {  4,  5,  2,  3,  3,  0 },
> -    {  4,  5,  3,  2,  0,  3 },
> -    {  0,  1,  1,  1,  1,  1 },
> -    { 16, 17,  9,  5,  3,  0 }
> -};
> -const uint8_t ff_vc1_if_1mv_mbmode_bits[8][6] = {
> -    { 5, 5, 1, 3, 2, 4 },
> -    { 5, 5, 1, 2, 3, 4 },
> -    { 5, 5, 2, 1, 4, 3 },
> -    { 5, 5, 2, 4, 1, 3 },
> -    { 4, 4, 2, 3, 2, 2 },
> -    { 4, 4, 3, 2, 2, 2 },
> -    { 5, 5, 3, 4, 1, 2 },
> -    { 5, 5, 4, 3, 2, 1 }
> +const uint8_t ff_vc1_if_1mv_mbmode_tabs[8][6][2] = {
> +    { { 0x00, 5 }, { 0x01, 5 }, { 0x05, 4 },
> +      { 0x03, 3 }, { 0x04, 2 }, { 0x02, 1 } },
> +    { { 0x00, 5 }, { 0x01, 5 }, { 0x05, 4 },
> +      { 0x04, 3 }, { 0x03, 2 }, { 0x02, 1 } },
> +    { { 0x03, 1 }, { 0x00, 5 }, { 0x01, 5 },
> +      { 0x04, 4 }, { 0x05, 3 }, { 0x02, 2 } },
> +    { { 0x04, 1 }, { 0x05, 3 }, { 0x00, 5 },
> +      { 0x01, 5 }, { 0x03, 4 }, { 0x02, 2 } },
> +    { { 0x05, 2 }, { 0x00, 4 }, { 0x01, 4 },
> +      { 0x03, 3 }, { 0x02, 2 }, { 0x04, 2 } },
> +    { { 0x04, 2 }, { 0x00, 4 }, { 0x01, 4 },
> +      { 0x02, 3 }, { 0x03, 2 }, { 0x05, 2 } },
> +    { { 0x00, 5 }, { 0x01, 5 }, { 0x03, 4 },
> +      { 0x02, 3 }, { 0x05, 2 }, { 0x04, 1 } },
> +    { { 0x05, 1 }, { 0x00, 5 }, { 0x01, 5 },
> +      { 0x02, 4 }, { 0x03, 3 }, { 0x04, 2 } },
>  };
...
> -- 
> 2.25.1




More information about the ffmpeg-devel mailing list