From d92111a8ca9bd0b9b773c2ff545cba9c7b8f4a02 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 9 Nov 2024 11:56:52 +0100 Subject: [PATCH] nihav_realmedia: fix or update clippy warnings --- nihav-realmedia/src/codecs/cook.rs | 51 +++---- nihav-realmedia/src/codecs/cookenc.rs | 4 +- nihav-realmedia/src/codecs/mod.rs | 13 +- nihav-realmedia/src/codecs/ra144.rs | 24 ++-- nihav-realmedia/src/codecs/ra288.rs | 18 ++- nihav-realmedia/src/codecs/ralf.rs | 24 ++-- nihav-realmedia/src/codecs/rv10.rs | 19 +-- nihav-realmedia/src/codecs/rv20.rs | 40 ++---- nihav-realmedia/src/codecs/rv3040.rs | 107 +++++++-------- nihav-realmedia/src/codecs/rv30dsp.rs | 3 + nihav-realmedia/src/codecs/rv34codes.rs | 31 +++-- nihav-realmedia/src/codecs/rv34dsp.rs | 5 +- nihav-realmedia/src/codecs/rv40.rs | 2 + nihav-realmedia/src/codecs/rv40dsp.rs | 20 +-- .../src/codecs/rv40enc/bitstream.rs | 1 + nihav-realmedia/src/codecs/rv40enc/dsp/blk.rs | 1 + .../src/codecs/rv40enc/dsp/ipred.rs | 1 + .../src/codecs/rv40enc/dsp/loopfilt.rs | 24 ++-- nihav-realmedia/src/codecs/rv40enc/mod.rs | 4 + .../src/codecs/rv40enc/motion_est.rs | 2 + nihav-realmedia/src/codecs/rv60.rs | 58 ++++---- nihav-realmedia/src/codecs/rv60codes.rs | 6 +- nihav-realmedia/src/codecs/rv60dsp.rs | 5 +- nihav-realmedia/src/demuxers/mod.rs | 1 - nihav-realmedia/src/demuxers/realmedia.rs | 128 ++++++++---------- nihav-realmedia/src/lib.rs | 17 --- 26 files changed, 276 insertions(+), 333 deletions(-) diff --git a/nihav-realmedia/src/codecs/cook.rs b/nihav-realmedia/src/codecs/cook.rs index 1afe246..5b771d3 100644 --- a/nihav-realmedia/src/codecs/cook.rs +++ b/nihav-realmedia/src/codecs/cook.rs @@ -98,8 +98,8 @@ impl CookDSP { let mut window: [f32; 1024] = [0.0; 1024]; let factor = consts::PI / (2.0 * fsamples); let scale = (2.0 / fsamples).sqrt() / 32768.0; - for k in 0..samples { - window[k] = (factor * ((k as f32) + 0.5)).sin() * scale; + for (k, el) in window[..samples].iter_mut().enumerate() { + *el = (factor * ((k as f32) + 0.5)).sin() * scale; } let mut pow_tab: [f32; 128] = [0.0; 128]; let mut hpow_tab: [f32; 128] = [0.0; 128]; @@ -213,7 +213,7 @@ impl CookChannelPair { self.js_bits = 0; self.mode = Mode::Mono; } else { - validate!((js_bits >= 2) && (js_bits <= 6)); + validate!((2..=6).contains(&js_bits)); self.js_bits = js_bits as u8; self.mode = Mode::JointStereo; } @@ -254,9 +254,10 @@ impl CookChannelPair { if tbias1 + tbias2 > avail_bits * 2 { let mut max = -999999; let mut idx = total_subbands + 1; - for j in 0..total_subbands { - if exp_index1[j] >= (NUM_CATEGORIES - 1) { continue; } - let t = -2 * (exp_index1[j] as i32) - (self.qindex[j] as i32) + bias; + for (j, (&exp_idx, &q_idx)) in exp_index1.iter() + .zip(self.qindex.iter()).enumerate().take(total_subbands) { + if exp_idx >= (NUM_CATEGORIES - 1) { continue; } + let t = -2 * (exp_idx as i32) - (q_idx as i32) + bias; if t >= max { max = t; idx = j; @@ -270,9 +271,10 @@ impl CookChannelPair { } else { let mut min = 999999; let mut idx = total_subbands + 1; - for j in 0..total_subbands { - if exp_index2[j] == 0 { continue; } - let t = -2 * (exp_index2[j] as i32) - (self.qindex[j] as i32) + bias; + for (j, (&exp_idx, &q_idx)) in exp_index2.iter() + .zip(self.qindex.iter()).enumerate().take(total_subbands) { + if exp_idx == 0 { continue; } + let t = -2 * (exp_idx as i32) - (q_idx as i32) + bias; if t < min { min = t; idx = j; @@ -285,8 +287,8 @@ impl CookChannelPair { exp_index2[idx] -= 1; } } - for i in 0..total_subbands { - self.category[i] = exp_index2[i] as u8; + for (cat, &exp_idx) in self.category.iter_mut().zip(exp_index2.iter()).take(total_subbands) { + *cat = exp_idx as u8; } for _ in 0..num_vectors { @@ -312,12 +314,11 @@ impl CookChannelPair { let mut ipos = 0; for _ in 0..num_gains { let idx = br.read(3)? as usize; - let val; - if br.read_bool()? { - val = (br.read(4)? as i32) - 7; - } else { - val = -1; - } + let val = if br.read_bool()? { + (br.read(4)? as i32) - 7 + } else { + -1 + }; validate!(idx >= ipos); while ipos <= idx { self.prev_gains[channel][ipos] = val; @@ -374,14 +375,13 @@ impl CookChannelPair { unpack_band(&mut br, codebooks, &mut coef_index, &mut coef_sign, cat)?; } for i in 0..BAND_SIZE { - let val; - if coef_index[i] == 0 { - let v = COOK_DITHER_TAB[cat]; - val = if !rnd.get_sign() { v } else { -v }; - } else { - let v = COOK_QUANT_CENTROID[cat][coef_index[i] as usize]; - val = if !coef_sign[i] { v } else { -v }; - } + let val = if coef_index[i] == 0 { + let v = COOK_DITHER_TAB[cat]; + if !rnd.get_sign() { v } else { -v } + } else { + let v = COOK_QUANT_CENTROID[cat][coef_index[i] as usize]; + if !coef_sign[i] { v } else { -v } + }; self.block[channel][off + i] = val * dsp.hpow_tab[(self.qindex[sb] + 64) as usize]; } off += BAND_SIZE; @@ -389,6 +389,7 @@ impl CookChannelPair { Ok(()) } + #[allow(clippy::needless_range_loop)] fn decode(&mut self, dsp: &mut CookDSP, rnd: &mut RND, codebooks: &Codebooks, src: &[u8], buf: &mut [u8], abuf: &mut NABufferType) -> DecoderResult<()> { if self.mode == Mode::Stereo { let mut schunk = src.chunks(src.len() / 2); diff --git a/nihav-realmedia/src/codecs/cookenc.rs b/nihav-realmedia/src/codecs/cookenc.rs index 3b9e3c4..5080011 100644 --- a/nihav-realmedia/src/codecs/cookenc.rs +++ b/nihav-realmedia/src/codecs/cookenc.rs @@ -34,8 +34,8 @@ fn bitalloc(samples: usize, bits: usize, vector_bits: u8, total_subbands: usize, let mut bias: i32 = -32; for i in 0..6 { let mut sum = 0; - for j in 0..total_subbands { - let idx = ((32 >> i) + bias - (qindex[j] as i32)) / 2; + for &qidx in qindex[..total_subbands].iter() { + let idx = ((32 >> i) + bias - (qidx as i32)) / 2; sum += COOK_EXP_BITS[idx.clip_cat()]; } if sum >= (avail_bits - 32) { diff --git a/nihav-realmedia/src/codecs/mod.rs b/nihav-realmedia/src/codecs/mod.rs index c6058a5..4e13041 100644 --- a/nihav-realmedia/src/codecs/mod.rs +++ b/nihav-realmedia/src/codecs/mod.rs @@ -10,13 +10,17 @@ macro_rules! validate { } #[cfg(any(feature="decoder_realvideo3", feature="decoder_realvideo4"))] +#[allow(clippy::too_many_arguments)] mod rv3040; #[cfg(any(feature="decoder_realvideo3", feature="decoder_realvideo4", feature="encoder_realvideo4"))] #[allow(clippy::erasing_op)] mod rv34codes; #[cfg(any(feature="decoder_realvideo3", feature="decoder_realvideo4"))] +#[allow(clippy::collapsible_else_if)] #[allow(clippy::erasing_op)] +#[allow(clippy::identity_op)] #[allow(clippy::many_single_char_names)] +#[allow(clippy::too_many_arguments)] mod rv34dsp; #[cfg(feature="decoder_realvideo1")] @@ -26,29 +30,34 @@ pub mod rv20; #[cfg(feature="decoder_realvideo3")] pub mod rv30; #[cfg(feature="decoder_realvideo3")] -#[allow(clippy::erasing_op)] #[allow(clippy::many_single_char_names)] #[allow(clippy::neg_multiply)] +#[allow(clippy::too_many_arguments)] pub mod rv30dsp; #[cfg(feature="decoder_realvideo4")] pub mod rv40; #[cfg(any(feature="decoder_realvideo4", feature="encoder_realvideo4"))] pub mod rv40data; #[cfg(feature="decoder_realvideo4")] +#[allow(clippy::eq_op)] #[allow(clippy::erasing_op)] #[allow(clippy::many_single_char_names)] +#[allow(clippy::too_many_arguments)] pub mod rv40dsp; #[cfg(feature="decoder_realvideo6")] pub mod rv60; #[cfg(feature="decoder_realvideo6")] +#[allow(clippy::identity_op)] +#[allow(clippy::too_many_arguments)] pub mod rv60codes; #[cfg(feature="decoder_realvideo6")] #[allow(clippy::erasing_op)] +#[allow(clippy::identity_op)] #[allow(clippy::many_single_char_names)] +#[allow(clippy::too_many_arguments)] 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/ra144.rs b/nihav-realmedia/src/codecs/ra144.rs index a28850f..f3237e7 100644 --- a/nihav-realmedia/src/codecs/ra144.rs +++ b/nihav-realmedia/src/codecs/ra144.rs @@ -80,6 +80,7 @@ impl RA144Decoder { rescale_rms(self.lpc_refl_rms[if copyold { 1 } else { 0 }], energy) } } + #[allow(clippy::needless_range_loop)] fn process_subblock(&mut self, br: &mut BitReader, lpc_coeffs: &[i16; LPC_ORDER], rms: u32) -> DecoderResult<()> { let cba_idx = br.read(7)? as usize; let gain = br.read(8)? as usize; @@ -91,9 +92,7 @@ impl RA144Decoder { if cba_idx != 0 { let len = cba_idx + BLOCKSIZE/2 - 1; let soff = BUFFERSIZE - len; - for i in 0..len.min(BLOCKSIZE) { - tmp_a[i] = self.adapt_cb[i + soff]; - } + tmp_a[..len.min(BLOCKSIZE)].copy_from_slice(&self.adapt_cb[soff..][..len.min(BLOCKSIZE)]); for i in len..BLOCKSIZE { tmp_a[i] = self.adapt_cb[i + soff - len]; } @@ -141,10 +140,8 @@ const CHMAP_MONO: [NAChannelType; 1] = [NAChannelType::C]; fn celp_synth_filter(dst: &mut [i16], src: &[i16], filt: &[i16; LPC_ORDER]) -> bool { //1,0,0xfff for i in 0..BLOCKSIZE { - let mut sum = -0xFFF; - for j in 0..LPC_ORDER { - sum += (filt[j] as i32) * (dst[LPC_ORDER + i - j - 1] as i32); - } + let sum = filt.iter().zip(dst[i..].iter().rev()) + .fold(-0xFFFi32, |acc, (&filt, &samp)| acc + (filt as i32) * (samp as i32)); let sum1 = (-sum >> 12) + (src[BUFFERSIZE - BLOCKSIZE + i] as i32); if ((sum1 >> 16) != 0) && ((sum1 >> 16) != -1) { // overflow return true; @@ -167,8 +164,8 @@ fn calc_rms(coeffs: &[i32; LPC_ORDER]) -> u32 { let mut res = 1 << 16; let mut shift = 10; - for i in 0..LPC_ORDER { - res = ((((1 << 24) - ((coeffs[i] * coeffs[i]) as u32)) >> 12) * res) >> 12; + for &coef in coeffs.iter() { + res = ((((1 << 24) - ((coef * coef) as u32)) >> 12) * res) >> 12; if res == 0 { return 0; } while res < (1 << 14) { res <<= 2; @@ -179,10 +176,7 @@ fn calc_rms(coeffs: &[i32; LPC_ORDER]) -> u32 { } fn calc_irms(coeffs: &[i16; BLOCKSIZE]) -> u32 { - let mut sum = 0; - for i in 0..BLOCKSIZE { - sum += ((coeffs[i] as i32) * (coeffs[i] as i32)) as u32; - } + let sum = coeffs.iter().fold(0u32, |acc, &a| acc + (((a as i32) * (a as i32)) as u32)); if sum != 0 { (1 << 29) / (fixp_sqrt(sum) >> 8) } else { @@ -293,8 +287,8 @@ impl NADecoder for RA144Decoder { for (i, block) in output.chunks_mut(BLOCKSIZE).enumerate() { self.process_subblock(&mut br, &block_coeffs[i], refl_rms[i])?; - for j in 0..BLOCKSIZE { - block[j] = clip_out(self.audio[j + LPC_ORDER]) << 2; + for (dst, &src) in block.iter_mut().zip(self.audio[LPC_ORDER..].iter()) { + *dst = clip_out(src) << 2; } } diff --git a/nihav-realmedia/src/codecs/ra288.rs b/nihav-realmedia/src/codecs/ra288.rs index 822b1e5..1774ff5 100644 --- a/nihav-realmedia/src/codecs/ra288.rs +++ b/nihav-realmedia/src/codecs/ra288.rs @@ -28,6 +28,7 @@ struct RA288Decoder { const BF_ORDER: usize = SP_LPC_ORDER + 1; const BF_WORK_SIZE: usize = SP_LPC_ORDER + 40 + 35; +#[allow(clippy::too_many_arguments)] fn backfilter(hist: &mut [f32], rec: &mut [f32], filt: &mut [f32], win: &[f32], bw_tab: &[f32], start: usize, non_rec: usize, move_size: usize) { let mut temp: [f32; BF_ORDER] = [0.0; BF_ORDER]; let order = filt.len(); @@ -125,16 +126,15 @@ impl RA288Decoder { for i in 0..SP_LPC_ORDER { self.speech_hist[SP_START + i] = self.speech_hist[75 + i]; } - let mut sum: f32 = 32.0; - for i in 0..GAIN_LPC_ORDER { - sum -= self.gain_hist[GAIN_START + GAIN_LPC_ORDER - 1 - i] * self.gain_lpc[i]; - } - sum = sum.max(0.0).min(60.0); + let sum = self.gain_hist[GAIN_START..].iter().rev() + .zip(self.gain_lpc.iter()) + .fold(32.0f32, |acc, (&a, &b)| acc - a * b) + .max(0.0).min(60.0); let scale = (sum * 0.1151292546497).exp() * gain * (1.0 / ((1 << 23) as f32)); let mut buf: [f32; BLOCKSIZE] = [0.0; BLOCKSIZE]; - for i in 0..BLOCKSIZE { - buf[i] = (RA288_CODEBOOK[cb_idx][i] as f32) * scale; + for (dst, &cb) in buf.iter_mut().zip(RA288_CODEBOOK[cb_idx].iter()) { + *dst = (cb as f32) * scale; } let mut sum: f32 = 0.0; @@ -183,9 +183,7 @@ impl NADecoder for RA288Decoder { self.process_subblock(gain, cb); - for j in 0..BLOCKSIZE { - block[j] = self.speech_hist[SP_START + SP_LPC_ORDER + j]; - } + block.copy_from_slice(&self.speech_hist[SP_START + SP_LPC_ORDER..][..BLOCKSIZE]); if (i & 7) == 3 { backfilter(&mut self.speech_hist, &mut self.speech_rec, &mut self.speech_lpc, RA288_SPEECH_WINDOW, RA288_SPEECH_BW_TAB, 40, 35, SP_START); backfilter(&mut self.gain_hist, &mut self.gain_rec, &mut self.gain_lpc, RA288_GAIN_WINDOW, RA288_GAIN_BW_TAB, 8, 20, GAIN_START); diff --git a/nihav-realmedia/src/codecs/ralf.rs b/nihav-realmedia/src/codecs/ralf.rs index 154b80c..d009f18 100644 --- a/nihav-realmedia/src/codecs/ralf.rs +++ b/nihav-realmedia/src/codecs/ralf.rs @@ -113,6 +113,7 @@ impl Filter { } fn is_none(&self) -> bool { self.params == FILTER_NONE } fn is_raw(&self) -> bool { self.params == FILTER_RAW } + #[allow(clippy::comparison_chain)] fn read_coeffs(&mut self, br: &mut BitReader, cset: &CodebookSet) -> DecoderResult<()> { let coeff_cb = &cset.filter_coeffs_cb[self.bits as usize]; let mut cmode: i32 = 0; @@ -182,6 +183,7 @@ impl Channel { fn new() -> Self { Self { bias: 0, mode: 0, bits: 0, data: [0; 4096], filter: Filter::new() } } + #[allow(clippy::identity_op)] fn decode(&mut self, br: &mut BitReader, codebooks: &[CodebookSet; 3], length: usize) -> DecoderResult<()> { let cset = &codebooks[self.mode as usize]; self.filter.params = br.read_cb(&cset.filter_params_cb).unwrap(); @@ -282,12 +284,11 @@ impl RALFDecoder { let length = read_block_length(&mut br).unwrap(); validate!(length + self.sample_offset <= self.max_frame_size); - let dmode; - if self.channels > 1 { - dmode = (br.read(2).unwrap() + 1) as u8; - } else { - dmode = 0; - } + let dmode = if self.channels > 1 { + (br.read(2).unwrap() + 1) as u8 + } else { + 0 + }; self.ch_data[0].mode = dmode >> 2; self.ch_data[0].bits = 16; self.ch_data[1].mode = if dmode >= 2 { 2 } else { 0 }; @@ -431,12 +432,11 @@ impl NADecoder for RALFDecoder { let mut br = BitReader::new(&self.pkt_buf[2..][..table_bytes], BitReaderMode::BE); while br.tell() < table_bits { let size = br.read(13 + self.channels).unwrap() as usize; - let pts; - if br.read_bool().unwrap() { - pts = br.read(9).unwrap() as u16; - } else { - pts = 0; - } + let pts = if br.read_bool().unwrap() { + br.read(9).unwrap() as u16 + } else { + 0 + }; self.blocks.push(Block{ size, _pts: pts }); } } diff --git a/nihav-realmedia/src/codecs/rv10.rs b/nihav-realmedia/src/codecs/rv10.rs index 317f356..9eca2a9 100644 --- a/nihav-realmedia/src/codecs/rv10.rs +++ b/nihav-realmedia/src/codecs/rv10.rs @@ -9,13 +9,11 @@ use nihav_codec_support::codecs::h263::code::H263BlockDSP; use nihav_codec_support::codecs::h263::decoder::*; use nihav_codec_support::codecs::h263::data::*; -#[allow(dead_code)] struct Tables { intra_mcbpc_cb: Codebook, inter_mcbpc_cb: Codebook, cbpy_cb: Codebook, rl_cb: Codebook, - aic_rl_cb: Codebook, mv_cb: Codebook, luma_dc_cb: Codebook, chroma_dc_cb: Codebook, @@ -93,7 +91,7 @@ impl<'a> RealVideo10BR<'a> { } } -#[allow(unused_variables)] + #[allow(clippy::collapsible_else_if)] fn decode_block(&mut self, sstate: &SliceState, quant: u8, intra: bool, coded: bool, blk: &mut [i16; 64], plane_no: usize) -> DecoderResult<()> { let br = &mut self.br; let mut idx = 0; @@ -221,21 +219,19 @@ fn decode_mv(br: &mut BitReader, mv_cb: &Codebook) -> DecoderResult { impl<'a> BlockDecoder for RealVideo10BR<'a> { -#[allow(unused_variables)] fn decode_pichdr(&mut self) -> DecoderResult { self.slice_no = 0; let shdr = self.read_slice_header()?; validate!((shdr.mb_x == 0) && (shdr.mb_y == 0)); - let mb_end = shdr.mb_x + shdr.mb_y * self.mb_w + shdr.mb_c; + let _mb_end = shdr.mb_x + shdr.mb_y * self.mb_w + shdr.mb_c; let ftype = if !shdr.is_p { Type::I } else { Type::P }; let picinfo = PicInfo::new(self.w, self.h, ftype, self.mvmode, false, false, shdr.qscale, 0, None, None); Ok(picinfo) } - #[allow(unused_variables)] - fn decode_slice_header(&mut self, info: &PicInfo) -> DecoderResult { + fn decode_slice_header(&mut self, _info: &PicInfo) -> DecoderResult { let shdr = self.read_slice_header()?; self.slice_no += 1; let mb_end = shdr.mb_x + shdr.mb_y * self.mb_w + shdr.mb_c; @@ -311,13 +307,11 @@ impl<'a> BlockDecoder for RealVideo10BR<'a> { } } - #[allow(unused_variables)] - fn decode_block_intra(&mut self, info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { + fn decode_block_intra(&mut self, _info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { self.decode_block(sstate, quant, true, coded, blk, if no < 4 { 0 } else { no - 3 }) } - #[allow(unused_variables)] - fn decode_block_inter(&mut self, info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { + fn decode_block_inter(&mut self, _info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { self.decode_block(sstate, quant, false, coded, blk, if no < 4 { 0 } else { no - 3 }) } @@ -381,8 +375,6 @@ impl RealVideo10Decoder { let cbpy_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let mut coderead = H263RLCodeReader::new(H263_RL_CODES); let rl_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = H263RLCodeReader::new(H263_RL_CODES_AIC); - let aic_rl_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let mut coderead = H263ShortCodeReader::new(H263_MV); let mv_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let mut coderead = CodeReader::new(RV10_LUMA_DC_CODES, RV10_LUMA_DC_BITS); @@ -395,7 +387,6 @@ impl RealVideo10Decoder { inter_mcbpc_cb, cbpy_cb, rl_cb, - aic_rl_cb, mv_cb, luma_dc_cb, chroma_dc_cb, diff --git a/nihav-realmedia/src/codecs/rv20.rs b/nihav-realmedia/src/codecs/rv20.rs index 333e91a..8c83760 100644 --- a/nihav-realmedia/src/codecs/rv20.rs +++ b/nihav-realmedia/src/codecs/rv20.rs @@ -11,7 +11,6 @@ use nihav_codec_support::codecs::h263::decoder::*; use nihav_codec_support::codecs::h263::data::*; -#[allow(dead_code)] struct Tables { intra_mcbpc_cb: Codebook, inter_mcbpc_cb: Codebook, @@ -77,6 +76,7 @@ struct RV20SliceInfo { struct RV20BlockDSP {} impl RV20SliceInfo { + #[allow(clippy::too_many_arguments)] fn new(ftype: Type, seq: u32, qscale: u8, mb_x: usize, mb_y: usize, mb_pos: usize, w: usize, h: usize, loop_filter: bool) -> Self { RV20SliceInfo { ftype, seq, qscale, mb_x, mb_y, mb_pos, w, h, loop_filter } } @@ -145,12 +145,12 @@ impl BlockDSP for RV20BlockDSP { fn copy_blocks8x8(&self, dst: &mut NAVideoBuffer, src: NAVideoBufferRef, xpos: usize, ypos: usize, mvs: &[MV; 4]) { let mut dst = NASimpleVideoFrame::from_video_buf(dst).unwrap(); - for i in 0..4 { + for (i, mv) in mvs.iter().enumerate() { let xadd = (i & 1) * 8; let yadd = (i & 2) * 4; - let mode = ((mvs[i].x & 1) + (mvs[i].y & 1) * 2) as usize; + let mode = ((mv.x & 1) + (mv.y & 1) * 2) as usize; - blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mvs[i].x >> 1, mvs[i].y >> 1, 8, 8, 0, 1, mode, H263_INTERP_FUNCS); + blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mv.x >> 1, mv.y >> 1, 8, 8, 0, 1, mode, H263_INTERP_FUNCS); } let sum_mv = mvs[0] + mvs[1] + mvs[2] + mvs[3]; @@ -174,12 +174,12 @@ impl BlockDSP for RV20BlockDSP { fn avg_blocks8x8(&self, dst: &mut NAVideoBuffer, src: NAVideoBufferRef, xpos: usize, ypos: usize, mvs: &[MV; 4]) { let mut dst = NASimpleVideoFrame::from_video_buf(dst).unwrap(); - for i in 0..4 { + for (i, mv) in mvs.iter().enumerate() { let xadd = (i & 1) * 8; let yadd = (i & 2) * 4; - let mode = ((mvs[i].x & 1) + (mvs[i].y & 1) * 2) as usize; + let mode = ((mv.x & 1) + (mv.y & 1) * 2) as usize; - blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mvs[i].x >> 1, mvs[i].y >> 1, 8, 8, 0, 1, mode, H263_INTERP_AVG_FUNCS); + blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mv.x >> 1, mv.y >> 1, 8, 8, 0, 1, mode, H263_INTERP_AVG_FUNCS); } let sum_mv = mvs[0] + mvs[1] + mvs[2] + mvs[3]; @@ -197,9 +197,9 @@ impl BlockDSP for RV20BlockDSP { fn get_mb_pos_bits(mb_w: usize, mb_h: usize) -> u8 { let max_pos = mb_w * mb_h - 1; - for i in 0..H263_MBB.len() { - if max_pos <= H263_MBB[i].blocks { - return H263_MBB[i].bits; + for mbb in H263_MBB.iter() { + if max_pos <= mbb.blocks { + return mbb.bits; } } 0 @@ -238,7 +238,7 @@ impl<'a> RealVideo20BR<'a> { } } -#[allow(unused_variables)] + #[allow(clippy::too_many_arguments)] fn decode_block(&mut self, sstate: &SliceState, quant: u8, intra: bool, coded: bool, blk: &mut [i16; 64], plane_no: usize, acpred: ACPredMode) -> DecoderResult<()> { let br = &mut self.br; let mut idx = 0; @@ -327,7 +327,6 @@ fn read_dquant(br: &mut BitReader, q: u8) -> DecoderResult { impl<'a> BlockDecoder for RealVideo20BR<'a> { -#[allow(unused_variables)] fn decode_pichdr(&mut self) -> DecoderResult { self.slice_no = 0; let shdr = self.read_slice_header()?; @@ -348,8 +347,7 @@ impl<'a> BlockDecoder for RealVideo20BR<'a> { Ok(picinfo) } - #[allow(unused_variables)] - fn decode_slice_header(&mut self, info: &PicInfo) -> DecoderResult { + fn decode_slice_header(&mut self, _info: &PicInfo) -> DecoderResult { let shdr = self.read_slice_header()?; self.slice_no += 1; let mb_count; @@ -482,8 +480,7 @@ impl<'a> BlockDecoder for RealVideo20BR<'a> { self.decode_block(sstate, quant, true, coded, blk, if no < 4 { 0 } else { no - 3 }, info.get_acpred()) } - #[allow(unused_variables)] - fn decode_block_inter(&mut self, info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { + fn decode_block_inter(&mut self, _info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { self.decode_block(sstate, quant, false, coded, blk, if no < 4 { 0 } else { no - 3 }, ACPredMode::None) } @@ -491,7 +488,6 @@ impl<'a> BlockDecoder for RealVideo20BR<'a> { } impl<'a> RealVideo20BR<'a> { -#[allow(unused_variables)] fn read_slice_header(&mut self) -> DecoderResult { validate!(self.slice_no < self.num_slices); @@ -509,12 +505,7 @@ impl<'a> RealVideo20BR<'a> { validate!(marker == 0); let qscale = br.read(5)? as u8; validate!(qscale > 0); - let loop_filter; - if self.minor_ver >= 2 { - loop_filter = br.read_bool()?; - } else { - loop_filter = false; - } + let loop_filter = if self.minor_ver >= 2 { br.read_bool()? } else { false }; let seq = if self.minor_ver <= 1 { br.read(8)? << 8 } else { @@ -602,7 +593,6 @@ impl RealVideo20Decoder { } impl NADecoder for RealVideo20Decoder { -#[allow(unused_variables)] fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); @@ -618,7 +608,7 @@ impl NADecoder for RealVideo20Decoder { let ver = ((src[4] as u32) << 12) | ((src[5] as u32) << 4) | ((src[6] as u32) >> 4); let maj_ver = ver >> 16; let min_ver = (ver >> 8) & 0xFF; - let mic_ver = ver & 0xFF; + let _mic_ver = ver & 0xFF; validate!(maj_ver == 2); self.minor_ver = min_ver as u8; let rprb = src[1] & 7; diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index bbaabdf..62a258d 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -51,7 +51,6 @@ impl RV34SliceHeader { } } -#[allow(dead_code)] #[derive(Debug,Clone,Copy,PartialEq)] pub enum MBType { MBIntra, @@ -327,6 +326,7 @@ impl MVInfo { self.has_b.clear(); self.has_b.resize(size >> 2, false); } + #[allow(clippy::identity_op)] fn fill(&mut self, mb_x: usize, mb_y: usize, fwd: bool, mv: MV) { let idx = mb_x * 2 + mb_y * 2 * self.w; if fwd { @@ -362,6 +362,8 @@ impl MVInfo { pub fn pred_mb_mv(&self, mb_x: usize, mb_y: usize, fwd: bool, has_top: bool, has_left: bool, has_tr: bool, has_tl: bool) -> MV { self.pred_mv(mb_x * 2 + mb_y * 2 * self.w, fwd, has_top, has_left, has_tr, has_tl, true) } + #[allow(clippy::collapsible_else_if)] + #[allow(clippy::identity_op)] fn set_mb(&mut self, mb_x: usize, mb_y: usize, mbtype: MBType, ref_mvi: &Self, mvs: &[MV], sstate: &SState) { let mb_idx = mb_x + mb_y * (self.w >> 1); self.has_f[mb_idx] = mbtype.is_fwd(); @@ -418,12 +420,11 @@ impl MVInfo { for x in 0..2 { let has_left = (x > 0) || sstate.has_left; let has_tr = if y > 0 { x == 0 } else if x == 0 { sstate.has_top } else { sstate.has_tr }; - let has_tl; - if y == 0 { - has_tl = if x == 0 { sstate.has_tl } else { sstate.has_top }; - } else { - has_tl = if x == 0 { sstate.has_left } else { true }; - } + let has_tl = if y == 0 { + if x == 0 { sstate.has_tl } else { sstate.has_top } + } else { + if x == 0 { sstate.has_left } else { true } + }; let pred_mv = self.pred_mv(idx8 + x, true, has_top, has_left, has_tr, has_tl, false); let new_mv = mvs[x + y * 2] + pred_mv; self.mv_f[idx8 + x] = new_mv; @@ -482,7 +483,7 @@ impl MVInfo { let off = if vert { self.w } else { 1 }; let diffx = self.mv_f[idx].x - self.mv_f[idx - off].x; let diffy = self.mv_f[idx].y - self.mv_f[idx - off].y; - (diffx < -3) || (diffx > 3) || (diffy < -3) || (diffy > 3) + (diffx.abs() > 3) || (diffy.abs() > 3) } } @@ -537,18 +538,16 @@ fn decode_slice_header(br: &mut BitReader, bd: &mut dyn RV34BitstreamDecoder, sl if let Ok(nhdr) = bd.decode_slice_header(br, shdr.width, shdr.height) { validate!(nhdr.start > shdr.start); shdr.end = nhdr.start; - } else { - if slice_no + 2 < slice_offs.len() { - br.seek((slice_offs[slice_no + 2] * 8) as u32)?; - if let Ok(nhdr) = bd.decode_slice_header(br, shdr.width, shdr.height) { - validate!(nhdr.start > shdr.start); - shdr.end = nhdr.start; - } else { - shdr.end = ((shdr.width + 15) >> 4) * ((shdr.height + 15) >> 4); - } + } else if slice_no + 2 < slice_offs.len() { + br.seek((slice_offs[slice_no + 2] * 8) as u32)?; + if let Ok(nhdr) = bd.decode_slice_header(br, shdr.width, shdr.height) { + validate!(nhdr.start > shdr.start); + shdr.end = nhdr.start; } else { shdr.end = ((shdr.width + 15) >> 4) * ((shdr.height + 15) >> 4); } + } else { + shdr.end = ((shdr.width + 15) >> 4) * ((shdr.height + 15) >> 4); } br.seek(cur_pos)?; } else { @@ -825,12 +824,11 @@ impl RV34Decoder { for y in 0..4 { for x in 0..4 { let mut coeffs: [i16; 16] = [0; 16]; - let has_ac; - if (cur_cbp & 1) != 0 { - has_ac = self.coderead.decode_block(br, &mut coeffs, luma_set, 0, q_ac, q_ac, q_ac)?; - } else { - has_ac = false; - } + let has_ac = if (cur_cbp & 1) != 0 { + self.coderead.decode_block(br, &mut coeffs, luma_set, 0, q_ac, q_ac, q_ac)? + } else { + false + }; if is_16 { coeffs[0] = coeffs16[x + y * 4]; } else { @@ -874,12 +872,11 @@ impl RV34Decoder { for y in 0..2 { for x in 0..2 { let mut coeffs: [i16; 16] = [0; 16]; - let has_ac; - if (cur_cbp & 1) != 0 { - has_ac = self.coderead.decode_block(br, &mut coeffs, chroma_set, 1, q_dc, q_ac, q_ac)?; - } else { - has_ac = false; - } + let has_ac = if (cur_cbp & 1) != 0 { + self.coderead.decode_block(br, &mut coeffs, chroma_set, 1, q_dc, q_ac, q_ac)? + } else { + false + }; if !is_16 { let noright = (sstate.mb_x == sstate.mb_w - 1) && (x == 1); let has_top = sstate.has_top || (y > 0); @@ -996,12 +993,11 @@ impl RV34Decoder { for y in 0..4 { for x in 0..4 { let mut coeffs: [i16; 16] = [0; 16]; - let has_ac; - if (cur_cbp & 1) != 0 { - has_ac = self.coderead.decode_block(br, &mut coeffs, luma_set, 0, q_ac, q_ac, q_ac)?; - } else { - has_ac = false; - } + let has_ac = if (cur_cbp & 1) != 0 { + self.coderead.decode_block(br, &mut coeffs, luma_set, 0, q_ac, q_ac, q_ac)? + } else { + false + }; if is_16 { coeffs[0] = coeffs16[x + y * 4]; } @@ -1030,12 +1026,11 @@ impl RV34Decoder { for _ in 0..2 { for x in 0..2 { let mut coeffs: [i16; 16] = [0; 16]; - let has_ac; - if (cur_cbp & 1) != 0 { - has_ac = self.coderead.decode_block(br, &mut coeffs, chroma_set, 1, q_dc, q_ac, q_ac)?; - } else { - has_ac = false; - } + let has_ac = if (cur_cbp & 1) != 0 { + self.coderead.decode_block(br, &mut coeffs, chroma_set, 1, q_dc, q_ac, q_ac)? + } else { + false + }; if has_ac { self.cdsp.transform(&mut coeffs); } else { @@ -1088,6 +1083,7 @@ impl RV34Decoder { } #[allow(clippy::cognitive_complexity)] + #[allow(clippy::collapsible_else_if)] pub fn parse_frame(&mut self, supp: &mut NADecoderSupport, src: &[u8], bd: &mut dyn RV34BitstreamDecoder) -> DecoderResult<(NABufferType, FrameType, u64)> { let mut slice_offs: Vec = Vec::new(); parse_slice_offsets(src, &mut slice_offs)?; @@ -1197,19 +1193,18 @@ impl RV34Decoder { self.decode_mb_header_intra(bd, &mut br, is_i16, &mut imode, q, sstate.has_top, false)? } else { if skip_run == 0 { - let mbtype; - if self.is_rv30 { - mbtype = MBType::Invalid; - } else { - let mut hist = MBHist::new(hdr0.ftype); - if sstate.has_top { - hist.add(mbinfo[mb_pos - mb_w].mbtype); - if sstate.has_tr { hist.add(mbinfo[mb_pos - mb_w + 1].mbtype); } - } - if sstate.has_left { hist.add(mbinfo[mb_pos - 1].mbtype); } - if sstate.has_tl { hist.add(mbinfo[mb_pos - mb_w - 1].mbtype); } - mbtype = hist.get_mbtype(); - } + let mbtype = if self.is_rv30 { + MBType::Invalid + } else { + let mut hist = MBHist::new(hdr0.ftype); + if sstate.has_top { + hist.add(mbinfo[mb_pos - mb_w].mbtype); + if sstate.has_tr { hist.add(mbinfo[mb_pos - mb_w + 1].mbtype); } + } + if sstate.has_left { hist.add(mbinfo[mb_pos - 1].mbtype); } + if sstate.has_tl { hist.add(mbinfo[mb_pos - mb_w - 1].mbtype); } + hist.get_mbtype() + }; self.decode_mb_header_inter(bd, &mut br, hdr0.ftype, mbtype, &mut imode, q, sstate.has_top)? } else { skip_run -= 1; @@ -1218,8 +1213,8 @@ impl RV34Decoder { }; if !mbh.mbtype.is_intra() { let mut mvs: [MV; 4] = [ZERO_MV; 4]; - for i in 0..mbh.mbtype.get_num_mvs() { - mvs[i] = decode_mv(&mut br)?; + for mv in mvs[..mbh.mbtype.get_num_mvs()].iter_mut() { + *mv = decode_mv(&mut br)?; } if !self.is_b { self.mvi.set_mb(mb_x, mb_y, mbh.mbtype, &self.ref_mvi, &mvs, &sstate); diff --git a/nihav-realmedia/src/codecs/rv30dsp.rs b/nihav-realmedia/src/codecs/rv30dsp.rs index 36ae629..4ec44bd 100644 --- a/nihav-realmedia/src/codecs/rv30dsp.rs +++ b/nihav-realmedia/src/codecs/rv30dsp.rs @@ -9,6 +9,7 @@ fn clip8(a: i16) -> u8 { else { a as u8 } } +#[allow(clippy::identity_op)] fn rv3_filter_h(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx: usize, sstride: usize, bsize: usize, c1: i16, c2: i16) { for _ in 0..bsize { for x in 0..bsize { @@ -19,6 +20,8 @@ fn rv3_filter_h(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut } } +#[allow(clippy::erasing_op)] +#[allow(clippy::identity_op)] fn rv3_filter_v(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx: usize, sstride: usize, bsize: usize, c1: i16, c2: i16) { for _ in 0..bsize { for x in 0..bsize { diff --git a/nihav-realmedia/src/codecs/rv34codes.rs b/nihav-realmedia/src/codecs/rv34codes.rs index c5181fa..4c684b5 100644 --- a/nihav-realmedia/src/codecs/rv34codes.rs +++ b/nihav-realmedia/src/codecs/rv34codes.rs @@ -27,24 +27,24 @@ pub struct RV34CodeReader { impl RV34CodeReader { pub fn new(data: &'static [u8]) -> Self { - let len = data.len(); - let mut lengths: Vec = Vec::with_capacity(len); - let mut codes: Vec = Vec::with_capacity(len); - let mut syms: Vec = Vec::with_capacity(len); + let data_len = data.len(); + let mut lengths: Vec = Vec::with_capacity(data_len); + let mut codes: Vec = Vec::with_capacity(data_len); + let mut syms: Vec = Vec::with_capacity(data_len); let mut counts: [u32; 17] = [0; 17]; let mut prefix: [u32; 17] = [0; 17]; - for i in 0..len { - if data[i] > 0 { - counts[data[i] as usize] += 1; + for &len in data.iter() { + if len > 0 { + counts[len as usize] += 1; } } for i in 0..16 { prefix[i + 1] = (prefix[i] + counts[i]) << 1; } - for i in 0..len { - if data[i] == 0 { continue; } - lengths.push(data[i]); - let bits = data[i] as usize; + for (i, &len) in data.iter().enumerate() { + if len == 0 { continue; } + lengths.push(len); + let bits = len as usize; codes.push(prefix[bits]); prefix[bits] += 1; syms.push(i as u16); @@ -109,6 +109,7 @@ impl CodebookDescReader for RV34CBPCodeReader { } impl CBPSet { + #[allow(clippy::identity_op)] fn new(intra: bool, set: usize, subset: usize) -> Self { if intra { let mut coderead = RV34CodeReader::new(&RV34_INTRA_CBPPAT[set][subset]); @@ -227,6 +228,7 @@ fn decode_coeff(br: &mut BitReader, ccodes: &Codebook, val: u8, esc: u8, qu Ok(nval) } +#[allow(clippy::identity_op)] fn decode_subblock3(br: &mut BitReader, ccodes: &Codebook, idx: usize, q2: u16, q3: u16, q4: u16, coeffs: &mut [i16]) -> DecoderResult<()> { let flags = RV34_MODULO_THREE_TABLE[idx]; coeffs[0*4 + 0] = decode_coeff(br, ccodes, (flags >> 6) & 3, 3, q2)?; @@ -240,6 +242,7 @@ fn decode_subblock1(br: &mut BitReader, ccodes: &Codebook, idx: usize, q2: coeffs[0] = decode_coeff(br, ccodes, val, 3, q2)?; Ok(()) } +#[allow(clippy::identity_op)] fn decode_subblock(br: &mut BitReader, ccodes: &Codebook, idx: usize, invert: bool, q4: u16, coeffs: &mut [i16]) -> DecoderResult<()> { let flags = RV34_MODULO_THREE_TABLE[idx]; coeffs[0*4 + 0] = decode_coeff(br, ccodes, (flags >> 6) & 3, 3, q4)?; @@ -254,7 +257,6 @@ fn decode_subblock(br: &mut BitReader, ccodes: &Codebook, idx: usize, inver Ok(()) } -#[allow(dead_code)] pub struct RV34Codes { intra_set: Vec, inter_set: Vec, @@ -303,10 +305,10 @@ impl RV34Codes { let ones = RV34_ONES_COUNT[pattern as usize]; - for i in 0..4 { + for (i, &shift) in RV34_CBP_SHIFTS.iter().enumerate() { if ((pattern >> (3 - i)) & 1) != 0 { let code = br.read_cb(&codeset.cbp[ones])? as u32; - cbp |= code << RV34_CBP_SHIFTS[i]; + cbp |= code << shift; } } @@ -318,6 +320,7 @@ impl RV34Codes { Ok(cbp) } + #[allow(clippy::too_many_arguments)] pub fn decode_block(&mut self, br: &mut BitReader, coeffs: &mut [i16], idx0: usize, idx1: usize, q2: u16, q3: u16, q4: u16) -> DecoderResult { let codeset = if self.is_intra { &self.intra_set[self.set_idx].cset diff --git a/nihav-realmedia/src/codecs/rv34dsp.rs b/nihav-realmedia/src/codecs/rv34dsp.rs index a8f9e03..f7b3d77 100644 --- a/nihav-realmedia/src/codecs/rv34dsp.rs +++ b/nihav-realmedia/src/codecs/rv34dsp.rs @@ -18,7 +18,6 @@ pub enum PredType4x4 { VerLeftNoDown } -#[allow(dead_code)] #[derive(Debug,Clone,Copy)] pub enum PredType8x8 { DC, @@ -101,7 +100,7 @@ impl RV34CommonDSP { } pub fn transform_dc(&self, coeffs: &mut [i16]) { let val = (((coeffs[0] as i32) * 13 * 13 + 0x200) >> 10) as i16; - for i in 0..16 { coeffs[i] = val; } + for el in coeffs[..16].iter_mut() { *el = val; } } pub fn transform16(&self, coeffs: &mut [i16]) { let mut tmp: [i32; 16] = [0; 16]; @@ -120,7 +119,7 @@ impl RV34CommonDSP { } pub fn transform16_dc(&self, coeffs: &mut [i16]) { let val = (((coeffs[0] as i32) * 13 * 13 * 3) >> 11) as i16; - for i in 0..16 { coeffs[i] = val; } + for el in coeffs[..16].iter_mut() { *el = val; } } pub fn weight(&self, dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx: usize, sstride: usize, ratio1: u32, ratio2: u32, diff --git a/nihav-realmedia/src/codecs/rv40.rs b/nihav-realmedia/src/codecs/rv40.rs index 6421c22..a80b481 100644 --- a/nihav-realmedia/src/codecs/rv40.rs +++ b/nihav-realmedia/src/codecs/rv40.rs @@ -107,6 +107,7 @@ impl RealVideo40BR { had_skip_run: false, } } + #[allow(clippy::collapsible_else_if)] fn predict_b_mv_component(&self, sstate: &SState, mvi: &MVInfo, mbinfo: &[RV34MBInfo], mbtype: MBType, fwd: bool) -> MV { let mut pred_mvs: [MV; 3] = [ZERO_MV; 3]; let mut mv_count: usize = 0; @@ -196,6 +197,7 @@ impl RV34BitstreamDecoder for RealVideo40BR { Ok(RV34SliceHeader{ ftype, quant: q, deblock, pts, width: w, height: h, start, end: 0, set_idx }) } + #[allow(clippy::identity_op)] fn decode_intra_pred(&mut self, br: &mut BitReader, types: &mut [i8], mut pos: usize, tstride: usize, has_top: bool) -> DecoderResult<()> { let start; if has_top { diff --git a/nihav-realmedia/src/codecs/rv40dsp.rs b/nihav-realmedia/src/codecs/rv40dsp.rs index 2300941..466a88d 100644 --- a/nihav-realmedia/src/codecs/rv40dsp.rs +++ b/nihav-realmedia/src/codecs/rv40dsp.rs @@ -285,12 +285,9 @@ fn rv40_weak_loop_filter4(pix: &mut [u8], mut off: usize, step: usize, stride: u let q1 = el!(pix, off + step); let q2 = el!(pix, off + 2*step); - let strength; - if filter_p1 && filter_q1 { - strength = (t << 2) + (p1 - q1); - } else { - strength = t << 2; - } + let strength = if filter_p1 && filter_q1 { + (t << 2) + (p1 - q1) + } else { t << 2 }; let diff = clip_symm((strength + 4) >> 3, lim_p0q0); pix[off - step] = clip8(p0 + diff); @@ -315,7 +312,6 @@ fn rv40_weak_loop_filter4_h(pix: &mut [u8], off: usize, stride: usize, lim_p0q0: i16, lim_p1: i16, lim_q1: i16) { rv40_weak_loop_filter4(pix, off, stride, 1, filter_p1, filter_q1, alpha, beta, lim_p0q0, lim_p1, lim_q1); } -#[allow(clippy::eq_op)] fn rv40_weak_loop_filter4_v(pix: &mut [u8], off: usize, stride: usize, filter_p1: bool, filter_q1: bool, alpha: i16, beta: i16, lim_p0q0: i16, lim_p1: i16, lim_q1: i16) { @@ -340,12 +336,9 @@ fn rv40_weak_loop_filter4_v(pix: &mut [u8], off: usize, stride: usize, let q1 = el!(ch, 3 + 1); let q2 = el!(ch, 3 + 2); - let strength; - if filter_p1 && filter_q1 { - strength = (t << 2) + (p1 - q1); - } else { - strength = t << 2; - } + let strength = if filter_p1 && filter_q1 { + (t << 2) + (p1 - q1) + } else { t << 2 }; let diff = clip_symm((strength + 4) >> 3, lim_p0q0); ch[3 - 1] = clip8(p0 + diff); @@ -474,7 +467,6 @@ fn rv40_loop_strength_h(pix: &[u8], off: usize, stride: usize, rv40_loop_strength(pix, off, stride, 1, beta, beta2, edge) } -#[allow(clippy::eq_op)] fn rv40_loop_strength_v(pix: &[u8], off: usize, stride: usize, beta: i16, beta2: i16, edge: bool) -> (bool, bool, bool) { let src = &pix[off - 3..][..stride * 3 + 3 + 3]; diff --git a/nihav-realmedia/src/codecs/rv40enc/bitstream.rs b/nihav-realmedia/src/codecs/rv40enc/bitstream.rs index 892b7ff..d41aeec 100644 --- a/nihav-realmedia/src/codecs/rv40enc/bitstream.rs +++ b/nihav-realmedia/src/codecs/rv40enc/bitstream.rs @@ -255,6 +255,7 @@ struct CBPSet { } impl CBPSet { + #[allow(clippy::identity_op)] fn new(intra: bool, set: usize, subset: usize) -> Self { if intra { let cbp_pat = RV34CodeReader::new(&RV34_INTRA_CBPPAT[set][subset]); diff --git a/nihav-realmedia/src/codecs/rv40enc/dsp/blk.rs b/nihav-realmedia/src/codecs/rv40enc/dsp/blk.rs index 9a4a716..192cf72 100644 --- a/nihav-realmedia/src/codecs/rv40enc/dsp/blk.rs +++ b/nihav-realmedia/src/codecs/rv40enc/dsp/blk.rs @@ -1,6 +1,7 @@ use super::super::types::Block; use super::clip8; +#[allow(clippy::wrong_self_convention)] pub trait BlockOps { fn from_diff(&mut self, new: &[u8], old: &[u8], stride: usize); fn add_to(&self, dst: &mut [u8], stride: usize); diff --git a/nihav-realmedia/src/codecs/rv40enc/dsp/ipred.rs b/nihav-realmedia/src/codecs/rv40enc/dsp/ipred.rs index f5df3d2..aac1c1b 100644 --- a/nihav-realmedia/src/codecs/rv40enc/dsp/ipred.rs +++ b/nihav-realmedia/src/codecs/rv40enc/dsp/ipred.rs @@ -168,6 +168,7 @@ impl Intra4Pred { } (left, top) } + #[allow(clippy::collapsible_else_if)] #[allow(clippy::many_single_char_names)] pub fn apply(&self, ptype: PredType4x4, buf: &mut [u8], stride: usize) { match ptype { diff --git a/nihav-realmedia/src/codecs/rv40enc/dsp/loopfilt.rs b/nihav-realmedia/src/codecs/rv40enc/dsp/loopfilt.rs index 5fa25ef..aa9bfbc 100644 --- a/nihav-realmedia/src/codecs/rv40enc/dsp/loopfilt.rs +++ b/nihav-realmedia/src/codecs/rv40enc/dsp/loopfilt.rs @@ -359,12 +359,11 @@ fn rv40_weak_loop_filter4(pix: &mut [u8], mut off: usize, step: usize, stride: u let q1 = el!(pix, off + step); let q2 = el!(pix, off + 2*step); - let strength; - if filter_p1 && filter_q1 { - strength = (t << 2) + (p1 - q1); - } else { - strength = t << 2; - } + let strength = if filter_p1 && filter_q1 { + (t << 2) + (p1 - q1) + } else { + t << 2 + }; let diff = clip_symm((strength + 4) >> 3, lim_p0q0); pix[off - step] = clip8(p0 + diff); @@ -389,7 +388,6 @@ fn rv40_weak_loop_filter4_h(pix: &mut [u8], off: usize, stride: usize, lim_p0q0: i16, lim_p1: i16, lim_q1: i16) { rv40_weak_loop_filter4(pix, off, stride, 1, filter_p1, filter_q1, alpha, beta, lim_p0q0, lim_p1, lim_q1); } -#[allow(clippy::eq_op)] fn rv40_weak_loop_filter4_v(pix: &mut [u8], off: usize, stride: usize, filter_p1: bool, filter_q1: bool, alpha: i16, beta: i16, lim_p0q0: i16, lim_p1: i16, lim_q1: i16) { @@ -414,12 +412,11 @@ fn rv40_weak_loop_filter4_v(pix: &mut [u8], off: usize, stride: usize, let q1 = el!(ch, 3 + 1); let q2 = el!(ch, 3 + 2); - let strength; - if filter_p1 && filter_q1 { - strength = (t << 2) + (p1 - q1); - } else { - strength = t << 2; - } + let strength = if filter_p1 && filter_q1 { + (t << 2) + (p1 - q1) + } else { + t << 2 + }; let diff = clip_symm((strength + 4) >> 3, lim_p0q0); ch[3 - 1] = clip8(p0 + diff); @@ -539,7 +536,6 @@ fn rv40_loop_strength_h(pix: &[u8], off: usize, stride: usize, rv40_loop_strength(pix, off, stride, 1, beta, beta2, edge) } -#[allow(clippy::eq_op)] fn rv40_loop_strength_v(pix: &[u8], off: usize, stride: usize, beta: i16, beta2: i16, edge: bool) -> (bool, bool, bool) { let src = &pix[off - 3..][..stride * 3 + 3 + 3]; diff --git a/nihav-realmedia/src/codecs/rv40enc/mod.rs b/nihav-realmedia/src/codecs/rv40enc/mod.rs index 071a7ae..8096697 100644 --- a/nihav-realmedia/src/codecs/rv40enc/mod.rs +++ b/nihav-realmedia/src/codecs/rv40enc/mod.rs @@ -8,12 +8,16 @@ use nihav_core::io::bitwriter::*; mod bitstream; use bitstream::*; +#[allow(clippy::eq_op)] +#[allow(clippy::identity_op)] +#[allow(clippy::too_many_arguments)] mod dsp; use dsp::loop_filter_frame; mod estimator; use estimator::*; +#[allow(clippy::too_many_arguments)] mod mb_coding; use mb_coding::*; diff --git a/nihav-realmedia/src/codecs/rv40enc/motion_est.rs b/nihav-realmedia/src/codecs/rv40enc/motion_est.rs index 9fa18e9..f59c588 100644 --- a/nihav-realmedia/src/codecs/rv40enc/motion_est.rs +++ b/nihav-realmedia/src/codecs/rv40enc/motion_est.rs @@ -53,6 +53,7 @@ impl FromStr for MVSearchMode { const MAX_DIST: u32 = std::u32::MAX; const DIST_THRESH: u32 = 256; +#[allow(clippy::wrong_self_convention)] trait FromPixels { fn from_pixels(self) -> Self; } @@ -305,6 +306,7 @@ impl UniqueSet { } } +#[allow(clippy::wrong_self_convention)] trait MVOps { fn scale(self, scale: i16) -> Self; fn is_in_range(self, range: i16) -> bool; diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index befe7a6..f51c62c 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -60,6 +60,8 @@ struct FrameHeader { const RV60_CUSTOM_MSG_LENS: [u32; 4] = [ 2, 4, 16, 32 ]; impl FrameHeader { + #[allow(clippy::identity_op)] + #[allow(clippy::needless_late_init)] fn read(br: &mut BitReader) -> DecoderResult { let marker = br.read(2)?; validate!(marker == 3); @@ -107,8 +109,8 @@ impl FrameHeader { if br.read_bool()? { let custom_msg_hdr_len = br.read(2)? as usize; if custom_msg_hdr_len != 0 { - for i in 0..custom_msg_hdr_len { - br.skip(RV60_CUSTOM_MSG_LENS[i] * 8)?; + for &msg_len in RV60_CUSTOM_MSG_LENS[..custom_msg_hdr_len].iter() { + br.skip(msg_len * 8)?; } } } @@ -135,18 +137,15 @@ impl FrameHeader { sum += first_size; let mut lastsize = first_size; sizes.push(first_size); - for i in 1..nslices { + for &sign in signs[1..nslices].iter() { let diff = br.read(nbits)? as isize; - let size; - if signs[i] { - let sum = (lastsize as isize).checked_add(diff); - validate!(sum.is_some()); - size = sum.unwrap() as usize; - } else { - let sum = (lastsize as isize).checked_sub(diff); - validate!(sum.is_some()); - size = sum.unwrap() as usize; - } + let newsize = if sign { + (lastsize as isize).checked_add(diff) + } else { + (lastsize as isize).checked_sub(diff) + }; + validate!(newsize.is_some()); + let size = newsize.unwrap() as usize; sizes.push(size); sum += size; lastsize = size; @@ -411,16 +410,16 @@ struct CBHeader { } impl CBHeader { + #[allow(clippy::collapsible_else_if)] fn read(br: &mut BitReader, ftype: FrameType, two_f_refs: bool, size: usize) -> DecoderResult { - let cu_type; let pu_type; let mut imode: [IntraMode; 4] = [IntraMode::Index(0); 4]; let mut mv: [MVInfo; 4] = [MVInfo::default(); 4]; - if ftype == FrameType::I { - cu_type = CUType::Intra; - } else { - cu_type = RV60_CU_TYPES[br.read(2)? as usize]; - } + let cu_type = if ftype == FrameType::I { + CUType::Intra + } else { + RV60_CU_TYPES[br.read(2)? as usize] + }; match cu_type { CUType::Intra => { if (size == 8) && br.read_bool()? { @@ -429,8 +428,8 @@ impl CBHeader { pu_type = PUType::Full; } if pu_type == PUType::Quarters { - for i in 0..4 { - imode[i] = CBHeader::read_intra_mode(br)?; + for imode in imode.iter_mut() { + *imode = CBHeader::read_intra_mode(br)?; } } else if size <= 32 { imode[0] = CBHeader::read_intra_mode(br)?; @@ -486,8 +485,8 @@ impl CBHeader { } fn read_mv_data(br: &mut BitReader, ftype: FrameType, two_f_refs: bool, size: usize, pu_type: PUType, mv: &mut [MVInfo; 4]) -> DecoderResult<()> { let mv_count = pu_type.get_num_mvs(); - for i in 0..mv_count { - mv[i] = CBHeader::read_mv_info(br, ftype, two_f_refs, size, pu_type)?; + for mv in mv[..mv_count].iter_mut() { + *mv = CBHeader::read_mv_info(br, ftype, two_f_refs, size, pu_type)?; } Ok(()) } @@ -713,6 +712,8 @@ println!(" left {} bits", br.left()); Ok(()) } #[allow(clippy::cognitive_complexity)] + #[allow(clippy::collapsible_else_if)] + #[allow(clippy::identity_op)] 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.awidth) || (ypos >= hdr.aheight) { return Ok(()); } @@ -830,12 +831,9 @@ println!(" left {} bits", br.left()); TransformType::T4X4 => { let subset = if is_intra { 0 } else { 2 }; if size == 16 { - let cbp16; - if br.read_bool()? { - cbp16 = rv6_decode_cbp16(br, &self.cbs, subset, self.sel_qp)?; - } else { - cbp16 = 0; - } + let cbp16 = if br.read_bool()? { + rv6_decode_cbp16(br, &self.cbs, subset, self.sel_qp)? + } else { 0 }; if cbp16 != 0 { rv6_decode_cu_4x4in16x16(br, &self.cbs, is_intra, self.qp, self.sel_qp, &mut self.y_coeffs, &mut self.u_coeffs, &mut self.v_coeffs, cbp16)?; for y in 0..4 { @@ -1132,6 +1130,7 @@ println!(" left {} bits", br.left()); _ => unreachable!(), } } + #[allow(clippy::too_many_arguments)] fn populate_ipred(&mut self, hdr: &FrameHeader, src: &[u8], soff: usize, stride: usize, xoff: usize, yoff: usize, size: usize, is_luma: bool) { let src_off = if is_luma { soff + self.xpos + xoff + (self.ypos + yoff) * stride @@ -1365,6 +1364,7 @@ println!(" left {} bits", br.left()); } } } + #[allow(clippy::collapsible_if)] fn derive_deblock_strength(&mut self, xpos: usize, ypos: usize, size4: usize) { let blk_pos = (xpos >> 2) + (ypos >> 2) * self.blk_stride; let mut dblk_pos = self.dblk.get_pos(xpos, ypos); diff --git a/nihav-realmedia/src/codecs/rv60codes.rs b/nihav-realmedia/src/codecs/rv60codes.rs index 390458c..a8f36fb 100644 --- a/nihav-realmedia/src/codecs/rv60codes.rs +++ b/nihav-realmedia/src/codecs/rv60codes.rs @@ -290,13 +290,11 @@ pub fn rv6_decode_cbp8(br: &mut BitReader, cbs: &RV60Codebooks, subset: usize, q pub fn rv6_decode_cbp16(br: &mut BitReader, cbs: &RV60Codebooks, subset: usize, qp: u8) -> DecoderResult { let cb_set = RV60_QP_TO_IDX[qp as usize]; - let cbp16; if subset == 0 { - cbp16 = decode_super_cbp(br, &cbs.cbp8_cb[cb_set])?; + decode_super_cbp(br, &cbs.cbp8_cb[cb_set]) } else { - cbp16 = decode_super_cbp(br, &cbs.cbp16_cb[cb_set][(subset - 1) * 4..][..4])?; + decode_super_cbp(br, &cbs.cbp16_cb[cb_set][(subset - 1) * 4..][..4]) } - Ok(cbp16) } pub fn rv6_decode_cu_8x8(br: &mut BitReader, cbs: &RV60Codebooks, is_intra: bool, qp: u8, sel_qp: u8, y_coeffs: &mut [i16; 16 * 16], u_coeffs: &mut [i16; 8 * 8], v_coeffs: &mut [i16; 8 * 8], ccbp: u32, mode4x4: bool) -> DecoderResult<()> { diff --git a/nihav-realmedia/src/codecs/rv60dsp.rs b/nihav-realmedia/src/codecs/rv60dsp.rs index 8995b48..84fdeff 100644 --- a/nihav-realmedia/src/codecs/rv60dsp.rs +++ b/nihav-realmedia/src/codecs/rv60dsp.rs @@ -660,6 +660,7 @@ pub struct IntraPredContext { pub has_ld: bool, } +#[allow(clippy::needless_range_loop)] impl IntraPredContext { pub fn new() -> Self { Self { @@ -781,8 +782,8 @@ impl IntraPredContext { fn filter_bilin32(dst: &mut [u8], v0: u8, v1: u8, size: usize) { let diff = (v1 as i16) - (v0 as i16); let mut sum = ((v0 as i16) << 5) + (1 << (5 - 1)); - for i in 0..size { - dst[i] = (sum >> 5) as u8; + for el in dst[..size].iter_mut() { + *el = (sum >> 5) as u8; sum += diff; } } diff --git a/nihav-realmedia/src/demuxers/mod.rs b/nihav-realmedia/src/demuxers/mod.rs index 820dd2e..7f9e4ac 100644 --- a/nihav-realmedia/src/demuxers/mod.rs +++ b/nihav-realmedia/src/demuxers/mod.rs @@ -11,7 +11,6 @@ macro_rules! validate { #[cfg(feature="demuxer_real")] #[allow(clippy::identity_op)] -#[allow(clippy::needless_range_loop)] mod realmedia; const RM_DEMUXERS: &[&dyn DemuxerCreator] = &[ diff --git a/nihav-realmedia/src/demuxers/realmedia.rs b/nihav-realmedia/src/demuxers/realmedia.rs index 7f94cdc..2978260 100644 --- a/nihav-realmedia/src/demuxers/realmedia.rs +++ b/nihav-realmedia/src/demuxers/realmedia.rs @@ -257,9 +257,9 @@ impl RMAudioStream { fn sipro_restore(buf: &mut [u8], factor: usize, fsize: usize) { let stride = factor * fsize * 2 / 96; - for i in 0..38 { - let mut sidx = (RM_SIPRO_SWAPS[i][0] as usize) * stride; - let mut didx = (RM_SIPRO_SWAPS[i][1] as usize) * stride; + for swap in RM_SIPRO_SWAPS.iter() { + let mut sidx = (swap[0] as usize) * stride; + let mut didx = (swap[1] as usize) * stride; for _ in 0..stride { let in0 = buf[sidx >> 1]; let in1 = buf[didx >> 1]; @@ -537,28 +537,25 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); streams.push(RMStreamType::Audio(astr)); Ok(()) } -#[allow(unused_variables)] fn parse_video_stream(strmgr: &mut StreamManager, streams: &mut Vec, stream_no: u32, src: &mut ByteReader, edata_: &[u8], tag2: u32, duration: u32) -> DemuxerResult<()> { src.read_skip(4)?; let fcc = src.read_u32be()?; let width = src.read_u16be()? as usize; let height = src.read_u16be()? as usize; - let bpp = src.read_u16be()?; - let pad_w = src.read_u16be()?; - let pad_h = src.read_u16be()?; - let _fps; - if tag2 == mktag!('V', 'I', 'D', 'O') { - _fps = src.read_u32be()?; - } else { - _fps = 0x10000; - } - let extradata: Option>; - if src.left() > 0 { - let eslice = &edata_[(src.tell() as usize)..]; - extradata = Some(eslice.to_vec()); - } else { - extradata = None; - } + let _bpp = src.read_u16be()?; + let _pad_w = src.read_u16be()?; + let _pad_h = src.read_u16be()?; + let _fps = if tag2 == mktag!('V', 'I', 'D', 'O') { + src.read_u32be()? + } else { + 0x10000 + }; + let extradata = if src.left() > 0 { + let eslice = &edata_[(src.tell() as usize)..]; + Some(eslice.to_vec()) + } else { + None + }; let cname = find_codec_name(RM_VIDEO_CODEC_REGISTER, fcc); let vhdr = NAVideoInfo::new(width, height, false, RGB24_FORMAT); @@ -570,8 +567,7 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); streams.push(RMStreamType::Video(vstr)); Ok(()) } -#[allow(unused_variables)] - #[allow(clippy::question_mark)] + #[allow(clippy::too_many_arguments)] fn parse_packet_payload(src: &mut ByteReader, rmstream: &mut RMStreamType, stream: NAStreamRef, slice_buf: &mut Vec, queued_pkts: &mut Vec, keyframe: bool, ts: u32, payload_size: usize) -> DemuxerResult { match rmstream { RMStreamType::Video(ref mut vstr) => { @@ -586,7 +582,7 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); let packet_num = hdr1 & 0x7F; let (_, frame_size) = read_14or30(src)?; let (_, off) = read_14or30(src)?; - let seq_no = src.read_byte()?; + let _seq_no = src.read_byte()?; let hdr_skip = (src.tell() - pos) as usize; let slice_size = payload_size - hdr_skip; @@ -606,7 +602,7 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); Ok(pkt) }, 1 => { // whole frame - let seq_no = src.read_byte()?; + let _seq_no = src.read_byte()?; read_video_buf(src, stream, ts, keyframe, payload_size - 2) }, 2 => { // last partial frame @@ -616,7 +612,7 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); let packet_num = hdr1 & 0x7F; let (_, frame_size) = read_14or30(src)?; let (_, tail_size) = read_14or30(src)?; - let seq_no = src.read_byte()?; + let _seq_no = src.read_byte()?; slice_buf.resize(tail_size as usize, 0); src.read_buf(slice_buf.as_mut_slice())?; if packet_num == 1 && frame_size == tail_size { @@ -626,9 +622,8 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); } while src.tell() < pos + (payload_size as u64) { - let res = read_multiple_frame(src, stream.clone(), false, false); - if res.is_err() { break; } - queued_pkts.push(res.unwrap()); + let pkt = read_multiple_frame(src, stream.clone(), false, false)?; + queued_pkts.push(pkt); } queued_pkts.reverse(); let ts = stream.make_ts(Some(ts as u64), None, None); @@ -636,15 +631,13 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); Ok(pkt) }, _ => { // multiple frames - let res = read_multiple_frame(src, stream.clone(), keyframe, true); - if res.is_err() { return res; } + let pkt0 = read_multiple_frame(src, stream.clone(), keyframe, true)?; while src.tell() < pos + (payload_size as u64) { - let res = read_multiple_frame(src, stream.clone(), false, false); - if res.is_err() { break; } - queued_pkts.push(res.unwrap()); + let pkt = read_multiple_frame(src, stream.clone(), false, false)?; + queued_pkts.push(pkt); } queued_pkts.reverse(); - res + Ok(pkt0) }, } }, @@ -665,7 +658,6 @@ impl<'a> DemuxCore<'a> for RealMediaDemuxer<'a> { Ok(()) } -#[allow(unused_variables)] fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult { if !self.queued_pkts.is_empty() { let pkt = self.queued_pkts.pop().unwrap(); @@ -677,8 +669,7 @@ impl<'a> DemuxCore<'a> for RealMediaDemuxer<'a> { if self.cur_data_chunk < self.data_chunks.len() { let (pos, _, _) = self.data_chunks[self.cur_data_chunk]; self.src.seek(SeekFrom::Start(pos))?; - let res = read_chunk(self.src); - if let Ok((id, size, ver)) = res { + if let Ok((_id, size, ver)) = read_chunk(self.src) { self.data_pos = self.src.tell(); self.data_ver = ver; self.data_end = self.data_pos + (size as u64); @@ -745,7 +736,6 @@ impl<'a> DemuxCore<'a> for RealMediaDemuxer<'a> { } } - #[allow(unused_variables)] fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> { self.queued_pkts.clear(); let ret = seek_idx.find_pos(time); @@ -839,7 +829,6 @@ fn skip_ra_metadata(src: &mut ByteReader) -> DemuxerResult<()> { Ok(()) } -#[allow(unused_variables)] fn parse_aformat3(src: &mut ByteReader) -> DemuxerResult { let start = src.tell(); let header_len = src.read_u16be()?; @@ -873,13 +862,12 @@ fn parse_aformat3(src: &mut ByteReader) -> DemuxerResult { }) } -#[allow(unused_variables)] fn parse_aformat4(src: &mut ByteReader) -> DemuxerResult { let start = src.tell(); src.read_skip(2)?; // zeroes let id = src.read_u32be()?; validate!(id == mktag!(b".ra4")); - let data_size = src.read_u32be()?; + let _data_size = src.read_u32be()?; let _ver4 = src.read_u16be()?; // should be 4 let header_size = src.read_u32be()?; let flavor = src.read_u16be()?; @@ -926,13 +914,12 @@ fn parse_aformat4(src: &mut ByteReader) -> DemuxerResult { }) } -#[allow(unused_variables)] fn parse_aformat5(src: &mut ByteReader) -> DemuxerResult { let start = src.tell(); src.read_skip(2)?; // zeroes let id = src.read_u32be()?; validate!((id == mktag!(b".ra5")) || (id == mktag!(b".ra4"))); - let data_size = src.read_u32be()?; + let _data_size = src.read_u32be()?; let _ver5 = src.read_u16be()?; // should be 5 let header_size = src.read_u32be()?; let flavor = src.read_u16be()?; @@ -943,7 +930,7 @@ fn parse_aformat5(src: &mut ByteReader) -> DemuxerResult { let ileave_factor = src.read_u16be()?; let frame_size = src.read_u16be()?; let ileave_block_size = src.read_u16be()?; - let user_data = src.read_u32be()?; + let _user_data = src.read_u32be()?; let _sample_rate1 = src.read_u16be()?; let sample_rate = src.read_u32be()?; let sample_size = src.read_u32be()?; @@ -1009,9 +996,8 @@ impl<'a> RealMediaDemuxer<'a> { slice_buf: Vec::new(), } } -#[allow(unused_variables)] fn read_header(&mut self, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex) -> DemuxerResult<()> { - let (id, size, ver) = read_chunk(self.src)?; + let (id, size, _ver) = read_chunk(self.src)?; validate!((id == mktag!(b".RMF")) || (id == mktag!(b".RMP"))); validate!(size >= RMVB_HDR_SIZE); let fver = self.src.read_u32be()?; @@ -1026,17 +1012,17 @@ impl<'a> RealMediaDemuxer<'a> { let prop_size = if ver == 0 { RMVB_PROP_SIZE } else { RMVB_PROP_SIZE + 4 }; validate!(size >= prop_size); validate!((ver == 0) || (ver == 2)); - let maxbr = self.src.read_u32be()?; - let avgbr = self.src.read_u32be()?; - let maxps = self.src.read_u32be()?; - let avgps = self.src.read_u32be()?; - let num_pkt = self.src.read_u32be()? as usize; - let duration = self.src.read_u32be()?; - let preroll = self.src.read_u32be()?; - let idx_off = self.src.read_size(ver)?; - let data_off = self.src.read_u32be()?; - let num_streams = self.src.read_u16be()? as usize; - let flags = self.src.read_u16be()?; + let _maxbr = self.src.read_u32be()?; + let _avgbr = self.src.read_u32be()?; + let _maxps = self.src.read_u32be()?; + let _avgps = self.src.read_u32be()?; + let _num_pkt = self.src.read_u32be()? as usize; + let _duration = self.src.read_u32be()?; + let _preroll = self.src.read_u32be()?; + let _idx_off = self.src.read_size(ver)?; + let _data_off = self.src.read_u32be()?; + let _um_streams = self.src.read_u16be()? as usize; + let _flags = self.src.read_u16be()?; if size > prop_size { self.src.read_skip((size - prop_size) as usize)?; } @@ -1102,7 +1088,6 @@ impl<'a> RealMediaDemuxer<'a> { } Ok(false) } -#[allow(unused_variables)] fn parse_content_desc(&mut self) -> DemuxerResult<()> { let title_len = self.src.read_u16be()? as usize; self.src.read_skip(title_len)?; @@ -1114,21 +1099,20 @@ impl<'a> RealMediaDemuxer<'a> { self.src.read_skip(comment_len)?; Ok(()) } -#[allow(unused_variables)] fn parse_mdpr(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<()> { let stream_no = self.src.read_u16be()? as u32; //todo check stream_no for duplicates - let maxbr = self.src.read_u32be()?; - let avgbr = self.src.read_u32be()?; - let maxps = self.src.read_u32be()?; - let avgps = self.src.read_u32be()?; - let start = self.src.read_u32be()?; - let preroll = self.src.read_u32be()?; + let _maxbr = self.src.read_u32be()?; + let _avgbr = self.src.read_u32be()?; + let _maxps = self.src.read_u32be()?; + let _avgps = self.src.read_u32be()?; + let _start = self.src.read_u32be()?; + let _preroll = self.src.read_u32be()?; let duration = self.src.read_u32be()?; let sname_size = self.src.read_byte()? as usize; - let sname = read_string_size(self.src, sname_size)?; + let _sname = read_string_size(self.src, sname_size)?; let mime_size = self.src.read_byte()? as usize; - let mime = read_string_size(self.src, mime_size)?; + let _mime = read_string_size(self.src, mime_size)?; let edata_size = self.src.read_u32be()? as usize; let edata: Option> = if edata_size == 0 { None } else { let mut edvec: Vec = vec![0; edata_size]; @@ -1200,7 +1184,6 @@ struct RealAudioDemuxer<'a> { } impl<'a> DemuxCore<'a> for RealAudioDemuxer<'a> { - #[allow(unused_variables)] fn open(&mut self, strmgr: &mut StreamManager, _seek_idx: &mut SeekIndex) -> DemuxerResult<()> { let magic = self.src.read_u32be()?; validate!(magic == mktag!(b".ra\xFD")); @@ -1276,8 +1259,7 @@ impl<'a> DemuxCore<'a> for RealAudioDemuxer<'a> { Err(DemuxerError::NoSuchInput) } - #[allow(unused_variables)] - fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> { + fn seek(&mut self, _time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> { Err(NotImplemented) } @@ -1547,8 +1529,7 @@ struct RealIVRDemuxer<'a> { } impl<'a> DemuxCore<'a> for RealIVRDemuxer<'a> { - #[allow(unused_variables)] - fn open(&mut self, strmgr: &mut StreamManager, seek_idx: &mut SeekIndex) -> DemuxerResult<()> { + fn open(&mut self, strmgr: &mut StreamManager, _seek_idx: &mut SeekIndex) -> DemuxerResult<()> { let magic = self.src.peek_u32be()?; if magic == mktag!(b".REC") { let mut rec = RecordDemuxer::new(0, 0); @@ -1617,8 +1598,7 @@ impl<'a> DemuxCore<'a> for RealIVRDemuxer<'a> { } } - #[allow(unused_variables)] - fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> { + fn seek(&mut self, _time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> { Err(NotImplemented) } diff --git a/nihav-realmedia/src/lib.rs b/nihav-realmedia/src/lib.rs index a5083c0..1a16258 100644 --- a/nihav-realmedia/src/lib.rs +++ b/nihav-realmedia/src/lib.rs @@ -3,21 +3,9 @@ extern crate nihav_core; extern crate nihav_codec_support; #[cfg(any(feature="decoders", feature="encoders"))] -#[allow(clippy::cast_lossless)] -#[allow(clippy::collapsible_if)] -#[allow(clippy::collapsible_else_if)] -#[allow(clippy::comparison_chain)] #[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)] -#[allow(clippy::needless_late_init)] #[allow(clippy::upper_case_acronyms)] -#[allow(clippy::manual_range_contains)] -#[allow(clippy::wrong_self_convention)] mod codecs; #[cfg(feature="decoders")] pub use crate::codecs::realmedia_register_all_decoders; @@ -25,11 +13,6 @@ pub use crate::codecs::realmedia_register_all_decoders; pub use crate::codecs::realmedia_register_all_encoders; #[cfg(feature="demuxers")] -#[allow(clippy::cast_lossless)] -#[allow(clippy::too_many_arguments)] -#[allow(clippy::unreadable_literal)] -#[allow(clippy::useless_let_if_seq)] -#[allow(clippy::needless_late_init)] #[allow(clippy::upper_case_acronyms)] mod demuxers; #[cfg(feature="demuxers")] -- 2.39.5