forge
Explore
Log in

Don't you dare go Hollow

A decoder with nothing to say about the GPU's 1080p

Browse files at this commit

85641e4c2680b4ca98da48449e216652287a3c1aAhmet Kaan GümüşParent: a082e61
  • test
    • a decoder with nothing to say about the GPU's 1080p
Show full message
✅ test(hevc): a decoder with nothing to say about the GPU's 1080p

The twin the seat shipped without. It asserts the three things a frame count
cannot see: ffmpeg's error channel *empty*, the coded size still cropping to
1920x1080, and SSIM against the frames that went in (a desynced stream scores
about 0.22, this one 0.98). `testsrc2` at 1080p is what makes it bite -- it
splits transform trees deep enough and pushes the rate controller hard enough
to need the syntax the parameter sets have to declare, where the two-frame
fixtures beside it are flat and pass either way.

Checked against each of the three defects in turn: depth 0 fails on the error
channel, `cu_qp_delta` off and the min-CB size both fail on SSIM.
crates/engine/tests/hevc_export.rsmodified+84 -0
@@ -195,6 +195,69 @@ fn an_hevc_export_decodes_back_into_pictures_through_edith() {
195 }195 }
196 }196 }
197 197
198+/// The same 1080p picture, coded by the **GPU**, and the test that would have
199+/// caught what shipped: the hardware seat's file decoded frame for frame while
200+/// every frame of it was a band of noise over flat green, because the parameter
201+/// sets promised coding tools the driver was not using. Nothing that counts
202+/// frames sees that. Three things do, and all three are asserted here --
203+/// ffmpeg's decoder saying *nothing at all* on its error channel, the coded
204+/// size still cropping back to 1920x1080, and the picture being the source's
205+/// rather than a fill (SSIM against the very frames that went in; a desynced
206+/// stream scores about 0.2, this one about 0.98).
207+///
208+/// `testsrc2` is what makes it bite: 1080p of it splits transform trees deep
209+/// enough and pushes the rate controller hard enough to need the syntax the
210+/// parameter sets have to declare. The two-frame fixtures above are flat and
211+/// pass either way, which is exactly how the defect got through.
212+#[test]
213+#[ignore = "needs libengine_hw.so, VE_HW_HEVC=1 and a driver with an HEVC encode entrypoint"]
214+fn a_1080p_hardware_export_leaves_a_decoder_with_nothing_to_say() {
215+ let Some(source) = fixture_1080p() else {
216+ eprintln!("no ffmpeg: skipping the 1080p hardware twin");
217+ return;
218+ };
219+ let session = PlaybackSession::open(&source).expect("open the 1080p fixture");
220+ let settings = ExportSettings {
221+ format: Format::Hevc,
222+ ..Default::default()
223+ };
224+ let planned = engine::export::planned_video(session.meta(), &settings);
225+ assert!(
226+ planned.is_some_and(|seat| seat.contains("HW encode")),
227+ "this twin is the GPU's, and this box named {planned:?} (VE_HW_HEVC=1?)"
228+ );
229+
230+ let out = out_path("1080p_hw", "mkv");
231+ export(&session, &out, Format::Hevc);
232+
233+ let probed = probe(&out);
234+ assert_eq!(
235+ probed.as_deref(),
236+ Some("hevc,1920,1080"),
237+ "ffprobe reads the cropped size out of the bitstream"
238+ );
239+
240+ let decoded = Command::new("ffmpeg")
241+ .args(["-v", "error", "-i"])
242+ .arg(&out)
243+ .args(["-f", "null", "-"])
244+ .output()
245+ .expect("run ffmpeg");
246+ let complaints = String::from_utf8_lossy(&decoded.stderr);
247+ assert!(
248+ decoded.status.success() && complaints.is_empty(),
249+ "a decoder complained about the GPU's stream: {complaints}"
250+ );
251+
252+ let ssim = ssim(&source, &out).expect("ffmpeg reports an SSIM");
253+ assert!(
254+ ssim >= 0.90,
255+ "the GPU coded the source's picture, not a fill (SSIM {ssim:.4})"
256+ );
257+ std::fs::remove_file(&out).unwrap();
258+ let _ = std::fs::remove_file(&source);
259+}
260+
198 /// An audio-only timeline has no picture to code, and an HEVC export says so by261 /// An audio-only timeline has no picture to code, and an HEVC export says so by
199 /// name exactly as the mp4 and AV1 ones do -- and writes nothing.262 /// name exactly as the mp4 and AV1 ones do -- and writes nothing.
200 #[test]263 #[test]
@@ -270,6 +333,27 @@ fn probe(path: &Path) -> Option<String> {
270 Some(String::from_utf8_lossy(&out.stdout).trim().to_string())333 Some(String::from_utf8_lossy(&out.stdout).trim().to_string())
271 }334 }
272 335
336+/// Mean SSIM of `out` against `source`, over the frames the two have in common,
337+/// as ffmpeg's own filter measures it. `None` where ffmpeg is not installed or
338+/// said nothing -- the caller decides whether that is a skip or a failure.
339+fn ssim(source: &Path, out: &Path) -> Option<f64> {
340+ let measured = Command::new("ffmpeg")
341+ .args(["-v", "info", "-i"])
342+ .arg(source)
343+ .arg("-i")
344+ .arg(out)
345+ .args(["-filter_complex", "ssim", "-f", "null", "-"])
346+ .output()
347+ .ok()?;
348+ String::from_utf8_lossy(&measured.stderr)
349+ .rsplit("All:")
350+ .next()?
351+ .split_whitespace()
352+ .next()?
353+ .parse()
354+ .ok()
355+}
356+
273 /// A two-second 1920x1080 H.264 fixture in the temp directory -- the assets are357 /// A two-second 1920x1080 H.264 fixture in the temp directory -- the assets are
274 /// all 720p, which is a multiple of 16 in both directions and would leave the358 /// all 720p, which is a multiple of 16 in both directions and would leave the
275 /// crop path untested. `None` where ffmpeg is not installed.359 /// crop path untested. `None` where ffmpeg is not installed.