diff options
-rw-r--r-- | include/common/frame.h | 37 | ||||
-rw-r--r-- | src/cdf.c | 6 | ||||
-rw-r--r-- | src/decode.c | 35 | ||||
-rw-r--r-- | src/obu.c | 23 | ||||
-rw-r--r-- | src/recon_tmpl.c | 5 |
5 files changed, 73 insertions, 33 deletions
diff --git a/include/common/frame.h b/include/common/frame.h new file mode 100644 index 0000000..de2bd0d --- /dev/null +++ b/include/common/frame.h @@ -0,0 +1,37 @@ +/* + * Copyright © 2021, VideoLAN and dav1d authors + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DAV1D_COMMON_FRAME_H +#define DAV1D_COMMON_FRAME_H + +/* + * Checks whether Dav1dFrameType == INTER || == SWITCH + * Both are defined as odd numbers {1, 3} and therefore have the LSB set. + */ +#define IS_INTER_OR_SWITCH(frame_header) \ + ((frame_header)->frame_type & 1) + +#endif /* DAV1D_COMMON_FRAME_H */ @@ -1,5 +1,5 @@ /* - * Copyright © 2018, VideoLAN and dav1d authors + * Copyright © 2018-2021, VideoLAN and dav1d authors * Copyright © 2018, Two Orioles, LLC * All rights reserved. * @@ -29,6 +29,8 @@ #include <string.h> +#include "common/frame.h" + #include "src/internal.h" #include "src/tables.h" @@ -4012,7 +4014,7 @@ void dav1d_cdf_thread_update(const Dav1dFrameHeader *const hdr, update_cdf_1d(11, m.txtp_inter2); update_bit_1d(4, m.txtp_inter3); - if (!(hdr->frame_type & 1)) { + if (!IS_INTER_OR_SWITCH(hdr)) { update_bit_0d(m.intrabc); update_cdf_1d(N_MV_JOINTS - 1, dmv.joint); diff --git a/src/decode.c b/src/decode.c index 6730b22..c732c00 100644 --- a/src/decode.c +++ b/src/decode.c @@ -1,5 +1,5 @@ /* - * Copyright © 2018, VideoLAN and dav1d authors + * Copyright © 2018-2021, VideoLAN and dav1d authors * Copyright © 2018, Two Orioles, LLC * All rights reserved. * @@ -35,6 +35,7 @@ #include "dav1d/data.h" +#include "common/frame.h" #include "common/intops.h" #include "src/ctx.h" @@ -727,7 +728,7 @@ static int decode_b(Dav1dTileContext *const t, case_set(bh4, l., 1, by4); case_set(bw4, a->, 0, bx4); #undef set_ctx - if (f->frame_hdr->frame_type & 1) { + if (IS_INTER_OR_SWITCH(f->frame_hdr)) { refmvs_block *const r = &t->rt.r[(t->by & 31) + 5 + bh4 - 1][t->bx]; for (int x = 0; x < bw4; x++) { r[x].ref.ref[0] = 0; @@ -748,7 +749,7 @@ static int decode_b(Dav1dTileContext *const t, #undef set_ctx } } else { - if (f->frame_hdr->frame_type & 1 /* not intrabc */ && + if (IS_INTER_OR_SWITCH(f->frame_hdr) /* not intrabc */ && b->comp_type == COMP_INTER_NONE && b->motion_mode == MM_WARP) { if (b->matrix[0] == SHRT_MIN) { @@ -791,7 +792,7 @@ static int decode_b(Dav1dTileContext *const t, case_set(bw4, a->, 0, bx4); #undef set_ctx - if (f->frame_hdr->frame_type & 1) { + if (IS_INTER_OR_SWITCH(f->frame_hdr)) { refmvs_block *const r = &t->rt.r[(t->by & 31) + 5 + bh4 - 1][t->bx]; for (int x = 0; x < bw4; x++) { r[x].ref.ref[0] = b->ref[0] + 1; @@ -1043,7 +1044,7 @@ static int decode_b(Dav1dTileContext *const t, if (b->skip_mode) { b->intra = 0; - } else if (f->frame_hdr->frame_type & 1) { + } else if (IS_INTER_OR_SWITCH(f->frame_hdr)) { if (seg && (seg->ref >= 0 || seg->globalmv)) { b->intra = !seg->ref; } else { @@ -1064,7 +1065,7 @@ static int decode_b(Dav1dTileContext *const t, // intra/inter-specific stuff if (b->intra) { - uint16_t *const ymode_cdf = f->frame_hdr->frame_type & 1 ? + uint16_t *const ymode_cdf = IS_INTER_OR_SWITCH(f->frame_hdr) ? ts->cdf.m.y_mode[dav1d_ymode_size_context[bs]] : ts->cdf.kfym[dav1d_intra_mode_context[t->a->mode[bx4]]] [dav1d_intra_mode_context[t->l.mode[by4]]]; @@ -1252,7 +1253,7 @@ static int decode_b(Dav1dTileContext *const t, rep_macro(type, t->dir skip, off, mul * b->skip); \ /* see aomedia bug 2183 for why we use luma coordinates here */ \ rep_macro(type, t->pal_sz_uv[diridx], off, mul * (has_chroma ? b->pal_sz[1] : 0)); \ - if (f->frame_hdr->frame_type & 1) { \ + if (IS_INTER_OR_SWITCH(f->frame_hdr)) { \ rep_macro(type, t->dir comp_type, off, mul * COMP_INTER_NONE); \ rep_macro(type, t->dir ref[0], off, mul * ((uint8_t) -1)); \ rep_macro(type, t->dir ref[1], off, mul * ((uint8_t) -1)); \ @@ -1293,10 +1294,10 @@ static int decode_b(Dav1dTileContext *const t, } } } - if ((f->frame_hdr->frame_type & 1) || f->frame_hdr->allow_intrabc) { + if (IS_INTER_OR_SWITCH(f->frame_hdr) || f->frame_hdr->allow_intrabc) { splat_intraref(&t->rt, t->by, t->bx, bs); } - } else if (!(f->frame_hdr->frame_type & 1)) { + } else if (!IS_INTER_OR_SWITCH(f->frame_hdr)) { // intra block copy refmvs_candidate mvstack[8]; int n_mvs, ctx; @@ -2513,14 +2514,14 @@ int dav1d_decode_tile_sbrow(Dav1dTileContext *const t) { const int col_sb_start = f->frame_hdr->tiling.col_start_sb[tile_col]; const int col_sb128_start = col_sb_start >> !f->seq_hdr->sb128; - if ((f->frame_hdr->frame_type & 1) || f->frame_hdr->allow_intrabc) { + if (IS_INTER_OR_SWITCH(f->frame_hdr) || f->frame_hdr->allow_intrabc) { dav1d_refmvs_tile_sbrow_init(&t->rt, &f->rf, ts->tiling.col_start, ts->tiling.col_end, ts->tiling.row_start, ts->tiling.row_end, t->by >> f->sb_shift, ts->tiling.row); } - reset_context(&t->l, !(f->frame_hdr->frame_type & 1), f->frame_thread.pass); + reset_context(&t->l, !IS_INTER_OR_SWITCH(f->frame_hdr), f->frame_thread.pass); if (f->frame_thread.pass == 2) { for (t->bx = ts->tiling.col_start, t->a = f->a + col_sb128_start + tile_row * f->sb128w; @@ -2631,7 +2632,7 @@ int dav1d_decode_tile_sbrow(Dav1dTileContext *const t) { } } - if (f->n_tc > 1 && f->frame_hdr->frame_type & 1) { + if (f->n_tc > 1 && IS_INTER_OR_SWITCH(f->frame_hdr)) { dav1d_refmvs_save_tmvs(&t->rt, ts->tiling.col_start >> 1, ts->tiling.col_end >> 1, t->by >> 1, (t->by + sb_step) >> 1); @@ -2950,7 +2951,7 @@ int dav1d_decode_frame(Dav1dFrameContext *const f) { } // init ref mvs - if ((f->frame_hdr->frame_type & 1) || f->frame_hdr->allow_intrabc) { + if (IS_INTER_OR_SWITCH(f->frame_hdr) || f->frame_hdr->allow_intrabc) { const int ret = dav1d_refmvs_init_frame(&f->rf, f->seq_hdr, f->frame_hdr, f->refpoc, f->mvs, f->refrefpoc, f->ref_mvs, f->n_tc); @@ -3086,7 +3087,7 @@ int dav1d_decode_frame(Dav1dFrameContext *const f) { f->frame_thread.pass == 1 ? PLANE_TYPE_BLOCK : PLANE_TYPE_Y; for (int n = 0; n < f->sb128w * f->frame_hdr->tiling.rows; n++) - reset_context(&f->a[n], !(f->frame_hdr->frame_type & 1), f->frame_thread.pass); + reset_context(&f->a[n], !IS_INTER_OR_SWITCH(f->frame_hdr), f->frame_thread.pass); if (f->n_tc == 1 || (c->n_pfc > 1 && f->frame_hdr->tiling.cols * f->frame_hdr->tiling.rows == 1)) { Dav1dTileContext *const t = f->tc; @@ -3117,7 +3118,7 @@ int dav1d_decode_frame(Dav1dFrameContext *const f) { t->ts = &f->ts[tile_row * f->frame_hdr->tiling.cols + tile_col]; if (dav1d_decode_tile_sbrow(t)) goto error; } - if (f->frame_thread.pass <= 1 && f->frame_hdr->frame_type & 1) { + if (f->frame_thread.pass <= 1 && IS_INTER_OR_SWITCH(f->frame_hdr)) { dav1d_refmvs_save_tmvs(&t->rt, 0, f->bw >> 1, t->by >> 1, by_end); } @@ -3391,7 +3392,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { #undef assign_bitdepth_case int ref_coded_width[7]; - if (f->frame_hdr->frame_type & 1) { + if (IS_INTER_OR_SWITCH(f->frame_hdr)) { if (f->frame_hdr->primary_ref_frame != DAV1D_PRIMARY_REF_NONE) { const int pri_ref = f->frame_hdr->refidx[f->frame_hdr->primary_ref_frame]; if (!c->refs[pri_ref].p.p.data[0]) { @@ -3509,7 +3510,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { f->bitdepth_max = (1 << f->cur.p.bpc) - 1; // ref_mvs - if ((f->frame_hdr->frame_type & 1) || f->frame_hdr->allow_intrabc) { + if (IS_INTER_OR_SWITCH(f->frame_hdr) || f->frame_hdr->allow_intrabc) { f->mvs_ref = dav1d_ref_create_using_pool(c->refmvs_pool, sizeof(*f->mvs) * f->sb128h * 16 * (f->b4_stride >> 1)); if (!f->mvs_ref) { @@ -1,5 +1,5 @@ /* - * Copyright © 2018, VideoLAN and dav1d authors + * Copyright © 2018-2021, VideoLAN and dav1d authors * Copyright © 2018, Two Orioles, LLC * All rights reserved. * @@ -33,6 +33,7 @@ #include "dav1d/data.h" +#include "common/frame.h" #include "common/intops.h" #include "src/decode.h" @@ -406,7 +407,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { else hdr->force_integer_mv = 0; - if (!(hdr->frame_type & 1)) + if (!IS_INTER_OR_SWITCH(hdr)) hdr->force_integer_mv = 1; if (seqhdr->frame_id_numbers_present) @@ -420,7 +421,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { #endif hdr->frame_offset = seqhdr->order_hint ? dav1d_get_bits(gb, seqhdr->order_hint_n_bits) : 0; - hdr->primary_ref_frame = !hdr->error_resilient_mode && hdr->frame_type & 1 ? + hdr->primary_ref_frame = !hdr->error_resilient_mode && IS_INTER_OR_SWITCH(hdr) ? dav1d_get_bits(gb, 3) : DAV1D_PRIMARY_REF_NONE; if (seqhdr->decoder_model_info_present) { @@ -438,10 +439,8 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { } } } - - if (hdr->frame_type == DAV1D_FRAME_TYPE_KEY || - hdr->frame_type == DAV1D_FRAME_TYPE_INTRA) - { + // frame_type == KEY || == INTRA + if (!IS_INTER_OR_SWITCH(hdr)) { hdr->refresh_frame_flags = (hdr->frame_type == DAV1D_FRAME_TYPE_KEY && hdr->show_frame) ? 0xff : dav1d_get_bits(gb, 8); if (hdr->refresh_frame_flags != 0xff && hdr->error_resilient_mode && seqhdr->order_hint) @@ -569,7 +568,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { hdr->switchable_motion_mode = dav1d_get_bits(gb, 1); hdr->use_ref_frame_mvs = !hdr->error_resilient_mode && seqhdr->ref_frame_mvs && seqhdr->order_hint && - hdr->frame_type & 1 && dav1d_get_bits(gb, 1); + IS_INTER_OR_SWITCH(hdr) && dav1d_get_bits(gb, 1); } #if DEBUG_FRAME_HDR printf("HDR: post-frametype-specific-bits: off=%td\n", @@ -916,13 +915,13 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { printf("HDR: post-txfmmode: off=%td\n", (gb->ptr - init_ptr) * 8 - gb->bits_left); #endif - hdr->switchable_comp_refs = hdr->frame_type & 1 ? dav1d_get_bits(gb, 1) : 0; + hdr->switchable_comp_refs = IS_INTER_OR_SWITCH(hdr) ? dav1d_get_bits(gb, 1) : 0; #if DEBUG_FRAME_HDR printf("HDR: post-refmode: off=%td\n", (gb->ptr - init_ptr) * 8 - gb->bits_left); #endif hdr->skip_mode_allowed = 0; - if (hdr->switchable_comp_refs && hdr->frame_type & 1 && seqhdr->order_hint) { + if (hdr->switchable_comp_refs && IS_INTER_OR_SWITCH(hdr) && seqhdr->order_hint) { const unsigned poc = hdr->frame_offset; unsigned off_before = 0xFFFFFFFFU; int off_after = -1; @@ -982,7 +981,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { printf("HDR: post-extskip: off=%td\n", (gb->ptr - init_ptr) * 8 - gb->bits_left); #endif - hdr->warp_motion = !hdr->error_resilient_mode && hdr->frame_type & 1 && + hdr->warp_motion = !hdr->error_resilient_mode && IS_INTER_OR_SWITCH(hdr) && seqhdr->warped_motion && dav1d_get_bits(gb, 1); #if DEBUG_FRAME_HDR printf("HDR: post-warpmotionbit: off=%td\n", @@ -997,7 +996,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { for (int i = 0; i < 7; i++) hdr->gmv[i] = dav1d_default_wm_params; - if (hdr->frame_type & 1) { + if (IS_INTER_OR_SWITCH(hdr)) { for (int i = 0; i < 7; i++) { hdr->gmv[i].type = !dav1d_get_bits(gb, 1) ? DAV1D_WM_TYPE_IDENTITY : dav1d_get_bits(gb, 1) ? DAV1D_WM_TYPE_ROT_ZOOM : diff --git a/src/recon_tmpl.c b/src/recon_tmpl.c index 9905914..2ad0874 100644 --- a/src/recon_tmpl.c +++ b/src/recon_tmpl.c @@ -1,5 +1,5 @@ /* - * Copyright © 2018, VideoLAN and dav1d authors + * Copyright © 2018-2021, VideoLAN and dav1d authors * Copyright © 2018, Two Orioles, LLC * All rights reserved. * @@ -33,6 +33,7 @@ #include "common/attributes.h" #include "common/bitdepth.h" #include "common/dump.h" +#include "common/frame.h" #include "common/intops.h" #include "src/cdef_apply.h" @@ -1544,7 +1545,7 @@ int bytefn(dav1d_recon_b_inter)(Dav1dTileContext *const t, const enum BlockSize 4 * (t->by * PXSTRIDE(f->cur.stride[0]) + t->bx); const ptrdiff_t uvdstoff = 4 * ((t->bx >> ss_hor) + (t->by >> ss_ver) * PXSTRIDE(f->cur.stride[1])); - if (!(f->frame_hdr->frame_type & 1)) { + if (!IS_INTER_OR_SWITCH(f->frame_hdr)) { // intrabc assert(!f->frame_hdr->super_res.enabled); res = mc(t, dst, NULL, f->cur.stride[0], bw4, bh4, t->bx, t->by, 0, |