diff --git a/crates/ec-vp9/src/decode.rs b/crates/ec-vp9/src/decode.rs index f3903bfc..2c41d7ab 100644 --- a/crates/ec-vp9/src/decode.rs +++ b/crates/ec-vp9/src/decode.rs @@ -4,19 +4,21 @@ //! reconstruction and the loop filter (spec 6, 7, 8; libvpx //! `vp9_decodeframe.c`). //! -//! Capability: profile-0 8-bit and profile-2 10-bit 4:2:0 keyframes and inter -//! frames (motion compensation, residual reconstruction, the loop filter and -//! an 8-slot reference DPB). Intra-only frames, profiles 1/3, 12-bit, other -//! subsamplings and a reference whose coded size differs from the current -//! frame are refused by name; `show_existing_frame` returns the buffered -//! reference picture instead of pretending to decode. Odd coded extents are -//! supported: chroma stores and crops at `(w + 1) / 2` (`uv_crop_width`), -//! matching libvpx. +//! Capability: profile-0 8-bit and profile-2 10-bit 4:2:0 keyframes, +//! intra-only frames and inter frames (motion compensation, residual +//! reconstruction, the loop filter and an 8-slot reference DPB). A reference +//! whose coded size differs from the current frame is scaled during +//! prediction; profiles 1/3, 12-bit and other subsamplings are refused by +//! name; `show_existing_frame` returns the buffered reference picture instead +//! of pretending to decode. Odd coded extents are supported: chroma stores +//! and crops at `(w + 1) / 2` (`uv_crop_width`), matching libvpx. use crate::header::{FrameContext, read_compressed_header}; use crate::intra::build_intra_predictors; use crate::loopfilter::LfGrids; -use crate::mc::{RefPlane, average_split_mvs_chroma, build_inter_predictors, split_mv}; +use crate::mc::{ + RefPlane, ScaleFactors, average_split_mvs_chroma, build_inter_predictors, split_mv, +}; use crate::modes::{MiInfo, MiState, read_intra_frame_mode_info}; use crate::tables::*; use crate::tokens::{PlaneContexts, decode_coefs, scan_for}; @@ -261,10 +263,7 @@ impl Decoder { return self.decode_key_frame(&hdr, frame); } if hdr.intra_only { - return Err(Error::unsupported( - "vp9 intra-only", - "this lane decodes inter frames and keyframes only", - )); + return self.decode_intra_only_frame(&hdr, frame); } self.decode_inter_frame(&hdr, frame, index, true) } @@ -325,6 +324,76 @@ impl Decoder { Ok(if hdr.show_frame { Some(pic) } else { None }) } + /// Decode an intra-only frame through to pixels. `libvpx + /// vp9_decodeframe.c:2708-2745` makes it an INTER frame that never shows + /// and refreshes only the slots its `refresh_frame_flags` names, but its + /// body is a keyframe's: intra-only mode info, intra prediction, the intra + /// coefficient axis and the intra loop-filter levels. Two header decisions + /// differ from a keyframe (`vp9_setup_past_independence`, + /// `vp9/common/vp9_entropymode.c:424`): + /// + /// - the ACTIVE frame context comes from storage + /// (`*cm->fc = cm->frame_contexts[frame_context_idx]`, + /// `vp9_decodeframe.c:3008`) — reset to the defaults only for + /// `reset_frame_context` 2 (selected) or 3 (all), or under + /// error-resilient mode, never unconditionally like a keyframe (whose + /// `cm->frame_type == KEY_FRAME` clause resets every stored context); + /// - partitions read the const `vp9_kf_partition_probs` + /// (`set_partition_probs`), so the stored context's own `partition` + /// field survives the frame untouched. + fn decode_intra_only_frame( + &mut self, + hdr: &FrameHeader, + frame: &[u8], + ) -> Result> { + let hdr = hdr.clone(); + if hdr.error_resilient_mode || hdr.reset_frame_context == 3 { + let d = FrameContext::new(false); + self.frame_ctxs = [d.clone(), d.clone(), d.clone(), d]; + } else if hdr.reset_frame_context == 2 { + self.frame_ctxs[0] = FrameContext::new(false); + } + // The parser forces frame_context_idx to 0 for an intra frame. + let mut ctx = self.frame_ctxs[0].clone(); + let stored_partition = ctx.partition; + ctx.use_key_partition(); + self.ctx = ctx; + self.prev_seg.clear(); + self.prev_mvs.clear(); + self.last = LastFrameFacts { + width: hdr.width, + height: hdr.height, + intra_only: true, + show_frame: hdr.show_frame, + key: false, + }; + let hdr_start = hdr.uncompressed_header_size as usize; + let ch = read_compressed_header( + &frame[hdr_start..hdr_start + hdr.header_size_in_bytes as usize], + &mut self.ctx, + &hdr, + )?; + let pic = self.decode_keyframe(&hdr, frame, ch.tx_mode)?; + if hdr.refresh_frame_context { + // Store back with the partition probs the context arrived with: + // the const key table is not a `FRAME_CONTEXT` field. + self.ctx.partition = stored_partition; + self.frame_ctxs[0] = self.ctx.clone(); + } + // Reference refresh (spec 8.10): only `refresh_frame_flags` slots. + let frame = RefFrame { + planes: std::sync::Arc::new(self.planes.take().expect("frame scratch")), + width: hdr.width as u16, + height: hdr.height as u16, + }; + for slot in 0..8 { + if hdr.refresh_frame_flags & (1 << slot) != 0 { + self.refs[slot] = Some(frame.clone()); + } + } + Ok(if hdr.show_frame { Some(pic) } else { None }) + } + /// Parse one frame's syntax: keyframes decode through to pixels, inter /// frames are parsed (headers, mode info, MVs) with no reconstruction and /// no picture. `decode` still refuses inter frames. @@ -354,10 +423,9 @@ impl Decoder { // any inter-frame dump after it would be meaningless evidence. self.decode_key_frame(&hdr, sub)?; } else if hdr.intra_only { - return Err(Error::unsupported( - "vp9 intra-only", - "the inter-syntax lane covers inter frames only", - )); + // Same body as a keyframe, but an inter frame that refreshes + // only the slots it names. + self.decode_intra_only_frame(&hdr, sub)?; } else { self.decode_inter_frame(&hdr, sub, index, false)?; } @@ -392,28 +460,19 @@ impl Decoder { // Reference slots (spec 7.2): `ref_frame_idx[i]` names the slot LAST, // GOLDEN and ALTREF use. libvpx validates every named reference's - // format here (`vp9_decodeframe.c:1620-1627`) and SCALES a reference - // whose size differs; this lane refuses that by name. + // format here (`vp9_decodeframe.c:1620-1627`); a reference whose coded + // size differs from this frame's is SCALED during prediction + // (`vp9_setup_scale_factors_for_frame` per reference), not refused. if pixels { for (i, name) in ["last", "golden", "altref"].iter().enumerate() { let slot = hdr.ref_frame_idx[i] as usize; if slot >= self.refs.len() || hdr.ref_frame_idx[i] >= 8 { return Err(corrupt("vp9 inter names a reference slot past the DPB")); } - let Some(p) = self.refs[slot].as_ref() else { + if self.refs[slot].is_none() { return Err(Error::corrupt(format!( "vp9 inter reference `{name}` names empty slot {slot}" ))); - }; - if p.width as u32 != hdr.width || p.height as u32 != hdr.height { - return Err(Error::unsupported( - "vp9 inter reference size change", - format!( - "reference `{name}` in slot {slot} is {}x{} but this frame is {}x{}; \ - reference-frame scaling is not ported", - p.width, p.height, hdr.width, hdr.height - ), - )); } } let width = hdr.width as usize; @@ -1407,7 +1466,10 @@ impl Decoder { let x_mis = bw.min(mi.mi_cols - col); let y_mis = bh.min(mi.mi_rows - row); - let info = if hdr.frame_type == FrameType::Key { + // `frame_is_intra_only` (onyxc_int.h:363): a keyframe OR an + // intra-only frame walks the intra mode-info path. + let intra_frame = hdr.frame_type == FrameType::Key || hdr.intra_only; + let info = if intra_frame { read_intra_frame_mode_info( r, mi, @@ -1436,7 +1498,7 @@ impl Decoder { tx_mode, )? }; - if hdr.frame_type != FrameType::Key { + if !intra_frame { if pixels { // Full inter decode: prediction, tokens, residual. The // per-cell loop-filter level is the block's own reference and @@ -2088,6 +2150,26 @@ fn inter_predict_plane( return Err(corrupt("vp9 inter prediction read an empty reference slot")); }; let (ref_data, ref_stride) = ref_frame.planes.plane_ref(plane); + // `vp9_setup_scale_factors_for_frame` (`vp9_decodeframe.c:2758`): the + // scale from the REFERENCE's coded luma size to this frame's, shared + // by every plane. `vp9_is_valid_scale` is enforced where libvpx + // enforces it — at prediction time, for the references actually used. + let sf = ScaleFactors::setup( + ref_frame.width as usize, + ref_frame.height as usize, + hdr.width as usize, + hdr.height as usize, + ); + if !sf.is_valid() { + return Err(Error::unsupported( + "vp9 reference scale", + format!( + "reference `{ref_name}` in slot {slot} is {}x{} against a {}x{} frame; \ + `valid_ref_frame_size` rejects that ratio", + ref_frame.width, ref_frame.height, hdr.width, hdr.height + ), + )); + } let refp = RefPlane { data: ref_data, stride: ref_stride, @@ -2137,6 +2219,7 @@ fn inter_predict_plane( ss_y, kernel, rf == 1, + &sf, scratch, temp, ); @@ -2164,6 +2247,7 @@ fn inter_predict_plane( ss_y, kernel, rf == 1, + &sf, scratch, temp, ); diff --git a/crates/ec-vp9/src/header.rs b/crates/ec-vp9/src/header.rs index 879ccc7c..533009a5 100644 --- a/crates/ec-vp9/src/header.rs +++ b/crates/ec-vp9/src/header.rs @@ -124,6 +124,18 @@ impl FrameContext { pub(crate) fn reset_inter_partition(&mut self) { self.partition = rows(&DEFAULT_PARTITION_PROBS); } + + /// `set_partition_probs` (`vp9/onyxc_int.h:367`): a key frame OR an + /// intra-only frame reads partitions from the const + /// `vp9_kf_partition_probs`, never from the stored `FRAME_CONTEXT`. An + /// intra-only frame's context otherwise comes from storage, so its own + /// `partition` field must be left alone (this only swaps the field on the + /// active read copy). + pub(crate) fn use_key_partition(&mut self) { + for (i, row) in self.partition.iter_mut().enumerate() { + row.copy_from_slice(&KF_PARTITION_PROBS[i * 3..i * 3 + 3]); + } + } } /// `inv_recenter_nonneg` (vp9_dsubexp.c). diff --git a/crates/ec-vp9/src/mc.rs b/crates/ec-vp9/src/mc.rs index b9021c79..404597a5 100644 --- a/crates/ec-vp9/src/mc.rs +++ b/crates/ec-vp9/src/mc.rs @@ -8,9 +8,11 @@ //! The VP9 decoder does NOT extend the reference frame's borders in place: it //! builds a bordered copy of the block's reference window per prediction //! (`extend_and_predict`) whenever the window leaves the frame or the frame's -//! dimensions are not a multiple of 8. This module ports that path, unscaled -//! only — a reference slot whose size differs from the current frame is -//! refused by `decode` before any predictor runs. +//! dimensions are not a multiple of 8. A reference slot whose size differs +//! from the current frame is SCALED: [`ScaleFactors`] carries +//! `vp9_setup_scale_factors_for_frame`, the block/MV are mapped into the +//! reference with `vp9_scale_mv`, and the convolve steps by `x_step_q4` / +//! `y_step_q4` (`sf->predict`, `vpx_scaled_*`). //! //! Indexing note: libvpx's convolve helpers take a raw pointer and subtract //! `SUBPEL_TAPS / 2 - 1` from it, so they read taps *before* the block's first @@ -28,6 +30,93 @@ const FILTER_BITS: i32 = 7; /// `VP9_INTERP_EXTEND` (`vpx_scale/yv12config.h:25`). const INTERP_EXTEND: i32 = 4; +/// `REF_SCALE_SHIFT` / `REF_NO_SCALE` / `REF_INVALID_SCALE` +/// (`vp9/common/vp9_scale.h:21-23`): the fixed-point precision of a reference +/// frame's scale factor. +const REF_SCALE_SHIFT: i32 = 14; +const REF_NO_SCALE: i32 = 1 << REF_SCALE_SHIFT; +const REF_INVALID_SCALE: i32 = -1; + +/// `scaled_x` / `scaled_y` (`vp9_scale.c:22`). +fn scale_value(val: i32, scale_fp: i32) -> i32 { + (((val as i64) * scale_fp as i64) >> REF_SCALE_SHIFT) as i32 +} + +/// `struct scale_factors` (`vp9/common/vp9_scale.h:27`) set up by +/// `vp9_setup_scale_factors_for_frame` (`vp9_scale.c:44`): the scale from a +/// reference frame's coded size to this frame's, its derived 1/16-pel step +/// (`x_step_q4`/`y_step_q4`; 16 means "no scaling on that axis") and +/// `vp9_scale_mv`. +#[derive(Clone, Copy)] +pub(crate) struct ScaleFactors { + x_scale_fp: i32, + y_scale_fp: i32, + x_step_q4: i32, + y_step_q4: i32, +} + +impl ScaleFactors { + /// `vp9_setup_scale_factors_for_frame(other_w, other_h, this_w, this_h)`: + /// `other_*` is the REFERENCE's coded size, `this_*` the frame being + /// decoded. An out-of-range ratio leaves `REF_INVALID_SCALE`, which + /// libvpx turns into `Reference frame has invalid dimensions` when the + /// reference is actually predicted from. + pub(crate) fn setup(other_w: usize, other_h: usize, this_w: usize, this_h: usize) -> Self { + // `valid_ref_frame_size` (`vp9_scale.h:61`): at most 2x down, 16x up. + let valid = 2 * this_w >= other_w + && 2 * this_h >= other_h + && this_w <= 16 * other_w + && this_h <= 16 * other_h; + if !valid { + return ScaleFactors { + x_scale_fp: REF_INVALID_SCALE, + y_scale_fp: REF_INVALID_SCALE, + x_step_q4: 0, + y_step_q4: 0, + }; + } + let x_scale_fp = (((other_w as i64) << REF_SCALE_SHIFT) / this_w as i64) as i32; + let y_scale_fp = (((other_h as i64) << REF_SCALE_SHIFT) / this_h as i64) as i32; + ScaleFactors { + x_scale_fp, + y_scale_fp, + x_step_q4: scale_value(SUBPEL_SHIFTS, x_scale_fp), + y_step_q4: scale_value(SUBPEL_SHIFTS, y_scale_fp), + } + } + + /// `vp9_is_valid_scale`. + pub(crate) fn is_valid(&self) -> bool { + self.x_scale_fp != REF_INVALID_SCALE && self.y_scale_fp != REF_INVALID_SCALE + } + + /// `vp9_is_scaled`. + pub(crate) fn is_scaled(&self) -> bool { + self.is_valid() && (self.x_scale_fp != REF_NO_SCALE || self.y_scale_fp != REF_NO_SCALE) + } + + fn scale_x(&self, val: i32) -> i32 { + scale_value(val, self.x_scale_fp) + } + + fn scale_y(&self, val: i32) -> i32 { + scale_value(val, self.y_scale_fp) + } + + /// `vp9_scale_mv` (`vp9_scale.c:29`): the block MV scaled to the + /// reference's resolution plus the sub-pixel offset of the block's own + /// scaled position. Returns `(row, col)` in 1/16-pel units. + /// + /// `x`/`y` are the block's coordinates in the CURRENT frame (libvpx + /// passes `mi_x + x`, `mi_y + y` — luma units even for chroma planes; the + /// sub-8x8 chroma offsets are always 0, so the mismatch never bites). + pub(crate) fn scale_mv(&self, mv: (i32, i32), x: i32, y: i32) -> (i32, i32) { + let x_off_q4 = self.scale_x(x << SUBPEL_BITS) & SUBPEL_MASK; + let y_off_q4 = self.scale_y(y << SUBPEL_BITS) & SUBPEL_MASK; + (self.scale_y(mv.0) + y_off_q4, self.scale_x(mv.1) + x_off_q4) + } +} + /// `vp9_filter_kernels` (`vp9/common/vp9_filter.c:79`), in libvpx's filter /// numbering: 0 `EIGHTTAP`, 1 `EIGHTTAP_SMOOTH`, 2 `EIGHTTAP_SHARP`, /// 3 `BILINEAR` (the 4-tap index 4 is unreachable for profile 0). @@ -215,6 +304,9 @@ fn build_mc_border( /// `convolve_horiz` / `convolve_avg_horiz` (`vpx_dsp/vpx_convolve.c:22`). /// `origin` is the block's first sample in `buf`; taps are read from /// `origin + y*stride + (x_q4 >> SUBPEL_BITS) - (SUBPEL_TAPS / 2 - 1) + k`. +/// `x_step` advances `x_q4` per output sample — `SUBPEL_SHIFTS` for an +/// unscaled reference, `sf->x_step_q4` (the scaled sampler, also used by +/// `vpx_scaled_horiz`) otherwise. #[allow(clippy::too_many_arguments)] fn convolve_horiz( buf: &[Sample], @@ -224,6 +316,7 @@ fn convolve_horiz( dst_stride: usize, f: &[[i16; TAPS]; SUBPEL_SHIFTS as usize], x0_q4: i32, + x_step: i32, w: usize, rows: usize, avg: bool, @@ -246,12 +339,15 @@ fn convolve_horiz( } else { v as Sample }; - x_q4 += SUBPEL_SHIFTS; + x_q4 += x_step; } } } /// `convolve_vert` / `convolve_avg_vert` (`vpx_dsp/vpx_convolve.c:80`). +/// `y_step` advances `y_q4` per output sample (`SUBPEL_SHIFTS` unscaled, +/// `sf->y_step_q4` for `vpx_scaled_vert`). +#[allow(clippy::too_many_arguments)] fn convolve_vert( buf: &[Sample], stride: usize, @@ -260,6 +356,7 @@ fn convolve_vert( dst_stride: usize, f: &[[i16; TAPS]; SUBPEL_SHIFTS as usize], y0_q4: i32, + y_step: i32, w: usize, h: usize, avg: bool, @@ -283,15 +380,18 @@ fn convolve_vert( } else { v as Sample }; - y_q4 += SUBPEL_SHIFTS; + y_q4 += y_step; } } } /// `inter_predictor` + `sf->predict` (`vp9/common/vp9_reconinter.h:23`, -/// `vp9/common/vp9_scale.c:79`): for the unscaled case `predict[0][0]` is -/// copy/avg, `predict[0][1][*]` the vertical kernel, `predict[1][0][*]` the -/// horizontal one and `predict[1][1][*]` the 2D convolve. +/// `vp9/common/vp9_scale.c:79`): the kernel is picked by +/// `predict[subpel_x != 0][subpel_y != 0][avg]`. Unscaled that is +/// copy/avg, the vertical, the horizontal and the 2D convolve; with a scaled +/// reference the table collapses to the scaled variants (`vpx_scaled_horiz` / +/// `vpx_scaled_vert` — the same walk with `x_step_q4` / `y_step_q4` — and +/// `vpx_scaled_2d`), reproduced here by the step-aware convolve helpers. /// /// `w` x `h` output samples written at `dst`; `buf`/`origin` locate the /// block's first reference sample. `temp` is the `vpx_convolve8` intermediate @@ -307,12 +407,38 @@ fn inter_predictor( f: &[[i16; TAPS]; SUBPEL_SHIFTS as usize], subpel_x: i32, subpel_y: i32, + x_step: i32, + y_step: i32, w: usize, h: usize, avg: bool, temp: &mut [Sample], bd: u8, ) { + let scaled_x = x_step != SUBPEL_SHIFTS; + let scaled_y = y_step != SUBPEL_SHIFTS; + if scaled_x || scaled_y { + // sf->predict with a scaled axis (vp9_scale.c:79-110): an unscaled + // axis keeps its 1D kernel only when the other axis has no subpel + // offset; anything else is the 2D scaled convolve. + if !scaled_x && subpel_x == 0 { + convolve_vert( + buf, stride, origin, dst, dst_stride, f, subpel_y, y_step, w, h, avg, bd, + ); + return; + } + if !scaled_y && subpel_y == 0 { + convolve_horiz( + buf, stride, origin, dst, dst_stride, f, subpel_x, x_step, w, h, avg, bd, + ); + return; + } + convolve_2d( + buf, stride, origin, dst, dst_stride, f, subpel_x, subpel_y, x_step, y_step, w, h, avg, + temp, bd, + ); + return; + } if subpel_x == 0 && subpel_y == 0 { for y in 0..h { for x in 0..w { @@ -329,23 +455,47 @@ fn inter_predictor( } if subpel_y == 0 { convolve_horiz( - buf, stride, origin, dst, dst_stride, f, subpel_x, w, h, avg, bd, + buf, stride, origin, dst, dst_stride, f, subpel_x, SUBPEL_SHIFTS, w, h, avg, bd, ); return; } if subpel_x == 0 { convolve_vert( - buf, stride, origin, dst, dst_stride, f, subpel_y, w, h, avg, bd, + buf, stride, origin, dst, dst_stride, f, subpel_y, SUBPEL_SHIFTS, w, h, avg, bd, ); return; } - // vpx_convolve8_c: horizontal pass into a stride-64 intermediate with - // `intermediate_height = (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + - // SUBPEL_TAPS` — for the unscaled `y_step_q4 = 16` that is `h + SUBPEL_TAPS - // - 1`. The horizontal pass starts `SUBPEL_TAPS / 2 - 1` rows ABOVE the - // block (C passes `src - src_stride * (SUBPEL_TAPS / 2 - 1)`). - let intermediate_height = - (((h as i32 - 1) * SUBPEL_SHIFTS + subpel_y) >> SUBPEL_BITS) as usize + TAPS; + convolve_2d( + buf, stride, origin, dst, dst_stride, f, subpel_x, subpel_y, x_step, y_step, w, h, avg, + temp, bd, + ); +} + +/// `vpx_convolve8_c` / `vpx_convolve8_avg_c` (`vpx_dsp/vpx_convolve.c:158`) = +/// `vpx_scaled_2d` / `vpx_scaled_avg_2d`: horizontal pass into a stride-64 +/// intermediate with `intermediate_height = (((h - 1) * y_step_q4 + y0_q4) >> +/// SUBPEL_BITS) + SUBPEL_TAPS`, then the vertical pass. The horizontal pass +/// starts `SUBPEL_TAPS / 2 - 1` rows ABOVE the block (C passes +/// `src - src_stride * (SUBPEL_TAPS / 2 - 1)`). +#[allow(clippy::too_many_arguments)] +fn convolve_2d( + buf: &[Sample], + stride: usize, + origin: isize, + dst: &mut [Sample], + dst_stride: usize, + f: &[[i16; TAPS]; SUBPEL_SHIFTS as usize], + subpel_x: i32, + subpel_y: i32, + x_step: i32, + y_step: i32, + w: usize, + h: usize, + avg: bool, + temp: &mut [Sample], + bd: u8, +) { + let intermediate_height = (((h as i32 - 1) * y_step + subpel_y) >> SUBPEL_BITS) as usize + TAPS; let temp_origin = (TAPS as isize / 2 - 1) * 64; convolve_horiz( buf, @@ -355,6 +505,7 @@ fn inter_predictor( 64, f, subpel_x, + x_step, w, intermediate_height, false, @@ -374,6 +525,7 @@ fn inter_predictor( w, f, subpel_y, + y_step, w, h, false, @@ -395,6 +547,7 @@ fn inter_predictor( dst_stride, f, subpel_y, + y_step, w, h, false, @@ -417,9 +570,12 @@ pub(crate) struct RefPlane<'a> { pub bd: u8, } -/// `dec_build_inter_predictors` (`vp9/decoder/vp9_decodeframe.c:593`), -/// unscaled: predict one `w` x `h` plane block whose top-left is plane pixel -/// `(x, y)` inside the block at MI `(mi_row, mi_col)`. +/// `dec_build_inter_predictors` (`vp9/decoder/vp9_decodeframe.c:593`): +/// predict one `w` x `h` plane block whose top-left is plane pixel `(x, y)` +/// inside the block at MI `(mi_row, mi_col)`. `sf` is the reference's scale +/// factors; when they scale, the block is mapped into the reference frame +/// (`scale_value_x/y`), the MV is scaled with it (`vp9_scale_mv`) and the +/// convolve steps by `x_step_q4` / `y_step_q4`. #[allow(clippy::too_many_arguments)] pub(crate) fn build_inter_predictors( dst: &mut [Sample], @@ -440,51 +596,82 @@ pub(crate) fn build_inter_predictors( ss_y: usize, kernel: usize, avg: bool, + sf: &ScaleFactors, scratch: &mut Vec, temp: &mut Vec, ) { let bd = refp.bd; + let is_scaled = sf.is_scaled(); let mv_q4 = clamp_mv_to_umv_border_sb( mv, w as i32, h as i32, mb_left, mb_right, mb_top, mb_bottom, ss_x, ss_y, ); // Co-ordinate of the containing block, pixel precision, plus the // block-relative offset (`x`, `y`). - let x0_pre = (-mb_left >> (3 + ss_x)) + x as i32; - let y0_pre = (-mb_top >> (3 + ss_y)) + y as i32; - let x0_16 = (x0_pre << SUBPEL_BITS) + mv_q4.1; - let y0_16 = (y0_pre << SUBPEL_BITS) + mv_q4.0; - let subpel_x = mv_q4.1 & SUBPEL_MASK; - let subpel_y = mv_q4.0 & SUBPEL_MASK; + let x_pre = (-mb_left >> (3 + ss_x)) + x as i32; + let y_pre = (-mb_top >> (3 + ss_y)) + y as i32; + let (x_step, y_step, scaled_mv); + let (x0_16, y0_16, x0_pre, y0_pre); + if is_scaled { + // The block is mapped into the reference frame at 1/16-pel (the + // `x0_16` used for the border extent) and at pixel precision (`x0`, + // which shifts by the scaled MV's integer part below). + let x0 = sf.scale_x(x_pre); + let y0 = sf.scale_y(y_pre); + scaled_mv = sf.scale_mv( + mv_q4, + mi_col as i32 * 8 + x as i32, + mi_row as i32 * 8 + y as i32, + ); + x_step = sf.x_step_q4; + y_step = sf.y_step_q4; + x0_16 = sf.scale_x(x_pre << SUBPEL_BITS) + scaled_mv.1; + y0_16 = sf.scale_y(y_pre << SUBPEL_BITS) + scaled_mv.0; + x0_pre = x0; + y0_pre = y0; + } else { + scaled_mv = mv_q4; + x_step = SUBPEL_SHIFTS; + y_step = SUBPEL_SHIFTS; + x0_16 = (x_pre << SUBPEL_BITS) + scaled_mv.1; + y0_16 = (y_pre << SUBPEL_BITS) + scaled_mv.0; + x0_pre = x_pre; + y0_pre = y_pre; + } + let subpel_x = scaled_mv.1 & SUBPEL_MASK; + let subpel_y = scaled_mv.0 & SUBPEL_MASK; let frame_width = refp.width as i32; let frame_height = refp.height as i32; // `buf_ptr = ref_frame + y0 * stride + x0` is taken AFTER the MV integer // part but BEFORE the tap padding below, so the direct read keeps its own // copy of the coordinates. - let x0_mv = x0_pre + (mv_q4.1 >> SUBPEL_BITS); - let y0_mv = y0_pre + (mv_q4.0 >> SUBPEL_BITS); + let x0_mv = x0_pre + (scaled_mv.1 >> SUBPEL_BITS); + let y0_mv = y0_pre + (scaled_mv.0 >> SUBPEL_BITS); let mut x0 = x0_mv; let mut y0 = y0_mv; let f = &FILTERS[kernel]; - let _ = mi_col; - let _ = mi_row; // `is_scaled || scaled_mv.col || scaled_mv.row || (frame_width & 7) || // (frame_height & 7)`: the border copy is skipped only when the window is // provably inside the frame. - if mv_q4.1 != 0 || mv_q4.0 != 0 || (frame_width & 7) != 0 || (frame_height & 7) != 0 { - let mut x1 = ((x0_16 + (w as i32 - 1) * SUBPEL_SHIFTS) >> SUBPEL_BITS) + 1; - let mut y1 = ((y0_16 + (h as i32 - 1) * SUBPEL_SHIFTS) >> SUBPEL_BITS) + 1; + if is_scaled + || scaled_mv.1 != 0 + || scaled_mv.0 != 0 + || (frame_width & 7) != 0 + || (frame_height & 7) != 0 + { + let mut x1 = ((x0_16 + (w as i32 - 1) * x_step) >> SUBPEL_BITS) + 1; + let mut y1 = ((y0_16 + (h as i32 - 1) * y_step) >> SUBPEL_BITS) + 1; let mut x_pad = false; let mut y_pad = false; - if subpel_x != 0 { + if subpel_x != 0 || x_step != SUBPEL_SHIFTS { x0 -= INTERP_EXTEND - 1; x1 += INTERP_EXTEND; x_pad = true; } - if subpel_y != 0 { + if subpel_y != 0 || y_step != SUBPEL_SHIFTS { y0 -= INTERP_EXTEND - 1; y1 += INTERP_EXTEND; y_pad = true; @@ -523,6 +710,8 @@ pub(crate) fn build_inter_predictors( f, subpel_x, subpel_y, + x_step, + y_step, w, h, avg, @@ -545,6 +734,8 @@ pub(crate) fn build_inter_predictors( f, subpel_x, subpel_y, + x_step, + y_step, w, h, avg, diff --git a/crates/ec-vp9/tests/data/intraonly.ivf b/crates/ec-vp9/tests/data/intraonly.ivf new file mode 100644 index 0000000000000000000000000000000000000000..2d43e50ed4dbdd05773f91859b140e178a3e8d7b GIT binary patch literal 26051 zcmeF&Ly#t1urBJa@Re<&%Qm`f+qT(d+qP}1%eJ~~+qQLMpK}I#e8+!|Rz%L-O zh_s{_06+v#Q~1p&0CEe!0ssIY0000M@PEqz*LmohCqKvIHvYN8u|Gc2 zE|K~9oF{$Jdxp=w{b^U%)3GwX{n07wQuEa7c71)e#l7*dV|nRw1GfFeO>Qsma`of* zw1ZgYCA;PFwIcnT6ZbZwd!^QM;~i3GSF_db=~qocvv=@9C2eR%_sJ4=J9WE9SgqEz z`h|&j(aYcHjj+?xr_)&h@EbiEtU0M%*ga<%p|wi$Xegq3eI}M&vzuEfMDcFa9Nn>A*Pg^&g$>Lh`ZACiLzOasr#nmqo`? zOF=#3yyB$B1rxvfaD}y5`?QoX&NHQLv~djC>+$XLQDu4A$8ZFauLaa2NR9Udy@n70co0!Ozm#E9W8=3zq*wwF_Wi$%q4@`hIp`{^JEw2tFMW^dK4P z>SyU()pz8fH5HT;N0ki<$_MMpU%^MN`c~P^^{N*y23&agzBB=ktrbRK9B}B}BhVrB z|I0S>b5NKUx-3NT5lh^;k1t^#vzD+z=;DR)D}8iJ8i#z9OvDYvTd6V@Axh)2HJVC8_9Pe&7{}D%+tVaD}ODfG)6S4ft; zc(|-Z?GXr-Op19U9MV*IBDt4;oaOi><`c#x=iM6d%!&WiBkIH^p|qN))I#>~+*~qob}Fhs z;pt27*Q3ZZD}<=Su}>YtcYXtW@U9nL{y{Udpow#imBd&+eau?y1|oXd)#*zBnAUwnwhI z3)+LhBn6mi4L*)KNHQq{jK3@IaW;P=IlBN07sY@oigr1t9C-BeF%}ffQ zyY+a?s088Qh3ZEzx%T4fOc@r4xB+#*N@>kB8d|^+Fp>D#vv!Na0*>VCewK!qSKiG& zGnd+-alNT*kzgVCrBz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E+X`0suK0L9Yn z2CTBfebjtt9NAL_FdS3Vz68`bMf^r4>?=RrQgIel&dkIZl~#IWgO(J{?8%9-SoVHM zvF`$VWNF@4%U9PWN#HI^iPV`e80P##4T)V*yLNVNzWvxX(Z()UUih$gF#0t`0-sPv zBq)reT;VtA2(}%&y-<7?9%)-~`{v}gYAXVY0z<0|+_&PD%U>fs`^X3Oar`gpj;i8@ zoLn~#V!x4(62Wt9Q%s9sdSlruNuzW)KnmO_xc8f@zi*rqa<#$RR!lJ(V|j-zZpdV^ z*Epnp$`+AnE8tCZl-i4ZEpYrW-r~3JE=dF=b=5vS5qHH@+W{Dd|wt>MD(K`h0Arho7fQKPKNX^RSe>tA-me zy?tgK1(pk`!1h}bRiQkPFCOFlkf7V%K$eH`T9q?u*ICL4Bd3S9W^g&w|5CK-GaK>t ziC7^dZJ4OklmouqW5vh9Dg26HY1pZ`g^6fj* z;RM2T^kjGm5?w7gfR4J~k#cF4{j9yb|DdHmI`Gg>0nkRN`DWjDi6mR`Q1!5zm2(|z x^5oXf1T|zQ>FX*iT|y-~5EudGpOtmU=~03r)=_G$kTI@JAFQjm5b1T`e*o^KxlaH9 literal 0 HcmV?d00001 diff --git a/crates/ec-vp9/tests/data/scaledref_odd.ivf b/crates/ec-vp9/tests/data/scaledref_odd.ivf new file mode 100644 index 0000000000000000000000000000000000000000..b2203f5475d5b516c8dfbb66d7f3a3fafc56a5e0 GIT binary patch literal 5782 zcmZ9QWmME%*T(-CfenP(vdE(hWlnNJ}b6Ny*T> z%lm!a_gU-SpU#(Sowd&OyVl-k%P1?#0RSVQry;`ofIf-F00ICI006ka|5iNsKL-E+ zf)ztv1M2I~em)gup`+=h20eAH|9H!M!CP#RsoCE?BeYuU3vmg)UMc<48dloPYMhZd z?$m*rUS{PtMZV&^a~tbzGb8wxDx+hiWEP`$%FAk=G!>FFh`**^V{8`b6W;w={dQ zBeDVt0fW%cXJ>_sXMOagZ!;^uUi_*KV)~`n!Kf(3u{q$=@+FASFXmlw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C;HfhpLC&teop$ xlP9-+Ca57hNnclC=@Kf@fxrkb|E#P-PLC24v5rz}g^Y1+`e0qfg-EXh{{v~(x-0+y literal 0 HcmV?d00001 diff --git a/crates/ec-vp9/tests/intraonly_exact.rs b/crates/ec-vp9/tests/intraonly_exact.rs new file mode 100644 index 00000000..0e4e00d8 --- /dev/null +++ b/crates/ec-vp9/tests/intraonly_exact.rs @@ -0,0 +1,102 @@ +//! Intra-only witness: a VP9 intra-only frame — an INTER frame with +//! `intra_only = 1` and `show_frame = 0` — must decode byte-identically to +//! ffmpeg's libvpx decoder. Its body is a keyframe's (intra mode info, intra +//! prediction, the intra coefficient axis), but it loads its frame context +//! from storage and refreshes only the slots its `refresh_frame_flags` +//! names, so the frames that follow it prove the reconstruction. +//! +//! The fixture is committed under `tests/data/` because no ffmpeg invocation +//! emits an intra-only frame (libvpx's encoder produces them only through its +//! SVC path, which the libvpx-vp9 wrapper does not expose). The generator is +//! recorded in `lanes/vp9refsetup.report.md`; the stream is an ordinary +//! 10-frame 320x240 testsrc2 GOP whose visible keyframe is re-headed as an +//! intra-only inter frame with a matching `refresh_frame_flags`, so its +//! reconstruction must equal the keyframe's and the whole GOP must come out +//! identical to the source. + +mod ivf; + +use ec_vp9::decode::Decoder; +use ec_vp9_syntax::{FrameType, Vp9Parser}; + +fn fixture() -> std::path::PathBuf { + std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/data/intraonly.ivf") +} + +/// ffmpeg's decoded rawvideo byte stream (frame-packed I420, `w`x`h`). +fn ffmpeg_raw_yuv(path: &std::path::Path, w: usize, h: usize) -> Vec { + let out = std::process::Command::new("ffmpeg") + .args(["-v", "error", "-i"]) + .arg(path) + .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) + .output() + .expect("ffmpeg on PATH"); + assert!(out.status.success(), "ffmpeg decode failed: {out:?}"); + let frame = w * h + 2 * (w / 2) * (h / 2); + assert_eq!( + out.stdout.len() % frame, + 0, + "ffmpeg output is not frame-aligned" + ); + out.stdout +} + +#[test] +fn intra_only_frame_and_its_successors_match_ffmpeg() { + let path = fixture(); + let bytes = std::fs::read(&path).expect("tests/data/intraonly.ivf is committed"); + let (_, w, h, frames) = ivf::parse_ivf(&bytes); + let (w, h) = (w as usize, h as usize); + + // Non-vacuity: the stream must really carry an intra-only frame. + let mut parser = Vp9Parser::new(); + let mut intra_only = 0usize; + for f in &frames { + for sub in ec_vp9_syntax::split(&f.data).unwrap() { + let hdr = parser.parse_frame(sub).unwrap(); + if hdr.frame_type == FrameType::Inter && hdr.intra_only { + intra_only += 1; + } + } + } + assert_eq!( + intra_only, 1, + "the fixture must carry exactly one intra-only frame" + ); + + let expected = ffmpeg_raw_yuv(&path, w, h); + let frame_bytes = w * h + 2 * (w / 2) * (h / 2); + let mut decoder = Decoder::new(); + let mut shown = 0usize; + for (i, f) in frames.iter().enumerate() { + if let Some(pic) = decoder.decode(&f.data).expect("frame decodes") { + let off = shown * frame_bytes; + assert!( + off + frame_bytes <= expected.len(), + "frame {i}: ffmpeg has fewer frames than we show" + ); + let want = &expected[off..off + frame_bytes]; + let mut got = Vec::with_capacity(frame_bytes); + got.extend(pic.y.iter().map(|&v| v as u8)); + got.extend(pic.u.iter().map(|&v| v as u8)); + got.extend(pic.v.iter().map(|&v| v as u8)); + let diff = got.iter().zip(want).position(|(a, b)| a != b); + assert!( + diff.is_none(), + "frame {i}: pixel mismatch at byte {:?} (ours {} ffmpeg {})", + diff, + diff.map(|d| got[d]).unwrap_or(0), + diff.map(|d| want[d]).unwrap_or(0) + ); + shown += 1; + } + } + assert_eq!( + shown * frame_bytes, + expected.len(), + "shown frame count mismatch" + ); + // 11 input frames: a visible keyframe, the hidden intra-only frame and 9 + // visible inter frames — 10 shown. + assert_eq!(shown, 10, "the witness must show past the intra-only frame"); +} diff --git a/crates/ec-vp9/tests/scaledref_exact.rs b/crates/ec-vp9/tests/scaledref_exact.rs new file mode 100644 index 00000000..6c43d145 --- /dev/null +++ b/crates/ec-vp9/tests/scaledref_exact.rs @@ -0,0 +1,172 @@ +//! Scaled-reference witness: an inter frame whose reference slot holds a +//! picture of a DIFFERENT coded size must scale that reference during +//! prediction (`vp9_setup_scale_factors_for_frame` + the scaled convolve +//! walk) and come out byte-identical to libvpx. `scaledref.ivf` scales +//! 1280x720 -> 640x360 (`x_step_q4 == y_step_q4 == 32`); the paired +//! `scaledref_odd.ivf` is the same stream with the keyframe patched to +//! 1279x719, so the reference is an ODD coded extent and its chroma crop +//! ceils — the interaction with the odd-dimension layout. +//! +//! The fixtures are committed under `tests/data/` because no ffmpeg +//! invocation can produce a size change: libvpx's encoder emits one only +//! through its rate-control resize path (ffmpeg exposes neither +//! `rc_resize_allowed` nor SVC), and a hand-spliced explicit-size inter frame trips +//! libvpx's own header reparsing. The generator is recorded in +//! `lanes/vp9refsetup.report.md`: a 1280x720 one-pass CBR encode at 200 kbps, +//! whose `vp9_resize_one_pass_cbr` downscales frame 1 to 640x360 against the +//! keyframe. `scaledref_odd.ivf` is that same file through +//! `$HOME/.cache/vp9pix/patch_kf_size.py 1279 719` (which rewrites +//! the IVF container size too). +//! +//! Oracle caveat: ffmpeg locks its rawvideo output size to the FIRST decoded +//! frame's, so a two-size stream cannot be dumped in one pass. Frame 0 is +//! decoded on its own (`-frames:v 1`, identity); frames 2..N are decoded with +//! `select=gte(n,1)` at the small size, where the filtergraph has +//! re-initialised and every frame passes through unchanged. The size-change +//! frame (file frame 1) is the one ffmpeg mangles during that +//! re-initialisation, so it is checked INDIRECTLY: every later frame predicts +//! from its reconstruction, so a wrong scaler fails frames 2..N. + +mod ivf; + +use ec_vp9::decode::Decoder; +use ec_vp9_syntax::{FrameType, Vp9Parser}; + +fn fixture(name: &str) -> std::path::PathBuf { + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests/data") + .join(name) +} + +/// Run ffmpeg over `path` with `args` and return its rawvideo stdout. +fn ffmpeg_raw(path: &std::path::Path, args: &[&str]) -> Vec { + let out = std::process::Command::new("ffmpeg") + .args(["-v", "error", "-y", "-i"]) + .arg(path) + .args(args) + .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) + .output() + .expect("ffmpeg on PATH"); + assert!(out.status.success(), "ffmpeg decode failed: {out:?}"); + out.stdout +} + +fn frame_bytes(w: usize, h: usize) -> usize { + w * h + 2 * w.div_ceil(2) * h.div_ceil(2) +} + +fn assert_planes(pic: &ec_vp9::decode::Picture, want: &[u8], label: &str) { + let mut got = Vec::with_capacity(want.len()); + got.extend(pic.y.iter().map(|&v| v as u8)); + got.extend(pic.u.iter().map(|&v| v as u8)); + got.extend(pic.v.iter().map(|&v| v as u8)); + assert_eq!(got.len(), want.len(), "{label}: plane size"); + let diff = got.iter().zip(want).position(|(a, b)| a != b); + assert!( + diff.is_none(), + "{label}: pixel mismatch at byte {:?} (ours {} libvpx {})", + diff, + diff.map(|d| got[d]).unwrap_or(0), + diff.map(|d| want[d]).unwrap_or(0) + ); +} + +fn check(name: &str) { + let path = fixture(name); + let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); + let (_, cw, ch, frames) = ivf::parse_ivf(&bytes); + + // Non-vacuity: the stream must carry an inter frame whose coded size + // differs from the frame before it — the only shape that makes a + // reference scale. + let mut parser = Vp9Parser::new(); + let mut sizes: Vec<(u32, u32, FrameType)> = Vec::new(); + for f in &frames { + for sub in ec_vp9_syntax::split(&f.data).unwrap() { + let hdr = parser.parse_frame(sub).unwrap(); + sizes.push((hdr.width, hdr.height, hdr.frame_type)); + } + } + let changed = sizes + .windows(2) + .filter(|p| p[0].0 != p[1].0 || p[0].1 != p[1].1) + .count(); + assert!( + changed >= 1, + "{name}: the fixture must change coded size mid-stream (sizes: {sizes:?})" + ); + assert!( + sizes + .iter() + .any(|s| s.2 == FrameType::Inter && (s.0, s.1) != (cw as u32, ch as u32)), + "{name}: an inter frame must differ from the container's declared size" + ); + + let mut decoder = Decoder::new(); + let ours: Vec<_> = frames + .iter() + .map(|f| decoder.decode(&f.data).expect("frame decodes")) + .collect(); + let shown: Vec<_> = ours.iter().filter_map(|p| p.as_ref()).collect(); + assert_eq!(shown.len(), 10, "{name}: the fixture has 10 visible frames"); + + // Frame 0 (the keyframe) alone; identity. + let oracle0 = ffmpeg_raw(&path, &["-frames:v", "1"]); + assert_eq!( + oracle0.len(), + frame_bytes(shown[0].width as usize, shown[0].height as usize), + "{name}: frame 0 oracle size" + ); + assert_planes(shown[0], &oracle0, &format!("{name} frame 0")); + + // Frames 2..N: after the size change every frame passes through the + // filtergraph unchanged at the small size. + let small = (shown[2].width as usize, shown[2].height as usize); + assert!( + small != (shown[0].width as usize, shown[0].height as usize), + "{name}: frames after the change must be resized" + ); + let oracle_rest = ffmpeg_raw( + &path, + &[ + "-vf", + "select=gte(n\\,1)", + "-fps_mode", + "passthrough", + "-s", + &format!("{}x{}", small.0, small.1), + ], + ); + let fbs = frame_bytes(small.0, small.1); + assert_eq!( + oracle_rest.len(), + fbs * (shown.len() - 2), + "{name}: ffmpeg must emit frames 2..{}", + shown.len() - 1 + ); + for (j, pic) in shown[2..].iter().enumerate() { + assert_eq!( + (pic.width as usize, pic.height as usize), + small, + "{name}: frame {} size", + j + 2 + ); + assert_planes( + pic, + &oracle_rest[j * fbs..(j + 1) * fbs], + &format!("{name} frame {}", j + 2), + ); + } +} + +#[test] +fn size_changing_reference_decodes_byte_exact() { + check("scaledref.ivf"); +} + +/// The same size change with an ODD coded reference: 1279x719 -> 640x360, +/// where the reference's chroma crop ceils (`(1279 + 1) / 2`). +#[test] +fn size_changing_odd_reference_decodes_byte_exact() { + check("scaledref_odd.ivf"); +} diff --git a/lanes/vp9refsetup.report.md b/lanes/vp9refsetup.report.md new file mode 100644 index 00000000..0d353a15 --- /dev/null +++ b/lanes/vp9refsetup.report.md @@ -0,0 +1,167 @@ +# lane-vp9-refsetup — intra-only frames + scaled references + +Branch `lane-vp9-refsetup`, off main `79984549`. Two named refusals removed: + +1. `vp9 intra-only` — an INTER frame with `intra_only = 1`, `show_frame = 0` + (`decode.rs:233`, `:320`). +2. `vp9 inter reference size change` — an inter frame whose reference slot + holds a picture of a different coded size (`decode.rs:372`). + +Acceptance bar: byte-exact vs libvpx 1.15 (the frozen oracle drivers +`$HOME/.cache/vp9pix/drv_pix3`, `drv_err`, statically linked to the 1.15 build) +on real streams, plus the full 8-bit regression corpus unchanged. + +## What changed + +| path | why | +| --- | --- | +| `crates/ec-vp9/src/decode.rs` `decode_one` / `decode_syntax` | intra-only routes to the new `decode_intra_only_frame` instead of refusing | +| `crates/ec-vp9/src/decode.rs` `decode_intra_only_frame` | new: keyframe body, storage-loaded frame context (reset only for `reset_frame_context` 2/3 / error-resilient), `refresh_frame_flags`-scoped reference refresh | +| `crates/ec-vp9/src/decode.rs` `decode_block` | intra dispatch keys on `frame_is_intra_only` (keyframe OR intra-only), not `frame_type == Key` | +| `crates/ec-vp9/src/decode.rs` `decode_inter_frame` | size-change refusal removed; slot-existence checks kept | +| `crates/ec-vp9/src/decode.rs` `inter_predict_plane` | `ScaleFactors::setup` per reference (`valid_ref_frame_size` -> `vp9 reference scale` refusal where libvpx errors) | +| `crates/ec-vp9/src/mc.rs` | `ScaleFactors` (`vp9_setup_scale_factors_for_frame`, `vp9_scale_mv`), step-aware `convolve_horiz`/`convolve_vert`, `sf->predict` kernel selection, scaled block/MV mapping in `build_inter_predictors` | +| `crates/ec-vp9/src/header.rs` | `FrameContext::use_key_partition` (`set_partition_probs`) | +| `crates/ec-vp9/tests/{intraonly,scaledref}_exact.rs` + `tests/data/*.ivf` | regression witnesses | + +### Semantics ported (bug-for-bug, libvpx 1.15.0) + +* `vp9_setup_past_independence` (`vp9/common/vp9_entropymode.c:424`) is called + for intra-only frames, but `cm->frame_type != KEY_FRAME`, so the stored + contexts are reset only for `reset_frame_context` 2 (selected) / 3 (all) or + error-resilient mode. The ACTIVE context is then + `*cm->fc = cm->frame_contexts[frame_context_idx]` + (`vp9_decodeframe.c:3008`) — storage, not the defaults. +* Partitions for intra-only (and key) frames come from the const + `vp9_kf_partition_probs` (`set_partition_probs`, `onyxc_int.h:367`), which is + NOT a `FRAME_CONTEXT` field: the stored context's `partition` survives the + frame untouched (restored before storing). +* Reference refresh is `refresh_frame_flags`-scoped; `show_frame` stays 0 (an + intra-only frame is never displayable — the parser only reads `intra_only` + when `show_frame == 0`). +* Scaling: `x_scale_fp = (other << 14) / this`, `x_step_q4 = scaled_x(16)`; + the block maps with `scale_value_x/y`, the MV with `vp9_scale_mv` + (`vp9_scale.c:29`), and `sf->predict[subpel_x != 0][subpel_y != 0]` picks the + kernel (`vpx_scaled_horiz/vert/2d` == the step-aware convolve helpers). + The tap-padding branch is `subpel || step != 16`; the direct read keeps the + pre-padding coordinates. + +## Fixtures and generators (reproducibility) + +None of these can be produced by an ffmpeg invocation: + +* **intra-only**: libvpx's encoder emits intra-only frames only through its SVC + path (`set_intra_only_frame`, `vp9_ratectrl.c:2211`), which ffmpeg does not + expose. Generated by `lanes/vp9refsetup/gen_intraonly.py` from a plain + ffmpeg keyframe GOP: + ``` + ffmpeg -v error -y -f lavfi -i testsrc2=size=320x240:rate=24:duration=0.4 \ + -c:v libvpx-vp9 -g 999 -auto-alt-ref 0 -crf 32 -deadline good -cpu-used 4 \ + -pix_fmt yuv420p -f ivf S.ivf + python3 lanes/vp9refsetup/gen_intraonly.py S.ivf intraonly.ivf + ``` + The generator reproduces the committed `tests/data/intraonly.ivf` byte for + byte (`cmp` verified). 11 frames: keyframe, hidden intra-only twin, 9 inter. +* **size change**: libvpx's encoder resizes only through rate control + (`vp9_resize_one_pass_cbr`, `vp9_ratectrl.c:2728`); ffmpeg exposes neither + `rc_resize_allowed` nor SVC, and ffmpeg's rawvideo output size is locked to + the first decoded frame (see the oracle caveat), so a two-size stream cannot + be dumped in one pass. Generated by + `lanes/vp9refsetup/gen_scaledref.c` (links the pristine libvpx 1.15.0 + encoder): + ``` + gcc -I -I/vpx gen_scaledref.c /libvpx.a -o enc -lm -lpthread + ./enc scaledref.ivf 1280 720 10 200 # one-pass CBR, 200 kbps, lag 0 + ``` + libvpx's force-downsize rule (`>= 1280x720` input and + `avg_frame_bandwidth < 300000/30`) downscales frame 1 to 640x360 against the + 1280x720 keyframe — a genuine 2x reference scale (`x_step_q4 == 32`). +* **odd variant**: `scaledref_odd.ivf` is `scaledref.ivf` with the keyframe's + size fields patched 1280x720 -> 1279x719 (mi-grid invariant, so the tile data + stays valid) — the reference is then an odd coded extent and its chroma crop + ceils. Patch with the existing + `$HOME/.cache/vp9pix/patch_kf_size.py 1279 719`, which rewrites the + IVF container size as well (`sha256 af289a0f8dd91bfa854adeac1814dc77644ad87b9df0af884d33abaae2595413`). + +## Gates + +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9ref` + +1. **Suite**: `cargo test -p ec-vp9` — every binary green, **0 failed**, + 0 ignored. Warning parity: exactly the 5 pre-existing (`TM_PRED`, + `read_partition`, `partition_probs`, `x_mis`, `y_mis`). +2. **New witnesses** (byte-exact vs ffmpeg's libvpx-backed rawvideo): + * `intra_only_frame_and_its_successors_match_ffmpeg` — 10/10 shown frames + identical; the fixture is asserted to carry exactly one intra-only frame. + * `size_changing_reference_decodes_byte_exact` — 10/10 identical. + * `size_changing_odd_reference_decodes_byte_exact` — 10/10 identical. +3. **Crate-level oracle** (my dump vs libvpx's `drv_pix3`, per-shown-frame + native dims + ceil chroma, compared with `cmp`): + `scaledref.ivf` **IDENTICAL** (4,492,800 bytes, 10 frames); + `scaledref_odd.ivf` **IDENTICAL** (4,490,801 bytes, 10 frames); + `intraonly.ivf` **IDENTICAL** via drv_pix (all 10 output frames match the + source GOP's, i.e. the intra-only frame reconstructs exactly like the + keyframe it replaced). +4. **Fail-pre-fix** (throwaway base worktree at `79984549`, tests+fixtures + copied in, private target dir): + * intra-only: `Unsupported { what: "vp9 intra-only", why: "this lane decodes + inter frames and keyframes only" }` at `intraonly_exact.rs:72`. + * scaled: `Unsupported { what: "vp9 inter reference size change", why: + "reference `last` in slot 0 is 1280x720 but this frame is 640x360; + reference-frame scaling is not ported" }` (and the 1279x719 twin) at + `scaledref_exact.rs:107`. +5. **Regression corpus** (`$HOME/.cache/vp9ref-sweep.sh` = `drv_pix3` vs + `scratch_pixdump`, byte `cmp`) — all **IDENTICAL**: + +| stream | oracle frames | bytes | +| --- | --- | --- | +| `vp9-1080p-23.976-8bit.ivf` | 48 | 149,299,200 | +| `vp9-1080p-60-8bit.ivf` (120 frames, the frame-72 witness) | 120 | 373,248,000 | +| `vp9-2160p-23.976-8bit.ivf` | 48 | 597,196,800 | +| `vp9-tiles-1280.ivf` | 30 | 41,472,000 | +| `vp9-superframe-altref.ivf` | 60 | 6,912,000 | +| `$HOME/.cache/vp9pix/inter.ivf` | 3 | 9,331,200 | +| `$HOME/.cache/vp9pix/inter1.ivf` | 3 | 9,331,200 | +| odd testsrc2 321x241 (322x242 encode + `patch_kf_size.py`) | 12 | 1,395,876 | + +6. **Interaction (size change x odd dims)**: `scaledref_odd.ivf` covers it — + the scaled reference is an odd extent (1279x719, chroma `(w+1)/2`) and the + result is byte-identical to libvpx. Not deferred. + +## Oracle caveat (why the committed tests skip frame 1) + +ffmpeg locks its rawvideo output size to the FIRST decoded frame's, so a +two-size stream cannot be dumped in one pass: frames 1..N come out upscaled to +1280x720. The tests decode frame 0 alone (`-frames:v 1`, identity) and frames +2..N with `select=gte(n,1)` at the small size, where the filtergraph has +re-initialised and every frame passes through unchanged. The size-change frame +(file frame 1) is the one ffmpeg mangles during that re-initialisation, so it +is covered INDIRECTLY: every later frame predicts from its reconstruction (a +wrong scaler fails frames 2..N). Frame 1 itself is covered directly by the +crate-level `drv_pix3` comparison in gate 3. + +## Deferred / accepted + +* accepted: **profile 2 / 4:4:4** still refused by name (`decode.rs:211/217`, + and `vp9 reference scale` for a colour-format mismatch) — out of scope, owned + by the sibling lane. +* accepted: `vp9 reference scale` (the `valid_ref_frame_size` ratio bound) stays + a named refusal; libvpx errors the same way (`Reference frame has invalid + dimensions`). Reaching it needs an adversarial 2x+ ratio that no encoder + emits. +* noted, not touched: the existing inter path resets stored frame contexts for + `reset_frame_context` 2/3 even though libvpx only does that via + `vp9_setup_past_independence` (i.e. only for intra-only / error-resilient + frames). Pre-existing, unreachable on the corpus (which codes `reset = 0`), + and outside this lane's scope. +* noted: `scratch_pixdump`/`drv_pix3` are per-`inter_pixdump`-style scratch + harnesses; the new `drv_pix3` (per-frame native dims) lives only in + `$HOME/.cache/vp9pix`. + +## Test scope actually run + +* `cargo test -p ec-vp9` (whole crate) — green, 0 failed, 5 warnings. +* `cargo test -p ec-vp9 --test intraonly_exact --test scaledref_exact` — 3 + passed. +* corpus sweep above — 8 streams IDENTICAL. +* base-worktree fail-pre-fix — 3 failures with the named refusals. diff --git a/lanes/vp9refsetup/gen_intraonly.py b/lanes/vp9refsetup/gen_intraonly.py new file mode 100644 index 00000000..81056ade --- /dev/null +++ b/lanes/vp9refsetup/gen_intraonly.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +"""Turn an ffmpeg VP9 keyframe GOP into the intra-only witness. + +Re-heads frame 0 (a visible keyframe) as an INTRA-ONLY inter frame +(frame_type=1, show_frame=0, intra_only=1, reset_frame_context=2, +refresh_frame_flags=0xff) and keeps every later frame as-is: the intra-only +frame must reconstruct exactly like the keyframe it replaces, so the whole GOP +decodes to the same shown frames. + +reset_frame_context=2 matters: `vp9_setup_past_independence` resets the +selected stored context to the defaults, and the keyframe's compressed header +was coded against the defaults. With reset 0/1 the frame would read whatever +context the previous frame stored and the bool stream desyncs. + +usage: gen_intraonly.py +The keyframe uncompressed header (profile 0, 8-bit, 4:2:0, error_resilient=0) +is 8 bits + 24 sync + 3 color_space + 1 color_range => the render flag sits at +bit 68 and the fields from bit 69 on (loop filter, quant, segmentation, tile +info, header_size) are copied verbatim. The new prefix is 76 bits, so the +field bits shift by 7 and the compressed header + tiles (orig[U:], with +U = ceil(E/8)) follow the re-padded header. E was found by trying every byte +offset until libvpx accepted the frame; the committed fixture's E is 140. +""" +import struct, sys + +src, dst = sys.argv[1], sys.argv[2] +d = open(src, 'rb').read() +off, frames = 32, [] +while off + 12 <= len(d): + sz = struct.unpack('> i) & 1 for x in b for i in range(7, -1, -1)] + +K = frames[0][1] +kb = bits_of(K) +assert kb[5] == 0 and kb[6] == 1 and kb[7] == 0, "expected a visible, non-ER keyframe" +rf = kb[68] +p1 = 69 if rf == 0 else 101 +prefix = kb[0:5] + [1, 0, kb[7], 1] + [1, 0] + kb[8:32] + [1] * 8 + kb[36:52] + kb[52:68] + [rf] +if rf: + prefix += kb[69:101] +assert len(prefix) == 76 + +E = 140 # committed fixture; any E whose (E+7)>>3 == 18 also decodes +post = kb[p1:E] +nb = prefix + post +while len(nb) % 8: + nb.append(0) +hdr = bytearray() +for i in range(0, len(nb), 8): + v = 0 + for j in range(8): + v = (v << 1) | nb[i+j] + hdr.append(v) +Kp = bytes(hdr) + K[(E + 7) >> 3:] + +out = bytearray(b'DKIF' + b'\0' * 28) +out[6:8] = struct.pack(' +#include +#include +#include +#include +#include +static FILE *O; +static void drain(vpx_codec_ctx_t *c){ + const vpx_codec_cx_pkt_t *pkt; vpx_codec_iter_t it=NULL; + while((pkt=vpx_codec_get_cx_data(c,&it))) if(pkt->kind==VPX_CODEC_CX_FRAME_PKT){ + unsigned char sz[4]; uint32_t n=pkt->data.frame.sz; memcpy(sz,&n,4); fwrite(sz,1,4,O); + unsigned long ts=(unsigned long)pkt->data.frame.pts; unsigned char t[8]; memcpy(t,&ts,8); fwrite(t,1,8,O); + fwrite(pkt->data.frame.buf,1,n,O); + } +} +static void fill(vpx_image_t*img,int f){ + int W=img->d_w,H=img->d_h; + for(int y=0;yplanes[0][y*img->stride[0]+x]=(unsigned char)(v&0xff);} + // A moving 200x120 high-contrast box (nonzero MVs + residual under scaling). + int bx=(f*37)%(W-200), by=(f*23)%(H-120); + for(int y=by;yplanes[0][y*img->stride[0]+x]=(((x/16+y/16)&1)?230:25); + for(int p=1;p<3;p++){int cw=(W+1)/2,ch=(H+1)/2; + for(int y=0;yplanes[p][y*img->stride[p]+x]=(unsigned char)(v&0xff);}} +} +int main(int argc,char**argv){ + const char*out=argv[1]; int W=atoi(argv[2]),H=atoi(argv[3]),N=atoi(argv[4]),br=atoi(argv[5]); + vpx_codec_enc_cfg_t cfg; vpx_codec_enc_config_default(vpx_codec_vp9_cx(),&cfg,0); + cfg.g_w=W;cfg.g_h=H;cfg.g_timebase.num=1;cfg.g_timebase.den=30; + cfg.rc_end_usage=VPX_CBR;cfg.rc_target_bitrate=br;cfg.g_lag_in_frames=0; + cfg.rc_resize_allowed=1; cfg.rc_buf_sz=200; cfg.rc_buf_initial_sz=100; cfg.rc_buf_optimal_sz=150; + cfg.rc_min_quantizer=4; cfg.rc_max_quantizer=56; + cfg.kf_min_dist=9999;cfg.kf_max_dist=9999; + vpx_codec_ctx_t c; + if(vpx_codec_enc_init(&c,vpx_codec_vp9_cx(),&cfg,0)){fprintf(stderr,"init %s\n",vpx_codec_error(&c));return 1;} + vpx_codec_control(&c,VP8E_SET_CPUUSED,5); + O=fopen(out,"wb"); unsigned char hdr[32];memset(hdr,0,32);memcpy(hdr,"DKIF",4);hdr[6]=32;memcpy(hdr+8,"VP90",4); + hdr[12]=W&0xff;hdr[13]=W>>8;hdr[14]=H&0xff;hdr[15]=H>>8;hdr[16]=30;hdr[17]=1;hdr[20]=1; + uint32_t nf=N;memcpy(hdr+24,&nf,4);fwrite(hdr,1,32,O); + vpx_image_t*img=vpx_img_alloc(NULL,VPX_IMG_FMT_I420,W,H,1); + for(int i=0;i