[FFmpeg-devel] [PATCH v2 096/162] avcodec/vc1: Already offset subblock VLC tables during init

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Fri Nov 20 09:20:09 EET 2020


Offseting by +1 is possible without adding dummy elements to the
beginning of the codes and lengths tables by switching to
ff_init_vlc_from_lengths() as this allows one to set the symbols
arbitrarily without incurring any penalty.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
All the VC1 patches have improved documentation on what the symbols
actually contain.

 libavcodec/vc1.c       |  7 ++++---
 libavcodec/vc1_block.c |  2 +-
 libavcodec/vc1data.c   | 27 +++++++++++++++++----------
 libavcodec/vc1data.h   |  6 +++---
 4 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index 9df778bcab..d973fd6c57 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -1616,9 +1616,10 @@ av_cold int ff_vc1_init_common(VC1Context *v)
                      ff_vc1_ttblk_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
             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];
-            init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
-                     ff_vc1_subblkpat_bits[i], 1, 1,
-                     ff_vc1_subblkpat_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
+            ff_init_vlc_from_lengths(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
+                                     &ff_vc1_subblkpat_tabs[i][0][1], 2,
+                                     &ff_vc1_subblkpat_tabs[i][0][0], 2, 1,
+                                     0, INIT_VLC_USE_NEW_STATIC, NULL);
         }
         for (i = 0; i < 4; i++) {
             ff_vc1_4mv_block_pattern_vlc[i].table           = &vlc_table[vlc_offs[i * 3 + 9]];
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 5c33170933..b8987b0015 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -1143,7 +1143,7 @@ static int vc1_decode_p_block(VC1Context *v, int16_t block[64], int n,
         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)];
     }
     if (ttblk == TT_4X4) {
-        subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
+        subblkpat = ~get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1);
     }
     if ((ttblk != TT_8X8 && ttblk != TT_4X4)
         && ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
diff --git a/libavcodec/vc1data.c b/libavcodec/vc1data.c
index 19f1cad45f..e92d9b7310 100644
--- a/libavcodec/vc1data.c
+++ b/libavcodec/vc1data.c
@@ -921,16 +921,23 @@ const uint8_t ff_vc1_ttblk_bits[3][8] = {
     {  2,  3,  3,  3,  3,  3,  4,  4 }
 };
 
-/* SUBBLKPAT tables, p93-94, reordered */
-const uint8_t ff_vc1_subblkpat_codes[3][15] = {
-    { 14, 12,  7, 11,  9, 26,  2, 10, 27,  8,  0,  6,  1, 15,  1 },
-    { 14,  0,  8, 15, 10,  4, 23, 13,  5,  9, 25,  3, 24, 22,  1 },
-    {  5,  6,  2,  2,  8,  0, 28,  3,  1,  3, 29,  1, 19, 18, 15 }
-};
-const uint8_t ff_vc1_subblkpat_bits[3][15] = {
-    {  5,  5,  5,  5,  5,  6,  4,  5,  6,  5,  4,  5,  4,  5,  1},
-    {  4,  3,  4,  4,  4,  5,  5,  4,  5,  4,  5,  4,  5,  5,  2},
-    {  3,  3,  4,  3,  4,  5,  5,  3,  5,  4,  5,  4,  5,  5,  4}
+/* SUBBLKPAT tables, p93-94, reordered and offset by 1 */
+const uint8_t ff_vc1_subblkpat_tabs[3][15][2] = {
+    {
+        { 0x0B, 4 }, { 0x0D, 4 }, { 0x07, 4 }, { 0x0C, 5 }, { 0x03, 5 },
+        { 0x0A, 5 }, { 0x05, 5 }, { 0x08, 5 }, { 0x04, 5 }, { 0x02, 5 },
+        { 0x06, 6 }, { 0x09, 6 }, { 0x01, 5 }, { 0x0E, 5 }, { 0x0F, 1 },
+    },
+    {
+        { 0x02, 3 }, { 0x06, 5 }, { 0x09, 5 }, { 0x0C, 4 }, { 0x0F, 2 },
+        { 0x03, 4 }, { 0x0A, 4 }, { 0x05, 4 }, { 0x0E, 5 }, { 0x07, 5 },
+        { 0x0D, 5 }, { 0x0B, 5 }, { 0x08, 4 }, { 0x01, 4 }, { 0x04, 4 },
+    },
+    {
+        { 0x06, 5 }, { 0x09, 5 }, { 0x0C, 4 }, { 0x03, 4 }, { 0x0A, 4 },
+        { 0x04, 3 }, { 0x08, 3 }, { 0x05, 4 }, { 0x0E, 5 }, { 0x0D, 5 },
+        { 0x01, 3 }, { 0x02, 3 }, { 0x07, 5 }, { 0x0B, 5 }, { 0x0F, 4 },
+    }
 };
 
 /* MV differential tables, p265 */
diff --git a/libavcodec/vc1data.h b/libavcodec/vc1data.h
index 90dd8baf61..02603ca9bc 100644
--- a/libavcodec/vc1data.h
+++ b/libavcodec/vc1data.h
@@ -152,9 +152,9 @@ extern const uint8_t ff_vc1_ttmb_bits[3][16];
 extern const uint8_t ff_vc1_ttblk_codes[3][8];
 extern const uint8_t ff_vc1_ttblk_bits[3][8];
 
-/* SUBBLKPAT tables, p93-94, reordered */
-extern const uint8_t ff_vc1_subblkpat_codes[3][15];
-extern const uint8_t ff_vc1_subblkpat_bits[3][15];
+/* SUBBLKPAT tables (tables #65-#67).
+ * The symbols contain the Subblock Pattern. */
+extern const uint8_t ff_vc1_subblkpat_tabs[3][15][2];
 
 /* MV differential tables, p265 */
 extern const uint16_t ff_vc1_mv_diff_codes[4][73];
-- 
2.25.1



More information about the ffmpeg-devel mailing list