Création d'un décodeur générique
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
use pmoflac::{
|
||||
decode_aiff_stream, encode_flac_stream, EncoderOptions, PcmFormat, StreamInfo,
|
||||
};
|
||||
use pmoflac::{decode_aiff_stream, encode_flac_stream, EncoderOptions, PcmFormat, StreamInfo};
|
||||
|
||||
const TEST_AIFF: &str = "test_data/wood24.aiff";
|
||||
|
||||
|
||||
47
pmoflac/tests/auto_decode.rs
Normal file
47
pmoflac/tests/auto_decode.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
use pmoflac::{autodetect::decode_audio_stream, encode_flac_stream, EncoderOptions, PcmFormat};
|
||||
|
||||
const SAMPLE_FILES: &[&str] = &[
|
||||
"test_data/1abaa2c7fb4302e20ac570e79857b700.32bits-44.1Khz.flac",
|
||||
"test_data/file_example_MP3_5MG.mp3",
|
||||
"test_data/file_example_OOG_5MG.ogg",
|
||||
"test_data/music_orig.opus",
|
||||
"test_data/music_orig.wav",
|
||||
"test_data/wood24.aiff",
|
||||
];
|
||||
|
||||
#[tokio::test]
|
||||
async fn decode_audio_stream_recognises_formats() -> Result<(), Box<dyn std::error::Error>> {
|
||||
for path in SAMPLE_FILES {
|
||||
let file = tokio::fs::File::open(path).await?;
|
||||
let mut stream = decode_audio_stream(file).await?;
|
||||
let info = stream.info().clone();
|
||||
assert!(info.sample_rate > 0);
|
||||
assert!(info.channels > 0);
|
||||
let mut pcm = Vec::new();
|
||||
stream.read_to_end(&mut pcm).await?;
|
||||
assert!(!pcm.is_empty());
|
||||
stream.wait().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn decode_audio_stream_transcodes_to_flac() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let file = tokio::fs::File::open("test_data/file_example_MP3_5MG.mp3").await?;
|
||||
let stream = decode_audio_stream(file).await?;
|
||||
let (info, reader) = stream.into_reader();
|
||||
let format = PcmFormat {
|
||||
sample_rate: info.sample_rate,
|
||||
channels: info.channels,
|
||||
bits_per_sample: info.bits_per_sample,
|
||||
};
|
||||
|
||||
let mut flac_stream = encode_flac_stream(reader, format, EncoderOptions::default()).await?;
|
||||
let mut flac_data = Vec::new();
|
||||
flac_stream.read_to_end(&mut flac_data).await?;
|
||||
assert!(flac_data.starts_with(b"fLaC"));
|
||||
flac_stream.wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -224,7 +224,8 @@ async fn encoder_streams_without_buffering_all_input() -> Result<(), FlacError>
|
||||
let chunks_read_counter = slow_reader.chunks_read();
|
||||
|
||||
// Start encoding
|
||||
let mut encoder_stream = encode_flac_stream(slow_reader, format, EncoderOptions::default()).await?;
|
||||
let mut encoder_stream =
|
||||
encode_flac_stream(slow_reader, format, EncoderOptions::default()).await?;
|
||||
|
||||
// Try to read some FLAC data before all PCM data has been consumed
|
||||
let mut first_chunk = vec![0u8; 4096];
|
||||
@@ -247,12 +248,11 @@ async fn encoder_streams_without_buffering_all_input() -> Result<(), FlacError>
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
|
||||
// Check that we've started getting output
|
||||
let (first_read, mut encoder_stream) = read_handle.await.map_err(|e| {
|
||||
FlacError::TaskJoin {
|
||||
let (first_read, mut encoder_stream) =
|
||||
read_handle.await.map_err(|e| FlacError::TaskJoin {
|
||||
role: "read-test",
|
||||
details: e.to_string(),
|
||||
}
|
||||
})??;
|
||||
})??;
|
||||
|
||||
assert!(first_read > 0, "Should have received some FLAC data");
|
||||
assert!(
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
use pmoflac::{
|
||||
decode_mp3_stream, encode_flac_stream, EncoderOptions, PcmFormat, StreamInfo,
|
||||
};
|
||||
use pmoflac::{decode_mp3_stream, encode_flac_stream, EncoderOptions, PcmFormat, StreamInfo};
|
||||
|
||||
const TEST_MP3: &str = "test_data/file_example_MP3_5MG.mp3";
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ async fn ogg_decoder_detects_corrupted_crc() -> Result<(), Box<dyn std::error::E
|
||||
// Find the second "OggS" (skip the first one to corrupt an audio page, not header)
|
||||
let mut oggs_positions = Vec::new();
|
||||
for i in 0..bytes.len().saturating_sub(4) {
|
||||
if &bytes[i..i+4] == b"OggS" {
|
||||
if &bytes[i..i + 4] == b"OggS" {
|
||||
oggs_positions.push(i);
|
||||
if oggs_positions.len() >= 2 {
|
||||
break;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
use pmoflac::{
|
||||
decode_ogg_opus_stream, encode_flac_stream, EncoderOptions, PcmFormat, StreamInfo,
|
||||
};
|
||||
use pmoflac::{decode_ogg_opus_stream, encode_flac_stream, EncoderOptions, PcmFormat, StreamInfo};
|
||||
|
||||
const TEST_OPUS: &str = "test_data/music_orig.opus";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user