From bbd6955561e875bf89815e09e2191ca9a98fde8f Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 27 Jul 2023 18:44:56 +0200 Subject: [PATCH] videoplayer: fix clippy warnings --- videoplayer/src/audiodec.rs | 6 +++--- videoplayer/src/main.rs | 10 +++------- videoplayer/src/videodec.rs | 10 +++++----- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/videoplayer/src/audiodec.rs b/videoplayer/src/audiodec.rs index ad906f0..1f5c52e 100644 --- a/videoplayer/src/audiodec.rs +++ b/videoplayer/src/audiodec.rs @@ -78,7 +78,7 @@ impl AudioQueue { if self.end + src.len() > self.queue.len() { self.queue.resize(self.end + src.len(), 0); } - self.queue[self.end..][..src.len()].copy_from_slice(&src); + self.queue[self.end..][..src.len()].copy_from_slice(src); self.end += src.len(); self.spos = samplepos; self.set_time(); @@ -164,7 +164,7 @@ fn start_audio_decoding(asystem: &AudioSubsystem, ainfo: NAAudioInfo, sbr_hack: samples: None }; let dst_info = NAAudioInfo { - sample_rate: sample_rate, + sample_rate, channels: ch, format: SND_S16_FORMAT, block_len: 0, @@ -321,7 +321,7 @@ impl AudioControl { pub fn get_queue_size(&self) -> usize { self.aqueue.len() } pub fn try_send_audio(&mut self, evt: PktSendEvent) -> bool { - if self.aqueue.len() > 0 { + if !self.aqueue.is_empty() { self.aqueue.push(evt); false } else { diff --git a/videoplayer/src/main.rs b/videoplayer/src/main.rs index 2389e1f..98d3447 100644 --- a/videoplayer/src/main.rs +++ b/videoplayer/src/main.rs @@ -35,8 +35,9 @@ mod osd; use osd::*; #[repr(u8)] -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] enum DecodingState { + #[default] Normal, Waiting, Flush, @@ -45,10 +46,6 @@ enum DecodingState { End, } -impl Default for DecodingState { - fn default() -> Self { DecodingState::Normal } -} - impl From for DecodingState { fn from(val: u8) -> Self { match val { @@ -553,7 +550,6 @@ impl Player { println!("failed to open {}", name); return; }; - let dmx_fact; let mut fr = FileReader::new_read(&mut file); let mut br = ByteReader::new(&mut fr); let res = detect::detect_format(name, &mut br); @@ -579,7 +575,7 @@ impl Player { println!("error finding {} demuxer", dmx_name); return; } - dmx_fact = ret.unwrap(); + let dmx_fact = ret.unwrap(); br.seek(SeekFrom::Start(0)).expect("should be able to seek to the start"); let ret = create_demuxer(dmx_fact, &mut br); if ret.is_err() { diff --git a/videoplayer/src/videodec.rs b/videoplayer/src/videodec.rs index 6965ae5..d385e68 100644 --- a/videoplayer/src/videodec.rs +++ b/videoplayer/src/videodec.rs @@ -59,7 +59,7 @@ impl VideoDecoder { self.ifmt.get_format() != vinfo.get_format() { self.ifmt = vinfo; let sc_ifmt = ScaleInfo { width: self.ifmt.get_width(), height: self.ifmt.get_height(), fmt: self.ifmt.get_format() }; - let do_yuv = if let ColorModel::YUV(_) = self.ifmt.get_format().get_model() { true } else { false }; + let do_yuv = self.ifmt.get_format().get_model().is_yuv(); let ofmt = if do_yuv { self.ofmt_yuv } else { self.ofmt_rgb }; self.scaler = NAScale::new(sc_ifmt, ofmt).expect("scaling should not fail"); } @@ -103,7 +103,7 @@ impl VideoDecoder { }, DecoderType::VideoMT(ref mut vdec, ref mut reord) => { let queue_id = reord.register_frame(); - match vdec.queue_pkt(&mut self.dec.dsupp, &pkt, queue_id) { + match vdec.queue_pkt(&mut self.dec.dsupp, pkt, queue_id) { Ok(true) => {}, Ok(false) => { while !vdec.can_take_input() || vdec.has_output() { @@ -119,7 +119,7 @@ impl VideoDecoder { }, }; } - match vdec.queue_pkt(&mut self.dec.dsupp, &pkt, queue_id) { + match vdec.queue_pkt(&mut self.dec.dsupp, pkt, queue_id) { Ok(true) => {}, Ok(false) => { println!("still can't queue frame!"); @@ -383,7 +383,7 @@ impl VideoControl { self.vqueue.len() >= size } pub fn try_send_video(&mut self, evt: PktSendEvent) -> bool { - if self.vqueue.len() > 0 { + if !self.vqueue.is_empty() { self.vqueue.push(evt); false } else { @@ -444,7 +444,7 @@ impl VideoControl { frm.rgb_tex.with_lock(None, |buffer: &mut [u8], pitch: usize| { let csize = sstride.min(pitch); for (dst, src) in buffer.chunks_mut(pitch).zip(src.chunks(sstride)) { - (&mut dst[..csize]).copy_from_slice(&src[..csize]); + dst[..csize].copy_from_slice(&src[..csize]); } true }).expect("surface should be locked"); -- 2.39.5