Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ license = "MIT"
include = ["src", "benches", "Cargo.toml", "README", "LICENSE"]

[dependencies]
thiserror = "^1.0"
thiserror = "^2.0"
byteorder = "1"
bytes = "1.1.0"
num-rational = { version = "0.4.0", features = ["serde"] }
bytes = "1.12.1"
num-rational = { version = "0.4.2", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

[dev-dependencies]
criterion = "0.3"
criterion = "0.8"

[[bench]]
name = "bench_main"
Expand Down
2 changes: 1 addition & 1 deletion src/mp4box/dinf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl UrlBox {
let mut size = HEADER_SIZE + HEADER_EXT_SIZE;

if !self.location.is_empty() {
size += self.location.bytes().len() as u64 + 1;
size += self.location.len() as u64 + 1;
}

size
Expand Down
2 changes: 1 addition & 1 deletion src/mp4box/ftyp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<R: Read + Seek> ReadBox<&mut R> for FtypBox {
fn read_box(reader: &mut R, size: u64) -> Result<Self> {
let start = box_start(reader)?;

if size < 16 || size % 4 != 0 {
if size < 16 || !size.is_multiple_of(4) {
return Err(Error::InvalidData("ftyp size too small or not aligned"));
}
let brand_count = (size - 16) / 4; // header + major + minor
Expand Down
6 changes: 3 additions & 3 deletions src/mp4box/ilst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<R: Read + Seek> ReadBox<&mut R> for IlstItemBox {
}

impl<'a> Metadata<'a> for IlstBox {
fn title(&self) -> Option<Cow<str>> {
fn title(&self) -> Option<Cow<'_, str>> {
self.items.get(&MetadataKey::Title).map(item_to_str)
}

Expand All @@ -178,7 +178,7 @@ impl<'a> Metadata<'a> for IlstBox {
self.items.get(&MetadataKey::Poster).map(item_to_bytes)
}

fn summary(&self) -> Option<Cow<str>> {
fn summary(&self) -> Option<Cow<'_, str>> {
self.items.get(&MetadataKey::Summary).map(item_to_str)
}
}
Expand All @@ -187,7 +187,7 @@ fn item_to_bytes(item: &IlstItemBox) -> &[u8] {
&item.data.data
}

fn item_to_str(item: &IlstItemBox) -> Cow<str> {
fn item_to_str(item: &IlstItemBox) -> Cow<'_, str> {
String::from_utf8_lossy(&item.data.data)
}

Expand Down
2 changes: 1 addition & 1 deletion src/mp4box/mp4a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ fn size_of_length(size: u32) -> u32 {
fn write_desc<W: Write>(writer: &mut W, tag: u8, size: u32) -> Result<u64> {
writer.write_u8(tag)?;

if size as u64 > std::u32::MAX as u64 {
if size as u64 > u32::MAX as u64 {
return Err(Error::InvalidData("invalid descriptor length range"));
}

Expand Down
6 changes: 3 additions & 3 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl Mp4Track {

pub fn sequence_parameter_set(&self) -> Result<&[u8]> {
if let Some(ref avc1) = self.trak.mdia.minf.stbl.stsd.avc1 {
match avc1.avcc.sequence_parameter_sets.get(0) {
match avc1.avcc.sequence_parameter_sets.first() {
Some(nal) => Ok(nal.bytes.as_ref()),
None => Err(Error::EntryInStblNotFound(
self.track_id(),
Expand All @@ -276,7 +276,7 @@ impl Mp4Track {

pub fn picture_parameter_set(&self) -> Result<&[u8]> {
if let Some(ref avc1) = self.trak.mdia.minf.stbl.stsd.avc1 {
match avc1.avcc.picture_parameter_sets.get(0) {
match avc1.avcc.picture_parameter_sets.first() {
Some(nal) => Ok(nal.bytes.as_ref()),
None => Err(Error::EntryInStblNotFound(
self.track_id(),
Expand Down Expand Up @@ -580,7 +580,7 @@ impl Mp4Track {
fn is_sync_sample(&self, sample_id: u32) -> bool {
if !self.trafs.is_empty() {
let sample_sizes_count = self.sample_count() / self.trafs.len() as u32;
return sample_id == 1 || sample_id % sample_sizes_count == 0;
return sample_id == 1 || sample_id.is_multiple_of(sample_sizes_count);
}

if let Some(ref stss) = self.trak.mdia.minf.stbl.stss {
Expand Down
18 changes: 9 additions & 9 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ const DISPLAY_TYPE_AUDIO: &str = "Audio";
const DISPLAY_TYPE_SUBTITLE: &str = "Subtitle";

const HANDLER_TYPE_VIDEO: &str = "vide";
const HANDLER_TYPE_VIDEO_FOURCC: [u8; 4] = [b'v', b'i', b'd', b'e'];
const HANDLER_TYPE_VIDEO_FOURCC: [u8; 4] = *b"vide";

const HANDLER_TYPE_AUDIO: &str = "soun";
const HANDLER_TYPE_AUDIO_FOURCC: [u8; 4] = [b's', b'o', b'u', b'n'];
const HANDLER_TYPE_AUDIO_FOURCC: [u8; 4] = *b"soun";

const HANDLER_TYPE_SUBTITLE: &str = "sbtl";
const HANDLER_TYPE_SUBTITLE_FOURCC: [u8; 4] = [b's', b'b', b't', b'l'];
const HANDLER_TYPE_SUBTITLE_FOURCC: [u8; 4] = *b"sbtl";

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TrackType {
Expand Down Expand Up @@ -695,17 +695,17 @@ pub enum MetadataKey {

pub trait Metadata<'a> {
/// The video's title
fn title(&self) -> Option<Cow<str>>;
fn title(&self) -> Option<Cow<'_, str>>;
/// The video's release year
fn year(&self) -> Option<u32>;
/// The video's poster (cover art)
fn poster(&self) -> Option<&[u8]>;
/// The video's summary
fn summary(&self) -> Option<Cow<str>>;
fn summary(&self) -> Option<Cow<'_, str>>;
}

impl<'a, T: Metadata<'a>> Metadata<'a> for &'a T {
fn title(&self) -> Option<Cow<str>> {
fn title(&self) -> Option<Cow<'_, str>> {
(**self).title()
}

Expand All @@ -717,13 +717,13 @@ impl<'a, T: Metadata<'a>> Metadata<'a> for &'a T {
(**self).poster()
}

fn summary(&self) -> Option<Cow<str>> {
fn summary(&self) -> Option<Cow<'_, str>> {
(**self).summary()
}
}

impl<'a, T: Metadata<'a>> Metadata<'a> for Option<T> {
fn title(&self) -> Option<Cow<str>> {
fn title(&self) -> Option<Cow<'_, str>> {
self.as_ref().and_then(|t| t.title())
}

Expand All @@ -735,7 +735,7 @@ impl<'a, T: Metadata<'a>> Metadata<'a> for Option<T> {
self.as_ref().and_then(|t| t.poster())
}

fn summary(&self) -> Option<Cow<str>> {
fn summary(&self) -> Option<Cow<'_, str>> {
self.as_ref().and_then(|t| t.summary())
}
}
2 changes: 1 addition & 1 deletion src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<W: Write + Seek> Mp4Writer<W> {
fn update_mdat_size(&mut self) -> Result<()> {
let mdat_end = self.writer.stream_position()?;
let mdat_size = mdat_end - self.mdat_pos;
if mdat_size > std::u32::MAX as u64 {
if mdat_size > u32::MAX as u64 {
self.writer.seek(SeekFrom::Start(self.mdat_pos))?;
self.writer.write_u32::<BigEndian>(1)?;
self.writer.seek(SeekFrom::Start(self.mdat_pos + 8))?;
Expand Down
Loading