| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | #[path = "support/hwchild.rs"] |
| 16 | mod hwchild; |
| 17 | |
| 18 | use std::path::{Path, PathBuf}; |
| 19 | use std::time::Instant; |
| 20 | |
| 21 | use engine::DecodeSession; |
| 22 | use engine::colorspace::{ColorDescription, Matrix}; |
| 23 | use engine::convert::i420_to_bgra; |
| 24 | use engine::demux::{Codec, Demuxer}; |
| 25 | use engine::mux::{self, Mp4Muxer, VideoParams}; |
| 26 | use engine::scratch::Scratch; |
| 27 | use engine::hw::HwSession; |
| 28 | use engine::tonemap::{ToneMapper, Transfer}; |
| 29 | |
| 30 | fn asset(name: &str) -> PathBuf { |
| 31 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 32 | .join("../../assets") |
| 33 | .join(name) |
| 34 | } |
| 35 | |
| 36 | |
| 37 | |
| 38 | fn color_of(path: &Path) -> ColorDescription { |
| 39 | Demuxer::open(path).expect("open for colour").0.color |
| 40 | } |
| 41 | |
| 42 | fn open_hw(path: &Path) -> HwSession { |
| 43 | HwSession::open(path).expect("no hardware decode plugin/driver available") |
| 44 | } |
| 45 | |
| 46 | |
| 47 | fn decode_all_hw(name: &str) -> (usize, Vec<u8>) { |
| 48 | let path = asset(name); |
| 49 | let color = color_of(&path); |
| 50 | let mut hw = open_hw(&path); |
| 51 | let meta = hw.meta().expect("meta"); |
| 52 | assert_eq!( |
| 53 | (meta.width, meta.height), |
| 54 | (1280, 720), |
| 55 | "{name} container dims" |
| 56 | ); |
| 57 | |
| 58 | let mut count = 0usize; |
| 59 | let mut frame_30 = Vec::new(); |
| 60 | let start = Instant::now(); |
| 61 | while let Some((y, u, v, w, h)) = hw.next_frame().expect("hardware decode") { |
| 62 | assert_eq!((w, h), (1280, 720), "{name} frame {count} dims"); |
| 63 | if count == 30 { |
| 64 | frame_30 = i420_to_bgra(&color, y, u, v, w as usize, h as usize); |
| 65 | } |
| 66 | count += 1; |
| 67 | } |
| 68 | eprintln!( |
| 69 | "{name}: {count} hardware frames in {:?} ({:?}/frame)", |
| 70 | start.elapsed(), |
| 71 | start.elapsed() / count.max(1) as u32 |
| 72 | ); |
| 73 | (count, frame_30) |
| 74 | } |
| 75 | |
| 76 | |
| 77 | #[test] |
| 78 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 79 | fn rejects_unopenable_files() { |
| 80 | hwchild::require(); |
| 81 | assert!(HwSession::open(Path::new("/definitely/not/here.mp4")).is_none()); |
| 82 | assert!( |
| 83 | HwSession::open(Path::new("/etc/hostname")).is_none(), |
| 84 | "not an mp4" |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | #[test] |
| 95 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 96 | fn hardware_decodes_4k_wavefront_slices() { |
| 97 | hwchild::require(); |
| 98 | let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/test_hevc_4k_wpp.mkv"); |
| 99 | let mut hw = open_hw(&path); |
| 100 | let mut count = 0usize; |
| 101 | while let Some((_, _, _, w, h)) = hw.next_frame().expect("hardware decode") { |
| 102 | assert_eq!((w, h), (3840, 2160), "frame {count} dims"); |
| 103 | count += 1; |
| 104 | } |
| 105 | assert!(count > 0, "4K wavefront stream decoded no pictures"); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | #[test] |
| 113 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 114 | fn an_undecodable_hevc_stream_is_refused_by_name() { |
| 115 | hwchild::require(); |
| 116 | let good = std::fs::read( |
| 117 | PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/test_hevc_4k_wpp.mkv"), |
| 118 | ) |
| 119 | .expect("read the 4K fixture"); |
| 120 | |
| 121 | |
| 122 | |
| 123 | let mut broken = good.clone(); |
| 124 | let mut patched = 0; |
| 125 | for i in 0..broken.len() - 2 { |
| 126 | if broken[i] == 0x42 && broken[i + 1] == 0x01 { |
| 127 | broken[i + 2] |= 0x0e; |
| 128 | patched += 1; |
| 129 | } |
| 130 | } |
| 131 | assert!(patched > 0, "no SPS found in the fixture"); |
| 132 | let path = Scratch::file("undecodable_hevc", "mkv"); |
| 133 | std::fs::write(&path, &broken).expect("write the broken copy"); |
| 134 | |
| 135 | let refused = DecodeSession::open(&path) |
| 136 | .expect_err("a stream with no decodable picture must not open") |
| 137 | .to_string(); |
| 138 | assert_eq!(refused, Codec::Hevc.undecodable()); |
| 139 | } |
| 140 | |
| 141 | #[test] |
| 142 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 143 | fn hardware_decodes_baseline() { |
| 144 | hwchild::require(); |
| 145 | let (count, _) = decode_all_hw("test_baseline.mp4"); |
| 146 | assert_eq!(count, 150); |
| 147 | } |
| 148 | |
| 149 | #[test] |
| 150 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 151 | fn hardware_decodes_high_profile() { |
| 152 | hwchild::require(); |
| 153 | |
| 154 | |
| 155 | let (count, _) = decode_all_hw("test_high.mp4"); |
| 156 | assert_eq!(count, 150); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | |
| 161 | #[test] |
| 162 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 163 | fn seek_matches_linear() { |
| 164 | hwchild::require(); |
| 165 | const TARGET: u32 = 60; |
| 166 | let path = asset("test_baseline.mp4"); |
| 167 | |
| 168 | engine::envcfg::set("VE_SW", "1"); |
| 169 | let (_, rx) = DecodeSession::open(&path).expect("software open"); |
| 170 | let linear = rx |
| 171 | .into_iter() |
| 172 | .find(|f| f.index == TARGET) |
| 173 | .expect("software frame 60") |
| 174 | .bgra; |
| 175 | |
| 176 | let start = Instant::now(); |
| 177 | let (_, rx, _cancel) = DecodeSession::open_at(&path, TARGET).expect("software open_at"); |
| 178 | let seeked = rx.into_iter().next().expect("no frame after software seek"); |
| 179 | eprintln!("software seek to {TARGET} took {:?}", start.elapsed()); |
| 180 | assert_eq!(seeked.index, TARGET, "first frame after seek is the target"); |
| 181 | assert_eq!(seeked.bgra, linear, "software seek != software linear"); |
| 182 | |
| 183 | let start = Instant::now(); |
| 184 | let mut hw = HwSession::open_at(&path, TARGET).expect("no plugin/driver available"); |
| 185 | let (y, u, v, w, h) = hw |
| 186 | .next_frame() |
| 187 | .expect("hardware decode") |
| 188 | .expect("no frame after hardware seek"); |
| 189 | eprintln!("hardware seek to {TARGET} took {:?}", start.elapsed()); |
| 190 | assert_eq!( |
| 191 | i420_to_bgra(&color_of(&path), y, u, v, w as usize, h as usize), |
| 192 | linear, |
| 193 | "hardware seek != software linear" |
| 194 | ); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | #[test] |
| 211 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 212 | fn seek_matches_linear_every_container() { |
| 213 | hwchild::require(); |
| 214 | engine::envcfg::unset("VE_SW"); |
| 215 | for name in [ |
| 216 | "test_baseline.mp4", |
| 217 | "test_high.mp4", |
| 218 | "test_hevc.mp4", |
| 219 | "test_hevc.mkv", |
| 220 | "test_hevc10.mkv", |
| 221 | "test_h264.mkv", |
| 222 | "test_av1.mkv", |
| 223 | ] { |
| 224 | let path = asset(name); |
| 225 | let (meta, rx) = DecodeSession::open(&path).unwrap_or_else(|e| panic!("{name}: open: {e}")); |
| 226 | |
| 227 | |
| 228 | |
| 229 | let mut targets = vec![0, 1, 29, 30, 31, 45, meta.frame_count - 1]; |
| 230 | targets.retain(|&t| t < meta.frame_count); |
| 231 | targets.sort_unstable(); |
| 232 | targets.dedup(); |
| 233 | let linear: Vec<(u32, Vec<u8>)> = rx |
| 234 | .into_iter() |
| 235 | .filter(|f| targets.contains(&f.index)) |
| 236 | .map(|f| (f.index, f.bgra)) |
| 237 | .collect(); |
| 238 | assert_eq!( |
| 239 | linear.iter().map(|(i, _)| *i).collect::<Vec<_>>(), |
| 240 | targets, |
| 241 | "{name}: linear decode never delivered every target" |
| 242 | ); |
| 243 | for (target, want) in linear { |
| 244 | let (_, rx, _cancel) = DecodeSession::open_at(&path, target) |
| 245 | .unwrap_or_else(|e| panic!("{name}: open_at({target}): {e}")); |
| 246 | let seeked = rx |
| 247 | .into_iter() |
| 248 | .next() |
| 249 | .unwrap_or_else(|| panic!("{name}: no frame after seek to {target}")); |
| 250 | assert_eq!( |
| 251 | seeked.index, target, |
| 252 | "{name}: first frame after seek is not the target" |
| 253 | ); |
| 254 | assert!( |
| 255 | seeked.bgra == want, |
| 256 | "{name}: seek to {target} handed back a different picture than a linear decode of {target}" |
| 257 | ); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | |
| 263 | |
| 264 | fn range_indices(path: &Path, start: u32, end: u32) -> Vec<u32> { |
| 265 | let (_, rx, _cancel) = DecodeSession::open_range(path, start, end).expect("open_range"); |
| 266 | let mut got = Vec::new(); |
| 267 | while let Ok(frame) = rx.recv() { |
| 268 | got.push(frame.index); |
| 269 | } |
| 270 | got |
| 271 | } |
| 272 | |
| 273 | |
| 274 | |
| 275 | #[test] |
| 276 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 277 | fn range_stops_at_end() { |
| 278 | hwchild::require(); |
| 279 | const START: u32 = 30; |
| 280 | const END: u32 = 60; |
| 281 | let path = asset("test_baseline.mp4"); |
| 282 | let want: Vec<u32> = (START..END).collect(); |
| 283 | |
| 284 | engine::envcfg::unset("VE_SW"); |
| 285 | assert_eq!(range_indices(&path, START, END), want, "hardware range"); |
| 286 | |
| 287 | engine::envcfg::set("VE_SW", "1"); |
| 288 | assert_eq!(range_indices(&path, START, END), want, "software range"); |
| 289 | |
| 290 | |
| 291 | assert!(range_indices(&path, 30, 30).is_empty(), "empty range"); |
| 292 | assert!(range_indices(&path, 60, 30).is_empty(), "inverted range"); |
| 293 | |
| 294 | assert_eq!(range_indices(&path, 148, 999).len(), 2, "clamped range"); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | #[test] |
| 306 | #[ignore = "needs libengine_hw.so, a VA-API driver and the film"] |
| 307 | fn the_hdr_film_renders_tone_mapped() { |
| 308 | hwchild::require(); |
| 309 | |
| 310 | const TARGET: u32 = 3000; |
| 311 | let Some(path) = engine::real_library::film("hevc_4k_hdr") else { |
| 312 | return; |
| 313 | }; |
| 314 | let path = path.as_path(); |
| 315 | engine::envcfg::unset("VE_SW"); |
| 316 | |
| 317 | |
| 318 | |
| 319 | let mut hw = HwSession::open_at(path, TARGET).expect("no plugin/driver available"); |
| 320 | let (y, u, v, w, h) = hw |
| 321 | .next_frame() |
| 322 | .expect("hardware decode") |
| 323 | .expect("no frame at the seek"); |
| 324 | let (w, h) = (w as usize, h as usize); |
| 325 | let (y, u, v) = (y.to_vec(), u.to_vec(), v.to_vec()); |
| 326 | let untouched = i420_to_bgra(&color_of(path), &y, &u, &v, w, h); |
| 327 | |
| 328 | |
| 329 | let (_, rx, _cancel) = DecodeSession::open_at(path, TARGET).expect("open the film"); |
| 330 | let shown = rx.recv().expect("a frame off the funnel").bgra; |
| 331 | assert_eq!(shown.len(), untouched.len(), "frame size"); |
| 332 | |
| 333 | |
| 334 | let spread = |bgra: &[u8]| -> f64 { |
| 335 | let total: u64 = bgra |
| 336 | .as_chunks::<4>().0.iter() |
| 337 | .map(|px| u64::from(px[..3].iter().max().unwrap() - px[..3].iter().min().unwrap())) |
| 338 | .sum(); |
| 339 | total as f64 / (bgra.len() / 4) as f64 |
| 340 | }; |
| 341 | |
| 342 | let luma = |bgra: &[u8]| -> f64 { |
| 343 | let total: f64 = bgra |
| 344 | .as_chunks::<4>().0.iter() |
| 345 | .map(|px| { |
| 346 | 0.2126 * f64::from(px[2]) + 0.7152 * f64::from(px[1]) + 0.0722 * f64::from(px[0]) |
| 347 | }) |
| 348 | .sum(); |
| 349 | 16.0 + 219.0 * (total / (bgra.len() / 4) as f64) / 255.0 |
| 350 | }; |
| 351 | let (was, now) = (spread(&untouched), spread(&shown)); |
| 352 | eprintln!( |
| 353 | "frame {TARGET}: saturation {was:.1} -> {now:.1}, mean luma {:.1} -> {:.1}", |
| 354 | luma(&untouched), |
| 355 | luma(&shown) |
| 356 | ); |
| 357 | assert!( |
| 358 | now > was, |
| 359 | "the tone-mapped frame is no more colourful: {now}" |
| 360 | ); |
| 361 | let mean = luma(&shown); |
| 362 | assert!( |
| 363 | (24.0..=200.0).contains(&mean), |
| 364 | "the tone-mapped frame sits at one end of the scale: mean luma {mean}" |
| 365 | ); |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | let mapper = ToneMapper::new(Transfer::Pq, engine::tonemap::Preset::default(), None); |
| 371 | let sdr = ColorDescription { |
| 372 | matrix: Matrix::Bt709, |
| 373 | transfer: engine::colorspace::Transfer::Sdr, |
| 374 | full_range: false, |
| 375 | }; |
| 376 | let mut best = f64::MAX; |
| 377 | for _ in 0..5 { |
| 378 | let (mut my, mut mu, mut mv) = (y.clone(), u.clone(), v.clone()); |
| 379 | let t = Instant::now(); |
| 380 | mapper.map(&mut my, &mut mu, &mut mv, w, h); |
| 381 | let _ = i420_to_bgra(&sdr, &my, &mu, &mv, w, h); |
| 382 | best = best.min(t.elapsed().as_secs_f64() * 1000.0); |
| 383 | } |
| 384 | eprintln!("{w}x{h} tone map + convert: {best:.1} ms/frame"); |
| 385 | assert!(best <= 39.0, "{best:.1} ms/frame over the 39 ms budget"); |
| 386 | } |
| 387 | |
| 388 | |
| 389 | |
| 390 | #[test] |
| 391 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 392 | fn hardware_matches_software_on_frame_30() { |
| 393 | hwchild::require(); |
| 394 | let (_, hw) = decode_all_hw("test_baseline.mp4"); |
| 395 | |
| 396 | engine::envcfg::set("VE_SW", "1"); |
| 397 | |
| 398 | let start = Instant::now(); |
| 399 | let (_, rx) = DecodeSession::open(asset("test_baseline.mp4")).expect("software open"); |
| 400 | let sw = rx |
| 401 | .into_iter() |
| 402 | .find(|f| f.index == 30) |
| 403 | .expect("software frame 30") |
| 404 | .bgra; |
| 405 | eprintln!("software reached frame 30 in {:?}", start.elapsed()); |
| 406 | |
| 407 | assert_eq!(hw.len(), sw.len(), "frame size"); |
| 408 | let diff = hw.iter().zip(&sw).filter(|(a, b)| a != b).count(); |
| 409 | eprintln!("frame 30 differing bytes: {diff} / {}", hw.len()); |
| 410 | assert_eq!(diff, 0, "hardware and software decode disagree"); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | #[test] |
| 419 | #[ignore = "needs libengine_hw.so and a VA-API driver with AV1 decode"] |
| 420 | fn av1_hardware_matches_software_on_every_frame() { |
| 421 | hwchild::require(); |
| 422 | const NAME: &str = "test_av1.mkv"; |
| 423 | let (hw_count, hw_frame_30) = decode_all_hw(NAME); |
| 424 | |
| 425 | engine::envcfg::set("VE_SW", "1"); |
| 426 | let path = asset(NAME); |
| 427 | let start = Instant::now(); |
| 428 | let (meta, rx) = DecodeSession::open(&path).expect("software open"); |
| 429 | let mut sw_count = 0usize; |
| 430 | let mut sw_frame_30 = Vec::new(); |
| 431 | for frame in rx { |
| 432 | if frame.index == 30 { |
| 433 | sw_frame_30 = frame.bgra; |
| 434 | } |
| 435 | sw_count += 1; |
| 436 | } |
| 437 | let sw_elapsed = start.elapsed(); |
| 438 | engine::envcfg::unset("VE_SW"); |
| 439 | eprintln!("{NAME}: hardware {hw_count} frames, software {sw_count} frames in {sw_elapsed:?}"); |
| 440 | assert_eq!(sw_count, hw_count, "frame count"); |
| 441 | assert_eq!(sw_count, usize::try_from(meta.frame_count).expect("count")); |
| 442 | assert_eq!(hw_frame_30.len(), sw_frame_30.len(), "frame size"); |
| 443 | let diff = hw_frame_30.iter().zip(&sw_frame_30).filter(|(a, b)| a != b).count(); |
| 444 | eprintln!("frame 30 differing bytes: {diff} / {}", sw_frame_30.len()); |
| 445 | assert_eq!(diff, 0, "hardware and software AV1 decode disagree"); |
| 446 | } |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | #[test] |
| 452 | #[ignore = "needs libengine_hw.so and a VA-API driver with 10-bit AV1 decode"] |
| 453 | fn av1_ten_bit_hardware_matches_software_on_every_frame() { |
| 454 | hwchild::require(); |
| 455 | const NAME: &str = "test_av1_10.mkv"; |
| 456 | let (hw_count, hw_frame_30) = decode_all_hw(NAME); |
| 457 | engine::envcfg::set("VE_SW", "1"); |
| 458 | let path = asset(NAME); |
| 459 | let start = Instant::now(); |
| 460 | let (_, rx) = DecodeSession::open(&path).expect("software open"); |
| 461 | let mut sw_count = 0usize; |
| 462 | let mut sw_frame_30 = Vec::new(); |
| 463 | for frame in rx { |
| 464 | if frame.index == 30 { |
| 465 | sw_frame_30 = frame.bgra; |
| 466 | } |
| 467 | sw_count += 1; |
| 468 | } |
| 469 | let sw_elapsed = start.elapsed(); |
| 470 | engine::envcfg::unset("VE_SW"); |
| 471 | eprintln!("{NAME}: hardware {hw_count} frames, software {sw_count} frames in {sw_elapsed:?}"); |
| 472 | assert_eq!(sw_count, hw_count, "frame count"); |
| 473 | assert_eq!(hw_frame_30.len(), sw_frame_30.len(), "frame size"); |
| 474 | let diff = hw_frame_30.iter().zip(&sw_frame_30).filter(|(a, b)| a != b).count(); |
| 475 | eprintln!("frame 30 differing bytes: {diff} / {}", sw_frame_30.len()); |
| 476 | assert_eq!(diff, 0, "hardware and software 10-bit AV1 decode disagree"); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | fn nals(annex_b: &[u8]) -> Vec<&[u8]> { |
| 481 | let mut out = Vec::new(); |
| 482 | let mut start = None; |
| 483 | let mut i = 0; |
| 484 | while i + 2 < annex_b.len() { |
| 485 | if annex_b[i] == 0 && annex_b[i + 1] == 0 && annex_b[i + 2] == 1 { |
| 486 | if let Some(s) = start { |
| 487 | out.push(&annex_b[s..i]); |
| 488 | } |
| 489 | i += 3; |
| 490 | start = Some(i); |
| 491 | } else { |
| 492 | i += 1; |
| 493 | } |
| 494 | } |
| 495 | if let Some(s) = start { |
| 496 | out.push(&annex_b[s..]); |
| 497 | } |
| 498 | out |
| 499 | } |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | fn sample_with_trailing_zeros(annex_b: &[u8], zeros: usize) -> (Vec<u8>, bool) { |
| 506 | let mut coded: Vec<&[u8]> = Vec::new(); |
| 507 | let mut key = false; |
| 508 | for nal in nals(annex_b) { |
| 509 | let end = nal.iter().rposition(|&b| b != 0).map_or(0, |p| p + 1); |
| 510 | let nal = &nal[..end]; |
| 511 | if nal.is_empty() { |
| 512 | continue; |
| 513 | } |
| 514 | match nal[0] & 0x1f { |
| 515 | 6..=9 => continue, |
| 516 | 5 => key = true, |
| 517 | _ => {} |
| 518 | } |
| 519 | coded.push(nal); |
| 520 | } |
| 521 | let mut sample = Vec::new(); |
| 522 | let last = coded.len().saturating_sub(1); |
| 523 | for (i, nal) in coded.iter().enumerate() { |
| 524 | let len = nal.len() + if i == last { zeros } else { 0 }; |
| 525 | sample.extend_from_slice(&(len as u32).to_be_bytes()); |
| 526 | sample.extend_from_slice(nal); |
| 527 | if i == last { |
| 528 | sample.extend(std::iter::repeat_n(0u8, zeros)); |
| 529 | } |
| 530 | } |
| 531 | (sample, key) |
| 532 | } |
| 533 | |
| 534 | |
| 535 | |
| 536 | fn write_trailing_zero_fixture(src: &Path, out: &Path, frames: usize) { |
| 537 | let (meta, mut demuxer) = Demuxer::open(src).expect("open fixture source"); |
| 538 | let first = demuxer.next_access_unit().expect("read").expect("au"); |
| 539 | let (sps, pps) = mux::parameter_sets(&first).expect("parameter sets in the first au"); |
| 540 | let mut muxer = Mp4Muxer::create( |
| 541 | out, |
| 542 | &VideoParams { |
| 543 | width: meta.width, |
| 544 | height: meta.height, |
| 545 | frame_rate: meta.frame_rate, |
| 546 | sps, |
| 547 | pps, |
| 548 | }, |
| 549 | None, |
| 550 | ) |
| 551 | .expect("create fixture"); |
| 552 | let (sample, key) = sample_with_trailing_zeros(&first, 4); |
| 553 | muxer.write_coded_sample(&sample, key).expect("first sample"); |
| 554 | for _ in 1..frames { |
| 555 | let Some(au) = demuxer.next_access_unit().expect("read") else { |
| 556 | break; |
| 557 | }; |
| 558 | let (sample, key) = sample_with_trailing_zeros(&au, 4); |
| 559 | muxer.write_coded_sample(&sample, key).expect("sample"); |
| 560 | } |
| 561 | muxer.finish().expect("finish fixture"); |
| 562 | } |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | #[test] |
| 571 | #[ignore = "needs libengine_hw.so and a VA-API driver"] |
| 572 | fn hardware_decodes_samples_with_trailing_zero_words() { |
| 573 | hwchild::require(); |
| 574 | let out = Scratch::file("ve_hw_trailing_zeros", "mp4"); |
| 575 | write_trailing_zero_fixture(&asset("test_baseline.mp4"), &out, 30); |
| 576 | let mut hw = open_hw(&out); |
| 577 | let mut count = 0usize; |
| 578 | while let Some((_, _, _, w, h)) = hw |
| 579 | .next_frame() |
| 580 | .expect("hardware decode of trailing-zero samples") |
| 581 | { |
| 582 | assert_eq!((w, h), (1280, 720), "frame {count} dims"); |
| 583 | count += 1; |
| 584 | } |
| 585 | assert_eq!(count, 30, "every picture decoded"); |
| 586 | } |