allocate Tile Group cache dynamically

parent f753caea
Pipeline #3966 passed with stages
in 7 minutes and 20 seconds
...@@ -3172,6 +3172,12 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3172,6 +3172,12 @@ int dav1d_submit_frame(Dav1dContext *const c) {
} }
// FIXME qsort so tiles are in order (for frame threading) // 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)); memcpy(f->tile, c->tile, c->n_tile_data * sizeof(*f->tile));
memset(c->tile, 0, c->n_tile_data * sizeof(*c->tile)); memset(c->tile, 0, c->n_tile_data * sizeof(*c->tile));
f->n_tile_data = c->n_tile_data; f->n_tile_data = c->n_tile_data;
......
...@@ -65,16 +65,19 @@ typedef struct Dav1dDSPContext { ...@@ -65,16 +65,19 @@ typedef struct Dav1dDSPContext {
Dav1dLoopRestorationDSPContext lr; Dav1dLoopRestorationDSPContext lr;
} Dav1dDSPContext; } Dav1dDSPContext;
struct Dav1dTileGroup {
Dav1dData data;
int start, end;
};
struct Dav1dContext { struct Dav1dContext {
Dav1dFrameContext *fc; Dav1dFrameContext *fc;
unsigned n_fc; unsigned n_fc;
// cache of OBUs that make up a single frame before we submit them // cache of OBUs that make up a single frame before we submit them
// to a frame worker to be decoded // to a frame worker to be decoded
struct { struct Dav1dTileGroup *tile;
Dav1dData data; int n_tile_data_alloc;
int start, end;
} tile[256];
int n_tile_data; int n_tile_data;
int n_tiles; int n_tiles;
Dav1dRef *seq_hdr_ref; Dav1dRef *seq_hdr_ref;
...@@ -139,10 +142,8 @@ struct Dav1dFrameContext { ...@@ -139,10 +142,8 @@ struct Dav1dFrameContext {
unsigned refpoc[7], refrefpoc[7][7]; unsigned refpoc[7], refrefpoc[7][7];
uint8_t gmv_warp_allowed[7]; uint8_t gmv_warp_allowed[7];
CdfThreadContext in_cdf, out_cdf; CdfThreadContext in_cdf, out_cdf;
struct { struct Dav1dTileGroup *tile;
Dav1dData data; int n_tile_data_alloc;
int start, end;
} tile[256];
int n_tile_data; int n_tile_data;
// for scalable references // for scalable references
......
...@@ -473,6 +473,7 @@ void dav1d_close(Dav1dContext **const c_out) { ...@@ -473,6 +473,7 @@ void dav1d_close(Dav1dContext **const c_out) {
dav1d_free_aligned(f->tc); dav1d_free_aligned(f->tc);
dav1d_free_aligned(f->ipred_edge[0]); dav1d_free_aligned(f->ipred_edge[0]);
free(f->a); free(f->a);
free(f->tile);
free(f->lf.mask); free(f->lf.mask);
free(f->lf.lr_mask); free(f->lf.lr_mask);
free(f->lf.level); free(f->lf.level);
...@@ -491,6 +492,7 @@ void dav1d_close(Dav1dContext **const c_out) { ...@@ -491,6 +492,7 @@ void dav1d_close(Dav1dContext **const c_out) {
} }
for (int n = 0; n < c->n_tile_data; n++) for (int n = 0; n < c->n_tile_data; n++)
dav1d_data_unref_internal(&c->tile[n].data); dav1d_data_unref_internal(&c->tile[n].data);
free(c->tile);
for (int n = 0; n < 8; n++) { for (int n = 0; n < 8; n++) {
dav1d_cdf_thread_unref(&c->cdf[n]); dav1d_cdf_thread_unref(&c->cdf[n]);
if (c->refs[n].p.p.data[0]) if (c->refs[n].p.p.data[0])
......
...@@ -1311,7 +1311,14 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1311,7 +1311,14 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
case OBU_TILE_GRP: { case OBU_TILE_GRP: {
if (global) break; if (global) break;
if (!c->frame_hdr) goto error; 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); parse_tile_hdr(c, &gb);
// Align to the next byte boundary and check for overrun. // Align to the next byte boundary and check for overrun.
dav1d_bytealign_get_bits(&gb); dav1d_bytealign_get_bits(&gb);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment