Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo fmt and clippy #73

Merged
merged 2 commits into from
Jun 1, 2022
Merged
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
18 changes: 11 additions & 7 deletions benches/bench_main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
use criterion::BenchmarkId;
use criterion::{criterion_group, criterion_main, Criterion};
use mp4;

use std::fs::File;

fn read_mp4(filename: &str) -> u64 {
let f = File::open(filename).unwrap();
let m = mp4::read_mp4(f).unwrap();
let size = m.size();
size

m.size()
}

fn criterion_benchmark(c: &mut Criterion) {
let filename = "tests/samples/minimal.mp4";

c.bench_with_input(BenchmarkId::new("input_example", filename), &filename, |b, &s| {
b.iter(|| read_mp4(s));
});
c.bench_with_input(
BenchmarkId::new("input_example", filename),
&filename,
|b, &s| {
b.iter(|| read_mp4(s));
},
);
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
criterion_main!(benches);
15 changes: 4 additions & 11 deletions examples/mp4copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ use std::io::{self, BufReader, BufWriter};
use std::path::Path;

use mp4::{
AacConfig,
AvcConfig,
HevcConfig,
Vp9Config,
TtxtConfig,
MediaConfig,
MediaType,
Mp4Config,
Result,
TrackConfig};
AacConfig, AvcConfig, HevcConfig, MediaConfig, MediaType, Mp4Config, Result, TrackConfig,
TtxtConfig, Vp9Config,
};

