mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-04 23:07:20 +00:00
Clippy
This commit is contained in:
parent
f95e7cfdff
commit
d519fa5ea1
5 changed files with 31 additions and 29 deletions
|
@ -10,7 +10,7 @@ use std::time::Duration;
|
|||
|
||||
pub(in crate::components) fn read_properties<R>(
|
||||
data: &mut R,
|
||||
first_page: Page,
|
||||
first_page: &Page,
|
||||
stream_len: u64,
|
||||
) -> Result<FileProperties>
|
||||
where
|
||||
|
@ -43,23 +43,27 @@ where
|
|||
let last_page = find_last_page(data)?;
|
||||
let last_page_abgp = last_page.abgp;
|
||||
|
||||
return if let Some(frame_count) = last_page_abgp.checked_sub(first_page_abgp + pre_skip as u64)
|
||||
{
|
||||
let length = frame_count * 1000 / 48000;
|
||||
let duration = Duration::from_millis(length as u64);
|
||||
let bitrate = ((audio_size * 8) / length) as u32;
|
||||
last_page_abgp
|
||||
.checked_sub(first_page_abgp + u64::from(pre_skip))
|
||||
.map_or_else(
|
||||
|| {
|
||||
Err(LoftyError::InvalidData(
|
||||
"OGG file contains incorrect PCM values",
|
||||
))
|
||||
},
|
||||
|frame_count| {
|
||||
let length = frame_count * 1000 / 48000;
|
||||
let duration = Duration::from_millis(length as u64);
|
||||
let bitrate = ((audio_size * 8) / length) as u32;
|
||||
|
||||
Ok(FileProperties {
|
||||
duration,
|
||||
bitrate: Some(bitrate),
|
||||
sample_rate: Some(sample_rate),
|
||||
channels: Some(channels),
|
||||
})
|
||||
} else {
|
||||
Err(LoftyError::InvalidData(
|
||||
"OGG file contains incorrect PCM values",
|
||||
))
|
||||
};
|
||||
Ok(FileProperties {
|
||||
duration,
|
||||
bitrate: Some(bitrate),
|
||||
sample_rate: Some(sample_rate),
|
||||
channels: Some(channels),
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn write_to(data: &mut File, writer: &mut Vec<u8>, ser: u32, pages: &mut [Page]) -> Result<()> {
|
||||
|
|
|
@ -18,7 +18,7 @@ pub type OGGTags = (
|
|||
OggFormat,
|
||||
);
|
||||
|
||||
fn read_properties<R>(data: &mut R, header_sig: &[u8], first_page: Page) -> Result<FileProperties>
|
||||
fn read_properties<R>(data: &mut R, header_sig: &[u8], first_page: &Page) -> Result<FileProperties>
|
||||
where
|
||||
R: Read + Seek,
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
let properties = read_properties(data, header_sig, first_page)?;
|
||||
let properties = read_properties(data, header_sig, &first_page)?;
|
||||
|
||||
Ok((vendor_str, pictures, md, properties, format))
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::time::Duration;
|
|||
|
||||
pub(in crate::components) fn read_properties<R>(
|
||||
data: &mut R,
|
||||
first_page: Page,
|
||||
first_page: &Page,
|
||||
stream_len: u64,
|
||||
) -> Result<FileProperties>
|
||||
where
|
||||
|
@ -46,8 +46,10 @@ where
|
|||
let last_page = find_last_page(data)?;
|
||||
let last_page_abgp = last_page.abgp;
|
||||
|
||||
return if let Some(frame_count) = last_page_abgp.checked_sub(first_page_abgp) {
|
||||
let length = frame_count * 1000 / sample_rate as u64;
|
||||
last_page_abgp.checked_sub(first_page_abgp).map_or_else(|| Err(LoftyError::InvalidData(
|
||||
"OGG file contains incorrect PCM values",
|
||||
)), |frame_count| {
|
||||
let length = frame_count * 1000 / u64::from(sample_rate);
|
||||
let duration = Duration::from_millis(length as u64);
|
||||
let bitrate = ((audio_size * 8) / length) as u32;
|
||||
|
||||
|
@ -57,11 +59,7 @@ where
|
|||
sample_rate: Some(sample_rate),
|
||||
channels: Some(channels),
|
||||
})
|
||||
} else {
|
||||
Err(LoftyError::InvalidData(
|
||||
"OGG file contains incorrect PCM values",
|
||||
))
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
pub fn write_to(
|
||||
|
|
|
@ -137,7 +137,7 @@ impl TryFrom<metaflac::Tag> for OggTag {
|
|||
impl OggTag {
|
||||
#[allow(missing_docs)]
|
||||
#[allow(clippy::missing_errors_doc)]
|
||||
pub fn read_from<R>(reader: &mut R, format: OggFormat) -> Result<Self>
|
||||
pub fn read_from<R>(reader: &mut R, format: &OggFormat) -> Result<Self>
|
||||
where
|
||||
R: Read + Seek,
|
||||
{
|
||||
|
|
|
@ -107,7 +107,7 @@ impl Tag {
|
|||
feature = "format-flac",
|
||||
feature = "format-opus"
|
||||
))]
|
||||
TagType::Ogg(format) => Ok(Box::new(OggTag::read_from(reader, format)?)),
|
||||
TagType::Ogg(format) => Ok(Box::new(OggTag::read_from(reader, &format)?)),
|
||||
#[cfg(feature = "format-aiff")]
|
||||
TagType::AiffText => Ok(Box::new(AiffTag::read_from(reader)?)),
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue