From: Kostya Shishkov Date: Tue, 8 Oct 2024 06:51:50 +0000 (+0200) Subject: some pretty-printing X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;ds=sidebyside;h=HEAD;hp=081797c71bd8cd4342d58a2124cbd7f72d02b7d2;p=nihav-tool.git some pretty-printing --- diff --git a/src/demux.rs b/src/demux.rs index 9c65b85..1dc78c5 100644 --- a/src/demux.rs +++ b/src/demux.rs @@ -112,7 +112,7 @@ impl<'a> DemuxerObject<'a> { } } let (dmx_name, _) = res.unwrap_or(("", detect::DetectionScore::No)); - if dmx_name != "" { + if !dmx_name.is_empty() { println!("trying demuxer {} on {}", dmx_name, name); if let Some(dmx_fact) = reg.dmx_reg.find_demuxer(dmx_name) { br.seek(SeekFrom::Start(0)).unwrap(); @@ -120,7 +120,7 @@ impl<'a> DemuxerObject<'a> { return DemuxerObject::Normal(dmx); } } - if dmx_name != "" { + if !dmx_name.is_empty() { println!("trying raw demuxer {} on {}", dmx_name, name); if let Some(rdmx_fact) = reg.rdmx_reg.find_demuxer(dmx_name) { br.seek(SeekFrom::Start(0)).unwrap(); @@ -128,7 +128,8 @@ impl<'a> DemuxerObject<'a> { let mut pkts = Vec::new(); for stream in dmx.get_streams() { if let Some(pcreate) = reg.pkt_reg.find_packetiser(stream.get_info().get_name()) { - let packetiser = (pcreate)(); + let mut packetiser = (pcreate)(); + packetiser.attach_stream(stream); pkts.push(Some(packetiser)); } else { pkts.push(None); @@ -169,7 +170,7 @@ impl<'a> DemuxerObject<'a> { break; } } - if pname != "" { + if !pname.is_empty() { println!("found raw stream of type {} for {}", pname, name); let pcreate = reg.pkt_reg.find_packetiser(pname).unwrap(); let mut packetiser = (pcreate)(); @@ -182,10 +183,7 @@ impl<'a> DemuxerObject<'a> { } } pub fn is_none(&self) -> bool { - match *self { - DemuxerObject::None => true, - _ => false, - } + matches!(*self, DemuxerObject::None) } pub fn get_duration(&self) -> u64 { match *self { diff --git a/src/main.rs b/src/main.rs index fcf6a56..f756c86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -200,7 +200,7 @@ fn main() { if seek_time != NATimePoint::None { let ret = demuxer.seek(seek_time); if ret.is_err() { -println!(" seek error {:?}", ret.err().unwrap()); + println!(" seek error {:?}", ret.err().unwrap()); } } @@ -219,7 +219,7 @@ println!(" seek error {:?}", ret.err().unwrap()); let s = demuxer.get_stream(i).unwrap(); let info = s.get_info(); let decfunc = full_reg.dec_reg.find_decoder(info.get_name()); -println!("stream {} - {} {}", i, s, info.get_name()); + println!("stream {} - {} {}", i, s, info.get_name()); let str_id = s.get_id(); let mut has_out = false; sids.push(str_id); @@ -308,7 +308,7 @@ println!("stream {} - {} {}", i, s, info.get_name()); } }, }; - if pkt.get_pts() != None && lastpts != NATimePoint::None && !pkt.ts.less_than(lastpts) { break; } + if pkt.get_pts().is_some() && lastpts != NATimePoint::None && !pkt.ts.less_than(lastpts) { break; } } } //panic!("end"); diff --git a/src/wavwriter.rs b/src/wavwriter.rs index ab26f6c..e32a4ec 100644 --- a/src/wavwriter.rs +++ b/src/wavwriter.rs @@ -77,14 +77,14 @@ impl<'a> WavWriter<'a> { self.io.write_u32le(16)?; self.io.write_u16le(0x0001)?; // PCM self.io.write_u16le(ainfo.get_channels() as u16)?; - self.io.write_u32le(ainfo.get_sample_rate() as u32)?; + self.io.write_u32le(ainfo.get_sample_rate())?; if bits <= 8 { - self.io.write_u32le((ainfo.get_channels() as u32) * (ainfo.get_sample_rate() as u32))?; + self.io.write_u32le((ainfo.get_channels() as u32) * ainfo.get_sample_rate())?; self.io.write_u16le(ainfo.get_channels() as u16)?; // block align self.io.write_u16le(8)?; } else { - self.io.write_u32le(2 * (ainfo.get_channels() as u32) * (ainfo.get_sample_rate() as u32))?; + self.io.write_u32le(2 * (ainfo.get_channels() as u32) * ainfo.get_sample_rate())?; self.io.write_u16le((2 * ainfo.get_channels()) as u16)?; // block align self.io.write_u16le(16)?; } @@ -122,7 +122,7 @@ impl<'a> WavWriter<'a> { }, 12 if !self.be => { let mut src = data.chunks_exact(3); - while let Some(chunk) = src.next() { + for chunk in src.by_ref() { self.io.write_byte(chunk[0] << 4)?; self.io.write_byte((chunk[1] << 4) | (chunk[0] >> 4))?; self.io.write_byte(chunk[1] & 0xF0)?; @@ -172,7 +172,7 @@ impl<'a> Drop for WavWriter<'a> { let res = self.io.seek(SeekFrom::Start(4)); let res = self.io.write_u32le((size - 8) as u32); let res = self.io.seek(SeekFrom::Start(self.data_pos - 4)); - let res = self.io.write_u32le(((size as u64) - self.data_pos) as u32); + let res = self.io.write_u32le((size - self.data_pos) as u32); let res = self.io.flush(); } }