/// Returns the original saved reference frame or `None` if it is not present.
#[allow(dead_code)]
pub fn get_output_frame(&mut self) -> Option<NAVideoBufferRef<T>> {
- match self.lastframe {
- Some(ref frm) => Some(frm.clone()),
- None => None,
- }
+ self.lastframe.as_ref().cloned()
}
}
/// Returns the original saved reference frame or `None` if it is not present.
#[allow(dead_code)]
pub fn get_ref(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.lastframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.lastframe.as_ref().cloned()
}
}
/// Returns the previous reference frame or `None` if it is not present.
#[allow(dead_code)]
pub fn get_lastref(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.lastframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.lastframe.as_ref().cloned()
}
/// Returns second last reference frame or `None` if it is not present.
#[allow(dead_code)]
pub fn get_nextref(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.nextframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.nextframe.as_ref().cloned()
}
/// Returns the temporally following reference for B-frame or `None` if it is not present.
#[allow(dead_code)]
pub fn get_b_fwdref(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.nextframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.nextframe.as_ref().cloned()
}
/// Returns the temporally preceeding reference for B-frame or `None` if it is not present.
#[allow(dead_code)]
pub fn get_b_bwdref(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.lastframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.lastframe.as_ref().cloned()
}
}
#[allow(clippy::many_single_char_names)]
#[allow(clippy::collapsible_if)]
+#[allow(clippy::collapsible_else_if)]
impl MV {
/// Creates a new motion vector instance.
pub fn new(x: i16, y: i16) -> Self { MV{ x, y } }
}
}
- 'tail_loop: for dentry in decs.iter_mut() {
- if let Some((_, ref mut dec)) = dentry {
+ 'tail_loop: for (_, ref mut dec) in decs.iter_mut().flatten() {
loop {
match dec.get_frame() {
(Ok(frm), id) => {
break;
}
}
- }
}
if let ExpectedTestResult::MD5(ref ref_hash) = test {
md5.finish();
let res = self.io.seek(SeekFrom::Start(4));
let res = self.io.write_u32le((size - 8) as u32);
let res = self.io.seek(SeekFrom::Start(self.data_pos - 4));
- let res = self.io.write_u32le(((size as u64) - self.data_pos) as u32);
+ let res = self.io.write_u32le((size - self.data_pos) as u32);
}
}
}
} else {
eob = br.read_bool()?;
let run = br.read(6)? as usize;
- let lev = br.read_s(8)? as i32;
+ let lev = br.read_s(8)?;
(lev, run)
};
idx += skip;
std::mem::swap(&mut self.buf, &mut data);
let ret = self.decode_scan(&data, buf, &ci[..ns], ss, se);
std::mem::swap(&mut self.buf, &mut data);
- if let Err(err) = ret {
- return Err(err);
- }
+ ret?;
} else { unreachable!(); }
},
JPEGType::Progressive => {
mod pcm;
#[cfg(feature="decoder_sipro")]
#[allow(clippy::collapsible_if)]
+#[allow(clippy::collapsible_else_if)]
#[allow(clippy::identity_op)]
#[allow(clippy::manual_memcpy)]
mod sipro;
#[cfg(feature="decoder_pcm")]
fn get_duration(ainfo: &NAAudioInfo, duration: Option<u64>, data_size: usize) -> u64 {
- if duration == None {
+ if let Some(dur) = duration {
+ dur
+ } else {
let size_bits = (data_size as u64) * 8;
let blk_size = u64::from(ainfo.get_channels()) * u64::from(ainfo.get_format().get_bits());
size_bits / blk_size
- } else {
- duration.unwrap()
}
}
}
}
+#[allow(clippy::neg_cmp_op_on_partial_ord)]
fn read_stsd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult<u64> {
const KNOWN_STSD_SIZE: u64 = 24;
validate!(size >= KNOWN_STSD_SIZE);
match depth & 0x1F {
2 => {
let mut pal = [0; 1024];
- (&mut pal[..4 * 4]).copy_from_slice(&MOV_DEFAULT_PAL_2BIT);
+ pal[..4 * 4].copy_from_slice(&MOV_DEFAULT_PAL_2BIT);
track.pal = Some(Arc::new(pal));
},
4 => {
let mut pal = [0; 1024];
- (&mut pal[..16 * 4]).copy_from_slice(&MOV_DEFAULT_PAL_4BIT);
+ pal[..16 * 4].copy_from_slice(&MOV_DEFAULT_PAL_4BIT);
track.pal = Some(Arc::new(pal));
},
8 => {
for kf_time in self.keyframes.iter() {
let pts = tsearch.map_time(*kf_time - 1, &self.time_to_sample);
let time = NATimeInfo::ts_to_time(pts, 1000, self.tb_num, self.tb_den);
- seek_index.add_entry(self.track_no as u32, SeekEntry { time, pts: u64::from(*kf_time - 1), pos: 0 });
+ seek_index.add_entry(self.track_no, SeekEntry { time, pts: u64::from(*kf_time - 1), pos: 0 });
}
}
fn calculate_chunk_size(&self, nsamp: usize) -> usize {
}
}
#[allow(clippy::collapsible_if)]
+ #[allow(clippy::collapsible_else_if)]
fn seek(&mut self, pts: u64, tpoint: NATimePoint) -> DemuxerResult<u64> {
self.cur_sample = pts as usize;
self.samples_left = 0;
}
validate!(self.width > 0 && self.height > 0);
self.frame_size = 0;
- for chromaton in format.comp_info.iter() {
- if let Some(ref chr) = chromaton {
- self.frame_size += chr.get_data_size(self.width, self.height);
- }
+ for chr in format.comp_info.iter().flatten() {
+ self.frame_size += chr.get_data_size(self.width, self.height);
}
validate!(self.frame_size > 0);
#[allow(clippy::unreadable_literal)]
#[allow(clippy::too_many_arguments)]
#[allow(clippy::excessive_precision)]
+#[allow(clippy::upper_case_acronyms)]
+#[allow(clippy::manual_range_contains)]
+#[allow(clippy::collapsible_else_if)]
mod codecs;
#[cfg(feature="decoders")]
}
/// Frame skipping mode for decoders.
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
pub enum FrameSkipMode {
/// Decode all frames.
+ #[default]
None,
/// Decode all key frames.
KeyframesOnly,
IntraOnly,
}
-impl Default for FrameSkipMode {
- fn default() -> Self {
- FrameSkipMode::None
- }
-}
-
impl FromStr for FrameSkipMode {
type Err = DecoderError;
let mut lut_bits = cb.lut_bits;
let orig_br = self.br;
while esc {
- let lut_idx = (self.peek(lut_bits) as usize) + (idx as usize);
+ let lut_idx = (self.peek(lut_bits) as usize) + idx;
if cb.table[lut_idx] == TABLE_FILL_VALUE { return Err(CodebookError::InvalidCode); }
let bits = cb.table[lut_idx] & 0x7F;
esc = (cb.table[lut_idx] & 0x80) != 0;
self.refill();
return Err(CodebookError::MemoryError);
}
- self.skip(skip_bits as u32).unwrap();
+ self.skip(skip_bits).unwrap();
lut_bits = bits as u8;
}
Ok(cb.syms[idx])
}
///! Deflate compression mode.
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
pub enum DeflateMode {
///! No compression.
NoCompr,
///! Fast compression.
Fast,
///! Still fast but better compression.
+ #[default]
Better,
///! Slow but the best compression.
Best,
}
-impl Default for DeflateMode {
- fn default() -> Self { DeflateMode::Better }
-}
-
pub const DEFLATE_MODE_DESCRIPTION: &str = "Deflate compression level.";
///! Deflate option for no compression.
pub const DEFLATE_MODE_NONE: &str = "none";
//! Various compression formats support.
#[cfg(feature="deflate")]
+#[allow(clippy::manual_range_contains)]
pub mod deflate;
use crate::io::byteio::ByteIOError;
let buf = &mut buf[ipos..];
if ipos + len <= dst_pos {
let (src, dst) = buf.split_at_mut(offset);
- (&mut dst[..len]).copy_from_slice(&src[..len]);
+ dst[..len].copy_from_slice(&src[..len]);
} else {
for i in 0..len {
buf[offset + i] = buf[i];
}
/// Seeking modes.
-#[derive(Clone,Copy,PartialEq)]
+#[derive(Clone,Copy,PartialEq,Default)]
pub enum SeekIndexMode {
/// No seeking index present.
+ #[default]
None,
/// Seeking index is present.
Present,
Automatic,
}
-impl Default for SeekIndexMode {
- fn default() -> Self { SeekIndexMode::None }
-}
-
/// A structure holding seeking information.
#[derive(Clone,Copy,Default)]
pub struct SeekEntry {
}
/// Returns stream reference for provided stream ID.
pub fn get_stream_index(&mut self, id: u32) -> Option<&mut StreamSeekInfo> {
- for stream in self.seek_info.iter_mut() {
- if stream.id == id {
- return Some(stream);
- }
- }
- None
+ self.seek_info.iter_mut().find(|stream| stream.id == id)
}
/// Adds seeking information to the index.
pub fn add_entry(&mut self, id: u32, entry: SeekEntry) {
}
/// Searches for a demuxer that supports requested container format.
pub fn find_demuxer(&self, name: &str) -> Option<&dyn DemuxerCreator> {
- for &dmx in self.dmxs.iter() {
- if dmx.get_name() == name {
- return Some(dmx);
- }
- }
- None
+ self.dmxs.iter().find(|&&dmx| dmx.get_name() == name).copied()
}
/// Provides an iterator over currently registered demuxers.
pub fn iter(&self) -> std::slice::Iter<&dyn DemuxerCreator> {
}
/// Searches for a demuxer that supports requested container format.
pub fn find_demuxer(&self, name: &str) -> Option<&dyn RawDemuxerCreator> {
- for &dmx in self.dmxs.iter() {
- if dmx.get_name() == name {
- return Some(dmx);
- }
- }
- None
+ self.dmxs.iter().find(|&&dmx| dmx.get_name() == name).copied()
}
/// Provides an iterator over currently registered demuxers.
pub fn iter(&self) -> std::slice::Iter<&dyn RawDemuxerCreator> {
let mut map = String::new();
for el in self.ids.iter() {
if !map.is_empty() { map.push(','); }
- map.push_str(&*el.to_string());
+ map.push_str(&el.to_string());
}
write!(f, "{}", map)
}
/// Reports whether the format is not packed.
pub fn is_unpacked(&self) -> bool {
if self.palette { return false; }
- for chr in self.comp_info.iter() {
- if let Some(ref chromaton) = chr {
- if chromaton.is_packed() { return false; }
- }
+ for chromaton in self.comp_info.iter().flatten() {
+ if chromaton.is_packed() { return false; }
}
true
}
/// Returns the maximum component bit depth.
pub fn get_max_depth(&self) -> u8 {
let mut mdepth = 0;
- for chr in self.comp_info.iter() {
- if let Some(ref chromaton) = chr {
- mdepth = mdepth.max(chromaton.depth);
- }
+ for chromaton in self.comp_info.iter().flatten() {
+ mdepth = mdepth.max(chromaton.depth);
}
mdepth
}
/// Returns the total amount of bits needed for components.
pub fn get_total_depth(&self) -> u8 {
let mut depth = 0;
- for chr in self.comp_info.iter() {
- if let Some(ref chromaton) = chr {
- depth += chromaton.depth;
- }
+ for chromaton in self.comp_info.iter().flatten() {
+ depth += chromaton.depth;
}
depth
}
/// Returns the maximum component subsampling.
pub fn get_max_subsampling(&self) -> u8 {
let mut ssamp = 0;
- for chr in self.comp_info.iter() {
- if let Some(ref chromaton) = chr {
- let (ss_v, ss_h) = chromaton.get_subsampling();
- ssamp = ssamp.max(ss_v).max(ss_h);
- }
+ for chromaton in self.comp_info.iter().flatten() {
+ let (ss_v, ss_h) = chromaton.get_subsampling();
+ ssamp = ssamp.max(ss_v).max(ss_h);
}
ssamp
}
let mut start_off = 0;
let mut start_shift = 0;
let mut use_shift = true;
- for comp in self.comp_info.iter() {
- if let Some(comp) = comp {
- start_off = start_off.min(comp.comp_offs);
- start_shift = start_shift.min(comp.shift);
- if comp.comp_offs != 0 { use_shift = false; }
- }
+ for comp in self.comp_info.iter().flatten() {
+ start_off = start_off.min(comp.comp_offs);
+ start_shift = start_shift.min(comp.shift);
+ if comp.comp_offs != 0 { use_shift = false; }
}
for component in 0..(self.components as usize) {
for (comp, cname) in self.comp_info.iter().zip(b"rgba".iter()) {
let mut parse_end = components as usize;
for ch in s.chars().skip(components as usize) {
parse_end += 1;
- if ('0'..='9').contains(&ch) {
+ if ch.is_ascii_digit() {
format = format * 10 + u32::from((ch as u8) - b'0');
if format > 444 { return Err(FormatParseError {}); }
} else {
let depth = if s.len() == parse_end { 8 } else {
let mut val = 0;
for ch in s.chars().skip(parse_end) {
- if ('0'..='9').contains(&ch) {
+ if ch.is_ascii_digit() {
val = val * 10 + ((ch as u8) - b'0');
if val > 16 { return Err(FormatParseError {}); }
} else {
NAVideoInfo { width: w, height: h, flipped: flip, format: fmt, bits }
}
/// Returns picture width.
- pub fn get_width(&self) -> usize { self.width as usize }
+ pub fn get_width(&self) -> usize { self.width }
/// Returns picture height.
- pub fn get_height(&self) -> usize { self.height as usize }
+ pub fn get_height(&self) -> usize { self.height }
/// Returns picture orientation.
pub fn is_flipped(&self) -> bool { self.flipped }
/// Returns picture pixel format.
let mut strides: Vec<usize> = Vec::new();
for i in 0..fmt.get_num_comp() {
- if fmt.get_chromaton(i) == None { return Err(AllocatorError::FormatError); }
+ if fmt.get_chromaton(i).is_none() { return Err(AllocatorError::FormatError); }
}
let align_mod = ((1 << align) as usize) - 1;
- let width = ((vinfo.width as usize) + align_mod) & !align_mod;
- let height = ((vinfo.height as usize) + align_mod) & !align_mod;
+ let width = (vinfo.width + align_mod) & !align_mod;
+ let height = (vinfo.height + align_mod) & !align_mod;
let mut max_depth = 0;
let mut all_packed = true;
let mut all_bytealigned = true;
//todo various-sized palettes?
let stride = vinfo.get_format().get_chromaton(0).unwrap().get_linesize(width);
let pic_sz = stride.checked_mul(height);
- if pic_sz == None { return Err(AllocatorError::TooLargeDimensions); }
+ if pic_sz.is_none() { return Err(AllocatorError::TooLargeDimensions); }
let pal_size = 256 * (fmt.get_elem_size() as usize);
let new_size = pic_sz.unwrap().checked_add(pal_size);
- if new_size == None { return Err(AllocatorError::TooLargeDimensions); }
+ if new_size.is_none() { return Err(AllocatorError::TooLargeDimensions); }
offs.push(0);
offs.push(stride * height);
strides.push(stride);
let ochr = fmt.get_chromaton(i);
if ochr.is_none() { continue; }
let chr = ochr.unwrap();
- offs.push(new_size as usize);
+ offs.push(new_size);
let stride = chr.get_linesize(width);
let cur_h = chr.get_height(height);
let cur_sz = stride.checked_mul(cur_h);
- if cur_sz == None { return Err(AllocatorError::TooLargeDimensions); }
+ if cur_sz.is_none() { return Err(AllocatorError::TooLargeDimensions); }
let new_sz = new_size.checked_add(cur_sz.unwrap());
- if new_sz == None { return Err(AllocatorError::TooLargeDimensions); }
+ if new_sz.is_none() { return Err(AllocatorError::TooLargeDimensions); }
new_size = new_sz.unwrap();
strides.push(stride);
}
} else if all_bytealigned || unfit_elem_size {
let elem_sz = fmt.get_elem_size();
let line_sz = width.checked_mul(elem_sz as usize);
- if line_sz == None { return Err(AllocatorError::TooLargeDimensions); }
+ if line_sz.is_none() { return Err(AllocatorError::TooLargeDimensions); }
let new_sz = line_sz.unwrap().checked_mul(height);
- if new_sz == None { return Err(AllocatorError::TooLargeDimensions); }
+ if new_sz.is_none() { return Err(AllocatorError::TooLargeDimensions); }
new_size = new_sz.unwrap();
let data: Vec<u8> = vec![0; new_size];
strides.push(line_sz.unwrap());
} else {
let elem_sz = fmt.get_elem_size();
let new_sz = width.checked_mul(height);
- if new_sz == None { return Err(AllocatorError::TooLargeDimensions); }
+ if new_sz.is_none() { return Err(AllocatorError::TooLargeDimensions); }
new_size = new_sz.unwrap();
match elem_sz {
2 => {
/// Constructs a new audio buffer for the requested format and length.
#[allow(clippy::collapsible_if)]
+#[allow(clippy::collapsible_else_if)]
pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelMap) -> Result<NABufferType, AllocatorError> {
let mut offs: Vec<usize> = Vec::new();
if ainfo.format.is_planar() || ((ainfo.format.get_bits() % 8) == 0) {
let len = nsamples.checked_mul(ainfo.channels as usize);
- if len == None { return Err(AllocatorError::TooLargeDimensions); }
+ if len.is_none() { return Err(AllocatorError::TooLargeDimensions); }
let length = len.unwrap();
let stride;
let step;
}
} else {
let len = nsamples.checked_mul(ainfo.channels as usize);
- if len == None { return Err(AllocatorError::TooLargeDimensions); }
+ if len.is_none() { return Err(AllocatorError::TooLargeDimensions); }
let length = ainfo.format.get_audio_size(len.unwrap() as u64);
let data: Vec<u8> = vec![0; length];
let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride: 0, step: 0 };
/// Converts time in given scale into timestamp in given base.
#[allow(clippy::collapsible_if)]
+ #[allow(clippy::collapsible_else_if)]
pub fn time_to_ts(time: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 {
let tb_num = u64::from(tb_num);
let tb_den = u64::from(tb_den);
}
/// Time information for specifying durations or seek positions.
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
pub enum NATimePoint {
/// Time in milliseconds.
Milliseconds(u64),
/// Stream timestamp.
PTS(u64),
/// No time information present.
+ #[default]
None,
}
-impl Default for NATimePoint {
- fn default() -> Self {
- NATimePoint::None
- }
-}
-
impl fmt::Display for NATimePoint {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
let mut mval = 0;
let mut base = 0;
for ch in val.chars() {
- if ('0'..='9').contains(&ch) {
+ if ch.is_ascii_digit() {
mval = mval * 10 + u64::from((ch as u8) - b'0');
base += 1;
if base > 3 { break; }
if nbits == 0 { return Ok(0) }
if nbits > 32 { return Err(TooManyBitsRequested) }
if self.bits < nbits {
- if let Err(err) = self.refill() { return Err(err) }
+ self.refill()?;
if self.bits < nbits { return Err(BitstreamEnd) }
}
let res = self.read_cache(nbits);
pub fn read_s(&mut self, nbits: u8) -> BitReaderResult<i32> {
if nbits == 0 || nbits > 32 { return Err(TooManyBitsRequested) }
if self.bits < nbits {
- if let Err(err) = self.refill() { return Err(err) }
+ self.refill()?;
if self.bits < nbits { return Err(BitstreamEnd) }
}
let res = self.read_cache_s(nbits);
#[inline(always)]
pub fn read_bool(&mut self) -> BitReaderResult<bool> {
if self.bits < 1 {
- if let Err(err) = self.refill() { return Err(err) }
+ self.refill()?;
if self.bits < 1 { return Err(BitstreamEnd) }
}
let res = self.read_cache(1);
}
/// Writes `bits` bits of `val` value to the output.
#[allow(clippy::collapsible_if)]
+ #[allow(clippy::collapsible_else_if)]
pub fn write(&mut self, val: u32, bits: u8) {
if bits == 0 {
return;
}
fn tell(&mut self) -> u64 {
- self.file.seek(SeekFrom::Current(0)).unwrap()
+ self.file.stream_position().unwrap()
}
fn seek(&mut self, pos: SeekFrom) -> ByteIOResult<u64> {
/// Destroys the reader and releases the reader resource for a further use.
pub fn finish(self) -> Box<T> { self.file }
fn real_tell(&mut self) -> u64 {
- self.file.seek(SeekFrom::Current(0)).unwrap()
+ self.file.stream_position().unwrap()
}
fn max_read_len(&mut self, len: usize) -> usize {
if let Some(epos) = self.end {
}
fn tell(&mut self) -> u64 {
- self.file.seek(SeekFrom::Current(0)).unwrap() - self.start
+ self.file.stream_position().unwrap() - self.start
}
fn seek(&mut self, pos: SeekFrom) -> ByteIOResult<u64> {
}
fn tell(&mut self) -> u64 {
- self.file.seek(SeekFrom::Current(0)).unwrap()
+ self.file.stream_position().unwrap()
}
fn seek(&mut self, pos: SeekFrom) -> ByteIOResult<u64> {
let cur_offset = bucket.offset;
for (ckey, sec_bucket) in &mut escape_list {
- let key = *ckey as u32;
+ let key = *ckey;
let maxlen = min(sec_bucket.maxlen, MAX_LUT_BITS);
let new_off = resize_table(table, maxlen)?;
fill_lut(table, mode, cur_offset, key, maxlen,
let mut idx = 0;
let mut lut_bits = cb.lut_bits;
while esc {
- let lut_idx = (self.peek(lut_bits) as usize) + (idx as usize);
+ let lut_idx = (self.peek(lut_bits) as usize) + idx;
if cb.table[lut_idx] == TABLE_FILL_VALUE { return Err(CodebookError::InvalidCode); }
let bits = cb.table[lut_idx] & 0x7F;
esc = (cb.table[lut_idx] & 0x80) != 0;
if (skip_bits as isize) > self.left() {
return Err(CodebookError::InvalidCode);
}
- self.skip(skip_bits as u32).unwrap();
+ self.skip(skip_bits).unwrap();
lut_bits = bits as u8;
}
Ok(cb.syms[idx])
//! Core functionality of NihAV intended to be used by both crates implementing format support and users.
#[cfg(feature="decoders")]
+#[allow(clippy::upper_case_acronyms)]
#[allow(clippy::cast_lossless)]
#[allow(clippy::identity_op)]
#[allow(clippy::too_many_arguments)]
pub mod options;
pub mod refs;
pub mod reorder;
+#[allow(clippy::upper_case_acronyms)]
#[allow(clippy::collapsible_if)]
#[allow(clippy::many_single_char_names)]
#[allow(clippy::needless_range_loop)]
}
/// Searches for a muxer that supports requested container format.
pub fn find_muxer(&self, name: &str) -> Option<&dyn MuxerCreator> {
- for &mux in self.muxes.iter() {
- if mux.get_name() == name {
- return Some(mux);
- }
- }
- None
+ self.muxes.iter().find(|&&mux| mux.get_name() == name).copied()
}
/// Provides an iterator over currently registered muxers.
pub fn iter(&self) -> std::slice::Iter<&dyn MuxerCreator> {
}
/// Gets the next frame to be displayed (or `None` if that is not possible).
#[allow(clippy::collapsible_if)]
+ #[allow(clippy::collapsible_else_if)]
pub fn get_frame(&mut self) -> Option<NAFrameRef> {
// check if we have consequent timestamps that we can output
if !self.frames.is_empty() {
}
let end = self.ids.iter().position(|&id| id == kf_id).unwrap();
for ref_id in self.ids[..end].iter() {
- if self.frames.iter().position(|(id, _)| id == ref_id).is_none() {
+ if !self.frames.iter().any(|(id, _)| id == ref_id) {
return None;
}
}
let dst = &mut ddata[doff..];
let copy_size = sstride.min(dstride);
for (dline, sline) in dst.chunks_exact_mut(dstride).take(h).zip(src.chunks_exact(sstride)) {
- (&mut dline[..copy_size]).copy_from_slice(&sline[..copy_size]);
+ dline[..copy_size].copy_from_slice(&sline[..copy_size]);
}
}
}
let dst = &mut ddata[doff..];
let copy_size = sstride.min(dstride);
for (dline, sline) in dst.chunks_exact_mut(dstride).take(h).zip(src.chunks_exact(sstride)) {
- (&mut dline[..copy_size]).copy_from_slice(&sline[..copy_size]);
+ dline[..copy_size].copy_from_slice(&sline[..copy_size]);
}
}
}
for _ in 0..h/2 {
line0.copy_from_slice(&data[doff0..][..stride]);
line1.copy_from_slice(&data[doff1..][..stride]);
- (&mut data[doff1..][..stride]).copy_from_slice(line0);
- (&mut data[doff0..][..stride]).copy_from_slice(line1);
+ data[doff1..][..stride].copy_from_slice(line0);
+ data[doff0..][..stride].copy_from_slice(line1);
doff0 += stride;
doff1 -= stride;
}
pivot = start + end;
cand1 = start;
}
- (&mut arr[start..][..end]).copy_from_slice(bucket.as_slice());
+ arr[start..][..end].copy_from_slice(bucket.as_slice());
start += end;
}
for bucket in buckets.iter() {
//use mediancut::quantise_median_cut;
//use neuquant::NeuQuantQuantiser;
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
/// Palette quantisation algorithms.
pub enum QuantisationMode {
/// Median cut approach proposed by Paul Heckbert.
///
/// This is moderately fast and moderately good.
+ #[default]
MedianCut,
/// Enhanced LBG algorithm proposed by Giuseppe Patane and Marco Russo.
///
NeuQuant(u8),
}
-impl Default for QuantisationMode {
- fn default() -> Self { QuantisationMode::MedianCut }
-}
-
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
/// Algorithms for seaching an appropriate palette entry for a given pixel.
pub enum PaletteSearchMode {
/// Full search (slowest).
Full,
/// Local search (faster but may be not so good).
+ #[default]
Local,
/// k-d tree based one (the fastest but not so accurate).
KDTree,
}
-impl Default for PaletteSearchMode {
- fn default() -> Self { PaletteSearchMode::Local }
-}
-
use crate::scale::palette::elbg::ELBG;
use crate::scale::palette::mediancut::quantise_median_cut;
use crate::scale::palette::neuquant::NeuQuantQuantiser;
};
let esize = ofmt.elem_size as usize;
let coffs = [ofmt.comp_info[0].unwrap().comp_offs as usize, ofmt.comp_info[1].unwrap().comp_offs as usize, ofmt.comp_info[2].unwrap().comp_offs as usize];
- for (dpal, spal) in (&mut dst[paloff..]).chunks_mut(esize).zip(pal.iter()) {
+ for (dpal, spal) in dst[paloff..].chunks_mut(esize).zip(pal.iter()) {
dpal[coffs[0]] = spal[0];
dpal[coffs[1]] = spal[1];
dpal[coffs[2]] = spal[2];
let a = order as f32;
for i in 0..(order * 2) {
let x = frac - ((i as f32) + 1.0 - a);
- let fp = std::f32::consts::PI * (x as f32);
- coeffs[i] = a * fp.sin() * (fp / a).sin() / (norm * (x as f32) * (x as f32));
+ let fp = std::f32::consts::PI * x;
+ coeffs[i] = a * fp.sin() * (fp / a).sin() / (norm * x * x);
}
}
fn create_cache(order: usize, den: usize) -> Vec<Vec<f32>> {
0 | 1 => {
self.imdct_long.imdct_half(coeffs, &mut self.tmp);
overlap_half(dst, &self.tmp, delay, self.win_long);
- (&mut delay[0..COEFFS/2]).copy_from_slice(&self.tmp[COEFFS/2..COEFFS]);
+ delay[0..COEFFS/2].copy_from_slice(&self.tmp[COEFFS/2..COEFFS]);
for i in COEFFS/2..COEFFS {
delay[i] = delay[COEFFS - 1 - i];
}
let idx = if !dir { i } else { bands - 1 - i };
synth_filter(src, tmp, size, step, bands, idx);
}
- (&mut dst[..size]).copy_from_slice(&tmp[..size]);
+ dst[..size].copy_from_slice(&tmp[..size]);
}
fn synth_generic(src: &[f32], dst: &mut [f32], tmpbuf: &mut [f32; COEFFS * 2], is_40khz: bool, size: usize) {
let order = if is_40khz { MERGE_ORDER_40K } else { MERGE_ORDER_44K };
- (&mut dst[..size]).copy_from_slice(&src[..size]);
+ dst[..size].copy_from_slice(&src[..size]);
let mut order_idx = 0;
synth_recursive(dst, tmpbuf, size, order, &mut order_idx, false);
for el in dst.iter_mut().take(COEFFS) { *el *= 0.125; }
if val >= 0 {
qtab[val as usize] * scale
} else {
- -qtab[val.abs() as usize] * scale
+ -qtab[val.unsigned_abs() as usize] * scale
}
}
use nihav_core::io::byteio::*;
use super::truemotion1data::*;
-#[derive(Clone,Copy,PartialEq)]
+#[derive(Clone,Copy,PartialEq,Default)]
enum BlockMode {
FourByFour,
+ #[default]
TwoByTwo,
FourByTwo,
TwoByFour,
}
-impl Default for BlockMode {
- fn default() -> Self {
- BlockMode::TwoByTwo
- }
-}
-
impl FromStr for BlockMode {
type Err = ();
fn from_str(s: &str) -> Result<BlockMode, Self::Err> {
}
}
-#[derive(Clone,Copy,PartialEq)]
+#[derive(Clone,Copy,PartialEq,Default)]
enum OptionMode {
Off,
On,
+ #[default]
Auto,
}
-impl Default for OptionMode {
- fn default() -> Self {
- OptionMode::Auto
- }
-}
-
impl FromStr for OptionMode {
type Err = ();
fn from_str(s: &str) -> Result<OptionMode, Self::Err> {
pair[1] = self.prev_frame[x * 2 + 1 + y * self.width];
hpred[0] = pair[0] - vpred[0];
hpred[1] = pair[1] - vpred[1];
- vpred.copy_from_slice(&pair);
+ vpred.copy_from_slice(pair);
continue;
}
let pval = [vpred[0] + hpred[0], vpred[1] + hpred[1]];
if let Some(ref codes) = self.aux_codes {
for _ in 0..self.y_blocks/4 {
if self.blocks[self.blk_addr[cur_blk] >> 2].btype == VPMBType::InterFourMV {
- let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]];
- let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]];
+ let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.unsigned_abs() as usize]];
+ let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.unsigned_abs() as usize]];
let x_sign = last_mv.x < 0;
let y_sign = last_mv.y < 0;
last2_mv = last_mv;
cur_mv = ZERO_MV;
},
VPMBType::InterMV => {
- let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]];
- let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]];
+ let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.unsigned_abs() as usize]];
+ let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.unsigned_abs() as usize]];
let x_sign = last_mv.x < 0;
let y_sign = last_mv.y < 0;
let x = i16::from(br.read_cb(x_cb)?);
std::mem::swap(&mut last_mv, &mut last2_mv);
},
_ => { // GoldenMV
- let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv_g.x.abs() as usize]];
- let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv_g.y.abs() as usize]];
+ let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv_g.x.unsigned_abs() as usize]];
+ let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv_g.y.unsigned_abs() as usize]];
let x_sign = last_mv_g.x < 0;
let y_sign = last_mv_g.y < 0;
let x = i16::from(br.read_cb(x_cb)?);
let mut pred = 0i32;
for i in 0..4 {
if (pp & (1 << i)) != 0 {
- pred += (preds[i] as i32) * i32::from(VP31_DC_WEIGHTS[pp][i]);
+ pred += preds[i] * i32::from(VP31_DC_WEIGHTS[pp][i]);
}
}
pred /= i32::from(VP31_DC_WEIGHTS[pp][4]);
let mut npred = 0;
for i in 0..4 {
if (pp & (1 << i)) != 0 {
- pred += preds[i] as i32;
+ pred += preds[i];
npred += 1;
if npred == 2 {
return (pred / 2) as i16;
std::mem::swap(&mut self.models, &mut self.amodels);
let ret = self.decode_planes(br, &mut dframe, &mut bc, &ahdr, asrc, true);
std::mem::swap(&mut self.models, &mut self.amodels);
- if let Err(err) = ret {
- return Err(err);
- }
+ ret?;
match (hdr.is_golden, ahdr.is_golden) {
(true, true) => { self.shuf.add_golden_frame(buf.clone()); },
(true, false) => {
let sum = u32::from(prob_xmitted[mode * 2]) + u32::from(prob_xmitted[mode * 2 + 1]);
mdl.probs[9] = 255 - rescale_mb_mode_prob(u32::from(prob_xmitted[mode * 2 + 1]), sum);
- let inter_mv0_weight = (cnt[0] as u32) + (cnt[2] as u32);
- let inter_mv1_weight = (cnt[3] as u32) + (cnt[4] as u32);
- let gold_mv0_weight = (cnt[5] as u32) + (cnt[6] as u32);
- let gold_mv1_weight = (cnt[8] as u32) + (cnt[9] as u32);
- let mix_weight = (cnt[1] as u32) + (cnt[7] as u32);
+ let inter_mv0_weight = cnt[0] + cnt[2];
+ let inter_mv1_weight = cnt[3] + cnt[4];
+ let gold_mv0_weight = cnt[5] + cnt[6];
+ let gold_mv1_weight = cnt[8] + cnt[9];
+ let mix_weight = cnt[1] + cnt[7];
mdl.probs[0] = 1 + rescale_mb_mode_prob(inter_mv0_weight + inter_mv1_weight, total);
mdl.probs[1] = 1 + rescale_mb_mode_prob(inter_mv0_weight, inter_mv0_weight + inter_mv1_weight);
mdl.probs[2] = 1 + rescale_mb_mode_prob(mix_weight, mix_weight + gold_mv0_weight + gold_mv1_weight);
- mdl.probs[3] = 1 + rescale_mb_mode_prob(cnt[0] as u32, inter_mv0_weight);
- mdl.probs[4] = 1 + rescale_mb_mode_prob(cnt[3] as u32, inter_mv1_weight);
+ mdl.probs[3] = 1 + rescale_mb_mode_prob(cnt[0], inter_mv0_weight);
+ mdl.probs[4] = 1 + rescale_mb_mode_prob(cnt[3], inter_mv1_weight);
mdl.probs[5] = 1 + rescale_mb_mode_prob(cnt[1], mix_weight);
mdl.probs[6] = 1 + rescale_mb_mode_prob(gold_mv0_weight, gold_mv0_weight + gold_mv1_weight);
mdl.probs[7] = 1 + rescale_mb_mode_prob(cnt[5], gold_mv0_weight);
hdr.multistream = true;
}
let bytes = br.tell() >> 3;
- std::mem::drop(br);
bc.skip_bytes(bytes);
self.loop_mode = 0;
if hdr.is_intra {
let sum = u32::from(prob_xmitted[mode * 2]) + u32::from(prob_xmitted[mode * 2 + 1]);
mdl.probs[9] = 255 - rescale_mb_mode_prob(u32::from(prob_xmitted[mode * 2 + 1]), sum);
- let inter_mv0_weight = (cnt[0] as u32) + (cnt[2] as u32);
- let inter_mv1_weight = (cnt[3] as u32) + (cnt[4] as u32);
- let gold_mv0_weight = (cnt[5] as u32) + (cnt[6] as u32);
- let gold_mv1_weight = (cnt[8] as u32) + (cnt[9] as u32);
- let mix_weight = (cnt[1] as u32) + (cnt[7] as u32);
+ let inter_mv0_weight = cnt[0] + cnt[2];
+ let inter_mv1_weight = cnt[3] + cnt[4];
+ let gold_mv0_weight = cnt[5] + cnt[6];
+ let gold_mv1_weight = cnt[8] + cnt[9];
+ let mix_weight = cnt[1] + cnt[7];
mdl.probs[0] = 1 + rescale_mb_mode_prob(inter_mv0_weight + inter_mv1_weight, total);
mdl.probs[1] = 1 + rescale_mb_mode_prob(inter_mv0_weight, inter_mv0_weight + inter_mv1_weight);
mdl.probs[2] = 1 + rescale_mb_mode_prob(mix_weight, mix_weight + gold_mv0_weight + gold_mv1_weight);
- mdl.probs[3] = 1 + rescale_mb_mode_prob(cnt[0] as u32, inter_mv0_weight);
- mdl.probs[4] = 1 + rescale_mb_mode_prob(cnt[3] as u32, inter_mv1_weight);
+ mdl.probs[3] = 1 + rescale_mb_mode_prob(cnt[0], inter_mv0_weight);
+ mdl.probs[4] = 1 + rescale_mb_mode_prob(cnt[3], inter_mv1_weight);
mdl.probs[5] = 1 + rescale_mb_mode_prob(cnt[1], mix_weight);
mdl.probs[6] = 1 + rescale_mb_mode_prob(gold_mv0_weight, gold_mv0_weight + gold_mv1_weight);
mdl.probs[7] = 1 + rescale_mb_mode_prob(cnt[5], gold_mv0_weight);
bc.put_bool(diff < 0, 128)?;
bc.write_el(d0, MODE_TREE_DIFF, MODE_TREE_DIFF_PROBS)?;
if d0 == 7 {
- bc.put_bits(diff.abs() as u32, 7)?;
+ bc.put_bits(u32::from(diff.unsigned_abs()), 7)?;
}
tprob[i ^ 1] = (i16::from(tprob[i ^ 1]) + deltas[i ^ 1]) as u8;
}
fn sad(src1: &[u8; 64], src2: &[u8; 64]) -> u32 {
let mut sum = 0;
for (&p1, &p2) in src1.iter().zip(src2.iter()) {
- sum += (i32::from(p1) - i32::from(p2)).abs() as u32;
+ sum += (i32::from(p1) - i32::from(p2)).unsigned_abs();
}
sum
}
let mut sum = 0;
for (blk1, blk2) in mb1.coeffs.iter().zip(mb2.coeffs.iter()) {
for (&c1, &c2) in blk1.iter().zip(blk2.iter()) {
- sum += (i32::from(c1) - i32::from(c2)).abs() as u32;
+ sum += (i32::from(c1) - i32::from(c2)).unsigned_abs();
}
}
sum
}
}
pub fn estimate_mvs(&mut self, ref_frame: NAVideoBufferRef<u8>, mc_buf: NAVideoBufferRef<u8>, golden: bool) {
- let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant as usize]);
+ let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant]);
let inter_mbs = if !golden { &mut self.inter_mbs } else { &mut self.golden_mbs };
}
}
fn estimate_fourmv(&mut self, ref_frame: NAVideoBufferRef<u8>, mc_buf: NAVideoBufferRef<u8>, mb_x: usize, mb_y: usize) -> bool {
- let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant as usize]);
+ let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant]);
if self.fourmv_mbs.is_empty() {
for _ in 0..self.mb_w * self.mb_h {
}
}
pub fn select_inter_blocks_fast(&mut self, ref_frame: NAVideoBufferRef<u8>, gold_frame: Option<NAVideoBufferRef<u8>>, mc_buf: NAVideoBufferRef<u8>, lambda: f32) {
- let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant as usize]);
+ let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant]);
if self.inter_mbs.is_empty() {
for _ in 0..self.mb_w * self.mb_h {
self.pcache.resize(self.mb_w);
}
+ #[allow(clippy::field_reassign_with_default)]
fn read_features(&mut self, bc: &mut BoolCoder) -> DecoderResult<()> {
for (i, feat) in self.dstate.features.iter_mut().enumerate() {
if bc.read_bool() {
}
#[repr(u8)]
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
pub enum PredMode {
+ #[default]
DCPred,
HPred,
VPred,
Inter,
}
-impl Default for PredMode {
- fn default() -> Self { PredMode::DCPred }
-}
-
impl PredMode {
pub fn to_b_mode(self) -> Self {
if self == PredMode::DCPred {
let dst = &mut dst[doff..];
let src = &src[EDGE_PRE + EDGE_PRE * sstride..];
for (out, src) in dst.chunks_mut(dstride).take(size).zip(src.chunks(sstride)) {
- (&mut out[0..size]).copy_from_slice(&src[0..size]);
+ out[..size].copy_from_slice(&src[..size]);
}
} else if my == 0 {
let src = &src[EDGE_PRE * sstride..];
let src = &reffrm.get_data();
let src = &src[srcoff..];
for (out, src) in dst.chunks_mut(dstride).take(size).zip(src.chunks(sstride)) {
- (&mut out[0..size]).copy_from_slice(&src[0..size]);
+ out[..size].copy_from_slice(&src[..size]);
}
return;
}
(&data[off + (start_x as usize) + (start_y as usize) * stride..],
((stride as isize) + xstep) as usize)
} else {
- let add = (size + EDGE_PRE + EDGE_POST) * (xstep.abs() as usize);
+ let add = (size + EDGE_PRE + EDGE_POST) * xstep.unsigned_abs();
let bw = size + EDGE_PRE + EDGE_POST + add;
let bh = (end_y - start_y) as usize;
let bo = if xstep >= 0 { 0 } else { add };
let dstride = dstfrm.stride[plane];
let dst = &mut dstfrm.data[dstfrm.offset[plane]..];
for (src, dst) in src.chunks(sstride).zip(dst.chunks_mut(dstride)).take(ha) {
- (&mut dst[0..wa]).copy_from_slice(&src[0..wa]);
+ dst[..wa].copy_from_slice(&src[..wa]);
}
}
}
}
pub fn apply_ipred_luma(&self, mode: PredMode, ipred: &IPredContext, dst: &mut Residue) {
let mut tmp = [0; 256];
- (&mut tmp).ipred16(16, mode, ipred);
+ tmp.ipred16(16, mode, ipred);
dst.set_luma_from_diff(&self.luma, &tmp);
}
pub fn fill_ipred_luma(&mut self, mode: PredMode, ipred: &IPredContext) {
}
pub fn get_frame_quant(&self, is_intra: bool) -> usize {
if let Some(q) = self.force_q {
- q as usize
+ q
} else {
let expected_size = self.get_target_size(is_intra);
let nits_per_mb = ((expected_size * 8) as f32) / (self.num_mb as f32);
use super::vp78dsp::*;
use super::vp8dsp::*;
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
enum VP8Ref {
+ #[default]
Intra,
Last,
Golden,
AltRef,
}
-impl Default for VP8Ref {
- fn default() -> Self { VP8Ref::Intra }
-}
-
#[derive(Default)]
pub struct VP8Shuffler {
lastframe: Option<NAVideoBufferRef<u8>>,
self.altframe = Some(buf);
}
pub fn get_last(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.lastframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.lastframe.as_ref().cloned()
}
pub fn get_golden(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.goldframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.goldframe.as_ref().cloned()
}
pub fn get_altref(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.altframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.altframe.as_ref().cloned()
}
pub fn has_refs(&self) -> bool {
self.lastframe.is_some()
if (mx == 0) && (my == 0) {
let dst = &mut dst[doff..];
for (out, src) in dst.chunks_mut(dstride).take(size).zip(src.chunks(sstride)) {
- (&mut out[0..size]).copy_from_slice(&src[0..size]);
+ out[..size].copy_from_slice(&src[..size]);
}
} else if my == 0 {
for src in src.chunks(sstride).take(size) {
let src = &reffrm.get_data();
let src = &src[srcoff..];
for (out, src) in dst.chunks_mut(dstride).take(size).zip(src.chunks(sstride)) {
- (&mut out[0..size]).copy_from_slice(&src[0..size]);
+ out[..size].copy_from_slice(&src[..size]);
}
return;
}
palette: false
};
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
#[allow(dead_code)]
pub enum VPMBType {
+ #[default]
Intra,
InterNoMV,
InterMV,
}
}
-impl Default for VPMBType {
- fn default() -> Self { VPMBType::Intra }
-}
-
#[derive(Default)]
pub struct VPShuffler {
lastframe: Option<NAVideoBufferRef<u8>>,
self.goldframe = Some(buf);
}
pub fn get_last(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.lastframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.lastframe.as_ref().cloned()
}
pub fn get_golden(&mut self) -> Option<NAVideoBufferRef<u8>> {
- if let Some(ref frm) = self.goldframe {
- Some(frm.clone())
- } else {
- None
- }
+ self.goldframe.as_ref().cloned()
}
pub fn has_refs(&self) -> bool {
self.lastframe.is_some()
use std::str::FromStr;
-#[derive(Debug,Clone,Copy,PartialEq)]
+#[derive(Debug,Clone,Copy,PartialEq,Default)]
#[allow(dead_code)]
pub enum MVSearchMode {
Full,
SEA,
Diamond,
+ #[default]
Hexagon,
EPZS,
}
-impl Default for MVSearchMode {
- fn default() -> Self { MVSearchMode::Hexagon }
-}
-
pub struct ParseError{}
impl FromStr for MVSearchMode {
extern crate nihav_codec_support;
#[allow(clippy::collapsible_if)]
+#[allow(clippy::collapsible_else_if)]
#[allow(clippy::comparison_chain)]
#[allow(clippy::excessive_precision)]
#[allow(clippy::identity_op)]
+#[allow(clippy::needless_late_init)]
#[allow(clippy::unreadable_literal)]
+#[allow(clippy::upper_case_acronyms)]
#[allow(clippy::verbose_bit_mask)]
+#[allow(clippy::manual_range_contains)]
+#[allow(clippy::wrong_self_convention)]
mod codecs;
mod demuxers;
}
fn has_last_frame(&self) -> bool { self.lastframe.is_some() }
fn get_key_frame(&mut self) -> Option<NAVideoBufferRef<u8>> {
- match self.keyframe {
- Some(ref frm) => Some(frm.clone()),
- None => None,
- }
+ self.keyframe.as_ref().cloned()
}
fn get_last_frame(&mut self) -> Option<NAVideoBufferRef<u8>> {
- match self.lastframe {
- Some(ref frm) => Some(frm.clone()),
- None => None,
- }
+ self.lastframe.as_ref().cloned()
}
}
let top = (bits.read_bits(br, 4)? as usize) << 8;
let offs = top + (br.read_byte()? as usize);
if (subtag != 0) || (offs <= 0xF80) {
- let len = (subtag as usize) + 3;
+ let len = subtag + 3;
self.lz_copy(idx, (offs as isize) - 4096, len)?;
idx += len;
} else {
let abuf = alloc_audio_buffer(self.ainfo, daudio.len(), self.chmap.clone())?;
let mut adata = abuf.get_abuf_f32().unwrap();
let buf = adata.get_data_mut().unwrap();
- (&mut buf[..daudio.len()]).copy_from_slice(daudio.as_slice());
+ buf[..daudio.len()].copy_from_slice(daudio.as_slice());
let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), abuf);
frm.set_duration(Some(CODEC_SAMPLES as u64));
let src = &ref_frm.get_data()[ref_frm.get_offset(0) + (src_x as usize) + (src_y as usize) * sstride..];
let dst = &mut frm.data[ydst + x..];
for (dst, src) in dst.chunks_mut(frm.stride[0]).zip(src.chunks(sstride)).take(16) {
- (&mut dst[..16]).copy_from_slice(&src[..16]);
+ dst[..16].copy_from_slice(&src[..16]);
}
let xoff = (src_x as usize) >> 1;
let yoff = (src_y as usize) >> 1;
let src = &ref_frm.get_data()[ref_frm.get_offset(plane) + xoff + yoff * sstride..];
let dst = &mut frm.data[if plane == 1 { udst } else { vdst } + x / 2..];
for (dst, src) in dst.chunks_mut(frm.stride[plane]).zip(src.chunks(sstride)).take(8) {
- (&mut dst[..8]).copy_from_slice(&src[..8]);
+ dst[..8].copy_from_slice(&src[..8]);
}
}
if has_residue {
const MV_PART: [i8; 16] = [ 0, 4, 8, 12, 16, 20, 24, 28, -32, -4, -8, -12, -16, -20, -24, -28 ];
let idx = br.read_byte()? as usize;
- let x = MV_PART[(idx & 0xF) as usize] as isize;
- let y = MV_PART[(idx >> 4) as usize] as isize;
+ let x = MV_PART[idx & 0xF] as isize;
+ let y = MV_PART[idx >> 4] as isize;
let src_off = (tile_off as isize) + x + y * (self.w as isize);
validate!(src_off >= 0);
validate!((src_off as usize) + self.tile_w + (self.tile_h - 1) * self.w <= self.w * self.h);
self.pic.fpal[i] = self.pic.fpal[i].wrapping_add(self.pic.pdelta[i]);
self.pic.pal[i] = (self.pic.fpal[i] >> 7) as u8;
}
- br.read_skip((size as usize) - 4)?;
+ br.read_skip(size - 4)?;
},
2 => {
validate!(size == 0x904);
let paloff = buf.get_offset(1);
let data = buf.get_data_mut().unwrap();
for (inrow, outrow) in self.framebuf.chunks(self.width).zip(data.chunks_mut(stride)) {
- (&mut outrow[..self.width]).copy_from_slice(inrow);
+ outrow[..self.width].copy_from_slice(inrow);
}
if !self.is_24bit {
- (&mut data[paloff..][..768]).copy_from_slice(&self.pal);
+ data[paloff..][..768].copy_from_slice(&self.pal);
}
videobuf = if !self.is_24bit { NABufferType::Video(buf) } else { NABufferType::VideoPacked(buf) };
} else {
validate!(abits == 8 || abits == 16);
self.bps = (channels as usize) * abits / 8;
let bsize = read_u16le(&buf[32..])? as usize;
- let ahdr = NAAudioInfo::new(arate, channels as u8, if abits == 16 { SND_S16_FORMAT } else { SND_U8_FORMAT }, bsize);
+ let ahdr = NAAudioInfo::new(arate, channels, if abits == 16 { SND_S16_FORMAT } else { SND_U8_FORMAT }, bsize);
let ainfo = NACodecInfo::new("pcm", NACodecTypeInfo::Audio(ahdr), None);
self.a_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, arate, 2));
}
let hdr_size = self.src.read_u32be()?;
validate!(cmp == 0 && size1 == hdr_size);
- let size = (nframes - 1) as usize;
+ let size = nframes - 1;
self.offsets = Vec::with_capacity(size);
self.sizes = Vec::with_capacity(size);
self.samples = Vec::with_capacity(size);
extern crate nihav_codec_support;
#[allow(clippy::collapsible_if)]
+#[allow(clippy::collapsible_else_if)]
#[allow(clippy::excessive_precision)]
#[allow(clippy::needless_range_loop)]
+#[allow(clippy::manual_range_contains)]
#[allow(clippy::unreadable_literal)]
#[allow(clippy::useless_let_if_seq)]
+#[allow(clippy::upper_case_acronyms)]
+#[allow(clippy::needless_late_init)]
mod codecs;
pub use crate::codecs::game_register_all_decoders;
#[allow(clippy::collapsible_if)]
#[allow(clippy::needless_range_loop)]
#[allow(clippy::unreadable_literal)]
+#[allow(clippy::manual_range_contains)]
+#[allow(clippy::upper_case_acronyms)]
mod demuxers;
pub use crate::demuxers::game_register_all_demuxers;
if len < 0 { len = 0; }
if len > 6 { len = 6; }
self.band_bits[band] = len as u8;
- cur_bits += (self.band_width[band] as i32) * (len as i32);
+ cur_bits += (self.band_width[band] as i32) * len;
if len > 0 {
acc += self.band_width[band] as i32;
}
}
if self.ba.band_present[band] {
let band_w = IMC_BANDS[band + 1] - IMC_BANDS[band];
- let bitsum = self.ba.band_bitsum[band] as usize;
+ let bitsum = self.ba.band_bitsum[band];
if (bitsum > 0) && (((band_w * 3) >> 1) > bitsum) {
self.ba.band_skip[band] = true;
}
let channels = self.ainfo.get_channels() as usize;
for chunk in pktbuf.chunks(BLOCK_SIZE * channels) {
for ch in 0..channels {
- let off = abuf.get_offset(ch as usize) + start;
- self.decode_block(chunk, ch as usize, &mut dst[off..off+COEFFS])?;
+ let off = abuf.get_offset(ch) + start;
+ self.decode_block(chunk, ch, &mut dst[off..off+COEFFS])?;
}
if (channels == 2) && ((chunk[1] & 0x20) != 0) {
let off1 = abuf.get_offset(0) + start;
}
x += run;
} else {
- framebuf[base + x + 0] = table[(idx * 2 + 0) as usize];
- framebuf[base + x + 1] = table[(idx * 2 + 1) as usize];
+ framebuf[base + x + 0] = table[idx * 2];
+ framebuf[base + x + 1] = table[idx * 2 + 1];
x += 2;
}
}
if delta == 0 {
continue;
}
- let delta = delta.abs() as u8;
+ let delta = delta.unsigned_abs();
self.add_delta(delta);
}
}
if delta == 0 {
continue;
}
- let delta = delta.abs() as u8;
+ let delta = delta.unsigned_abs();
self.add_delta(delta);
}
}
fn determine_mode(&self, intra: bool, mut mode_hint: u8) -> (u8, [u8; 2]) {
if let Some(qmode) = self.quant {
if intra {
- return (mode_hint, [qmode as u8, qmode as u8]);
+ return (mode_hint, [qmode, qmode]);
} else {
- let qmode = (qmode & 7) as u8;
+ let qmode = qmode & 7;
return (mode_hint, [qmode, qmode]);
}
}
let (prev, cur) = cell4.split_at_mut(pivot);
let prev = &prev[prev.len() - 4..];
let cur = &mut cur[..4];
- let (idx0, idx1) = find_quad(&cb.data, prev, cur);
+ let (idx0, idx1) = find_quad(cb.data, prev, cur);
cur[0] = ((prev[0] as i8) + cb.data[usize::from(idx1) * 2]) as u8;
cur[1] = ((prev[1] as i8) + cb.data[usize::from(idx1) * 2 + 1]) as u8;
let cb = cbs[y];
let esc_val = esc_vals[y];
- let (idx0, idx1) = find_quad(&cb.data, prev, cur);
+ let (idx0, idx1) = find_quad(cb.data, prev, cur);
cur[0] = ((prev[0] as i8) + cb.data[usize::from(idx1) * 2]) as u8;
cur[1] = ((prev[1] as i8) + cb.data[usize::from(idx1) * 2 + 1]) as u8;
}
fn pair_dist(src: &[i8], pair: &[i8]) -> u32 {
- let d0 = (i32::from(src[0]) - i32::from(pair[0])).abs() as u32;
- let d1 = (i32::from(src[1]) - i32::from(pair[1])).abs() as u32;
+ let d0 = (i32::from(src[0]) - i32::from(pair[0])).unsigned_abs();
+ let d1 = (i32::from(src[1]) - i32::from(pair[1])).unsigned_abs();
d0 * d0 + d1 * d1
}
}
let mut iw = Indeo3Writer::new(dbuf);
- self.cframe.plane[planeno].encode_tree(&mut iw, &tree, &mut self.cenc, ref_plane);
+ self.cframe.plane[planeno].encode_tree(&mut iw, tree, &mut self.cenc, ref_plane);
drop(iw);
while (dbuf.len() & 3) != 0 {
dbuf.push(0);
use super::ivibr::*;
fn calc_quant(glob_q: u32, qd: i16) -> usize {
- let qq = (glob_q as i16) + (qd as i16);
+ let qq = (glob_q as i16) + qd;
if qq < 0 {
0
} else if qq > 23 {
unreachable!();
}
- fn decode_single_frame<'a>(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader<'a>) -> DecoderResult<NABufferType> {
+ fn decode_single_frame(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader) -> DecoderResult<NABufferType> {
let pic_hdr = dec.decode_picture_header(br)?;
self.ftype = pic_hdr.ftype;
if pic_hdr.ftype.is_null() {
Ok(buftype)
}
- pub fn decode_frame<'a>(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader<'a>) -> DecoderResult<NABufferType> {
- let res = self.decode_single_frame(dec, br);
- if res.is_err() { return res; }
+ pub fn decode_frame(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader) -> DecoderResult<NABufferType> {
+ let res = self.decode_single_frame(dec, br)?;
if (self.ftype == IVIFrameType::Intra) && (br.left() > 16) {
loop {
if br.left() < 8 { break; }
}
}
if self.bref.is_some() && self.ftype == IVIFrameType::Inter {
- let mut bref: Option<NABufferType> = Some(res.unwrap());
+ let mut bref: Option<NABufferType> = Some(res);
mem::swap(&mut bref, &mut self.bref);
return Ok(bref.unwrap());
}
- if let Ok(NABufferType::None) = res {
+ if let NABufferType::None = res {
if self.bref.is_some() {
let mut bref: Option<NABufferType> = None;
mem::swap(&mut bref, &mut self.bref);
return Ok(bref.unwrap());
}
}
- res
+ Ok(res)
}
pub fn flush(&mut self) {
fn open(&mut self, strmgr: &mut StreamManager, _seek_index: &mut SeekIndex) -> DemuxerResult<()> {
let mut guid = [0; 16];
self.src.read_buf(&mut guid)?;
- let version = match &guid {
- &IVF_GUID_0 => 0,
- &IVF_GUID_1 => 1,
+ let version = match guid {
+ IVF_GUID_0 => 0,
+ IVF_GUID_1 => 1,
_ => return Err(DemuxerError::InvalidData),
};
let flags = self.src.read_u32le()?;
let fcc = self.src.read_tag()?;
self.src.read_skip(20)?;
- let mut vhdr = NAVideoInfo::new(width, height.abs() as usize, height < 0, YUV420_FORMAT);
+ let mut vhdr = NAVideoInfo::new(width, height.unsigned_abs() as usize, height < 0, YUV420_FORMAT);
vhdr.bits = (planes as u8) * (bitcount as u8);
let cname = match &fcc {
b"IV31" | b"IV32" => "indeo3",
impl<'a> NAOptionHandler for IVFDemuxer<'a> {
fn get_supported_options(&self) -> &[NAOptionDefinition] { DEMUXER_OPTS }
+ #[allow(clippy::single_match)]
fn set_options(&mut self, options: &[NAOption]) {
for option in options.iter() {
for opt_def in DEMUXER_OPTS.iter() {
}
}
}
+ #[allow(clippy::single_match)]
fn query_option_value(&self, name: &str) -> Option<NAValue> {
match name {
PASSES => Some(NAValue::Int(i64::from(self.passes))),
extern crate nihav_codec_support;
#[allow(clippy::collapsible_if)]
+#[allow(clippy::collapsible_else_if)]
#[allow(clippy::identity_op)]
#[allow(clippy::needless_range_loop)]
+#[allow(clippy::needless_late_init)]
#[allow(clippy::too_many_arguments)]
#[allow(clippy::useless_let_if_seq)]
#[allow(clippy::verbose_bit_mask)]
+#[allow(clippy::upper_case_acronyms)]
+#[allow(clippy::manual_range_contains)]
mod codecs;
pub use crate::codecs::indeo_register_all_decoders;
} else { new_mode };
}
mb_info.ipred[x + y * 4] = pred_mode.into();
- sstate.get_cur_blk4(x + y * 4).ipred = (pred_mode as u8).into();
+ sstate.get_cur_blk4(x + y * 4).ipred = pred_mode.into();
}
let mut ctx = 0;
if sstate.get_left_mb().cmode != 0 {
mb_info.ipred[blk4 + 1] = pred_mode.into();
mb_info.ipred[blk4 + 4] = pred_mode.into();
mb_info.ipred[blk4 + 5] = pred_mode.into();
- sstate.get_cur_blk4(blk4).ipred = (pred_mode as u8).into();
- sstate.get_cur_blk4(blk4 + 1).ipred = (pred_mode as u8).into();
- sstate.get_cur_blk4(blk4 + 4).ipred = (pred_mode as u8).into();
- sstate.get_cur_blk4(blk4 + 5).ipred = (pred_mode as u8).into();
+ sstate.get_cur_blk4(blk4).ipred = pred_mode.into();
+ sstate.get_cur_blk4(blk4 + 1).ipred = pred_mode.into();
+ sstate.get_cur_blk4(blk4 + 4).ipred = pred_mode.into();
+ sstate.get_cur_blk4(blk4 + 5).ipred = pred_mode.into();
}
let mut ctx = 0;
if sstate.get_left_mb().cmode != 0 {
val += 1;
}
if (val & 1) != 0 {
- ((val >> 1) as i32) + 2
+ (val >> 1) + 2
} else {
- -((val >> 1) as i32) - 1
+ -(val >> 1) - 1
}
}
}
} else { new_mode };
}
mb_info.ipred[x + y * 4] = pred_mode.into();
- sstate.get_cur_blk4(x + y * 4).ipred = (pred_mode as u8).into();
+ sstate.get_cur_blk4(x + y * 4).ipred = pred_mode.into();
}
mb_info.chroma_ipred = br.read_ue_lim(3)? as u8;
},
mb_info.ipred[blk4 + 1] = pred_mode.into();
mb_info.ipred[blk4 + 4] = pred_mode.into();
mb_info.ipred[blk4 + 5] = pred_mode.into();
- sstate.get_cur_blk4(blk4).ipred = (pred_mode as u8).into();
- sstate.get_cur_blk4(blk4 + 1).ipred = (pred_mode as u8).into();
- sstate.get_cur_blk4(blk4 + 4).ipred = (pred_mode as u8).into();
- sstate.get_cur_blk4(blk4 + 5).ipred = (pred_mode as u8).into();
+ sstate.get_cur_blk4(blk4).ipred = pred_mode.into();
+ sstate.get_cur_blk4(blk4 + 1).ipred = pred_mode.into();
+ sstate.get_cur_blk4(blk4 + 4).ipred = pred_mode.into();
+ sstate.get_cur_blk4(blk4 + 5).ipred = pred_mode.into();
}
mb_info.chroma_ipred = br.read_ue_lim(3)? as u8;
},
17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41
];
- let mut mb_idx = slice_hdr.first_mb_in_slice as usize;
+ let mut mb_idx = slice_hdr.first_mb_in_slice;
let mut mb_info = CurrentMBInfo { qp_y: slice_hdr.slice_qp, ..Default::default() };
let skip_type = if slice_hdr.slice_type.is_p() { MBType::PSkip } else { MBType::BSkip };
while br.tell() < full_size && mb_idx < self.num_mbs {
Ok(mb_idx)
}
fn decode_slice_cabac(&mut self, cabac: &mut CABAC, slice_hdr: &SliceHeader, refs: &SliceRefs) -> DecoderResult<usize> {
- let mut mb_idx = slice_hdr.first_mb_in_slice as usize;
+ let mut mb_idx = slice_hdr.first_mb_in_slice;
let mut prev_mb_skipped = false;
let skip_type = if slice_hdr.slice_type.is_p() { MBType::PSkip } else { MBType::BSkip };
let mut last_qp_diff = false;
}
let num_bufs = if !self.sps.is_empty() {
- self.sps[0].num_ref_frames as usize + 1
+ self.sps[0].num_ref_frames + 1
} else {
3
}.max(16 + 1);
self.has_pic = self.decode_slice_cavlc(&mut br, &slice_hdr, full_size)?;
} else {
br.align();
- let start = (br.tell() / 8) as usize;
+ let start = br.tell() / 8;
let csrc = &src[start..];
validate!(csrc.len() >= 2);
let mut cabac = CABAC::new(csrc, slice_hdr.slice_type, slice_hdr.slice_qp, slice_hdr.cabac_init_idc as usize)?;
17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41
];
- let mut mb_idx = slice_hdr.first_mb_in_slice as usize;
+ let mut mb_idx = slice_hdr.first_mb_in_slice;
let mut mb_info = CurrentMBInfo { qp_y: slice_hdr.slice_qp, ..Default::default() };
let skip_type = if slice_hdr.slice_type.is_p() { MBType::PSkip } else { MBType::BSkip };
while br.tell() < full_size && mb_idx < self.num_mbs {
Ok(mb_idx == self.num_mbs)
}
fn decode_slice_cabac(&mut self, cabac: &mut CABAC, slice_hdr: &SliceHeader) -> DecoderResult<bool> {
- let mut mb_idx = slice_hdr.first_mb_in_slice as usize;
+ let mut mb_idx = slice_hdr.first_mb_in_slice;
let mut prev_mb_skipped = false;
let skip_type = if slice_hdr.slice_type.is_p() { MBType::PSkip } else { MBType::BSkip };
let mut last_qp_diff = false;
}
let num_bufs = if !self.sps.is_empty() {
- self.sps[0].num_ref_frames as usize + 1
+ self.sps[0].num_ref_frames + 1
} else {
3
}.max(16 + 1);
dst.push(pic.full_id);
}
}
- for ltpic in self.long_term.iter() {
- if let Some(ref pic) = ltpic {
- if !dst.contains(&pic.full_id) {
- dst.push(pic.full_id);
- }
+ for pic in self.long_term.iter().flatten() {
+ if !dst.contains(&pic.full_id) {
+ dst.push(pic.full_id);
}
}
}
Bi,
}
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
pub enum MBType {
+ #[default]
Intra4x4,
Intra8x8,
Intra16x16(u8, u8, u8),
}
}
-impl Default for MBType {
- fn default() -> Self { MBType::Intra4x4 }
-}
-
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
pub enum SubMBType {
P8x8,
P8x4,
P4x8,
P4x4,
+ #[default]
Direct8x8,
B8x8(BMode),
B8x4(BMode),
}
}
-impl Default for SubMBType {
- fn default() -> Self { SubMBType::Direct8x8 }
-}
-
#[repr(u8)]
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
pub enum CompactMBType {
Intra4x4,
Intra8x8,
B8x8,
BSkip,
+ #[default]
None,
}
}
}
-impl Default for CompactMBType {
- fn default() -> Self { CompactMBType::None }
-}
-
impl From<MBType> for CompactMBType {
fn from(mbtype: MBType) -> Self {
match mbtype {
}
#[repr(u8)]
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
pub enum IntraPredMode {
Vertical,
Horizontal,
HorDown,
VerLeft,
HorUp,
+ #[default]
None,
}
}
}
-impl Default for IntraPredMode {
- fn default() -> Self { IntraPredMode::None }
-}
-
impl From<u8> for IntraPredMode {
fn from(val: u8) -> Self {
match val {
}
#[allow(clippy::collapsible_else_if)]
+#[allow(clippy::manual_range_contains)]
#[allow(clippy::too_many_arguments)]
#[allow(clippy::upper_case_acronyms)]
#[cfg(feature="decoder_h264")]
} else {
return Err(DecoderError::NotImplemented);
};
- self.ainfo = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, 4602);
+ self.ainfo = NAAudioInfo::new(srate, channels, SND_S16P_FORMAT, 4602);
Ok(())
} else {
Err(DecoderError::InvalidData)
_ => return Err(DecoderError::NotImplemented),
};
- self.ainfo = NAAudioInfo::new(self.srate, self.channels as u8, fmt, self.max_blk_size.max(1));
+ self.ainfo = NAAudioInfo::new(self.srate, self.channels, fmt, self.max_blk_size.max(1));
Ok(())
} else {
Err(DecoderError::InvalidData)
const WV_HEADER_SIZE: usize = 32;
impl WVHeader {
+ #[allow(clippy::field_reassign_with_default)]
fn parse(src: &[u8]) -> DecoderResult<Self> {
let mut mr = MemoryReader::new_read(src);
let mut br = ByteReader::new(&mut mr);
self.srate = srate;
let base = if self.blk_samples != 0 { u32::from(self.blk_samples) } else { 1 };
- let ahdr = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, base as usize);
+ let ahdr = NAAudioInfo::new(srate, channels, SND_S16P_FORMAT, base as usize);
let ainfo = NACodecInfo::new("flac", NACodecTypeInfo::Audio(ahdr), Some(streaminfo));
strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, base, srate, 0)).unwrap();
self.srate = srate;
let base = if self.blk_samples != 0 { u32::from(self.blk_samples) } else { 1 };
- let ahdr = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, base as usize);
+ let ahdr = NAAudioInfo::new(srate, channels, SND_S16P_FORMAT, base as usize);
let ainfo = NACodecInfo::new("flac", NACodecTypeInfo::Audio(ahdr), Some(streaminfo));
strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, base, srate, 0)).unwrap();
const WV_HEADER_SIZE: usize = 32;
impl WVHeader {
+ #[allow(clippy::field_reassign_with_default)]
fn parse(src: &[u8]) -> DemuxerResult<Self> {
let mut mr = MemoryReader::new_read(src);
let mut br = ByteReader::new(&mut mr);
2.0f32.powf(0.25 * (f32::from(scale) - 100.0 - 56.0))
}
fn iquant(val: i16) -> f32 {
- let idx = val.abs() as usize;
+ let idx = val.unsigned_abs() as usize;
if idx < CBRT_TAB.len() {
if val < 0 {
-CBRT_TAB[idx]
for i in 0..4 {
let val = AAC_QUADS[cw][i] - 1;
if val < 0 {
- out[i] = -CBRT_TAB[val.abs() as usize] * scale;
+ out[i] = -CBRT_TAB[val.unsigned_abs() as usize] * scale;
} else {
- out[i] = CBRT_TAB[val.abs() as usize] * scale;
+ out[i] = CBRT_TAB[val.unsigned_abs() as usize] * scale;
}
}
}
out[0] = iquant(x) * scale;
out[1] = iquant(y) * scale;
} else {
- out[0] = scale * if x < 0 { -CBRT_TAB[x.abs() as usize] } else { CBRT_TAB[x as usize] };
- out[1] = scale * if y < 0 { -CBRT_TAB[y.abs() as usize] } else { CBRT_TAB[y as usize] };
+ out[0] = scale * if x < 0 { -CBRT_TAB[x.unsigned_abs() as usize] } else { CBRT_TAB[x as usize] };
+ out[1] = scale * if y < 0 { -CBRT_TAB[y.unsigned_abs() as usize] } else { CBRT_TAB[y as usize] };
}
}
Ok(())
4 => { // ID_DSE
let _id = br.read(4)?;
let align = br.read_bool()?;
- let mut count = br.read(8)? as u32;
- if count == 255 { count += br.read(8)? as u32; }
+ let mut count = br.read(8)?;
+ if count == 255 { count += br.read(8)?; }
if align { br.align(); }
br.skip(count * 8)?; // no SBR payload or such
},
let var_bord_1 = br.read(2)? as u8;
let num_rel_0 = br.read(2)? as usize;
let num_rel_1 = br.read(2)? as usize;
- chan.num_env = (num_rel_0 as usize) + (num_rel_1 as usize) + 1;
+ chan.num_env = num_rel_0 + num_rel_1 + 1;
let mut rel_bord_0 = [0u8; NUM_ENVELOPES];
let mut rel_bord_1 = [0u8; NUM_ENVELOPES];
for el in rel_bord_0[..num_rel_0].iter_mut() {
let mut e_o_sum = EPS0;
let mut e_c_sum = EPS0;
for k in start..end {
- e_o_sum += e_orig_mapped[env][k] as f32;
+ e_o_sum += e_orig_mapped[env][k];
e_c_sum += e_curr[env][k];
}
*dst = (e_o_sum / e_c_sum).sqrt() * LIM_GAIN[hdr.limiter_gains as usize];
start = end;
}
for k in kx..km {
- let e_orig = e_orig_mapped[env][k] as f32;
- let q_orig = q_mapped[env][k] as f32;
+ let e_orig = e_orig_mapped[env][k];
+ let q_orig = q_mapped[env][k];
let e_curr = e_curr[env][k];
q_m[k] = (e_orig * q_orig / (1.0 + q_orig)).sqrt();
let mut nsum = EPS0;
let mut dsum = EPS0;
for k in start..end {
- nsum += e_orig_mapped[env][k] as f32;
+ nsum += e_orig_mapped[env][k];
dsum += e_curr[env][k] * g_lim[k] * g_lim[k];
if s_m[k] != 0.0 || (env as i8) == l_a || (env as i8) == la_prev {
dsum += s_m[k] * s_m[k];
ctx.mpeg1 = self.sf_idx < 3;
ctx.sf_idx = self.sf_idx;
ctx.read_mp3_side_data(br, channels)?;
- let hdr_size = (br.tell() / 8) as usize;
+ let hdr_size = br.tell() / 8;
let add_len = src.len() - hdr_size;
if self.bytebuf.len() + add_len > BYTEBUF_SIZE {
self.bytebuf.drain(..self.bytebuf.len() + add_len - BYTEBUF_SIZE);
#[cfg(feature="decoders")]
#[allow(clippy::collapsible_if)]
+#[allow(clippy::collapsible_else_if)]
#[allow(clippy::needless_range_loop)]
+#[allow(clippy::needless_late_init)]
+#[allow(clippy::manual_range_contains)]
+#[allow(clippy::upper_case_acronyms)]
mod codecs;
#[cfg(feature="decoders")]
nw.write(nib)?;
}
}
- drop(nw);
} else {
self.nodes.reserve(self.block_len);
self.nibs.resize(self.channels, Vec::new());
nw.write(self.nibs[ch][i])?;
}
}
- drop(nw);
}
self.samples.drain(..self.block_len * self.channels);
}
#[cfg(feature="encoder_msvideo1")]
+#[allow(clippy::collapsible_else_if)]
pub mod msvideo1enc;
const MS_ENCODERS: &[EncoderInfo] = &[
}
}
self.samples.drain(..len * self.channels);
- drop(bw);
let ts = NATimeInfo::new(None, None, Some(1), 1, self.srate);
Ok(NAPacket::new(self.stream.clone().unwrap(), ts, true, dbuf))
}
self.clr2.swap(0, 1);
}
} else {
- let (clrs, mask, dist) = quant2_16pix(&buf);
+ let (clrs, mask, dist) = quant2_16pix(buf);
self.clr2 = clrs;
self.clr2_flags = mask;
self.clr2_dist = dist;
let dst = cur_frm.get_data_mut().unwrap();
let mut skip_run = 0;
let bpainter = BlockPainter15::new();
- for ((sstrip, rstrip), dstrip) in (&src[soff..]).chunks(sstride * 4).take(h / 4).zip((&rsrc[roff..]).chunks(rstride * 4)).zip((&mut dst[doff..]).chunks_mut(dstride * 4)) {
+ for ((sstrip, rstrip), dstrip) in src[soff..].chunks(sstride * 4).take(h / 4).zip(rsrc[roff..].chunks(rstride * 4)).zip(dst[doff..].chunks_mut(dstride * 4)) {
for x in (0..w).step_by(4) {
let mut buf = [UnpackedPixel::default(); 16];
let mut refbuf = [UnpackedPixel::default(); 16];
let doff = cur_frm.get_offset(0);
let dst = cur_frm.get_data_mut().unwrap();
let bpainter = BlockPainter15::new();
- for (sstrip, dstrip) in (&src[soff..]).chunks(sstride * 4).take(h / 4).zip((&mut dst[doff..]).chunks_mut(dstride * 4)) {
+ for (sstrip, dstrip) in src[soff..].chunks(sstride * 4).take(h / 4).zip(dst[doff..].chunks_mut(dstride * 4)) {
for x in (0..w).step_by(4) {
let mut buf = [UnpackedPixel::default(); 16];
Self::get_block(&sstrip[x..], sstride, &mut buf);
let dst = cur_frm.get_data_mut().unwrap();
let mut skip_run = 0;
let bpainter = BlockPainterPal::new(ls);
- for ((sstrip, rstrip), dstrip) in (&src[soff..]).chunks(sstride * 4).take(h / 4).zip((&rsrc[roff..]).chunks(rstride * 4)).zip((&mut dst[doff..]).chunks_mut(dstride * 4)) {
+ for ((sstrip, rstrip), dstrip) in src[soff..].chunks(sstride * 4).take(h / 4).zip(rsrc[roff..].chunks(rstride * 4)).zip(dst[doff..].chunks_mut(dstride * 4)) {
for x in (0..w).step_by(4) {
let mut buf = [UnpackedPixel::default(); 16];
let mut refbuf = [UnpackedPixel::default(); 16];
let doff = cur_frm.get_offset(0);
let dst = cur_frm.get_data_mut().unwrap();
let bpainter = BlockPainterPal::new(ls);
- for (sstrip, dstrip) in (&src[soff..]).chunks(sstride * 4).take(h / 4).zip((&mut dst[doff..]).chunks_mut(dstride * 4)) {
+ for (sstrip, dstrip) in src[soff..].chunks(sstride * 4).take(h / 4).zip(dst[doff..].chunks_mut(dstride * 4)) {
for x in (0..w).step_by(4) {
let mut buf = [UnpackedPixel::default(); 16];
Self::get_block8(&sstrip[x..], sstride, &mut buf, pal);
for (cur_pal, new_pal) in self.pal.iter_mut().zip(pal.chunks_exact(3)) {
let (cur_clr, luma) = cur_pal.split_at_mut(3);
let new_clr = [u16::from(new_pal[0]), u16::from(new_pal[1]), u16::from(new_pal[2])];
- if cur_clr != &new_clr {
+ if cur_clr != new_clr {
pal_changed = true;
cur_clr.copy_from_slice(&new_clr);
luma[0] = rgb2y(cur_clr[0], cur_clr[1], cur_clr[2]);
extern crate nihav_codec_support;
#[allow(clippy::needless_range_loop)]
+#[allow(clippy::needless_late_init)]
#[allow(clippy::single_match)]
#[allow(clippy::verbose_bit_mask)]
mod codecs;
}
q = q.wrapping_sub(self.grid_3_quant[ch][band - 4]);
}
- self.tone_idx[ch][band][i] = q as i8;
+ self.tone_idx[ch][band][i] = q;
if q > 0 || (self.is_intra && q == 0) {
self.tone_scale[ch][band][i] = TONE_SCALES[0][(q & 0x3F) as usize];
} else {
let mut idx = 0;
let mut lut_bits = cb.lut_bits;
while esc {
- let lut_idx = (self.peek(lut_bits) as usize) + (idx as usize);
+ let lut_idx = (self.peek(lut_bits) as usize) + idx;
if cb.table[lut_idx] == TABLE_FILL_VALUE { return Err(CodebookError::InvalidCode); }
let bits = cb.table[lut_idx] & 0x7F;
esc = (cb.table[lut_idx] & 0x80) != 0;
idx = (cb.table[lut_idx] >> 8) as usize;
let skip_bits = if esc { u32::from(lut_bits) } else { bits };
- self.skip(skip_bits as u32);
+ self.skip(skip_bits);
lut_bits = bits as u8;
}
Ok(cb.syms[idx])
}
fn put_block(dst: &mut [u16], dstride: usize, block: &[u16; 16]) {
for (line, src) in dst.chunks_mut(dstride).take(4).zip(block.chunks(4)) {
- (&mut line[..4]).copy_from_slice(src);
+ line[..4].copy_from_slice(src);
}
}
}
}
fn put_block(dst: &mut [u8], dstride: usize, block: &[u8; 16]) {
for (line, src) in dst.chunks_mut(dstride).take(4).zip(block.chunks(4)) {
- (&mut line[..4]).copy_from_slice(src);
+ line[..4].copy_from_slice(src);
}
}
fn put_blocks(&self, dst: &mut [u8], stride: usize, doff: &mut usize, x: &mut usize, len: usize, block: &[u8; 16]) {
SVQ3_RUNLEVEL_ALT[val as usize]
} else {
let run = (val & 0x7) as usize;
- (run, ((val >> 3) as i16) + RUN_ADD_ALT[(run as usize).min(RUN_ADD_ALT.len() - 1)])
+ (run, ((val >> 3) as i16) + RUN_ADD_ALT[run.min(RUN_ADD_ALT.len() - 1)])
};
idx += run;
validate!(idx < end);
SVQ3_RUNLEVEL[val as usize]
} else {
let run = (val & 0xF) as usize;
- (run, ((val >> 4) as i16) + RUN_ADD[(run as usize).min(RUN_ADD.len() - 1)])
+ (run, ((val >> 4) as i16) + RUN_ADD[run.min(RUN_ADD.len() - 1)])
};
idx += run;
validate!(idx < blk.len());
} else {
MCMode::Pixel
};
- let (bw, bh) = SVQ3_PART_SIZES[mb_type as usize];
+ let (bw, bh) = SVQ3_PART_SIZES[mb_type];
let bw = (bw >> 2) as usize;
let bh = (bh >> 2) as usize;
}
let ret = self.decode_slice(&mut br, &hdr, &mut dframe);
std::mem::swap(&mut sbuf, &mut self.slice_buf);
- if let Err(err) = ret {
- return Err(err);
- }
+ ret?;
slice_prepared = false;
off += slice_len;
}
#[allow(clippy::comparison_chain)]
#[allow(clippy::single_match)]
+#[allow(clippy::field_reassign_with_default)]
+#[allow(clippy::upper_case_acronyms)]
+#[allow(clippy::collapsible_else_if)]
mod codecs;
pub use crate::codecs::qt_register_all_decoders;
Ok(v)
}*/
let exp = br.read(5)? as u8;
- let mant = br.read(23)? as u32;
- let sign = br.read(1)? as u32;
+ let mant = br.read(23)?;
+ let sign = br.read(1)?;
let nexp = exp.wrapping_add(0x7E) as u32;
let nmant = (mant << 1) & ((1 << 23) - 1);
Ok(f32::from_bits((sign << 31) | (nexp << 23) | nmant))
last = col_hi[last as usize].read_sym(br, trees)?;
let lo = self.tree.read_sym(br, trees)?;
let val = Self::cvt_color(lo, last, new_bink);
- for i in 0..len { self.data[self.dec_pos + i] = val as u8; }
+ for i in 0..len { self.data[self.dec_pos + i] = val; }
self.dec_pos += len;
} else {
while self.dec_pos < end {
let mut esc: [u32; 3] = [0; 3];
for i in 0..esc.len() {
- esc[i] = br.read(16)? as u32;
+ esc[i] = br.read(16)?;
}
let nsyms = (((size + 3) >> 2) + 4) as usize;
let mut pred: [u8; 2] = [ pred1, pred0 ];
for ch in 0..2 { dst[ch] = pred[ch]; }
for i in 2..unp_size {
- let diff = br.read_tree8(&trees[i & 1])? as u8;
+ let diff = br.read_tree8(&trees[i & 1])?;
pred[i & 1] = pred[i & 1].wrapping_add(diff);
dst[i] = pred[i & 1];
}
let mut pred = br.read(8)? as u8;
dst[0] = pred;
for i in 1..unp_size {
- let diff = br.read_tree8(&tree)? as u8;
+ let diff = br.read_tree8(&tree)?;
pred = pred.wrapping_add(diff);
dst[i] = pred;
}
Ok(pkt)
}
fn seek(&mut self, time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
- let seek_to_start = match time {
- NATimePoint::Milliseconds(0) => true,
- NATimePoint::PTS(0) => true,
- _ => false,
- };
+ let seek_to_start = matches!(time, NATimePoint::Milliseconds(0) | NATimePoint::PTS(0));
if seek_to_start {
let start = self.start;
self.src.seek(SeekFrom::Start(start))?;
#[cfg(feature="decoders")]
#[allow(clippy::cast_lossless)]
#[allow(clippy::collapsible_if)]
+#[allow(clippy::collapsible_else_if)]
#[allow(clippy::excessive_precision)]
#[allow(clippy::identity_op)]
#[allow(clippy::needless_range_loop)]
+#[allow(clippy::needless_late_init)]
#[allow(clippy::too_many_arguments)]
#[allow(clippy::unreadable_literal)]
#[allow(clippy::useless_let_if_seq)]
+#[allow(clippy::upper_case_acronyms)]
mod codecs;
#[cfg(feature="decoders")]
pub use crate::codecs::rad_register_all_decoders;
for _ in 0..num_vectors {
let idx = tcat[tcat_idx2];
tcat_idx2 += 1;
- self.category[idx] = (self.category[idx] + 1).min((NUM_CATEGORIES - 1) as u8) as u8;
+ self.category[idx] = (self.category[idx] + 1).min((NUM_CATEGORIES - 1) as u8);
}
}
fn decode_channel_data(&mut self, dsp: &mut CookDSP, rnd: &mut RND, codebooks: &Codebooks, src: &[u8], buf: &mut [u8], channel: usize) -> DecoderResult<()> {
let rl_cb = if sstate.is_iframe { &self.tables.aic_rl_cb } else { &self.tables.rl_cb };
let q = if plane_no == 0 { (quant * 2) as i16 } else { (H263_CHROMA_QUANT[quant as usize] * 2) as i16 };
- let q_add = if q == 0 || sstate.is_iframe { 0i16 } else { (((q >> 1) - 1) | 1) as i16 };
+ let q_add = if q == 0 || sstate.is_iframe { 0i16 } else { ((q >> 1) - 1) | 1 };
while idx < 64 {
let code = br.read_cb(rl_cb)?;
let run;
h: 0,
minor_ver: 0,
rpr: RPRInfo { present: false, bits: 0, widths: [0; 8], heights: [0; 8] },
- bdsp: Box::new(RV20BlockDSP::default()),
+ bdsp: Box::<RV20BlockDSP>::default(),
base_ts: 0,
last_ts: 0,
next_ts: 0,
self.rpr.present = false;
} else {
self.rpr.present = true;
- self.rpr.bits = ((rprb >> 1) + 1).min(3) as u8;
+ self.rpr.bits = ((rprb >> 1) + 1).min(3);
let num_dim = ((src.len() - 8) / 2).min(self.rpr.widths.len() - 1);
for i in 0..num_dim {
self.rpr.widths [i] = (src[i * 2 + 8] as usize) * 4;
}
}
pub fn init(&mut self, quant: usize, subset: usize) {
- let mut idx = quant as usize;
+ let mut idx = quant;
if (subset == 2) && (idx < 19) {
idx += 10;
} else if (subset != 0) && (idx < 26) {
}
if self.debug_log.is_set(DEBUG_BIT_PSNR) {
- let psnr = calc_psnr(&vbuf, &rvbuf);
+ let psnr = calc_psnr(vbuf, &rvbuf);
println!(" encoded frame PSNR {} size {}", psnr, dvec.len());
}
for (line1, line2) in data1[pic1.get_offset(comp)..].chunks(pic1.get_stride(comp)).zip(
data2[pic2.get_offset(comp)..].chunks(pic2.get_stride(comp))).take(h) {
for (&pix1, &pix2) in line1[..w].iter().zip(line2.iter()) {
- let diff = (i32::from(pix1) - i32::from(pix2)).abs() as u32;
+ let diff = (i32::from(pix1) - i32::from(pix2)).unsigned_abs();
sum += u64::from(diff * diff);
}
}
use std::str::FromStr;
use super::dsp::{RefMBData, luma_mc, chroma_mc};
-#[derive(Clone,Copy,PartialEq)]
+#[derive(Clone,Copy,PartialEq,Default)]
pub enum MVSearchMode {
Dummy,
Diamond,
+ #[default]
Hexagon,
UMH,
}
}
}
-impl Default for MVSearchMode {
- fn default() -> Self { MVSearchMode::Hexagon }
-}
-
impl std::fmt::Display for MVSearchMode {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
hadamard!(diffs[i], diffs[i + 4], diffs[i + 8], diffs[i + 12],
diffs[i], diffs[i + 4], diffs[i + 8], diffs[i + 12]);
}
- diffs.iter().fold(0u32, |acc, x| acc + (x.abs() as u32))
+ diffs.iter().fold(0u32, |acc, x| acc + (x.unsigned_abs() as u32))
}
fn satd(src0: &[u8], src1: &[u8], stride: usize) -> u32 {
let mut diffs = [0; 16];
hadamard!(diffs[i], diffs[i + 4], diffs[i + 8], diffs[i + 12],
diffs[i], diffs[i + 4], diffs[i + 8], diffs[i + 12]);
}
- diffs.iter().fold(0u32, |acc, x| acc + (x.abs() as u32))
+ diffs.iter().fold(0u32, |acc, x| acc + (x.unsigned_abs() as u32))
}
fn downscale(dst: &mut NAVideoBuffer<u8>, src: &NAVideoBuffer<u8>) {
let dst = NASimpleVideoFrame::from_video_buf(dst).unwrap();
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
];
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
enum CUType {
+ #[default]
Intra,
InterMV,
Skip,
InterNoMV,
}
-impl Default for CUType {
- fn default() -> Self { CUType::Intra }
-}
-
const RV60_CU_TYPES: [CUType; 4] = [ CUType::Intra, CUType::InterMV, CUType::Skip, CUType::InterNoMV ];
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
enum PUType {
+ #[default]
Full,
N2Hor,
N2Ver,
}
}
-impl Default for PUType {
- fn default() -> Self { PUType::Full }
-}
-
#[derive(Clone,Copy,Debug)]
enum IntraMode {
Index(u8),
Plane64,
}
-#[derive(Clone,Copy,PartialEq,Debug)]
+#[derive(Clone,Copy,PartialEq,Debug,Default)]
enum TransformType {
+ #[default]
None,
T4X4,
T8X8,
T16X16,
}
-impl Default for TransformType {
- fn default() -> Self { TransformType::None }
-}
-
#[derive(Clone,Copy,PartialEq,Debug)]
enum MVRef {
None,
if hdr.deblock {
self.dblk.reinit(hdr.awidth, hdr.aheight);
}
- let mut off = hsize + ((br.tell() >> 3) as usize);
+ let mut off = hsize + (br.tell() >> 3);
let mut dframe = NASimpleVideoFrame::from_video_buf(&mut buf).unwrap();
for (cu_y, size) in slices.into_iter().enumerate() {
self.decode_cu_line(&mut dframe, &hdr, &src[off..][..size], cu_y)?;
fn decode_2x2_dc(br: &mut BitReader, cb: &Codebook<u16>, coeffs: &mut [i16], stride: usize, block2: bool, dsc: usize, q_dc: i16, q_ac: i16) -> DecoderResult<()> {
if dsc == 0 { return Ok(()); }
- let lx = RV60_DSC_TO_LX[dsc as usize];
+ let lx = RV60_DSC_TO_LX[dsc];
let l0 = ((lx >> 0) & 0xFF) as i16;
let l1 = ((lx >> 8) & 0xFF) as i16;
let l2 = ((lx >> 16) & 0xFF) as i16;
}
fn decode_2x2(br: &mut BitReader, cb: &Codebook<u16>, coeffs: &mut [i16], stride: usize, block2: bool, dsc: usize, q_ac: i16) -> DecoderResult<()> {
if dsc == 0 { return Ok(()); }
- let lx = RV60_DSC_TO_LX[dsc as usize];
+ let lx = RV60_DSC_TO_LX[dsc];
let l0 = ((lx >> 0) & 0xFF) as i16;
let l1 = ((lx >> 8) & 0xFF) as i16;
let l2 = ((lx >> 16) & 0xFF) as i16;
}
fn read_video_buf(src: &mut ByteReader, stream: NAStreamRef, ts: u32, keyframe: bool, frame_size: usize) -> DemuxerResult<NAPacket> {
- let size = (frame_size as usize) + 9;
+ let size = frame_size + 9;
let mut vec: Vec<u8> = vec![0; size];
//v[0] = 0; // 1 slice
vec[4] = 1;
let soniton = NASoniton::new(samp_size as u8, SONITON_FLAG_SIGNED);
let ahdr = NAAudioInfo::new(sample_rate, channels as u8, soniton, 1);
let nainfo = NACodecInfo::new("ralf", NACodecTypeInfo::Audio(ahdr), extradata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, nainfo, 1, 1000, u64::from(duration)));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no, nainfo, 1, 1000, u64::from(duration)));
if res.is_none() { return Err(MemoryError); }
let astr = RMAudioStream::new(None);
str_data.streams.push(RMStreamType::Audio(astr));
};
let duration = if duration == 0 { ainfo.get_duration(1000) } else { u64::from(duration) };
let nainfo = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), extradata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, nainfo, 1, 1000, duration));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no, nainfo, 1, 1000, duration));
if res.is_none() { return Err(MemoryError); }
let astr = RMAudioStream::new(ainfo.ileave_info);
let vhdr = NAVideoInfo::new(width, height, false, RGB24_FORMAT);
let vinfo = NACodecInfo::new(cname, NACodecTypeInfo::Video(vhdr), extradata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Video, stream_no as u32, vinfo, 1, 1000, u64::from(duration)));
+ let res = strmgr.add_stream(NAStream::new(StreamType::Video, stream_no, vinfo, 1, 1000, u64::from(duration)));
if res.is_none() { return Err(DemuxerError::MemoryError); }
let vstr = RMVideoStream::new();
Ok(())
}
#[allow(unused_variables)]
+ #[allow(clippy::question_mark)]
fn parse_packet_payload(src: &mut ByteReader, rmstream: &mut RMStreamType, stream: NAStreamRef, slice_buf: &mut Vec<u8>, queued_pkts: &mut Vec<NAPacket>, keyframe: bool, ts: u32, payload_size: usize) -> DemuxerResult<NAPacket> {
match rmstream {
RMStreamType::Video(ref mut vstr) => {
let seq_no = src.read_byte()?;
let hdr_skip = (src.tell() - pos) as usize;
- let slice_size = (payload_size - hdr_skip) as usize;
+ let slice_size = payload_size - hdr_skip;
slice_buf.resize(slice_size, 0);
src.read_buf(slice_buf.as_mut_slice())?;
if packet_num == 1 {
let payload_size = len - (hdr_size as usize);
- let stream_id = self.str_data.get_stream_id(str_no as u32, pkt_grp);
+ let stream_id = self.str_data.get_stream_id(str_no, pkt_grp);
let sr = self.str_data.find_stream(stream_id);
if sr.is_none() {
self.src.read_skip(payload_size)?;
validate!(sr.is_some());
let str_no = self.start_str + (sr.unwrap() as u32);
let pkt_grp = ((flags >> 8) & 0xFF) as u16;
- let stream_id = str_data.get_stream_id(str_no as u32, pkt_grp);
+ let stream_id = str_data.get_stream_id(str_no, pkt_grp);
let sr = str_data.find_stream(stream_id);
if sr.is_none() {
src.read_skip(payload_size)?;
#[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::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;
#[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")]
pub use crate::demuxers::realmedia_register_all_demuxers;
fn get_packet(&mut self) -> Option<(Vec<u8>, bool)> {
let mut ret = None;
std::mem::swap(&mut self.pkt, &mut ret);
- if let Some(pkt) = ret {
- Some((pkt, true))
- } else {
- None
- }
+ ret.map(|pkt| (pkt, true))
}
fn flush(&mut self) {}
}
return false;
}
let pos = self.map[self.cur_frame];
- self.buf[pos * self.frame_size..][..self.frame_size].copy_from_slice(&src);
+ self.buf[pos * self.frame_size..][..self.frame_size].copy_from_slice(src);
self.cur_frame += 1;
true
}
return false;
}
let pos = self.map[self.cur_frame];
- self.buf[pos * self.frame_size..][..self.frame_size].copy_from_slice(&src);
+ self.buf[pos * self.frame_size..][..self.frame_size].copy_from_slice(src);
self.cur_frame += 1;
true
}
self.mdpr_pos = bw.tell();
bw.write_chunk(b"MDPR", 0, 0)?;
- bw.write_u16be(self.stream_id as u16)?;
+ bw.write_u16be(self.stream_id)?;
bw.write_u32be(0)?; //max br
bw.write_u32be(0)?; //avg br
bw.write_u32be(0)?; //max ps
}
fn end(&mut self) -> MuxerResult<()> {
if let Some(ref mut sw) = self.sw {
- sw.finish(&mut self.bw)?;
+ sw.finish(self.bw)?;
}
Ok(())
}
fn write_multiple_frame(dst: &mut Vec<u8>, frm: &VideoData) {
dst.push(0xC0); // 0x3 = multiple frame
write_16_or_32(dst, frm.data.len() as u32);
- write_16_or_32(dst, frm.pts as u32);
+ write_16_or_32(dst, frm.pts);
dst.push(frm.seq_no);
dst.extend_from_slice(&frm.data);
}
/// Returns codec description for the provided codec short name if it is found.
pub fn get_codec_description(name: &str) -> Option<&'static CodecDescription> {
- for reg in CODEC_REGISTER {
- if reg.name == name {
- return Some(reg);
- }
- }
- None
+ CODEC_REGISTER.iter().find(|®| reg.name == name)
}
static CODEC_REGISTER: &[CodecDescription] = &[
Self::inverse_quant(&self.prev_lsp, &mut cur_lsp, &self.lsp_index, bad_frame);
Self::interpolate_lsp(&mut self.lpc, &cur_lsp, &self.prev_lsp);
self.prev_lsp.copy_from_slice(&cur_lsp);
- (&mut self.excitation[..MAX_PITCH]).copy_from_slice(&self.prev_excitation);
+ self.excitation[..MAX_PITCH].copy_from_slice(&self.prev_excitation);
if self.erased_frames == 0 {
let mut acb_vector = [0; SUBFRAME_LEN];
self.interp_gain = FIXED_CB_GAIN[(self.subframe[2].amp_index + self.subframe[3].amp_index) >> 1];
}
}
- (&mut self.synth_buf[LPC_ORDER..][..MAX_PITCH]).copy_from_slice(&self.prev_excitation);
+ self.synth_buf[LPC_ORDER..][..MAX_PITCH].copy_from_slice(&self.prev_excitation);
let mut acb_vec = [0; SUBFRAME_LEN];
let mut tmp = [0; SUBFRAME_LEN * 2];
for i in (0..SUBFRAMES).step_by(2) {
let buf = &mut self.synth_buf[LPC_ORDER + SUBFRAME_LEN * i..];
self.subframe[i].gen_acb_excitation(&mut acb_vec, buf, self.is_6300);
- (&mut buf[..SUBFRAME_LEN]).copy_from_slice(&acb_vec);
+ buf[..SUBFRAME_LEN].copy_from_slice(&acb_vec);
self.subframe[i + 1].gen_acb_excitation(&mut acb_vec, &buf[SUBFRAME_LEN..], self.is_6300);
- (&mut buf[SUBFRAME_LEN..][..SUBFRAME_LEN]).copy_from_slice(&acb_vec);
+ buf[SUBFRAME_LEN..][..SUBFRAME_LEN].copy_from_slice(&acb_vec);
let mut max = 0;
for j in 0..SUBFRAME_LEN*2 {
}
}
fn formant_postfilter(&mut self, dst: &mut [i16]) {
- (&mut self.synth_buf[..LPC_ORDER]).copy_from_slice(&self.fir_mem);
+ self.synth_buf[..LPC_ORDER].copy_from_slice(&self.fir_mem);
let mut filter_data = [0; LPC_ORDER + SAMPLES];
- (&mut filter_data[..LPC_ORDER]).copy_from_slice(&self.iir_mem);
+ filter_data[..LPC_ORDER].copy_from_slice(&self.iir_mem);
let mut filter_coef = [[0; LPC_ORDER]; 2];
for i in 0..SUBFRAMES {
self.synth_frame_other();
}
self.prev_ftype = self.cur_ftype;
- (&mut self.synth_buf[..LPC_ORDER]).copy_from_slice(&self.filt_mem);
+ self.synth_buf[..LPC_ORDER].copy_from_slice(&self.filt_mem);
for i in 0..SUBFRAMES {
Self::do_lpc(&mut self.synth_buf, LPC_ORDER + i * SUBFRAME_LEN, &self.lpc[i]);
}
extern crate nihav_core;
extern crate nihav_codec_support;
+#[allow(clippy::upper_case_acronyms)]
+#[allow(clippy::needless_late_init)]
mod codecs;
mod demuxers;