diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index f5e0a250..38d08158 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -1205,6 +1205,19 @@ pub const SINGLE_REF: [[[u16; 3]; 6]; 3] = [ /// least 8x8 both dims (`is_comp_ref_allowed`) -- lane-av1comp. pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [8127, 32768, 0]]; +/// `default_obmc_cdf` (spec 9.4): `use_obmc`, by square bsize (`BLOCK_8X8`, +/// `BLOCK_16X16`, `BLOCK_32X32`, `BLOCK_64X64` -- `BLOCK_SIZES_ALL` indices +/// 3/6/9/12, the only sizes this decoder ever codes). Read only once +/// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers +/// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 +/// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. +pub const OBMC: [[u16; 3]; 4] = [ + [10437, 32768, 0], + [17432, 32768, 0], + [25817, 32768, 0], + [30128, 32768, 0], +]; + /// `Default_Comp_Mode_Cdf` (spec 9.4, `default_comp_inter_cdf`): whether an /// inter block reads `SINGLE_REFERENCE` or `COMPOUND_REFERENCE` -- only /// reached once `read_ref_frames` knows the frame's `reference_select` diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index f04826cd..f243bd2d 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -318,6 +318,15 @@ pub(crate) struct Cdfs { /// Whether a block reads `skip_mode` (lane-av1comp, spec 5.11.29's /// `skip_mode`), indexed by `av1_get_skip_mode_context`. pub skip_mode: [[u16; 3]; 3], + /// `use_obmc` (spec 5.11.24's `read_motion_mode`, the `OBMC_CAUSAL`-vs- + /// `SIMPLE_TRANSLATION` two-symbol alphabet libaom's `obmc_cdf` reads + /// whenever `motion_mode_allowed` can't offer `WARPED_CAUSAL` -- + /// lane-motionmode round 1 only reaches this arm, never the three-way + /// `motion_mode_cdf`), indexed by this block's own square bsize: 0 = + /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` + /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- + /// this decoder only ever codes those four square sizes). + pub obmc: [[u16; 3]; 4], /// Which of the eight `INTER_COMPOUND_MODES` a `COMPOUND_REFERENCE` /// block takes (lane-av1comp, spec 5.11.24's `compound_mode`). pub inter_compound_mode: [[u16; 9]; 8], @@ -548,6 +557,7 @@ impl Cdfs { reset3(&mut self.single_ref); reset2(&mut self.comp_mode); reset2(&mut self.skip_mode); + reset2(&mut self.obmc); reset2(&mut self.inter_compound_mode); reset2(&mut self.comp_ref_type); reset3(&mut self.uni_comp_ref); @@ -988,6 +998,7 @@ impl Cdfs { comp_ref: cdf::COMP_REF, comp_bwdref: cdf::COMP_BWDREF, skip_mode: cdf::SKIP_MODE, + obmc: cdf::OBMC, comp_group_idx: cdf::COMP_GROUP_IDX, compound_idx: cdf::COMPOUND_IDX, y_mode: cdf::Y_MODE, diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 6b2a8c85..11893367 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4306,6 +4306,10 @@ fn decode_inter_block( // `compound_idx` read (libaom `decodemv.c` 1604-1619, 1382-1384, 1509). skip_mode_present: bool, skip_mode_frame: [u8; 2], + // lane-motionmode round 1: this frame header's own `is_motion_mode_switchable`/ + // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`). + switchable_motion_mode: bool, + allow_warped_motion: bool, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -6207,6 +6211,8 @@ pub fn decode_inter_frame_tile( false, [0; 2], true, + false, + false, ) .map(|(picture, _, _)| picture) } @@ -6257,6 +6263,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // `Set1` coefficient tables at 16x16/8x8 rather than the reduced // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]). reduced_tx_set: bool, + // lane-motionmode round 1: this frame header's own `is_motion_mode_switchable`/ + // `allow_warped_motion` bits, threaded to every `decode_inter_block` call + // below (spec 5.11.24's `read_motion_mode`) -- `decode_inter_block8`'s 8x8 + // leaves do not read this symbol yet (round 2). + switchable_motion_mode: bool, + allow_warped_motion: bool, ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { let tpl_frame = tpl_field.map(|field| TplFrameArgs { field, @@ -6461,6 +6473,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ref_order_hints, skip_mode_present, skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, )?; } PARTITION_SPLIT => { @@ -6531,6 +6545,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ref_order_hints, skip_mode_present, skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, )?; } else { let ctx16 = neighbours.partition_ctx(at16, SUB); @@ -7373,6 +7389,8 @@ mod tests { [0; 7], false, [0; 2], + false, + false, ) .unwrap(); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index fdcc5626..4cfa6d51 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -379,6 +379,8 @@ pub fn decode_stream(data: &[u8]) -> Result> { header.skip_mode_present, header.skip_mode_frame, header.reduced_tx_set, + header.is_motion_mode_switchable, + header.allow_warped_motion, )? }; // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's