From 6def760f4a44a04763517c35769ef8220b783472 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Mon, 1 Jun 2020 15:02:07 +0200 Subject: [PATCH] codec_support/test: document enc_video module --- nihav-codec-support/src/test/enc_video.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nihav-codec-support/src/test/enc_video.rs b/nihav-codec-support/src/test/enc_video.rs index 30089fd..6f9e1ec 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(); -- 2.30.2