diff --git a/Cargo.toml b/Cargo.toml index 3ca08666..b2e8d60e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ minimp3_fixed = { version = "0.5.4", optional = true} symphonia = { version = "0.5.4", optional = true, default-features = false } crossbeam-channel = { version = "0.5.8", optional = true } -thiserror = "1.0.49" rand = { version = "0.8.5", features = ["small_rng"], optional = true } tracing = { version = "0.1.40", optional = true } diff --git a/src/decoder/symphonia.rs b/src/decoder/symphonia.rs index 06380c7a..127c7202 100644 --- a/src/decoder/symphonia.rs +++ b/src/decoder/symphonia.rs @@ -1,4 +1,5 @@ -use std::time::Duration; +use core::fmt; +use core::time::Duration; use symphonia::{ core::{ audio::{AudioBufferRef, SampleBuffer, SignalSpec}, @@ -209,21 +210,57 @@ impl Source for SymphoniaDecoder { } /// Error returned when the try_seek implementation of the symphonia decoder fails. -#[derive(Debug, thiserror::Error)] +#[derive(Debug)] pub enum SeekError { /// Could not get next packet while refining seek position - #[error("Could not get next packet while refining seek position: {0:?}")] Refining(symphonia::core::errors::Error), /// Format reader failed to seek - #[error("Format reader failed to seek: {0:?}")] BaseSeek(symphonia::core::errors::Error), /// Decoding failed retrying on the next packet failed - #[error("Decoding failed retrying on the next packet failed: {0:?}")] Retrying(symphonia::core::errors::Error), /// Decoding failed on multiple consecutive packets - #[error("Decoding failed on multiple consecutive packets: {0:?}")] Decoding(symphonia::core::errors::Error), } +impl fmt::Display for SeekError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + SeekError::Refining(err) => { + write!( + f, + "Could not get next packet while refining seek position: {:?}", + err + ) + } + SeekError::BaseSeek(err) => { + write!(f, "Format reader failed to seek: {:?}", err) + } + SeekError::Retrying(err) => { + write!( + f, + "Decoding failed retrying on the next packet failed: {:?}", + err + ) + } + SeekError::Decoding(err) => { + write!( + f, + "Decoding failed on multiple consecutive packets: {:?}", + err + ) + } + } + } +} +impl std::error::Error for SeekError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + SeekError::Refining(err) => Some(err), + SeekError::BaseSeek(err) => Some(err), + SeekError::Retrying(err) => Some(err), + SeekError::Decoding(err) => Some(err), + } + } +} impl SymphoniaDecoder { /// Note frame offset must be set after diff --git a/src/source/mod.rs b/src/source/mod.rs index 72bf11b1..fe47771d 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -1,6 +1,7 @@ //! Sources of sound and various filters. -use std::time::Duration; +use core::fmt; +use core::time::Duration; use cpal::FromSample; @@ -585,28 +586,60 @@ where /// Occurs when try_seek fails because the underlying decoder has an error or /// does not support seeking. #[non_exhaustive] -#[derive(Debug, thiserror::Error)] +#[derive(Debug)] pub enum SeekError { - /// On of the underlying sources does not support seeking - #[error("Seeking is not supported by source: {underlying_source}")] + /// One of the underlying sources does not support seeking NotSupported { /// The source that did not support seek underlying_source: &'static str, }, #[cfg(feature = "symphonia")] /// The symphonia decoder ran into an issue - #[error("Error seeking: {0}")] - SymphoniaDecoder(#[from] crate::decoder::symphonia::SeekError), + SymphoniaDecoder(crate::decoder::symphonia::SeekError), #[cfg(feature = "wav")] - #[error("Error seeking in wav source: {0}")] /// The hound (wav) decoder ran into an issue HoundDecoder(std::io::Error), // Prefer adding an enum variant to using this. Its meant for end users their // own try_seek implementations /// Any other error probably in a custom Source - #[error("An error occurred")] Other(Box), } +impl fmt::Display for SeekError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + SeekError::NotSupported { underlying_source } => { + write!( + f, + "Seeking is not supported by source: {}", + underlying_source + ) + } + #[cfg(feature = "symphonia")] + SeekError::SymphoniaDecoder(err) => write!(f, "Error seeking: {}", err), + #[cfg(feature = "wav")] + SeekError::HoundDecoder(err) => write!(f, "Error seeking in wav source: {}", err), + SeekError::Other(_) => write!(f, "An error occurred"), + } + } +} +impl std::error::Error for SeekError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + SeekError::NotSupported { .. } => None, + #[cfg(feature = "symphonia")] + SeekError::SymphoniaDecoder(err) => Some(err), + #[cfg(feature = "wav")] + SeekError::HoundDecoder(err) => Some(err), + SeekError::Other(err) => Some(err.as_ref()), + } + } +} +impl From for SeekError { + #[allow(deprecated)] + fn from(source: crate::decoder::symphonia::SeekError) -> Self { + SeekError::SymphoniaDecoder(source) + } +} impl SeekError { /// Will the source remain playing at its position before the seek or is it