Decode the frame-edge half-strip instead of refusing it (odd height/width)
Browse files at this commita24f3293b899f146c0e6bb9c7abf028971bd325dParent: 2988169- feat
- decode the frame-edge half-strip instead of refusing it (odd height/width)
5 changed files +444 -31
- crates/ec-av1/fixtures/reelb_head_key_frame.obu +0 -0
- crates/ec-av1/src/decode.rs +286 -31
- crates/ec-av1/src/stream.rs +35 -0
- lanes/golomb-r1.report.md +47 -0
- lanes/oddh-r1.report.md +76 -0
crates/ec-av1/fixtures/reelb_head_key_frame.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+286 -31
| @@ -954,6 +954,21 @@ pub(crate) fn horz_vert_intra_hits() -> usize { | |||
| 954 | HORZ_VERT_INTRA_HITS.with(|c| c.get()) | 954 | HORZ_VERT_INTRA_HITS.with(|c| c.get()) |
| 955 | } | 955 | } |
| 956 | 956 | ||
| 957 | +// How many blocks were decoded as a frame-edge rect strip -- the single | ||
| 958 | +// coded half of a `PARTITION_HORZ`/`PARTITION_VERT` at the true frame edge | ||
| 959 | +// (lane-oddh r1), i.e. a block living inside the 8px band of a frame whose | ||
| 960 | +// height or width is 8 mod 16 (the user's 3840x1608 film). Intra and inter | ||
| 961 | +// paths share the counter. | ||
| 962 | +thread_local! { | ||
| 963 | + static EDGE_RECT_STRIP_HITS: std::cell::Cell<usize> = | ||
| 964 | + const { std::cell::Cell::new(0) }; | ||
| 965 | +} | ||
| 966 | + | ||
| 967 | +/// Current value of [`EDGE_RECT_STRIP_HITS`]. | ||
| 968 | +pub(crate) fn edge_rect_strip_hits() -> usize { | ||
| 969 | + EDGE_RECT_STRIP_HITS.with(|c| c.get()) | ||
| 970 | +} | ||
| 971 | + | ||
| 957 | // How many HORZ/VERT intra strips resolved a SPLIT luma transform | 972 | // How many HORZ/VERT intra strips resolved a SPLIT luma transform |
| 958 | // (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) -- | 973 | // (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) -- |
| 959 | // the case every rect path here refused by name before, and the first | 974 | // the case every rect path here refused by name before, and the first |
| @@ -10809,16 +10824,31 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 10809 | } | 10824 | } |
| 10810 | p | 10825 | p |
| 10811 | } else { | 10826 | } else { |
| 10827 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered | ||
| 10828 | + // bit is the answer, not a formality -- libaom's | ||
| 10829 | + // `ec_read_partition_impl` returns `PARTITION_HORZ` (resp. | ||
| 10830 | + // `PARTITION_VERT`) when it reads 0, and only `PARTITION_SPLIT` | ||
| 10831 | + // when it reads 1. Forcing SPLIT here desynced the last | ||
| 10832 | + // superblock row of every frame whose height is not a multiple | ||
| 10833 | + // of 64 -- the ReelB head (3840x1608) diverges at | ||
| 10834 | + // mi_row=400 mi_col=0, the first block of that row. | ||
| 10812 | match (has_cols, has_rows) { | 10835 | match (has_cols, has_rows) { |
| 10813 | (true, false) => { | 10836 | (true, false) => { |
| 10814 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); | 10837 | + if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)) == 1 { |
| 10838 | + PARTITION_SPLIT | ||
| 10839 | + } else { | ||
| 10840 | + PARTITION_HORZ | ||
| 10841 | + } | ||
| 10815 | } | 10842 | } |
| 10816 | (false, true) => { | 10843 | (false, true) => { |
| 10817 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); | 10844 | + if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)) == 1 { |
| 10845 | + PARTITION_SPLIT | ||
| 10846 | + } else { | ||
| 10847 | + PARTITION_VERT | ||
| 10818 | } | 10848 | } |
| 10819 | - _ => {} | ||
| 10820 | } | 10849 | } |
| 10821 | - PARTITION_SPLIT | 10850 | + _ => PARTITION_SPLIT, |
| 10851 | + } | ||
| 10822 | }; | 10852 | }; |
| 10823 | match part { | 10853 | match part { |
| 10824 | PARTITION_NONE => { | 10854 | PARTITION_NONE => { |
| @@ -10875,20 +10905,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 10875 | } else { | 10905 | } else { |
| 10876 | match (has_cols32, has_rows32) { | 10906 | match (has_cols32, has_rows32) { |
| 10877 | (true, false) => { | 10907 | (true, false) => { |
| 10878 | - dec.symbol_fixed(&gather( | 10908 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 10879 | - &cdfs.partition_w32[ctx32], | 10909 | + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT |
| 10880 | - VERT_ALIKE, | 10910 | + // (libaom `ec_read_partition_impl`). |
| 10881 | - )); | 10911 | + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 { |
| 10912 | + PARTITION_SPLIT | ||
| 10913 | + } else { | ||
| 10914 | + PARTITION_HORZ | ||
| 10915 | + } | ||
| 10882 | } | 10916 | } |
| 10883 | (false, true) => { | 10917 | (false, true) => { |
| 10884 | - dec.symbol_fixed(&gather( | 10918 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 10885 | - &cdfs.partition_w32[ctx32], | 10919 | + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT |
| 10886 | - HORZ_ALIKE, | 10920 | + // (libaom `ec_read_partition_impl`). |
| 10887 | - )); | 10921 | + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 { |
| 10922 | + PARTITION_SPLIT | ||
| 10923 | + } else { | ||
| 10924 | + PARTITION_VERT | ||
| 10888 | } | 10925 | } |
| 10889 | - _ => {} | ||
| 10890 | } | 10926 | } |
| 10891 | - PARTITION_SPLIT | 10927 | + _ => PARTITION_SPLIT, |
| 10928 | + } | ||
| 10892 | }; | 10929 | }; |
| 10893 | match part32 { | 10930 | match part32 { |
| 10894 | PARTITION_NONE => { | 10931 | PARTITION_NONE => { |
| @@ -11327,16 +11364,63 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11327 | does not code yet", | 11364 | does not code yet", |
| 11328 | )); | 11365 | )); |
| 11329 | } | 11366 | } |
| 11330 | - if has_cols16 { | 11367 | + // lane-golomb r1 (class |
| 11368 | + // `parsed-then-discarded`): the gathered | ||
| 11369 | + // bit IS the partition -- 0 names | ||
| 11370 | + // PARTITION_HORZ (resp. VERT), only 1 is | ||
| 11371 | + // SPLIT (libaom `ec_read_partition_impl`). | ||
| 11372 | + // This path can only walk the four SPLIT | ||
| 11373 | + // leaves, so a 0 refuses by name instead | ||
| 11374 | + // of desyncing. | ||
| 11375 | + let edge_split = if has_cols16 { | ||
| 11331 | dec.symbol_fixed(&gather( | 11376 | dec.symbol_fixed(&gather( |
| 11332 | &cdfs.partition_w16[ctx16], | 11377 | &cdfs.partition_w16[ctx16], |
| 11333 | VERT_ALIKE, | 11378 | VERT_ALIKE, |
| 11334 | - )); | 11379 | + )) |
| 11335 | } else { | 11380 | } else { |
| 11336 | dec.symbol_fixed(&gather( | 11381 | dec.symbol_fixed(&gather( |
| 11337 | &cdfs.partition_w16[ctx16], | 11382 | &cdfs.partition_w16[ctx16], |
| 11338 | HORZ_ALIKE, | 11383 | HORZ_ALIKE, |
| 11339 | - )); | 11384 | + )) |
| 11385 | + }; | ||
| 11386 | + if edge_split == 0 { | ||
| 11387 | + // lane-oddh r1: the strip IS decodable | ||
| 11388 | + // -- libaom's `decode_partition` codes | ||
| 11389 | + // only the FIRST half of an edge | ||
| 11390 | + // HORZ/VERT (the second call is | ||
| 11391 | + // guarded by the same has_rows/ | ||
| 11392 | + // has_cols test that made the | ||
| 11393 | + // partition non-square), so one | ||
| 11394 | + // 16x8 (resp. 8x16) strip covers the | ||
| 11395 | + // whole visible band of a frame whose | ||
| 11396 | + // height (resp. width) is 8 mod 16 -- | ||
| 11397 | + // the user's 3840x1608 film. | ||
| 11398 | + HORZ_VERT_INTRA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 11399 | + EDGE_RECT_STRIP_HITS.with(|c| c.set(c.get() + 1)); | ||
| 11400 | + let (mi_row0, mi_col0) = | ||
| 11401 | + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); | ||
| 11402 | + let (bw, bh) = if has_cols16 { (16, 8) } else { (8, 16) }; | ||
| 11403 | + let mode = decode_leaf_rect( | ||
| 11404 | + &mut dec, | ||
| 11405 | + &mut cdfs, | ||
| 11406 | + &mut neighbours, | ||
| 11407 | + at16, | ||
| 11408 | + (mi_row0 as usize, mi_col0 as usize), | ||
| 11409 | + bw, | ||
| 11410 | + bh, | ||
| 11411 | + None, | ||
| 11412 | + &mut y, | ||
| 11413 | + &mut u, | ||
| 11414 | + &mut v, | ||
| 11415 | + enable_filter_intra, | ||
| 11416 | + allow_screen_content_tools, | ||
| 11417 | + base_q_idx, | ||
| 11418 | + tx_select, | ||
| 11419 | + reduced_tx_set, | ||
| 11420 | + )?; | ||
| 11421 | + neighbours.above_mode[sc] = mode; | ||
| 11422 | + neighbours.left_mode[sr] = mode; | ||
| 11423 | + continue; | ||
| 11340 | } | 11424 | } |
| 11341 | let (mi_row0, mi_col0) = | 11425 | let (mi_row0, mi_col0) = |
| 11342 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); | 11426 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); |
| @@ -11886,6 +11970,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11886 | tx_select, | 11970 | tx_select, |
| 11887 | reduced_tx_set, | 11971 | reduced_tx_set, |
| 11888 | )?; | 11972 | )?; |
| 11973 | + // lane-golomb r1: at the frame edge only the first half of the | ||
| 11974 | + // strip is coded (libaom `decode_partition` guards the second | ||
| 11975 | + // with the same has_rows test that made this partition non-square). | ||
| 11976 | + if has_rows { | ||
| 11889 | decode_block_rect64( | 11977 | decode_block_rect64( |
| 11890 | &mut dec, | 11978 | &mut dec, |
| 11891 | &mut cdfs, | 11979 | &mut cdfs, |
| @@ -11903,6 +11991,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11903 | reduced_tx_set, | 11991 | reduced_tx_set, |
| 11904 | )?; | 11992 | )?; |
| 11905 | } | 11993 | } |
| 11994 | + } | ||
| 11906 | PARTITION_VERT => { | 11995 | PARTITION_VERT => { |
| 11907 | // lane-sbpart r2: mirror of PARTITION_HORZ above with | 11996 | // lane-sbpart r2: mirror of PARTITION_HORZ above with |
| 11908 | // width/height swapped. | 11997 | // width/height swapped. |
| @@ -11922,6 +12011,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11922 | tx_select, | 12011 | tx_select, |
| 11923 | reduced_tx_set, | 12012 | reduced_tx_set, |
| 11924 | )?; | 12013 | )?; |
| 12014 | + // lane-golomb r1: at the frame edge only the first half of the | ||
| 12015 | + // strip is coded (libaom `decode_partition` guards the second | ||
| 12016 | + // with the same has_cols test that made this partition non-square). | ||
| 12017 | + if has_cols { | ||
| 11925 | decode_block_rect64( | 12018 | decode_block_rect64( |
| 11926 | &mut dec, | 12019 | &mut dec, |
| 11927 | &mut cdfs, | 12020 | &mut cdfs, |
| @@ -11939,6 +12032,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11939 | reduced_tx_set, | 12032 | reduced_tx_set, |
| 11940 | )?; | 12033 | )?; |
| 11941 | } | 12034 | } |
| 12035 | + } | ||
| 11942 | PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { | 12036 | PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { |
| 11943 | // lane-part32 r4: the four superblock-level AB arms, each | 12037 | // lane-part32 r4: the four superblock-level AB arms, each |
| 11944 | // two 32x32 squares plus one 64x32/32x64 strip, in | 12038 | // two 32x32 squares plus one 64x32/32x64 strip, in |
| @@ -17776,12 +17870,24 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 17776 | p | 17870 | p |
| 17777 | } | 17871 | } |
| 17778 | (true, false) => { | 17872 | (true, false) => { |
| 17779 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)); | 17873 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 17874 | + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT | ||
| 17875 | + // (libaom `ec_read_partition_impl`). | ||
| 17876 | + if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)) == 1 { | ||
| 17780 | PARTITION_SPLIT | 17877 | PARTITION_SPLIT |
| 17878 | + } else { | ||
| 17879 | + PARTITION_HORZ | ||
| 17880 | + } | ||
| 17781 | } | 17881 | } |
| 17782 | (false, true) => { | 17882 | (false, true) => { |
| 17783 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)); | 17883 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 17884 | + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT | ||
| 17885 | + // (libaom `ec_read_partition_impl`). | ||
| 17886 | + if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)) == 1 { | ||
| 17784 | PARTITION_SPLIT | 17887 | PARTITION_SPLIT |
| 17888 | + } else { | ||
| 17889 | + PARTITION_VERT | ||
| 17890 | + } | ||
| 17785 | } | 17891 | } |
| 17786 | (false, false) => PARTITION_SPLIT, | 17892 | (false, false) => PARTITION_SPLIT, |
| 17787 | }; | 17893 | }; |
| @@ -17847,6 +17953,68 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 17847 | )?; | 17953 | )?; |
| 17848 | continue; | 17954 | continue; |
| 17849 | } | 17955 | } |
| 17956 | + // lane-oddh r1: a superblock at the TRUE frame edge whose gathered | ||
| 17957 | + // partition bit read 0 is a `PARTITION_HORZ` (resp. `VERT`) whose | ||
| 17958 | + // second half lies outside the frame -- libaom `decode_partition` | ||
| 17959 | + // guards that second call with the same has_rows/has_cols test, so | ||
| 17960 | + // exactly one 64x32 (resp. 32x64) block is coded. Interior rect | ||
| 17961 | + // superblocks still refuse below (this arm can only be reached from | ||
| 17962 | + // the gathered edge bit). | ||
| 17963 | + if (part64 == PARTITION_HORZ && !has_rows) || (part64 == PARTITION_VERT && !has_cols) { | ||
| 17964 | + EDGE_RECT_STRIP_HITS.with(|c| c.set(c.get() + 1)); | ||
| 17965 | + let (write_w, write_h) = | ||
| 17966 | + if part64 == PARTITION_HORZ { (SB, SB / 2) } else { (SB / 2, SB) }; | ||
| 17967 | + decode_inter_block( | ||
| 17968 | + &mut dec, | ||
| 17969 | + &mut cdfs, | ||
| 17970 | + &mut neighbours, | ||
| 17971 | + &mut grid, | ||
| 17972 | + sb_at, | ||
| 17973 | + SB, | ||
| 17974 | + mi_cols, | ||
| 17975 | + mi_rows, | ||
| 17976 | + &mut y, | ||
| 17977 | + &mut u, | ||
| 17978 | + &mut v, | ||
| 17979 | + &ref_y, | ||
| 17980 | + &ref_u, | ||
| 17981 | + &ref_v, | ||
| 17982 | + &ref_slots, | ||
| 17983 | + &sign_bias_table, | ||
| 17984 | + &global_motion, | ||
| 17985 | + base_q_idx, | ||
| 17986 | + TxbSet::Luma64, | ||
| 17987 | + TxbSet::Luma64, | ||
| 17988 | + TxbSet::Chroma32, | ||
| 17989 | + TX32, | ||
| 17990 | + TX32, | ||
| 17991 | + &scan32, | ||
| 17992 | + &scan32, | ||
| 17993 | + 3, | ||
| 17994 | + allow_high_precision_mv, | ||
| 17995 | + force_integer_mv, | ||
| 17996 | + interp_fixed, | ||
| 17997 | + enable_dual_filter, | ||
| 17998 | + tpl_frame.as_ref(), | ||
| 17999 | + reference_select, | ||
| 18000 | + enable_masked_compound, | ||
| 18001 | + enable_interintra_compound, | ||
| 18002 | + enable_jnt_comp, | ||
| 18003 | + order_hint_bits, | ||
| 18004 | + order_hint, | ||
| 18005 | + ref_order_hints, | ||
| 18006 | + skip_mode_present, | ||
| 18007 | + skip_mode_frame, | ||
| 18008 | + switchable_motion_mode, | ||
| 18009 | + allow_warped_motion, | ||
| 18010 | + false, | ||
| 18011 | + write_w, | ||
| 18012 | + write_h, | ||
| 18013 | + allow_screen_content_tools, | ||
| 18014 | + frame_width as usize, | ||
| 18015 | + )?; | ||
| 18016 | + continue; | ||
| 18017 | + } | ||
| 17850 | if part64 != PARTITION_SPLIT { | 18018 | if part64 != PARTITION_SPLIT { |
| 17851 | return Err(unsupported( | 18019 | return Err(unsupported( |
| 17852 | "an inter SB-level partition type other than NONE or SPLIT (this decoder's \ | 18020 | "an inter SB-level partition type other than NONE or SPLIT (this decoder's \ |
| @@ -17886,14 +18054,27 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 17886 | } else { | 18054 | } else { |
| 17887 | match (has_cols32, has_rows32) { | 18055 | match (has_cols32, has_rows32) { |
| 17888 | (true, false) => { | 18056 | (true, false) => { |
| 17889 | - dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)); | 18057 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 18058 | + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT | ||
| 18059 | + // (libaom `ec_read_partition_impl`). | ||
| 18060 | + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 { | ||
| 18061 | + PARTITION_SPLIT | ||
| 18062 | + } else { | ||
| 18063 | + PARTITION_HORZ | ||
| 18064 | + } | ||
| 17890 | } | 18065 | } |
| 17891 | (false, true) => { | 18066 | (false, true) => { |
| 17892 | - dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)); | 18067 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 18068 | + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT | ||
| 18069 | + // (libaom `ec_read_partition_impl`). | ||
| 18070 | + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 { | ||
| 18071 | + PARTITION_SPLIT | ||
| 18072 | + } else { | ||
| 18073 | + PARTITION_VERT | ||
| 17893 | } | 18074 | } |
| 17894 | - _ => {} | ||
| 17895 | } | 18075 | } |
| 17896 | - PARTITION_SPLIT | 18076 | + _ => PARTITION_SPLIT, |
| 18077 | + } | ||
| 17897 | }; | 18078 | }; |
| 17898 | match part32 { | 18079 | match part32 { |
| 17899 | PARTITION_NONE => { | 18080 | PARTITION_NONE => { |
| @@ -17985,17 +18166,24 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 17985 | p | 18166 | p |
| 17986 | } else { | 18167 | } else { |
| 17987 | if has_cols16 { | 18168 | if has_cols16 { |
| 17988 | - dec.symbol_fixed(&gather( | 18169 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 17989 | - &cdfs.partition_w16[ctx16], | 18170 | + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT |
| 17990 | - VERT_ALIKE, | 18171 | + // (libaom `ec_read_partition_impl`). |
| 17991 | - )); | 18172 | + if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 { |
| 18173 | + PARTITION_SPLIT | ||
| 17992 | } else { | 18174 | } else { |
| 17993 | - dec.symbol_fixed(&gather( | 18175 | + PARTITION_HORZ |
| 17994 | - &cdfs.partition_w16[ctx16], | ||
| 17995 | - HORZ_ALIKE, | ||
| 17996 | - )); | ||
| 17997 | } | 18176 | } |
| 18177 | + } else { | ||
| 18178 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered | ||
| 18179 | + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT | ||
| 18180 | + // (libaom `ec_read_partition_impl`). | ||
| 18181 | + if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], HORZ_ALIKE)) == 1 { | ||
| 17998 | PARTITION_SPLIT | 18182 | PARTITION_SPLIT |
| 18183 | + } else { | ||
| 18184 | + PARTITION_VERT | ||
| 18185 | + } | ||
| 18186 | + } | ||
| 17999 | }; | 18187 | }; |
| 18000 | if part16 == PARTITION_NONE { | 18188 | if part16 == PARTITION_NONE { |
| 18001 | decode_inter_block( | 18189 | decode_inter_block( |
| @@ -18051,6 +18239,73 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18051 | allow_screen_content_tools, | 18239 | allow_screen_content_tools, |
| 18052 | frame_width as usize, | 18240 | frame_width as usize, |
| 18053 | )?; | 18241 | )?; |
| 18242 | + } else if (part16 == PARTITION_HORZ && !has_rows16) | ||
| 18243 | + || (part16 == PARTITION_VERT && !has_cols16) | ||
| 18244 | + { | ||
| 18245 | + // lane-oddh r1: the frame-edge half-strip (see the | ||
| 18246 | + // superblock-level arm) one level down -- a single | ||
| 18247 | + // 16x8 (resp. 8x16) inter block covering the whole | ||
| 18248 | + // visible band. Interior 16x8/8x16 inter leaves stay | ||
| 18249 | + // refused below. | ||
| 18250 | + EDGE_RECT_STRIP_HITS.with(|c| c.set(c.get() + 1)); | ||
| 18251 | + let (write_w, write_h) = if part16 == PARTITION_HORZ { | ||
| 18252 | + (SUB, SUB / 2) | ||
| 18253 | + } else { | ||
| 18254 | + (SUB / 2, SUB) | ||
| 18255 | + }; | ||
| 18256 | + decode_inter_block( | ||
| 18257 | + &mut dec, | ||
| 18258 | + &mut cdfs, | ||
| 18259 | + &mut neighbours, | ||
| 18260 | + &mut grid, | ||
| 18261 | + at16, | ||
| 18262 | + SUB, | ||
| 18263 | + mi_cols, | ||
| 18264 | + mi_rows, | ||
| 18265 | + &mut y, | ||
| 18266 | + &mut u, | ||
| 18267 | + &mut v, | ||
| 18268 | + &ref_y, | ||
| 18269 | + &ref_u, | ||
| 18270 | + &ref_v, | ||
| 18271 | + &ref_slots, | ||
| 18272 | + &sign_bias_table, | ||
| 18273 | + &global_motion, | ||
| 18274 | + base_q_idx, | ||
| 18275 | + TxbSet::Luma16, | ||
| 18276 | + if reduced_tx_set { | ||
| 18277 | + TxbSet::Luma16Inter | ||
| 18278 | + } else { | ||
| 18279 | + TxbSet::Luma16InterSet1 | ||
| 18280 | + }, | ||
| 18281 | + TxbSet::Chroma8, | ||
| 18282 | + TX16, | ||
| 18283 | + TX8, | ||
| 18284 | + &scan16, | ||
| 18285 | + &scan8, | ||
| 18286 | + 2, | ||
| 18287 | + allow_high_precision_mv, | ||
| 18288 | + force_integer_mv, | ||
| 18289 | + interp_fixed, | ||
| 18290 | + enable_dual_filter, | ||
| 18291 | + tpl_frame.as_ref(), | ||
| 18292 | + reference_select, | ||
| 18293 | + enable_masked_compound, | ||
| 18294 | + enable_interintra_compound, | ||
| 18295 | + enable_jnt_comp, | ||
| 18296 | + order_hint_bits, | ||
| 18297 | + order_hint, | ||
| 18298 | + ref_order_hints, | ||
| 18299 | + skip_mode_present, | ||
| 18300 | + skip_mode_frame, | ||
| 18301 | + switchable_motion_mode, | ||
| 18302 | + allow_warped_motion, | ||
| 18303 | + false, | ||
| 18304 | + write_w, | ||
| 18305 | + write_h, | ||
| 18306 | + allow_screen_content_tools, | ||
| 18307 | + frame_width as usize, | ||
| 18308 | + )?; | ||
| 18054 | } else if part16 != PARTITION_SPLIT { | 18309 | } else if part16 != PARTITION_SPLIT { |
| 18055 | return Err(unsupported( | 18310 | return Err(unsupported( |
| 18056 | "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)", | 18311 | "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)", |
crates/ec-av1/src/stream.rsmodified+35 -0
| @@ -2671,6 +2671,41 @@ mod tests { | |||
| 2671 | eprintln!("{NAME}: pixel-exact, grain_hits={}", crate::film_grain::grain_hits()); | 2671 | eprintln!("{NAME}: pixel-exact, grain_hits={}", crate::film_grain::grain_hits()); |
| 2672 | } | 2672 | } |
| 2673 | 2673 | ||
| 2674 | + /// lane-golomb r1: THE FILM ITSELF. `crates/ec-av1/fixtures/reelb_head_key_frame.obu` | ||
| 2675 | + /// is the first frame of the user's ReelB AV1 release (3840x1608 | ||
| 2676 | + /// yuv420p10le, `ffmpeg -i <mkv> -c copy -frames:v 1 -f obu`, 147 bytes) -- | ||
| 2677 | + /// a real 10-bit key frame whose height is NOT a multiple of the 64-pixel | ||
| 2678 | + /// superblock, so its last superblock row (mi_row=400 of 402) carries the | ||
| 2679 | + /// edge partition symbol this lane fixed: libaom's `ec_read_partition_impl` | ||
| 2680 | + /// returns `PARTITION_HORZ` when the gathered `split_or_horz` bit is 0, and | ||
| 2681 | + /// this decoder used to READ that bit and throw it away, forcing SPLIT | ||
| 2682 | + /// (class `parsed-then-discarded`). The desync surfaced two rows later as | ||
| 2683 | + /// "a Golomb tail longer than this decoder reads" -- a refusal naming the | ||
| 2684 | + /// symptom, never the cause. | ||
| 2685 | + #[test] | ||
| 2686 | + fn the_reelb_head_key_frame_decodes_pixel_exact() { | ||
| 2687 | + const NAME: &str = "the_reelb_head_key_frame_decodes_pixel_exact"; | ||
| 2688 | + if !have_ffmpeg() { | ||
| 2689 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 2690 | + return; | ||
| 2691 | + } | ||
| 2692 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2693 | + .join("fixtures/reelb_head_key_frame.obu"); | ||
| 2694 | + let stream = std::fs::read(&path) | ||
| 2695 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 2696 | + let (width, height) = (3840usize, 1608usize); | ||
| 2697 | + let frames = match decode_stream(&stream) { | ||
| 2698 | + Ok(frames) => frames, | ||
| 2699 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | ||
| 2700 | + }; | ||
| 2701 | + assert_eq!(frames.len(), 1, "{NAME}: one key frame"); | ||
| 2702 | + assert_eq!((frames[0].width, frames[0].height), (width, height)); | ||
| 2703 | + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1); | ||
| 2704 | + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); | ||
| 2705 | + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg"); | ||
| 2706 | + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg"); | ||
| 2707 | + } | ||
| 2708 | + | ||
| 2674 | /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1 | 2709 | /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1 |
| 2675 | /// --superres-denominator=12` key frame, decoded pixel-exact against | 2710 | /// --superres-denominator=12` key frame, decoded pixel-exact against |
| 2676 | /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s | 2711 | /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s |
lanes/golomb-r1.report.mdadded+47 -0
| @@ -0,0 +1,47 @@ | |||
| 1 | +# lane-golomb r1 — the edge partition bit was read and thrown away | ||
| 2 | + | ||
| 3 | +## Verdict | ||
| 4 | +The "a Golomb tail longer than this decoder reads" refusal on the ReelB head was, as | ||
| 5 | +suspected (`refusal-from-own-desync`), a symptom. Root cause: at a frame edge the partition | ||
| 6 | +symbol is a single *gathered* bit, and this decoder read it and **discarded** it, always | ||
| 7 | +inferring `PARTITION_SPLIT`. libaom `ec_read_partition_impl` (decodeframe.c:1255): | ||
| 8 | +`!has_rows && has_cols` → `read ? PARTITION_SPLIT : PARTITION_HORZ`; the mirror case → | ||
| 9 | +`PARTITION_VERT`. Class: `parsed-then-discarded`. | ||
| 10 | + | ||
| 11 | +Charter STEP-2 fallback ("libaom read_golomb caps at 32 bits, extend the reader") is FALSE: | ||
| 12 | +`~/.cache/aom-oracle/src/av1/decoder/decodetxb.c:22` aborts the frame at `length > 20`, exactly | ||
| 13 | +our cap. The cap was never the bug and is unchanged. | ||
| 14 | + | ||
| 15 | +## First divergent element (EVIDENCE) | ||
| 16 | +EVIDENCE: /tmp/.../scratchpad/{ao-all.txt,ours-all.txt} | instrumented aomdec vs decode_probe, | ||
| 17 | +EC_TRACE_MODE+EC_TRACE_MODE_STEP+EC_TRACE_COEFF on the 2-frame extract f2.obu, ladders aligned | ||
| 18 | +element by element on msac RANGE | first diff at element 12053: key frame, **mi_row=400 | ||
| 19 | +mi_col=0** (last, 8-pixel-tall superblock row of a 1608-tall frame), `name=skip` | ||
| 20 | +oracle rng=34753 vs ours rng=43258. Oracle codes that superblock as one `BLOCK_64X32` | ||
| 21 | +(`EC_IMODE ... bsize=11`, PARTITION_HORZ); we forced SPLIT and descended to 16x16. | ||
| 22 | +After the fix the range ladder is element-exact for all 13712 shared elements of the key frame | ||
| 23 | +(EVIDENCE: /tmp/.../scratchpad/{a4.n,o4.n} | awk first-diff | idx 13713, inside a later INTER | ||
| 24 | +frame, i.e. past the whole key frame). | ||
| 25 | + | ||
| 26 | +## Fix | ||
| 27 | +`crates/ec-av1/src/decode.rs` — every edge-partition site, both tile paths, all three levels | ||
| 28 | +(64/32/16, intra and inter): the gathered bit now names HORZ/VERT vs SPLIT. The 64-level | ||
| 29 | +HORZ/VERT arms only decode the second half when it is inside the frame (`has_rows`/`has_cols`), | ||
| 30 | +mirroring libaom `decode_partition`. The intra 16x16 edge site can only walk four SPLIT leaves, | ||
| 31 | +so a 0 bit refuses by name there (new string, listed in `refusal_inventory.rs`) instead of | ||
| 32 | +desyncing. | ||
| 33 | + | ||
| 34 | +## Gates | ||
| 35 | +- NEW `stream::tests::the_reelb_head_key_frame_decodes_pixel_exact` — the film itself: | ||
| 36 | + `crates/ec-av1/fixtures/reelb_head_key_frame.obu` (147 B, first frame of his 3840x1608 | ||
| 37 | + yuv420p10le release) decodes and matches `ffmpeg -pix_fmt yuv420p10le` on Y, U and V. | ||
| 38 | + EVIDENCE: cargo test -p ec-av1 --lib -- the_reelb_head_key_frame | 1 passed | | ||
| 39 | + Y/U/V all equal to ffmpeg's decode, 3840x1608. | ||
| 40 | +- Full lib suite: `$HOME/.cache/golomb-suite.log` — **337 passed / 0 failed / 31 ignored**. | ||
| 41 | + | ||
| 42 | +## Film probes after the fix | ||
| 43 | +- `hg-head.obu` (18 frames): key frame + first inter frames now entropy-exact; stops at | ||
| 44 | + "an inter SB-level partition type other than NONE or SPLIT" — the same edge partition, now | ||
| 45 | + correctly decoded as HORZ, on an INTER superblock row the inter path cannot code (rect inter | ||
| 46 | + residual coding does not exist here). Next lane. | ||
| 47 | +- `reelb5.obu`: "a 32x32-level 1:4 strip with a split transform (depth=2)" (unchanged by this lane). | ||
lanes/oddh-r1.report.mdadded+76 -0
| @@ -0,0 +1,76 @@ | |||
| 1 | +# lane-oddh r1 — frames whose height/width is 8 mod 16 | ||
| 2 | + | ||
| 3 | +Branch `lane-oddh` off main `b1d8457`. Target: the user's ReelB film shape | ||
| 4 | +(3840x1608, `1608 % 16 == 8`), where every inter attempt derailed. | ||
| 5 | + | ||
| 6 | +## What the round established (measured, not reasoned) | ||
| 7 | + | ||
| 8 | +1. **The charter's premise is stale in its blame, right in its shape.** The refusal | ||
| 9 | + `"a non-DC chroma mode on an 8x8 inter-frame leaf"` is NOT what odd-height frames | ||
| 10 | + stop at once lane-golomb's edge-partition fix is present. Cherry-picking | ||
| 11 | + `eacd7fd` (clean, no conflicts) moves 192x136 to the same refusal its | ||
| 12 | + *even-height control* 192x128 hits, i.e. that one is width/content-related, not | ||
| 13 | + odd-height (see 4). | ||
| 14 | + | ||
| 15 | +2. **Minimal repro is 64x72, not 192x136.** With the standard inter-gate recipe | ||
| 16 | + (`--enable-rect-partitions=0 --min/max-partition-size=8/16`, mandelbrot, cq 40): | ||
| 17 | + - `64x64` decodes 4/4 frames pixel-exact (control), | ||
| 18 | + - `64x72` (bottom band 8 px) stopped at the key-frame 16-level edge refusal, | ||
| 19 | + - `72x64` (right band 8 px) stops in the inter tile path. | ||
| 20 | + | ||
| 21 | +3. **The real blocker underneath is a first-symbol desync of the KEY tile at | ||
| 22 | + height 72.** Not an edge-band defect at all: the *first* partition symbol of the | ||
| 23 | + frame diverges. | ||
| 24 | + `EVIDENCE: /tmp/.../scratchpad/k-64x72.obu (667 B, key frame only, aomenc cq40) | EC_AV1_TRACE=1 decode_probe vs EC_TRACE=1 aomdec | first element mi=(0,0) bsize=BLOCK_64X64 ctx=0: aomdec value=3 (PARTITION_SPLIT, tell=1 rng=32768), ours value=9` | ||
| 25 | + `EVIDENCE: /tmp/.../scratchpad/k-64x72.{ours,aom,ref}.y | aomdec --rawvideo + ffmpeg rawvideo vs our Y dump | aomdec == ffmpeg byte-for-byte; ours differs in 4583 of 4608 Y samples (whole frame), while the 64x64 control differs in 0` | ||
| 26 | + Our tile payload starts at file offset 20 in both the 64x64 and the 64x72 stream | ||
| 27 | + (`key_tile_bytes len=543`/`647`, file sizes 563/667), and `base_q_idx=160`, | ||
| 28 | + `mi_cols=16`, `mi_rows=18` all parse correctly, so the header field values are | ||
| 29 | + right; the divergence is in the very first symbol read off those bytes. | ||
| 30 | + **Not diagnosed further — this is the handoff item.** Ruled out by reading the | ||
| 31 | + source: `sb_rows`/`sb_cols` (`sequence.rs:409-422`, 18 -> 2 correct) and the | ||
| 32 | + uniform-spacing tile-info loops (`frame.rs:1296-1334`, both increment loops match | ||
| 33 | + spec 5.9.15, so the extra `increment_tile_rows_log2` bit that height 72 introduces | ||
| 34 | + IS consumed). | ||
| 35 | + | ||
| 36 | +4. Pre-existing, unrelated to odd height: `192x128` and `192x136` both stop at | ||
| 37 | + `"a 1:4 partition below 16x16"` with `--enable-1to4-partitions=0` on the command | ||
| 38 | + line — a same-shaped refusal-from-own-desync at width 192, present on the control. | ||
| 39 | + | ||
| 40 | +## Code changed (all in this worktree, unproven end to end) | ||
| 41 | + | ||
| 42 | +- cherry-pick `eacd7fd` (lane-golomb) — the frame-edge partition bit at 6 sites in | ||
| 43 | + both tile paths, plus its film key-frame fixture/gate. Clean merge. | ||
| 44 | +- `crates/ec-av1/src/decode.rs:11371` — the key-frame 16-level frame-edge | ||
| 45 | + `PARTITION_HORZ`/`VERT` now decodes its single visible 16x8 / 8x16 strip through | ||
| 46 | + `decode_leaf_rect` instead of refusing (removes that refusal string; entry dropped | ||
| 47 | + from `refusal_inventory.rs`). | ||
| 48 | +- `crates/ec-av1/src/decode.rs` (inter tile path, superblock level and 16-level) — | ||
| 49 | + the same edge half-strip as one 64x32 / 32x64 resp. 16x8 / 8x16 inter block | ||
| 50 | + (`write_w`/`write_h`, square CDF/size-class corner-cut, exactly the accepted | ||
| 51 | + corner-cut of the 32-level rect arm at `decode.rs:18448`). Interior rect | ||
| 52 | + partitions still refuse by name. | ||
| 53 | +- `decode.rs` — new counter `edge_rect_strip_hits()` (blocks decoded inside the 8px | ||
| 54 | + edge band), for the gate a successor must write. | ||
| 55 | + | ||
| 56 | +`corner-cut:` the two inter edge arms read square CDFs / size classes for a | ||
| 57 | +rectangular block (ceiling: coefficient and mode syntax for TX_64X32/TX_16X8 inter is | ||
| 58 | +not modelled; upgrade path = the same treatment the 32-level rect arm eventually gets). | ||
| 59 | + | ||
| 60 | +## Verification status — honest | ||
| 61 | + | ||
| 62 | +- NO gate was added and NO refusal claim is proven: every stream that reaches the new | ||
| 63 | + arms is desynced before them (finding 3), so a pixel compare would measure the | ||
| 64 | + desync, not the arm. Writing | ||
| 65 | + `a_real_aomenc_inter_sequence_with_an_8px_tall_edge_row_decodes_pixel_exact` on top | ||
| 66 | + of a first-symbol desync would have produced a vacuous or a permanently-red gate. | ||
| 67 | +- Suite: see `$HOME/.cache/oddh-suite.log` (run as a systemd unit, result quoted in | ||
| 68 | + the handoff message). | ||
| 69 | + | ||
| 70 | +## Disposition | ||
| 71 | + | ||
| 72 | +- fix-now (next round, r2): the 64x72 key-tile first-symbol desync. It is the root | ||
| 73 | + blocker; the edge arms above are dead code until it is fixed. | ||
| 74 | +- deferred(the desync above): the 8px-edge-band gate + the refusal lift claim. | ||
| 75 | +- deferred(width-192 defect, separate lane): the `"1:4 partition below 16x16"` stop | ||
| 76 | + that both 192x128 and 192x136 share. | ||