mux/mp4: add round trip testing infrastructure

This makes use of the recently added qtdemux changes to verify
that muxing works. At this stage its only used for unpadded RGB,
RGBA, BGRA, BGR and GRAY8 since that is all qtdemux supports
at this time. However the approach is general.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2066>
This commit is contained in:
Brad Hards 2025-02-09 19:25:33 +11:00
parent 812d4fdc9d
commit 12b0c814d7

View file

@ -173,6 +173,44 @@ fn test_roundtrip_av1_aac() {
})
}
fn test_uncompressed_with(format: &str, width: u32, height: u32, cb: impl FnOnce(&Path)) {
let Ok(pipeline) = gst::parse::launch(&format!(
"videotestsrc num-buffers=99 ! video/x-raw,format={format},width={width},height={height} ! mux. \
isomp4mux name=mux ! filesink name=sink"
)) else {
println!("could not build encoding pipeline");
return;
};
let pipeline = Pipeline(pipeline.downcast::<gst::Pipeline>().unwrap());
let dir = tempfile::TempDir::new().unwrap();
let mut location = dir.path().to_owned();
location.push("test.mp4");
let sink = pipeline.by_name("sink").unwrap();
sink.set_property("location", location.to_str().expect("Non-UTF8 filename"));
pipeline.into_completion();
cb(&location)
}
fn test_roundtrip_uncompressed(video_format: &str, width: u32, height: u32) {
test_uncompressed_with(video_format, width, height, |location| {
let Ok(pipeline) = gst::parse::launch(
"filesrc name=src ! qtdemux name=demux \
demux.video_0 ! queue ! fakesink",
) else {
panic!("could not build decoding pipeline")
};
let pipeline = Pipeline(pipeline.downcast::<gst::Pipeline>().unwrap());
pipeline
.by_name("src")
.unwrap()
.set_property("location", location.display().to_string());
pipeline.into_completion();
})
}
fn test_encode_uncompressed(video_format: &str, width: u32, height: u32) {
let pipeline_text = format!("videotestsrc num-buffers=250 ! video/x-raw,format={format},width={width},height={height} ! isomp4mux ! filesink location={format}_{width}x{height}.mp4", format = video_format);
let Ok(pipeline) = gst::parse::launch(&pipeline_text) else {
@ -215,9 +253,10 @@ fn encode_uncompressed_rgb() {
}
#[test]
fn encode_uncompressed_rgb_no_pad() {
fn encode_uncompressed_rgb_row_align_0() {
init();
test_encode_uncompressed("RGB", 1280, 720);
test_roundtrip_uncompressed("RGB", 1280, 720);
}
#[test]
@ -226,6 +265,13 @@ fn encode_uncompressed_bgr() {
test_encode_uncompressed("BGR", 1275, 713);
}
#[test]
fn encode_uncompressed_bgr_row_align_0() {
init();
test_encode_uncompressed("BGR", 1280, 720);
test_roundtrip_uncompressed("BGR", 1280, 720);
}
#[test]
fn encode_uncompressed_nv12() {
init();
@ -244,6 +290,13 @@ fn encode_uncompressed_rgba() {
test_encode_uncompressed("RGBA", 1275, 713);
}
#[test]
fn encode_uncompressed_rgba_row_align_0() {
init();
test_encode_uncompressed("RGBA", 1280, 720);
test_roundtrip_uncompressed("RGBA", 1280, 720);
}
#[test]
fn encode_uncompressed_argb() {
init();
@ -256,6 +309,13 @@ fn encode_uncompressed_abgr() {
test_encode_uncompressed("ABGR", 1275, 713);
}
#[test]
fn encode_uncompressed_abgr_row_align_0() {
init();
test_encode_uncompressed("ABGR", 1280, 720);
test_roundtrip_uncompressed("ABGR", 1280, 720);
}
#[test]
fn encode_uncompressed_bgra() {
init();
@ -349,6 +409,13 @@ fn encode_uncompressed_gray8() {
test_encode_uncompressed("GRAY8", 1275, 713);
}
#[test]
fn encode_uncompressed_gray8_row_align_0() {
init();
test_encode_uncompressed("GRAY8", 1280, 720);
test_roundtrip_uncompressed("GRAY8", 1280, 720);
}
#[test]
fn encode_uncompressed_gray16_be() {
init();