shithub: dav1d

Download patch

ref: 4d3b6c153ba787adacabaa5e0e3b6e229b144c5a
parent: 8c95771dfa7a0bdb542eef8924bd0d3009e5efff
author: Janne Grunau <janne-vlc@jannau.net>
date: Thu Nov 8 18:55:06 EST 2018

reduce size of Av1FrameHeader by 7940 bytes

Take the maximal number of tile rows and columns (each 64) into account.
Reduces size of Av1FrameHeader from 9588 to 1648 bytes on x86_64
according to pahole.
Refs #156.

--- a/src/levels.h
+++ b/src/levels.h
@@ -41,6 +41,10 @@
     OBU_PADDING   = 15,
 };
 
+// Constants from Section 3. "Symbols and abbreviated terms"
+#define MAX_TILE_COLS 64
+#define MAX_TILE_ROWS 64
+
 enum TxfmSize {
     TX_4X4,
     TX_8X8,
@@ -443,9 +447,9 @@
         int uniform;
         unsigned n_bytes;
         int min_log2_cols, max_log2_cols, log2_cols, cols;
-        int col_start_sb[1025];
         int min_log2_rows, max_log2_rows, log2_rows, rows;
-        int row_start_sb[1025];
+        uint16_t col_start_sb[MAX_TILE_COLS + 1];
+        uint16_t row_start_sb[MAX_TILE_ROWS + 1];
         int update;
     } tiling;
     struct {
--- a/src/obu.c
+++ b/src/obu.c
@@ -454,8 +454,8 @@
     int max_tile_width_sb = 4096 >> sbsz_log2;
     int max_tile_area_sb = 4096 * 2304 >> (2 * sbsz_log2);
     hdr->tiling.min_log2_cols = tile_log2(max_tile_width_sb, sbw);
-    hdr->tiling.max_log2_cols = tile_log2(1, imin(sbw, 1024));
-    hdr->tiling.max_log2_rows = tile_log2(1, imin(sbh, 1024));
+    hdr->tiling.max_log2_cols = tile_log2(1, imin(sbw, MAX_TILE_COLS));
+    hdr->tiling.max_log2_rows = tile_log2(1, imin(sbh, MAX_TILE_ROWS));
     int min_log2_tiles = imax(tile_log2(max_tile_area_sb, sbw * sbh),
                               hdr->tiling.min_log2_cols);
     if (hdr->tiling.uniform) {
@@ -479,7 +479,7 @@
     } else {
         hdr->tiling.cols = 0;
         int widest_tile = 0, max_tile_area_sb = sbw * sbh;
-        for (int sbx = 0; sbx < sbw; hdr->tiling.cols++) {
+        for (int sbx = 0; sbx < sbw && hdr->tiling.cols < MAX_TILE_COLS; hdr->tiling.cols++) {
             const int tile_width_sb = imin(sbw - sbx, max_tile_width_sb);
             const int tile_w = (tile_width_sb > 1) ?
                                    1 + dav1d_get_uniform(gb, tile_width_sb) :
@@ -493,7 +493,7 @@
         int max_tile_height_sb = imax(max_tile_area_sb / widest_tile, 1);
 
         hdr->tiling.rows = 0;
-        for (int sby = 0; sby < sbh; hdr->tiling.rows++) {
+        for (int sby = 0; sby < sbh && hdr->tiling.rows < MAX_TILE_ROWS; hdr->tiling.rows++) {
             const int tile_height_sb = imin(sbh - sby, max_tile_height_sb);
             const int tile_h = (tile_height_sb > 1) ?
                                    1 + dav1d_get_uniform(gb, tile_height_sb) :