diff options
author | James Almer <jamrial@gmail.com> | 2022-03-07 05:34:54 +0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2022-03-07 05:43:21 +0300 |
commit | 56fc43ae2b25dd02faa04fee3b21c2c7849d40ad (patch) | |
tree | 9f4590ca6037dd7b3ded45dac91cee29ef2e6dc9 | |
parent | 4124eded3b316f457ce8616fecd6f5c1734952b3 (diff) |
lib: don't buffer an extra frame when there's a single spatial layer
-rw-r--r-- | src/internal.h | 1 | ||||
-rw-r--r-- | src/lib.c | 11 | ||||
-rw-r--r-- | src/obu.c | 2 |
3 files changed, 8 insertions, 6 deletions
diff --git a/src/internal.h b/src/internal.h index b42b316..55710bf 100644 --- a/src/internal.h +++ b/src/internal.h @@ -189,6 +189,7 @@ struct Dav1dContext { int operating_point; unsigned operating_point_idc; int all_layers; + int max_spatial_id; unsigned frame_size_limit; int strict_std_compliance; int output_invisible_frames; @@ -322,7 +322,8 @@ static int output_image(Dav1dContext *const c, Dav1dPicture *const out) { int res = 0; - Dav1dThreadPicture *const in = c->all_layers ? &c->out : &c->cache; + Dav1dThreadPicture *const in = c->all_layers || !c->max_spatial_id + ? &c->out : &c->cache; if (!c->apply_grain || !has_grain(&in->p)) { dav1d_picture_move_ref(out, &in->p); dav1d_thread_picture_unref(in); @@ -332,18 +333,16 @@ static int output_image(Dav1dContext *const c, Dav1dPicture *const out) res = dav1d_apply_grain(c, out, &in->p); dav1d_thread_picture_unref(in); end: - if (!c->all_layers && c->out.p.data[0]) { + if (!c->all_layers && c->max_spatial_id && c->out.p.data[0]) { dav1d_thread_picture_move_ref(in, &c->out); } return res; } static int output_picture_ready(Dav1dContext *const c, const int drain) { - if (!c->all_layers) { + if (!c->all_layers && c->max_spatial_id) { if (c->out.p.data[0] && c->cache.p.data[0]) { - const unsigned spatial_mask = c->operating_point_idc >> 8; - const int max_spatial_id = spatial_mask ? ulog2(spatial_mask) : 0; - if (max_spatial_id == c->cache.p.frame_hdr->spatial_id || + if (c->max_spatial_id == c->cache.p.frame_hdr->spatial_id || c->out.flags & PICTURE_FLAG_NEW_TEMPORAL_UNIT) return 1; dav1d_thread_picture_unref(&c->cache); @@ -138,6 +138,8 @@ static int parse_seq_hdr(Dav1dContext *const c, GetBits *const gb, const int op_idx = c->operating_point < hdr->num_operating_points ? c->operating_point : 0; c->operating_point_idc = hdr->operating_points[op_idx].idc; + const unsigned spatial_mask = c->operating_point_idc >> 8; + c->max_spatial_id = spatial_mask ? ulog2(spatial_mask) : 0; #if DEBUG_SEQ_HDR printf("SEQHDR: post-operating-points: off=%u\n", dav1d_get_bits_pos(gb) - init_bit_pos); |