Skip to content

Commit b70e51f

Browse files
committed
Change Mp4parseByteData.length to usize, eliminating unsafe casts
Also, fix a clippy lint
1 parent b4cc8c4 commit b70e51f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

mp4parse/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ enum IlocFieldSize {
10521052
}
10531053

10541054
impl IlocFieldSize {
1055-
fn to_bits(&self) -> u8 {
1055+
fn as_bits(&self) -> u8 {
10561056
match self {
10571057
IlocFieldSize::Zero => 0,
10581058
IlocFieldSize::Four => 32,
@@ -2454,7 +2454,7 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryHashMap<u32, ItemLocati
24542454
));
24552455
}
24562456

2457-
let base_offset = iloc.read_u64(base_offset_size.to_bits())?;
2457+
let base_offset = iloc.read_u64(base_offset_size.as_bits())?;
24582458
let extent_count = iloc.read_u16(16)?;
24592459

24602460
if extent_count < 1 {
@@ -2481,16 +2481,16 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryHashMap<u32, ItemLocati
24812481
None | Some(IlocFieldSize::Zero) => None,
24822482
Some(index_size) => {
24832483
debug_assert!(version == IlocVersion::One || version == IlocVersion::Two);
2484-
Some(iloc.read_u64(index_size.to_bits())?)
2484+
Some(iloc.read_u64(index_size.as_bits())?)
24852485
}
24862486
};
24872487

24882488
// Per ISOBMFF (ISO 14496-12:2015) § 8.11.3.1:
24892489
// "If the offset is not identified (the field has a length of zero), then the
24902490
// beginning of the source (offset 0) is implied"
24912491
// This behavior will follow from BitReader::read_u64(0) -> 0.
2492-
let extent_offset = iloc.read_u64(offset_size.to_bits())?;
2493-
let extent_length = iloc.read_u64(length_size.to_bits())?.try_into()?;
2492+
let extent_offset = iloc.read_u64(offset_size.as_bits())?;
2493+
let extent_length = iloc.read_u64(length_size.as_bits())?.try_into()?;
24942494

24952495
// "If the length is not specified, or specified as zero, then the entire length of
24962496
// the source is implied" (ibid)

mp4parse_capi/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub struct Mp4parseIndice {
294294
#[repr(C)]
295295
#[derive(Debug)]
296296
pub struct Mp4parseByteData {
297-
pub length: u32,
297+
pub length: usize,
298298
// cheddar can't handle generic type, so it needs to be multiple data types here.
299299
pub data: *const u8,
300300
pub indices: *const Mp4parseIndice,
@@ -312,12 +312,12 @@ impl Default for Mp4parseByteData {
312312

313313
impl Mp4parseByteData {
314314
fn set_data(&mut self, data: &[u8]) {
315-
self.length = data.len() as u32;
315+
self.length = data.len();
316316
self.data = data.as_ptr();
317317
}
318318

319319
fn set_indices(&mut self, data: &[Mp4parseIndice]) {
320-
self.length = data.len() as u32;
320+
self.length = data.len();
321321
self.indices = data.as_ptr();
322322
}
323323
}
@@ -928,9 +928,9 @@ fn get_track_audio_info(
928928
if esds.codec_esds.len() > std::u32::MAX as usize {
929929
return Err(Mp4parseStatus::Invalid);
930930
}
931-
sample_info.extra_data.length = esds.codec_esds.len() as u32;
931+
sample_info.extra_data.length = esds.codec_esds.len();
932932
sample_info.extra_data.data = esds.codec_esds.as_ptr();
933-
sample_info.codec_specific_config.length = esds.decoder_specific_data.len() as u32;
933+
sample_info.codec_specific_config.length = esds.decoder_specific_data.len();
934934
sample_info.codec_specific_config.data = esds.decoder_specific_data.as_ptr();
935935
if let Some(rate) = esds.audio_sample_rate {
936936
sample_info.sample_rate = rate;
@@ -952,7 +952,7 @@ fn get_track_audio_info(
952952
if streaminfo.block_type != 0 || streaminfo.data.len() != 34 {
953953
return Err(Mp4parseStatus::Invalid);
954954
}
955-
sample_info.codec_specific_config.length = streaminfo.data.len() as u32;
955+
sample_info.codec_specific_config.length = streaminfo.data.len();
956956
sample_info.codec_specific_config.data = streaminfo.data.as_ptr();
957957
}
958958
AudioCodecSpecific::OpusSpecificBox(ref opus) => {
@@ -967,14 +967,14 @@ fn get_track_audio_info(
967967
if v.len() > std::u32::MAX as usize {
968968
return Err(Mp4parseStatus::Invalid);
969969
}
970-
sample_info.codec_specific_config.length = v.len() as u32;
970+
sample_info.codec_specific_config.length = v.len();
971971
sample_info.codec_specific_config.data = v.as_ptr();
972972
}
973973
}
974974
}
975975
}
976976
AudioCodecSpecific::ALACSpecificBox(ref alac) => {
977-
sample_info.codec_specific_config.length = alac.data.len() as u32;
977+
sample_info.codec_specific_config.length = alac.data.len();
978978
sample_info.codec_specific_config.data = alac.data.as_ptr();
979979
}
980980
AudioCodecSpecific::MP3 | AudioCodecSpecific::LPCM => (),

0 commit comments

Comments
 (0)