}
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)?;
}
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 {
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;
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,
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)?;
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)
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);
];
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());
}
}
}
Ok(false)
},
- _ => return Err(DecoderError::InvalidData),
+ _ => Err(DecoderError::InvalidData),
}
}
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);
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();
} 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;
}
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;
}
fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<NAPacket> {
- if self.pkt_buf.len() > 0 {
+ if !self.pkt_buf.is_empty() {
return Ok(self.pkt_buf.pop().unwrap());
}
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<u8> = Vec::with_capacity(size - asize + 1);
- buf.resize(size - asize + 1, 0);
+ let mut buf: Vec<u8> = vec![0; size - asize + 1];
buf[0] = ctype;
self.src.read_buf(&mut buf[1..])?;
}
fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<NAPacket> {
- if self.pkt_buf.len() > 0 {
+ if !self.pkt_buf.is_empty() {
return Ok(self.pkt_buf.pop().unwrap());
}
asize = self.asize;
}
validate!(asize <= size);
- let mut buf: Vec<u8> = Vec::with_capacity(asize + 1);
- buf.resize(asize + 1, 0);
+ let mut buf: Vec<u8> = vec![0; asize + 1];
buf[0] = (self.src.tell() & 1) as u8;
self.src.read_buf(&mut buf[1..])?;
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<u8> = Vec::with_capacity(size - asize + 1);
- buf.resize(size - asize + 1, 0);
+ let mut buf: Vec<u8> = vec![0; size - asize + 1];
buf[0] = ctype;
self.src.read_buf(&mut buf[1..])?;
}
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;
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)
}
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)
}
}
#[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")]
];
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);
}
}
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;
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<u32> = Vec::with_capacity(nframes);
for i in 0..nframes {
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))?;
}
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)