Misc: Add debug logging via log crate

This commit is contained in:
Serial 2022-09-30 07:05:33 -04:00
parent ac420960de
commit 0d4b907e31
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
4 changed files with 17 additions and 18 deletions

View file

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`read_properties`, specified with a `bool` in `read_from{_path}`. This will now default to `true`,
and can be overridden when using `Probe`.
- **FileProperties**: `FileProperties::new`
- Debug logging via the [log](crates.io/crates/log) crate for exposing recoverable errors.
### Changed
- **ID3v2**: Frame/tag flags with optional additional data are now `Option<T>` instead of `(bool, T)`

View file

@ -19,7 +19,10 @@ byteorder = "1.4.3"
cfg-if = "1.0.0"
# ID3 compressed frames
flate2 = { version = "1.0.24", optional = true }
# Proc macros
lofty_attr = { path = "lofty_attr" }
# Debug logging
log = "0.4.17"
# OGG Vorbis/Opus
ogg_pager = "0.3.2"
# Key maps

View file

@ -48,8 +48,8 @@ where
let read_only = (flags & 1) == 1;
let item_type = (flags >> 1) & 3;
// TODO: This could use a warning
if value_size == 0 || key.len() < 2 || key.len() > 255 {
log::debug!("APE: Encountered invalid item key ({})", key);
continue;
}

View file

@ -1,7 +1,6 @@
use super::constants::{BITRATES, PADDING_SIZES, SAMPLES, SAMPLE_RATES, SIDE_INFORMATION_SIZES};
use crate::error::Result;
use crate::macros::{decode_err, parse_mode_choice};
use crate::probe::ParsingMode;
use crate::macros::decode_err;
use std::io::{Read, Seek, SeekFrom};
@ -190,12 +189,12 @@ pub(crate) struct Header {
}
impl Header {
pub(super) fn read(data: u32, parse_mode: ParsingMode) -> Result<Option<Self>> {
pub(super) fn read(data: u32) -> Option<Self> {
let version = match (data >> 19) & 0b11 {
0 => MpegVersion::V2_5,
2 => MpegVersion::V2,
3 => MpegVersion::V1,
_ => return Ok(None),
_ => return None,
};
let version_index = if version == MpegVersion::V1 { 0 } else { 1 };
@ -205,11 +204,8 @@ impl Header {
2 => Layer::Layer2,
3 => Layer::Layer1,
_ => {
parse_mode_choice!(
parse_mode,
STRICT: decode_err!(@BAIL MPEG, "Frame header uses a reserved layer"),
RELAXED: return Ok(None)
);
log::debug!("MPEG: Frame header uses a reserved layer");
return None;
},
};
@ -233,14 +229,14 @@ impl Header {
let bitrate_index = (data >> 12) & 0xF;
header.bitrate = BITRATES[version_index][layer_index][bitrate_index as usize];
if header.bitrate == 0 {
return Ok(None);
return None;
}
// Sample rate index
let sample_rate_index = (data >> 10) & 0b11;
header.sample_rate = match sample_rate_index {
// This is invalid
3 => return Ok(None),
3 => return None,
_ => SAMPLE_RATES[header.version as usize][sample_rate_index as usize],
};
@ -281,7 +277,7 @@ impl Header {
header.len =
(u32::from(header.samples) * header.bitrate * 125 / header.sample_rate) + padding;
Ok(Some(header))
Some(header)
}
}
@ -291,7 +287,7 @@ pub(super) struct XingHeader {
}
impl XingHeader {
pub(super) fn read(reader: &mut &[u8], parse_mode: ParsingMode) -> Result<Option<Self>> {
pub(super) fn read(reader: &mut &[u8]) -> Result<Option<Self>> {
let reader_len = reader.len();
let mut header = [0; 4];
@ -307,11 +303,10 @@ impl XingHeader {
reader.read_exact(&mut flags)?;
if flags[3] & 0x03 != 0x03 {
parse_mode_choice!(
parse_mode,
STRICT: decode_err!(@BAIL MPEG, "Xing header doesn't have required flags set (0x0001 and 0x0002)"),
RELAXED: return Ok(None)
log::debug!(
"MPEG: Xing header doesn't have required flags set (0x0001 and 0x0002)"
);
return Ok(None);
}
let frames = reader.read_u32::<BigEndian>()?;