diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 5f0a0812..59978722 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2997,7 +2997,7 @@ pub(crate) fn build_motion_field( const REFMVS_LIMIT: i32 = (1 << 12) - 1; for row in 0..mi_rows { for col in 0..mi_cols { - let Some(info) = grid.get(row, col) else { + let Some(info) = grid.get_frame(row, col) else { continue; }; // `av1_copy_frame_mvs` runs for EVERY block of an inter frame and @@ -3036,6 +3036,12 @@ pub(crate) fn build_motion_field( field.set(row, col, saved); } } + if std::env::var_os("EC_TRACE_TPL").is_some() { + eprintln!("EC_TPL_SAVED oh={order_hint}"); + for (r, row) in field.occupancy().iter().enumerate() { + eprintln!("EC_TPL_SAVED r{r} {row}"); + } + } field } diff --git a/crates/ec-av1/src/motion_field.rs b/crates/ec-av1/src/motion_field.rs index ac29d6fa..5768e499 100644 --- a/crates/ec-av1/src/motion_field.rs +++ b/crates/ec-av1/src/motion_field.rs @@ -75,6 +75,18 @@ impl MotionField { } } + /// lane-mergefix r5 rung (`EC_TRACE_TPL`): occupancy map of the SAVED + /// field, the input side of [`setup_motion_field`]'s projection. + pub fn occupancy(&self) -> Vec { + (0..self.rows) + .map(|r| { + (0..self.cols) + .map(|c| if self.cells[r * self.cols + c].is_some() { '#' } else { '.' }) + .collect() + }) + .collect() + } + fn get(&self, row8: usize, col8: usize) -> Option { if row8 < self.rows && col8 < self.cols { self.cells[row8 * self.cols + col8] @@ -95,6 +107,13 @@ pub struct TplField { } impl TplField { + /// lane-mergefix r5 rung (`EC_TPL`): how many 8x8 cells the projection + /// actually filled -- an empty field means every temporal candidate is + /// silently absent while the entropy stream still matches. + pub fn filled_cells(&self) -> usize { + self.cells.iter().filter(|c| c.is_some()).count() + } + fn get(&self, row8: usize, col8: usize) -> Option<((i32, i32), i32)> { if row8 < self.rows && col8 < self.cols { self.cells[row8 * self.cols + col8] diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index 4755c69c..ad6ccc21 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -274,6 +274,22 @@ impl MiGrid { None } } + + /// The unit at `(row, col)` ignoring the tile window -- the frame-level + /// read `av1_copy_frame_mvs` (this crate's + /// `crate::decode::build_motion_field`) needs: it stores EVERY block of + /// the frame, and it runs after the last tile has already narrowed + /// [`Self::set_tile_bounds`], so reading it through [`Self::get`] saved + /// only the last tile's columns into the motion field and every other + /// tile's temporal candidates silently vanished from the next frame's + /// MV stack. + pub fn get_frame(&self, row: usize, col: usize) -> Option<&MiInfo> { + if row < self.rows && col < self.cols { + self.cells[row * self.cols + col].as_ref() + } else { + None + } + } } /// One entry of the reference MV stack: a candidate motion vector and the diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 9aebbe31..5f7d9e88 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -766,6 +766,14 @@ pub fn decode_stream(data: &[u8]) -> Result> { header.mi_cols as usize, ) }); + if std::env::var_os("EC_TPL").is_some() { + eprintln!( + "EC_TPL order_hint={} use_ref_frame_mvs={} cells={}", + header.order_hint, + header.use_ref_frame_mvs, + tpl_field.as_ref().map_or(0, crate::motion_field::TplField::filled_cells) + ); + } let (picture, end_cdfs, motion_field) = decode_inter_frame_tile_with_cdfs( &tile_bufs, &header.tile_info,