fn main() {
let args: Vec<String> = env::args().collect();
Expand All @@ -41,7 +34,7 @@ fn copy<P: AsRef<Path>>(src_filename: &P, dst_filename: &P) -> Result<()> {
let mut mp4_writer = mp4::Mp4Writer::write_start(
writer,
&Mp4Config {
major_brand: mp4_reader.major_brand().clone(),
major_brand: *mp4_reader.major_brand(),
minor_version: mp4_reader.minor_version(),
compatible_brands: mp4_reader.compatible_brands().to_vec(),
timescale: mp4_reader.timescale(),
Expand Down
12 changes: 6 additions & 6 deletions examples/mp4dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::prelude::*;
use std::io::{self, BufReader};
use std::path::Path;

use mp4::{Result, Mp4Box};
use mp4::{Mp4Box, Result};

fn main() {
let args: Vec<String> = env::args().collect();
Expand All @@ -25,7 +25,7 @@ fn dump<P: AsRef<Path>>(filename: &P) -> Result<()> {

// print out boxes
for b in boxes.iter() {
println!("[{}] size={} {}", b.name, b.size, b.summary);
println!("[{}] size={} {}", b.name, b.size, b.summary);
}

Ok(())
Expand Down Expand Up @@ -133,11 +133,11 @@ fn get_boxes(file: File) -> Result<Vec<Box>> {
Ok(boxes)
}

fn build_box<M: Mp4Box + std::fmt::Debug>(ref m: &M) -> Box {
return Box{
fn build_box<M: Mp4Box + std::fmt::Debug>(m: &M) -> Box {
Box {
name: m.box_type().to_string(),
size: m.box_size(),
summary: m.summary().unwrap(),
indent: 0,
};
}
}
}
2 changes: 1 addition & 1 deletion examples/mp4info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn info<P: AsRef<Path>>(filename: &P) -> Result<()> {
let mut compatible_brands = String::new();
for brand in mp4.compatible_brands().iter() {
compatible_brands.push_str(&brand.to_string());
compatible_brands.push_str(" ");
compatible_brands.push(' ');
}
println!(" compatible_brands: {}\n", compatible_brands);

Expand Down
17 changes: 9 additions & 8 deletions examples/mp4sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::prelude::*;
use std::io::{self, BufReader};
use std::path::Path;

use mp4::{Result};
use mp4::Result;

fn main() {
let args: Vec<String> = env::args().collect();
Expand Down Expand Up @@ -34,13 +34,14 @@ fn samples<P: AsRef<Path>>(filename: &P) -> Result<()> {
let sample = mp4.read_sample(track_id, sample_id);

if let Some(ref samp) = sample.unwrap() {
println!("[{}] start_time={} duration={} rendering_offset={} size={} is_sync={}",
sample_id,
samp.start_time,
samp.duration,
samp.rendering_offset,
samp.bytes.len(),
samp.is_sync,
println!(
"[{}] start_time={} duration={} rendering_offset={} size={} is_sync={}",
sample_id,
samp.start_time,
samp.duration,
samp.rendering_offset,
samp.bytes.len(),
samp.is_sync,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/mp4writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ fn main() -> mp4::Result<()> {
let data: Vec<u8> = writer.into_writer().into_inner();
println!("{:?}", data);
Ok(())
}
}
6 changes: 3 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use mp4;
use std::env;
use std::fs::File;

Expand All @@ -17,11 +16,12 @@ fn main() {
println!("Major Brand: {}", mp4.major_brand());

for track in mp4.tracks().values() {
println!("Track: #{}({}) {} {}",
println!(
"Track: #{}({}) {} {}",
track.track_id(),
track.language(),
track.track_type().unwrap(),
track.box_type().unwrap(),
);
}
}
}
19 changes: 9 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! `mp4` is a Rust library to read and write ISO-MP4 files.
//!
//!
//! This package contains MPEG-4 specifications defined in parts:
//! * ISO/IEC 14496-12 - ISO Base Media File Format (QuickTime, MPEG-4, etc)
//! * ISO/IEC 14496-14 - MP4 file format
//! * ISO/IEC 14496-17 - Streaming text format
//!
//!
//! See: [mp4box] for supported MP4 atoms.
//!
//!
//! ### Example
//!
//!
//! ```
//! use std::fs::File;
//! use std::io::{BufReader};
Expand Down Expand Up @@ -49,9 +49,9 @@
//! Ok(())
//! }
//! ```
//!
//!
//! See [examples] for more examples.
//!
//!
//! # Installation
//!
//! Add the following to your `Cargo.toml` file:
Expand All @@ -60,14 +60,13 @@
//! [dependencies]
//! mp4 = "0.7.0"
//! ```
//!
//!
//! [mp4box]: https://github.com/alfg/mp4-rust/blob/master/src/mp4box/mod.rs
//! [examples]: https://github.com/alfg/mp4-rust/blob/master/src/examples
#![doc(html_root_url = "https://docs.rs/mp4/*")]


use std::io::{BufReader};
use std::fs::File;
use std::io::BufReader;

mod error;
pub use error::Error;
Expand All @@ -94,4 +93,4 @@ pub fn read_mp4(f: File) -> Result<Mp4Reader<BufReader<File>>> {
let reader = BufReader::new(f);
let mp4 = reader::Mp4Reader::read_header(reader, size)?;
Ok(mp4)
}
}
15 changes: 8 additions & 7 deletions src/mp4box/avc1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use serde::Serialize;
use std::io::{Read, Seek, Write};
use serde::{Serialize};

use crate::mp4box::*;

Expand Down Expand Up @@ -60,20 +60,22 @@ impl Avc1Box {

impl Mp4Box for Avc1Box {
fn box_type(&self) -> BoxType {
return self.get_type();
self.get_type()
}

fn box_size(&self) -> u64 {
return self.get_size();
self.get_size()
}

fn to_json(&self) -> Result<String> {
Ok(serde_json::to_string(&self).unwrap())
}

fn summary(&self) -> Result<String> {
let s = format!("data_reference_index={} width={} height={} frame_count={}",
self.data_reference_index, self.width, self.height, self.frame_count);
let s = format!(
"data_reference_index={} width={} height={} frame_count={}",
self.data_reference_index, self.width, self.height, self.frame_count
);
Ok(s)
}
}
Expand Down Expand Up @@ -197,8 +199,7 @@ impl Mp4Box for AvcCBox {
}

fn summary(&self) -> Result<String> {
let s = format!("avc_profile_indication={}",
self.avc_profile_indication);
let s = format!("avc_profile_indication={}", self.avc_profile_indication);
Ok(s)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/mp4box/co64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use serde::Serialize;
use std::io::{Read, Seek, Write};
use serde::{Serialize};

use crate::mp4box::*;

Expand All @@ -25,11 +25,11 @@ impl Co64Box {

impl Mp4Box for Co64Box {
fn box_type(&self) -> BoxType {
return self.get_type();
self.get_type()
}

fn box_size(&self) -> u64 {
return self.get_size();
self.get_size()
}

fn to_json(&self) -> Result<String> {
Expand Down
6 changes: 3 additions & 3 deletions src/mp4box/ctts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use serde::Serialize;
use std::io::{Read, Seek, Write};
use serde::{Serialize};

use crate::mp4box::*;

Expand Down Expand Up @@ -31,11 +31,11 @@ pub struct CttsEntry {

impl Mp4Box for CttsBox {
fn box_type(&self) -> BoxType {
return self.get_type();
self.get_type()
}

fn box_size(&self) -> u64 {
return self.get_size();
self.get_size()
}

fn to_json(&self) -> Result<String> {
Expand Down
Loading