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

Clippy lints #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
86 changes: 40 additions & 46 deletions examples/concat.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,53 @@

extern crate mpegts;

use std::io::BufReader;
use std::env;
use std::fs::File;
use std::io::BufReader;
use std::process;
use std::env;

use mpegts::parser::packet::parse_next_packets;
use mpegts::writer::packet::write_packets;
use mpegts::writer::continuity_counter::ContinuityCounter;
use mpegts::writer::packet::write_packets;

fn main() {
if env::args().count() != 4 {
println!("ERROR: missing filepath argument.");
println!("usage:");
println!(" dump [input1.ts] [input2.ts] [output.ts]");
process::exit(0x0f00);
}

if env::args().count() != 4 {
println!("ERROR: missing filepath argument.");
println!("usage:");
println!(" dump [input1.ts] [input2.ts] [output.ts]");
process::exit(0x0f00);
}

let source1_path = env::args().nth(1).unwrap();

let mut sources = vec![
env::args().nth(2).unwrap()
];

let output_path = env::args().nth(3).unwrap();

let mut output_file = File::create(output_path).unwrap();

let file = File::open(source1_path).unwrap();
let mut stream = BufReader::new(file);

let mut cc = ContinuityCounter{streams: vec![]};
let mut count = 0;
loop {
match parse_next_packets(&mut stream) {
Ok(packets) => {
write_packets(&mut output_file, &packets, &mut cc);
count += packets.len();

print!("{:?} \r", count);
},
Err(_msg) => {
match sources.pop() {
Some(source) => {
let file = File::open(source).unwrap();
stream = BufReader::new(file);
},
None => {
println!("No more source");
return;
},
let source1_path = env::args().nth(1).unwrap();

let mut sources = vec![env::args().nth(2).unwrap()];

let output_path = env::args().nth(3).unwrap();

let mut output_file = File::create(output_path).unwrap();

let file = File::open(source1_path).unwrap();
let mut stream = BufReader::new(file);

let mut cc = ContinuityCounter { streams: vec![] };
let mut count = 0;
loop {
match parse_next_packets(&mut stream) {
Ok(packets) => {
write_packets(&mut output_file, &packets, &mut cc);
count += packets.len();

print!("{:?} \r", count);
}
Err(_msg) => match sources.pop() {
Some(source) => {
let file = File::open(source).unwrap();
stream = BufReader::new(file);
}
None => {
println!("No more source");
return;
}
},
}
}
}
}
}
36 changes: 17 additions & 19 deletions examples/dump.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@

extern crate mpegts;

use std::io::BufReader;
use std::env;
use std::fs::File;
use std::io::BufReader;
use std::process;
use std::env;

use mpegts::parser::packet::parse_next_packets;

fn main() {
if env::args().count() != 2 {
println!("ERROR: missing filepath argument.");
println!("usage:");
println!(" dump [filepath.ts]");
process::exit(0x0f00);
}

if env::args().count() != 2 {
println!("ERROR: missing filepath argument.");
println!("usage:");
println!(" dump [filepath.ts]");
process::exit(0x0f00);
}

let path = env::args().last().unwrap();
let path = env::args().last().unwrap();

let file = File::open(path).unwrap();
let mut stream = BufReader::new(file);
let file = File::open(path).unwrap();
let mut stream = BufReader::new(file);

loop {
let packets = parse_next_packets(&mut stream).unwrap();
loop {
let packets = parse_next_packets(&mut stream).unwrap();

for packet in packets {
// println!("{}", packet);
println!("{:?}", packet);
for packet in packets {
// println!("{}", packet);
println!("{:?}", packet);
}
}
}
}
81 changes: 43 additions & 38 deletions examples/pcr_measure.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

extern crate mpegts;

use std::io::BufReader;
use std::env;
use std::fs::File;
use std::io::BufReader;
use std::process;
use std::env;

use mpegts::parser::packet::parse_next_packets;
use mpegts::writer::continuity_pcr::ContinuityPcr;
Expand All @@ -13,52 +12,58 @@ const TS_PACKET_SIZE: usize = 188;
const SYSTEM_CLOCK_FREQUENCY: usize = 27000000;

fn main() {
if env::args().count() != 2 {
println!("ERROR: missing filepath argument.");
println!("usage:");
println!(" pcr_measure [filepath.ts]");
process::exit(0x0f00);
}

if env::args().count() != 2 {
println!("ERROR: missing filepath argument.");
println!("usage:");
println!(" pcr_measure [filepath.ts]");
process::exit(0x0f00);
}
let path = env::args().last().unwrap();

let path = env::args().last().unwrap();
let file = File::open(path).unwrap();
let mut stream = BufReader::new(file);

let file = File::open(path).unwrap();
let mut stream = BufReader::new(file);
let mut ts_packet_count = 0;

let mut ts_packet_count = 0;
let mut continuity_pcr = ContinuityPcr { streams: vec![] };

let mut continuity_pcr = ContinuityPcr{streams: vec![]};
loop {
let packets = parse_next_packets(&mut stream).unwrap();

loop {
let packets = parse_next_packets(&mut stream).unwrap();
for packet in packets {
if packet.program_id == 0 {
continue;
}
if packet.adaptation_field.is_some() {
let af = packet.adaptation_field.unwrap();
if af.pcr.is_some() {
let pcr = af.pcr.unwrap();

for packet in packets {
if packet.program_id == 0 {
continue;
}
if packet.adaptation_field.is_some() {
let af = packet.adaptation_field.unwrap();
if af.pcr.is_some() {
let pcr = af.pcr.unwrap();
let new_pcr = pcr.get();
let new_pcr_index = (ts_packet_count * TS_PACKET_SIZE) + 10;

let new_pcr = pcr.get();
let new_pcr_index = (ts_packet_count * TS_PACKET_SIZE) + 10;
match continuity_pcr.get(packet.program_id) {
None => {}
Some(pcr_stream) => {
let instant_bitrate = ((new_pcr_index as i64 - pcr_stream.index as i64)
* 8
* SYSTEM_CLOCK_FREQUENCY as i64)
as f64
/ (new_pcr as i64 - pcr_stream.pcr as i64) as f64;

match continuity_pcr.get(packet.program_id) {
None => {},
Some(pcr_stream) => {
let instant_bitrate = ((new_pcr_index as i64 - pcr_stream.index as i64) * 8 * SYSTEM_CLOCK_FREQUENCY as i64) as f64 / (new_pcr as i64 - pcr_stream.pcr as i64) as f64;
println!(
"{} bitrate = {:?}",
packet.program_id, instant_bitrate as i64
);
}
}

println!("{} bitrate = {:?}", packet.program_id, instant_bitrate as i64);
},
}
continuity_pcr.update(packet.program_id, new_pcr, new_pcr_index);
}
}

continuity_pcr.update(packet.program_id, new_pcr, new_pcr_index);
ts_packet_count += 1;
}
}

ts_packet_count += 1;
}
}
}
25 changes: 10 additions & 15 deletions examples/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@

extern crate mpegts;

use std::fs::File;
use mpegts::wrapper::*;
use mpegts::writer::packet::write_packets;
use mpegts::writer::continuity_counter::ContinuityCounter;
use mpegts::writer::packet::write_packets;
use std::fs::File;

fn main() {
let mut output_file = File::create("output.ts").unwrap();

let mut output_file = File::create("output.ts").unwrap();

// let program = wrapper::Program{
// id: 301
// };

let wrapper = wrapper::Wrapper{
programs: vec![]
};
// let program = wrapper::Program{
// id: 301
// };

let packets = wrapper.append_data(vec![0;100]);
let wrapper = Wrapper { programs: vec![] };

let mut cc = ContinuityCounter{streams: vec![]};
write_packets(&mut output_file, &packets, &mut cc);
let packets = wrapper.append_data(vec![0; 100]);

let mut cc = ContinuityCounter { streams: vec![] };
write_packets(&mut output_file, &packets, &mut cc);
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ extern crate crc;

pub mod mpegts;
pub mod parser;
pub mod writer;
pub mod wrapper;
pub mod writer;
21 changes: 10 additions & 11 deletions src/mpegts/adaptation_field.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

use mpegts::program_clock::ProgramClock;
use mpegts::adaptation_field_extension::AdaptationFieldExtension;
use mpegts::program_clock::ProgramClock;

#[derive(Debug, Clone)]
pub struct AdaptationField {
pub length: u8,
pub discontinuity_indicator: bool,
pub random_access_indicator: bool,
pub elementary_stream_priority_indicator: bool,
pub pcr: Option<ProgramClock>,
pub opcr: Option<ProgramClock>,
pub splice_countdown: Option<i8>,
pub transport_private_data: Vec<u8>,
pub adaptation_field_extension: Option<AdaptationFieldExtension>,
pub length: u8,
pub discontinuity_indicator: bool,
pub random_access_indicator: bool,
pub elementary_stream_priority_indicator: bool,
pub pcr: Option<ProgramClock>,
pub opcr: Option<ProgramClock>,
pub splice_countdown: Option<i8>,
pub transport_private_data: Vec<u8>,
pub adaptation_field_extension: Option<AdaptationFieldExtension>,
}
7 changes: 3 additions & 4 deletions src/mpegts/adaptation_field_extension.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#[derive(Debug, Clone)]
pub struct AdaptationFieldExtension {
pub legal_time_window: Option<u16>,
pub piecewise_rate: Option<u32>,
pub seamless_splice: Option<u64>
pub legal_time_window: Option<u16>,
pub piecewise_rate: Option<u32>,
pub seamless_splice: Option<u64>,
}
7 changes: 3 additions & 4 deletions src/mpegts/descriptor/aac.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#[derive(Debug, Clone)]
pub struct Aac {
pub profile_and_level: u8,
pub aac_type: Option<u8>,
pub additional_info: Vec<u8>,
pub profile_and_level: u8,
pub aac_type: Option<u8>,
pub additional_info: Vec<u8>,
}
3 changes: 1 addition & 2 deletions src/mpegts/descriptor/hevc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#[derive(Debug, Clone)]
pub struct Hevc {
pub profile_space: u8
pub profile_space: u8,
}
1 change: 0 additions & 1 deletion src/mpegts/descriptor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

pub mod aac;
pub mod hevc;
17 changes: 8 additions & 9 deletions src/mpegts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

pub mod packet;
pub mod adaptation_field;
pub mod adaptation_field_extension;
pub mod program_clock;
pub mod descriptor;
pub mod pack_header;
pub mod packet;
pub mod packetized_elementary_stream;
pub mod payload;
pub mod program_association;
pub mod program_clock;
pub mod program_descriptor;
pub mod program_map;
pub mod stream_id;
pub mod stream_type;
pub mod table_id;
pub mod program_descriptor;
pub mod program_association;
pub mod program_map;
pub mod packetized_elementary_stream;
pub mod pack_header;
pub mod descriptor;
Loading