[FFmpeg-devel] [PATCH v2 097/162] avcodec/vc1: Use symbols table for VLC for Block-level Transform Type
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Fri Nov 20 09:20:10 EET 2020
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 for the Block-level Transform Type and
therefore this commit implements this; switching from
ff_init_vlc_sparse() to ff_init_vlc_from_lengths() means that we can
also remove the codes table in the process which had the same size as
the new symbols table; the array used to translate the get_vlc2() values
to the desired form has also been removed, saving space.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavcodec/vc1.c | 7 ++++---
libavcodec/vc1_block.c | 2 +-
libavcodec/vc1data.c | 30 +++++++++++++-----------------
libavcodec/vc1data.h | 9 +++------
4 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index d973fd6c57..8c8387b7fb 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -1611,9 +1611,10 @@ av_cold int ff_vc1_init_common(VC1Context *v)
ff_vc1_ttmb_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 1]];
ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i * 3 + 2] - vlc_offs[i * 3 + 1];
- init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,
- ff_vc1_ttblk_bits[i], 1, 1,
- ff_vc1_ttblk_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
+ ff_init_vlc_from_lengths(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,
+ &ff_vc1_ttblk_tabs[i][0][1], 2,
+ &ff_vc1_ttblk_tabs[i][0][0], 2, 1,
+ 0, INIT_VLC_USE_NEW_STATIC, NULL);
ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 2]];
ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i * 3 + 3] - vlc_offs[i * 3 + 2];
ff_init_vlc_from_lengths(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index b8987b0015..da58a0738f 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -1140,7 +1140,7 @@ static int vc1_decode_p_block(VC1Context *v, int16_t block[64], int n,
s->bdsp.clear_block(block);
if (ttmb == -1) {
- ttblk = ff_vc1_ttblk_to_tt[v->tt_index][get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
+ ttblk = get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1);
}
if (ttblk == TT_4X4) {
subblkpat = ~get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1);
diff --git a/libavcodec/vc1data.c b/libavcodec/vc1data.c
index e92d9b7310..ed5e680527 100644
--- a/libavcodec/vc1data.c
+++ b/libavcodec/vc1data.c
@@ -30,13 +30,6 @@
#include "vc1.h"
#include "vc1data.h"
-/** Table for conversion between TTBLK and TTMB */
-const int ff_vc1_ttblk_to_tt[3][8] = {
- { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT },
- { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP },
- { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP }
-};
-
const int ff_vc1_ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 };
/** MV P mode - the 5th element is only used for mode 1 */
@@ -908,17 +901,20 @@ const uint8_t ff_vc1_ttmb_bits[3][16] = {
11
}
};
-
/* TTBLK (Transform Type per Block) tables */
-const uint8_t ff_vc1_ttblk_codes[3][8] = {
- { 0, 1, 3, 5, 16, 17, 18, 19 },
- { 3, 0, 1, 2, 3, 5, 8, 9 },
- { 1, 0, 1, 4, 6, 7, 10, 11 }
-};
-const uint8_t ff_vc1_ttblk_bits[3][8] = {
- { 2, 2, 2, 3, 5, 5, 5, 5 },
- { 2, 3, 3, 3, 3, 3, 4, 4 },
- { 2, 3, 3, 3, 3, 3, 4, 4 }
+const uint8_t ff_vc1_ttblk_tabs[3][8][2] = {
+ {
+ { TT_8X4, 2 }, { TT_4X8, 2 }, { TT_8X4_TOP, 5 }, { TT_8X4_BOTTOM, 5 },
+ { TT_4X8_RIGHT, 5 }, { TT_4X8_LEFT, 5 }, { TT_4X4, 3 }, { TT_8X8, 2 },
+ },
+ {
+ { TT_4X8_RIGHT, 3 }, { TT_4X8_LEFT, 3 }, { TT_4X4, 3 }, { TT_8X4, 3 },
+ { TT_8X4_BOTTOM, 4 }, { TT_8X4_TOP, 4 }, { TT_4X8, 3 }, { TT_8X8, 2 },
+ },
+ {
+ { TT_4X8, 3 }, { TT_4X4, 3 }, { TT_8X8, 2 }, { TT_8X4_BOTTOM, 3 },
+ { TT_8X4, 4 }, { TT_8X4_TOP, 4 }, { TT_4X8_RIGHT, 3 }, { TT_4X8_LEFT, 3 },
+ },
};
/* SUBBLKPAT tables, p93-94, reordered and offset by 1 */
diff --git a/libavcodec/vc1data.h b/libavcodec/vc1data.h
index 02603ca9bc..9c6ac7370b 100644
--- a/libavcodec/vc1data.h
+++ b/libavcodec/vc1data.h
@@ -34,9 +34,6 @@
#include "vlc.h"
-/** Table for conversion between TTBLK and TTMB */
-extern const int ff_vc1_ttblk_to_tt[3][8];
-
extern const int ff_vc1_ttfrm_to_tt[4];
/** MV P mode - the 5th element is only used for mode 1 */
@@ -148,9 +145,9 @@ extern const uint16_t ff_vc1_ttmb_codes[3][16];
extern const uint8_t ff_vc1_ttmb_bits[3][16];
-/* TTBLK (Transform Type per Block) tables */
-extern const uint8_t ff_vc1_ttblk_codes[3][8];
-extern const uint8_t ff_vc1_ttblk_bits[3][8];
+/* TTBLK (Transform Type per Block) tables (tables #62-#64).
+ * The symbols contain enum TransformTypes (TT_*) values. */
+extern const uint8_t ff_vc1_ttblk_tabs[3][8][2];
/* SUBBLKPAT tables (tables #65-#67).
* The symbols contain the Subblock Pattern. */
--
2.25.1
More information about the ffmpeg-devel
mailing list