From 0be82f7264fdaea80e5ab3f244fd8c0a1c956f79 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sat, 14 Sep 2024 16:12:36 -0400 Subject: [PATCH] MP4: Add `AtomReader::read_u24` --- lofty/src/mp4/ilst/write.rs | 2 +- lofty/src/mp4/properties.rs | 2 +- lofty/src/mp4/read.rs | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lofty/src/mp4/ilst/write.rs b/lofty/src/mp4/ilst/write.rs index 99e2ce3c..25791030 100644 --- a/lofty/src/mp4/ilst/write.rs +++ b/lofty/src/mp4/ilst/write.rs @@ -767,7 +767,7 @@ fn write_data(flags: u32, data: &[u8], writer: &mut AtomWriterCompanion<'_>) -> // Version writer.write_u8(0)?; - writer.write_uint::(u64::from(flags), 3)?; + writer.write_u24::(u32::from(flags))?; // Locale writer.write_all(&[0; 4])?; diff --git a/lofty/src/mp4/properties.rs b/lofty/src/mp4/properties.rs index 125f76f0..b4fab20c 100644 --- a/lofty/src/mp4/properties.rs +++ b/lofty/src/mp4/properties.rs @@ -652,7 +652,7 @@ where // 15 means the sample rate is stored in the next 24 bits 0x0F => { let sample_rate; - let explicit_sample_rate = stsd.read_u24::()?; + let explicit_sample_rate = stsd.read_u24()?; if extended_object_type { sample_rate = explicit_sample_rate >> 1; channel_conf = ((explicit_sample_rate >> 4) & 0x0F) as u8; diff --git a/lofty/src/mp4/read.rs b/lofty/src/mp4/read.rs index 08961327..6e172f70 100644 --- a/lofty/src/mp4/read.rs +++ b/lofty/src/mp4/read.rs @@ -54,6 +54,11 @@ where self.reader.read_u16::() } + pub(super) fn read_u24(&mut self) -> std::io::Result { + self.remaining_size = self.remaining_size.saturating_sub(3); + self.reader.read_u24::() + } + pub(super) fn read_u32(&mut self) -> std::io::Result { self.remaining_size = self.remaining_size.saturating_sub(4); self.reader.read_u32::()