shithub: dav1d

Download patch

ref: 46435a537a6ec3e38792c482f94d18559261908a
parent: f753caeac09bcf7ebe5d3fe1c0903deb277e9433
author: James Almer <jamrial@gmail.com>
date: Tue Jan 15 12:39:06 EST 2019

allocate Tile Group cache dynamically

--- a/src/decode.c
+++ b/src/decode.c
@@ -3172,6 +3172,12 @@
     }
 
     // FIXME qsort so tiles are in order (for frame threading)
+    if (f->n_tile_data_alloc < c->n_tile_data) {
+        struct Dav1dTileGroup *tile = realloc(f->tile, c->n_tile_data * sizeof(*f->tile));
+        if (!tile) goto error;
+        f->tile = tile;
+        f->n_tile_data_alloc = c->n_tile_data;
+    }
     memcpy(f->tile, c->tile, c->n_tile_data * sizeof(*f->tile));
     memset(c->tile, 0, c->n_tile_data * sizeof(*c->tile));
     f->n_tile_data = c->n_tile_data;
--- a/src/internal.h
+++ b/src/internal.h
@@ -65,6 +65,11 @@
     Dav1dLoopRestorationDSPContext lr;
 } Dav1dDSPContext;
 
+struct Dav1dTileGroup {
+    Dav1dData data;
+    int start, end;
+};
+
 struct Dav1dContext {
     Dav1dFrameContext *fc;
     unsigned n_fc;
@@ -71,10 +76,8 @@
 
     // cache of OBUs that make up a single frame before we submit them
     // to a frame worker to be decoded
-    struct {
-        Dav1dData data;
-        int start, end;
-    } tile[256];
+    struct Dav1dTileGroup *tile;
+    int n_tile_data_alloc;
     int n_tile_data;
     int n_tiles;
     Dav1dRef *seq_hdr_ref;
@@ -139,10 +142,8 @@
     unsigned refpoc[7], refrefpoc[7][7];
     uint8_t gmv_warp_allowed[7];
     CdfThreadContext in_cdf, out_cdf;
-    struct {
-        Dav1dData data;
-        int start, end;
-    } tile[256];
+    struct Dav1dTileGroup *tile;
+    int n_tile_data_alloc;
     int n_tile_data;
 
     // for scalable references
--- a/src/lib.c
+++ b/src/lib.c
@@ -473,6 +473,7 @@
         dav1d_free_aligned(f->tc);
         dav1d_free_aligned(f->ipred_edge[0]);
         free(f->a);
+        free(f->tile);
         free(f->lf.mask);
         free(f->lf.lr_mask);
         free(f->lf.level);
@@ -491,6 +492,7 @@
     }
     for (int n = 0; n < c->n_tile_data; n++)
         dav1d_data_unref_internal(&c->tile[n].data);
+    free(c->tile);
     for (int n = 0; n < 8; n++) {
         dav1d_cdf_thread_unref(&c->cdf[n]);
         if (c->refs[n].p.p.data[0])
--- a/src/obu.c
+++ b/src/obu.c
@@ -1311,7 +1311,14 @@
     case OBU_TILE_GRP: {
         if (global) break;
         if (!c->frame_hdr) goto error;
-        if (c->n_tile_data >= 256) goto error;
+        if (c->n_tile_data_alloc < c->n_tile_data + 1) {
+            if ((c->n_tile_data + 1) > INT_MAX / (int)sizeof(*c->tile)) goto error;
+            struct Dav1dTileGroup *tile = realloc(c->tile, (c->n_tile_data + 1) * sizeof(*c->tile));
+            if (!tile) goto error;
+            c->tile = tile;
+            memset(c->tile + c->n_tile_data, 0, sizeof(*c->tile));
+            c->n_tile_data_alloc = c->n_tile_data + 1;
+        }
         parse_tile_hdr(c, &gb);
         // Align to the next byte boundary and check for overrun.
         dav1d_bytealign_get_bits(&gb);