// Copyright (C) 2019 Sebastian Dröge // Copyright (C) 2021 Arun Raghavan // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use gst::glib; use gst::prelude::*; use std::fs; use std::path::PathBuf; fn init() { use std::sync::Once; static INIT: Once = Once::new(); INIT.call_once(|| { gst::init().unwrap(); gstffv1::plugin_register_static().expect("ffv1 test"); }); } #[test] fn test_decode_yuv420p() { init(); test_decode("yuv420p"); } fn test_decode(name: &str) { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); path.push(format!("tests/ffv1_v3_{}.mkv", name)); let bin = gst::parse_bin_from_description( &format!( "filesrc location={:?} ! matroskademux name=m m.video_0 ! ffv1dec name=ffv1dec", path ), false, ) .unwrap(); let srcpad = bin.by_name("ffv1dec").unwrap().static_pad("src").unwrap(); let _ = bin.add_pad(&gst::GhostPad::with_target(Some("src"), &srcpad).unwrap()); let mut h = gst_check::Harness::with_element(&bin, None, Some("src")); h.play(); let buf = h.pull().unwrap(); let frame = buf.into_mapped_buffer_readable().unwrap(); let mut refpath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); refpath.push(format!("tests/ffv1_v3_{}.ref", name)); let ref_frame = fs::read(refpath).unwrap(); assert_eq!(frame.len(), ref_frame.len()); assert_eq!(frame.as_slice(), glib::Bytes::from_owned(ref_frame)); }