#[cfg(streaming_api_landed)]
mod gated_tests {
use container::demux::{self, DemuxResult};
use std::path::{Path, PathBuf};
fn test_media_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.parent()
.unwrap()
.join("test_media")
}
fn read_test_file(name: &str) -> Option<Vec<u8>> {
std::fs::read(test_media_dir().join(name)).ok()
}
fn drain_streaming(input: &[u8]) -> anyhow::Result<(String, Vec<Vec<u8>>)> {
let mut sd = demux::demux_streaming(input)?;
let header = sd.header().clone();
let mut out = Vec::new();
while let Some(s) = sd.next_video_sample()? {
out.push(s.data);
}
Ok((header.codec, out))
}
fn assert_byte_equal(legacy: &DemuxResult, streamed: &(String, Vec<Vec<u8>>), label: &str) {
assert_eq!(
legacy.codec, streamed.0,
"{label}: codec mismatch (legacy={}, streaming={})",
legacy.codec, streamed.0
);
assert_eq!(
legacy.samples.len(),
streamed.1.len(),
"{label}: sample count mismatch (legacy={}, streaming={})",
legacy.samples.len(),
streamed.1.len(),
);
for (i, (a, b)) in legacy.samples.iter().zip(streamed.1.iter()).enumerate() {
assert_eq!(
a.len(),
b.len(),
"{label}: sample {i} length differs (legacy={}, streaming={})",
a.len(),
b.len(),
);
assert_eq!(
a,
b,
"{label}: sample {i} bytes differ (first byte legacy=0x{:02x} streaming=0x{:02x})",
a.first().copied().unwrap_or(0),
b.first().copied().unwrap_or(0),
);
}
}
#[test]
fn streaming_mp4_h264_matches_legacy() {
let Some(data) = read_test_file("bigbuck_bunny_8bit_750kbps_720p_60.0fps_h264.mp4") else {
eprintln!("SKIP: BBB H.264 MP4 not in test_media");
return;
};
let legacy = demux::demux(&data).expect("legacy demux mp4 h264");
let streamed = drain_streaming(&data).expect("streaming demux mp4 h264");
assert_byte_equal(&legacy, &streamed, "mp4-h264");
}
#[test]
fn streaming_mp4_hevc_matches_legacy() {
let Some(data) = read_test_file("bigbuck_bunny_8bit_750kbps_720p_60.0fps_hevc.mp4") else {
eprintln!("SKIP: BBB HEVC MP4 not in test_media");
return;
};
let legacy = demux::demux(&data).expect("legacy demux mp4 hevc");
let streamed = drain_streaming(&data).expect("streaming demux mp4 hevc");
assert_byte_equal(&legacy, &streamed, "mp4-hevc");
}
#[test]
fn streaming_mp4_av1_matches_legacy() {
let Some(data) = read_test_file("jellyfin_av1_main_1080p_24fps.mp4") else {
eprintln!("SKIP: Jellyfin AV1 MP4 not in test_media");
return;
};
let legacy = demux::demux(&data).expect("legacy demux mp4 av1");
let streamed = drain_streaming(&data).expect("streaming demux mp4 av1");
assert_byte_equal(&legacy, &streamed, "mp4-av1");
}
#[test]
fn streaming_mkv_vp9_matches_legacy() {
let Some(data) = read_test_file("bigbuck_bunny_8bit_750kbps_720p_60.0fps_vp9.mkv") else {
eprintln!("SKIP: BBB VP9 MKV not in test_media");
return;
};
let legacy = demux::demux(&data).expect("legacy demux mkv vp9");
let streamed = drain_streaming(&data).expect("streaming demux mkv vp9");
assert_byte_equal(&legacy, &streamed, "mkv-vp9");
}
#[test]
fn streaming_mkv_h264_matches_legacy() {
let candidates = [
"bigbuck_bunny_8bit_750kbps_720p_60.0fps_h264.mkv",
"jellyfin_h264_high_l40_1080p_24fps.mkv",
"h264_main_720p.mkv",
];
let mut ran = false;
for name in candidates {
let Some(data) = read_test_file(name) else {
continue;
};
let legacy = demux::demux(&data).expect("legacy demux mkv h264");
let streamed = drain_streaming(&data).expect("streaming demux mkv h264");
assert_byte_equal(&legacy, &streamed, &format!("mkv-h264-{name}"));
ran = true;
break;
}
if !ran {
eprintln!(
"SKIP: no MKV-h264 sample in test_media — tracker drift \
coverage gap on the matroska AVC code path."
);
}
}
#[test]
fn streaming_mkv_hevc_matches_legacy() {
let candidates = [
"bigbuck_bunny_8bit_750kbps_720p_60.0fps_hevc.mkv",
"jellyfin_hevc_main_1080p_24fps.mkv",
"hevc_main_720p.mkv",
];
let mut ran = false;
for name in candidates {
let Some(data) = read_test_file(name) else {
continue;
};
let legacy = demux::demux(&data).expect("legacy demux mkv hevc");
let streamed = drain_streaming(&data).expect("streaming demux mkv hevc");
assert_byte_equal(&legacy, &streamed, &format!("mkv-hevc-{name}"));
ran = true;
break;
}
if !ran {
eprintln!(
"SKIP: no MKV-hevc sample in test_media — tracker drift \
coverage gap on the matroska HEVC code path."
);
}
}
#[test]
fn streaming_webm_av1_matches_legacy() {
let Some(data) = read_test_file("webmfiles_bbb_av1_main_webm.webm") else {
eprintln!("SKIP: BBB AV1 WebM not in test_media");
return;
};
let legacy = demux::demux(&data).expect("legacy demux webm av1");
let streamed = drain_streaming(&data).expect("streaming demux webm av1");
assert_byte_equal(&legacy, &streamed, "webm-av1");
}
#[test]
fn streaming_ts_matches_legacy() {
let candidates = [
"ts_h264_main_720p.ts",
"ts_hevc_main_720p.ts",
"ts_mpeg2_720p.ts",
"bigbuck_bunny_h264.ts",
];
let mut ran = false;
for name in candidates {
let Some(data) = read_test_file(name) else {
continue;
};
let legacy = demux::demux(&data).expect("legacy demux ts");
let streamed = drain_streaming(&data).expect("streaming demux ts");
assert_byte_equal(&legacy, &streamed, &format!("ts-{name}"));
ran = true;
}
if !ran {
eprintln!("SKIP: no MPEG-TS sample in test_media");
}
}
#[test]
fn streaming_avi_matches_legacy() {
let candidates = [
"xvid_avi_720p.avi",
"divx_avi_720p.avi",
"bigbuck_bunny_xvid.avi",
];
let mut ran = false;
for name in candidates {
let Some(data) = read_test_file(name) else {
continue;
};
let legacy = demux::demux(&data).expect("legacy demux avi");
let streamed = drain_streaming(&data).expect("streaming demux avi");
assert_byte_equal(&legacy, &streamed, &format!("avi-{name}"));
ran = true;
}
if !ran {
eprintln!("SKIP: no AVI sample in test_media");
}
}
#[test]
fn streaming_eof_is_idempotent_ok_none() {
let Some(data) = read_test_file("bigbuck_bunny_8bit_750kbps_720p_60.0fps_h264.mp4") else {
eprintln!("SKIP: BBB H.264 MP4 not in test_media");
return;
};
let mut sd = demux::demux_streaming(&data).expect("streaming demux");
let mut count = 0;
while sd.next_video_sample().expect("next ok").is_some() {
count += 1;
}
assert!(count > 0, "must yield at least one sample");
for i in 0..3 {
assert!(
sd.next_video_sample()
.expect("post-EOF must be Ok")
.is_none(),
"post-EOF call {i} returned Some — streaming demuxer must be idempotent past EOF",
);
}
}
#[test]
fn streaming_truncated_input_propagates_error() {
let Some(full) = read_test_file("bigbuck_bunny_8bit_750kbps_720p_60.0fps_h264.mp4") else {
eprintln!("SKIP: BBB H.264 MP4 not in test_media");
return;
};
let truncated = &full[..64.min(full.len())];
let result = demux::demux_streaming(truncated);
match result {
Err(_) => { }
Ok(mut sd) => {
let first = sd.next_video_sample();
assert!(
first.is_err() || matches!(first, Ok(None)),
"truncated input must error or yield None at first pull, not Some"
);
}
}
}
#[test]
fn streaming_header_matches_legacy_info() {
let candidates = [
"bigbuck_bunny_8bit_750kbps_720p_60.0fps_h264.mp4",
"bigbuck_bunny_8bit_750kbps_720p_60.0fps_hevc.mp4",
"jellyfin_av1_main_1080p_24fps.mp4",
];
for name in candidates {
let Some(data) = read_test_file(name) else {
continue;
};
let legacy = demux::demux(&data).expect("legacy");
let sd = demux::demux_streaming(&data).expect("streaming");
let h = sd.header();
assert_eq!(h.codec, legacy.codec, "{name}: codec drift");
assert_eq!(h.info.width, legacy.info.width, "{name}: width drift");
assert_eq!(h.info.height, legacy.info.height, "{name}: height drift");
assert_eq!(
h.info.pixel_format, legacy.info.pixel_format,
"{name}: pixel_format drift"
);
assert_eq!(
h.info.frame_rate, legacy.info.frame_rate,
"{name}: frame_rate drift"
);
}
}
#[allow(dead_code)]
fn _silence_unused_path(_p: &Path) {}
}
#[test]
fn _streaming_equality_gate_status() {
if cfg!(streaming_api_landed) {
eprintln!(
"streaming_equality: gate ON — the per-format equality \
tests in `gated_tests` are active."
);
} else {
eprintln!(
"streaming_equality: gate OFF — the per-format equality \
tests are compile-skipped because `demux_streaming()` is \
not yet on this branch (P1 not merged in). Re-run with \
`RUSTFLAGS=\"--cfg streaming_api_landed\"` after the \
P1 merge to activate the regressions."
);
}
}