wip(av1): OBMC decode round 1 -- CDF + header-bit plumbing, symbol NOT read yet
Browse files at this commit0b6a5ba412b557b7c15989baebcf62fffcaa24d8Parent: 4d297114 changed files +44 -0
- crates/ec-av1/src/cdf.rs +13 -0
- crates/ec-av1/src/cdf_state.rs +11 -0
- crates/ec-av1/src/decode.rs +18 -0
- crates/ec-av1/src/stream.rs +2 -0
crates/ec-av1/src/cdf.rsmodified+13 -0
| @@ -1205,6 +1205,19 @@ pub const SINGLE_REF: [[[u16; 3]; 6]; 3] = [ | ||
| 1205 | 1205 | /// least 8x8 both dims (`is_comp_ref_allowed`) -- lane-av1comp. |
| 1206 | 1206 | pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [8127, 32768, 0]]; |
| 1207 | 1207 | |
| 1208 | +/// `default_obmc_cdf` (spec 9.4): `use_obmc`, by square bsize (`BLOCK_8X8`, | |
| 1209 | +/// `BLOCK_16X16`, `BLOCK_32X32`, `BLOCK_64X64` -- `BLOCK_SIZES_ALL` indices | |
| 1210 | +/// 3/6/9/12, the only sizes this decoder ever codes). Read only once | |
| 1211 | +/// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers | |
| 1212 | +/// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 | |
| 1213 | +/// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. | |
| 1214 | +pub const OBMC: [[u16; 3]; 4] = [ | |
| 1215 | + [10437, 32768, 0], | |
| 1216 | + [17432, 32768, 0], | |
| 1217 | + [25817, 32768, 0], | |
| 1218 | + [30128, 32768, 0], | |
| 1219 | +]; | |
| 1220 | + | |
| 1208 | 1221 | /// `Default_Comp_Mode_Cdf` (spec 9.4, `default_comp_inter_cdf`): whether an |
| 1209 | 1222 | /// inter block reads `SINGLE_REFERENCE` or `COMPOUND_REFERENCE` -- only |
| 1210 | 1223 | /// reached once `read_ref_frames` knows the frame's `reference_select` |
crates/ec-av1/src/cdf_state.rsmodified+11 -0
| @@ -318,6 +318,15 @@ pub(crate) struct Cdfs { | ||
| 318 | 318 | /// Whether a block reads `skip_mode` (lane-av1comp, spec 5.11.29's |
| 319 | 319 | /// `skip_mode`), indexed by `av1_get_skip_mode_context`. |
| 320 | 320 | pub skip_mode: [[u16; 3]; 3], |
| 321 | + /// `use_obmc` (spec 5.11.24's `read_motion_mode`, the `OBMC_CAUSAL`-vs- | |
| 322 | + /// `SIMPLE_TRANSLATION` two-symbol alphabet libaom's `obmc_cdf` reads | |
| 323 | + /// whenever `motion_mode_allowed` can't offer `WARPED_CAUSAL` -- | |
| 324 | + /// lane-motionmode round 1 only reaches this arm, never the three-way | |
| 325 | + /// `motion_mode_cdf`), indexed by this block's own square bsize: 0 = | |
| 326 | + /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` | |
| 327 | + /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- | |
| 328 | + /// this decoder only ever codes those four square sizes). | |
| 329 | + pub obmc: [[u16; 3]; 4], | |
| 321 | 330 | /// Which of the eight `INTER_COMPOUND_MODES` a `COMPOUND_REFERENCE` |
| 322 | 331 | /// block takes (lane-av1comp, spec 5.11.24's `compound_mode`). |
| 323 | 332 | pub inter_compound_mode: [[u16; 9]; 8], |
| @@ -548,6 +557,7 @@ impl Cdfs { | ||
| 548 | 557 | reset3(&mut self.single_ref); |
| 549 | 558 | reset2(&mut self.comp_mode); |
| 550 | 559 | reset2(&mut self.skip_mode); |
| 560 | + reset2(&mut self.obmc); | |
| 551 | 561 | reset2(&mut self.inter_compound_mode); |
| 552 | 562 | reset2(&mut self.comp_ref_type); |
| 553 | 563 | reset3(&mut self.uni_comp_ref); |
| @@ -988,6 +998,7 @@ impl Cdfs { | ||
| 988 | 998 | comp_ref: cdf::COMP_REF, |
| 989 | 999 | comp_bwdref: cdf::COMP_BWDREF, |
| 990 | 1000 | skip_mode: cdf::SKIP_MODE, |
| 1001 | + obmc: cdf::OBMC, | |
| 991 | 1002 | comp_group_idx: cdf::COMP_GROUP_IDX, |
| 992 | 1003 | compound_idx: cdf::COMPOUND_IDX, |
| 993 | 1004 | y_mode: cdf::Y_MODE, |
crates/ec-av1/src/decode.rsmodified+18 -0
| @@ -4306,6 +4306,10 @@ fn decode_inter_block( | ||
| 4306 | 4306 | // `compound_idx` read (libaom `decodemv.c` 1604-1619, 1382-1384, 1509). |
| 4307 | 4307 | skip_mode_present: bool, |
| 4308 | 4308 | skip_mode_frame: [u8; 2], |
| 4309 | + // lane-motionmode round 1: this frame header's own `is_motion_mode_switchable`/ | |
| 4310 | + // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`). | |
| 4311 | + switchable_motion_mode: bool, | |
| 4312 | + allow_warped_motion: bool, | |
| 4309 | 4313 | ) -> Result<()> { |
| 4310 | 4314 | let (r, c) = at; |
| 4311 | 4315 | let (px, py) = (c * SUB, r * SUB); |
| @@ -6207,6 +6211,8 @@ pub fn decode_inter_frame_tile( | ||
| 6207 | 6211 | false, |
| 6208 | 6212 | [0; 2], |
| 6209 | 6213 | true, |
| 6214 | + false, | |
| 6215 | + false, | |
| 6210 | 6216 | ) |
| 6211 | 6217 | .map(|(picture, _, _)| picture) |
| 6212 | 6218 | } |
| @@ -6257,6 +6263,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6257 | 6263 | // `Set1` coefficient tables at 16x16/8x8 rather than the reduced |
| 6258 | 6264 | // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]). |
| 6259 | 6265 | reduced_tx_set: bool, |
| 6266 | + // lane-motionmode round 1: this frame header's own `is_motion_mode_switchable`/ | |
| 6267 | + // `allow_warped_motion` bits, threaded to every `decode_inter_block` call | |
| 6268 | + // below (spec 5.11.24's `read_motion_mode`) -- `decode_inter_block8`'s 8x8 | |
| 6269 | + // leaves do not read this symbol yet (round 2). | |
| 6270 | + switchable_motion_mode: bool, | |
| 6271 | + allow_warped_motion: bool, | |
| 6260 | 6272 | ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { |
| 6261 | 6273 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { |
| 6262 | 6274 | field, |
| @@ -6461,6 +6473,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6461 | 6473 | ref_order_hints, |
| 6462 | 6474 | skip_mode_present, |
| 6463 | 6475 | skip_mode_frame, |
| 6476 | + switchable_motion_mode, | |
| 6477 | + allow_warped_motion, | |
| 6464 | 6478 | )?; |
| 6465 | 6479 | } |
| 6466 | 6480 | PARTITION_SPLIT => { |
| @@ -6531,6 +6545,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6531 | 6545 | ref_order_hints, |
| 6532 | 6546 | skip_mode_present, |
| 6533 | 6547 | skip_mode_frame, |
| 6548 | + switchable_motion_mode, | |
| 6549 | + allow_warped_motion, | |
| 6534 | 6550 | )?; |
| 6535 | 6551 | } else { |
| 6536 | 6552 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| @@ -7373,6 +7389,8 @@ mod tests { | ||
| 7373 | 7389 | [0; 7], |
| 7374 | 7390 | false, |
| 7375 | 7391 | [0; 2], |
| 7392 | + false, | |
| 7393 | + false, | |
| 7376 | 7394 | ) |
| 7377 | 7395 | .unwrap(); |
| 7378 | 7396 |
crates/ec-av1/src/stream.rsmodified+2 -0
| @@ -379,6 +379,8 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 379 | 379 | header.skip_mode_present, |
| 380 | 380 | header.skip_mode_frame, |
| 381 | 381 | header.reduced_tx_set, |
| 382 | + header.is_motion_mode_switchable, | |
| 383 | + header.allow_warped_motion, | |
| 382 | 384 | )? |
| 383 | 385 | }; |
| 384 | 386 | // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's |