From e69b11482edfe7d2d3604a828e46990df78ef852 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 15 May 2019 11:58:16 +0200 Subject: [PATCH] game: fix some clippy warnings --- nihav-game/src/codecs/bmv.rs | 6 ++---- nihav-game/src/codecs/bmv3.rs | 13 +++---------- nihav-game/src/codecs/gremlinvideo.rs | 6 ++---- nihav-game/src/codecs/mod.rs | 2 +- nihav-game/src/codecs/vmd.rs | 14 ++++++-------- nihav-game/src/demuxers/bmv.rs | 17 +++++++---------- nihav-game/src/demuxers/gdv.rs | 16 ++++++++-------- nihav-game/src/demuxers/mod.rs | 4 ++-- nihav-game/src/demuxers/vmd.rs | 10 +++++----- 9 files changed, 36 insertions(+), 52 deletions(-) diff --git a/nihav-game/src/codecs/bmv.rs b/nihav-game/src/codecs/bmv.rs index c00760e..f2458af 100644 --- a/nihav-game/src/codecs/bmv.rs +++ b/nihav-game/src/codecs/bmv.rs @@ -206,9 +206,7 @@ impl NADecoder for BMVVideoDecoder { } let pos = br.tell() as usize; - let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 0); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let mut bufinfo = bufret.unwrap(); + let mut bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 0)?; self.decode_frame(&src[pos..], &mut bufinfo, line)?; @@ -242,7 +240,7 @@ impl BMVAudioDecoder { } fn scale_sample(samp: u8, scale: i32) -> i16 { - let val = (((samp as i8) as i32) * scale) >> 5; + let val = (i32::from(samp as i8) * scale) >> 5; if val < -32768 { -32768 } else if val > 32767 { diff --git a/nihav-game/src/codecs/bmv3.rs b/nihav-game/src/codecs/bmv3.rs index b30628e..efc3c7e 100644 --- a/nihav-game/src/codecs/bmv3.rs +++ b/nihav-game/src/codecs/bmv3.rs @@ -85,11 +85,6 @@ struct BMV3VideoDecoder { impl BMV3VideoDecoder { fn new() -> Self { - let mut frame1 = Vec::with_capacity(BMV_MAX_SIZE); - frame1.resize(BMV_MAX_SIZE, 0); - let mut frame2 = Vec::with_capacity(BMV_MAX_SIZE); - frame2.resize(BMV_MAX_SIZE, 0); - let mut pixels = [0u16; 256]; for (i, el) in pixels.iter_mut().enumerate() { *el = i as u16; @@ -105,8 +100,8 @@ impl BMV3VideoDecoder { info: NACodecInfoRef::default(), stride: 0, height: 0, - frame: frame1, - prev_frame: frame2, + frame: vec![0; BMV_MAX_SIZE], + prev_frame: vec![0; BMV_MAX_SIZE], pixels, pixbuf, mode: BMV3Mode::Normal, pos: 0, @@ -481,9 +476,7 @@ impl NADecoder for BMV3VideoDecoder { self.pos = off + self.stride; self.is_intra = (flags & BMV_INTRA) == BMV_INTRA; - let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 0); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 0)?; self.decode_frame(&mut br)?; diff --git a/nihav-game/src/codecs/gremlinvideo.rs b/nihav-game/src/codecs/gremlinvideo.rs index 19021ee..621e23c 100644 --- a/nihav-game/src/codecs/gremlinvideo.rs +++ b/nihav-game/src/codecs/gremlinvideo.rs @@ -50,7 +50,7 @@ impl Bits32 { self.queue >>= nbits; self.fill -= nbits; if self.fill <= 16 { - self.queue |= (br.read_u16le()? as u32) << self.fill; + self.queue |= u32::from(br.read_u16le()?) << self.fill; self.fill += 16; } Ok(res) @@ -447,9 +447,7 @@ impl NADecoder for GremlinVideoDecoder { return Err(DecoderError::NotImplemented); } - let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 0); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let mut bufinfo = bufret.unwrap(); + let mut bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 0)?; self.output_frame(&mut bufinfo, w, h); diff --git a/nihav-game/src/codecs/mod.rs b/nihav-game/src/codecs/mod.rs index 0cd5f35..29e025e 100644 --- a/nihav-game/src/codecs/mod.rs +++ b/nihav-game/src/codecs/mod.rs @@ -33,7 +33,7 @@ const GAME_CODECS: &[DecoderInfo] = &[ ]; pub fn game_register_all_codecs(rd: &mut RegisteredDecoders) { - for decoder in GAME_CODECS.into_iter() { + for decoder in GAME_CODECS.iter() { rd.add_decoder(decoder.clone()); } } diff --git a/nihav-game/src/codecs/vmd.rs b/nihav-game/src/codecs/vmd.rs index ea6c31d..4284716 100644 --- a/nihav-game/src/codecs/vmd.rs +++ b/nihav-game/src/codecs/vmd.rs @@ -142,7 +142,7 @@ fn decode_frame_data(br: &mut ByteReader, dst: &mut [u8], mut dpos: usize, strid } Ok(false) }, - _ => return Err(DecoderError::InvalidData), + _ => Err(DecoderError::InvalidData), } } @@ -202,7 +202,7 @@ impl VMDVideoDecoder { let method = br.read_byte()?; let is_intra; if (method & 0x80) != 0 { - validate!(self.buf.len() > 0); + validate!(!self.buf.is_empty()); lz_unpack(br, &mut self.buf)?; let mut mr = MemoryReader::new_read(&self.buf); let mut buf_br = ByteReader::new(&mut mr); @@ -251,9 +251,7 @@ impl NADecoder for VMDVideoDecoder { if let Some(bbuf) = bufret { buf = bbuf; } else { - let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4)?; buf = bufinfo.get_vbuf().unwrap(); self.hams.add_frame(buf); buf = self.hams.get_output_frame().unwrap(); @@ -324,7 +322,7 @@ impl VMDAudioDecoder { } else { let mut pred: [i32; 2] = [0; 2]; for ch in 0..channels { - pred[ch] = br.read_u16le()? as i32; + pred[ch] = i32::from(br.read_u16le()?); dst[off[ch]] = pred[ch] as i16; off[ch] += 1; } @@ -333,9 +331,9 @@ impl VMDAudioDecoder { for _ in channels..self.blk_align*channels { let b = br.read_byte()? as usize; if (b & 0x80) != 0 { - pred[ch] -= SOL_AUD_STEPS16[b & 0x7F] as i32; + pred[ch] -= i32::from(SOL_AUD_STEPS16[b & 0x7F]); } else { - pred[ch] += SOL_AUD_STEPS16[b & 0x7F] as i32; + pred[ch] += i32::from(SOL_AUD_STEPS16[b & 0x7F]); } //pred[ch] = pred[ch].max(-32768).min(32767); dst[off[ch]] = pred[ch] as i16; diff --git a/nihav-game/src/demuxers/bmv.rs b/nihav-game/src/demuxers/bmv.rs index 6ef023b..afb1731 100644 --- a/nihav-game/src/demuxers/bmv.rs +++ b/nihav-game/src/demuxers/bmv.rs @@ -30,7 +30,7 @@ impl<'a> DemuxCore<'a> for BMVDemuxer<'a> { } fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult { - if self.pkt_buf.len() > 0 { + if !self.pkt_buf.is_empty() { return Ok(self.pkt_buf.pop().unwrap()); } @@ -51,13 +51,12 @@ impl<'a> DemuxCore<'a> for BMVDemuxer<'a> { let (tb_num, tb_den) = str.get_timebase(); let ts = NATimeInfo::new(Some(self.apos), None, None, tb_num, tb_den); let apkt = self.src.read_packet(str, ts, false, asize)?; - self.apos += (nblocks as u64) * 32; + self.apos += u64::from(nblocks) * 32; self.pkt_buf.push(apkt); } else { asize = 0; } - let mut buf: Vec = Vec::with_capacity(size - asize + 1); - buf.resize(size - asize + 1, 0); + let mut buf: Vec = vec![0; size - asize + 1]; buf[0] = ctype; self.src.read_buf(&mut buf[1..])?; @@ -158,7 +157,7 @@ impl<'a> DemuxCore<'a> for BMV3Demuxer<'a> { } fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult { - if self.pkt_buf.len() > 0 { + if !self.pkt_buf.is_empty() { return Ok(self.pkt_buf.pop().unwrap()); } @@ -178,8 +177,7 @@ impl<'a> DemuxCore<'a> for BMV3Demuxer<'a> { asize = self.asize; } validate!(asize <= size); - let mut buf: Vec = Vec::with_capacity(asize + 1); - buf.resize(asize + 1, 0); + let mut buf: Vec = vec![0; asize + 1]; buf[0] = (self.src.tell() & 1) as u8; self.src.read_buf(&mut buf[1..])?; @@ -194,14 +192,13 @@ impl<'a> DemuxCore<'a> for BMV3Demuxer<'a> { asize = 0; } if size == asize { - if self.pkt_buf.len() > 0 { + if !self.pkt_buf.is_empty() { return Ok(self.pkt_buf.pop().unwrap()); } else { continue; } } - let mut buf: Vec = Vec::with_capacity(size - asize + 1); - buf.resize(size - asize + 1, 0); + let mut buf: Vec = vec![0; size - asize + 1]; buf[0] = ctype; self.src.read_buf(&mut buf[1..])?; diff --git a/nihav-game/src/demuxers/gdv.rs b/nihav-game/src/demuxers/gdv.rs index 6fde92b..6f27cc4 100644 --- a/nihav-game/src/demuxers/gdv.rs +++ b/nihav-game/src/demuxers/gdv.rs @@ -80,18 +80,18 @@ impl<'a> DemuxCore<'a> for GremlinVideoDemuxer<'a> { } let vhdr = NAVideoInfo::new(width as usize, height as usize, false, PAL8_FORMAT); let vci = NACodecTypeInfo::Video(vhdr); - let vinfo = NACodecInfo::new("gdv-video", vci, if edata.len() == 0 { None } else { Some(edata) }); - self.v_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, fps as u32)); + let vinfo = NACodecInfo::new("gdv-video", vci, if edata.is_empty() { None } else { Some(edata) }); + self.v_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, u32::from(fps))); } if (aflags & 1) != 0 { let channels = if (aflags & 2) != 0 { 2 } else { 1 }; let packed = if (aflags & 8) != 0 { 1 } else { 0 }; let depth = if (aflags & 4) != 0 { 16 } else { 8 }; - let ahdr = NAAudioInfo::new(rate as u32, channels as u8, if depth == 16 { SND_S16_FORMAT } else { SND_U8_FORMAT }, 2); + let ahdr = NAAudioInfo::new(u32::from(rate), channels as u8, if depth == 16 { SND_S16_FORMAT } else { SND_U8_FORMAT }, 2); let ainfo = NACodecInfo::new(if packed != 0 { "gdv-audio" } else { "pcm" }, NACodecTypeInfo::Audio(ahdr), None); - self.a_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, rate as u32)); + self.a_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, u32::from(rate))); self.asize = (((rate / fps) * channels * (depth / 8)) >> packed) as usize; self.apacked = (aflags & 8) != 0; @@ -139,7 +139,7 @@ pktdta: Vec::new(), self.state = GDVState::AudioRead; let str = strmgr.get_stream(self.a_id.unwrap()).unwrap(); let (tb_num, tb_den) = str.get_timebase(); - let ts = NATimeInfo::new(Some(self.cur_frame as u64), None, None, tb_num, tb_den); + let ts = NATimeInfo::new(Some(u64::from(self.cur_frame)), None, None, tb_num, tb_den); self.src.read_packet(str, ts, true, self.asize) } @@ -152,10 +152,10 @@ pktdta: Vec::new(), let tmp = src.peek_u32le()?; let flags = (tmp & 0xFF) as usize; self.state = GDVState::NewFrame; - self.cur_frame = self.cur_frame + 1; + self.cur_frame += 1; let (tb_num, tb_den) = str.get_timebase(); - let ts = NATimeInfo::new(Some((self.cur_frame - 1) as u64), None, None, tb_num, tb_den); - src.read_packet(str, ts, if (flags & 64) != 0 { true } else { false }, size) + let ts = NATimeInfo::new(Some(u64::from(self.cur_frame - 1)), None, None, tb_num, tb_den); + src.read_packet(str, ts, (flags & 64) != 0, size) } } diff --git a/nihav-game/src/demuxers/mod.rs b/nihav-game/src/demuxers/mod.rs index 884539c..7dca6d2 100644 --- a/nihav-game/src/demuxers/mod.rs +++ b/nihav-game/src/demuxers/mod.rs @@ -12,7 +12,7 @@ mod gdv; #[cfg(feature="demuxer_vmd")] mod vmd; -const GAME_DEMUXERS: &[&'static DemuxerCreator] = &[ +const GAME_DEMUXERS: &[&DemuxerCreator] = &[ #[cfg(feature="demuxer_bmv")] &bmv::BMVDemuxerCreator {}, #[cfg(feature="demuxer_bmv3")] @@ -24,7 +24,7 @@ const GAME_DEMUXERS: &[&'static DemuxerCreator] = &[ ]; pub fn game_register_all_demuxers(rd: &mut RegisteredDemuxers) { - for demuxer in GAME_DEMUXERS.into_iter() { + for demuxer in GAME_DEMUXERS.iter() { rd.add_demuxer(*demuxer); } } diff --git a/nihav-game/src/demuxers/vmd.rs b/nihav-game/src/demuxers/vmd.rs index 80c503a..cc4ac0e 100644 --- a/nihav-game/src/demuxers/vmd.rs +++ b/nihav-game/src/demuxers/vmd.rs @@ -53,7 +53,7 @@ impl<'a> DemuxCore<'a> for VMDDemuxer<'a> { let vinfo = NACodecInfo::new(if !self.is_indeo { "vmd-video" } else { "indeo3" }, vci, Some(edata)); self.vid_id = strmgr.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, 12)).unwrap(); - let srate = read_u16le(&header[804..])? as u32; + let srate = u32::from(read_u16le(&header[804..])?); let block_size; if srate > 0 { let bsize = read_u16le(&header[806..])? as usize; @@ -74,8 +74,8 @@ impl<'a> DemuxCore<'a> for VMDDemuxer<'a> { block_size = 0; } - let adelay = read_u16le(&header[808..])? as u32; - let idx_off = read_u32le(&header[812..])? as u64; + let adelay = u32::from(read_u16le(&header[808..])?); + let idx_off = u64::from(read_u32le(&header[812..])?); src.seek(SeekFrom::Start(idx_off))?; let mut offs: Vec = Vec::with_capacity(nframes); for i in 0..nframes { @@ -122,7 +122,7 @@ impl<'a> DemuxCore<'a> for VMDDemuxer<'a> { if self.fno >= self.frames.len() { return Err(DemuxerError::EOF); } let cur_frame = &self.frames[self.fno]; //println!("fno {} -> type {} size {} @ {:X} ts {}", self.fno, cur_frame.chtype, cur_frame.size, cur_frame.off, cur_frame.ts); - let next_pos = cur_frame.off as u64; + let next_pos = u64::from(cur_frame.off); if self.src.tell() != next_pos { self.src.seek(SeekFrom::Start(next_pos))?; } @@ -143,7 +143,7 @@ impl<'a> DemuxCore<'a> for VMDDemuxer<'a> { let str_id = if is_video { self.vid_id } else { self.aud_id }; let str = strmgr.get_stream(str_id).unwrap(); let (tb_num, tb_den) = str.get_timebase(); - let ts = NATimeInfo::new(Some(cur_frame.ts as u64), None, None, tb_num, tb_den); + let ts = NATimeInfo::new(Some(u64::from(cur_frame.ts)), None, None, tb_num, tb_den); let pkt = NAPacket::new(str, ts, false, buf); Ok(pkt) -- 2.39.5