From: Kostya Shishkov Date: Tue, 16 Jun 2020 12:14:24 +0000 (+0200) Subject: realmedia: fix or silence clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=fa57381ec2a3b8c441aa1388492b9ca037cfcf78;p=nihav.git realmedia: fix or silence clippy warnings --- diff --git a/nihav-realmedia/src/codecs/cook.rs b/nihav-realmedia/src/codecs/cook.rs index b4e2ea9..2ac7a66 100644 --- a/nihav-realmedia/src/codecs/cook.rs +++ b/nihav-realmedia/src/codecs/cook.rs @@ -456,7 +456,7 @@ impl CookChannelPair { *out *= cur_gain; cur_gain *= cur_gain2; } - for i in 0..self.samples { self.delay[ch][i] = dsp.out[i]; } + self.delay[ch][..self.samples].copy_from_slice(&dsp.out[..self.samples]); } Ok(()) } diff --git a/nihav-realmedia/src/codecs/mod.rs b/nihav-realmedia/src/codecs/mod.rs index cbcdb83..b8ad7be 100644 --- a/nihav-realmedia/src/codecs/mod.rs +++ b/nihav-realmedia/src/codecs/mod.rs @@ -41,6 +41,7 @@ pub mod rv60codes; pub mod rv60dsp; #[cfg(feature="decoder_realaudio144")] +#[allow(clippy::manual_memcpy)] pub mod ra144; #[cfg(feature="decoder_realaudio288")] pub mod ra288; diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index 8da291b..f9a1817 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -699,13 +699,13 @@ fn decode_mv(br: &mut BitReader) -> DecoderResult { Ok(MV{ x, y }) } -fn do_mc_16x16(dsp: &Box, buf: &mut NAVideoBuffer, prevbuf: &NAVideoBuffer, mb_x: usize, mb_y: usize, mv: MV, avg: bool) { +fn do_mc_16x16(dsp: &mut dyn RV34DSP, buf: &mut NAVideoBuffer, prevbuf: &NAVideoBuffer, mb_x: usize, mb_y: usize, mv: MV, avg: bool) { dsp.do_luma_mc (buf, prevbuf, mb_x * 16, mb_y * 16, mv, true, avg); dsp.do_chroma_mc(buf, prevbuf, mb_x * 8, mb_y * 8, 1, mv, true, avg); dsp.do_chroma_mc(buf, prevbuf, mb_x * 8, mb_y * 8, 2, mv, true, avg); } -fn do_mc_8x8(dsp: &Box, buf: &mut NAVideoBuffer, prevbuf: &NAVideoBuffer, mb_x: usize, xoff: usize, mb_y: usize, yoff: usize, mv: MV, avg: bool) { +fn do_mc_8x8(dsp: &mut dyn RV34DSP, buf: &mut NAVideoBuffer, prevbuf: &NAVideoBuffer, mb_x: usize, xoff: usize, mb_y: usize, yoff: usize, mv: MV, avg: bool) { dsp.do_luma_mc (buf, prevbuf, mb_x * 16 + xoff * 8, mb_y * 16 + yoff * 8, mv, false, avg); dsp.do_chroma_mc(buf, prevbuf, mb_x * 8 + xoff * 4, mb_y * 8 + yoff * 4, 1, mv, false, avg); dsp.do_chroma_mc(buf, prevbuf, mb_x * 8 + xoff * 4, mb_y * 8 + yoff * 4, 2, mv, false, avg); @@ -924,19 +924,19 @@ impl RV34Decoder { MBType::MBP16x16 | MBType::MBP16x16Mix => { if let Some(ref prevbuf) = self.ipbs.get_lastref() { let mv = self.mvi.get_mv(mb_x, mb_y, 0, 0, true); - do_mc_16x16(&self.dsp, buf, prevbuf, mb_x, mb_y, mv, false); + do_mc_16x16(self.dsp.as_mut(), buf, prevbuf, mb_x, mb_y, mv, false); } }, MBType::MBForward => { if let Some(ref fwdbuf) = self.ipbs.get_b_fwdref() { let mv = self.mvi.get_mv(mb_x, mb_y, 0, 0, true); - do_mc_16x16(&self.dsp, buf, fwdbuf, mb_x, mb_y, mv, false); + do_mc_16x16(self.dsp.as_mut(), buf, fwdbuf, mb_x, mb_y, mv, false); } }, MBType::MBBackward => { if let Some(ref bwdbuf) = self.ipbs.get_b_bwdref() { let mv = self.mvi.get_mv(mb_x, mb_y, 0, 0, false); - do_mc_16x16(&self.dsp, buf, bwdbuf, mb_x, mb_y, mv, false); + do_mc_16x16(self.dsp.as_mut(), buf, bwdbuf, mb_x, mb_y, mv, false); } }, MBType::MBP8x8 | MBType::MBP8x16 | MBType::MBP16x8 => { @@ -944,14 +944,14 @@ impl RV34Decoder { for y in 0..2 { for x in 0..2 { let mv = self.mvi.get_mv(mb_x, mb_y, x, y, true); - do_mc_8x8(&self.dsp, buf, prevbuf, mb_x, x, mb_y, y, mv, false); + do_mc_8x8(self.dsp.as_mut(), buf, prevbuf, mb_x, x, mb_y, y, mv, false); } } } }, MBType::MBSkip if !self.is_b => { if let Some(ref prevbuf) = self.ipbs.get_lastref() { - do_mc_16x16(&self.dsp, buf, prevbuf, mb_x, mb_y, ZERO_MV, false); + do_mc_16x16(self.dsp.as_mut(), buf, prevbuf, mb_x, mb_y, ZERO_MV, false); } }, MBType::MBSkip | MBType::MBDirect => { @@ -959,8 +959,8 @@ impl RV34Decoder { for y in 0..2 { for x in 0..2 { let (mv_f, mv_b) = self.ref_mvi.get_mv(mb_x, mb_y, x, y, true).scale(sstate.trd, sstate.trb); - do_mc_8x8(&self.dsp, buf, fwdbuf, mb_x, x, mb_y, y, mv_f, false); - do_mc_8x8(&self.dsp, &mut self.avg_buf, bwdbuf, mb_x, x, mb_y, y, mv_b, true); + do_mc_8x8(self.dsp.as_mut(), buf, fwdbuf, mb_x, x, mb_y, y, mv_f, false); + do_mc_8x8(self.dsp.as_mut(), &mut self.avg_buf, bwdbuf, mb_x, x, mb_y, y, mv_b, true); do_avg(&self.cdsp, buf, &self.avg_buf, mb_x, x, mb_y, y, 8, self.ratio1, self.ratio2); } } @@ -970,8 +970,8 @@ impl RV34Decoder { if let (Some(ref fwdbuf), Some(ref bwdbuf)) = (self.ipbs.get_b_fwdref(), self.ipbs.get_b_bwdref()) { let mv_f = self.mvi.get_mv(mb_x, mb_y, 0, 0, true); let mv_b = self.mvi.get_mv(mb_x, mb_y, 0, 0, false); - do_mc_16x16(&self.dsp, buf, fwdbuf, mb_x, mb_y, mv_f, false); - do_mc_16x16(&self.dsp, &mut self.avg_buf, bwdbuf, mb_x, mb_y, mv_b, true); + do_mc_16x16(self.dsp.as_mut(), buf, fwdbuf, mb_x, mb_y, mv_f, false); + do_mc_16x16(self.dsp.as_mut(), &mut self.avg_buf, bwdbuf, mb_x, mb_y, mv_b, true); do_avg(&self.cdsp, buf, &self.avg_buf, mb_x, 0, mb_y, 0, 16, self.ratio1, self.ratio2); } }, @@ -1095,6 +1095,7 @@ impl RV34Decoder { } } + #[allow(clippy::cyclomatic_complexity)] pub fn parse_frame(&mut self, supp: &mut NADecoderSupport, src: &[u8], bd: &mut RV34BitstreamDecoder) -> DecoderResult<(NABufferType, FrameType, u64)> { let mut slice_offs: Vec = Vec::new(); parse_slice_offsets(src, &mut slice_offs)?; diff --git a/nihav-realmedia/src/codecs/rv30dsp.rs b/nihav-realmedia/src/codecs/rv30dsp.rs index 6065f7e..ebdd1f3 100644 --- a/nihav-realmedia/src/codecs/rv30dsp.rs +++ b/nihav-realmedia/src/codecs/rv30dsp.rs @@ -140,7 +140,7 @@ const RV30_CHROMA_FRAC2: [u16; 3] = [ 0, 3, 5 ]; fn rv30_chroma_mc(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx: usize, sstride: usize, size: usize, x: usize, y: usize) { if (x == 0) && (y == 0) { for _ in 0..size { - for x in 0..size { dst[didx + x] = src[sidx + x]; } + dst[didx..][..size].copy_from_slice(&src[sidx..][..size]); didx += dstride; sidx += sstride; } @@ -162,6 +162,7 @@ fn rv30_chroma_mc(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], m } } +#[allow(clippy::type_complexity)] pub struct RV30DSP { luma_mc: [[fn (&mut [u8], usize, usize, &[u8], usize, usize); 9]; 2], } @@ -238,6 +239,7 @@ const RV30_EDGE1: [isize; 3] = [ 0, 1, 1 ]; const RV30_EDGE2: [isize; 3] = [ 0, 2, 2 ]; impl RV34DSP for RV30DSP { + #[allow(clippy::cyclomatic_complexity)] fn loop_filter(&self, frame: &mut NAVideoBuffer, _ftype: FrameType, mbinfo: &[RV34MBInfo], mb_w: usize, _mb_h: usize, row: usize) { let mut offs: [usize; 3] = [0; 3]; let mut stride: [usize; 3] = [0; 3]; diff --git a/nihav-realmedia/src/codecs/rv40dsp.rs b/nihav-realmedia/src/codecs/rv40dsp.rs index 5023671..299c395 100644 --- a/nihav-realmedia/src/codecs/rv40dsp.rs +++ b/nihav-realmedia/src/codecs/rv40dsp.rs @@ -189,7 +189,7 @@ const RV40_CHROMA_BIAS: [[u16; 4]; 4] = [ fn rv40_chroma_mc(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx: usize, sstride: usize, size: usize, x: usize, y: usize) { if (x == 0) && (y == 0) { for _ in 0..size { - for x in 0..size { dst[didx + x] = src[sidx + x]; } + dst[didx..][..size].copy_from_slice(&src[sidx..][..size]); didx += dstride; sidx += sstride; } @@ -226,6 +226,7 @@ fn rv40_chroma_mc(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], m } } +#[allow(clippy::type_complexity)] pub struct RV40DSP { luma_mc: [[fn (&mut [u8], usize, usize, &[u8], usize, usize); 16]; 2], } @@ -590,6 +591,7 @@ const C_LEFT_COL_MASK: u32 = 0x5; const C_RIGHT_COL_MASK: u32 = 0xA; impl RV34DSP for RV40DSP { + #[allow(clippy::cyclomatic_complexity)] fn loop_filter(&self, frame: &mut NAVideoBuffer, _ftype: FrameType, mbinfo: &[RV34MBInfo], mb_w: usize, mb_h: usize, row: usize) { // todo proper B-frame filtering? let mut offs: [usize; 3] = [0; 3]; diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index 4788f3e..ecc400a 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -728,6 +728,7 @@ println!(" left {} bits", br.left()); } Ok(()) } + #[allow(clippy::cyclomatic_complexity)] fn decode_cb_tree(&mut self, buf: &mut NASimpleVideoFrame, hdr: &FrameHeader, br: &mut BitReader, xpos: usize, ypos: usize, log_size: u8) -> DecoderResult<()> { if (xpos >= hdr.width) || (ypos >= hdr.height) { return Ok(()); } diff --git a/nihav-realmedia/src/codecs/rv60dsp.rs b/nihav-realmedia/src/codecs/rv60dsp.rs index e037366..760777a 100644 --- a/nihav-realmedia/src/codecs/rv60dsp.rs +++ b/nihav-realmedia/src/codecs/rv60dsp.rs @@ -58,10 +58,11 @@ macro_rules! filter_row { }); } +#[allow(clippy::cyclomatic_complexity)] fn luma_mc(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx: usize, sstride: usize, w: usize, h: usize, cx: usize, cy: usize) { if (cx == 0) && (cy == 0) { for _ in 0..h { - for x in 0..w { dst[didx + x] = src[sidx + x]; } + dst[didx..][..w].copy_from_slice(&src[sidx..][..w]); didx += dstride; sidx += sstride; } @@ -102,7 +103,7 @@ fn luma_mc(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx fn chroma_mc(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx: usize, sstride: usize, w: usize, h: usize, x: usize, y: usize) { if (x == 0) && (y == 0) { for _ in 0..h { - for x in 0..w { dst[didx + x] = src[sidx + x]; } + dst[didx..][..w].copy_from_slice(&src[sidx..][..w]); didx += dstride; sidx += sstride; } @@ -757,9 +758,7 @@ impl IntraPredContext { let off = ((sum >> 5) + 32) as usize; let frac = (sum & 0x1F) as u16; if frac == 0 { - for x in 0..size { - dst[doff + x] = src[off + x]; - } + dst[doff..][..size].copy_from_slice(&src[off..][..size]); } else { for x in 0..size { let a = src[off + x + 0] as u16; @@ -785,6 +784,7 @@ impl IntraPredContext { sum += diff; } } + #[allow(clippy::cyclomatic_complexity)] pub fn pred_angle(&self, dst: &mut [u8], mut doff: usize, dstride: usize, size: usize, angle: usize, filter: bool) { let mut filtered1: [u8; 96] = [0; 96]; let mut filtered2: [u8; 96] = [0; 96]; @@ -880,9 +880,7 @@ impl IntraPredContext { Self::filter_bilin32(&mut filtered1[32..], self.t[1], self.t[33], 32); } for _ in 0..size { - for x in 0..size { - dst[doff + x] = filtered1[32 + x]; - } + dst[doff..][..size].copy_from_slice(&filtered1[32..][..size]); doff += dstride; } if filter { diff --git a/nihav-realmedia/src/demuxers/mod.rs b/nihav-realmedia/src/demuxers/mod.rs index e6f8a2c..0ba1316 100644 --- a/nihav-realmedia/src/demuxers/mod.rs +++ b/nihav-realmedia/src/demuxers/mod.rs @@ -5,6 +5,8 @@ macro_rules! validate { } #[cfg(feature="demuxer_real")] +#[allow(clippy::identity_op)] +#[allow(clippy::needless_range_loop)] mod realmedia; const RM_DEMUXERS: &[&DemuxerCreator] = &[ diff --git a/nihav-realmedia/src/demuxers/realmedia.rs b/nihav-realmedia/src/demuxers/realmedia.rs index b5cd9b7..16c4746 100644 --- a/nihav-realmedia/src/demuxers/realmedia.rs +++ b/nihav-realmedia/src/demuxers/realmedia.rs @@ -412,17 +412,17 @@ fn read_multiple_frame(src: &mut ByteReader, stream: NAStreamRef, keyframe: bool struct RMDemuxCommon {} impl RMDemuxCommon { - fn parse_stream_info(str_data: &mut CommonStreamData, strmgr: &mut StreamManager, stream_no: u32, edata: &Vec) -> DemuxerResult { + fn parse_stream_info(str_data: &mut CommonStreamData, strmgr: &mut StreamManager, stream_no: u32, edata: &[u8]) -> DemuxerResult { let mut is_mlti = false; - let mut mr = MemoryReader::new_read(edata.as_slice()); + let mut mr = MemoryReader::new_read(edata); let mut src = ByteReader::new(&mut mr); let tag = src.read_u32be()?; let tag2 = src.peek_u32be()?; //println!("tag1 {:X} tag2 {:X}", tag, tag2); if tag == mktag!('.', 'r', 'a', 0xFD) { - Self::parse_audio_stream(strmgr, &mut str_data.streams, stream_no, &mut src, edata.as_slice())?; + Self::parse_audio_stream(strmgr, &mut str_data.streams, stream_no, &mut src, edata)?; } else if ((tag2 == mktag!('V', 'I', 'D', 'O')) || (tag2 == mktag!('I', 'M', 'A', 'G'))) && ((tag as usize) <= edata.len()) { - Self::parse_video_stream(strmgr, &mut str_data.streams, stream_no, &mut src, edata.as_slice(), tag2)?; + Self::parse_video_stream(strmgr, &mut str_data.streams, stream_no, &mut src, edata, tag2)?; } else if tag == mktag!(b"LSD:") { let extradata = Some(edata.to_owned()); @@ -1030,14 +1030,14 @@ impl<'a> RealMediaDemuxer<'a> { Ok(last) => { if last { break; } }, Err(DemuxerError::IOError) => { break; }, Err(etype) => { - if self.data_chunks.len() == 0 { // data is not found, report error + if self.data_chunks.is_empty() { // data is not found, report error return Err(etype); } }, }; } //println!("now @ {:X} / {}", self.src.tell(), self.data_pos); - validate!(self.data_chunks.len() > 0); + validate!(!self.data_chunks.is_empty()); self.cur_data_chunk = 0; let (pos, size, ver) = self.data_chunks[self.cur_data_chunk]; self.data_pos = pos; diff --git a/nihav-realmedia/src/lib.rs b/nihav-realmedia/src/lib.rs index aec7ef3..634e3b2 100644 --- a/nihav-realmedia/src/lib.rs +++ b/nihav-realmedia/src/lib.rs @@ -7,6 +7,7 @@ extern crate nihav_codec_support; #[allow(clippy::excessive_precision)] #[allow(clippy::identity_op)] #[allow(clippy::needless_range_loop)] +#[allow(clippy::single_match)] #[allow(clippy::too_many_arguments)] #[allow(clippy::unreadable_literal)] #[allow(clippy::useless_let_if_seq)] @@ -21,4 +22,4 @@ pub use crate::codecs::realmedia_register_all_codecs; #[allow(clippy::useless_let_if_seq)] mod demuxers; #[cfg(feature="demuxers")] -pub use crate::demuxers::realmedia_register_all_demuxers; \ No newline at end of file +pub use crate::demuxers::realmedia_register_all_demuxers;