Wire read_lr into both SB loops
Browse files at this commitdc215f73dd0570ea92b2ffa15af5e21cd62c0e72Parent: 4c75e5c- feat
- wire read_lr into both SB loops
- narrow the whole-frame LR refusal to 'filters not applied'
2 changed files +43 -2
crates/ec-av1/src/decode.rsmodified+35 -1
| @@ -21,7 +21,7 @@ | |||
| 21 | //! too). Anything outside that refuses with [`Error::unsupported`] rather than | 21 | //! too). Anything outside that refuses with [`Error::unsupported`] rather than |
| 22 | //! silently miscoding. | 22 | //! silently miscoding. |
| 23 | 23 | ||
| 24 | -use ec_av1_syntax::{CdefParams, LoopFilterParams}; | 24 | +use ec_av1_syntax::{CdefParams, LoopFilterParams, LoopRestorationParams}; |
| 25 | use ec_core::{Error, Result}; | 25 | use ec_core::{Error, Result}; |
| 26 | 26 | ||
| 27 | use crate::cdf; | 27 | use crate::cdf; |
| @@ -4458,6 +4458,7 @@ pub fn decode_key_frame_tile( | |||
| 4458 | false, | 4458 | false, |
| 4459 | cdef, | 4459 | cdef, |
| 4460 | loop_filter, | 4460 | loop_filter, |
| 4461 | + &LoopRestorationParams::default(), | ||
| 4461 | None, | 4462 | None, |
| 4462 | tx_select, | 4463 | tx_select, |
| 4463 | reduced_tx_set, | 4464 | reduced_tx_set, |
| @@ -4486,6 +4487,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4486 | enable_edge_filter: bool, | 4487 | enable_edge_filter: bool, |
| 4487 | cdef: &CdefParams, | 4488 | cdef: &CdefParams, |
| 4488 | loop_filter: &LoopFilterParams, | 4489 | loop_filter: &LoopFilterParams, |
| 4490 | + lr: &LoopRestorationParams, | ||
| 4489 | initial_cdfs: Option<Cdfs>, | 4491 | initial_cdfs: Option<Cdfs>, |
| 4490 | tx_select: bool, | 4492 | tx_select: bool, |
| 4491 | reduced_tx_set: bool, | 4493 | reduced_tx_set: bool, |
| @@ -4543,10 +4545,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4543 | mi_cols as usize, | 4545 | mi_cols as usize, |
| 4544 | mi_rows as usize, | 4546 | mi_rows as usize, |
| 4545 | ); | 4547 | ); |
| 4548 | + let mut lr_grid = crate::restoration::RestorationGrid::new(lr, frame_width, frame_height); | ||
| 4549 | + let mut lr_reference = [( | ||
| 4550 | + crate::restoration::WienerInfo::default(), | ||
| 4551 | + crate::restoration::SgrprojInfo::default(), | ||
| 4552 | + ); 3]; | ||
| 4546 | 4553 | ||
| 4547 | for sb_r in 0..sb_rows { | 4554 | for sb_r in 0..sb_rows { |
| 4548 | neighbours.start_row(); | 4555 | neighbours.start_row(); |
| 4549 | for sb_c in 0..sb_cols { | 4556 | for sb_c in 0..sb_cols { |
| 4557 | + crate::restoration::read_lr( | ||
| 4558 | + &mut dec, | ||
| 4559 | + &mut cdfs, | ||
| 4560 | + lr, | ||
| 4561 | + &mut lr_grid, | ||
| 4562 | + &mut lr_reference, | ||
| 4563 | + sb_r * SB_MI, | ||
| 4564 | + sb_c * SB_MI, | ||
| 4565 | + SB_MI, | ||
| 4566 | + ); | ||
| 4550 | let at = (sb_r as usize * 4, sb_c as usize * 4); | 4567 | let at = (sb_r as usize * 4, sb_c as usize * 4); |
| 4551 | let ctx = neighbours.partition_ctx(at, SB); | 4568 | let ctx = neighbours.partition_ctx(at, SB); |
| 4552 | let (has_cols, has_rows) = ( | 4569 | let (has_cols, has_rows) = ( |
| @@ -9055,6 +9072,7 @@ pub fn decode_inter_frame_tile( | |||
| 9055 | other_refs, | 9072 | other_refs, |
| 9056 | cdef, | 9073 | cdef, |
| 9057 | loop_filter, | 9074 | loop_filter, |
| 9075 | + &LoopRestorationParams::default(), | ||
| 9058 | None, | 9076 | None, |
| 9059 | allow_high_precision_mv, | 9077 | allow_high_precision_mv, |
| 9060 | force_integer_mv, | 9078 | force_integer_mv, |
| @@ -9096,6 +9114,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9096 | other_refs: [Option<&Picture>; 8], | 9114 | other_refs: [Option<&Picture>; 8], |
| 9097 | cdef: &CdefParams, | 9115 | cdef: &CdefParams, |
| 9098 | loop_filter: &LoopFilterParams, | 9116 | loop_filter: &LoopFilterParams, |
| 9117 | + lr: &LoopRestorationParams, | ||
| 9099 | initial_cdfs: Option<Cdfs>, | 9118 | initial_cdfs: Option<Cdfs>, |
| 9100 | allow_high_precision_mv: bool, | 9119 | allow_high_precision_mv: bool, |
| 9101 | force_integer_mv: bool, | 9120 | force_integer_mv: bool, |
| @@ -9271,10 +9290,25 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9271 | mi_rows as usize, | 9290 | mi_rows as usize, |
| 9272 | ); | 9291 | ); |
| 9273 | let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize); | 9292 | let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize); |
| 9293 | + let mut lr_grid = crate::restoration::RestorationGrid::new(lr, frame_width, frame_height); | ||
| 9294 | + let mut lr_reference = [( | ||
| 9295 | + crate::restoration::WienerInfo::default(), | ||
| 9296 | + crate::restoration::SgrprojInfo::default(), | ||
| 9297 | + ); 3]; | ||
| 9274 | 9298 | ||
| 9275 | for sb_r in 0..sb_rows { | 9299 | for sb_r in 0..sb_rows { |
| 9276 | neighbours.start_row(); | 9300 | neighbours.start_row(); |
| 9277 | for sb_c in 0..sb_cols { | 9301 | for sb_c in 0..sb_cols { |
| 9302 | + crate::restoration::read_lr( | ||
| 9303 | + &mut dec, | ||
| 9304 | + &mut cdfs, | ||
| 9305 | + lr, | ||
| 9306 | + &mut lr_grid, | ||
| 9307 | + &mut lr_reference, | ||
| 9308 | + sb_r * SB_MI, | ||
| 9309 | + sb_c * SB_MI, | ||
| 9310 | + SB_MI, | ||
| 9311 | + ); | ||
| 9278 | let sb_at = (sb_r as usize * 4, sb_c as usize * 4); | 9312 | let sb_at = (sb_r as usize * 4, sb_c as usize * 4); |
| 9279 | let sb_ctx = neighbours.partition_ctx(sb_at, SB); | 9313 | let sb_ctx = neighbours.partition_ctx(sb_at, SB); |
| 9280 | let (has_cols, has_rows) = ( | 9314 | let (has_cols, has_rows) = ( |
crates/ec-av1/src/stream.rsmodified+8 -1
| @@ -191,10 +191,15 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 191 | // silent-desync shape as the refusals above. Traced live 2026-08-27: | 191 | // silent-desync shape as the refusals above. Traced live 2026-08-27: |
| 192 | // an aomenc inter frame with `Sgrproj` on the V plane desynced the | 192 | // an aomenc inter frame with `Sgrproj` on the V plane desynced the |
| 193 | // partition walk into out-of-alphabet garbage. | 193 | // partition walk into out-of-alphabet garbage. |
| 194 | + // lane-lr r2: the per-superblock `read_lr`/`read_lr_unit` symbols are | ||
| 195 | + // now read (`crate::restoration`) and no longer desync the partition | ||
| 196 | + // walk -- the refusal narrows to its true remaining gap: decoded | ||
| 197 | + // Wiener/SGR filters are stored per unit but never applied to | ||
| 198 | + // pixels. | ||
| 194 | if header.loop_restoration.uses_lr { | 199 | if header.loop_restoration.uses_lr { |
| 195 | return Err(Error::unsupported( | 200 | return Err(Error::unsupported( |
| 196 | "AV1 decode_stream", | 201 | "AV1 decode_stream", |
| 197 | - "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)", | 202 | + "a frame with loop restoration enabled (the per-unit lr symbols are read but the Wiener/self-guided filters are not yet applied to pixels)", |
| 198 | )); | 203 | )); |
| 199 | } | 204 | } |
| 200 | // `decode_inter_block`/`decode_inter_block8`'s `GLOBALMV` arm (spec | 205 | // `decode_inter_block`/`decode_inter_block8`'s `GLOBALMV` arm (spec |
| @@ -370,6 +375,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 370 | enable_edge_filter, | 375 | enable_edge_filter, |
| 371 | &header.cdef, | 376 | &header.cdef, |
| 372 | &header.loop_filter, | 377 | &header.loop_filter, |
| 378 | + &header.loop_restoration, | ||
| 373 | initial_cdfs, | 379 | initial_cdfs, |
| 374 | header.tx_mode == TxMode::Select, | 380 | header.tx_mode == TxMode::Select, |
| 375 | header.reduced_tx_set, | 381 | header.reduced_tx_set, |
| @@ -437,6 +443,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 437 | other_refs, | 443 | other_refs, |
| 438 | &header.cdef, | 444 | &header.cdef, |
| 439 | &header.loop_filter, | 445 | &header.loop_filter, |
| 446 | + &header.loop_restoration, | ||
| 440 | initial_cdfs, | 447 | initial_cdfs, |
| 441 | header.allow_high_precision_mv, | 448 | header.allow_high_precision_mv, |
| 442 | header.force_integer_mv, | 449 | header.force_integer_mv, |