Merge branch 'lane-dgolomb' (a4670b5a): temporal MV candidates ignored force_integer_mv; libaom's film B streams decode sample-exact
Browse files at this commit5 changed files +309 -10
- crates/ec-av1/src/decode.rs +6 -0
- crates/ec-av1/src/motion_field.rs +70 -8
- crates/ec-av1/src/mvstack.rs +35 -2
- crates/ec-av1/src/stream.rs +109 -0
- lanes/dgolomb.report.md +89 -0
crates/ec-av1/src/decode.rsmodified+6 -0
| @@ -26220,6 +26220,7 @@ fn decode_inter_block( | ||
| 26220 | 26220 | t.ref_order_hints[(ref1 - LAST_FRAME) as usize], |
| 26221 | 26221 | ), |
| 26222 | 26222 | allow_high_precision_mv, |
| 26223 | + force_integer_mv, | |
| 26223 | 26224 | }); |
| 26224 | 26225 | let gm_table = build_gm_mv_table( |
| 26225 | 26226 | global_motion, |
| @@ -27444,6 +27445,7 @@ fn decode_inter_block( | ||
| 27444 | 27445 | t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], |
| 27445 | 27446 | ), |
| 27446 | 27447 | allow_high_precision_mv, |
| 27448 | + force_integer_mv, | |
| 27447 | 27449 | }); |
| 27448 | 27450 | let gm_table = build_gm_mv_table( |
| 27449 | 27451 | global_motion, |
| @@ -29829,6 +29831,7 @@ fn decode_inter_sub8_split4( | ||
| 29829 | 29831 | t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], |
| 29830 | 29832 | ), |
| 29831 | 29833 | allow_high_precision_mv, |
| 29834 | + force_integer_mv, | |
| 29832 | 29835 | }); |
| 29833 | 29836 | let stack = crate::mvstack::find_mv_stack_with_sign_bias( |
| 29834 | 29837 | grid, |
| @@ -30857,6 +30860,7 @@ fn decode_inter_sub8_rect2( | ||
| 30857 | 30860 | t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], |
| 30858 | 30861 | ), |
| 30859 | 30862 | allow_high_precision_mv, |
| 30863 | + force_integer_mv, | |
| 30860 | 30864 | }); |
| 30861 | 30865 | let stack = crate::mvstack::find_mv_stack_with_sign_bias( |
| 30862 | 30866 | grid, |
| @@ -31603,6 +31607,7 @@ fn decode_inter_block8( | ||
| 31603 | 31607 | t.ref_order_hints[(ref1 - LAST_FRAME) as usize], |
| 31604 | 31608 | ), |
| 31605 | 31609 | allow_high_precision_mv, |
| 31610 | + force_integer_mv, | |
| 31606 | 31611 | }); |
| 31607 | 31612 | // lane-av1comp: this leaf path has neither a real sign-bias |
| 31608 | 31613 | // table nor `tpl_frame` (see this function's own doc on the |
| @@ -32293,6 +32298,7 @@ fn decode_inter_block8( | ||
| 32293 | 32298 | t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], |
| 32294 | 32299 | ), |
| 32295 | 32300 | allow_high_precision_mv, |
| 32301 | + force_integer_mv, | |
| 32296 | 32302 | }); |
| 32297 | 32303 | let stack = crate::mvstack::find_mv_stack_with_sign_bias( |
| 32298 | 32304 | grid, |
crates/ec-av1/src/motion_field.rsmodified+70 -8
| @@ -174,11 +174,35 @@ fn get_mv_projection(mv: (i32, i32), num: i32, den: i32) -> (i32, i32) { | ||
| 174 | 174 | (scale(mv.0), scale(mv.1)) |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | -/// `lower_mv_precision` (`mvref_common.h`), the `is_integer == false` half | |
| 178 | -/// only — every stream this decoder ever reaches has `force_integer_mv == | |
| 179 | -/// false` on an inter frame (`allow_screen_content_tools`, the only source | |
| 180 | -/// of a `true` value here, is refused outright at the stream level). | |
| 181 | -pub fn lower_mv_precision(mv: (i32, i32), allow_high_precision_mv: bool) -> (i32, i32) { | |
| 177 | +/// `lower_mv_precision` (`mvref_common.h`), both halves. lane-dgolomb: the | |
| 178 | +/// `is_integer` half used to be dropped as unreachable on the claim that | |
| 179 | +/// `allow_screen_content_tools` is refused at the stream level -- it is not, | |
| 180 | +/// and libaom turns screen-content tools on for dark, smooth FILM (its | |
| 181 | +/// `av1_set_screen_content_options` counts near-flat blocks), so a real | |
| 182 | +/// libaom stream carries `force_integer_mv == 1` on an inter frame and every | |
| 183 | +/// temporal MV candidate has to be rounded to full pel. Without it the | |
| 184 | +/// candidates were 1/8-pel values libaom never produces: a whole-frame | |
| 185 | +/// prediction mismatch behind a clean parse (class | |
| 186 | +/// `branch-dropped-as-unreachable`). | |
| 187 | +pub fn lower_mv_precision( | |
| 188 | + mv: (i32, i32), | |
| 189 | + allow_high_precision_mv: bool, | |
| 190 | + force_integer_mv: bool, | |
| 191 | +) -> (i32, i32) { | |
| 192 | + if force_integer_mv { | |
| 193 | + // `integer_mv_precision`: drop to the nearest full pel, ties away | |
| 194 | + // from zero (`abs(mod) > 4`). | |
| 195 | + let round = |v: i32| { | |
| 196 | + let m = v % 8; | |
| 197 | + match m { | |
| 198 | + 0 => v, | |
| 199 | + _ if m > 4 => v - m + 8, | |
| 200 | + _ if m < -4 => v - m - 8, | |
| 201 | + _ => v - m, | |
| 202 | + } | |
| 203 | + }; | |
| 204 | + return (round(mv.0), round(mv.1)); | |
| 205 | + } | |
| 182 | 206 | if allow_high_precision_mv { |
| 183 | 207 | return mv; |
| 184 | 208 | } |
| @@ -526,6 +550,7 @@ pub fn add_tpl_ref_mv( | ||
| 526 | 550 | blk_col: isize, |
| 527 | 551 | cur_offset_0: i32, |
| 528 | 552 | allow_high_precision_mv: bool, |
| 553 | + force_integer_mv: bool, | |
| 529 | 554 | ) -> Option<TplCandidate> { |
| 530 | 555 | let probe = tpl.probe(mi_row, mi_col).cell(blk_row, blk_col); |
| 531 | 556 | if crate::envflags::env_flag!("EC_TRACE_TPL") { |
| @@ -539,7 +564,13 @@ pub fn add_tpl_ref_mv( | ||
| 539 | 564 | } |
| 540 | 565 | let (fwd_mv, ref_frame_offset) = probe?; |
| 541 | 566 | Some(TplCandidate { |
| 542 | - mv: project_tpl_mv(fwd_mv, cur_offset_0, ref_frame_offset, allow_high_precision_mv), | |
| 567 | + mv: project_tpl_mv( | |
| 568 | + fwd_mv, | |
| 569 | + cur_offset_0, | |
| 570 | + ref_frame_offset, | |
| 571 | + allow_high_precision_mv, | |
| 572 | + force_integer_mv, | |
| 573 | + ), | |
| 543 | 574 | }) |
| 544 | 575 | } |
| 545 | 576 | |
| @@ -552,9 +583,10 @@ pub fn project_tpl_mv( | ||
| 552 | 583 | cur_offset: i32, |
| 553 | 584 | ref_frame_offset: i32, |
| 554 | 585 | allow_high_precision_mv: bool, |
| 586 | + force_integer_mv: bool, | |
| 555 | 587 | ) -> (i32, i32) { |
| 556 | 588 | let projected = get_mv_projection(fwd_mv, cur_offset, ref_frame_offset); |
| 557 | - lower_mv_precision(projected, allow_high_precision_mv) | |
| 589 | + lower_mv_precision(projected, allow_high_precision_mv, force_integer_mv) | |
| 558 | 590 | } |
| 559 | 591 | |
| 560 | 592 | /// One query block's view of [`TplField`] (lane-tpl). `add_tpl_ref_mv`'s |
| @@ -709,7 +741,37 @@ mod tests { | ||
| 709 | 741 | // ref_frame_offset = get_relative_dist(2,1) = 1, scaling (-64,0) by |
| 710 | 742 | // 2/1 -> (-128,0); get_block_position's sign_bias (dir=2) subtracts |
| 711 | 743 | // the offset, landing at 8x8 cell (2, 0). |
| 712 | - let cand = add_tpl_ref_mv(&tpl, 4, 0, 0isize, 0isize, get_relative_dist(7, 4, 2), true); | |
| 744 | + let cand = | |
| 745 | + add_tpl_ref_mv(&tpl, 4, 0, 0isize, 0isize, get_relative_dist(7, 4, 2), true, false); | |
| 713 | 746 | assert!(cand.is_some(), "expected a projected temporal candidate"); |
| 714 | 747 | } |
| 748 | + | |
| 749 | + /// lane-dgolomb: `lower_mv_precision`'s `force_integer_mv` half, which | |
| 750 | + /// this decoder used to drop as unreachable. The values are the ones a | |
| 751 | + /// real libaom stream (film B, `-cpu-used 6 -crf 35`, the one inter frame | |
| 752 | + /// whose header carries `force_integer_mv == 1`) produces at its first | |
| 753 | + /// 128x128 block: the same 16 temporal probes, projected and then rounded | |
| 754 | + /// to full pel, are what put `(16,0)`/`(16,-8)`/`(8,-40)` in libaom's own | |
| 755 | + /// traced mv stack where the eighth-pel values were `(14,-4)`/`(12,-2)`/ | |
| 756 | + /// `(12,-38)`/`(16,-4)`. | |
| 757 | + #[test] | |
| 758 | + fn force_integer_mv_rounds_a_projected_candidate_to_full_pel() { | |
| 759 | + // (mfmv0, ref_frame_offset) -> (eighth-pel value, full-pel value), | |
| 760 | + // all at cur_offset_0 == 1. | |
| 761 | + for (mv, rfo, eighth, integer) in [ | |
| 762 | + ((74, -20), 5, (14, -4), (16, 0)), | |
| 763 | + ((74, -24), 5, (14, -4), (16, -8)), | |
| 764 | + ((82, -24), 5, (16, -4), (16, -8)), | |
| 765 | + ((66, -16), 5, (12, -2), (16, 0)), | |
| 766 | + ((24, -76), 2, (12, -38), (8, -40)), | |
| 767 | + ] { | |
| 768 | + assert_eq!(project_tpl_mv(mv, 1, rfo, false, false), eighth, "{mv:?}"); | |
| 769 | + assert_eq!(project_tpl_mv(mv, 1, rfo, false, true), integer, "{mv:?}"); | |
| 770 | + } | |
| 771 | + // `integer_mv_precision`'s tie rule is away from zero on |mod| > 4 | |
| 772 | + // only, and it is signed-symmetric. | |
| 773 | + assert_eq!(lower_mv_precision((4, -4), false, true), (0, 0)); | |
| 774 | + assert_eq!(lower_mv_precision((5, -5), false, true), (8, -8)); | |
| 775 | + assert_eq!(lower_mv_precision((-12, 8), false, true), (-8, 8)); | |
| 776 | + } | |
| 715 | 777 | } |
crates/ec-av1/src/mvstack.rsmodified+35 -2
| @@ -154,6 +154,10 @@ pub struct TplArgs<'a> { | ||
| 154 | 154 | pub cur_offset_0: i32, |
| 155 | 155 | /// The frame header's own `allow_high_precision_mv`. |
| 156 | 156 | pub allow_high_precision_mv: bool, |
| 157 | + /// The frame header's own `force_integer_mv` (`lower_mv_precision`'s | |
| 158 | + /// `is_integer`): a screen-content frame rounds every projected temporal | |
| 159 | + /// candidate to full pel. | |
| 160 | + pub force_integer_mv: bool, | |
| 157 | 161 | } |
| 158 | 162 | |
| 159 | 163 | /// [`MiInfo::ref_frame1`]'s "this unit was not coded compound" value. Slot 1 |
| @@ -1036,6 +1040,7 @@ fn tpl_trace_sample( | ||
| 1036 | 1040 | blk_col: isize, |
| 1037 | 1041 | cur_offset: i32, |
| 1038 | 1042 | allow_high_precision_mv: bool, |
| 1043 | + force_integer_mv: bool, | |
| 1039 | 1044 | ) -> Option<(i32, i32)> { |
| 1040 | 1045 | crate::motion_field::add_tpl_ref_mv( |
| 1041 | 1046 | field, |
| @@ -1045,6 +1050,7 @@ fn tpl_trace_sample( | ||
| 1045 | 1050 | blk_col, |
| 1046 | 1051 | cur_offset, |
| 1047 | 1052 | allow_high_precision_mv, |
| 1053 | + force_integer_mv, | |
| 1048 | 1054 | ) |
| 1049 | 1055 | .map(|c| c.mv) |
| 1050 | 1056 | } |
| @@ -1061,6 +1067,7 @@ fn tpl_trace_sample_compound( | ||
| 1061 | 1067 | blk_col: isize, |
| 1062 | 1068 | cur_offsets: (i32, i32), |
| 1063 | 1069 | allow_high_precision_mv: bool, |
| 1070 | + force_integer_mv: bool, | |
| 1064 | 1071 | ) { |
| 1065 | 1072 | for off in [cur_offsets.0, cur_offsets.1] { |
| 1066 | 1073 | let _ = crate::motion_field::add_tpl_ref_mv( |
| @@ -1071,6 +1078,7 @@ fn tpl_trace_sample_compound( | ||
| 1071 | 1078 | blk_col, |
| 1072 | 1079 | off, |
| 1073 | 1080 | allow_high_precision_mv, |
| 1081 | + force_integer_mv, | |
| 1074 | 1082 | ); |
| 1075 | 1083 | } |
| 1076 | 1084 | } |
| @@ -1093,6 +1101,7 @@ fn tpl_sample( | ||
| 1093 | 1101 | blk_col: isize, |
| 1094 | 1102 | cur_offset: i32, |
| 1095 | 1103 | allow_high_precision_mv: bool, |
| 1104 | + force_integer_mv: bool, | |
| 1096 | 1105 | ) -> Option<(i32, i32)> { |
| 1097 | 1106 | if trace_tpl { |
| 1098 | 1107 | return tpl_trace_sample( |
| @@ -1103,6 +1112,7 @@ fn tpl_sample( | ||
| 1103 | 1112 | blk_col, |
| 1104 | 1113 | cur_offset, |
| 1105 | 1114 | allow_high_precision_mv, |
| 1115 | + force_integer_mv, | |
| 1106 | 1116 | ); |
| 1107 | 1117 | } |
| 1108 | 1118 | let (fwd_mv, rfo) = probe.cell(blk_row, blk_col)?; |
| @@ -1111,6 +1121,7 @@ fn tpl_sample( | ||
| 1111 | 1121 | cur_offset, |
| 1112 | 1122 | rfo, |
| 1113 | 1123 | allow_high_precision_mv, |
| 1124 | + force_integer_mv, | |
| 1114 | 1125 | )) |
| 1115 | 1126 | } |
| 1116 | 1127 | |
| @@ -1128,6 +1139,7 @@ fn tpl_sample_compound( | ||
| 1128 | 1139 | blk_col: isize, |
| 1129 | 1140 | cur_offsets: (i32, i32), |
| 1130 | 1141 | allow_high_precision_mv: bool, |
| 1142 | + force_integer_mv: bool, | |
| 1131 | 1143 | ) -> Option<((i32, i32), (i32, i32))> { |
| 1132 | 1144 | if trace_tpl { |
| 1133 | 1145 | tpl_trace_sample_compound( |
| @@ -1138,12 +1150,25 @@ fn tpl_sample_compound( | ||
| 1138 | 1150 | blk_col, |
| 1139 | 1151 | cur_offsets, |
| 1140 | 1152 | allow_high_precision_mv, |
| 1153 | + force_integer_mv, | |
| 1141 | 1154 | ); |
| 1142 | 1155 | } |
| 1143 | 1156 | let (fwd_mv, rfo) = probe.cell(blk_row, blk_col)?; |
| 1144 | 1157 | Some(( |
| 1145 | - crate::motion_field::project_tpl_mv(fwd_mv, cur_offsets.0, rfo, allow_high_precision_mv), | |
| 1146 | - crate::motion_field::project_tpl_mv(fwd_mv, cur_offsets.1, rfo, allow_high_precision_mv), | |
| 1158 | + crate::motion_field::project_tpl_mv( | |
| 1159 | + fwd_mv, | |
| 1160 | + cur_offsets.0, | |
| 1161 | + rfo, | |
| 1162 | + allow_high_precision_mv, | |
| 1163 | + force_integer_mv, | |
| 1164 | + ), | |
| 1165 | + crate::motion_field::project_tpl_mv( | |
| 1166 | + fwd_mv, | |
| 1167 | + cur_offsets.1, | |
| 1168 | + rfo, | |
| 1169 | + allow_high_precision_mv, | |
| 1170 | + force_integer_mv, | |
| 1171 | + ), | |
| 1147 | 1172 | )) |
| 1148 | 1173 | } |
| 1149 | 1174 | |
| @@ -1312,6 +1337,7 @@ pub fn find_mv_stack_with_sign_bias( | ||
| 1312 | 1337 | field, |
| 1313 | 1338 | cur_offset_0, |
| 1314 | 1339 | allow_high_precision_mv, |
| 1340 | + force_integer_mv, | |
| 1315 | 1341 | }) = tpl |
| 1316 | 1342 | { |
| 1317 | 1343 | let mut any_hit = false; |
| @@ -1342,6 +1368,7 @@ pub fn find_mv_stack_with_sign_bias( | ||
| 1342 | 1368 | blk_col, |
| 1343 | 1369 | cur_offset_0, |
| 1344 | 1370 | allow_high_precision_mv, |
| 1371 | + force_integer_mv, | |
| 1345 | 1372 | ) |
| 1346 | 1373 | }; |
| 1347 | 1374 | let mut blk_row = 0usize; |
| @@ -2116,6 +2143,7 @@ pub fn find_mv_stack_compound( | ||
| 2116 | 2143 | cur_offset_0, |
| 2117 | 2144 | cur_offset_1, |
| 2118 | 2145 | allow_high_precision_mv, |
| 2146 | + force_integer_mv, | |
| 2119 | 2147 | }) = tpl |
| 2120 | 2148 | { |
| 2121 | 2149 | let mut any_hit = false; |
| @@ -2144,6 +2172,7 @@ pub fn find_mv_stack_compound( | ||
| 2144 | 2172 | blk_col, |
| 2145 | 2173 | (cur_offset_0, cur_offset_1), |
| 2146 | 2174 | allow_high_precision_mv, |
| 2175 | + force_integer_mv, | |
| 2147 | 2176 | ) |
| 2148 | 2177 | }; |
| 2149 | 2178 | let mut blk_row = 0usize; |
| @@ -2411,6 +2440,10 @@ pub struct CompoundTplArgs<'a> { | ||
| 2411 | 2440 | pub cur_offset_1: i32, |
| 2412 | 2441 | /// The frame header's own `allow_high_precision_mv`. |
| 2413 | 2442 | pub allow_high_precision_mv: bool, |
| 2443 | + /// The frame header's own `force_integer_mv` (`lower_mv_precision`'s | |
| 2444 | + /// `is_integer`): a screen-content frame rounds every projected temporal | |
| 2445 | + /// candidate to full pel. | |
| 2446 | + pub force_integer_mv: bool, | |
| 2414 | 2447 | } |
| 2415 | 2448 | |
| 2416 | 2449 | /// The single-reference context shared by the `single_ref_p1`/`p3`/`p4` |
crates/ec-av1/src/stream.rsmodified+109 -0
| @@ -3758,6 +3758,115 @@ pub(crate) mod tests { | ||
| 3758 | 3758 | } |
| 3759 | 3759 | } |
| 3760 | 3760 | |
| 3761 | + /// lane-dgolomb: the `force_integer_mv` gate. libaom turns screen-content | |
| 3762 | + /// tools on for DARK, SMOOTH content -- its `av1_set_screen_content_options` | |
| 3763 | + /// counts 16x16 blocks with 2..=4 distinct luma values -- and then sets | |
| 3764 | + /// `force_integer_mv` on any inter frame whose source is pixel-identical to | |
| 3765 | + /// the previously coded source (`av1_is_integer_mv`: `cs_rate >= 0.8` and | |
| 3766 | + /// `C == T`, every collocated 8x8 block matching, is the only path that | |
| 3767 | + /// returns 1). Both hold on his real AV1 films, and this decoder used to | |
| 3768 | + /// drop `lower_mv_precision`'s `is_integer` half as unreachable, so every | |
| 3769 | + /// temporal MV candidate on such a frame came out at eighth-pel: the frame | |
| 3770 | + /// decoded without any error into a whole-frame prediction mismatch, and | |
| 3771 | + /// the desync surfaced blocks later as "a Golomb tail longer than this | |
| 3772 | + /// decoder reads". | |
| 3773 | + /// | |
| 3774 | + /// The source is SYNTHETIC (no film sample lives in `fixtures`): a | |
| 3775 | + /// near-flat dark background at the film-B crop size, 1920x1024, with one | |
| 3776 | + /// textured patch stepping 9 px every SECOND frame, so half the frames are | |
| 3777 | + /// exact duplicates of their predecessor (the `C == T` trigger) while the | |
| 3778 | + /// motion field still holds non-zero MVs whose projections are not | |
| 3779 | + /// multiples of 8. The gate asserts both halves: at least one INTER frame | |
| 3780 | + /// really carries `force_integer_mv` (class `gate-blind-to-feature`), and | |
| 3781 | + /// every shown frame decodes sample-exact against ffmpeg's own decode. | |
| 3782 | + #[test] | |
| 3783 | + fn a_libaom_force_integer_mv_stream_decodes_exact() { | |
| 3784 | + const NAME: &str = "a_libaom_force_integer_mv_stream_decodes_exact"; | |
| 3785 | + if !have_ffmpeg() { | |
| 3786 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 3787 | + return; | |
| 3788 | + } | |
| 3789 | + let (w, h, frames) = (1920usize, 1024usize, 12usize); | |
| 3790 | + let mut raw = Vec::with_capacity(frames * w * h * 3 / 2); | |
| 3791 | + for f in 0..frames { | |
| 3792 | + let mut y = vec![0u8; w * h]; | |
| 3793 | + for row in 0..h { | |
| 3794 | + for col in 0..w { | |
| 3795 | + // 2..=4 distinct values per 16x16 block, all dark: the | |
| 3796 | + // screen-content detector's own counting rule. | |
| 3797 | + y[row * w + col] = | |
| 3798 | + 16 + ((col / 32 + row / 32) % 5) as u8 + ((col / 4 + row / 4) % 3) as u8; | |
| 3799 | + } | |
| 3800 | + } | |
| 3801 | + let x0 = 200 + 9 * (f / 2); | |
| 3802 | + for row in 300..428 { | |
| 3803 | + for col in x0..x0 + 192 { | |
| 3804 | + y[row * w + col] = | |
| 3805 | + ((((col - x0) / 3) * 7 + ((row - 300) / 5) * 13) % 200 + 30) as u8; | |
| 3806 | + } | |
| 3807 | + } | |
| 3808 | + raw.extend_from_slice(&y); | |
| 3809 | + raw.extend(std::iter::repeat_n(128u8, w * h / 2)); | |
| 3810 | + } | |
| 3811 | + // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. | |
| 3812 | + let src = std::env::temp_dir().join(format!("ec-av1-intmv-{}.yuv", std::process::id())); | |
| 3813 | + std::fs::write(&src, &raw).expect("raw source"); | |
| 3814 | + let out = Command::new("ffmpeg") | |
| 3815 | + .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) | |
| 3816 | + .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) | |
| 3817 | + .arg(&src) | |
| 3818 | + .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"]) | |
| 3819 | + .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"]) | |
| 3820 | + .stdin(Stdio::null()) | |
| 3821 | + .stdout(Stdio::piped()) | |
| 3822 | + .stderr(Stdio::piped()) | |
| 3823 | + .output() | |
| 3824 | + .expect("ffmpeg failed to run"); | |
| 3825 | + let _ = std::fs::remove_file(&src); | |
| 3826 | + if !out.status.success() { | |
| 3827 | + eprintln!( | |
| 3828 | + "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})", | |
| 3829 | + String::from_utf8_lossy(&out.stderr) | |
| 3830 | + ); | |
| 3831 | + return; | |
| 3832 | + } | |
| 3833 | + let stream = out.stdout; | |
| 3834 | + | |
| 3835 | + // Half of the gate: the stream must actually carry the feature. | |
| 3836 | + let mut parser = Av1Parser::new(); | |
| 3837 | + let (mut pos, mut int_mv_inter) = (0usize, 0usize); | |
| 3838 | + while pos < stream.len() { | |
| 3839 | + let obu = parser.parse_obu(&stream[pos..]).expect("libaom OBU parses"); | |
| 3840 | + pos += obu.total_size.max(1); | |
| 3841 | + let header = match &obu.kind { | |
| 3842 | + ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h, | |
| 3843 | + _ => continue, | |
| 3844 | + }; | |
| 3845 | + if header.force_integer_mv && !header.frame_is_intra && header.use_ref_frame_mvs { | |
| 3846 | + int_mv_inter += 1; | |
| 3847 | + } | |
| 3848 | + } | |
| 3849 | + assert!( | |
| 3850 | + int_mv_inter > 0, | |
| 3851 | + "{NAME} went blind: libaom coded no inter frame with force_integer_mv" | |
| 3852 | + ); | |
| 3853 | + | |
| 3854 | + let ours = decode_stream(&stream).expect("libaom screen-content stream decodes"); | |
| 3855 | + let theirs = ffmpeg_decode_sequence(&stream, w, h, frames); | |
| 3856 | + assert_eq!(ours.len(), frames, "shown frame count"); | |
| 3857 | + for (i, (a, b)) in ours.iter().zip(theirs.iter()).enumerate() { | |
| 3858 | + for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] { | |
| 3859 | + let first = l.iter().zip(r.iter()).position(|(x, y)| x != y); | |
| 3860 | + assert!( | |
| 3861 | + first.is_none(), | |
| 3862 | + "frame {i} plane {plane} differs from ffmpeg at sample {} \ | |
| 3863 | + ({int_mv_inter} force_integer_mv inter frames in this stream)", | |
| 3864 | + first.unwrap() | |
| 3865 | + ); | |
| 3866 | + } | |
| 3867 | + } | |
| 3868 | + } | |
| 3869 | + | |
| 3761 | 3870 | /// Hardened past the report-only test above: a real libaom-av1 gradients |
| 3762 | 3871 | /// stream, pinned deterministic (`gradients`' own `seed=`, plus |
| 3763 | 3872 | /// `-threads 1`/`-row-mt 0`/no tiling so libaom's `cpu-used 8` RD search |
lanes/dgolomb.report.mdadded+89 -0
| @@ -0,0 +1,89 @@ | ||
| 1 | +# lane-dgolomb — libaom film-B decode (the "Golomb tail" refusal) | |
| 2 | + | |
| 3 | +## Root cause (closed) | |
| 4 | +`crates/ec-av1/src/motion_field.rs` `lower_mv_precision` implemented only the | |
| 5 | +`is_integer == false` half of libaom's function, on a comment claiming | |
| 6 | +`force_integer_mv` is unreachable because `allow_screen_content_tools` is | |
| 7 | +"refused outright at the stream level". Both halves of that claim are false: | |
| 8 | + | |
| 9 | +* libaom's `av1_set_screen_content_options` counts 16x16 blocks with 2..=4 | |
| 10 | + distinct luma values, so DARK, SMOOTH FILM reads as screen content — every | |
| 11 | + frame of the film-B gate clip has `allow_screen_content_tools = 1`; | |
| 12 | +* `av1_is_integer_mv` (encoder_utils.c:1357) returns 1 exactly when | |
| 13 | + `cs_rate >= 0.8` **and** `C == T`, i.e. when the source frame is | |
| 14 | + pixel-identical to the previously coded source. Film B has such frames. | |
| 15 | + | |
| 16 | +So a real libaom stream carries `force_integer_mv = 1` on an inter frame, and | |
| 17 | +every temporal MV candidate must be rounded to full pel. Ours stayed at | |
| 18 | +eighth-pel → the mv stack held values libaom never produced → whole-frame | |
| 19 | +prediction mismatch behind a clean parse, and the entropy desync surfaced | |
| 20 | +blocks later as `a Golomb tail longer than this decoder reads` | |
| 21 | +(class `refusal-names-a-correlate`). | |
| 22 | + | |
| 23 | +**Class: `branch-dropped-as-unreachable`** — a spec branch deleted on an | |
| 24 | +unreachability note that a later capability change silently invalidated. | |
| 25 | + | |
| 26 | +## First divergence (measured, not reasoned) | |
| 27 | +Film-B gate clip (1920x1024 crop, `-cpu-used 6 -crf 35 -g 12`), decode-order | |
| 28 | +frame 3 = order_hint 1, the ONE inter frame with `force_integer_mv = 1`, | |
| 29 | +block mi(0,0) (128x128, NEWMV, ref LAST): | |
| 30 | + | |
| 31 | +* `EC_TPL` field cells identical in both decoders (16 probes), range identical | |
| 32 | + (`rng=49952`) — so the field and the entropy state were right; | |
| 33 | +* instrumented aomdec stack: `(16,0)w16 (16,-8)w12 (8,-40)w4` | |
| 34 | +* ours before the fix: `(14,-4)w16 (12,-2)w8 (12,-38)w4 (16,-4)w4` | |
| 35 | +* `(74,-20)/5 → 15,-4 → integer → (16,0)` reproduces libaom exactly. | |
| 36 | + | |
| 37 | +## Fix | |
| 38 | +`lower_mv_precision(mv, allow_high_precision_mv, force_integer_mv)` with | |
| 39 | +libaom's `integer_mv_precision` (ties away from zero on `|mod| > 4`), threaded | |
| 40 | +through `project_tpl_mv`/`add_tpl_ref_mv`, `TplArgs`/`CompoundTplArgs` and the | |
| 41 | +six `decode.rs` construction sites. | |
| 42 | + | |
| 43 | +## Sweep (class + siblings) | |
| 44 | +* `grep` for unreachability claims over `ec-av1`/`ec-av1-syntax`: no other | |
| 45 | + "spec branch dropped because a header flag is refused" site. | |
| 46 | +* The other decoder-side `is_integer` consumers in libaom — | |
| 47 | + `av1_find_best_ref_mvs` (mvref_common.c:847) and the compound nearest/near | |
| 48 | + lowering (decodemv.c:1519) — are provably no-ops for us once the temporal | |
| 49 | + path is fixed: under `force_integer_mv` every other candidate source is | |
| 50 | + already integer (`read_mv_component` honours the flag, `warp.rs:128` honours | |
| 51 | + it for global MVs, spatial candidates are decoded MVs). Not implemented; if | |
| 52 | + a future defect lands here, this is the place. | |
| 53 | + | |
| 54 | +## Verification | |
| 55 | +* `crates/ec-av1/src/motion_field.rs` `force_integer_mv_rounds_a_projected_candidate_to_full_pel` | |
| 56 | + — the five (mfmv0, rfo) pairs of that first block, eighth-pel vs full-pel, | |
| 57 | + values taken from the oracle. Fails without the fix. PASSES. | |
| 58 | +* Film-B ladder, 48 frames, `-cpu-used 6 -g 48`, our `decode_stream` vs | |
| 59 | + `ffmpeg -c:v libdav1d`, sample-exact over all 48 shown frames: | |
| 60 | + crf 20 EXACT, crf 35 EXACT (was the Golomb refusal), crf 45 EXACT. | |
| 61 | + Same at `-g 12`. Before the fix: crf 20/45 25–28 dB garbage, crf 35 refused. | |
| 62 | +* `crates/ec-av1/src/stream.rs` `a_libaom_force_integer_mv_stream_decodes_exact` | |
| 63 | + — synthetic 1920x1024 source (no film sample in `fixtures`): near-flat dark | |
| 64 | + background (2..=4 luma values per 16x16 block, the detector's own rule) with | |
| 65 | + a textured patch stepping 9 px every SECOND frame, so half the frames are | |
| 66 | + exact duplicates (the `C == T` trigger). Asserts (a) libaom really coded an | |
| 67 | + inter frame with `force_integer_mv` + `use_ref_frame_mvs` (anti-blindness), | |
| 68 | + (b) all 12 shown frames decode sample-exact vs ffmpeg. PASSES, 2.1 s. | |
| 69 | + | |
| 70 | +## OPEN / deferred | |
| 71 | +1. **The synthetic gate is BLIND to this defect.** Re-run with the integer | |
| 72 | + branch stubbed out (`if false {`) and it still passes: on that source the | |
| 73 | + temporal candidates are already full-pel (or unused), so only the unit test | |
| 74 | + above actually regresses the fix. Fixing this needs a synthetic clip whose | |
| 75 | + duplicate frame still reads NON-multiple-of-8 projected temporal MVs — | |
| 76 | + e.g. motion of an odd number of half-pels between the earlier frames, with | |
| 77 | + the duplicate pair placed so the ARF's field survives into it. Unblocks: | |
| 78 | + one more recipe iteration against `EC_TPL`/`EC_STACK`. | |
| 79 | +2. **crf 5 still fails**: `-cpu-used 6 -crf 5 -g 48` desyncs on the KEY frame | |
| 80 | + (base_q 9, `delta_q_present`, `cdef_bits 3`), first divergent intra block | |
| 81 | + mi(184,344) — aomdec `EC_IMODE ... rng=49148` vs ours `rng=52010`, the | |
| 82 | + previous traced block being mi(188,340). Unrelated to temporal MVs; needs | |
| 83 | + its own bisect from that block's coefficient ladder (`EC_TRACE_COEFF`). | |
| 84 | +3. **Not done in this lane** (budget): the "reference streams decode exact | |
| 85 | + through our decoder" assertion inside `external_ladder`/the native gates; | |
| 86 | + the full `cargo test -p ec-av1 --release` run (started detached, was still | |
| 87 | + running at hand-off, log | |
| 88 | + `/tmp/claude-1000/.../scratchpad/suite.log`); `cargo check --workspace | |
| 89 | + --all-targets`; the byte pins (8590 / 28535) were not re-read. |