X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-codec-support%2Fsrc%2Ftest%2Fenc_video.rs;h=bde9e7874e46fbd969fd0a05f321b468398de1ee;hb=1047e98335ad782b48bcc88e9277336576c20597;hp=30089fde489cb48490e7ae85b1b5a6382022b950;hpb=f93045503e36631ed862a657d9266719f7784e26;p=nihav.git diff --git a/nihav-codec-support/src/test/enc_video.rs b/nihav-codec-support/src/test/enc_video.rs index 30089fd..bde9e78 100644 --- a/nihav-codec-support/src/test/enc_video.rs +++ b/nihav-codec-support/src/test/enc_video.rs @@ -1,3 +1,4 @@ +//! Routines for testing encoders and muxers. use std::fs::File; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -7,23 +8,39 @@ use nihav_core::scale::*; use nihav_core::soundcvt::*; use super::md5::MD5; +/// Parameters for the source used in the test. pub struct DecoderTestParams { + /// Demuxer name e.g. `"mov"`. pub demuxer: &'static str, + /// Input file name. pub in_name: &'static str, + /// Timestamp for last decoded frame. pub limit: Option, + /// Desired input stream type (that will be decoded and fed to the encoder). pub stream_type: StreamType, + /// Registered demuxers. pub dmx_reg: RegisteredDemuxers, + /// Registered decoders. pub dec_reg: RegisteredDecoders, } +/// Parameters for the encoding test output. pub struct EncoderTestParams { + /// Muxer name e.g. `"avi"`. pub muxer: &'static str, + /// Encoder name. pub enc_name: &'static str, + /// Output file name. pub out_name: &'static str, + /// Registered muxers. pub mux_reg: RegisteredMuxers, + /// Registered encoders. pub enc_reg: RegisteredEncoders, } +/// Tests muxer by making it mux raw streams from the input file. +/// +/// Streams not fitting the output profile (e.g. a video stream or a second audio stream for WAV muxer) will be ignored. pub fn test_remuxing(dec_config: &DecoderTestParams, enc_config: &EncoderTestParams) { let dmx_f = dec_config.dmx_reg.find_demuxer(dec_config.demuxer).unwrap(); let mut file = File::open(dec_config.in_name).unwrap(); @@ -104,6 +121,9 @@ pub fn test_remuxing(dec_config: &DecoderTestParams, enc_config: &EncoderTestPar mux.end().unwrap(); } +/// Tests muxer by making it mux raw streams from the input file and comparing MD5 hash of the result to the provided one. +/// +/// Streams not fitting the output profile (e.g. a video stream or a second audio stream for WAV muxer) will be ignored. pub fn test_remuxing_md5(dec_config: &DecoderTestParams, muxer: &str, mux_reg: &RegisteredMuxers, md5_hash: [u32; 4]) { let dmx_f = dec_config.dmx_reg.find_demuxer(dec_config.demuxer).unwrap(); let mut file = File::open(dec_config.in_name).unwrap(); @@ -189,6 +209,7 @@ pub fn test_remuxing_md5(dec_config: &DecoderTestParams, muxer: &str, mux_reg: & assert_eq!(hash, md5_hash); } +/// Tests an encoder by decoding a stream from input file, feeding it to the encoder and muxing the result into output file. pub fn test_encoding_to_file(dec_config: &DecoderTestParams, enc_config: &EncoderTestParams, mut enc_params: EncodeParameters) { let dmx_f = dec_config.dmx_reg.find_demuxer(dec_config.demuxer).unwrap(); let mut file = File::open(dec_config.in_name).unwrap(); @@ -237,7 +258,7 @@ pub fn test_encoding_to_file(dec_config: &DecoderTestParams, enc_config: &Encode let mut encoder = (encfunc)(); let out_str = encoder.init(0, enc_params).unwrap(); out_sm.add_stream(NAStream::clone(&out_str)); - + let mux_f = enc_config.mux_reg.find_muxer(enc_config.muxer).unwrap(); let out_name = "assets/test_out/".to_owned() + enc_config.out_name; let file = File::create(&out_name).unwrap(); @@ -250,7 +271,7 @@ pub fn test_encoding_to_file(dec_config: &DecoderTestParams, enc_config: &Encode vinfo) } else { (ScaleInfo { fmt: YUV420_FORMAT, width: 2, height: 2 }, - NAVideoInfo { width: 2, height: 2, format: YUV420_FORMAT, flipped: false }) + NAVideoInfo { width: 2, height: 2, format: YUV420_FORMAT, flipped: false, bits: 12 }) }; let ofmt = ifmt; let mut scaler = NAScale::new(ifmt, ofmt).unwrap();