From 5580b11b0e9daf065c81a8b354295c6d5d1dd3dd Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Mon, 18 Nov 2019 18:59:42 +0100 Subject: [PATCH] make audio decoder tests write .wav files only by request --- nihav-commonfmt/src/codecs/aac.rs | 2 +- nihav-commonfmt/src/codecs/atrac3.rs | 2 +- nihav-commonfmt/src/codecs/sipro.rs | 2 +- nihav-commonfmt/src/codecs/ts102366.rs | 2 +- nihav-core/src/test/dec_video.rs | 68 ++++++++++++++++---------- nihav-duck/src/codecs/dkadpcm.rs | 4 +- nihav-duck/src/codecs/on2avc.rs | 2 +- nihav-game/src/codecs/bmv.rs | 2 +- nihav-game/src/codecs/bmv3.rs | 2 +- nihav-game/src/codecs/vmd.rs | 2 +- nihav-indeo/src/codecs/imc.rs | 2 +- nihav-rad/src/codecs/binkaud.rs | 2 +- nihav-rad/src/codecs/smacker.rs | 2 +- nihav-realmedia/src/codecs/cook.rs | 2 +- nihav-realmedia/src/codecs/ra144.rs | 2 +- nihav-realmedia/src/codecs/ra288.rs | 2 +- nihav-realmedia/src/codecs/ralf.rs | 2 +- 17 files changed, 60 insertions(+), 42 deletions(-) diff --git a/nihav-commonfmt/src/codecs/aac.rs b/nihav-commonfmt/src/codecs/aac.rs index aeb2d06..f24ba20 100644 --- a/nihav-commonfmt/src/codecs/aac.rs +++ b/nihav-commonfmt/src/codecs/aac.rs @@ -1278,7 +1278,7 @@ mod test { // let file = "assets/RV/rv40_weighted_mc.rmvb"; let file = "assets/RV/rv40_weighted_mc_2.rmvb"; - test_decode_audio("realmedia", file, Some(12000), "aac", &dmx_reg, &dec_reg); + test_decode_audio("realmedia", file, Some(12000), None/*Some("aac")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-commonfmt/src/codecs/atrac3.rs b/nihav-commonfmt/src/codecs/atrac3.rs index 441da89..86b2349 100644 --- a/nihav-commonfmt/src/codecs/atrac3.rs +++ b/nihav-commonfmt/src/codecs/atrac3.rs @@ -715,7 +715,7 @@ mod test { let file = "assets/RV/rv30_atrc_384x208_realproducer_plus_8.51.rm"; // let file = "assets/RV/rv20_svt_atrc_640x352_realproducer_plus_8.51.rm"; - test_decode_audio("realmedia", file, Some(12000), "atrac3", &dmx_reg, &dec_reg); + test_decode_audio("realmedia", file, Some(12000), None/*Some("atrac3")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-commonfmt/src/codecs/sipro.rs b/nihav-commonfmt/src/codecs/sipro.rs index 745feaf..44f7942 100644 --- a/nihav-commonfmt/src/codecs/sipro.rs +++ b/nihav-commonfmt/src/codecs/sipro.rs @@ -755,7 +755,7 @@ mod test { generic_register_all_codecs(&mut dec_reg); let file = "assets/RV/autahi-vox.rm"; - test_decode_audio("realmedia", file, Some(5000), "sipro", &dmx_reg, &dec_reg); + test_decode_audio("realmedia", file, Some(5000), None/*Some("sipro")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-commonfmt/src/codecs/ts102366.rs b/nihav-commonfmt/src/codecs/ts102366.rs index 62acaeb..d6f2144 100644 --- a/nihav-commonfmt/src/codecs/ts102366.rs +++ b/nihav-commonfmt/src/codecs/ts102366.rs @@ -1259,7 +1259,7 @@ mod test { generic_register_all_codecs(&mut dec_reg); let file = "assets/RV/sp_sample1.rm"; - test_decode_audio("realmedia", file, Some(12000), "ac3", &dmx_reg, &dec_reg); + test_decode_audio("realmedia", file, Some(12000), None/*Some("ac3")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-core/src/test/dec_video.rs b/nihav-core/src/test/dec_video.rs index da29429..4cbdc36 100644 --- a/nihav-core/src/test/dec_video.rs +++ b/nihav-core/src/test/dec_video.rs @@ -206,7 +206,7 @@ panic!(" unknown format"); } } -pub fn test_decode_audio(demuxer: &str, name: &str, limit: Option, audio_pfx: &str, +pub fn test_decode_audio(demuxer: &str, name: &str, limit: Option, audio_pfx: Option<&str>, dmx_reg: &RegisteredDemuxers, dec_reg: &RegisteredDecoders) { let dmx_f = dmx_reg.find_demuxer(demuxer).unwrap(); let mut file = File::open(name).unwrap(); @@ -233,32 +233,50 @@ pub fn test_decode_audio(demuxer: &str, name: &str, limit: Option, audio_pf } } - let name = format!("assets/{}out.wav", audio_pfx); - let file = File::create(name).unwrap(); - let mut fw = FileWriter::new_write(file); - let mut wr = ByteWriter::new(&mut fw); - let mut wwr = WavWriter::new(&mut wr); - let mut wrote_header = false; + if let Some(audio_pfx) = audio_pfx { + let name = format!("assets/{}out.wav", audio_pfx); + let file = File::create(name).unwrap(); + let mut fw = FileWriter::new_write(file); + let mut wr = ByteWriter::new(&mut fw); + let mut wwr = WavWriter::new(&mut wr); + let mut wrote_header = false; - loop { - let pktres = dmx.get_frame(); - if let Err(e) = pktres { - if e == DemuxerError::EOF { break; } - panic!("error"); - } - let pkt = pktres.unwrap(); - if limit.is_some() && pkt.get_pts().is_some() && pkt.get_pts().unwrap() > limit.unwrap() { - break; - } - let streamno = pkt.get_stream().get_id() as usize; - if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] { - let frm = dec.decode(dsupp, &pkt).unwrap(); - if frm.get_info().is_audio() { - if !wrote_header { - wwr.write_header(frm.get_info().as_ref().get_properties().get_audio_info().unwrap()).unwrap(); - wrote_header = true; + loop { + let pktres = dmx.get_frame(); + if let Err(e) = pktres { + if e == DemuxerError::EOF { break; } + panic!("error"); + } + let pkt = pktres.unwrap(); + if limit.is_some() && pkt.get_pts().is_some() && pkt.get_pts().unwrap() > limit.unwrap() { + break; + } + let streamno = pkt.get_stream().get_id() as usize; + if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] { + let frm = dec.decode(dsupp, &pkt).unwrap(); + if frm.get_info().is_audio() { + if !wrote_header { + wwr.write_header(frm.get_info().as_ref().get_properties().get_audio_info().unwrap()).unwrap(); + wrote_header = true; + } + wwr.write_frame(frm.get_buffer()).unwrap(); } - wwr.write_frame(frm.get_buffer()).unwrap(); + } + } + } else { + loop { + let pktres = dmx.get_frame(); + if let Err(e) = pktres { + if e == DemuxerError::EOF { break; } + panic!("error"); + } + let pkt = pktres.unwrap(); + if limit.is_some() && pkt.get_pts().is_some() && pkt.get_pts().unwrap() > limit.unwrap() { + break; + } + let streamno = pkt.get_stream().get_id() as usize; + if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] { + let _ = dec.decode(dsupp, &pkt).unwrap(); } } } diff --git a/nihav-duck/src/codecs/dkadpcm.rs b/nihav-duck/src/codecs/dkadpcm.rs index 24f5b5b..712a864 100644 --- a/nihav-duck/src/codecs/dkadpcm.rs +++ b/nihav-duck/src/codecs/dkadpcm.rs @@ -190,7 +190,7 @@ mod test { duck_register_all_codecs(&mut dec_reg); let file = "assets/Duck/AVI-DUCK-dk3.duk"; - test_decode_audio("avi", file, Some(100), "dk3", &dmx_reg, &dec_reg); + test_decode_audio("avi", file, Some(100), None/*Some("dk3")*/, &dmx_reg, &dec_reg); } #[test] fn test_dk4() { @@ -200,7 +200,7 @@ mod test { duck_register_all_codecs(&mut dec_reg); let file = "assets/Duck/virtuafighter2-opening1.avi"; - test_decode_audio("avi", file, Some(100), "dk4", &dmx_reg, &dec_reg); + test_decode_audio("avi", file, Some(100), None/*Some("dk4")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-duck/src/codecs/on2avc.rs b/nihav-duck/src/codecs/on2avc.rs index 8273437..97c73c1 100644 --- a/nihav-duck/src/codecs/on2avc.rs +++ b/nihav-duck/src/codecs/on2avc.rs @@ -1073,7 +1073,7 @@ mod test { //let file = "assets/Duck/Cell-140.vp5"; //let file = "assets/Duck/Chocolat-500.vp5"; let file = "assets/Duck/potter-500.vp7"; - test_decode_audio("avi", file, Some(1500), "avc", &dmx_reg, &dec_reg); + test_decode_audio("avi", file, Some(1500), None/*Some("avc")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-game/src/codecs/bmv.rs b/nihav-game/src/codecs/bmv.rs index 902ae51..4417fb7 100644 --- a/nihav-game/src/codecs/bmv.rs +++ b/nihav-game/src/codecs/bmv.rs @@ -332,6 +332,6 @@ mod test { let file = "assets/Game/PERFECT.BMV"; // let file = "assets/Game/DW2-MOUSE.BMV"; // let file = "assets/Game/WILDCAT.BMV"; - test_decode_audio("bmv", file, None, "bmv", &dmx_reg, &dec_reg); + test_decode_audio("bmv", file, None, None/*Some("bmv")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-game/src/codecs/bmv3.rs b/nihav-game/src/codecs/bmv3.rs index 47378af..ae1419a 100644 --- a/nihav-game/src/codecs/bmv3.rs +++ b/nihav-game/src/codecs/bmv3.rs @@ -624,7 +624,7 @@ mod test { game_register_all_codecs(&mut dec_reg); let file = "assets/Game/DW3-Loffnote.bmv"; - test_decode_audio("bmv3", file, None, "bmv3", &dmx_reg, &dec_reg); + test_decode_audio("bmv3", file, None, None/*Some("bmv3")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-game/src/codecs/vmd.rs b/nihav-game/src/codecs/vmd.rs index e7f724f..abcb0af 100644 --- a/nihav-game/src/codecs/vmd.rs +++ b/nihav-game/src/codecs/vmd.rs @@ -476,6 +476,6 @@ mod test { let file = "assets/Game/128.vmd"; // let file = "assets/Game/1000.VMD"; // let file = "assets/Game/235.VMD"; - test_decode_audio("vmd", file, None, "vmd", &dmx_reg, &dec_reg); + test_decode_audio("vmd", file, None, None/*Some("vmd")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index 4b7c990..6840800 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -1126,7 +1126,7 @@ mod test { let file = "assets/Indeo/IMC/8khz.avi"; // let file = "assets/Indeo/STsKlassFist-1a.avi"; // let file = "assets/Indeo/IMC/Angel Bday.avi"; - test_decode_audio("avi", file, None, "imc", &dmx_reg, &dec_reg); + test_decode_audio("avi", file, None, None/*Some("imc")*/, &dmx_reg, &dec_reg); //test_file_decoding("avi", file, None, false, true, None); } } diff --git a/nihav-rad/src/codecs/binkaud.rs b/nihav-rad/src/codecs/binkaud.rs index 86f4fb0..df0970e 100644 --- a/nihav-rad/src/codecs/binkaud.rs +++ b/nihav-rad/src/codecs/binkaud.rs @@ -306,6 +306,6 @@ mod test { // let file = "assets/RAD/Snd0a110c51.dee"; // let file = "assets/RAD/NEW.BIK"; // let file = "assets/RAD/ge_video_86l.bk2"; - test_decode_audio("bink", file, None, "bink", &dmx_reg, &dec_reg); + test_decode_audio("bink", file, None, None/*Some("bink")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-rad/src/codecs/smacker.rs b/nihav-rad/src/codecs/smacker.rs index cb7d0ba..0faec8f 100644 --- a/nihav-rad/src/codecs/smacker.rs +++ b/nihav-rad/src/codecs/smacker.rs @@ -628,6 +628,6 @@ mod test { //let file = "assets/RAD/20130507_audio-distortion.smk"; let file = "assets/RAD/wetlogo.smk"; - test_decode_audio("smacker", file, None, "smk", &dmx_reg, &dec_reg); + test_decode_audio("smacker", file, None, None/*Some("smk")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-realmedia/src/codecs/cook.rs b/nihav-realmedia/src/codecs/cook.rs index a1a32e4..74364fc 100644 --- a/nihav-realmedia/src/codecs/cook.rs +++ b/nihav-realmedia/src/codecs/cook.rs @@ -696,7 +696,7 @@ mod test { // let file = "assets/RV/rv30_weighted_mc.rm"; let file = "assets/RV/multichannel.rma"; - test_decode_audio("realmedia", file, Some(2000), "cook", &dmx_reg, &dec_reg); + test_decode_audio("realmedia", file, Some(2000), None/*Some("cook")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-realmedia/src/codecs/ra144.rs b/nihav-realmedia/src/codecs/ra144.rs index 4e8a6a5..2b70f04 100644 --- a/nihav-realmedia/src/codecs/ra144.rs +++ b/nihav-realmedia/src/codecs/ra144.rs @@ -330,7 +330,7 @@ mod test { realmedia_register_all_codecs(&mut dec_reg); let file = "assets/RV/ra3_in_rm_file.rm"; - test_decode_audio("realmedia", file, Some(5000), "ra14.4", &dmx_reg, &dec_reg); + test_decode_audio("realmedia", file, Some(5000), None/*Some("ra14.4")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-realmedia/src/codecs/ra288.rs b/nihav-realmedia/src/codecs/ra288.rs index ef8faae..251e47c 100644 --- a/nihav-realmedia/src/codecs/ra288.rs +++ b/nihav-realmedia/src/codecs/ra288.rs @@ -220,7 +220,7 @@ mod test { realmedia_register_all_codecs(&mut dec_reg); let file = "assets/RV/A0000044.rm"; - test_decode_audio("realmedia", file, Some(5000), "ra28.8", &dmx_reg, &dec_reg); + test_decode_audio("realmedia", file, Some(5000), None/*Some("ra28.8")*/, &dmx_reg, &dec_reg); } } diff --git a/nihav-realmedia/src/codecs/ralf.rs b/nihav-realmedia/src/codecs/ralf.rs index 7bcab6b..c5a0f7f 100644 --- a/nihav-realmedia/src/codecs/ralf.rs +++ b/nihav-realmedia/src/codecs/ralf.rs @@ -490,7 +490,7 @@ mod test { realmedia_register_all_codecs(&mut dec_reg); let file = "assets/RV/rv40_ralf.rmvb"; - test_decode_audio("realmedia", file, Some(2000), "ralf", &dmx_reg, &dec_reg); + test_decode_audio("realmedia", file, Some(2000), None/*Some("ralf")*/, &dmx_reg, &dec_reg); //panic!("end"); } } -- 2.39.5