forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

hw_fallback.rs75 lines, 2.7 KiBHistoryRawDownload
1//! A hardware decode error part-way through a span hands the rest of the span
2//! to the software seat, at the picture it failed on.
3//!
4//! The error is injected (`engine::hw::inject_failure_after`) because a real
5//! one needs a hung GPU ring. The test compares the pictures delivered after
6//! the failure with a pure software decode of the same range (the hook set to
7//! 0 makes the hardware refuse its first picture, so the whole span runs in
8//! software), and checks the stream is complete: before the fallback existed it
9//! stopped at the failure. One test, because the hook is process-wide.
10//!
11//! Needs a built `libengine_hw.so` and a VA-API decoder; without them it skips.
12
13use crate::hwchild;
14
15use std::path::PathBuf;
16
17use engine::decode::DecodeSession;
18use engine::hw::{HwSession, inject_failure_after};
19
20fn asset(name: &str) -> PathBuf {
21 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
22 .join("../../assets")
23 .join(name)
24}
25
26fn span(path: &PathBuf, start: u32, end: u32) -> Vec<(u32, Vec<u8>)> {
27 let (_, rx, _) = DecodeSession::open_range(path, start, end).expect("open");
28 rx.iter().map(|f| (f.index, f.bgra)).collect()
29}
30
31#[test]
32fn a_hardware_error_mid_span_continues_in_software_with_the_same_frames() {
33 let _seat = crate::seat::hardware();
34 hwchild::require();
35 for (name, start, end, fail_after) in [
36 ("test_25fps.mp4", 0, 50, 17),
37 ("test_25fps.mp4", 10, 40, 5),
38 ("test_25fps.mp4", 0, 50, 49),
39 ("test_h264.mkv", 0, u32::MAX, 20),
40 ("test_hevc.mp4", 0, u32::MAX, 12),
41 ] {
42 let path = asset(name);
43 inject_failure_after(None);
44 if HwSession::open(&path).is_none() {
45 eprintln!("skipped: no hardware decode for {name}");
46 return;
47 }
48 // Reference: software for the whole span.
49 inject_failure_after(Some(0));
50 let software = span(&path, start, end);
51 // Hardware that dies after `fail_after` pictures.
52 inject_failure_after(Some(fail_after));
53 let fell_back = span(&path, start, end);
54 inject_failure_after(None);
55
56 assert!(!software.is_empty(), "{name}: reference decoded nothing");
57 assert_eq!(
58 fell_back.len(),
59 software.len(),
60 "{name}: the stream ended at the failure instead of continuing"
61 );
62 let first = software[0].0;
63 let at = first + fail_after as u32;
64 for (got, want) in fell_back.iter().zip(&software) {
65 assert_eq!(got.0, want.0, "{name}: frame order");
66 if got.0 >= at {
67 assert!(
68 got.1 == want.1,
69 "{name}: frame {} differs from a software decode",
70 got.0
71 );
72 }
73 }
74 }
75}