From 6f2630992fe340ad1a122ec10c649f756e478185 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 22 Sep 2022 17:53:58 +0200 Subject: [PATCH] fix some clippy warnings --- nihav-codec-support/src/codecs/mod.rs | 15 +---- nihav-commonfmt/src/codecs/cinepakenc.rs | 7 ++- nihav-commonfmt/src/codecs/jpeg.rs | 2 +- nihav-commonfmt/src/codecs/pcm.rs | 7 ++- nihav-commonfmt/src/codecs/ts102366.rs | 12 ++-- nihav-commonfmt/src/codecs/zmbvenc.rs | 7 ++- nihav-commonfmt/src/demuxers/avi.rs | 4 +- nihav-commonfmt/src/demuxers/mov.rs | 26 ++++---- nihav-commonfmt/src/demuxers/y4m.rs | 2 +- nihav-commonfmt/src/muxers/avi.rs | 14 ++--- nihav-commonfmt/src/muxers/wav.rs | 4 +- nihav-core/src/compr/deflate.rs | 7 +-- nihav-core/src/formats.rs | 54 +++++++---------- nihav-core/src/frame.rs | 23 ++----- nihav-core/src/io/codebook.rs | 8 +-- nihav-core/src/options.rs | 4 +- nihav-core/src/scale/mod.rs | 40 ++++++------ nihav-core/src/scale/palette/mod.rs | 2 +- nihav-core/src/soundcvt/mod.rs | 30 ++++----- nihav-duck/src/codecs/on2avc.rs | 2 +- nihav-duck/src/codecs/truemotion1.rs | 11 +--- nihav-duck/src/codecs/vp56.rs | 2 +- nihav-duck/src/codecs/vp6enc/mb.rs | 2 +- nihav-duck/src/codecs/vp6enc/mod.rs | 7 ++- nihav-duck/src/codecs/vp7.rs | 34 +++++------ nihav-duck/src/codecs/vp78dsp.rs | 3 +- nihav-duck/src/codecs/vp7enc/blocks.rs | 6 +- nihav-duck/src/codecs/vp7enc/mb_coding.rs | 2 +- nihav-duck/src/codecs/vp7enc/mod.rs | 6 +- nihav-duck/src/codecs/vp8.rs | 26 ++++---- nihav-flash/src/codecs/adpcmenc.rs | 6 +- nihav-flash/src/codecs/asao.rs | 2 +- nihav-game/src/codecs/midivid3.rs | 2 +- nihav-game/src/codecs/vmd.rs | 4 +- nihav-game/src/codecs/vx.rs | 4 +- nihav-game/src/demuxers/smush.rs | 2 +- nihav-indeo/src/codecs/imc.rs | 4 +- nihav-indeo/src/codecs/indeo4.rs | 10 +-- nihav-indeo/src/codecs/indeo5.rs | 8 +-- nihav-indeo/src/codecs/intel263.rs | 2 +- nihav-indeo/src/codecs/ivibr.rs | 30 ++++----- nihav-llaudio/src/codecs/flacenc.rs | 6 +- nihav-llaudio/src/demuxers/ape.rs | 2 +- nihav-llaudio/src/demuxers/flacraw.rs | 6 +- nihav-ms/src/codecs/imaadpcmenc.rs | 6 +- nihav-ms/src/codecs/msadpcm.rs | 6 +- nihav-ms/src/codecs/msvideo1enc.rs | 16 ++--- nihav-qt/src/codecs/alac.rs | 2 +- nihav-qt/src/codecs/qdm2fft.rs | 6 +- nihav-qt/src/codecs/qdmc.rs | 2 +- nihav-qt/src/codecs/svq3.rs | 4 +- nihav-realmedia/src/codecs/ralf.rs | 2 +- nihav-realmedia/src/codecs/rv3040.rs | 18 ++---- nihav-realmedia/src/codecs/rv60.rs | 74 ++++++++--------------- nihav-realmedia/src/demuxers/realmedia.rs | 35 +++++------ nihav-registry/src/detect.rs | 2 +- nihav-vivo/src/codecs/g723_1.rs | 4 +- nihav-vivo/src/codecs/vivo.rs | 2 +- nihav-vivo/src/demuxers/vivo.rs | 2 +- 59 files changed, 272 insertions(+), 366 deletions(-) diff --git a/nihav-codec-support/src/codecs/mod.rs b/nihav-codec-support/src/codecs/mod.rs index ebdbaa7..2bac7e2 100644 --- a/nihav-codec-support/src/codecs/mod.rs +++ b/nihav-codec-support/src/codecs/mod.rs @@ -25,6 +25,7 @@ use std::mem; /// shuffler.add_frame(frame.clone()); // tells frame manager to use the frame as the next reference /// ``` #[allow(dead_code)] +#[derive(Default)] pub struct HAMShuffler { lastframe: Option>, } @@ -62,10 +63,6 @@ impl HAMShuffler { } } -impl Default for HAMShuffler { - fn default() -> Self { Self { lastframe: None } } -} - /// Frame manager for codecs with intra and inter frames. /// /// This frame manager simplifies frame management for the case when codec decodes new frame using previous frame as source of some data. @@ -85,6 +82,7 @@ impl Default for HAMShuffler { /// shuffler.add_frame(frame.clone()); // tells frame manager to use the frame as the next reference /// ``` #[allow(dead_code)] +#[derive(Default)] pub struct IPShuffler { lastframe: Option>, } @@ -112,10 +110,6 @@ impl IPShuffler { } } -impl Default for IPShuffler { - fn default() -> Self { Self { lastframe: None } } -} - /// Frame manager for codecs with I-, P- and B-frames. /// /// This frame manager simplifies frame management for the case when codec uses I/P/B frame scheme. @@ -146,6 +140,7 @@ impl Default for IPShuffler { /// } /// ``` #[allow(dead_code)] +#[derive(Default)] pub struct IPBShuffler { lastframe: Option>, nextframe: Option>, @@ -202,10 +197,6 @@ impl IPBShuffler { } } -impl Default for IPBShuffler { - fn default() -> Self { Self { lastframe: None, nextframe: None } } -} - /// Motion vector data type. /// /// # Examples diff --git a/nihav-commonfmt/src/codecs/cinepakenc.rs b/nihav-commonfmt/src/codecs/cinepakenc.rs index 3269cf8..604bc87 100644 --- a/nihav-commonfmt/src/codecs/cinepakenc.rs +++ b/nihav-commonfmt/src/codecs/cinepakenc.rs @@ -925,9 +925,10 @@ impl NAEncoder for CinepakEncoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)), + ..Default::default() + }) }, NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Video(vinfo) => { diff --git a/nihav-commonfmt/src/codecs/jpeg.rs b/nihav-commonfmt/src/codecs/jpeg.rs index f9689a0..957104c 100644 --- a/nihav-commonfmt/src/codecs/jpeg.rs +++ b/nihav-commonfmt/src/codecs/jpeg.rs @@ -443,7 +443,7 @@ fn build_default_cb(dc: bool, idx: usize) -> DecoderResult> { if dc { generate_cb(&DC_LENS[idx], &DC_SYMS) } else { - generate_cb(&AC_LENS[idx], &AC_SYMS[idx]) + generate_cb(&AC_LENS[idx], AC_SYMS[idx]) } } diff --git a/nihav-commonfmt/src/codecs/pcm.rs b/nihav-commonfmt/src/codecs/pcm.rs index 29926a5..3bc67c0 100644 --- a/nihav-commonfmt/src/codecs/pcm.rs +++ b/nihav-commonfmt/src/codecs/pcm.rs @@ -189,9 +189,10 @@ impl NAEncoder for PCMEncoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 0, SND_S16P_FORMAT, 0)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 0, SND_S16P_FORMAT, 0)), + ..Default::default() + }) }, NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Audio(_) => { diff --git a/nihav-commonfmt/src/codecs/ts102366.rs b/nihav-commonfmt/src/codecs/ts102366.rs index 963f07d..a2ee21c 100644 --- a/nihav-commonfmt/src/codecs/ts102366.rs +++ b/nihav-commonfmt/src/codecs/ts102366.rs @@ -261,21 +261,17 @@ impl ACMode { chmap } fn is_3_x(self) -> bool { - match self { + matches!(self, ACMode::Mode3_0 | ACMode::Mode3_1 | - ACMode::Mode3_2 => true, - _ => false, - } + ACMode::Mode3_2) } fn is_surround(self) -> bool { - match self { + matches!(self, ACMode::Mode2_1 | ACMode::Mode3_1 | ACMode::Mode2_2 | - ACMode::Mode3_2 => true, - _ => false, - } + ACMode::Mode3_2) } } diff --git a/nihav-commonfmt/src/codecs/zmbvenc.rs b/nihav-commonfmt/src/codecs/zmbvenc.rs index b3f75bf..0c8b945 100644 --- a/nihav-commonfmt/src/codecs/zmbvenc.rs +++ b/nihav-commonfmt/src/codecs/zmbvenc.rs @@ -374,9 +374,10 @@ impl NAEncoder for ZMBVEncoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)), + ..Default::default() + }) }, NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Video(vinfo) => { diff --git a/nihav-commonfmt/src/demuxers/avi.rs b/nihav-commonfmt/src/demuxers/avi.rs index cc24fe3..2b89580 100644 --- a/nihav-commonfmt/src/demuxers/avi.rs +++ b/nihav-commonfmt/src/demuxers/avi.rs @@ -361,7 +361,7 @@ impl<'a> AVIDemuxer<'a> { if ret.is_err() { break; } let (csz, end) = ret.unwrap(); if end { - let _res = parse_idx1(&mut self.src, strmgr, seek_idx, csz, self.movi_pos, &mut self.key_offs); + let _res = parse_idx1(self.src, strmgr, seek_idx, csz, self.movi_pos, &mut self.key_offs); break; } rest_size -= csz; @@ -388,7 +388,7 @@ impl<'a> AVIDemuxer<'a> { start = 0; last_strm_no = stream_no; } - let ret = parse_odml_ix(&mut self.src, strmgr, seek_idx, stream_no, size, start); + let ret = parse_odml_ix(self.src, strmgr, seek_idx, stream_no, size, start); if let Ok(new_start) = ret { start = new_start; } else { diff --git a/nihav-commonfmt/src/demuxers/mov.rs b/nihav-commonfmt/src/demuxers/mov.rs index aea8ecb..ce2b0bf 100644 --- a/nihav-commonfmt/src/demuxers/mov.rs +++ b/nihav-commonfmt/src/demuxers/mov.rs @@ -92,8 +92,8 @@ fn print_cname(ctype: u32, size: u64, off: u64, depth: u8) { for _ in 0..depth { print!(" "); } let tag = [(ctype >> 24) as u8, (ctype >> 16) as u8, (ctype >> 8) as u8, ctype as u8]; let mut printable = true; - for &ch in tag.iter() { - if ch < 0x20 || ch > 0x7F { + for ch in tag.iter() { + if !(0x20..=0x7F).contains(ch) { printable = false; break; } @@ -113,7 +113,7 @@ macro_rules! read_chunk_list { validate!(self.depth < 32); let list_end = self.src.tell() + size; while self.src.tell() < list_end { - let ret = read_chunk_header(&mut self.src); + let ret = read_chunk_header(self.src); if ret.is_err() { break; } let (ctype, size) = ret.unwrap(); if self.print_chunks { @@ -284,7 +284,7 @@ fn read_cmov(dmx: &mut MOVDemuxer, strmgr: &mut StreamManager, size: u64) -> Dem fn read_ctab(dmx: &mut MOVDemuxer, _strmgr: &mut StreamManager, size: u64) -> DemuxerResult { let mut pal = [0; 1024]; - let size = read_palette(&mut dmx.src, size, &mut pal)?; + let size = read_palette(dmx.src, size, &mut pal)?; dmx.pal = Some(Arc::new(pal)); Ok(size) } @@ -305,7 +305,7 @@ fn skip_chunk_mov(_dmx: &mut MOVDemuxer, _strmgr: &mut StreamManager, _size: u64 fn read_trak(dmx: &mut MOVDemuxer, strmgr: &mut StreamManager, size: u64) -> DemuxerResult { let mut track = Track::new(dmx.cur_track as u32, dmx.tb_den); track.print_chunks = dmx.print_chunks; - track.read_trak(&mut dmx.src, size)?; + track.read_trak(dmx.src, size)?; validate!(track.tkhd_found && track.stsd_found); validate!(strmgr.get_stream_by_id(track.track_id).is_none()); dmx.cur_track += 1; @@ -351,7 +351,7 @@ fn read_traf(dmx: &mut MOVDemuxer, _strmgr: &mut StreamManager, size: u64) -> De } if let Some(track) = track { track.moof_off = dmx.moof_off; - track.read_traf(&mut dmx.src, size)?; + track.read_traf(dmx.src, size)?; Ok(size) } else { Ok(0) @@ -752,14 +752,12 @@ fn read_stsd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult }, }; track.tb_den = sample_rate; - track.raw_audio = match &fcc { + track.raw_audio = matches!(&fcc, b"NONE" | b"raw " | b"twos" | b"sowt" | b"in24" | b"in32" | b"fl32" | b"fl64" | b"ima4" | b"ms\x00\x02" | b"ms\x00\x21" | b"alaw" | b"ulaw" | - b"MAC3" | b"MAC6" => true, - _ => false, - }; + b"MAC3" | b"MAC6"); let ahdr = NAAudioInfo::new(sample_rate, nchannels as u8, soniton, block_align); let edata = parse_audio_edata(br, start_pos, size)?; codec_info = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), edata); @@ -1606,7 +1604,7 @@ impl<'a> DemuxCore<'a> for MOVDemuxer<'a> { let first = track.cur_sample == 0; if let Some((pts, offset, size)) = track.get_next_chunk() { self.cur_track = trk_no + 1; - return process_packet(&mut self.src, strmgr, track, pts, offset, size, first); + return process_packet(self.src, strmgr, track, pts, offset, size, first); } } } @@ -1621,7 +1619,7 @@ impl<'a> DemuxCore<'a> for MOVDemuxer<'a> { self.cur_track += 1; let first = track.cur_sample == 0; if let Some((pts, offset, size)) = track.get_next_chunk() { - return process_packet(&mut self.src, strmgr, track, pts, offset, size, first); + return process_packet(self.src, strmgr, track, pts, offset, size, first); } } Err(DemuxerError::EOF) @@ -1724,7 +1722,7 @@ impl<'a> MOVDemuxer<'a> { fn read_root(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<()> { self.depth = 0; while self.src.left() != 0 { - let ret = read_chunk_header(&mut self.src); + let ret = read_chunk_header(self.src); if ret.is_err() { break; } let (ctype, size) = ret.unwrap(); if self.print_chunks { @@ -1736,7 +1734,7 @@ impl<'a> MOVDemuxer<'a> { } let handler = ROOT_CHUNK_HANDLERS.iter().find(|x| x.ctype == ctype); let read_size; - if let Some(ref handler) = handler { + if let Some(handler) = handler { read_size = (handler.parse)(self, strmgr, size)?; } else { println!("skipping unknown chunk {:08X} size {}", ctype, size); diff --git a/nihav-commonfmt/src/demuxers/y4m.rs b/nihav-commonfmt/src/demuxers/y4m.rs index 93831e9..05157ca 100644 --- a/nihav-commonfmt/src/demuxers/y4m.rs +++ b/nihav-commonfmt/src/demuxers/y4m.rs @@ -91,7 +91,7 @@ impl<'a> Y4MDemuxer<'a> { let mut magic = [0u8; 10]; self.src.read_buf(&mut magic)?; validate!(&magic == b"YUV4MPEG2 "); - while let Ok((last, tok)) = read_token(&mut self.src) { + while let Ok((last, tok)) = read_token(self.src) { let (id, val) = tok.split_at(1); validate!(id.len() == 1); match id.bytes().next().unwrap() { diff --git a/nihav-commonfmt/src/muxers/avi.rs b/nihav-commonfmt/src/muxers/avi.rs index e094060..ac09974 100644 --- a/nihav-commonfmt/src/muxers/avi.rs +++ b/nihav-commonfmt/src/muxers/avi.rs @@ -224,10 +224,10 @@ impl<'a> MuxCore<'a> for AVIMuxer<'a> { }, _ => unreachable!(), }; - patch_size(&mut self.bw, strf_pos)?; - patch_size(&mut self.bw, strl_pos)?; + patch_size(self.bw, strf_pos)?; + patch_size(self.bw, strl_pos)?; } - patch_size(&mut self.bw, hdrl_pos)?; + patch_size(self.bw, hdrl_pos)?; self.data_pos = self.bw.tell() + 8; self.bw.write_buf(b"LIST\0\0\0\0movi")?; @@ -286,7 +286,7 @@ impl<'a> MuxCore<'a> for AVIMuxer<'a> { key: pkt.keyframe, pos: self.bw.tell() as u32, len: chunk_len }); - write_chunk_hdr(&mut self.bw, str.get_media_type(), str_num as u32)?; + write_chunk_hdr(self.bw, str.get_media_type(), str_num as u32)?; self.bw.write_u32le(chunk_len)?; self.bw.write_buf(pkt.get_buffer().as_slice())?; if (self.bw.tell() & 1) != 0 { @@ -298,18 +298,18 @@ impl<'a> MuxCore<'a> for AVIMuxer<'a> { Ok(()) } fn end(&mut self) -> MuxerResult<()> { - patch_size(&mut self.bw, self.data_pos)?; + patch_size(self.bw, self.data_pos)?; if !self.index.is_empty() { self.bw.write_buf(b"idx1")?; self.bw.write_u32le((self.index.len() * 16) as u32)?; for item in self.index.iter() { - write_chunk_hdr(&mut self.bw, item.stype, item.stream)?; + write_chunk_hdr(self.bw, item.stype, item.stream)?; self.bw.write_u32le(if item.key { 0x10 } else { 0 })?; self.bw.write_u32le(item.pos)?; self.bw.write_u32le(item.len)?; } } - patch_size(&mut self.bw, 8)?; + patch_size(self.bw, 8)?; let mut max_frames = 0; let mut max_size = 0; for stri in self.stream_info.iter() { diff --git a/nihav-commonfmt/src/muxers/wav.rs b/nihav-commonfmt/src/muxers/wav.rs index 49be5d6..1317b95 100644 --- a/nihav-commonfmt/src/muxers/wav.rs +++ b/nihav-commonfmt/src/muxers/wav.rs @@ -90,8 +90,8 @@ impl<'a> MuxCore<'a> for WAVMuxer<'a> { Ok(()) } fn end(&mut self) -> MuxerResult<()> { - patch_size(&mut self.bw, self.data_pos)?; - patch_size(&mut self.bw, 8)?; + patch_size(self.bw, self.data_pos)?; + patch_size(self.bw, 8)?; // todo patch avg_bytes_per_second if calculated // todo write fact value if calculated Ok(()) diff --git a/nihav-core/src/compr/deflate.rs b/nihav-core/src/compr/deflate.rs index b126661..71e0dfe 100644 --- a/nihav-core/src/compr/deflate.rs +++ b/nihav-core/src/compr/deflate.rs @@ -366,10 +366,7 @@ impl Inflate { } ///! Reports whether decoder has finished decoding the input. pub fn is_finished(&self) -> bool { - match self.state { - InflateState::End => true, - _ => false, - } + matches!(self.state, InflateState::End) } ///! Reports the current amount of bytes output into the destination buffer after the last run. pub fn get_current_output_size(&self) -> usize { self.output_idx } @@ -624,7 +621,7 @@ impl Inflate { let (lit_lengths, dist_lengths) = self.all_lengths.split_at(self.hlit); let mut lit_codes = [ShortCodebookDesc { code: 0, bits: 0 }; NUM_LITERALS]; - lengths_to_codes(&lit_lengths, &mut lit_codes)?; + lengths_to_codes(lit_lengths, &mut lit_codes)?; let mut cr = ShortCodebookDescReader::new(lit_codes.to_vec()); let ret = Codebook::new(&mut cr, CodebookMode::LSB); if ret.is_err() { return Err(DecompressError::InvalidHeader); } diff --git a/nihav-core/src/formats.rs b/nihav-core/src/formats.rs index 99370f9..c0027ec 100644 --- a/nihav-core/src/formats.rs +++ b/nihav-core/src/formats.rs @@ -148,35 +148,29 @@ pub enum NAChannelType { impl NAChannelType { /// Reports whether this is some center channel. pub fn is_center(self) -> bool { - match self { - NAChannelType::C => true, NAChannelType::Ch => true, - NAChannelType::Cl => true, NAChannelType::Ov => true, - NAChannelType::LFE => true, NAChannelType::LFE2 => true, - NAChannelType::Cs => true, NAChannelType::Chs => true, - _ => false, - } + matches!(self, + NAChannelType::C | NAChannelType::Ch | + NAChannelType::Cl | NAChannelType::Ov | + NAChannelType::LFE | NAChannelType::LFE2 | + NAChannelType::Cs | NAChannelType::Chs) } /// Reports whether this is some left channel. pub fn is_left(self) -> bool { - match self { - NAChannelType::L => true, NAChannelType::Ls => true, - NAChannelType::Lss => true, NAChannelType::Lc => true, - NAChannelType::Lh => true, NAChannelType::Lw => true, - NAChannelType::Lhs => true, NAChannelType::Ll => true, - NAChannelType::Lt => true, NAChannelType::Lo => true, - _ => false, - } + matches!(self, + NAChannelType::L | NAChannelType::Ls | + NAChannelType::Lss | NAChannelType::Lc | + NAChannelType::Lh | NAChannelType::Lw | + NAChannelType::Lhs | NAChannelType::Ll | + NAChannelType::Lt | NAChannelType::Lo) } /// Reports whether this is some right channel. pub fn is_right(self) -> bool { - match self { - NAChannelType::R => true, NAChannelType::Rs => true, - NAChannelType::Rss => true, NAChannelType::Rc => true, - NAChannelType::Rh => true, NAChannelType::Rw => true, - NAChannelType::Rhs => true, NAChannelType::Rl => true, - NAChannelType::Rt => true, NAChannelType::Ro => true, - _ => false, - } + matches!(self, + NAChannelType::R | NAChannelType::Rs | + NAChannelType::Rss | NAChannelType::Rc | + NAChannelType::Rh | NAChannelType::Rw | + NAChannelType::Rhs | NAChannelType::Rl | + NAChannelType::Rt | NAChannelType::Ro) } } @@ -400,17 +394,11 @@ impl ColorModel { } /// Reports whether the current colour model is RGB. pub fn is_rgb(self) -> bool { - match self { - ColorModel::RGB(_) => true, - _ => false, - } + matches!(self, ColorModel::RGB(_)) } /// Reports whether the current colour model is YUV. pub fn is_yuv(self) -> bool { - match self { - ColorModel::YUV(_) => true, - _ => false, - } + matches!(self, ColorModel::YUV(_)) } /// Returns short name for the current colour mode. pub fn get_short_name(self) -> &'static str { @@ -1029,7 +1017,7 @@ fn parse_yuv_format(s: &str) -> Result { let mut parse_end = components as usize; for ch in s.chars().skip(components as usize) { parse_end += 1; - if ch >= '0' && ch <= '9' { + if ('0'..='9').contains(&ch) { format = format * 10 + u32::from((ch as u8) - b'0'); if format > 444 { return Err(FormatParseError {}); } } else { @@ -1041,7 +1029,7 @@ fn parse_yuv_format(s: &str) -> Result { let depth = if s.len() == parse_end { 8 } else { let mut val = 0; for ch in s.chars().skip(parse_end) { - if ch >= '0' && ch <= '9' { + if ('0'..='9').contains(&ch) { val = val * 10 + ((ch as u8) - b'0'); if val > 16 { return Err(FormatParseError {}); } } else { diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 7a09be4..fbdbdf5 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -112,17 +112,11 @@ impl NACodecTypeInfo { } /// Reports whether the current stream is video stream. pub fn is_video(&self) -> bool { - match *self { - NACodecTypeInfo::Video(_) => true, - _ => false, - } + matches!(*self, NACodecTypeInfo::Video(_)) } /// Reports whether the current stream is audio stream. pub fn is_audio(&self) -> bool { - match *self { - NACodecTypeInfo::Audio(_) => true, - _ => false, - } + matches!(*self, NACodecTypeInfo::Audio(_)) } } @@ -560,10 +554,7 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result false, - _ => true, - }; + let unfit_elem_size = !matches!(fmt.get_elem_size(), 2 | 4); //todo semi-packed like NV12 if fmt.is_paletted() { @@ -827,11 +818,7 @@ pub type NACodecInfoRef = Arc; impl NACodecInfo { /// Constructs a new instance of `NACodecInfo`. pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option>) -> Self { - let extradata = match edata { - None => None, - Some(vec) => Some(Arc::new(vec)), - }; - NACodecInfo { name, properties: p, extradata } + NACodecInfo { name, properties: p, extradata: edata.map(Arc::new) } } /// Constructs a new reference-counted instance of `NACodecInfo`. pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option>>) -> Self { @@ -1145,7 +1132,7 @@ impl FromStr for NATimePoint { let mut mval = 0; let mut base = 0; for ch in val.chars() { - if ch >= '0' && ch <= '9' { + if ('0'..='9').contains(&ch) { mval = mval * 10 + u64::from((ch as u8) - b'0'); base += 1; if base > 3 { break; } diff --git a/nihav-core/src/io/codebook.rs b/nihav-core/src/io/codebook.rs index 0ec8883..6ea3b1e 100644 --- a/nihav-core/src/io/codebook.rs +++ b/nihav-core/src/io/codebook.rs @@ -144,7 +144,7 @@ pub trait CodebookReader { pub const TABLE_FILL_VALUE: u32 = 0x7F; const MAX_LUT_BITS: u8 = 10; -fn fill_lut_msb(table: &mut Vec, off: usize, +fn fill_lut_msb(table: &mut [u32], off: usize, code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult<()> { if !esc { let fill_len = lut_bits - bits; @@ -164,7 +164,7 @@ fn fill_lut_msb(table: &mut Vec, off: usize, Ok(()) } -fn fill_lut_lsb(table: &mut Vec, off: usize, +fn fill_lut_lsb(table: &mut [u32], off: usize, code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult<()> { if !esc { let fill_len = lut_bits - bits; @@ -184,7 +184,7 @@ fn fill_lut_lsb(table: &mut Vec, off: usize, Ok(()) } -fn fill_lut(table: &mut Vec, mode: CodebookMode, +fn fill_lut(table: &mut [u32], mode: CodebookMode, off: usize, code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult { match mode { CodebookMode::MSB => fill_lut_msb(table, off, code, bits, lut_bits, symidx, esc)?, @@ -346,7 +346,7 @@ impl Codebook { } for bucket in escape_list.values() { - build_esc_lut(&mut table, mode, &bucket)?; + build_esc_lut(&mut table, mode, bucket)?; } for i in 0..cb.len() { diff --git a/nihav-core/src/options.rs b/nihav-core/src/options.rs index d3d8be8..4e4c7aa 100644 --- a/nihav-core/src/options.rs +++ b/nihav-core/src/options.rs @@ -183,7 +183,7 @@ impl NAOptionDefinition { Ok(()) }, NAValue::String(ref cur_str) => { - if let NAOptionDefinitionType::String(Some(ref strings)) = self.opt_type { + if let NAOptionDefinitionType::String(Some(strings)) = self.opt_type { for str in strings.iter() { if cur_str == str { return Ok(()); @@ -205,7 +205,7 @@ impl fmt::Display for NAOptionDefinition { NAOptionDefinitionType::None => write!(f, "{}: {}", self.name, self.description), NAOptionDefinitionType::Bool => write!(f, "[no]{}: {}", self.name, self.description), NAOptionDefinitionType::String(ref str_list) => { - if let Some(ref opts) = str_list { + if let Some(opts) = str_list { write!(f, "{} {}: {}", self.name, opts.join("|"), self.description) } else { write!(f, "{} : {}", self.name, self.description) diff --git a/nihav-core/src/scale/mod.rs b/nihav-core/src/scale/mod.rs index 6bf6e27..6c1daa9 100644 --- a/nihav-core/src/scale/mod.rs +++ b/nihav-core/src/scale/mod.rs @@ -263,7 +263,7 @@ fn fmt_needs_scale(ifmt: &NAPixelFormaton, ofmt: &NAPixelFormaton) -> bool { fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, options: &[(String, String)]) -> ScaleResult> { let mut debug = false; for (name, value) in options.iter() { - if name == "debug" && (value == "" || value == "true") { + if name == "debug" && (value.is_empty() || value == "true") { debug = true; break; } @@ -283,7 +283,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option let needs_unpack = !ifmt.fmt.is_unpacked(); let needs_pack = !ofmt.fmt.is_unpacked(); let needs_convert = inname != outname; - let scale_before_cvt = is_better_fmt(&ifmt, &ofmt) && needs_convert + let scale_before_cvt = is_better_fmt(ifmt, ofmt) && needs_convert && (ofmt.fmt.get_max_subsampling() == 0); let needs_palettise = ofmt.fmt.palette; //todo stages for model and gamma conversion @@ -296,9 +296,9 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option println!("[adding unpack]"); } let new_stage = if !cur_fmt.fmt.is_paletted() { - Stage::new("unpack", &cur_fmt, &ofmt, options)? + Stage::new("unpack", &cur_fmt, ofmt, options)? } else { - Stage::new("depal", &cur_fmt, &ofmt, options)? + Stage::new("depal", &cur_fmt, ofmt, options)? }; cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); @@ -307,7 +307,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[adding scale]"); } - let new_stage = Stage::new("scale", &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new("scale", &cur_fmt, ofmt, options)?; cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); } @@ -319,7 +319,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[{}]", cvtname); } - let new_stage = Stage::new(&cvtname, &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new(&cvtname, &cur_fmt, ofmt, options)?; //todo if fails try converting via RGB or YUV cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); @@ -329,7 +329,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[adding scale]"); } - let new_stage = Stage::new("scale", &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new("scale", &cur_fmt, ofmt, options)?; cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); } @@ -337,7 +337,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[adding pack]"); } - let new_stage = Stage::new("pack", &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new("pack", &cur_fmt, ofmt, options)?; //cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); } @@ -345,7 +345,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[adding palettise]"); } - let new_stage = Stage::new("palette", &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new("palette", &cur_fmt, ofmt, options)?; //cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); } @@ -438,24 +438,22 @@ pub fn flip_picture(pic: &mut NABufferType) -> ScaleResult<()> { impl NAScale { /// Constructs a new `NAScale` instance. pub fn new(fmt_in: ScaleInfo, fmt_out: ScaleInfo) -> ScaleResult { - let pipeline; let just_convert = (fmt_in.width == fmt_out.width) && (fmt_in.height == fmt_out.height); - if fmt_in != fmt_out { - pipeline = build_pipeline(&fmt_in, &fmt_out, just_convert, &[])?; - } else { - pipeline = None; - } + let pipeline = if fmt_in != fmt_out { + build_pipeline(&fmt_in, &fmt_out, just_convert, &[])? + } else { + None + }; Ok(Self { fmt_in, fmt_out, just_convert, pipeline }) } /// Constructs a new `NAScale` instance taking into account provided options. pub fn new_with_options(fmt_in: ScaleInfo, fmt_out: ScaleInfo, options: &[(String, String)]) -> ScaleResult { - let pipeline; let just_convert = (fmt_in.width == fmt_out.width) && (fmt_in.height == fmt_out.height); - if fmt_in != fmt_out { - pipeline = build_pipeline(&fmt_in, &fmt_out, just_convert, options)?; - } else { - pipeline = None; - } + let pipeline = if fmt_in != fmt_out { + build_pipeline(&fmt_in, &fmt_out, just_convert, options)? + } else { + None + }; Ok(Self { fmt_in, fmt_out, just_convert, pipeline }) } /// Checks whether requested conversion operation is needed at all. diff --git a/nihav-core/src/scale/palette/mod.rs b/nihav-core/src/scale/palette/mod.rs index ce673ee..f70300f 100644 --- a/nihav-core/src/scale/palette/mod.rs +++ b/nihav-core/src/scale/palette/mod.rs @@ -14,7 +14,7 @@ impl Pixel { fn new(src: &[u8]) -> Self { Self { r: src[0], g: src[1], b: src[2] } } - fn to_rgb(&self) -> [u8; 3] { + fn to_rgb(self) -> [u8; 3] { [self.r, self.g, self.b] } fn dist(&self, pix: Pixel) -> u32 { diff --git a/nihav-core/src/soundcvt/mod.rs b/nihav-core/src/soundcvt/mod.rs index 891a58a..a9f16c6 100644 --- a/nihav-core/src/soundcvt/mod.rs +++ b/nihav-core/src/soundcvt/mod.rs @@ -29,15 +29,11 @@ enum ChannelOp { impl ChannelOp { fn is_remix(&self) -> bool { - match *self { - ChannelOp::Remix(_) => true, - ChannelOp::DupMono(_) => true, - _ => false, - } + matches! (*self, ChannelOp::Remix(_) | ChannelOp::DupMono(_)) } } -fn apply_channel_op(ch_op: &ChannelOp, src: &[T], dst: &mut Vec) { +fn apply_channel_op(ch_op: &ChannelOp, src: &[T], dst: &mut [T]) { match *ch_op { ChannelOp::Passthrough => { dst.copy_from_slice(src); @@ -51,7 +47,7 @@ fn apply_channel_op(ch_op: &ChannelOp, src: &[T], dst: &mut Vec) { }; } -fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut Vec) { +fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut [i32]) { if let ChannelOp::Remix(ref remix_mat) = ch_op { let sch = src.len(); for (out, coeffs) in dst.iter_mut().zip(remix_mat.chunks(sch)) { @@ -70,7 +66,7 @@ fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut Vec) { } } -fn remix_f32(ch_op: &ChannelOp, src: &[f32], dst: &mut Vec) { +fn remix_f32(ch_op: &ChannelOp, src: &[f32], dst: &mut [f32]) { if let ChannelOp::Remix(ref remix_mat) = ch_op { let sch = src.len(); for (out, coeffs) in dst.iter_mut().zip(remix_mat.chunks(sch)) { @@ -164,8 +160,8 @@ impl IntoFmt for T where U: FromFmt { trait SampleReader { - fn get_samples_i32(&self, pos: usize, dst: &mut Vec); - fn get_samples_f32(&self, pos: usize, dst: &mut Vec); + fn get_samples_i32(&self, pos: usize, dst: &mut [i32]); + fn get_samples_f32(&self, pos: usize, dst: &mut [f32]); } struct GenericSampleReader<'a, T:Copy> { @@ -174,14 +170,14 @@ struct GenericSampleReader<'a, T:Copy> { } impl<'a, T:Copy+IntoFmt+IntoFmt> SampleReader for GenericSampleReader<'a, T> { - fn get_samples_i32(&self, pos: usize, dst: &mut Vec) { + fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) { let mut off = pos; for el in dst.iter_mut() { *el = self.data[off].cvt_into(); off += self.stride; } } - fn get_samples_f32(&self, pos: usize, dst: &mut Vec) { + fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) { let mut off = pos; for el in dst.iter_mut() { *el = self.data[off].cvt_into(); @@ -196,14 +192,14 @@ struct S8SampleReader<'a> { } impl<'a> SampleReader for S8SampleReader<'a> { - fn get_samples_i32(&self, pos: usize, dst: &mut Vec) { + fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) { let mut off = pos; for el in dst.iter_mut() { *el = (self.data[off] ^ 0x80).cvt_into(); off += self.stride; } } - fn get_samples_f32(&self, pos: usize, dst: &mut Vec) { + fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) { let mut off = pos; for el in dst.iter_mut() { *el = (self.data[off] ^ 0x80).cvt_into(); @@ -224,7 +220,7 @@ impl<'a> PackedSampleReader<'a> { let bpp = (fmt.bits >> 3) as usize; Self { data, fmt, bpp } } - fn get_samples(&self, pos: usize, dst: &mut Vec) where u8: IntoFmt, i16: IntoFmt, i32: IntoFmt, f32: IntoFmt { + fn get_samples(&self, pos: usize, dst: &mut [T]) where u8: IntoFmt, i16: IntoFmt, i32: IntoFmt, f32: IntoFmt { let mut offset = pos * self.bpp * dst.len(); for el in dst.iter_mut() { @@ -255,10 +251,10 @@ impl<'a> PackedSampleReader<'a> { } impl SampleReader for PackedSampleReader<'_> { - fn get_samples_i32(&self, pos: usize, dst: &mut Vec) { + fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) { self.get_samples(pos, dst); } - fn get_samples_f32(&self, pos: usize, dst: &mut Vec) { + fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) { self.get_samples(pos, dst); } } diff --git a/nihav-duck/src/codecs/on2avc.rs b/nihav-duck/src/codecs/on2avc.rs index 69505cf..8a34655 100644 --- a/nihav-duck/src/codecs/on2avc.rs +++ b/nihav-duck/src/codecs/on2avc.rs @@ -237,7 +237,7 @@ impl AVCDecoder { first = false; } else { scale += i16::from(br.read_cb(&self.codebooks.scale_cb)?); - validate!((scale >= 0) && (scale < 128)); + validate!((0..128).contains(&scale)); } self.scales[cur_band] = scale as u8; cur_band += 1; diff --git a/nihav-duck/src/codecs/truemotion1.rs b/nihav-duck/src/codecs/truemotion1.rs index c64c2ec..717a32b 100644 --- a/nihav-duck/src/codecs/truemotion1.rs +++ b/nihav-duck/src/codecs/truemotion1.rs @@ -128,6 +128,7 @@ impl Default for DeltaTables { } } +#[derive(Default)] struct FrameBuf { last16: Option>, last24: Option>, @@ -160,12 +161,6 @@ impl FrameBuf { } } -impl Default for FrameBuf { - fn default() -> Self { - Self { last16: None, last24: None } - } -} - #[derive(Default)] struct TM1Decoder { info: NACodecInfoRef, @@ -616,8 +611,8 @@ impl NADecoder for TM1Decoder { self.blk_w = compr_info.block_w; self.blk_h = compr_info.block_h; - let mut mask = MaskState::new(is_intra && !is_sprite, &mask_bits, mask_row_size); - let mut index = IndexState::new(&index_bytes); + let mut mask = MaskState::new(is_intra && !is_sprite, mask_bits, mask_row_size); + let mut index = IndexState::new(index_bytes); let bufinfo; if !is_24bit { if let Some(mut buf) = self.lastframe.get16() { diff --git a/nihav-duck/src/codecs/vp56.rs b/nihav-duck/src/codecs/vp56.rs index 01e8171..2ab474b 100644 --- a/nihav-duck/src/codecs/vp56.rs +++ b/nihav-duck/src/codecs/vp56.rs @@ -633,7 +633,7 @@ impl VP56Decoder { self.fstate.last_idx = [24; 4]; for mb_x in 0..self.mb_w { self.fstate.mb_x = mb_x; - self.decode_mb(dframe, bc, &mut cr, br, &hdr, alpha)?; + self.decode_mb(dframe, bc, &mut cr, br, hdr, alpha)?; self.dc_pred.next_mb(); } self.dc_pred.update_row(); diff --git a/nihav-duck/src/codecs/vp6enc/mb.rs b/nihav-duck/src/codecs/vp6enc/mb.rs index 2d460f1..cd33f12 100644 --- a/nihav-duck/src/codecs/vp6enc/mb.rs +++ b/nihav-duck/src/codecs/vp6enc/mb.rs @@ -507,7 +507,7 @@ impl FrameEncoder { } fn motion_est_mb(src_mb: &ResidueMB, cur_blk: &mut [[u8; 64]; 6], mb: &mut InterMB, mv_search: &mut Box, mv_est: &mut MVEstimator, mb_x: usize, mb_y: usize) { src_mb.fill(cur_blk); - let (best_mv, _best_dist) = mv_search.search_mb(mv_est, &cur_blk, mb_x, mb_y); + let (best_mv, _best_dist) = mv_search.search_mb(mv_est, cur_blk, mb_x, mb_y); mb.mv[3] = best_mv; for i in 0..4 { diff --git a/nihav-duck/src/codecs/vp6enc/mod.rs b/nihav-duck/src/codecs/vp6enc/mod.rs index b6ce632..d706fe7 100644 --- a/nihav-duck/src/codecs/vp6enc/mod.rs +++ b/nihav-duck/src/codecs/vp6enc/mod.rs @@ -666,9 +666,10 @@ impl NAEncoder for VP6Encoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, self.flipped, YUV420_FORMAT)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, self.flipped, YUV420_FORMAT)), + ..Default::default() + }) }, NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Video(vinfo) => { diff --git a/nihav-duck/src/codecs/vp7.rs b/nihav-duck/src/codecs/vp7.rs index 2252e0d..5ca88c0 100644 --- a/nihav-duck/src/codecs/vp7.rs +++ b/nihav-duck/src/codecs/vp7.rs @@ -768,7 +768,7 @@ impl VP7Decoder { let refframe = (if use_last { self.shuf.get_last() } else { self.shuf.get_golden() }).unwrap(); let single_mv = self.mb_info[mb_x + mb_y * self.mb_w].mb_type != VPMBType::InterFourMV; let mut iidx = mb_x * 4 + mb_y * 4 * self.mv_stride; - let mut mc_buf = self.mc_buf.get_data_mut().unwrap(); + let mc_buf = self.mc_buf.get_data_mut().unwrap(); let dst = &mut dframe.data[0..]; let ystride = dframe.stride[0]; @@ -776,12 +776,12 @@ impl VP7Decoder { if pitch_smode == 0 { if single_mv { mc_block16x16(dst, yoff, ystride, mb_x * 16, mb_y * 16, - self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, &mut mc_buf); + self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, mc_buf); } else { for y in 0..4 { for x in 0..4 { mc_block4x4(dst, yoff + x * 4, ystride, mb_x * 16 + x * 4, mb_y * 16 + y * 4, - self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, &mut mc_buf); + self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, mc_buf); } yoff += 4 * ystride; iidx += self.mv_stride; @@ -791,14 +791,14 @@ impl VP7Decoder { if single_mv { mc_block_special(dst, yoff, ystride, mb_x * 16, mb_y * 16, self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, - refframe.clone(), 0, &mut mc_buf, 16, pitch_smode); + refframe.clone(), 0, mc_buf, 16, pitch_smode); } else { for y in 0..4 { for x in 0..4 { mc_block_special(dst, yoff + x * 4, ystride, mb_x * 16 + x * 4, mb_y * 16 + y * 4, self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, - refframe.clone(), 0, &mut mc_buf, 4, pitch_smode); + refframe.clone(), 0, mc_buf, 4, pitch_smode); } yoff += 4 * ystride; iidx += self.mv_stride; @@ -815,13 +815,13 @@ impl VP7Decoder { let chroma_mv = self.mvs[iidx]; if pitch_smode == 0 { - mc_block8x8(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf); - mc_block8x8(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, &mut mc_buf); + mc_block8x8(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf); + mc_block8x8(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, mc_buf); } else { mc_block_special(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, - refframe.clone(), 1, &mut mc_buf, 8, pitch_smode); + refframe.clone(), 1, mc_buf, 8, pitch_smode); mc_block_special(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, - refframe, 2, &mut mc_buf, 8, pitch_smode); + refframe, 2, mc_buf, 8, pitch_smode); } } else { for y in 0..2 { @@ -844,15 +844,15 @@ impl VP7Decoder { if pitch_smode == 0 { mc_block4x4(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, - chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf); + chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf); mc_block4x4(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, - chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf); + chroma_mv.x, chroma_mv.y, refframe.clone(), 2, mc_buf); } else { mc_block_special(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, - chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf, + chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf, 4, pitch_smode); mc_block_special(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, - chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf, + chroma_mv.x, chroma_mv.y, refframe.clone(), 2, mc_buf, 4, pitch_smode); } } @@ -1185,13 +1185,13 @@ impl NADecoder for VP7Decoder { let mut new_gf = supp.pool_u8.get_copy(&gf).unwrap(); let dframe = NASimpleVideoFrame::from_video_buf(&mut new_gf).unwrap(); let mut mb_idx = 0; - let mut mc_buf = self.mc_buf.get_data_mut().unwrap(); + let mc_buf = self.mc_buf.get_data_mut().unwrap(); for mb_y in 0..self.mb_h { for mb_x in 0..self.mb_w { if self.mb_info[mb_idx].upd_gf { - mc_block16x16(dframe.data, dframe.offset[0] + mb_x * 16 + mb_y * 16 * dframe.stride[0], dframe.stride[0], mb_x * 16, mb_y * 16, 0, 0, buf.clone(), 0, &mut mc_buf); - mc_block8x8(dframe.data, dframe.offset[1] + mb_x * 8 + mb_y * 8 * dframe.stride[1], dframe.stride[1], mb_x * 8, mb_y * 8, 0, 0, buf.clone(), 1, &mut mc_buf); - mc_block8x8(dframe.data, dframe.offset[2] + mb_x * 8 + mb_y * 8 * dframe.stride[2], dframe.stride[2], mb_x * 8, mb_y * 8, 0, 0, buf.clone(), 2, &mut mc_buf); + mc_block16x16(dframe.data, dframe.offset[0] + mb_x * 16 + mb_y * 16 * dframe.stride[0], dframe.stride[0], mb_x * 16, mb_y * 16, 0, 0, buf.clone(), 0, mc_buf); + mc_block8x8(dframe.data, dframe.offset[1] + mb_x * 8 + mb_y * 8 * dframe.stride[1], dframe.stride[1], mb_x * 8, mb_y * 8, 0, 0, buf.clone(), 1, mc_buf); + mc_block8x8(dframe.data, dframe.offset[2] + mb_x * 8 + mb_y * 8 * dframe.stride[2], dframe.stride[2], mb_x * 8, mb_y * 8, 0, 0, buf.clone(), 2, mc_buf); } mb_idx += 1; } diff --git a/nihav-duck/src/codecs/vp78dsp.rs b/nihav-duck/src/codecs/vp78dsp.rs index bc0bbb3..e69a5ab 100644 --- a/nihav-duck/src/codecs/vp78dsp.rs +++ b/nihav-duck/src/codecs/vp78dsp.rs @@ -230,7 +230,6 @@ macro_rules! load_pred4 { pub struct IPred4x4 {} impl IPred4x4 { pub fn ipred_dc(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) { - let dc; let mut dcsum = 0; for el in ipred.left.iter().take(4) { dcsum += u16::from(*el); @@ -238,7 +237,7 @@ impl IPred4x4 { for el in ipred.top.iter().take(4) { dcsum += u16::from(*el); } - dc = ((dcsum + (1 << 2)) >> 3) as u8; + let dc = ((dcsum + (1 << 2)) >> 3) as u8; for _ in 0..4 { let out = &mut dst[off..][..4]; for el in out.iter_mut() { diff --git a/nihav-duck/src/codecs/vp7enc/blocks.rs b/nihav-duck/src/codecs/vp7enc/blocks.rs index bfb8fbd..2276382 100644 --- a/nihav-duck/src/codecs/vp7enc/blocks.rs +++ b/nihav-duck/src/codecs/vp7enc/blocks.rs @@ -20,11 +20,7 @@ pub enum MBType { impl MBType { pub fn is_intra(&self) -> bool { - match *self { - MBType::Intra(_, _) | - MBType::Intra4x4(_, _, _) => true, - _ => false, - } + matches!(*self, MBType::Intra(_, _) | MBType::Intra4x4(_, _, _)) } pub fn get_last(&self) -> bool { match *self { diff --git a/nihav-duck/src/codecs/vp7enc/mb_coding.rs b/nihav-duck/src/codecs/vp7enc/mb_coding.rs index cf73d2d..8fc79ff 100644 --- a/nihav-duck/src/codecs/vp7enc/mb_coding.rs +++ b/nihav-duck/src/codecs/vp7enc/mb_coding.rs @@ -187,7 +187,7 @@ pub fn select_intra_mode(sblk: &SrcBlock, newblk: &mut SrcBlock, res: &mut Resid if y_best_dist > SMALL_DIST { res.reset(); - let dist4 = try_i4x4_pred(sblk.luma_blocks(), &mut i4_modes, res, &mut newblk.luma, &imctx, y_best_dist); + let dist4 = try_i4x4_pred(sblk.luma_blocks(), &mut i4_modes, res, &mut newblk.luma, imctx, y_best_dist); use_i4 = dist4 < y_best_dist; y_best_dist = y_best_dist.min(dist4); } diff --git a/nihav-duck/src/codecs/vp7enc/mod.rs b/nihav-duck/src/codecs/vp7enc/mod.rs index 67d4bed..8a31f10 100644 --- a/nihav-duck/src/codecs/vp7enc/mod.rs +++ b/nihav-duck/src/codecs/vp7enc/mod.rs @@ -267,9 +267,9 @@ impl NAEncoder for VP7Encoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, YUV420_FORMAT)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, YUV420_FORMAT)), + ..Default::default() }) }, NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Video(vinfo) => { diff --git a/nihav-duck/src/codecs/vp8.rs b/nihav-duck/src/codecs/vp8.rs index de5d32a..cc2b175 100644 --- a/nihav-duck/src/codecs/vp8.rs +++ b/nihav-duck/src/codecs/vp8.rs @@ -975,7 +975,7 @@ impl VP8Decoder { }.unwrap(); let single_mv = self.mb_info[mb_x + mb_y * self.mb_w].mb_type != VPMBType::InterFourMV; let mut iidx = mb_x * 4 + mb_y * 4 * self.mv_stride; - let mut mc_buf = self.mc_buf.get_data_mut().unwrap(); + let mc_buf = self.mc_buf.get_data_mut().unwrap(); let dst = &mut dframe.data[0..]; let ystride = dframe.stride[0]; @@ -983,20 +983,20 @@ impl VP8Decoder { if single_mv { if self.dstate.version == 0 { mc_block16x16(dst, yoff, ystride, mb_x * 16, mb_y * 16, - self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, &mut mc_buf); + self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, mc_buf); } else { mc_block16x16_bilin(dst, yoff, ystride, mb_x * 16, mb_y * 16, - self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, &mut mc_buf); + self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, mc_buf); } } else { for y in 0..4 { for x in 0..4 { if self.dstate.version == 0 { mc_block4x4(dst, yoff + x * 4, ystride, mb_x * 16 + x * 4, mb_y * 16 + y * 4, - self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, &mut mc_buf); + self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, mc_buf); } else { mc_block4x4_bilin(dst, yoff + x * 4, ystride, mb_x * 16 + x * 4, mb_y * 16 + y * 4, - self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, &mut mc_buf); + self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, mc_buf); } } yoff += 4 * ystride; @@ -1013,15 +1013,15 @@ impl VP8Decoder { let mut chroma_mv = self.mvs[iidx]; if self.dstate.version == 0 { - mc_block8x8(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf); - mc_block8x8(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, &mut mc_buf); + mc_block8x8(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf); + mc_block8x8(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, mc_buf); } else { if self.dstate.version == 3 { chroma_mv.x &= !7; chroma_mv.y &= !7; } - mc_block8x8_bilin(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf); - mc_block8x8_bilin(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, &mut mc_buf); + mc_block8x8_bilin(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf); + mc_block8x8_bilin(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, mc_buf); } } else { for y in 0..2 { @@ -1049,14 +1049,14 @@ impl VP8Decoder { if self.dstate.version == 0 { mc_block4x4(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, - chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf); + chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf); mc_block4x4(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, - chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf); + chroma_mv.x, chroma_mv.y, refframe.clone(), 2, mc_buf); } else { mc_block4x4_bilin(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, - chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf); + chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf); mc_block4x4_bilin(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4, - chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf); + chroma_mv.x, chroma_mv.y, refframe.clone(), 2, mc_buf); } } uoff += ustride * 4; diff --git a/nihav-flash/src/codecs/adpcmenc.rs b/nihav-flash/src/codecs/adpcmenc.rs index 92a292b..9cd04f7 100644 --- a/nihav-flash/src/codecs/adpcmenc.rs +++ b/nihav-flash/src/codecs/adpcmenc.rs @@ -63,9 +63,9 @@ impl NAEncoder for ADPCMEncoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, BLOCK_LEN)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, BLOCK_LEN)), + ..Default::default() }) }, NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Audio(ainfo) => { diff --git a/nihav-flash/src/codecs/asao.rs b/nihav-flash/src/codecs/asao.rs index 5fe8b40..ca71792 100644 --- a/nihav-flash/src/codecs/asao.rs +++ b/nihav-flash/src/codecs/asao.rs @@ -269,7 +269,7 @@ impl NADecoder for ASAODecoder { let dst = adata.get_data_mut().unwrap(); for (src, dst) in src.chunks_exact(PACKED_BLK_LEN).zip(dst.chunks_mut(BLOCK_LEN)) { - let mut br = BitReader::new(&src, BitReaderMode::LE); + let mut br = BitReader::new(src, BitReaderMode::LE); self.decode_block(&mut br, dst)?; } diff --git a/nihav-game/src/codecs/midivid3.rs b/nihav-game/src/codecs/midivid3.rs index 31b8618..7878f2b 100644 --- a/nihav-game/src/codecs/midivid3.rs +++ b/nihav-game/src/codecs/midivid3.rs @@ -275,7 +275,7 @@ fn decode_values(br: &mut BitReader, dst: &mut [i16], cb: &Codebook) -> Dec *el = 0; zero_run -= 1; } else { - let val = br.read_cb(&cb)? as u8; + let val = br.read_cb(cb)? as u8; if val == 0 { zero_run = if br.read_bool()? { br.read(6)? as usize + 8 diff --git a/nihav-game/src/codecs/vmd.rs b/nihav-game/src/codecs/vmd.rs index 25f8b6d..f3a1d87 100644 --- a/nihav-game/src/codecs/vmd.rs +++ b/nihav-game/src/codecs/vmd.rs @@ -519,8 +519,8 @@ impl NADecoder for VMDAudioDecoder { VMDAudioMode::DPCM => { let mut adata = abuf.get_abuf_i16().unwrap(); let off1 = adata.get_offset(1); - let mut dst = adata.get_data_mut().unwrap(); - self.decode_16bit(&mut dst, off1, &mut br, nblocks, mask)?; + let dst = adata.get_data_mut().unwrap(); + self.decode_16bit(dst, off1, &mut br, nblocks, mask)?; }, VMDAudioMode::U8 => { let mut adata = abuf.get_abuf_u8().unwrap(); diff --git a/nihav-game/src/codecs/vx.rs b/nihav-game/src/codecs/vx.rs index c13fc49..057f617 100644 --- a/nihav-game/src/codecs/vx.rs +++ b/nihav-game/src/codecs/vx.rs @@ -1197,10 +1197,10 @@ impl VXAudioDecoder { f0[i] = (pfilt[i] + f1 [i]) >> 1; f2[i] = (f1 [i] + cfilt[i]) >> 1; } - apply_lpc(&mut cur_buf[ 0..][..32], &prev_buf[128..], &mut self.lpc_hist, &f0); + apply_lpc(&mut cur_buf[ 0..][..32], &prev_buf[128..], &mut self.lpc_hist, &f0); apply_lpc(&mut cur_buf[32..][..32], &prev_buf[128 + 32..], &mut self.lpc_hist, &f1); apply_lpc(&mut cur_buf[64..][..32], &prev_buf[128 + 64..], &mut self.lpc_hist, &f2); - apply_lpc(&mut cur_buf[96..][..32], &prev_buf[128 + 96..], &mut self.lpc_hist, &cfilt); + apply_lpc(&mut cur_buf[96..][..32], &prev_buf[128 + 96..], &mut self.lpc_hist, cfilt); Ok(()) } fn decode_intra(&mut self, br: &mut ByteReader, val: u16) -> DecoderResult<()> { diff --git a/nihav-game/src/demuxers/smush.rs b/nihav-game/src/demuxers/smush.rs index e863118..6476184 100644 --- a/nihav-game/src/demuxers/smush.rs +++ b/nihav-game/src/demuxers/smush.rs @@ -577,7 +577,7 @@ impl<'a> DemuxCore<'a> for MCMPDemuxer<'a> { arate = self.src.read_u32le()?; validate!(arate > 0); } else { - parse_iact(&mut self.src, data_start, &mut arate, &mut abits, &mut chans, true)?; + parse_iact(self.src, data_start, &mut arate, &mut abits, &mut chans, true)?; } if chans == 2 { for (samp, pts) in self.samples.iter_mut().zip(self.pts.iter_mut()) { diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index e94704c..98f97eb 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -652,7 +652,7 @@ impl IMCDecoder { self.read_skip_flags(br)?; - let mut ch_data = &mut self.ch_data[ch]; + let ch_data = &mut self.ch_data[ch]; for band in 0..BANDS { ch_data.adj_floor[band] = ch_data.new_floor[band]; let band_w = IMC_BANDS[band + 1] - IMC_BANDS[band]; @@ -675,7 +675,7 @@ impl IMCDecoder { } if bits_freed < 0 { return Err(DecoderError::Bug); } - self.ba.adjust_bit_allocation(&mut ch_data, bits_freed); + self.ba.adjust_bit_allocation(ch_data, bits_freed); Ok(()) } diff --git a/nihav-indeo/src/codecs/indeo4.rs b/nihav-indeo/src/codecs/indeo4.rs index a7263c6..c20732a 100644 --- a/nihav-indeo/src/codecs/indeo4.rs +++ b/nihav-indeo/src/codecs/indeo4.rs @@ -186,7 +186,7 @@ impl IndeoXParser for Indeo4Parser { txtype = TxType::Transform8(TxParams8x8::new(qintra, qinter, scan)); } else if scan_idx < 10 { validate!(!tr.is_8x8()); - validate!((qmat_idx >= 15) && (qmat_idx < 22)); + validate!((15..22).contains(&qmat_idx)); let scan = INDEO4_SCANS_4X4[scan_idx - 5]; let qidx = INDEO4_Q4X4_IDX[qmat_idx - 15]; let qintra = INDEO4_Q4_INTRA[qidx]; @@ -240,7 +240,7 @@ impl IndeoXParser for Indeo4Parser { if pic_hdr.ftype.is_intra() { mb.mtype = MBType::Intra; } else if band.inherit_mv { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { mb.mtype = tileref.mb[mb_idx].mtype; } else { return Err(DecoderError::MissingReference); @@ -263,7 +263,7 @@ impl IndeoXParser for Indeo4Parser { mb.cbp = br.read(4)? as u8; } if band.inherit_qd { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { mb.qd = tileref.mb[mb_idx].qd; mb.q = calc_quant(band.quant, mb.qd); } else { @@ -278,7 +278,7 @@ impl IndeoXParser for Indeo4Parser { if mb.mtype != MBType::Intra { if band.inherit_mv { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { let mx = tileref.mb[mb_idx].mv_x; let my = tileref.mb[mb_idx].mv_y; if mv_scale == 0 { @@ -315,7 +315,7 @@ impl IndeoXParser for Indeo4Parser { mb.q = calc_quant(band.quant, mb.qd); } if band.inherit_mv { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { let mx = tileref.mb[mb_idx].mv_x; let my = tileref.mb[mb_idx].mv_y; if mv_scale == 0 { diff --git a/nihav-indeo/src/codecs/indeo5.rs b/nihav-indeo/src/codecs/indeo5.rs index 11d813d..0115b2a 100644 --- a/nihav-indeo/src/codecs/indeo5.rs +++ b/nihav-indeo/src/codecs/indeo5.rs @@ -278,7 +278,7 @@ impl IndeoXParser for Indeo5Parser { if pic_hdr.ftype.is_intra() { mb.mtype = MBType::Intra; } else if band.inherit_mv { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { mb.mtype = tileref.mb[mb_idx].mtype; } else { return Err(DecoderError::MissingReference); @@ -294,7 +294,7 @@ impl IndeoXParser for Indeo5Parser { let q; if band.has_qdelta { if band.inherit_qd { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { mb.qd = tileref.mb[mb_idx].qd; q = calc_quant(band.quant, mb.qd); } else { @@ -326,7 +326,7 @@ impl IndeoXParser for Indeo5Parser { if mb.mtype != MBType::Intra { if band.inherit_mv { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { let mx = tileref.mb[mb_idx].mv_x; let my = tileref.mb[mb_idx].mv_y; if mv_scale == 0 { @@ -367,7 +367,7 @@ impl IndeoXParser for Indeo5Parser { } } if band.inherit_mv { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { let mx = tileref.mb[mb_idx].mv_x; let my = tileref.mb[mb_idx].mv_y; if mv_scale == 0 { diff --git a/nihav-indeo/src/codecs/intel263.rs b/nihav-indeo/src/codecs/intel263.rs index c9bb5f4..da1c10b 100644 --- a/nihav-indeo/src/codecs/intel263.rs +++ b/nihav-indeo/src/codecs/intel263.rs @@ -329,7 +329,7 @@ impl BlockDSP for I263BlockDSP { } } -fn check_marker<'a>(br: &mut BitReader<'a>) -> DecoderResult<()> { +fn check_marker(br: &mut BitReader) -> DecoderResult<()> { let mark = br.read(1)?; validate!(mark == 1); Ok(()) diff --git a/nihav-indeo/src/codecs/ivibr.rs b/nihav-indeo/src/codecs/ivibr.rs index 8ce4d1b..e023bdb 100644 --- a/nihav-indeo/src/codecs/ivibr.rs +++ b/nihav-indeo/src/codecs/ivibr.rs @@ -258,7 +258,7 @@ fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tabl } } idx += run; - validate!((idx >= 0) && (idx < 64)); + validate!((0..64).contains(&idx)); let spos = tables.scan[idx as usize]; let q = (u32::from(quant_mat[spos]) * u32::from(quant)) >> 9; @@ -308,7 +308,7 @@ fn decode_block4x4(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tabl } } idx += run; - validate!((idx >= 0) && (idx < 16)); + validate!((0..16).contains(&idx)); let spos = tables.scan[idx as usize]; let q = (u32::from(quant_mat[spos]) * u32::from(quant)) >> 9; @@ -653,7 +653,7 @@ br.skip(skip_part as u32)?; mb.mtype = MBType::Inter; mb.cbp = 0; if band.inherit_mv { - if let Some(ref tileref) = ref_tile { + if let Some(tileref) = ref_tile { let mx = tileref.mb[mb_idx].mv_x; let my = tileref.mb[mb_idx].mv_y; mb.mv_x = scale_mv(mx, mv_scale); @@ -680,7 +680,7 @@ br.skip(skip_part as u32)?; let stride = frame.plane_stride[band.plane_no]; let mut dstidx = tile.pos_x + tile.pos_y * stride; - let mut dst = &mut frame.plane_buf[band.plane_no]; + let dst = &mut frame.plane_buf[band.plane_no]; let pos_x = tile.pos_x; let pos_y = tile.pos_y; let tile_w = (tile.w + 15) & !15; @@ -728,23 +728,23 @@ br.skip(skip_part as u32)?; if let TxType::Transform8(ref params) = band.ttype { decode_block8x8(br, &band.blk_cb, &band.rvmap, params, is_intra, band.tr.is_2d(), &mut prev_dc, mb.q, &mut blk, tr)?; if is_intra { - put_block(&mut dst, dstidx + boff, stride, &blk, 8); + put_block(dst, dstidx + boff, stride, &blk, 8); } else { - add_block(&mut dst, dstidx + boff, stride, &blk, 8); + add_block(dst, dstidx + boff, stride, &blk, 8); } } if let TxType::Transform4(ref params) = band.ttype { decode_block4x4(br, &band.blk_cb, &band.rvmap, params, is_intra, band.tr.is_2d(), &mut prev_dc, mb.q, &mut blk, tr)?; if is_intra { - put_block(&mut dst, dstidx + boff, stride, &blk, 4); + put_block(dst, dstidx + boff, stride, &blk, 4); } else { - add_block(&mut dst, dstidx + boff, stride, &blk, 4); + add_block(dst, dstidx + boff, stride, &blk, 4); } } } else { if is_intra { (transform_dc)(&mut blk, prev_dc); - put_block(&mut dst, dstidx + boff, stride, &blk, band.blk_size); + put_block(dst, dstidx + boff, stride, &blk, band.blk_size); } } cbp >>= 1; @@ -788,24 +788,24 @@ br.skip(skip_part as u32)?; } if is_intra { if band.blk_size == 8 { - put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8); + put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8); } else { - put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4); + put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4); } } else { if band.blk_size == 8 { - add_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8); + add_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8); } else { - add_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4); + add_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4); } } } else { if is_intra { (transform_dc)(&mut blk, prev_dc); if band.blk_size == 8 { - put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8); + put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8); } else { - put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4); + put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4); } } } diff --git a/nihav-llaudio/src/codecs/flacenc.rs b/nihav-llaudio/src/codecs/flacenc.rs index 55c7eb0..8b5b44d 100644 --- a/nihav-llaudio/src/codecs/flacenc.rs +++ b/nihav-llaudio/src/codecs/flacenc.rs @@ -396,9 +396,9 @@ impl NAEncoder for FLACEncoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)), + ..Default::default() }) }, NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Audio(ainfo) => { diff --git a/nihav-llaudio/src/demuxers/ape.rs b/nihav-llaudio/src/demuxers/ape.rs index c58915b..1da6cf2 100644 --- a/nihav-llaudio/src/demuxers/ape.rs +++ b/nihav-llaudio/src/demuxers/ape.rs @@ -39,7 +39,7 @@ impl<'a> DemuxCore<'a> for APEDemuxer<'a> { let tag = src.read_tag()?; validate!(&tag == b"MAC "); let version = src.read_u16le()?; - validate!(version >= 3800 && version <= 3990); + validate!((3800..=3990).contains(&version)); let seektab_len; let _wavtail_len; diff --git a/nihav-llaudio/src/demuxers/flacraw.rs b/nihav-llaudio/src/demuxers/flacraw.rs index e8d1f4a..c04f1f0 100644 --- a/nihav-llaudio/src/demuxers/flacraw.rs +++ b/nihav-llaudio/src/demuxers/flacraw.rs @@ -137,11 +137,7 @@ impl RawDemuxerCreator for FLACDemuxerCreator { if br.seek(SeekFrom::Start(0)).is_err() { return false; } - if let Ok([b'f', b'L', b'a', b'C']) = br.read_tag() { - true - } else { - false - } + matches!(br.read_tag(), Ok([b'f', b'L', b'a', b'C'])) } } diff --git a/nihav-ms/src/codecs/imaadpcmenc.rs b/nihav-ms/src/codecs/imaadpcmenc.rs index f142646..15e76fb 100644 --- a/nihav-ms/src/codecs/imaadpcmenc.rs +++ b/nihav-ms/src/codecs/imaadpcmenc.rs @@ -189,9 +189,9 @@ impl NAEncoder for IMAADPCMEncoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)), + ..Default::default() }) }, NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Audio(ainfo) => { diff --git a/nihav-ms/src/codecs/msadpcm.rs b/nihav-ms/src/codecs/msadpcm.rs index 6b6c63e..768eb74 100644 --- a/nihav-ms/src/codecs/msadpcm.rs +++ b/nihav-ms/src/codecs/msadpcm.rs @@ -310,9 +310,9 @@ impl NAEncoder for MSADPCMEncoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)), + ..Default::default() }) }, NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Audio(ainfo) => { diff --git a/nihav-ms/src/codecs/msvideo1enc.rs b/nihav-ms/src/codecs/msvideo1enc.rs index d716df0..9ebc896 100644 --- a/nihav-ms/src/codecs/msvideo1enc.rs +++ b/nihav-ms/src/codecs/msvideo1enc.rs @@ -10,7 +10,7 @@ impl Pixel16 { ((self.0 >> 10) & 0x1F, (self.0 >> 5) & 0x1F, self.0 & 0x1F) } fn pack(r: u16, g: u16, b: u16) -> Self { - Pixel16{ 0: (r << 10) | (g << 5) | b } + Pixel16((r << 10) | (g << 5) | b) } fn invalid() -> Self { Self(0x8000) } fn is_invalid(self) -> bool { self == Self::invalid() } @@ -146,7 +146,7 @@ impl BlockState { self.clr2[0] = clr0; self.clr2[1] = if !clr1.is_invalid() { clr1 } else { clr0 }; if clr0 == clr1 { - self.fill_val = Pixel16 { 0: buf[0].0 & !0x400 }; + self.fill_val = Pixel16(buf[0].0 & !0x400); filled = true; } two_clr = true; @@ -157,7 +157,7 @@ impl BlockState { for pix in buf.iter() { avg.add(*pix, 1); } - self.fill_val = Pixel16 { 0: avg.get_centroid().0 & !0x400 }; + self.fill_val = Pixel16(avg.get_centroid().0 & !0x400); for pix in buf.iter() { self.fill_dist += pix.dist(self.fill_val); } @@ -210,7 +210,7 @@ impl BlockState { return; } - self.clr8 = [[Pixel16 { 0: 0}; 2]; 4]; + self.clr8 = [[Pixel16(0); 2]; 4]; self.clr8_flags = 0; self.clr8_dist = 0; let mut mask = 1; @@ -315,7 +315,7 @@ impl MSVideo1Encoder { fn get_block(src: &[u16], sstride: usize, buf: &mut [Pixel16; 16]) { for (line, dst) in src.chunks(sstride).zip(buf.chunks_mut(4)) { for i in 0..4 { - dst[i] = Pixel16 { 0: line[i] }; + dst[i] = Pixel16(line[i]); } } } @@ -446,9 +446,9 @@ impl NAEncoder for MSVideo1Encoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, RGB555_FORMAT)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, RGB555_FORMAT)), + ..Default::default() }) }, NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Video(vinfo) => { diff --git a/nihav-qt/src/codecs/alac.rs b/nihav-qt/src/codecs/alac.rs index a4f959d..6443917 100644 --- a/nihav-qt/src/codecs/alac.rs +++ b/nihav-qt/src/codecs/alac.rs @@ -289,7 +289,7 @@ impl NADecoder for ALACDecoder { let version = br.read_byte()?; validate!(version == 0); let bits = br.read_byte()?; - validate!(bits >= 8 && bits <= 32); + validate!((8..=32).contains(&bits)); self.pb = br.read_byte()?; validate!(self.pb == 40); self.mb = br.read_byte()?; diff --git a/nihav-qt/src/codecs/qdm2fft.rs b/nihav-qt/src/codecs/qdm2fft.rs index 22ca5dc..2e6082c 100644 --- a/nihav-qt/src/codecs/qdm2fft.rs +++ b/nihav-qt/src/codecs/qdm2fft.rs @@ -263,7 +263,7 @@ impl QDM2FFT { br.read(2) as u8 } else { 0 }; - let mut amp = br.read_code(&level_cb)? as i8; + let mut amp = br.read_code(level_cb)? as i8; amp += self.fft_levels[LEVEL_INDEX[pos] as usize] as i8; if amp < 0 { amp = 0; @@ -300,7 +300,7 @@ impl QDM2FFT { match id { 17..=23 => { let grp = i16::from(self.subsampling) + 4 - i16::from(id - 17); - if grp >= 0 && grp < 5 { + if (0..5).contains(&grp) { self.read_tones(br, grp as usize, false)?; } }, @@ -311,7 +311,7 @@ impl QDM2FFT { }, 33..=39 => { let grp = i16::from(self.subsampling) + 4 - i16::from(id - 33); - if grp >= 0 && grp < 5 { + if (0..5).contains(&grp) { self.read_tones(br, grp as usize, true)?; } }, diff --git a/nihav-qt/src/codecs/qdmc.rs b/nihav-qt/src/codecs/qdmc.rs index 27ef4e6..e80e098 100644 --- a/nihav-qt/src/codecs/qdmc.rs +++ b/nihav-qt/src/codecs/qdmc.rs @@ -352,7 +352,7 @@ impl NADecoder for QdmcDecoder { let mut chunks = self.fft_buf[ch].chunks_mut(1 << self.frame_bits); let first = chunks.next().unwrap(); let second = chunks.next().unwrap(); - first.copy_from_slice(&second); + first.copy_from_slice(second); for el in second.iter_mut() { *el = FFTC_ZERO; } diff --git a/nihav-qt/src/codecs/svq3.rs b/nihav-qt/src/codecs/svq3.rs index 07331c6..a455ed5 100644 --- a/nihav-qt/src/codecs/svq3.rs +++ b/nihav-qt/src/codecs/svq3.rs @@ -602,7 +602,7 @@ println!("slice offset {}", _offset); if !is_4x4 || (hdr.dquant && hdr.ftype != FrameType::I && cbp != 0) { let dq = br.read_code_signed(IntCodeType::Gamma)?; let new_q = i32::from(sstate.q) + dq; - validate!(new_q >= 0 && new_q < 32); + validate!((0..32).contains(&new_q)); sstate.q = new_q as u8; } if !is_4x4 { @@ -857,7 +857,7 @@ println!("slice offset {}", _offset); if hdr.dquant && cbp != 0 { let dq = br.read_code_signed(IntCodeType::Gamma)?; let new_q = i32::from(sstate.q) + dq; - validate!(new_q >= 0 && new_q < 32); + validate!((0..32).contains(&new_q)); sstate.q = new_q as u8; } for sb in 0..4 { diff --git a/nihav-realmedia/src/codecs/ralf.rs b/nihav-realmedia/src/codecs/ralf.rs index 94443a9..154b80c 100644 --- a/nihav-realmedia/src/codecs/ralf.rs +++ b/nihav-realmedia/src/codecs/ralf.rs @@ -370,7 +370,7 @@ impl NADecoder for RALFDecoder { let _bits = br.read_u16be().unwrap(); let sample_rate = br.read_u32be().unwrap(); let max_frame_size = br.read_u32be().unwrap(); - validate!((channels == 1 || channels == 2) && (sample_rate >= 8000 && sample_rate <= 96000)); + validate!((channels == 1 || channels == 2) && (8000..=96000).contains(&sample_rate)); self.max_frame_size = max_frame_size.max(sample_rate) as usize; let ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), channels as u8, diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index 762d054..bbaabdf 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -91,18 +91,13 @@ impl MBType { } } pub fn is_fwd(self) -> bool { - match self { + matches!(self, MBType::MBP16x16 | MBType::MBP16x16Mix | MBType::MBP16x8 | MBType::MBP8x16 | MBType::MBP8x8 | - MBType::MBForward => true, - _ => false, - } + MBType::MBForward) } pub fn is_bwd(self) -> bool { - match self { - MBType::MBBidir | MBType::MBBackward => true, - _ => false, - } + matches!(self, MBType::MBBidir | MBType::MBBackward) } pub fn has_mv_dir(self, fwd: bool) -> bool { match self { @@ -113,10 +108,7 @@ impl MBType { } } pub fn is_nomv(self) -> bool { - match self { - MBType::MBIntra | MBType::MBIntra16 | MBType::MBSkip | MBType::MBDirect => true, - _ => false, - } + matches!(self, MBType::MBIntra | MBType::MBIntra16 | MBType::MBSkip | MBType::MBDirect) } /*pub fn is_16x16(self) -> bool { match self { @@ -1057,7 +1049,7 @@ impl RV34Decoder { } Ok(()) } - fn fill_deblock_flags(&self, sstate: &SState, mb_pos: usize, mbinfo: &mut Vec) { + fn fill_deblock_flags(&self, sstate: &SState, mb_pos: usize, mbinfo: &mut [RV34MBInfo]) { let mbt = mbinfo[mb_pos].mbtype; let mut hmvmask = 0; let mut vmvmask = 0; diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index 55faf03..bedebc9 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -306,16 +306,10 @@ impl PUType { } } fn has_hor_split(self) -> bool { - match self { - PUType::N2Hor | PUType::N4Hor | PUType::N34Hor | PUType::Quarters => true, - _ => false, - } + matches!(self, PUType::N2Hor | PUType::N4Hor | PUType::N34Hor | PUType::Quarters) } fn has_ver_split(self) -> bool { - match self { - PUType::N2Ver | PUType::N4Ver | PUType::N34Ver | PUType::Quarters => true, - _ => false, - } + matches!(self, PUType::N2Ver | PUType::N4Ver | PUType::N34Ver | PUType::Quarters) } } @@ -368,22 +362,13 @@ impl MVRef { } } fn is_ref0(self) -> bool { - match self { - MVRef::Ref0 | MVRef::Ref0AndBRef => true, - _ => false, - } + matches!(self, MVRef::Ref0 | MVRef::Ref0AndBRef) } fn is_fwd(self) -> bool { - match self { - MVRef::Ref0 | MVRef::Ref1 | MVRef::Ref0AndBRef => true, - _ => false, - } + matches!(self, MVRef::Ref0 | MVRef::Ref1 | MVRef::Ref0AndBRef) } fn is_bwd(self) -> bool { - match self { - MVRef::BRef | MVRef::Ref0AndBRef => true, - _ => false, - } + matches!(self, MVRef::BRef | MVRef::Ref0AndBRef) } } @@ -692,7 +677,7 @@ impl RealVideo60Decoder { let cu_w = hdr.get_width_cu(); let dqp = hdr.read_line_qp_offset(&mut br)?; let qps = (hdr.qp as i8) + dqp; - validate!((qps >= 0) && (qps < 32)); + validate!((0..32).contains(&qps)); let qp = qps as u8; self.qp = qp; self.sel_qp = match hdr.osvquant { @@ -765,9 +750,9 @@ println!(" left {} bits", br.left()); let dstride = buf.stride[comp]; let soff = buf.offset[comp]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; + let dst = &mut buf.data; self.populate_ipred(hdr, dst, soff, dstride, 0, 0, size >> 1, false); - self.ipred.pred_angle(&mut dst, off, dstride, size >> 1, itype as usize, false); + self.ipred.pred_angle(dst, off, dstride, size >> 1, itype as usize, false); } }, _ => { @@ -866,8 +851,8 @@ println!(" left {} bits", br.left()); self.dsp.transform4x4(&mut self.y_coeffs[i * 16..][..16]); let dstride = buf.stride[0]; let off = xpos + x * 4 + (ypos + y * 4) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs[i*16..][..16], 4); + let dst = &mut buf.data; + self.dsp.add_block(dst, off, dstride, &self.y_coeffs[i*16..][..16], 4); } } } @@ -880,15 +865,15 @@ println!(" left {} bits", br.left()); self.dsp.transform4x4(&mut self.u_coeffs[i * 16..][..16]); let dstride = buf.stride[1]; let off = buf.offset[1] + xoff + yoff * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs[i * 16..][..16], 4); + let dst = &mut buf.data; + self.dsp.add_block(dst, off, dstride, &self.u_coeffs[i * 16..][..16], 4); } if ((cbp16 >> (20 + i)) & 1) != 0 { self.dsp.transform4x4(&mut self.v_coeffs[i * 16..][..16]); let dstride = buf.stride[2]; let off = buf.offset[2] + xoff + yoff * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs[i * 16..][..16], 4); + let dst = &mut buf.data; + self.dsp.add_block(dst, off, dstride, &self.v_coeffs[i * 16..][..16], 4); } } } @@ -905,10 +890,10 @@ println!(" left {} bits", br.left()); if split_i4x4 { let dstride = buf.stride[0]; let off = xpos + xoff + (ypos + yoff) * dstride; - let mut dst = &mut buf.data; + let dst = &mut buf.data; self.populate_ipred(hdr, dst, 0, dstride, xoff, yoff, 4, true); let itype = self.blk_info[self.blk_pos + (i & 1) + (i >> 1) * self.blk_stride].imode; - self.ipred.pred_angle(&mut dst, off, dstride, 4, itype as usize, false); + self.ipred.pred_angle(dst, off, dstride, 4, itype as usize, false); } if ((cbp8 >> i) & 1) != 0 { let blk = &mut self.y_coeffs[i * 16..][..16]; @@ -916,8 +901,7 @@ println!(" left {} bits", br.left()); let dstride = buf.stride[0]; let soff = buf.offset[0]; let off = soff + xpos + xoff + (ypos + yoff) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, blk, 4); + self.dsp.add_block(buf.data, off, dstride, blk, 4); } } if ((cbp8 >> 4) & 1) != 0 { @@ -925,16 +909,14 @@ println!(" left {} bits", br.left()); let dstride = buf.stride[1]; let soff = buf.offset[1]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 4); + self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 4); } if ((cbp8 >> 5) & 1) != 0 { self.dsp.transform4x4(&mut self.v_coeffs); let dstride = buf.stride[2]; let soff = buf.offset[2]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 4); + self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 4); } } }, @@ -948,24 +930,21 @@ println!(" left {} bits", br.left()); self.dsp.transform8x8(&mut self.y_coeffs); let dstride = buf.stride[0]; let off = xpos + ypos * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs, 8); + self.dsp.add_block(buf.data, off, dstride, &self.y_coeffs, 8); } if ((cbp8 >> 4) & 1) != 0 { self.dsp.transform4x4(&mut self.u_coeffs); let dstride = buf.stride[1]; let soff = buf.offset[1]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 4); + self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 4); } if ((cbp8 >> 5) & 1) != 0 { self.dsp.transform4x4(&mut self.v_coeffs); let dstride = buf.stride[2]; let soff = buf.offset[2]; let off = soff + (xpos >> 1) + (ypos >> 1) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 4); + self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 4); } } }, @@ -990,24 +969,21 @@ println!(" left {} bits", br.left()); self.dsp.transform16x16(&mut self.y_coeffs); let dstride = buf.stride[0]; let off = xpos + x * 16 + (ypos + y * 16) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs, 16); + self.dsp.add_block(buf.data, off, dstride, &self.y_coeffs, 16); } if ((super_cbp >> 16) & 0xF) != 0 { self.dsp.transform8x8(&mut self.u_coeffs); let dstride = buf.stride[1]; let soff = buf.offset[1]; let off = soff + (xpos >> 1) + x * 8 + ((ypos >> 1) + y * 8) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 8); + self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 8); } if ((super_cbp >> 20) & 0xF) != 0 { self.dsp.transform8x8(&mut self.v_coeffs); let dstride = buf.stride[2]; let soff = buf.offset[2]; let off = soff + (xpos >> 1) + x * 8 + ((ypos >> 1) + y * 8) * dstride; - let mut dst = &mut buf.data; - self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 8); + self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 8); } } } diff --git a/nihav-realmedia/src/demuxers/realmedia.rs b/nihav-realmedia/src/demuxers/realmedia.rs index f508c6a..f889284 100644 --- a/nihav-realmedia/src/demuxers/realmedia.rs +++ b/nihav-realmedia/src/demuxers/realmedia.rs @@ -154,8 +154,8 @@ impl RMAudioStream { let bsize = iinfo.block_size as usize; let ppos = self.sub_packet; for sb in 0..halffact { - let mut dst = &mut self.buf[sb * 2 * fsize + ppos * bsize..][..bsize]; - src.read_buf(&mut dst)?; + let dst = &mut self.buf[sb * 2 * fsize + ppos * bsize..][..bsize]; + src.read_buf(dst)?; } self.sub_packet += 1; if self.sub_packet == factor { @@ -175,8 +175,8 @@ impl RMAudioStream { for sb in 0..factor2 { let sb_pos = factor * sb + ((factor + 1) >> 1) * (ppos & 1) + (ppos >> 1); - let mut dst = &mut self.buf[bsize * sb_pos..][..bsize]; - src.read_buf(&mut dst)?; + let dst = &mut self.buf[bsize * sb_pos..][..bsize]; + src.read_buf(dst)?; } }, Deinterleaver::Sipro => { @@ -184,8 +184,8 @@ impl RMAudioStream { let fsize = iinfo.frame_size as usize; let ppos = self.sub_packet; - let mut dst = &mut self.buf[fsize * ppos..][..fsize]; - src.read_buf(&mut dst)?; + let dst = &mut self.buf[fsize * ppos..][..fsize]; + src.read_buf(dst)?; }, Deinterleaver::VBR => { validate!(payload_size >= 5); @@ -731,7 +731,7 @@ impl<'a> DemuxCore<'a> for RealMediaDemuxer<'a> { //todo skip unwanted packet let keyframe = (flags & KEYFRAME_FLAG) != 0; - let ret = RMDemuxCommon::parse_packet_payload(&mut self.src, &mut self.str_data.streams[str_id], stream, &mut self.slice_buf, &mut self.queued_pkts, keyframe, ts, payload_size); + let ret = RMDemuxCommon::parse_packet_payload(self.src, &mut self.str_data.streams[str_id], stream, &mut self.slice_buf, &mut self.queued_pkts, keyframe, ts, payload_size); if let Err(DemuxerError::TryAgain) = ret { continue; } else { @@ -1210,13 +1210,13 @@ impl<'a> DemuxCore<'a> for RealAudioDemuxer<'a> { let ver = self.src.read_u16be()?; let ainfo = match ver { 3 => { - parse_aformat3(&mut self.src)? + parse_aformat3(self.src)? }, 4 => { - parse_aformat4(&mut self.src)? + parse_aformat4(self.src)? }, 5 => { - parse_aformat5(&mut self.src)? + parse_aformat5(self.src)? }, _ => { println!("unknown version {}", ver); @@ -1266,7 +1266,7 @@ println!(" got ainfo {:?}", ainfo); let stream = streamres.unwrap(); if let Some(ref mut astr) = self.stream { loop { - let ret = astr.read_apackets(&mut self.queued_pkts, &mut self.src, stream.clone(), 0, false, self.blk_size); + let ret = astr.read_apackets(&mut self.queued_pkts, self.src, stream.clone(), 0, false, self.blk_size); if let Err(DemuxerError::TryAgain) = ret { continue; } @@ -1371,10 +1371,7 @@ impl IVRRecord { } } fn is_data_start(&self) -> bool { - match *self { - IVRRecord::DataStart => true, - _ => false, - } + matches!(*self, IVRRecord::DataStart) } } @@ -1560,13 +1557,13 @@ impl<'a> DemuxCore<'a> for RealIVRDemuxer<'a> { let magic = self.src.peek_u32be()?; if magic == mktag!(b".REC") { let mut rec = RecordDemuxer::new(0, 0); - rec.parse_header(&mut self.src, strmgr, &mut self.str_data)?; + rec.parse_header(self.src, strmgr, &mut self.str_data)?; self.recs.push(rec); } else if magic == mktag!(b".R1M") { println!("R1M kind"); self.src.read_skip(4)?; // magic self.src.read_skip(3)?; // always 0, 1, 1 ? - let _name = IVRRecord::read_string(&mut self.src)?; + let _name = IVRRecord::read_string(self.src)?; self.src.read_skip(1)?; // always 0? let len1 = self.src.read_u32be()? as u64; let off1 = self.src.read_u64be()?; @@ -1587,7 +1584,7 @@ println!("R1M kind"); if len > 0x20 { let num_streams = self.str_data.streams.len() as u32; let mut rec = RecordDemuxer::new(pos + 12, num_streams); - rec.parse_header(&mut self.src, strmgr, &mut self.str_data)?; + rec.parse_header(self.src, strmgr, &mut self.str_data)?; self.recs.push(rec); } self.src.seek(SeekFrom::Start(pos + len))?; @@ -1618,7 +1615,7 @@ println!("R1M kind"); } loop { if self.cur_rec >= self.recs.len() { return Err(DemuxerError::EOF); } - let res = self.recs[self.cur_rec].get_packet(&mut self.src, &mut self.str_data, strmgr, &mut self.queued_pkts, &mut self.slice_buf); + let res = self.recs[self.cur_rec].get_packet(self.src, &mut self.str_data, strmgr, &mut self.queued_pkts, &mut self.slice_buf); if let Err(DemuxerError::EOF) = res { self.cur_rec += 1; } else { diff --git a/nihav-registry/src/detect.rs b/nihav-registry/src/detect.rs index f79d063..f273121 100644 --- a/nihav-registry/src/detect.rs +++ b/nihav-registry/src/detect.rs @@ -169,7 +169,7 @@ enum CC<'a> { impl<'a> CC<'a> { fn eval(&self, src: &mut ByteReader) -> bool { match *self { - CC::Or (ref a, ref b) => { a.eval(src) || b.eval(src) }, + CC::Or(a, b) => { a.eval(src) || b.eval(src) }, CC::Eq(ref arg) => { arg.eq(src) }, CC::In(ref a, ref b) => { a.ge(src) && b.le(src) }, CC::Lt(ref arg) => { arg.lt(src) }, diff --git a/nihav-vivo/src/codecs/g723_1.rs b/nihav-vivo/src/codecs/g723_1.rs index 2f650d8..da00042 100644 --- a/nihav-vivo/src/codecs/g723_1.rs +++ b/nihav-vivo/src/codecs/g723_1.rs @@ -938,9 +938,9 @@ impl NADecoder for G7231Decoder { let abuf = alloc_audio_buffer(self.ainfo, SAMPLES, self.chmap.clone())?; let mut adata = abuf.get_abuf_i16().unwrap(); - let mut asamples = adata.get_data_mut().unwrap(); + let asamples = adata.get_data_mut().unwrap(); if self.cur_ftype == G7231FrameType::Active { - self.synth_frame_active(&mut asamples, bad_frame); + self.synth_frame_active(asamples, bad_frame); } else { self.synth_frame_other(); } diff --git a/nihav-vivo/src/codecs/vivo.rs b/nihav-vivo/src/codecs/vivo.rs index 64af5ff..2e73b3b 100644 --- a/nihav-vivo/src/codecs/vivo.rs +++ b/nihav-vivo/src/codecs/vivo.rs @@ -272,7 +272,7 @@ struct VivoBR<'a> { aic: bool, } -fn check_marker<'a>(br: &mut BitReader<'a>) -> DecoderResult<()> { +fn check_marker(br: &mut BitReader) -> DecoderResult<()> { let mark = br.read(1)?; validate!(mark == 1); Ok(()) diff --git a/nihav-vivo/src/demuxers/vivo.rs b/nihav-vivo/src/demuxers/vivo.rs index cd8e97d..5d455b6 100644 --- a/nihav-vivo/src/demuxers/vivo.rs +++ b/nihav-vivo/src/demuxers/vivo.rs @@ -38,7 +38,7 @@ impl<'a> DemuxCore<'a> for VivoDemuxer<'a> { let hdr = self.src.peek_byte()?; if (hdr & 0xF0) != 0 { break; } self.src.read_skip(1)?; - let hdr_len = read_size(&mut self.src)?; + let hdr_len = read_size(self.src)?; hdr_data.resize(hdr_len, 0); self.src.read_buf(&mut hdr_data)?; self.parse_header_packet(&hdr_data)?; -- 2.39.5