Don't error on missing Xing/VBRI header

This commit is contained in:
Serial 2022-02-14 21:24:27 -05:00
parent 6bb0427c84
commit f9be2c8b8c
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
2 changed files with 7 additions and 11 deletions

View file

@ -195,12 +195,12 @@ impl Header {
}
pub(crate) struct XingHeader {
pub frames: u32,
pub size: u32,
pub(crate) frames: u32,
pub(crate) size: u32,
}
impl XingHeader {
pub(crate) fn read(reader: &mut &[u8]) -> Result<Self> {
pub(crate) fn read(reader: &mut &[u8]) -> Result<Option<Self>> {
let reader_len = reader.len();
let mut header = [0; 4];
@ -230,7 +230,7 @@ impl XingHeader {
let frames = reader.read_u32::<BigEndian>()?;
let size = reader.read_u32::<BigEndian>()?;
Ok(Self { frames, size })
Ok(Some(Self { frames, size }))
},
b"VBRI" => {
if reader_len < 32 {
@ -250,13 +250,9 @@ impl XingHeader {
let size = reader.read_u32::<BigEndian>()?;
let frames = reader.read_u32::<BigEndian>()?;
Ok(Self { frames, size })
Ok(Some(Self { frames, size }))
},
_ => Err(FileDecodingError::new(
FileType::MP3,
"No Xing, LAME, or VBRI header located",
)
.into()),
_ => Ok(None),
}
}
}

View file

@ -163,7 +163,7 @@ where
let mut xing_reader = [0; 32];
reader.read_exact(&mut xing_reader)?;
let xing_header = XingHeader::read(&mut &xing_reader[..]).ok();
let xing_header = XingHeader::read(&mut &xing_reader[..])?;
super::properties::read_properties(
(first_frame_header, first_frame_offset),