Skip to content

Commit

Permalink
feat(playback): skip validation if unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
snylonue committed Aug 26, 2024
1 parent 58ed8a5 commit 4f864eb
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions anni-playback/src/sources/cached_http/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use symphonia::{
};

use anni_common::models::RawTrackIdentifier;
use symphonia_core::io::MediaSource;
use thiserror::Error;

#[derive(Debug, Clone)]
pub struct CacheStore {
Expand Down Expand Up @@ -93,8 +95,8 @@ pub fn create_dir_all(path: impl AsRef<Path>) -> io::Result<()> {
}
}

pub fn validate_audio(p: &Path) -> symphonia::core::errors::Result<bool> {
let source = MediaSourceStream::new(Box::new(File::open(p)?), Default::default());
pub fn validate(source: Box<dyn MediaSource>) -> Result<bool, ValidationError> {
let source = MediaSourceStream::new(source, Default::default());

let format_opts = FormatOptions::default();
let metadata_opts = MetadataOptions::default();
Expand All @@ -113,5 +115,21 @@ pub fn validate_audio(p: &Path) -> symphonia::core::errors::Result<bool> {
let _ = decoder.decode(&packet)?;
}

Ok(decoder.finalize().verify_ok.unwrap_or(false))
decoder.finalize().verify_ok.ok_or(ValidationError::Unsupported)
}

pub fn validate_audio(p: &Path) -> symphonia::core::errors::Result<bool> {
match validate(Box::new(File::open(p)?)) {
Ok(res) => Ok(res),
Err(ValidationError::Decode(e)) => Err(e),
Err(ValidationError::Unsupported) => Ok(true),
}
}

#[derive(Debug, Error)]
pub enum ValidationError {
#[error("Decode Error: {0}")]
Decode(#[from] symphonia::core::errors::Error),
#[error("Validation is not supported on the source")]
Unsupported
}

0 comments on commit 4f864eb

Please sign in to comment.