forge
Explore
Log in

Don't you dare go Hollow

Refuse use_superres by name -- was silent wrongness

Browse files at this commit

08cce92bb820c0046f8d75f72c83faad77ccf101Ahmet Kaan GümüşParent: 33241d0
  • fix
    • refuse use_superres by name -- was silent wrongness
Show full message
fix(av1): refuse use_superres by name -- was silent wrongness

Step 0 measurement: use_superres/superres_denom already parse fully in
ec-av1-syntax (unit-tested), and superres adds/removes no per-block
symbol (spec 7.16's upscaler is a pixel-domain post-process run after
loop restoration), so decode_stream stayed bit-exact in sync on a real
--superres-mode=1 stream -- but every decode path stores the Picture at
frame_width (the downscaled coded width) and never runs the upscaler,
so it would silently hand back a picture sized frame_width instead of
upscaled_width. Refuse by name until the upscaler lands (lane-superres
stage 2+).

Gate: a_real_aomenc_stream_with_superres_refuses_by_name, real aomenc
--superres-mode=1 --superres-denominator=12 stream, asserts the refusal
names use_superres rather than desyncing into something else. Suite:
233 passed / 0 failed (232 baseline + 1).
crates/ec-av1/src/stream.rsmodified+113 -0
@@ -185,6 +185,22 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
185185 "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)",
186186 ));
187187 }
188+ // lane-superres Step 0: `use_superres` adds/removes no per-block
189+ // symbol (spec 7.16's upscaling is a pixel-domain post-process run
190+ // after loop restoration, `av1_upscale_normative_*` in libaom's
191+ // `resize.c`), so this crate's tile readers stay bit-exact-in-sync
192+ // even without support. But every decode path below reads and
193+ // stores the frame at `header.frame_width` (the downscaled coded
194+ // width) and never runs the upscaler, so a superres stream would
195+ // silently produce a `Picture` sized `frame_width` instead of the
196+ // spec's `upscaled_width` -- SILENT WRONGNESS, not a desync. Refuse
197+ // by name until the upscaler (lane-superres) lands.
198+ if header.use_superres {
199+ return Err(Error::unsupported(
200+ "AV1 decode_stream",
201+ "a frame with use_superres set (this decoder never runs the spec 7.16 upscaler; it would silently output the frame at the downscaled frame_width instead of upscaled_width)",
202+ ));
203+ }
188204 // Loop restoration carries per-restoration-unit symbols in the tile
189205 // (spec 5.11.57 `read_lr`, one group per LR unit reached from the
190206 // superblock walk) that this decoder never reads -- same
@@ -3683,6 +3699,103 @@ mod tests {
36833699 );
36843700 }
36853701
3702+ /// lane-superres Step 0/stage 1: a real aomenc `--superres-mode=1`
3703+ /// stream must refuse BY NAME (`use_superres`), never desync into a
3704+ /// different error and never silently decode a wrong-sized picture.
3705+ /// `use_superres` adds no per-block symbol (spec 7.16's upscaler is a
3706+ /// pixel-domain post-process), so before the stream.rs refusal landed
3707+ /// this crate's tile readers stayed bit-exact in sync but stored the
3708+ /// `Picture` at the downscaled `frame_width` instead of
3709+ /// `upscaled_width` -- exactly the SILENT WRONGNESS the charter's Step 0
3710+ /// called for turning into an explicit refusal first.
3711+ #[test]
3712+ fn a_real_aomenc_stream_with_superres_refuses_by_name() {
3713+ const NAME: &str = "a_real_aomenc_stream_with_superres_refuses_by_name";
3714+ let _gate_lock = lock_gate_counters();
3715+ if !have_ffmpeg() {
3716+ eprintln!("SKIP {NAME}: no ffmpeg");
3717+ return;
3718+ }
3719+ if !have_aomenc() {
3720+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3721+ return;
3722+ }
3723+ let (width, height, frame_count) = (64usize, 64usize, 4usize);
3724+ let duration = frame_count as f64 / 25.0;
3725+ let source = gradients_source(42, width, height, &format!("duration={duration}:rate=25"));
3726+ let y4m = Command::new("ffmpeg")
3727+ .args([
3728+ "-v",
3729+ "error",
3730+ "-f",
3731+ "lavfi",
3732+ "-i",
3733+ &source,
3734+ "-pix_fmt",
3735+ "yuv420p",
3736+ "-f",
3737+ "yuv4mpegpipe",
3738+ "-",
3739+ ])
3740+ .stdin(Stdio::null())
3741+ .stdout(Stdio::piped())
3742+ .stderr(Stdio::piped())
3743+ .output()
3744+ .expect("ffmpeg failed to run");
3745+ assert!(
3746+ y4m.status.success(),
3747+ "ffmpeg fixture: {}",
3748+ String::from_utf8_lossy(&y4m.stderr)
3749+ );
3750+ let args: Vec<&str> = vec![
3751+ "--codec=av1",
3752+ "--passes=1",
3753+ "--end-usage=q",
3754+ "--cq-level=32",
3755+ "--cpu-used=0",
3756+ "--kf-max-dist=1000",
3757+ "--threads=1",
3758+ "--row-mt=0",
3759+ "--superres-mode=1",
3760+ "--superres-denominator=12",
3761+ "--obu",
3762+ "-o",
3763+ "-",
3764+ "-",
3765+ ];
3766+ let mut child = Command::new(aomenc_path())
3767+ .args(&args)
3768+ .stdin(Stdio::piped())
3769+ .stdout(Stdio::piped())
3770+ .stderr(Stdio::piped())
3771+ .spawn()
3772+ .expect("aomenc failed to start");
3773+ child
3774+ .stdin
3775+ .take()
3776+ .expect("aomenc stdin")
3777+ .write_all(&y4m.stdout)
3778+ .expect("writing y4m to aomenc");
3779+ let out = child.wait_with_output().expect("aomenc failed to run");
3780+ assert!(
3781+ out.status.success(),
3782+ "aomenc refused the fixture: {}",
3783+ String::from_utf8_lossy(&out.stderr)
3784+ );
3785+ let stream = out.stdout;
3786+ let err = decode_stream(&stream).expect_err(
3787+ "a real --superres-mode=1 stream must refuse -- superres decode is not implemented \
3788+ and silently produces a wrong-sized picture otherwise",
3789+ );
3790+ let msg = err.to_string();
3791+ assert!(
3792+ msg.contains("use_superres"),
3793+ "{NAME}: refused, but not by the superres name -- this stream desynced into a \
3794+ different refusal instead: {msg}"
3795+ );
3796+ eprintln!("{NAME}: refused by name: {msg}");
3797+ }
3798+
36863799 /// lane-interintra r1: `--enable-interintra-comp=1` streams must DECODE
36873800 /// pixel-exact -- the interintra flag/mode/wedge-flag syntax and the
36883801 /// non-wedge smooth blend are ported. A refusal naming interintra fails