From: Kostya Shishkov Date: Tue, 16 Jun 2020 13:06:54 +0000 (+0200) Subject: commonfmt: fix or silence clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=61cab15b810434b8e62234ab5cdfcb17ec2d566d;p=nihav.git commonfmt: fix or silence clippy warnings --- diff --git a/nihav-commonfmt/src/codecs/aac.rs b/nihav-commonfmt/src/codecs/aac.rs index 0c65d50..54ccef6 100644 --- a/nihav-commonfmt/src/codecs/aac.rs +++ b/nihav-commonfmt/src/codecs/aac.rs @@ -1003,6 +1003,7 @@ impl DSP { tmp: [0.0; 2048], ew_buf: [0.0; 1152], } } + #[allow(clippy::cyclomatic_complexity)] fn synth(&mut self, coeffs: &[f32; 1024], delay: &mut [f32; 1024], seq: u8, window_shape: bool, prev_window_shape: bool, dst: &mut [f32]) { let long_win = if window_shape { &self.kbd_long_win } else { &self.sine_long_win }; let short_win = if window_shape { &self.kbd_short_win } else { &self.sine_short_win }; diff --git a/nihav-commonfmt/src/codecs/atrac3.rs b/nihav-commonfmt/src/codecs/atrac3.rs index b74c533..8512482 100644 --- a/nihav-commonfmt/src/codecs/atrac3.rs +++ b/nihav-commonfmt/src/codecs/atrac3.rs @@ -260,6 +260,7 @@ struct DSP { tmp: [f32; ATRAC3_FRAME_SIZE + 64], } +#[allow(clippy::manual_memcpy)] impl DSP { fn new() -> Self { let mut gain_tab: [f32; 16] = [0.0; 16]; @@ -409,7 +410,7 @@ struct Atrac3CodebookReader { } impl CodebookDescReader for Atrac3CodebookReader { fn bits(&mut self, idx: usize) -> u8 { self.bits[idx] } - fn code(&mut self, idx: usize) -> u32 { self.codes[idx] as u32 } + fn code(&mut self, idx: usize) -> u32 { u32::from(self.codes[idx]) } fn sym (&mut self, idx: usize) -> u8 { idx as u8 } fn len(&mut self) -> usize { self.bits.len() } } @@ -455,6 +456,7 @@ impl Atrac3Decoder { scalefactors, } } + #[allow(clippy::identity_op)] fn rev_matrix(&mut self) { for i in 0..4 { let c0 = self.mci_prev[i]; diff --git a/nihav-commonfmt/src/codecs/cinepakenc.rs b/nihav-commonfmt/src/codecs/cinepakenc.rs index 09bb112..1c134c0 100644 --- a/nihav-commonfmt/src/codecs/cinepakenc.rs +++ b/nihav-commonfmt/src/codecs/cinepakenc.rs @@ -218,7 +218,7 @@ enum QuantMode { MedianCut, } -impl QuantMode { +impl std::string::ToString for QuantMode { fn to_string(&self) -> String { match *self { QuantMode::ELBG => "elbg".to_string(), @@ -436,7 +436,7 @@ impl CinepakEncoder { for _ in (start..end).step_by(4) { for x in (0..width).step_by(4) { if cur_bit == 0 { - if !intra || self.v1_idx.len() > 0 { + if !intra || !self.v1_idx.is_empty() { cur_mask = *miter.next().unwrap(); } else { cur_mask = 0xFFFFFFFF; @@ -722,7 +722,7 @@ impl CinepakEncoder { self.render_stripe(true, start_line, end_line); - if self.v4_idx.len() == 0 { + if self.v4_idx.is_empty() { bw.write_byte(0x32)?; bw.write_u24be((self.v1_idx.len() + 4) as u32)?; bw.write_buf(self.v1_idx.as_slice())?; @@ -917,7 +917,7 @@ impl NAEncoder for CinepakEncoder { ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)); Ok(ofmt) }, - NACodecTypeInfo::Audio(_) => return Err(EncoderError::FormatError), + NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Video(vinfo) => { let pix_fmt = if vinfo.format == GRAY_FORMAT { GRAY_FORMAT } else { YUV420_FORMAT }; let outinfo = NAVideoInfo::new((vinfo.width + 3) & !3, (vinfo.height + 3) & !3, true, pix_fmt); @@ -943,7 +943,7 @@ impl NAEncoder for CinepakEncoder { } let out_info = NAVideoInfo::new(vinfo.width, vinfo.height, false, vinfo.format); - let info = NACodecInfo::new("cinepak", NACodecTypeInfo::Video(out_info.clone()), None); + let info = NACodecInfo::new("cinepak", NACodecTypeInfo::Video(out_info), None); let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den); stream.set_num(stream_id as usize); let stream = stream.into_ref(); diff --git a/nihav-commonfmt/src/codecs/clearvideo.rs b/nihav-commonfmt/src/codecs/clearvideo.rs index 3d0f7bc..6021856 100644 --- a/nihav-commonfmt/src/codecs/clearvideo.rs +++ b/nihav-commonfmt/src/codecs/clearvideo.rs @@ -623,6 +623,7 @@ impl ClearVideoDecoder { } impl NADecoder for ClearVideoDecoder { + #[allow(clippy::or_fun_call)] fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); diff --git a/nihav-commonfmt/src/codecs/mod.rs b/nihav-commonfmt/src/codecs/mod.rs index 99c9e7b..9cedec9 100644 --- a/nihav-commonfmt/src/codecs/mod.rs +++ b/nihav-commonfmt/src/codecs/mod.rs @@ -10,12 +10,19 @@ mod cinepak; mod clearvideo; #[cfg(feature="decoder_aac")] +#[allow(clippy::manual_memcpy)] +#[allow(clippy::useless_let_if_seq)] mod aac; #[cfg(feature="decoder_atrac3")] +#[allow(clippy::identity_op)] +#[allow(clippy::useless_let_if_seq)] mod atrac3; #[cfg(any(feature="decoder_pcm",feature="encoder_pcm"))] mod pcm; #[cfg(feature="decoder_sipro")] +#[allow(clippy::collapsible_if)] +#[allow(clippy::identity_op)] +#[allow(clippy::manual_memcpy)] mod sipro; #[cfg(feature="decoder_ts102366")] mod ts102366; diff --git a/nihav-commonfmt/src/codecs/pcm.rs b/nihav-commonfmt/src/codecs/pcm.rs index b125c64..43c897a 100644 --- a/nihav-commonfmt/src/codecs/pcm.rs +++ b/nihav-commonfmt/src/codecs/pcm.rs @@ -174,7 +174,7 @@ impl NAEncoder for PCMEncoder { ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 0, SND_S16P_FORMAT, 0)); Ok(ofmt) }, - NACodecTypeInfo::Video(_) => return Err(EncoderError::FormatError), + NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Audio(_) => { Ok(*encinfo) } diff --git a/nihav-commonfmt/src/codecs/sipro.rs b/nihav-commonfmt/src/codecs/sipro.rs index 03cd762..86a8bd5 100644 --- a/nihav-commonfmt/src/codecs/sipro.rs +++ b/nihav-commonfmt/src/codecs/sipro.rs @@ -202,11 +202,9 @@ impl SiproDecoder { newfilt[i] = filter[i] + 0.33 * self.lsf_hist[i] + SIPRO_MEAN_LSF_LBR[i]; } for i in 0..8 { // maybe it's just bubble sort? - for j in (0..i+1).rev() { + for j in (0..=i).rev() { if newfilt[j] <= newfilt[j + 1] { break; } - let tmp = newfilt[j]; - newfilt[j] = newfilt[j + 1]; - newfilt[j + 1] = tmp; + newfilt.swap(j, j + 1); } } @@ -315,7 +313,7 @@ impl SiproDecoder { self.fix_vec = [0.0; 80]; let pitch_frac = SIPRO_GAIN_PITCH_CB_16K[self.gp_index[sf]].min(1.0); for i in 0..10 { - let mut scale = self.pulse_data[i * 2 + 1] as f32; + let mut scale = f32::from(self.pulse_data[i * 2 + 1]); let off = self.pulse_data[i * 2 + 0] as usize; for j in (off..80).step_by(self.prev_pitch) { self.fix_vec[j] += scale; @@ -364,6 +362,7 @@ impl SiproDecoder { } self.unpack_pulses_common(); } + #[allow(clippy::cast_lossless)] fn unpack_pulses_common(&mut self) { for i in 0..48 { self.fix_vec[i] = 0.0; @@ -590,7 +589,7 @@ fn lsp2poly(lsp: &[f32], poly: &mut [f64], order: usize) { poly[1] = -2.0 * f64::from(lsp[0]); for i in 1..order { poly[i + 1] = -2.0 * f64::from(lsp[2 * i]) * poly[i] + 2.0 * poly[i - 1]; - for j in (2..i+1).rev() { + for j in (2..=i).rev() { poly[j] += -2.0 * f64::from(lsp[2 * i]) * poly[j - 1] + poly[j - 2]; } poly[1] += -2.0 * f64::from(lsp[2 * i]); diff --git a/nihav-commonfmt/src/codecs/ts102366.rs b/nihav-commonfmt/src/codecs/ts102366.rs index 25f342b..ab0e84c 100644 --- a/nihav-commonfmt/src/codecs/ts102366.rs +++ b/nihav-commonfmt/src/codecs/ts102366.rs @@ -831,6 +831,7 @@ impl AudioBlock { bap_buf_fill: [0; 3], } } + #[allow(clippy::cyclomatic_complexity)] fn read(&mut self, br: &mut BitReader, bsi: &BSI, fscod: usize, blk_no: usize) -> DecoderResult { let channels = bsi.acmod.get_num_channels(); let is_stereo = bsi.acmod == ACMode::Stereo; diff --git a/nihav-commonfmt/src/demuxers/avi.rs b/nihav-commonfmt/src/demuxers/avi.rs index 1b59aac..71cdb01 100644 --- a/nihav-commonfmt/src/demuxers/avi.rs +++ b/nihav-commonfmt/src/demuxers/avi.rs @@ -455,14 +455,13 @@ fn parse_strf_auds(dmx: &mut AVIDemuxer, strmgr: &mut StreamManager, size: usize let soniton = NASoniton::new(bits_per_sample as u8, SONITON_FLAG_SIGNED); let ahdr = NAAudioInfo::new(samplespersec, channels as u8, soniton, block_align as usize); - let edata; - if size > 16 { - let edata_size = dmx.src.read_u16le()? as usize; - validate!(edata_size + 18 == size); - edata = dmx.read_extradata(size - 18)?; - } else { - edata = None; - } + let edata = if size > 16 { + let edata_size = dmx.src.read_u16le()? as usize; + validate!(edata_size + 18 == size); + dmx.read_extradata(size - 18)? + } else { + None + }; let cname = match register::find_codec_from_wav_twocc(w_format_tag) { None => "unknown", Some(name) => name, @@ -512,6 +511,7 @@ fn parse_junk(dmx: &mut AVIDemuxer, strmgr: &mut StreamManager, size: usize) -> Ok(size) } +#[allow(clippy::verbose_bit_mask)] fn parse_idx1(src: &mut ByteReader, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex, size: usize, movi_pos: u64, key_offs: &mut Vec) -> DemuxerResult { validate!((size & 15) == 0); let mut tag = [0u8; 4]; diff --git a/nihav-commonfmt/src/demuxers/mod.rs b/nihav-commonfmt/src/demuxers/mod.rs index 521cecf..ba8a8df 100644 --- a/nihav-commonfmt/src/demuxers/mod.rs +++ b/nihav-commonfmt/src/demuxers/mod.rs @@ -10,6 +10,7 @@ macro_rules! validate { #[allow(clippy::cast_lossless)] mod avi; #[cfg(feature="demuxer_mov")] +#[allow(clippy::cast_lossless)] mod mov; #[cfg(feature="demuxer_wav")] mod wav; diff --git a/nihav-commonfmt/src/demuxers/mov.rs b/nihav-commonfmt/src/demuxers/mov.rs index e147757..ece3366 100644 --- a/nihav-commonfmt/src/demuxers/mov.rs +++ b/nihav-commonfmt/src/demuxers/mov.rs @@ -393,7 +393,7 @@ fn read_stsd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult let _flags = br.read_u24be()?; let entries = br.read_u32be()?; validate!(entries > 0); - let esize = br.read_u32be()? as u64; + let esize = u64::from(br.read_u32be()?); validate!(esize + 8 <= size); let mut fcc = [0u8; 4]; br.read_buf(&mut fcc)?; @@ -477,16 +477,15 @@ fn read_stsd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult let format = if depth > 8 { RGB24_FORMAT } else { PAL8_FORMAT }; let mut vhdr = NAVideoInfo::new(width, height, false, format); vhdr.bits = depth as u8; - let edata; - if br.tell() - start_pos + 4 < size { + let edata = if br.tell() - start_pos + 4 < size { //todo skip various common atoms - let edata_size = br.read_u32be()? as usize; - let mut buf = vec![0; edata_size]; + let edata_size = br.read_u32be()? as usize; + let mut buf = vec![0; edata_size]; br.read_buf(buf.as_mut_slice())?; - edata = Some(buf); - } else { - edata = None; - } + Some(buf) + } else { + None + }; codec_info = NACodecInfo::new(cname, NACodecTypeInfo::Video(vhdr), edata); }, StreamType::Audio => { @@ -679,7 +678,7 @@ impl Track { read_chunk_list!(track; "minf", read_minf, MINF_CHUNK_HANDLERS); read_chunk_list!(track; "stbl", read_stbl, STBL_CHUNK_HANDLERS); fn fill_seek_index(&self, seek_index: &mut SeekIndex) { - if self.keyframes.len() > 0 { + if !self.keyframes.is_empty() { seek_index.mode = SeekIndexMode::Present; } for kf_time in self.keyframes.iter() { @@ -763,9 +762,9 @@ impl Track { } } fn get_size(&self, sample_no: usize) -> usize { - if self.chunk_sizes.len() > 0 { + if !self.chunk_sizes.is_empty() { self.chunk_sizes[sample_no] as usize - } else if self.sample_map.len() > 0 { + } else if !self.sample_map.is_empty() { let mut nsamp = 0; for (idx, samples) in self.sample_map.iter() { if *idx as usize <= self.cur_chunk { @@ -784,7 +783,7 @@ impl Track { self.samples_left = 0; if self.stream_type == StreamType::Audio { self.cur_chunk = self.cur_sample; - } else if self.chunk_offsets.len() != self.chunk_sizes.len() && self.sample_map.len() > 0{ + } else if self.chunk_offsets.len() != self.chunk_sizes.len() && !self.sample_map.is_empty() { let mut csamp = 0; self.cur_chunk = 0; let mut cmap = self.sample_map.iter(); @@ -819,7 +818,7 @@ impl<'a> DemuxCore<'a> for MOVDemuxer<'a> { fn open(&mut self, strmgr: &mut StreamManager, seek_index: &mut SeekIndex) -> DemuxerResult<()> { self.read_root(strmgr)?; validate!(self.mdat_pos > 0); - validate!(self.tracks.len() > 0); + validate!(!self.tracks.is_empty()); for track in self.tracks.iter() { track.fill_seek_index(seek_index); } @@ -829,7 +828,7 @@ impl<'a> DemuxCore<'a> for MOVDemuxer<'a> { } fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult { - if self.tracks.len() == 0 { + if self.tracks.is_empty() { return Err(DemuxerError::EOF); } for _ in 0..self.tracks.len() { @@ -852,7 +851,7 @@ impl<'a> DemuxCore<'a> for MOVDemuxer<'a> { return Ok(pkt); } } - return Err(DemuxerError::EOF); + Err(DemuxerError::EOF) } fn seek(&mut self, time: u64, seek_index: &SeekIndex) -> DemuxerResult<()> { diff --git a/nihav-commonfmt/src/demuxers/wav.rs b/nihav-commonfmt/src/demuxers/wav.rs index bf30686..f9c9551 100644 --- a/nihav-commonfmt/src/demuxers/wav.rs +++ b/nihav-commonfmt/src/demuxers/wav.rs @@ -4,10 +4,10 @@ use nihav_core::demuxers::DemuxerError::*; macro_rules! mktag { ($a:expr, $b:expr, $c:expr, $d:expr) => { - (($a as u32) << 24) | (($b as u32) << 16) | (($c as u32) << 8) | ($d as u32) + (u32::from($a) << 24) | (u32::from($b) << 16) | (u32::from($c) << 8) | u32::from($d) }; ($arr:expr) => { - (($arr[0] as u32) << 24) | (($arr[1] as u32) << 16) | (($arr[2] as u32) << 8) | ($arr[3] as u32) + (u32::from($arr[0]) << 24) | (u32::from($arr[1]) << 16) | (u32::from($arr[2]) << 8) | u32::from($arr[3]) }; } @@ -127,16 +127,15 @@ impl<'a> WAVDemuxer<'a> { let bits_per_sample = if csize >= 16 { self.src.read_u16le()? } else { 8 }; validate!(channels < 256); - let edata; - if csize > 16 { - validate!(csize >= 18); - let cb_size = self.src.read_u16le()? as usize; - let mut buf = vec![0; cb_size]; + let edata = if csize > 16 { + validate!(csize >= 18); + let cb_size = self.src.read_u16le()? as usize; + let mut buf = vec![0; cb_size]; self.src.read_buf(buf.as_mut_slice())?; - edata = Some(buf); - } else { - edata = None; - } + Some(buf) + } else { + None + }; let cname = register::find_codec_from_wav_twocc(format_tag).unwrap_or("unknown"); let soniton = if cname == "pcm" { diff --git a/nihav-commonfmt/src/lib.rs b/nihav-commonfmt/src/lib.rs index c4a2ca7..b5b96d2 100644 --- a/nihav-commonfmt/src/lib.rs +++ b/nihav-commonfmt/src/lib.rs @@ -3,6 +3,8 @@ extern crate nihav_codec_support; extern crate nihav_registry; #[cfg(feature="decoders")] +#[allow(clippy::needless_range_loop)] +#[allow(clippy::single_match)] #[allow(clippy::unreadable_literal)] #[allow(clippy::too_many_arguments)] #[allow(clippy::excessive_precision)] diff --git a/nihav-commonfmt/src/muxers/avi.rs b/nihav-commonfmt/src/muxers/avi.rs index 2f8e229..2c54118 100644 --- a/nihav-commonfmt/src/muxers/avi.rs +++ b/nihav-commonfmt/src/muxers/avi.rs @@ -61,6 +61,8 @@ fn write_chunk_hdr(bw: &mut ByteWriter, stype: StreamType, str_no: u32) -> Muxer } impl<'a> MuxCore<'a> for AVIMuxer<'a> { + #[allow(clippy::unreadable_literal)] + #[allow(clippy::cast_lossless)] fn create(&mut self, strmgr: &StreamManager) -> MuxerResult<()> { if strmgr.get_num_streams() == 0 { return Err(MuxerError::InvalidArgument); @@ -184,6 +186,7 @@ impl<'a> MuxCore<'a> for AVIMuxer<'a> { // unimplemented!(); self.bw.write_u32le(0)?; // total colors self.bw.write_u32le(0)?; // important colors +println!("pal?"); } else { self.bw.write_u32le(0)?; // total colors self.bw.write_u32le(0)?; // important colors @@ -263,7 +266,7 @@ impl<'a> MuxCore<'a> for AVIMuxer<'a> { } fn end(&mut self) -> MuxerResult<()> { patch_size(&mut self.bw, self.data_pos)?; - if self.index.len() > 0 { + 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() { diff --git a/nihav-commonfmt/src/muxers/wav.rs b/nihav-commonfmt/src/muxers/wav.rs index 9185f38..f99c147 100644 --- a/nihav-commonfmt/src/muxers/wav.rs +++ b/nihav-commonfmt/src/muxers/wav.rs @@ -51,7 +51,7 @@ impl<'a> MuxCore<'a> for WAVMuxer<'a> { twocc.unwrap_or(0) }; let avg_bytes_per_sec = if stream.get_info().get_name() == "pcm" { - u32::from(ainfo.channels) * ainfo.sample_rate * u32::from(ainfo.format.bits) >> 3 + (u32::from(ainfo.channels) * ainfo.sample_rate * u32::from(ainfo.format.bits)) >> 3 } else { 0 }; @@ -59,11 +59,11 @@ impl<'a> MuxCore<'a> for WAVMuxer<'a> { self.bw.write_buf(b"RIFF\0\0\0\0WAVEfmt ")?; self.bw.write_u32le(if edata_len == 0 { 16 } else { 18 + edata_len } as u32)?; self.bw.write_u16le(twocc)?; - self.bw.write_u16le(ainfo.channels as u16)?; + self.bw.write_u16le(u16::from(ainfo.channels))?; self.bw.write_u32le(ainfo.sample_rate)?; self.bw.write_u32le(avg_bytes_per_sec)?; self.bw.write_u16le(ainfo.block_len as u16)?; - self.bw.write_u16le(ainfo.format.bits as u16)?; + self.bw.write_u16le(u16::from(ainfo.format.bits))?; if let Some(ref buf) = stream.get_info().get_extradata() { self.bw.write_u16le(edata_len as u16)?; self.bw.write_buf(buf.as_slice())?;