Read compound DRL + assign compound MVs, still refuse before MC
Browse files at this commit214cdf2befd543569feaaaf45888fe80e40318dfParent: cadc399- feat
- read compound DRL + assign compound MVs, still refuse before MC
1 changed file +135 -7
- crates/ec-av1/src/decode.rs +135 -7
crates/ec-av1/src/decode.rsmodified+135 -7
| @@ -3937,6 +3937,94 @@ fn read_inter_compound_mode( | |||
| 3937 | dec.symbol(&mut cdfs.inter_compound_mode[ctx]) as u8 | 3937 | dec.symbol(&mut cdfs.inter_compound_mode[ctx]) as u8 |
| 3938 | } | 3938 | } |
| 3939 | 3939 | ||
| 3940 | +/// spec 7.10.2.10 `assign_mv`'s compound branch, plus the compound half of | ||
| 3941 | +/// `read_drl_idx` (spec 5.11.24) it depends on -- `mode` is | ||
| 3942 | +/// [`read_inter_compound_mode`]'s own `0..=7` (`NEAREST_NEARESTMV`.. | ||
| 3943 | +/// `NEW_NEWMV`, libaom `enums.h` order). Every `GLOBAL_GLOBALMV` side reads | ||
| 3944 | +/// as `(0, 0)` since [`crate::stream::decode_stream`] already refuses any | ||
| 3945 | +/// non-`IDENTITY` global motion model before a tile is ever decoded. | ||
| 3946 | +/// | ||
| 3947 | +/// Ported straight from libaom `decodemv.c`'s `read_drl_idx` (the | ||
| 3948 | +/// `NEW_NEWMV`/`have_nearmv_in_inter_mode` branches) and `assign_mv`/its | ||
| 3949 | +/// caller's `ref_mv[]`/`nearmv[]` setup: the `NEAR_NEWMV`/`NEW_NEARMV` | ||
| 3950 | +/// `1 + ref_mv_idx` special case is folded into `new_idx` below, matching | ||
| 3951 | +/// `read_drl_idx`'s own comment about "offsetting the NEARESTMV mode". | ||
| 3952 | +fn assign_compound_mv( | ||
| 3953 | + dec: &mut SymbolDecoder, | ||
| 3954 | + cdfs: &mut Cdfs, | ||
| 3955 | + comp_stack: &crate::mvstack::CompoundMvStack, | ||
| 3956 | + mode: u8, | ||
| 3957 | + allow_high_precision_mv: bool, | ||
| 3958 | +) -> ((i32, i32), (i32, i32)) { | ||
| 3959 | + const NEAREST_NEARESTMV: u8 = 0; | ||
| 3960 | + const NEAR_NEARMV: u8 = 1; | ||
| 3961 | + const NEAREST_NEWMV: u8 = 2; | ||
| 3962 | + const NEW_NEARESTMV: u8 = 3; | ||
| 3963 | + const NEAR_NEWMV: u8 = 4; | ||
| 3964 | + const NEW_NEARMV: u8 = 5; | ||
| 3965 | + const GLOBAL_GLOBALMV: u8 = 6; | ||
| 3966 | + const NEW_NEWMV: u8 = 7; | ||
| 3967 | + | ||
| 3968 | + let mut ref_mv_idx = 0usize; | ||
| 3969 | + if mode == NEW_NEWMV { | ||
| 3970 | + let mut idx = 0usize; | ||
| 3971 | + while idx < 2 && comp_stack.entries.len() > idx + 1 { | ||
| 3972 | + if dec.symbol(&mut cdfs.drl_mode[comp_stack.drl_ctx[idx]]) == 0 { | ||
| 3973 | + break; | ||
| 3974 | + } | ||
| 3975 | + idx += 1; | ||
| 3976 | + } | ||
| 3977 | + ref_mv_idx = idx; | ||
| 3978 | + } else if matches!(mode, NEAR_NEARMV | NEAR_NEWMV | NEW_NEARMV) { | ||
| 3979 | + let mut idx = 1usize; | ||
| 3980 | + while idx < 3 && comp_stack.entries.len() > idx + 1 { | ||
| 3981 | + if dec.symbol(&mut cdfs.drl_mode[comp_stack.drl_ctx[idx]]) == 0 { | ||
| 3982 | + break; | ||
| 3983 | + } | ||
| 3984 | + idx += 1; | ||
| 3985 | + } | ||
| 3986 | + ref_mv_idx = idx - 1; | ||
| 3987 | + } | ||
| 3988 | + | ||
| 3989 | + let near = comp_stack | ||
| 3990 | + .entries | ||
| 3991 | + .get(ref_mv_idx + 1) | ||
| 3992 | + .map_or(comp_stack.near_mv, |e| (e.mv0, e.mv1)); | ||
| 3993 | + let new_idx = if matches!(mode, NEAR_NEWMV | NEW_NEARMV) { | ||
| 3994 | + ref_mv_idx + 1 | ||
| 3995 | + } else { | ||
| 3996 | + ref_mv_idx | ||
| 3997 | + }; | ||
| 3998 | + let new_pred = comp_stack | ||
| 3999 | + .entries | ||
| 4000 | + .get(new_idx) | ||
| 4001 | + .map_or(comp_stack.nearest_mv, |e| (e.mv0, e.mv1)); | ||
| 4002 | + | ||
| 4003 | + let read_new = |dec: &mut SymbolDecoder, cdfs: &mut Cdfs, base: (i32, i32)| { | ||
| 4004 | + read_mv( | ||
| 4005 | + dec, | ||
| 4006 | + &mut cdfs.mv_comp, | ||
| 4007 | + &mut cdfs.mv_joint, | ||
| 4008 | + base, | ||
| 4009 | + allow_high_precision_mv, | ||
| 4010 | + ) | ||
| 4011 | + }; | ||
| 4012 | + | ||
| 4013 | + match mode { | ||
| 4014 | + NEAREST_NEARESTMV => comp_stack.nearest_mv, | ||
| 4015 | + NEAR_NEARMV => near, | ||
| 4016 | + NEAREST_NEWMV => (comp_stack.nearest_mv.0, read_new(dec, cdfs, new_pred.1)), | ||
| 4017 | + NEW_NEARESTMV => (read_new(dec, cdfs, new_pred.0), comp_stack.nearest_mv.1), | ||
| 4018 | + NEAR_NEWMV => (near.0, read_new(dec, cdfs, new_pred.1)), | ||
| 4019 | + NEW_NEARMV => (read_new(dec, cdfs, new_pred.0), near.1), | ||
| 4020 | + GLOBAL_GLOBALMV => ((0, 0), (0, 0)), | ||
| 4021 | + _ => ( | ||
| 4022 | + read_new(dec, cdfs, new_pred.0), | ||
| 4023 | + read_new(dec, cdfs, new_pred.1), | ||
| 4024 | + ), | ||
| 4025 | + } | ||
| 4026 | +} | ||
| 4027 | + | ||
| 3940 | /// Decodes one square inter-frame block (32x32 whole or 16x16 leaf): skip, | 4028 | /// Decodes one square inter-frame block (32x32 whole or 16x16 leaf): skip, |
| 3941 | /// `is_inter`, then either the single-reference/MV-stack/motion-vector chain | 4029 | /// `is_inter`, then either the single-reference/MV-stack/motion-vector chain |
| 3942 | /// and motion-compensated reconstruction, or the inter frame's own intra | 4030 | /// and motion-compensated reconstruction, or the inter frame's own intra |
| @@ -4077,16 +4165,23 @@ fn decode_inter_block( | |||
| 4077 | sign_bias_table, | 4165 | sign_bias_table, |
| 4078 | comp_tpl, | 4166 | comp_tpl, |
| 4079 | ); | 4167 | ); |
| 4080 | - let _compound_mode = read_inter_compound_mode( | 4168 | + let compound_mode = read_inter_compound_mode( |
| 4081 | dec, | 4169 | dec, |
| 4082 | cdfs, | 4170 | cdfs, |
| 4083 | comp_stack.new_mv_ctx, | 4171 | comp_stack.new_mv_ctx, |
| 4084 | comp_stack.ref_mv_ctx, | 4172 | comp_stack.ref_mv_ctx, |
| 4085 | ); | 4173 | ); |
| 4174 | + let _mv_pair = assign_compound_mv( | ||
| 4175 | + dec, | ||
| 4176 | + cdfs, | ||
| 4177 | + &comp_stack, | ||
| 4178 | + compound_mode, | ||
| 4179 | + allow_high_precision_mv, | ||
| 4180 | + ); | ||
| 4086 | return Err(unsupported( | 4181 | return Err(unsupported( |
| 4087 | - "a COMPOUND_REFERENCE block (comp_mode/comp_ref/inter_compound_mode read \ | 4182 | + "a COMPOUND_REFERENCE block (comp_mode/comp_ref/inter_compound_mode/\ |
| 4088 | - correctly; compound DRL, MV assignment, and two-reference motion \ | 4183 | + compound DRL/MV assignment read correctly; two-reference motion \ |
| 4089 | - compensation are not wired yet -- lane-av1comp)", | 4184 | + compensation is not wired yet -- lane-av1comp)", |
| 4090 | )); | 4185 | )); |
| 4091 | } | 4186 | } |
| 4092 | } | 4187 | } |
| @@ -4624,7 +4719,7 @@ fn decode_inter_block8( | |||
| 4624 | uni: false, | 4719 | uni: false, |
| 4625 | }); | 4720 | }); |
| 4626 | if read_comp_mode(dec, cdfs, above_nbr, left_nbr) { | 4721 | if read_comp_mode(dec, cdfs, above_nbr, left_nbr) { |
| 4627 | - read_compound_ref_frames( | 4722 | + let (ref0, ref1) = read_compound_ref_frames( |
| 4628 | dec, | 4723 | dec, |
| 4629 | cdfs, | 4724 | cdfs, |
| 4630 | above_nbr, | 4725 | above_nbr, |
| @@ -4640,9 +4735,42 @@ fn decode_inter_block8( | |||
| 4640 | -1 | 4735 | -1 |
| 4641 | }, | 4736 | }, |
| 4642 | ); | 4737 | ); |
| 4738 | + let (mi_row, mi_col) = leaf_mi; | ||
| 4739 | + // lane-av1comp: this leaf path has neither a real sign-bias | ||
| 4740 | + // table nor `tpl_frame` (see this function's own doc on the | ||
| 4741 | + // coarse `LAST_FRAME`-or-intra neighbour approximation | ||
| 4742 | + // already in force above), matching the plain `find_mv_stack` | ||
| 4743 | + // (no bias, no tpl) the leaf's single-ref arm below already | ||
| 4744 | + // uses. | ||
| 4745 | + let comp_stack = crate::mvstack::find_mv_stack_compound( | ||
| 4746 | + grid, | ||
| 4747 | + mi_row, | ||
| 4748 | + mi_col, | ||
| 4749 | + 2, | ||
| 4750 | + 2, | ||
| 4751 | + (ref0, ref1), | ||
| 4752 | + mi_cols as usize, | ||
| 4753 | + mi_rows as usize, | ||
| 4754 | + &NO_SIGN_BIAS, | ||
| 4755 | + None, | ||
| 4756 | + ); | ||
| 4757 | + let compound_mode = read_inter_compound_mode( | ||
| 4758 | + dec, | ||
| 4759 | + cdfs, | ||
| 4760 | + comp_stack.new_mv_ctx, | ||
| 4761 | + comp_stack.ref_mv_ctx, | ||
| 4762 | + ); | ||
| 4763 | + let _mv_pair = assign_compound_mv( | ||
| 4764 | + dec, | ||
| 4765 | + cdfs, | ||
| 4766 | + &comp_stack, | ||
| 4767 | + compound_mode, | ||
| 4768 | + allow_high_precision_mv, | ||
| 4769 | + ); | ||
| 4643 | return Err(unsupported( | 4770 | return Err(unsupported( |
| 4644 | - "a COMPOUND_REFERENCE 8x8 leaf (comp_mode/comp_ref read correctly; \ | 4771 | + "a COMPOUND_REFERENCE 8x8 leaf (comp_mode/comp_ref/inter_compound_mode/\ |
| 4645 | - two-reference motion compensation is not wired yet -- lane-av1comp)", | 4772 | + compound DRL/MV assignment read correctly; two-reference motion \ |
| 4773 | + compensation is not wired yet -- lane-av1comp)", | ||
| 4646 | )); | 4774 | )); |
| 4647 | } | 4775 | } |
| 4648 | } | 4776 | } |