/// shuffler.add_frame(frame.clone()); // tells frame manager to use the frame as the next reference
/// ```
#[allow(dead_code)]
+#[derive(Default)]
pub struct HAMShuffler<T: Copy> {
lastframe: Option<NAVideoBufferRef<T>>,
}
}
}
-impl<T: Copy> Default for HAMShuffler<T> {
- fn default() -> Self { Self { lastframe: None } }
-}
-
/// Frame manager for codecs with intra and inter frames.
///
/// This frame manager simplifies frame management for the case when codec decodes new frame using previous frame as source of some data.
/// shuffler.add_frame(frame.clone()); // tells frame manager to use the frame as the next reference
/// ```
#[allow(dead_code)]
+#[derive(Default)]
pub struct IPShuffler {
lastframe: Option<NAVideoBufferRef<u8>>,
}
}
}
-impl Default for IPShuffler {
- fn default() -> Self { Self { lastframe: None } }
-}
-
/// Frame manager for codecs with I-, P- and B-frames.
///
/// This frame manager simplifies frame management for the case when codec uses I/P/B frame scheme.
/// }
/// ```
#[allow(dead_code)]
+#[derive(Default)]
pub struct IPBShuffler {
lastframe: Option<NAVideoBufferRef<u8>>,
nextframe: Option<NAVideoBufferRef<u8>>,
}
}
-impl Default for IPBShuffler {
- fn default() -> Self { Self { lastframe: None, nextframe: None } }
-}
-
/// Motion vector data type.
///
/// # Examples
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)),
+ ..Default::default()
+ })
},
NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Video(vinfo) => {
if dc {
generate_cb(&DC_LENS[idx], &DC_SYMS)
} else {
- generate_cb(&AC_LENS[idx], &AC_SYMS[idx])
+ generate_cb(&AC_LENS[idx], AC_SYMS[idx])
}
}
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 0, SND_S16P_FORMAT, 0));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 0, SND_S16P_FORMAT, 0)),
+ ..Default::default()
+ })
},
NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Audio(_) => {
chmap
}
fn is_3_x(self) -> bool {
- match self {
+ matches!(self,
ACMode::Mode3_0 |
ACMode::Mode3_1 |
- ACMode::Mode3_2 => true,
- _ => false,
- }
+ ACMode::Mode3_2)
}
fn is_surround(self) -> bool {
- match self {
+ matches!(self,
ACMode::Mode2_1 |
ACMode::Mode3_1 |
ACMode::Mode2_2 |
- ACMode::Mode3_2 => true,
- _ => false,
- }
+ ACMode::Mode3_2)
}
}
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)),
+ ..Default::default()
+ })
},
NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Video(vinfo) => {
if ret.is_err() { break; }
let (csz, end) = ret.unwrap();
if end {
- let _res = parse_idx1(&mut self.src, strmgr, seek_idx, csz, self.movi_pos, &mut self.key_offs);
+ let _res = parse_idx1(self.src, strmgr, seek_idx, csz, self.movi_pos, &mut self.key_offs);
break;
}
rest_size -= csz;
start = 0;
last_strm_no = stream_no;
}
- let ret = parse_odml_ix(&mut self.src, strmgr, seek_idx, stream_no, size, start);
+ let ret = parse_odml_ix(self.src, strmgr, seek_idx, stream_no, size, start);
if let Ok(new_start) = ret {
start = new_start;
} else {
for _ in 0..depth { print!(" "); }
let tag = [(ctype >> 24) as u8, (ctype >> 16) as u8, (ctype >> 8) as u8, ctype as u8];
let mut printable = true;
- for &ch in tag.iter() {
- if ch < 0x20 || ch > 0x7F {
+ for ch in tag.iter() {
+ if !(0x20..=0x7F).contains(ch) {
printable = false;
break;
}
validate!(self.depth < 32);
let list_end = self.src.tell() + size;
while self.src.tell() < list_end {
- let ret = read_chunk_header(&mut self.src);
+ let ret = read_chunk_header(self.src);
if ret.is_err() { break; }
let (ctype, size) = ret.unwrap();
if self.print_chunks {
fn read_ctab(dmx: &mut MOVDemuxer, _strmgr: &mut StreamManager, size: u64) -> DemuxerResult<u64> {
let mut pal = [0; 1024];
- let size = read_palette(&mut dmx.src, size, &mut pal)?;
+ let size = read_palette(dmx.src, size, &mut pal)?;
dmx.pal = Some(Arc::new(pal));
Ok(size)
}
fn read_trak(dmx: &mut MOVDemuxer, strmgr: &mut StreamManager, size: u64) -> DemuxerResult<u64> {
let mut track = Track::new(dmx.cur_track as u32, dmx.tb_den);
track.print_chunks = dmx.print_chunks;
- track.read_trak(&mut dmx.src, size)?;
+ track.read_trak(dmx.src, size)?;
validate!(track.tkhd_found && track.stsd_found);
validate!(strmgr.get_stream_by_id(track.track_id).is_none());
dmx.cur_track += 1;
}
if let Some(track) = track {
track.moof_off = dmx.moof_off;
- track.read_traf(&mut dmx.src, size)?;
+ track.read_traf(dmx.src, size)?;
Ok(size)
} else {
Ok(0)
},
};
track.tb_den = sample_rate;
- track.raw_audio = match &fcc {
+ track.raw_audio = matches!(&fcc,
b"NONE" | b"raw " | b"twos" | b"sowt" |
b"in24" | b"in32" | b"fl32" | b"fl64" |
b"ima4" | b"ms\x00\x02" | b"ms\x00\x21" |
b"alaw" | b"ulaw" |
- b"MAC3" | b"MAC6" => true,
- _ => false,
- };
+ b"MAC3" | b"MAC6");
let ahdr = NAAudioInfo::new(sample_rate, nchannels as u8, soniton, block_align);
let edata = parse_audio_edata(br, start_pos, size)?;
codec_info = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), edata);
let first = track.cur_sample == 0;
if let Some((pts, offset, size)) = track.get_next_chunk() {
self.cur_track = trk_no + 1;
- return process_packet(&mut self.src, strmgr, track, pts, offset, size, first);
+ return process_packet(self.src, strmgr, track, pts, offset, size, first);
}
}
}
self.cur_track += 1;
let first = track.cur_sample == 0;
if let Some((pts, offset, size)) = track.get_next_chunk() {
- return process_packet(&mut self.src, strmgr, track, pts, offset, size, first);
+ return process_packet(self.src, strmgr, track, pts, offset, size, first);
}
}
Err(DemuxerError::EOF)
fn read_root(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<()> {
self.depth = 0;
while self.src.left() != 0 {
- let ret = read_chunk_header(&mut self.src);
+ let ret = read_chunk_header(self.src);
if ret.is_err() { break; }
let (ctype, size) = ret.unwrap();
if self.print_chunks {
}
let handler = ROOT_CHUNK_HANDLERS.iter().find(|x| x.ctype == ctype);
let read_size;
- if let Some(ref handler) = handler {
+ if let Some(handler) = handler {
read_size = (handler.parse)(self, strmgr, size)?;
} else {
println!("skipping unknown chunk {:08X} size {}", ctype, size);
let mut magic = [0u8; 10];
self.src.read_buf(&mut magic)?;
validate!(&magic == b"YUV4MPEG2 ");
- while let Ok((last, tok)) = read_token(&mut self.src) {
+ while let Ok((last, tok)) = read_token(self.src) {
let (id, val) = tok.split_at(1);
validate!(id.len() == 1);
match id.bytes().next().unwrap() {
},
_ => unreachable!(),
};
- patch_size(&mut self.bw, strf_pos)?;
- patch_size(&mut self.bw, strl_pos)?;
+ patch_size(self.bw, strf_pos)?;
+ patch_size(self.bw, strl_pos)?;
}
- patch_size(&mut self.bw, hdrl_pos)?;
+ patch_size(self.bw, hdrl_pos)?;
self.data_pos = self.bw.tell() + 8;
self.bw.write_buf(b"LIST\0\0\0\0movi")?;
key: pkt.keyframe,
pos: self.bw.tell() as u32,
len: chunk_len });
- write_chunk_hdr(&mut self.bw, str.get_media_type(), str_num as u32)?;
+ write_chunk_hdr(self.bw, str.get_media_type(), str_num as u32)?;
self.bw.write_u32le(chunk_len)?;
self.bw.write_buf(pkt.get_buffer().as_slice())?;
if (self.bw.tell() & 1) != 0 {
Ok(())
}
fn end(&mut self) -> MuxerResult<()> {
- patch_size(&mut self.bw, self.data_pos)?;
+ patch_size(self.bw, self.data_pos)?;
if !self.index.is_empty() {
self.bw.write_buf(b"idx1")?;
self.bw.write_u32le((self.index.len() * 16) as u32)?;
for item in self.index.iter() {
- write_chunk_hdr(&mut self.bw, item.stype, item.stream)?;
+ write_chunk_hdr(self.bw, item.stype, item.stream)?;
self.bw.write_u32le(if item.key { 0x10 } else { 0 })?;
self.bw.write_u32le(item.pos)?;
self.bw.write_u32le(item.len)?;
}
}
- patch_size(&mut self.bw, 8)?;
+ patch_size(self.bw, 8)?;
let mut max_frames = 0;
let mut max_size = 0;
for stri in self.stream_info.iter() {
Ok(())
}
fn end(&mut self) -> MuxerResult<()> {
- patch_size(&mut self.bw, self.data_pos)?;
- patch_size(&mut self.bw, 8)?;
+ patch_size(self.bw, self.data_pos)?;
+ patch_size(self.bw, 8)?;
// todo patch avg_bytes_per_second if calculated
// todo write fact value if calculated
Ok(())
}
///! Reports whether decoder has finished decoding the input.
pub fn is_finished(&self) -> bool {
- match self.state {
- InflateState::End => true,
- _ => false,
- }
+ matches!(self.state, InflateState::End)
}
///! Reports the current amount of bytes output into the destination buffer after the last run.
pub fn get_current_output_size(&self) -> usize { self.output_idx }
let (lit_lengths, dist_lengths) = self.all_lengths.split_at(self.hlit);
let mut lit_codes = [ShortCodebookDesc { code: 0, bits: 0 }; NUM_LITERALS];
- lengths_to_codes(&lit_lengths, &mut lit_codes)?;
+ lengths_to_codes(lit_lengths, &mut lit_codes)?;
let mut cr = ShortCodebookDescReader::new(lit_codes.to_vec());
let ret = Codebook::new(&mut cr, CodebookMode::LSB);
if ret.is_err() { return Err(DecompressError::InvalidHeader); }
impl NAChannelType {
/// Reports whether this is some center channel.
pub fn is_center(self) -> bool {
- match self {
- NAChannelType::C => true, NAChannelType::Ch => true,
- NAChannelType::Cl => true, NAChannelType::Ov => true,
- NAChannelType::LFE => true, NAChannelType::LFE2 => true,
- NAChannelType::Cs => true, NAChannelType::Chs => true,
- _ => false,
- }
+ matches!(self,
+ NAChannelType::C | NAChannelType::Ch |
+ NAChannelType::Cl | NAChannelType::Ov |
+ NAChannelType::LFE | NAChannelType::LFE2 |
+ NAChannelType::Cs | NAChannelType::Chs)
}
/// Reports whether this is some left channel.
pub fn is_left(self) -> bool {
- match self {
- NAChannelType::L => true, NAChannelType::Ls => true,
- NAChannelType::Lss => true, NAChannelType::Lc => true,
- NAChannelType::Lh => true, NAChannelType::Lw => true,
- NAChannelType::Lhs => true, NAChannelType::Ll => true,
- NAChannelType::Lt => true, NAChannelType::Lo => true,
- _ => false,
- }
+ matches!(self,
+ NAChannelType::L | NAChannelType::Ls |
+ NAChannelType::Lss | NAChannelType::Lc |
+ NAChannelType::Lh | NAChannelType::Lw |
+ NAChannelType::Lhs | NAChannelType::Ll |
+ NAChannelType::Lt | NAChannelType::Lo)
}
/// Reports whether this is some right channel.
pub fn is_right(self) -> bool {
- match self {
- NAChannelType::R => true, NAChannelType::Rs => true,
- NAChannelType::Rss => true, NAChannelType::Rc => true,
- NAChannelType::Rh => true, NAChannelType::Rw => true,
- NAChannelType::Rhs => true, NAChannelType::Rl => true,
- NAChannelType::Rt => true, NAChannelType::Ro => true,
- _ => false,
- }
+ matches!(self,
+ NAChannelType::R | NAChannelType::Rs |
+ NAChannelType::Rss | NAChannelType::Rc |
+ NAChannelType::Rh | NAChannelType::Rw |
+ NAChannelType::Rhs | NAChannelType::Rl |
+ NAChannelType::Rt | NAChannelType::Ro)
}
}
}
/// Reports whether the current colour model is RGB.
pub fn is_rgb(self) -> bool {
- match self {
- ColorModel::RGB(_) => true,
- _ => false,
- }
+ matches!(self, ColorModel::RGB(_))
}
/// Reports whether the current colour model is YUV.
pub fn is_yuv(self) -> bool {
- match self {
- ColorModel::YUV(_) => true,
- _ => false,
- }
+ matches!(self, ColorModel::YUV(_))
}
/// Returns short name for the current colour mode.
pub fn get_short_name(self) -> &'static str {
let mut parse_end = components as usize;
for ch in s.chars().skip(components as usize) {
parse_end += 1;
- if ch >= '0' && ch <= '9' {
+ if ('0'..='9').contains(&ch) {
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 ch >= '0' && ch <= '9' {
+ if ('0'..='9').contains(&ch) {
val = val * 10 + ((ch as u8) - b'0');
if val > 16 { return Err(FormatParseError {}); }
} else {
}
/// Reports whether the current stream is video stream.
pub fn is_video(&self) -> bool {
- match *self {
- NACodecTypeInfo::Video(_) => true,
- _ => false,
- }
+ matches!(*self, NACodecTypeInfo::Video(_))
}
/// Reports whether the current stream is audio stream.
pub fn is_audio(&self) -> bool {
- match *self {
- NACodecTypeInfo::Audio(_) => true,
- _ => false,
- }
+ matches!(*self, NACodecTypeInfo::Audio(_))
}
}
}
max_depth = max(max_depth, chr.get_depth());
}
- let unfit_elem_size = match fmt.get_elem_size() {
- 2 | 4 => false,
- _ => true,
- };
+ let unfit_elem_size = !matches!(fmt.get_elem_size(), 2 | 4);
//todo semi-packed like NV12
if fmt.is_paletted() {
impl NACodecInfo {
/// Constructs a new instance of `NACodecInfo`.
pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self {
- let extradata = match edata {
- None => None,
- Some(vec) => Some(Arc::new(vec)),
- };
- NACodecInfo { name, properties: p, extradata }
+ NACodecInfo { name, properties: p, extradata: edata.map(Arc::new) }
}
/// Constructs a new reference-counted instance of `NACodecInfo`.
pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option<Arc<Vec<u8>>>) -> Self {
let mut mval = 0;
let mut base = 0;
for ch in val.chars() {
- if ch >= '0' && ch <= '9' {
+ if ('0'..='9').contains(&ch) {
mval = mval * 10 + u64::from((ch as u8) - b'0');
base += 1;
if base > 3 { break; }
pub const TABLE_FILL_VALUE: u32 = 0x7F;
const MAX_LUT_BITS: u8 = 10;
-fn fill_lut_msb(table: &mut Vec<u32>, off: usize,
+fn fill_lut_msb(table: &mut [u32], off: usize,
code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult<()> {
if !esc {
let fill_len = lut_bits - bits;
Ok(())
}
-fn fill_lut_lsb(table: &mut Vec<u32>, off: usize,
+fn fill_lut_lsb(table: &mut [u32], off: usize,
code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult<()> {
if !esc {
let fill_len = lut_bits - bits;
Ok(())
}
-fn fill_lut(table: &mut Vec<u32>, mode: CodebookMode,
+fn fill_lut(table: &mut [u32], mode: CodebookMode,
off: usize, code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult<bool> {
match mode {
CodebookMode::MSB => fill_lut_msb(table, off, code, bits, lut_bits, symidx, esc)?,
}
for bucket in escape_list.values() {
- build_esc_lut(&mut table, mode, &bucket)?;
+ build_esc_lut(&mut table, mode, bucket)?;
}
for i in 0..cb.len() {
Ok(())
},
NAValue::String(ref cur_str) => {
- if let NAOptionDefinitionType::String(Some(ref strings)) = self.opt_type {
+ if let NAOptionDefinitionType::String(Some(strings)) = self.opt_type {
for str in strings.iter() {
if cur_str == str {
return Ok(());
NAOptionDefinitionType::None => write!(f, "{}: {}", self.name, self.description),
NAOptionDefinitionType::Bool => write!(f, "[no]{}: {}", self.name, self.description),
NAOptionDefinitionType::String(ref str_list) => {
- if let Some(ref opts) = str_list {
+ if let Some(opts) = str_list {
write!(f, "{} {}: {}", self.name, opts.join("|"), self.description)
} else {
write!(f, "{} <string>: {}", self.name, self.description)
fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, options: &[(String, String)]) -> ScaleResult<Option<Stage>> {
let mut debug = false;
for (name, value) in options.iter() {
- if name == "debug" && (value == "" || value == "true") {
+ if name == "debug" && (value.is_empty() || value == "true") {
debug = true;
break;
}
let needs_unpack = !ifmt.fmt.is_unpacked();
let needs_pack = !ofmt.fmt.is_unpacked();
let needs_convert = inname != outname;
- let scale_before_cvt = is_better_fmt(&ifmt, &ofmt) && needs_convert
+ let scale_before_cvt = is_better_fmt(ifmt, ofmt) && needs_convert
&& (ofmt.fmt.get_max_subsampling() == 0);
let needs_palettise = ofmt.fmt.palette;
//todo stages for model and gamma conversion
println!("[adding unpack]");
}
let new_stage = if !cur_fmt.fmt.is_paletted() {
- Stage::new("unpack", &cur_fmt, &ofmt, options)?
+ Stage::new("unpack", &cur_fmt, ofmt, options)?
} else {
- Stage::new("depal", &cur_fmt, &ofmt, options)?
+ Stage::new("depal", &cur_fmt, ofmt, options)?
};
cur_fmt = new_stage.fmt_out;
add_stage!(stages, new_stage);
if debug {
println!("[adding scale]");
}
- let new_stage = Stage::new("scale", &cur_fmt, &ofmt, options)?;
+ let new_stage = Stage::new("scale", &cur_fmt, ofmt, options)?;
cur_fmt = new_stage.fmt_out;
add_stage!(stages, new_stage);
}
if debug {
println!("[{}]", cvtname);
}
- let new_stage = Stage::new(&cvtname, &cur_fmt, &ofmt, options)?;
+ let new_stage = Stage::new(&cvtname, &cur_fmt, ofmt, options)?;
//todo if fails try converting via RGB or YUV
cur_fmt = new_stage.fmt_out;
add_stage!(stages, new_stage);
if debug {
println!("[adding scale]");
}
- let new_stage = Stage::new("scale", &cur_fmt, &ofmt, options)?;
+ let new_stage = Stage::new("scale", &cur_fmt, ofmt, options)?;
cur_fmt = new_stage.fmt_out;
add_stage!(stages, new_stage);
}
if debug {
println!("[adding pack]");
}
- let new_stage = Stage::new("pack", &cur_fmt, &ofmt, options)?;
+ let new_stage = Stage::new("pack", &cur_fmt, ofmt, options)?;
//cur_fmt = new_stage.fmt_out;
add_stage!(stages, new_stage);
}
if debug {
println!("[adding palettise]");
}
- let new_stage = Stage::new("palette", &cur_fmt, &ofmt, options)?;
+ let new_stage = Stage::new("palette", &cur_fmt, ofmt, options)?;
//cur_fmt = new_stage.fmt_out;
add_stage!(stages, new_stage);
}
impl NAScale {
/// Constructs a new `NAScale` instance.
pub fn new(fmt_in: ScaleInfo, fmt_out: ScaleInfo) -> ScaleResult<Self> {
- let pipeline;
let just_convert = (fmt_in.width == fmt_out.width) && (fmt_in.height == fmt_out.height);
- if fmt_in != fmt_out {
- pipeline = build_pipeline(&fmt_in, &fmt_out, just_convert, &[])?;
- } else {
- pipeline = None;
- }
+ let pipeline = if fmt_in != fmt_out {
+ build_pipeline(&fmt_in, &fmt_out, just_convert, &[])?
+ } else {
+ None
+ };
Ok(Self { fmt_in, fmt_out, just_convert, pipeline })
}
/// Constructs a new `NAScale` instance taking into account provided options.
pub fn new_with_options(fmt_in: ScaleInfo, fmt_out: ScaleInfo, options: &[(String, String)]) -> ScaleResult<Self> {
- let pipeline;
let just_convert = (fmt_in.width == fmt_out.width) && (fmt_in.height == fmt_out.height);
- if fmt_in != fmt_out {
- pipeline = build_pipeline(&fmt_in, &fmt_out, just_convert, options)?;
- } else {
- pipeline = None;
- }
+ let pipeline = if fmt_in != fmt_out {
+ build_pipeline(&fmt_in, &fmt_out, just_convert, options)?
+ } else {
+ None
+ };
Ok(Self { fmt_in, fmt_out, just_convert, pipeline })
}
/// Checks whether requested conversion operation is needed at all.
fn new(src: &[u8]) -> Self {
Self { r: src[0], g: src[1], b: src[2] }
}
- fn to_rgb(&self) -> [u8; 3] {
+ fn to_rgb(self) -> [u8; 3] {
[self.r, self.g, self.b]
}
fn dist(&self, pix: Pixel) -> u32 {
impl ChannelOp {
fn is_remix(&self) -> bool {
- match *self {
- ChannelOp::Remix(_) => true,
- ChannelOp::DupMono(_) => true,
- _ => false,
- }
+ matches! (*self, ChannelOp::Remix(_) | ChannelOp::DupMono(_))
}
}
-fn apply_channel_op<T:Copy>(ch_op: &ChannelOp, src: &[T], dst: &mut Vec<T>) {
+fn apply_channel_op<T:Copy>(ch_op: &ChannelOp, src: &[T], dst: &mut [T]) {
match *ch_op {
ChannelOp::Passthrough => {
dst.copy_from_slice(src);
};
}
-fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut Vec<i32>) {
+fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut [i32]) {
if let ChannelOp::Remix(ref remix_mat) = ch_op {
let sch = src.len();
for (out, coeffs) in dst.iter_mut().zip(remix_mat.chunks(sch)) {
}
}
-fn remix_f32(ch_op: &ChannelOp, src: &[f32], dst: &mut Vec<f32>) {
+fn remix_f32(ch_op: &ChannelOp, src: &[f32], dst: &mut [f32]) {
if let ChannelOp::Remix(ref remix_mat) = ch_op {
let sch = src.len();
for (out, coeffs) in dst.iter_mut().zip(remix_mat.chunks(sch)) {
trait SampleReader {
- fn get_samples_i32(&self, pos: usize, dst: &mut Vec<i32>);
- fn get_samples_f32(&self, pos: usize, dst: &mut Vec<f32>);
+ fn get_samples_i32(&self, pos: usize, dst: &mut [i32]);
+ fn get_samples_f32(&self, pos: usize, dst: &mut [f32]);
}
struct GenericSampleReader<'a, T:Copy> {
}
impl<'a, T:Copy+IntoFmt<i32>+IntoFmt<f32>> SampleReader for GenericSampleReader<'a, T> {
- fn get_samples_i32(&self, pos: usize, dst: &mut Vec<i32>) {
+ fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) {
let mut off = pos;
for el in dst.iter_mut() {
*el = self.data[off].cvt_into();
off += self.stride;
}
}
- fn get_samples_f32(&self, pos: usize, dst: &mut Vec<f32>) {
+ fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) {
let mut off = pos;
for el in dst.iter_mut() {
*el = self.data[off].cvt_into();
}
impl<'a> SampleReader for S8SampleReader<'a> {
- fn get_samples_i32(&self, pos: usize, dst: &mut Vec<i32>) {
+ fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) {
let mut off = pos;
for el in dst.iter_mut() {
*el = (self.data[off] ^ 0x80).cvt_into();
off += self.stride;
}
}
- fn get_samples_f32(&self, pos: usize, dst: &mut Vec<f32>) {
+ fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) {
let mut off = pos;
for el in dst.iter_mut() {
*el = (self.data[off] ^ 0x80).cvt_into();
let bpp = (fmt.bits >> 3) as usize;
Self { data, fmt, bpp }
}
- fn get_samples<T:Copy>(&self, pos: usize, dst: &mut Vec<T>) where u8: IntoFmt<T>, i16: IntoFmt<T>, i32: IntoFmt<T>, f32: IntoFmt<T> {
+ fn get_samples<T:Copy>(&self, pos: usize, dst: &mut [T]) where u8: IntoFmt<T>, i16: IntoFmt<T>, i32: IntoFmt<T>, f32: IntoFmt<T> {
let mut offset = pos * self.bpp * dst.len();
for el in dst.iter_mut() {
}
impl SampleReader for PackedSampleReader<'_> {
- fn get_samples_i32(&self, pos: usize, dst: &mut Vec<i32>) {
+ fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) {
self.get_samples(pos, dst);
}
- fn get_samples_f32(&self, pos: usize, dst: &mut Vec<f32>) {
+ fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) {
self.get_samples(pos, dst);
}
}
first = false;
} else {
scale += i16::from(br.read_cb(&self.codebooks.scale_cb)?);
- validate!((scale >= 0) && (scale < 128));
+ validate!((0..128).contains(&scale));
}
self.scales[cur_band] = scale as u8;
cur_band += 1;
}
}
+#[derive(Default)]
struct FrameBuf {
last16: Option<NAVideoBufferRef<u16>>,
last24: Option<NAVideoBufferRef<u8>>,
}
}
-impl Default for FrameBuf {
- fn default() -> Self {
- Self { last16: None, last24: None }
- }
-}
-
#[derive(Default)]
struct TM1Decoder {
info: NACodecInfoRef,
self.blk_w = compr_info.block_w;
self.blk_h = compr_info.block_h;
- let mut mask = MaskState::new(is_intra && !is_sprite, &mask_bits, mask_row_size);
- let mut index = IndexState::new(&index_bytes);
+ let mut mask = MaskState::new(is_intra && !is_sprite, mask_bits, mask_row_size);
+ let mut index = IndexState::new(index_bytes);
let bufinfo;
if !is_24bit {
if let Some(mut buf) = self.lastframe.get16() {
self.fstate.last_idx = [24; 4];
for mb_x in 0..self.mb_w {
self.fstate.mb_x = mb_x;
- self.decode_mb(dframe, bc, &mut cr, br, &hdr, alpha)?;
+ self.decode_mb(dframe, bc, &mut cr, br, hdr, alpha)?;
self.dc_pred.next_mb();
}
self.dc_pred.update_row();
}
fn motion_est_mb(src_mb: &ResidueMB, cur_blk: &mut [[u8; 64]; 6], mb: &mut InterMB, mv_search: &mut Box<dyn MVSearch+Send>, mv_est: &mut MVEstimator, mb_x: usize, mb_y: usize) {
src_mb.fill(cur_blk);
- let (best_mv, _best_dist) = mv_search.search_mb(mv_est, &cur_blk, mb_x, mb_y);
+ let (best_mv, _best_dist) = mv_search.search_mb(mv_est, cur_blk, mb_x, mb_y);
mb.mv[3] = best_mv;
for i in 0..4 {
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, self.flipped, YUV420_FORMAT));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, self.flipped, YUV420_FORMAT)),
+ ..Default::default()
+ })
},
NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Video(vinfo) => {
let refframe = (if use_last { self.shuf.get_last() } else { self.shuf.get_golden() }).unwrap();
let single_mv = self.mb_info[mb_x + mb_y * self.mb_w].mb_type != VPMBType::InterFourMV;
let mut iidx = mb_x * 4 + mb_y * 4 * self.mv_stride;
- let mut mc_buf = self.mc_buf.get_data_mut().unwrap();
+ let mc_buf = self.mc_buf.get_data_mut().unwrap();
let dst = &mut dframe.data[0..];
let ystride = dframe.stride[0];
if pitch_smode == 0 {
if single_mv {
mc_block16x16(dst, yoff, ystride, mb_x * 16, mb_y * 16,
- self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, &mut mc_buf);
+ self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, mc_buf);
} else {
for y in 0..4 {
for x in 0..4 {
mc_block4x4(dst, yoff + x * 4, ystride, mb_x * 16 + x * 4, mb_y * 16 + y * 4,
- self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, &mut mc_buf);
+ self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, mc_buf);
}
yoff += 4 * ystride;
iidx += self.mv_stride;
if single_mv {
mc_block_special(dst, yoff, ystride, mb_x * 16, mb_y * 16,
self.mvs[iidx].x * 2, self.mvs[iidx].y * 2,
- refframe.clone(), 0, &mut mc_buf, 16, pitch_smode);
+ refframe.clone(), 0, mc_buf, 16, pitch_smode);
} else {
for y in 0..4 {
for x in 0..4 {
mc_block_special(dst, yoff + x * 4, ystride,
mb_x * 16 + x * 4, mb_y * 16 + y * 4,
self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2,
- refframe.clone(), 0, &mut mc_buf, 4, pitch_smode);
+ refframe.clone(), 0, mc_buf, 4, pitch_smode);
}
yoff += 4 * ystride;
iidx += self.mv_stride;
let chroma_mv = self.mvs[iidx];
if pitch_smode == 0 {
- mc_block8x8(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf);
- mc_block8x8(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, &mut mc_buf);
+ mc_block8x8(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf);
+ mc_block8x8(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, mc_buf);
} else {
mc_block_special(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y,
- refframe.clone(), 1, &mut mc_buf, 8, pitch_smode);
+ refframe.clone(), 1, mc_buf, 8, pitch_smode);
mc_block_special(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y,
- refframe, 2, &mut mc_buf, 8, pitch_smode);
+ refframe, 2, mc_buf, 8, pitch_smode);
}
} else {
for y in 0..2 {
if pitch_smode == 0 {
mc_block4x4(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
- chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf);
+ chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf);
mc_block4x4(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
- chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf);
+ chroma_mv.x, chroma_mv.y, refframe.clone(), 2, mc_buf);
} else {
mc_block_special(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
- chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf,
+ chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf,
4, pitch_smode);
mc_block_special(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
- chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf,
+ chroma_mv.x, chroma_mv.y, refframe.clone(), 2, mc_buf,
4, pitch_smode);
}
}
let mut new_gf = supp.pool_u8.get_copy(&gf).unwrap();
let dframe = NASimpleVideoFrame::from_video_buf(&mut new_gf).unwrap();
let mut mb_idx = 0;
- let mut mc_buf = self.mc_buf.get_data_mut().unwrap();
+ let mc_buf = self.mc_buf.get_data_mut().unwrap();
for mb_y in 0..self.mb_h {
for mb_x in 0..self.mb_w {
if self.mb_info[mb_idx].upd_gf {
- mc_block16x16(dframe.data, dframe.offset[0] + mb_x * 16 + mb_y * 16 * dframe.stride[0], dframe.stride[0], mb_x * 16, mb_y * 16, 0, 0, buf.clone(), 0, &mut mc_buf);
- mc_block8x8(dframe.data, dframe.offset[1] + mb_x * 8 + mb_y * 8 * dframe.stride[1], dframe.stride[1], mb_x * 8, mb_y * 8, 0, 0, buf.clone(), 1, &mut mc_buf);
- mc_block8x8(dframe.data, dframe.offset[2] + mb_x * 8 + mb_y * 8 * dframe.stride[2], dframe.stride[2], mb_x * 8, mb_y * 8, 0, 0, buf.clone(), 2, &mut mc_buf);
+ mc_block16x16(dframe.data, dframe.offset[0] + mb_x * 16 + mb_y * 16 * dframe.stride[0], dframe.stride[0], mb_x * 16, mb_y * 16, 0, 0, buf.clone(), 0, mc_buf);
+ mc_block8x8(dframe.data, dframe.offset[1] + mb_x * 8 + mb_y * 8 * dframe.stride[1], dframe.stride[1], mb_x * 8, mb_y * 8, 0, 0, buf.clone(), 1, mc_buf);
+ mc_block8x8(dframe.data, dframe.offset[2] + mb_x * 8 + mb_y * 8 * dframe.stride[2], dframe.stride[2], mb_x * 8, mb_y * 8, 0, 0, buf.clone(), 2, mc_buf);
}
mb_idx += 1;
}
pub struct IPred4x4 {}
impl IPred4x4 {
pub fn ipred_dc(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
- let dc;
let mut dcsum = 0;
for el in ipred.left.iter().take(4) {
dcsum += u16::from(*el);
for el in ipred.top.iter().take(4) {
dcsum += u16::from(*el);
}
- dc = ((dcsum + (1 << 2)) >> 3) as u8;
+ let dc = ((dcsum + (1 << 2)) >> 3) as u8;
for _ in 0..4 {
let out = &mut dst[off..][..4];
for el in out.iter_mut() {
impl MBType {
pub fn is_intra(&self) -> bool {
- match *self {
- MBType::Intra(_, _) |
- MBType::Intra4x4(_, _, _) => true,
- _ => false,
- }
+ matches!(*self, MBType::Intra(_, _) | MBType::Intra4x4(_, _, _))
}
pub fn get_last(&self) -> bool {
match *self {
if y_best_dist > SMALL_DIST {
res.reset();
- let dist4 = try_i4x4_pred(sblk.luma_blocks(), &mut i4_modes, res, &mut newblk.luma, &imctx, y_best_dist);
+ let dist4 = try_i4x4_pred(sblk.luma_blocks(), &mut i4_modes, res, &mut newblk.luma, imctx, y_best_dist);
use_i4 = dist4 < y_best_dist;
y_best_dist = y_best_dist.min(dist4);
}
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, YUV420_FORMAT));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, YUV420_FORMAT)),
+ ..Default::default() })
},
NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Video(vinfo) => {
}.unwrap();
let single_mv = self.mb_info[mb_x + mb_y * self.mb_w].mb_type != VPMBType::InterFourMV;
let mut iidx = mb_x * 4 + mb_y * 4 * self.mv_stride;
- let mut mc_buf = self.mc_buf.get_data_mut().unwrap();
+ let mc_buf = self.mc_buf.get_data_mut().unwrap();
let dst = &mut dframe.data[0..];
let ystride = dframe.stride[0];
if single_mv {
if self.dstate.version == 0 {
mc_block16x16(dst, yoff, ystride, mb_x * 16, mb_y * 16,
- self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, &mut mc_buf);
+ self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, mc_buf);
} else {
mc_block16x16_bilin(dst, yoff, ystride, mb_x * 16, mb_y * 16,
- self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, &mut mc_buf);
+ self.mvs[iidx].x * 2, self.mvs[iidx].y * 2, refframe.clone(), 0, mc_buf);
}
} else {
for y in 0..4 {
for x in 0..4 {
if self.dstate.version == 0 {
mc_block4x4(dst, yoff + x * 4, ystride, mb_x * 16 + x * 4, mb_y * 16 + y * 4,
- self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, &mut mc_buf);
+ self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, mc_buf);
} else {
mc_block4x4_bilin(dst, yoff + x * 4, ystride, mb_x * 16 + x * 4, mb_y * 16 + y * 4,
- self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, &mut mc_buf);
+ self.mvs[iidx + x].x * 2, self.mvs[iidx + x].y * 2, refframe.clone(), 0, mc_buf);
}
}
yoff += 4 * ystride;
let mut chroma_mv = self.mvs[iidx];
if self.dstate.version == 0 {
- mc_block8x8(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf);
- mc_block8x8(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, &mut mc_buf);
+ mc_block8x8(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf);
+ mc_block8x8(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, mc_buf);
} else {
if self.dstate.version == 3 {
chroma_mv.x &= !7;
chroma_mv.y &= !7;
}
- mc_block8x8_bilin(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf);
- mc_block8x8_bilin(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, &mut mc_buf);
+ mc_block8x8_bilin(dst, uoff, ustride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf);
+ mc_block8x8_bilin(dst, voff, vstride, mb_x * 8, mb_y * 8, chroma_mv.x, chroma_mv.y, refframe, 2, mc_buf);
}
} else {
for y in 0..2 {
if self.dstate.version == 0 {
mc_block4x4(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
- chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf);
+ chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf);
mc_block4x4(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
- chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf);
+ chroma_mv.x, chroma_mv.y, refframe.clone(), 2, mc_buf);
} else {
mc_block4x4_bilin(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
- chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf);
+ chroma_mv.x, chroma_mv.y, refframe.clone(), 1, mc_buf);
mc_block4x4_bilin(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
- chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf);
+ chroma_mv.x, chroma_mv.y, refframe.clone(), 2, mc_buf);
}
}
uoff += ustride * 4;
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, BLOCK_LEN));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, BLOCK_LEN)),
+ ..Default::default() })
},
NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Audio(ainfo) => {
let dst = adata.get_data_mut().unwrap();
for (src, dst) in src.chunks_exact(PACKED_BLK_LEN).zip(dst.chunks_mut(BLOCK_LEN)) {
- let mut br = BitReader::new(&src, BitReaderMode::LE);
+ let mut br = BitReader::new(src, BitReaderMode::LE);
self.decode_block(&mut br, dst)?;
}
*el = 0;
zero_run -= 1;
} else {
- let val = br.read_cb(&cb)? as u8;
+ let val = br.read_cb(cb)? as u8;
if val == 0 {
zero_run = if br.read_bool()? {
br.read(6)? as usize + 8
VMDAudioMode::DPCM => {
let mut adata = abuf.get_abuf_i16().unwrap();
let off1 = adata.get_offset(1);
- let mut dst = adata.get_data_mut().unwrap();
- self.decode_16bit(&mut dst, off1, &mut br, nblocks, mask)?;
+ let dst = adata.get_data_mut().unwrap();
+ self.decode_16bit(dst, off1, &mut br, nblocks, mask)?;
},
VMDAudioMode::U8 => {
let mut adata = abuf.get_abuf_u8().unwrap();
f0[i] = (pfilt[i] + f1 [i]) >> 1;
f2[i] = (f1 [i] + cfilt[i]) >> 1;
}
- apply_lpc(&mut cur_buf[ 0..][..32], &prev_buf[128..], &mut self.lpc_hist, &f0);
+ apply_lpc(&mut cur_buf[ 0..][..32], &prev_buf[128..], &mut self.lpc_hist, &f0);
apply_lpc(&mut cur_buf[32..][..32], &prev_buf[128 + 32..], &mut self.lpc_hist, &f1);
apply_lpc(&mut cur_buf[64..][..32], &prev_buf[128 + 64..], &mut self.lpc_hist, &f2);
- apply_lpc(&mut cur_buf[96..][..32], &prev_buf[128 + 96..], &mut self.lpc_hist, &cfilt);
+ apply_lpc(&mut cur_buf[96..][..32], &prev_buf[128 + 96..], &mut self.lpc_hist, cfilt);
Ok(())
}
fn decode_intra(&mut self, br: &mut ByteReader, val: u16) -> DecoderResult<()> {
arate = self.src.read_u32le()?;
validate!(arate > 0);
} else {
- parse_iact(&mut self.src, data_start, &mut arate, &mut abits, &mut chans, true)?;
+ parse_iact(self.src, data_start, &mut arate, &mut abits, &mut chans, true)?;
}
if chans == 2 {
for (samp, pts) in self.samples.iter_mut().zip(self.pts.iter_mut()) {
self.read_skip_flags(br)?;
- let mut ch_data = &mut self.ch_data[ch];
+ let ch_data = &mut self.ch_data[ch];
for band in 0..BANDS {
ch_data.adj_floor[band] = ch_data.new_floor[band];
let band_w = IMC_BANDS[band + 1] - IMC_BANDS[band];
}
if bits_freed < 0 { return Err(DecoderError::Bug); }
- self.ba.adjust_bit_allocation(&mut ch_data, bits_freed);
+ self.ba.adjust_bit_allocation(ch_data, bits_freed);
Ok(())
}
txtype = TxType::Transform8(TxParams8x8::new(qintra, qinter, scan));
} else if scan_idx < 10 {
validate!(!tr.is_8x8());
- validate!((qmat_idx >= 15) && (qmat_idx < 22));
+ validate!((15..22).contains(&qmat_idx));
let scan = INDEO4_SCANS_4X4[scan_idx - 5];
let qidx = INDEO4_Q4X4_IDX[qmat_idx - 15];
let qintra = INDEO4_Q4_INTRA[qidx];
if pic_hdr.ftype.is_intra() {
mb.mtype = MBType::Intra;
} else if band.inherit_mv {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
mb.mtype = tileref.mb[mb_idx].mtype;
} else {
return Err(DecoderError::MissingReference);
mb.cbp = br.read(4)? as u8;
}
if band.inherit_qd {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
mb.qd = tileref.mb[mb_idx].qd;
mb.q = calc_quant(band.quant, mb.qd);
} else {
if mb.mtype != MBType::Intra {
if band.inherit_mv {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
let mx = tileref.mb[mb_idx].mv_x;
let my = tileref.mb[mb_idx].mv_y;
if mv_scale == 0 {
mb.q = calc_quant(band.quant, mb.qd);
}
if band.inherit_mv {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
let mx = tileref.mb[mb_idx].mv_x;
let my = tileref.mb[mb_idx].mv_y;
if mv_scale == 0 {
if pic_hdr.ftype.is_intra() {
mb.mtype = MBType::Intra;
} else if band.inherit_mv {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
mb.mtype = tileref.mb[mb_idx].mtype;
} else {
return Err(DecoderError::MissingReference);
let q;
if band.has_qdelta {
if band.inherit_qd {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
mb.qd = tileref.mb[mb_idx].qd;
q = calc_quant(band.quant, mb.qd);
} else {
if mb.mtype != MBType::Intra {
if band.inherit_mv {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
let mx = tileref.mb[mb_idx].mv_x;
let my = tileref.mb[mb_idx].mv_y;
if mv_scale == 0 {
}
}
if band.inherit_mv {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
let mx = tileref.mb[mb_idx].mv_x;
let my = tileref.mb[mb_idx].mv_y;
if mv_scale == 0 {
}
}
-fn check_marker<'a>(br: &mut BitReader<'a>) -> DecoderResult<()> {
+fn check_marker(br: &mut BitReader) -> DecoderResult<()> {
let mark = br.read(1)?;
validate!(mark == 1);
Ok(())
}
}
idx += run;
- validate!((idx >= 0) && (idx < 64));
+ validate!((0..64).contains(&idx));
let spos = tables.scan[idx as usize];
let q = (u32::from(quant_mat[spos]) * u32::from(quant)) >> 9;
}
}
idx += run;
- validate!((idx >= 0) && (idx < 16));
+ validate!((0..16).contains(&idx));
let spos = tables.scan[idx as usize];
let q = (u32::from(quant_mat[spos]) * u32::from(quant)) >> 9;
mb.mtype = MBType::Inter;
mb.cbp = 0;
if band.inherit_mv {
- if let Some(ref tileref) = ref_tile {
+ if let Some(tileref) = ref_tile {
let mx = tileref.mb[mb_idx].mv_x;
let my = tileref.mb[mb_idx].mv_y;
mb.mv_x = scale_mv(mx, mv_scale);
let stride = frame.plane_stride[band.plane_no];
let mut dstidx = tile.pos_x + tile.pos_y * stride;
- let mut dst = &mut frame.plane_buf[band.plane_no];
+ let dst = &mut frame.plane_buf[band.plane_no];
let pos_x = tile.pos_x;
let pos_y = tile.pos_y;
let tile_w = (tile.w + 15) & !15;
if let TxType::Transform8(ref params) = band.ttype {
decode_block8x8(br, &band.blk_cb, &band.rvmap, params, is_intra, band.tr.is_2d(), &mut prev_dc, mb.q, &mut blk, tr)?;
if is_intra {
- put_block(&mut dst, dstidx + boff, stride, &blk, 8);
+ put_block(dst, dstidx + boff, stride, &blk, 8);
} else {
- add_block(&mut dst, dstidx + boff, stride, &blk, 8);
+ add_block(dst, dstidx + boff, stride, &blk, 8);
}
}
if let TxType::Transform4(ref params) = band.ttype {
decode_block4x4(br, &band.blk_cb, &band.rvmap, params, is_intra, band.tr.is_2d(), &mut prev_dc, mb.q, &mut blk, tr)?;
if is_intra {
- put_block(&mut dst, dstidx + boff, stride, &blk, 4);
+ put_block(dst, dstidx + boff, stride, &blk, 4);
} else {
- add_block(&mut dst, dstidx + boff, stride, &blk, 4);
+ add_block(dst, dstidx + boff, stride, &blk, 4);
}
}
} else {
if is_intra {
(transform_dc)(&mut blk, prev_dc);
- put_block(&mut dst, dstidx + boff, stride, &blk, band.blk_size);
+ put_block(dst, dstidx + boff, stride, &blk, band.blk_size);
}
}
cbp >>= 1;
}
if is_intra {
if band.blk_size == 8 {
- put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
+ put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
} else {
- put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
+ put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
}
} else {
if band.blk_size == 8 {
- add_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
+ add_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
} else {
- add_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
+ add_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
}
}
} else {
if is_intra {
(transform_dc)(&mut blk, prev_dc);
if band.blk_size == 8 {
- put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
+ put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 8);
} else {
- put_block(&mut dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
+ put_block(dst, dstidx + mb_x * band.blk_size, stride, &blk, 4);
}
}
}
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)),
+ ..Default::default() })
},
NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Audio(ainfo) => {
let tag = src.read_tag()?;
validate!(&tag == b"MAC ");
let version = src.read_u16le()?;
- validate!(version >= 3800 && version <= 3990);
+ validate!((3800..=3990).contains(&version));
let seektab_len;
let _wavtail_len;
if br.seek(SeekFrom::Start(0)).is_err() {
return false;
}
- if let Ok([b'f', b'L', b'a', b'C']) = br.read_tag() {
- true
- } else {
- false
- }
+ matches!(br.read_tag(), Ok([b'f', b'L', b'a', b'C']))
}
}
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)),
+ ..Default::default() })
},
NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Audio(ainfo) => {
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Audio(NAAudioInfo::new(0, 1, SND_S16_FORMAT, DEFAULT_BLOCK_LEN)),
+ ..Default::default() })
},
NACodecTypeInfo::Video(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Audio(ainfo) => {
((self.0 >> 10) & 0x1F, (self.0 >> 5) & 0x1F, self.0 & 0x1F)
}
fn pack(r: u16, g: u16, b: u16) -> Self {
- Pixel16{ 0: (r << 10) | (g << 5) | b }
+ Pixel16((r << 10) | (g << 5) | b)
}
fn invalid() -> Self { Self(0x8000) }
fn is_invalid(self) -> bool { self == Self::invalid() }
self.clr2[0] = clr0;
self.clr2[1] = if !clr1.is_invalid() { clr1 } else { clr0 };
if clr0 == clr1 {
- self.fill_val = Pixel16 { 0: buf[0].0 & !0x400 };
+ self.fill_val = Pixel16(buf[0].0 & !0x400);
filled = true;
}
two_clr = true;
for pix in buf.iter() {
avg.add(*pix, 1);
}
- self.fill_val = Pixel16 { 0: avg.get_centroid().0 & !0x400 };
+ self.fill_val = Pixel16(avg.get_centroid().0 & !0x400);
for pix in buf.iter() {
self.fill_dist += pix.dist(self.fill_val);
}
return;
}
- self.clr8 = [[Pixel16 { 0: 0}; 2]; 4];
+ self.clr8 = [[Pixel16(0); 2]; 4];
self.clr8_flags = 0;
self.clr8_dist = 0;
let mut mask = 1;
fn get_block(src: &[u16], sstride: usize, buf: &mut [Pixel16; 16]) {
for (line, dst) in src.chunks(sstride).zip(buf.chunks_mut(4)) {
for i in 0..4 {
- dst[i] = Pixel16 { 0: line[i] };
+ dst[i] = Pixel16(line[i]);
}
}
}
fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
match encinfo.format {
NACodecTypeInfo::None => {
- let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, RGB555_FORMAT));
- Ok(ofmt)
+ Ok(EncodeParameters {
+ format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, RGB555_FORMAT)),
+ ..Default::default() })
},
NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Video(vinfo) => {
let version = br.read_byte()?;
validate!(version == 0);
let bits = br.read_byte()?;
- validate!(bits >= 8 && bits <= 32);
+ validate!((8..=32).contains(&bits));
self.pb = br.read_byte()?;
validate!(self.pb == 40);
self.mb = br.read_byte()?;
br.read(2) as u8
} else { 0 };
- let mut amp = br.read_code(&level_cb)? as i8;
+ let mut amp = br.read_code(level_cb)? as i8;
amp += self.fft_levels[LEVEL_INDEX[pos] as usize] as i8;
if amp < 0 {
amp = 0;
match id {
17..=23 => {
let grp = i16::from(self.subsampling) + 4 - i16::from(id - 17);
- if grp >= 0 && grp < 5 {
+ if (0..5).contains(&grp) {
self.read_tones(br, grp as usize, false)?;
}
},
},
33..=39 => {
let grp = i16::from(self.subsampling) + 4 - i16::from(id - 33);
- if grp >= 0 && grp < 5 {
+ if (0..5).contains(&grp) {
self.read_tones(br, grp as usize, true)?;
}
},
let mut chunks = self.fft_buf[ch].chunks_mut(1 << self.frame_bits);
let first = chunks.next().unwrap();
let second = chunks.next().unwrap();
- first.copy_from_slice(&second);
+ first.copy_from_slice(second);
for el in second.iter_mut() {
*el = FFTC_ZERO;
}
if !is_4x4 || (hdr.dquant && hdr.ftype != FrameType::I && cbp != 0) {
let dq = br.read_code_signed(IntCodeType::Gamma)?;
let new_q = i32::from(sstate.q) + dq;
- validate!(new_q >= 0 && new_q < 32);
+ validate!((0..32).contains(&new_q));
sstate.q = new_q as u8;
}
if !is_4x4 {
if hdr.dquant && cbp != 0 {
let dq = br.read_code_signed(IntCodeType::Gamma)?;
let new_q = i32::from(sstate.q) + dq;
- validate!(new_q >= 0 && new_q < 32);
+ validate!((0..32).contains(&new_q));
sstate.q = new_q as u8;
}
for sb in 0..4 {
let _bits = br.read_u16be().unwrap();
let sample_rate = br.read_u32be().unwrap();
let max_frame_size = br.read_u32be().unwrap();
- validate!((channels == 1 || channels == 2) && (sample_rate >= 8000 && sample_rate <= 96000));
+ validate!((channels == 1 || channels == 2) && (8000..=96000).contains(&sample_rate));
self.max_frame_size = max_frame_size.max(sample_rate) as usize;
let ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), channels as u8,
}
}
pub fn is_fwd(self) -> bool {
- match self {
+ matches!(self,
MBType::MBP16x16 | MBType::MBP16x16Mix |
MBType::MBP16x8 | MBType::MBP8x16 | MBType::MBP8x8 |
- MBType::MBForward => true,
- _ => false,
- }
+ MBType::MBForward)
}
pub fn is_bwd(self) -> bool {
- match self {
- MBType::MBBidir | MBType::MBBackward => true,
- _ => false,
- }
+ matches!(self, MBType::MBBidir | MBType::MBBackward)
}
pub fn has_mv_dir(self, fwd: bool) -> bool {
match self {
}
}
pub fn is_nomv(self) -> bool {
- match self {
- MBType::MBIntra | MBType::MBIntra16 | MBType::MBSkip | MBType::MBDirect => true,
- _ => false,
- }
+ matches!(self, MBType::MBIntra | MBType::MBIntra16 | MBType::MBSkip | MBType::MBDirect)
}
/*pub fn is_16x16(self) -> bool {
match self {
}
Ok(())
}
- fn fill_deblock_flags(&self, sstate: &SState, mb_pos: usize, mbinfo: &mut Vec<RV34MBInfo>) {
+ fn fill_deblock_flags(&self, sstate: &SState, mb_pos: usize, mbinfo: &mut [RV34MBInfo]) {
let mbt = mbinfo[mb_pos].mbtype;
let mut hmvmask = 0;
let mut vmvmask = 0;
}
}
fn has_hor_split(self) -> bool {
- match self {
- PUType::N2Hor | PUType::N4Hor | PUType::N34Hor | PUType::Quarters => true,
- _ => false,
- }
+ matches!(self, PUType::N2Hor | PUType::N4Hor | PUType::N34Hor | PUType::Quarters)
}
fn has_ver_split(self) -> bool {
- match self {
- PUType::N2Ver | PUType::N4Ver | PUType::N34Ver | PUType::Quarters => true,
- _ => false,
- }
+ matches!(self, PUType::N2Ver | PUType::N4Ver | PUType::N34Ver | PUType::Quarters)
}
}
}
}
fn is_ref0(self) -> bool {
- match self {
- MVRef::Ref0 | MVRef::Ref0AndBRef => true,
- _ => false,
- }
+ matches!(self, MVRef::Ref0 | MVRef::Ref0AndBRef)
}
fn is_fwd(self) -> bool {
- match self {
- MVRef::Ref0 | MVRef::Ref1 | MVRef::Ref0AndBRef => true,
- _ => false,
- }
+ matches!(self, MVRef::Ref0 | MVRef::Ref1 | MVRef::Ref0AndBRef)
}
fn is_bwd(self) -> bool {
- match self {
- MVRef::BRef | MVRef::Ref0AndBRef => true,
- _ => false,
- }
+ matches!(self, MVRef::BRef | MVRef::Ref0AndBRef)
}
}
let cu_w = hdr.get_width_cu();
let dqp = hdr.read_line_qp_offset(&mut br)?;
let qps = (hdr.qp as i8) + dqp;
- validate!((qps >= 0) && (qps < 32));
+ validate!((0..32).contains(&qps));
let qp = qps as u8;
self.qp = qp;
self.sel_qp = match hdr.osvquant {
let dstride = buf.stride[comp];
let soff = buf.offset[comp];
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut dst = &mut buf.data;
+ let dst = &mut buf.data;
self.populate_ipred(hdr, dst, soff, dstride, 0, 0, size >> 1, false);
- self.ipred.pred_angle(&mut dst, off, dstride, size >> 1, itype as usize, false);
+ self.ipred.pred_angle(dst, off, dstride, size >> 1, itype as usize, false);
}
},
_ => {
self.dsp.transform4x4(&mut self.y_coeffs[i * 16..][..16]);
let dstride = buf.stride[0];
let off = xpos + x * 4 + (ypos + y * 4) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs[i*16..][..16], 4);
+ let dst = &mut buf.data;
+ self.dsp.add_block(dst, off, dstride, &self.y_coeffs[i*16..][..16], 4);
}
}
}
self.dsp.transform4x4(&mut self.u_coeffs[i * 16..][..16]);
let dstride = buf.stride[1];
let off = buf.offset[1] + xoff + yoff * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs[i * 16..][..16], 4);
+ let dst = &mut buf.data;
+ self.dsp.add_block(dst, off, dstride, &self.u_coeffs[i * 16..][..16], 4);
}
if ((cbp16 >> (20 + i)) & 1) != 0 {
self.dsp.transform4x4(&mut self.v_coeffs[i * 16..][..16]);
let dstride = buf.stride[2];
let off = buf.offset[2] + xoff + yoff * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs[i * 16..][..16], 4);
+ let dst = &mut buf.data;
+ self.dsp.add_block(dst, off, dstride, &self.v_coeffs[i * 16..][..16], 4);
}
}
}
if split_i4x4 {
let dstride = buf.stride[0];
let off = xpos + xoff + (ypos + yoff) * dstride;
- let mut dst = &mut buf.data;
+ let dst = &mut buf.data;
self.populate_ipred(hdr, dst, 0, dstride, xoff, yoff, 4, true);
let itype = self.blk_info[self.blk_pos + (i & 1) + (i >> 1) * self.blk_stride].imode;
- self.ipred.pred_angle(&mut dst, off, dstride, 4, itype as usize, false);
+ self.ipred.pred_angle(dst, off, dstride, 4, itype as usize, false);
}
if ((cbp8 >> i) & 1) != 0 {
let blk = &mut self.y_coeffs[i * 16..][..16];
let dstride = buf.stride[0];
let soff = buf.offset[0];
let off = soff + xpos + xoff + (ypos + yoff) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, blk, 4);
+ self.dsp.add_block(buf.data, off, dstride, blk, 4);
}
}
if ((cbp8 >> 4) & 1) != 0 {
let dstride = buf.stride[1];
let soff = buf.offset[1];
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 4);
+ self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 4);
}
if ((cbp8 >> 5) & 1) != 0 {
self.dsp.transform4x4(&mut self.v_coeffs);
let dstride = buf.stride[2];
let soff = buf.offset[2];
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 4);
+ self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 4);
}
}
},
self.dsp.transform8x8(&mut self.y_coeffs);
let dstride = buf.stride[0];
let off = xpos + ypos * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs, 8);
+ self.dsp.add_block(buf.data, off, dstride, &self.y_coeffs, 8);
}
if ((cbp8 >> 4) & 1) != 0 {
self.dsp.transform4x4(&mut self.u_coeffs);
let dstride = buf.stride[1];
let soff = buf.offset[1];
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 4);
+ self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 4);
}
if ((cbp8 >> 5) & 1) != 0 {
self.dsp.transform4x4(&mut self.v_coeffs);
let dstride = buf.stride[2];
let soff = buf.offset[2];
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 4);
+ self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 4);
}
}
},
self.dsp.transform16x16(&mut self.y_coeffs);
let dstride = buf.stride[0];
let off = xpos + x * 16 + (ypos + y * 16) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs, 16);
+ self.dsp.add_block(buf.data, off, dstride, &self.y_coeffs, 16);
}
if ((super_cbp >> 16) & 0xF) != 0 {
self.dsp.transform8x8(&mut self.u_coeffs);
let dstride = buf.stride[1];
let soff = buf.offset[1];
let off = soff + (xpos >> 1) + x * 8 + ((ypos >> 1) + y * 8) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 8);
+ self.dsp.add_block(buf.data, off, dstride, &self.u_coeffs, 8);
}
if ((super_cbp >> 20) & 0xF) != 0 {
self.dsp.transform8x8(&mut self.v_coeffs);
let dstride = buf.stride[2];
let soff = buf.offset[2];
let off = soff + (xpos >> 1) + x * 8 + ((ypos >> 1) + y * 8) * dstride;
- let mut dst = &mut buf.data;
- self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 8);
+ self.dsp.add_block(buf.data, off, dstride, &self.v_coeffs, 8);
}
}
}
let bsize = iinfo.block_size as usize;
let ppos = self.sub_packet;
for sb in 0..halffact {
- let mut dst = &mut self.buf[sb * 2 * fsize + ppos * bsize..][..bsize];
- src.read_buf(&mut dst)?;
+ let dst = &mut self.buf[sb * 2 * fsize + ppos * bsize..][..bsize];
+ src.read_buf(dst)?;
}
self.sub_packet += 1;
if self.sub_packet == factor {
for sb in 0..factor2 {
let sb_pos = factor * sb + ((factor + 1) >> 1) * (ppos & 1) + (ppos >> 1);
- let mut dst = &mut self.buf[bsize * sb_pos..][..bsize];
- src.read_buf(&mut dst)?;
+ let dst = &mut self.buf[bsize * sb_pos..][..bsize];
+ src.read_buf(dst)?;
}
},
Deinterleaver::Sipro => {
let fsize = iinfo.frame_size as usize;
let ppos = self.sub_packet;
- let mut dst = &mut self.buf[fsize * ppos..][..fsize];
- src.read_buf(&mut dst)?;
+ let dst = &mut self.buf[fsize * ppos..][..fsize];
+ src.read_buf(dst)?;
},
Deinterleaver::VBR => {
validate!(payload_size >= 5);
//todo skip unwanted packet
let keyframe = (flags & KEYFRAME_FLAG) != 0;
- let ret = RMDemuxCommon::parse_packet_payload(&mut self.src, &mut self.str_data.streams[str_id], stream, &mut self.slice_buf, &mut self.queued_pkts, keyframe, ts, payload_size);
+ let ret = RMDemuxCommon::parse_packet_payload(self.src, &mut self.str_data.streams[str_id], stream, &mut self.slice_buf, &mut self.queued_pkts, keyframe, ts, payload_size);
if let Err(DemuxerError::TryAgain) = ret {
continue;
} else {
let ver = self.src.read_u16be()?;
let ainfo = match ver {
3 => {
- parse_aformat3(&mut self.src)?
+ parse_aformat3(self.src)?
},
4 => {
- parse_aformat4(&mut self.src)?
+ parse_aformat4(self.src)?
},
5 => {
- parse_aformat5(&mut self.src)?
+ parse_aformat5(self.src)?
},
_ => {
println!("unknown version {}", ver);
let stream = streamres.unwrap();
if let Some(ref mut astr) = self.stream {
loop {
- let ret = astr.read_apackets(&mut self.queued_pkts, &mut self.src, stream.clone(), 0, false, self.blk_size);
+ let ret = astr.read_apackets(&mut self.queued_pkts, self.src, stream.clone(), 0, false, self.blk_size);
if let Err(DemuxerError::TryAgain) = ret {
continue;
}
}
}
fn is_data_start(&self) -> bool {
- match *self {
- IVRRecord::DataStart => true,
- _ => false,
- }
+ matches!(*self, IVRRecord::DataStart)
}
}
let magic = self.src.peek_u32be()?;
if magic == mktag!(b".REC") {
let mut rec = RecordDemuxer::new(0, 0);
- rec.parse_header(&mut self.src, strmgr, &mut self.str_data)?;
+ rec.parse_header(self.src, strmgr, &mut self.str_data)?;
self.recs.push(rec);
} else if magic == mktag!(b".R1M") {
println!("R1M kind");
self.src.read_skip(4)?; // magic
self.src.read_skip(3)?; // always 0, 1, 1 ?
- let _name = IVRRecord::read_string(&mut self.src)?;
+ let _name = IVRRecord::read_string(self.src)?;
self.src.read_skip(1)?; // always 0?
let len1 = self.src.read_u32be()? as u64;
let off1 = self.src.read_u64be()?;
if len > 0x20 {
let num_streams = self.str_data.streams.len() as u32;
let mut rec = RecordDemuxer::new(pos + 12, num_streams);
- rec.parse_header(&mut self.src, strmgr, &mut self.str_data)?;
+ rec.parse_header(self.src, strmgr, &mut self.str_data)?;
self.recs.push(rec);
}
self.src.seek(SeekFrom::Start(pos + len))?;
}
loop {
if self.cur_rec >= self.recs.len() { return Err(DemuxerError::EOF); }
- let res = self.recs[self.cur_rec].get_packet(&mut self.src, &mut self.str_data, strmgr, &mut self.queued_pkts, &mut self.slice_buf);
+ let res = self.recs[self.cur_rec].get_packet(self.src, &mut self.str_data, strmgr, &mut self.queued_pkts, &mut self.slice_buf);
if let Err(DemuxerError::EOF) = res {
self.cur_rec += 1;
} else {
impl<'a> CC<'a> {
fn eval(&self, src: &mut ByteReader) -> bool {
match *self {
- CC::Or (ref a, ref b) => { a.eval(src) || b.eval(src) },
+ CC::Or(a, b) => { a.eval(src) || b.eval(src) },
CC::Eq(ref arg) => { arg.eq(src) },
CC::In(ref a, ref b) => { a.ge(src) && b.le(src) },
CC::Lt(ref arg) => { arg.lt(src) },
let abuf = alloc_audio_buffer(self.ainfo, SAMPLES, self.chmap.clone())?;
let mut adata = abuf.get_abuf_i16().unwrap();
- let mut asamples = adata.get_data_mut().unwrap();
+ let asamples = adata.get_data_mut().unwrap();
if self.cur_ftype == G7231FrameType::Active {
- self.synth_frame_active(&mut asamples, bad_frame);
+ self.synth_frame_active(asamples, bad_frame);
} else {
self.synth_frame_other();
}
aic: bool,
}
-fn check_marker<'a>(br: &mut BitReader<'a>) -> DecoderResult<()> {
+fn check_marker(br: &mut BitReader) -> DecoderResult<()> {
let mark = br.read(1)?;
validate!(mark == 1);
Ok(())
let hdr = self.src.peek_byte()?;
if (hdr & 0xF0) != 0 { break; }
self.src.read_skip(1)?;
- let hdr_len = read_size(&mut self.src)?;
+ let hdr_len = read_size(self.src)?;
hdr_data.resize(hdr_len, 0);
self.src.read_buf(&mut hdr_data)?;
self.parse_header_packet(&hdr_data)?;