}
fn synth_audio(&mut self, dsp: &mut DSP, abuf: &mut NABufferType, srate_idx: usize) {
let mut adata = abuf.get_abuf_f32().unwrap();
- let mut output = adata.get_data_mut();
+ let output = adata.get_data_mut().unwrap();
let off0 = abuf.get_offset(self.channel);
let off1 = abuf.get_offset(self.channel + 1);
self.ics[0].synth_channel(dsp, &mut output[off0..], srate_idx);
let abuf = alloc_audio_buffer(ainfo, ATRAC3_FRAME_SIZE, self.chmap.clone())?;
let mut adata = abuf.get_abuf_f32().unwrap();
- let mut output = adata.get_data_mut();
+ let output = adata.get_data_mut().unwrap();
for ch in 0..self.channels {
let dpos = abuf.get_offset(ch);
let mut idxu = buf.get_offset(1) + xpos * 8 + ypos * 8 * strideu;
let mut idxv = buf.get_offset(2) + xpos * 8 + ypos * 8 * stridev;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
for j in 0..8 {
let sbuf: &[u8] = sdta.as_slice();
let dstride = dst.get_stride(plane);
let mut doff = dst.get_offset(plane) + x + y * dstride;
- let mut ddta = dst.get_data_mut();
+ let ddta = dst.get_data_mut().unwrap();
let dbuf: &mut [u8] = ddta.as_mut_slice();
for _ in 0..size {
let dst = &mut dbuf[doff..][..size];
let sbuf: &[u8] = sdta.as_slice();
let dstride = dst.get_stride(plane);
let mut doff = dst.get_offset(plane) + x + y * dstride;
- let mut ddta = dst.get_data_mut();
+ let ddta = dst.get_data_mut().unwrap();
let dbuf: &mut [u8] = ddta.as_mut_slice();
for _ in 0..size {
let dst = &mut dbuf[doff..][..size];
let size = if comp == 0 { tile_size } else { tile_size >> 1 };
let stride = buf.get_stride(comp);
let planeoff = buf.get_offset(comp);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
let right = size - (w & (size - 1));
if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() {
let duration = get_duration(&ainfo, pkt.get_duration(), pkt.get_buffer().len());
let pktbuf = pkt.get_buffer();
- let mut buf: Vec<u8> = Vec::with_capacity(pktbuf.len());
- buf.clone_from(&pktbuf);
- let abuf = NAAudioBuffer::new_from_buf(ainfo, Rc::new(RefCell::new(buf)), self.chmap.clone());
+ let abuf = NAAudioBuffer::new_from_buf(ainfo, pktbuf, self.chmap.clone());
let mut frm = NAFrame::new_from_pkt(pkt, info, NABufferType::AudioPacked(abuf));
frm.set_duration(Some(duration));
frm.set_keyframe(true);
let abuf = alloc_audio_buffer(self.ainfo, duration, self.chmap.clone())?;
let mut adata = abuf.get_abuf_f32().unwrap();
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
let frame_len = self.mode.subframe_len * self.mode.subframes;
for (input, output) in pktbuf.chunks(frm_size).zip(dst.chunks_mut(out_frm_size)) {
let abuf = alloc_audio_buffer(ainfo, duration, bsi.acmod.get_channel_map(bsi.lfeon))?;
let mut adata = abuf.get_abuf_f32().unwrap();
- let mut output = adata.get_data_mut();
+ let output = adata.get_data_mut().unwrap();
self.ablk = AudioBlock::new();
for blk in 0..NBLOCKS {
let mut idxu = buf.get_offset(1) + xpos * 8 + ypos * 8 * strideu;
let mut idxv = buf.get_offset(2) + xpos * 8 + ypos * 8 * stridev;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
for j in 0..8 {
let mut idxu = buf.get_offset(1) + xpos * 8 + ypos * 8 * strideu;
let mut idxv = buf.get_offset(2) + xpos * 8 + ypos * 8 * stridev;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
for j in 0..8 {
for comp in 0..3 {
let dstride = dst.get_stride(comp);
let doff = dst.get_offset(comp);
- let mut ddta = dst.get_data_mut();
+ let ddta = dst.get_data_mut().unwrap();
let dbuf: &mut [u8] = ddta.as_mut_slice();
let x = if comp > 0 { dx/2 } else { dx };
let y = if comp > 0 { dy/2 } else { dy };
let sbuf: &[u8] = sdta.as_slice();
let dstride = dst.get_stride(comp);
let doff = dst.get_offset(comp);
- let mut ddta = dst.get_data_mut();
+ let ddta = dst.get_data_mut().unwrap();
let dbuf: &mut [u8] = ddta.as_mut_slice();
let x = if comp > 0 { dx/2 } else { dx };
let y = if comp > 0 { dy/2 } else { dy };
fn deblock_hor(buf: &mut NAVideoBuffer<u8>, comp: usize, q: u8, off: usize) {
let stride = buf.get_stride(comp);
- let mut dptr = buf.get_data_mut();
+ let dptr = buf.get_data_mut().unwrap();
let buf = dptr.as_mut_slice();
for x in 0..8 {
let a = buf[off - 2 * stride + x] as i16;
fn deblock_ver(buf: &mut NAVideoBuffer<u8>, comp: usize, q: u8, off: usize) {
let stride = buf.get_stride(comp);
- let mut dptr = buf.get_data_mut();
+ let dptr = buf.get_data_mut().unwrap();
let buf = dptr.as_mut_slice();
for y in 0..8 {
let a = buf[off - 2 + y * stride] as i16;
}
fn fill_packet(&mut self, pkt: &mut NAPacket) -> DemuxerResult<()> {
let mut refbuf = pkt.get_buffer();
- let buf = Rc::make_mut(&mut refbuf);
+ let buf = refbuf.as_mut().unwrap();
let res = self.read_buf(buf.as_mut_slice());
if let Err(_) = res { return Err(DemuxerError::IOError); }
Ok(())
}
None
}
-}
\ No newline at end of file
+}
pub use std::rc::Rc;
pub use std::cell::*;
pub use crate::formats::*;
+pub use crate::refs::*;
#[allow(dead_code)]
#[derive(Clone,Copy,PartialEq)]
}
}
-pub type NABufferRefT<T> = Rc<RefCell<Vec<T>>>;
-
#[derive(Clone)]
pub struct NAVideoBuffer<T> {
info: NAVideoInfo,
- data: NABufferRefT<T>,
+ data: NABufferRef<Vec<T>>,
offs: Vec<usize>,
strides: Vec<usize>,
}
else { self.offs[idx] }
}
pub fn get_info(&self) -> NAVideoInfo { self.info }
- pub fn get_data(&self) -> Ref<Vec<T>> { self.data.borrow() }
- pub fn get_data_mut(&mut self) -> RefMut<Vec<T>> { self.data.borrow_mut() }
+ pub fn get_data(&self) -> &Vec<T> { self.data.as_ref() }
+ pub fn get_data_mut(&mut self) -> Option<&mut Vec<T>> { self.data.as_mut() }
pub fn copy_buffer(&mut self) -> Self {
- let mut data: Vec<T> = Vec::with_capacity(self.data.borrow().len());
- data.clone_from(self.data.borrow().as_ref());
+ let mut data: Vec<T> = Vec::with_capacity(self.data.len());
+ data.clone_from(self.data.as_ref());
let mut offs: Vec<usize> = Vec::with_capacity(self.offs.len());
offs.clone_from(&self.offs);
let mut strides: Vec<usize> = Vec::with_capacity(self.strides.len());
strides.clone_from(&self.strides);
- NAVideoBuffer { info: self.info, data: Rc::new(RefCell::new(data)), offs: offs, strides: strides }
+ NAVideoBuffer { info: self.info, data: NABufferRef::new(data), offs: offs, strides: strides }
}
pub fn get_stride(&self, idx: usize) -> usize {
if idx >= self.strides.len() { return 0; }
#[derive(Clone)]
pub struct NAAudioBuffer<T> {
info: NAAudioInfo,
- data: NABufferRefT<T>,
+ data: NABufferRef<Vec<T>>,
offs: Vec<usize>,
chmap: NAChannelMap,
len: usize,
}
pub fn get_info(&self) -> NAAudioInfo { self.info }
pub fn get_chmap(&self) -> NAChannelMap { self.chmap.clone() }
- pub fn get_data(&self) -> Ref<Vec<T>> { self.data.borrow() }
- pub fn get_data_mut(&mut self) -> RefMut<Vec<T>> { self.data.borrow_mut() }
+ pub fn get_data(&self) -> &Vec<T> { self.data.as_ref() }
+ pub fn get_data_mut(&mut self) -> Option<&mut Vec<T>> { self.data.as_mut() }
pub fn copy_buffer(&mut self) -> Self {
- let mut data: Vec<T> = Vec::with_capacity(self.data.borrow().len());
- data.clone_from(self.data.borrow().as_ref());
+ let mut data: Vec<T> = Vec::with_capacity(self.data.len());
+ data.clone_from(self.data.as_ref());
let mut offs: Vec<usize> = Vec::with_capacity(self.offs.len());
offs.clone_from(&self.offs);
- NAAudioBuffer { info: self.info, data: Rc::new(RefCell::new(data)), offs: offs, chmap: self.get_chmap(), len: self.len }
+ NAAudioBuffer { info: self.info, data: NABufferRef::new(data), offs: offs, chmap: self.get_chmap(), len: self.len }
}
pub fn get_length(&self) -> usize { self.len }
}
impl NAAudioBuffer<u8> {
- pub fn new_from_buf(info: NAAudioInfo, data: NABufferRefT<u8>, chmap: NAChannelMap) -> Self {
- let len = data.borrow().len();
+ pub fn new_from_buf(info: NAAudioInfo, data: NABufferRef<Vec<u8>>, chmap: NAChannelMap) -> Self {
+ let len = data.len();
NAAudioBuffer { info: info, data: data, chmap: chmap, offs: Vec::new(), len: len }
}
}
AudioI32 (NAAudioBuffer<i32>),
AudioF32 (NAAudioBuffer<f32>),
AudioPacked(NAAudioBuffer<u8>),
- Data (NABufferRefT<u8>),
+ Data (NABufferRef<Vec<u8>>),
None,
}
strides.push(stride);
let mut data: Vec<u8> = Vec::with_capacity(new_size.unwrap());
data.resize(new_size.unwrap(), 0);
- let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
Ok(NABufferType::Video(buf))
} else if !all_packed {
for i in 0..fmt.get_num_comp() {
if max_depth <= 8 {
let mut data: Vec<u8> = Vec::with_capacity(new_size);
data.resize(new_size, 0);
- let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
Ok(NABufferType::Video(buf))
} else if max_depth <= 16 {
let mut data: Vec<u16> = Vec::with_capacity(new_size);
data.resize(new_size, 0);
- let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
Ok(NABufferType::Video16(buf))
} else {
let mut data: Vec<u32> = Vec::with_capacity(new_size);
data.resize(new_size, 0);
- let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
Ok(NABufferType::Video32(buf))
}
} else if all_bytealigned || unfit_elem_size {
let mut data: Vec<u8> = Vec::with_capacity(new_size);
data.resize(new_size, 0);
strides.push(line_sz.unwrap());
- let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
Ok(NABufferType::VideoPacked(buf))
} else {
let elem_sz = fmt.get_elem_size();
let mut data: Vec<u16> = Vec::with_capacity(new_size);
data.resize(new_size, 0);
strides.push(width);
- let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
Ok(NABufferType::Video16(buf))
},
4 => {
let mut data: Vec<u32> = Vec::with_capacity(new_size);
data.resize(new_size, 0);
strides.push(width);
- let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
Ok(NABufferType::Video32(buf))
},
_ => unreachable!(),
if ainfo.format.get_bits() == 32 {
let mut data: Vec<f32> = Vec::with_capacity(length);
data.resize(length, 0.0);
- let buf: NAAudioBuffer<f32> = NAAudioBuffer { data: Rc::new(RefCell::new(data)), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
+ let buf: NAAudioBuffer<f32> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
Ok(NABufferType::AudioF32(buf))
} else {
Err(AllocatorError::TooLargeDimensions)
if ainfo.format.get_bits() == 8 && !ainfo.format.is_signed() {
let mut data: Vec<u8> = Vec::with_capacity(length);
data.resize(length, 0);
- let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: Rc::new(RefCell::new(data)), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
+ let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
Ok(NABufferType::AudioU8(buf))
} else if ainfo.format.get_bits() == 16 && ainfo.format.is_signed() {
let mut data: Vec<i16> = Vec::with_capacity(length);
data.resize(length, 0);
- let buf: NAAudioBuffer<i16> = NAAudioBuffer { data: Rc::new(RefCell::new(data)), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
+ let buf: NAAudioBuffer<i16> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
Ok(NABufferType::AudioI16(buf))
} else {
Err(AllocatorError::TooLargeDimensions)
let length = ainfo.format.get_audio_size(len.unwrap() as u64);
let mut data: Vec<u8> = Vec::with_capacity(length);
data.resize(length, 0);
- let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: Rc::new(RefCell::new(data)), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
+ let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
Ok(NABufferType::AudioPacked(buf))
}
}
pub fn alloc_data_buffer(size: usize) -> Result<NABufferType, AllocatorError> {
let mut data: Vec<u8> = Vec::with_capacity(size);
data.resize(size, 0);
- let buf: NABufferRefT<u8> = Rc::new(RefCell::new(data));
+ let buf: NABufferRef<Vec<u8>> = NABufferRef::new(data);
Ok(NABufferType::Data(buf))
}
buf.clone()
}
+pub struct NABufferPool {
+ pool: Vec<NABufferRef<NABufferType>>,
+ max_len: usize,
+}
+
+impl NABufferPool {
+ pub fn new(max_len: usize) -> Self {
+ Self {
+ pool: Vec::with_capacity(max_len),
+ max_len,
+ }
+ }
+ pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> {
+ let nbufs = self.max_len - self.pool.len();
+ for _ in 0..nbufs {
+ let buf = alloc_video_buffer(vinfo.clone(), align)?;
+ self.pool.push(NABufferRef::new(buf));
+ }
+ Ok(())
+ }
+ pub fn prealloc_audio(&mut self, ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelMap) -> Result<(), AllocatorError> {
+ let nbufs = self.max_len - self.pool.len();
+ for _ in 0..nbufs {
+ let buf = alloc_audio_buffer(ainfo.clone(), nsamples, chmap.clone())?;
+ self.pool.push(NABufferRef::new(buf));
+ }
+ Ok(())
+ }
+ pub fn add(&mut self, buf: NABufferType) -> bool {
+ if self.pool.len() < self.max_len {
+ self.pool.push(NABufferRef::new(buf));
+ true
+ } else {
+ false
+ }
+ }
+ pub fn get_free(&mut self) -> Option<NABufferRef<NABufferType>> {
+ for e in self.pool.iter() {
+ if e.get_num_refs() == 1 {
+ return Some(e.clone());
+ }
+ }
+ None
+ }
+}
+
#[allow(dead_code)]
#[derive(Clone)]
pub struct NACodecInfo {
pub struct NAPacket {
stream: Rc<NAStream>,
ts: NATimeInfo,
- buffer: Rc<Vec<u8>>,
+ buffer: NABufferRef<Vec<u8>>,
keyframe: bool,
// options: HashMap<String, NAValue<'a>>,
}
pub fn new(str: Rc<NAStream>, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
// let mut vec: Vec<u8> = Vec::new();
// vec.resize(size, 0);
- NAPacket { stream: str, ts: ts, keyframe: kf, buffer: Rc::new(vec) }
+ NAPacket { stream: str, ts: ts, keyframe: kf, buffer: NABufferRef::new(vec) }
}
pub fn get_stream(&self) -> Rc<NAStream> { self.stream.clone() }
pub fn get_time_information(&self) -> NATimeInfo { self.ts }
pub fn get_dts(&self) -> Option<u64> { self.ts.get_dts() }
pub fn get_duration(&self) -> Option<u64> { self.ts.get_duration() }
pub fn is_keyframe(&self) -> bool { self.keyframe }
- pub fn get_buffer(&self) -> Rc<Vec<u8>> { self.buffer.clone() }
+ pub fn get_buffer(&self) -> NABufferRef<Vec<u8>> { self.buffer.clone() }
}
impl Drop for NAPacket {
pub mod formats;
pub mod frame;
pub mod io;
+pub mod refs;
pub mod register;
pub mod detect;
--- /dev/null
+use std::ops::{Deref, DerefMut};
+use std::sync::atomic::*;
+
+struct NABufferData<T> {
+ data: T,
+ refs: AtomicUsize,
+}
+
+impl<T> NABufferData<T> {
+ fn new(data: T) -> Self {
+ Self {
+ data: data,
+ refs: AtomicUsize::new(1),
+ }
+ }
+ fn inc_refs(obj: &mut Self) {
+ obj.refs.fetch_add(1, Ordering::SeqCst);
+ }
+ fn dec_refs(obj: &mut Self) {
+ if obj.refs.fetch_sub(1, Ordering::SeqCst) == 0 {
+ std::mem::forget(obj);
+ }
+ }
+ fn get_num_refs(obj: &Self) -> usize {
+ obj.refs.load(Ordering::Relaxed)
+ }
+ fn get_read_ptr(obj: &Self) -> &T {
+ &obj.data
+ }
+ fn get_write_ptr(obj: &mut Self) -> Option<&mut T> {
+ Some(&mut obj.data)
+ }
+}
+
+pub struct NABufferRef<T> {
+ ptr: *mut NABufferData<T>,
+}
+
+impl<T> NABufferRef<T> {
+ pub fn new(val: T) -> Self {
+ let bdata = NABufferData::new(val);
+ let nbox: Box<_> = Box::new(bdata);
+ Self { ptr: Box::into_raw(nbox) }
+ }
+ pub fn get_num_refs(&self) -> usize {
+ unsafe {
+ NABufferData::get_num_refs(self.ptr.as_mut().unwrap())
+ }
+ }
+ pub fn as_ref(&self) -> &T {
+ unsafe {
+ NABufferData::get_read_ptr(self.ptr.as_mut().unwrap())
+ }
+ }
+ pub fn as_mut(&mut self) -> Option<&mut T> {
+ unsafe {
+ NABufferData::get_write_ptr(self.ptr.as_mut().unwrap())
+ }
+ }
+}
+
+impl<T> Deref for NABufferRef<T> {
+ type Target = T;
+ fn deref(&self) -> &T { self.as_ref() }
+}
+
+impl<T> DerefMut for NABufferRef<T> {
+ fn deref_mut(&mut self) -> &mut T { self.as_mut().unwrap() }
+}
+
+impl<T> Clone for NABufferRef<T> {
+ fn clone(&self) -> Self {
+ unsafe {
+ NABufferData::inc_refs(self.ptr.as_mut().unwrap());
+ }
+ Self { ptr: self.ptr }
+ }
+}
+
+impl<T> Drop for NABufferRef<T> {
+ fn drop(&mut self) {
+ unsafe {
+ NABufferData::dec_refs(self.ptr.as_mut().unwrap());
+ }
+ }
+}
+
let mut adata = abuf.get_abuf_i16().unwrap();
let mut off0 = adata.get_offset(0);
let mut off1 = adata.get_offset(1);
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
for blk in pktbuf.chunks_exact(self.block_len) {
let mut mr = MemoryReader::new_read(blk);
if let Some(mut buf) = self.lastframe.get16() {
let stride = buf.get_stride(0);
{
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
if !is_sprite {
self.decode_16bit(data.as_mut_slice(), stride, out_width, height, &mut mask, &mut index)?;
} else {
if let Some(mut buf) = self.lastframe.get24() {
let stride = buf.get_stride(0);
{
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
self.decode_24bit(data.as_mut_slice(), stride, out_width, height, &mut mask, &mut index)?;
}
bufinfo = NABufferType::VideoPacked(buf);
fmt.get_chromaton(1).unwrap().get_offset() as usize,
fmt.get_chromaton(2).unwrap().get_offset() as usize];
let stride = buf.get_stride(0);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let mut off = 0;
fn output_frame(&mut self, buf: &mut NAVideoBuffer<u8>) {
let mut offs = [ buf.get_offset(0), buf.get_offset(1), buf.get_offset(2) ];
let strides = [ buf.get_stride(0), buf.get_stride(1), buf.get_stride(2) ];
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let mut pos = self.cur_frame.stride;
let (w, h) = buf.get_dimensions(plane);
let off = buf.get_offset(plane);
let stride = buf.get_stride(plane);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
self.decode_plane(&mut br, dst, off, stride, w, h, hscale, dbits, plane > 0)?;
}
let mut buf = bufo.unwrap();
let paloff = buf.get_offset(1);
let stride = buf.get_stride(0);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let fwd = (line <= -640) || (line >= 0);
let abuf = alloc_audio_buffer(self.ainfo, samples, self.chmap.clone())?;
let mut adata = abuf.get_abuf_i16().unwrap();
let off1 = adata.get_offset(1);
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
let psrc = &pktbuf[1..];
for (n, src) in psrc.chunks_exact(65).enumerate() {
let code = src[0].rotate_right(1);
{
let mut buf = bufinfo.get_vbuf16().unwrap();
let stride = buf.get_stride(0);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let refbuf = &self.frame[self.stride..];
let abuf = alloc_audio_buffer(self.ainfo, samples, self.chmap.clone())?;
let mut adata = abuf.get_abuf_i16().unwrap();
let off1 = adata.get_offset(1);
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
let mut first = pktbuf[0] == 0;
let psrc = &pktbuf[1..];
for (n, src) in psrc.chunks_exact(41).enumerate() {
let mut buf = bufo.unwrap();
let paloff = buf.get_offset(1);
let stride = buf.get_stride(0);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let mut sidx = PREAMBLE_SIZE;
let mut didx = 0;
let abuf = alloc_audio_buffer(self.ainfo, samples, self.chmap.clone())?;
let mut adata = abuf.get_abuf_i16().unwrap();
let off1 = adata.get_offset(1);
- let mut buf = adata.get_data_mut();
+ let buf = adata.get_data_mut().unwrap();
if self.chmap.num_channels() == 2 {
for (i, e) in pktbuf.chunks(2).enumerate() {
self.state0 = self.state0.wrapping_add(self.delta_tab[e[0] as usize]);
fn decode_frame(&mut self, br: &mut ByteReader, buf: &mut NAVideoBuffer<u8>) -> DecoderResult<bool> {
let paloff = buf.get_offset(1);
let stride = buf.get_stride(0);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let frame_x = br.read_u16le()? as usize;
if self.is16bit {
let mut adata = abuf.get_abuf_i16().unwrap();
let off1 = adata.get_offset(1);
- let mut dst = adata.get_data_mut();
+ let mut dst = adata.get_data_mut().unwrap();
self.decode_16bit(&mut dst, off1, &mut br, nblocks, mask)?;
} else {
let mut adata = abuf.get_abuf_u8().unwrap();
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
let mut doff = 0;
let mut mask = mask;
let channels = self.chmap.num_channels();
let abuf = alloc_audio_buffer(self.ainfo, duration, self.chmap.clone())?;
let mut adata = abuf.get_abuf_f32().unwrap();
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
let mut start: usize = 0;
let channels = self.ainfo.get_channels() as usize;
let stride = buf.get_stride(planeno);
let cb = &self.cb;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
let table = &INDEO2_DELTA_TABLE[tableno];
let stride = buf.get_stride(planeno);
let cb = &self.cb;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
let table = &INDEO2_DELTA_TABLE[tableno];
let width = if planeno == 0 { self.width } else { self.width >> 2 };
let height = if planeno == 0 { self.height } else { self.height >> 2 };
let src = if self.fbuf { &self.buf1[0..] } else { &self.buf2[0..] };
- let mut dst = fbuf.get_data_mut();
+ let dst = fbuf.get_data_mut().unwrap();
for _ in 0..height {
for x in 0..width {
dst[doff + x] = src[soff + x] * 2;
let (w, h) = vb.get_dimensions(dplane);
let mut didx = vb.get_offset(dplane);
let dstride = vb.get_stride(dplane);
- let mut dst = vb.get_data_mut();
+ let dst = vb.get_data_mut().unwrap();
let src = &self.plane_buf[plane];
let mut sidx = 0;
let sstride = self.plane_stride[plane];
let (w, h) = vb.get_dimensions(dplane);
let dstride = vb.get_stride(dplane);
let off = vb.get_offset(dplane);
- let mut dst = vb.get_data_mut();
+ let dst = vb.get_data_mut().unwrap();
dec.recombine_plane(&frame.plane_buf[plane], frame.plane_stride[plane], &mut dst[off..], dstride, w, h);
}
}
let (mut off_y, mut off_u, mut off_v, mut off_a) = (buf.get_offset(0), buf.get_offset(1), buf.get_offset(2), buf.get_offset(3));
let (ooff_y, ooff_u, ooff_v, ooff_a) = (off_y, off_u, off_v, off_a);
let (width, height) = buf.get_dimensions(0);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let bw = (width + 31) >> 5;
let bheight = (height + 31) >> 5;
let mut adata = abuf.get_abuf_f32().unwrap();
let mut off0 = adata.get_offset(0);
let mut off1 = adata.get_offset(1);
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
let num_subframes = nsamples / self.duration / self.chmap.num_channels() / 2;
let stride = buf.get_stride(plane_no);
let mut off = buf.get_offset(plane_no);
let (width, height) = buf.get_dimensions(plane_no);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let bw = (width + 7) >> 3;
let bh = (height + 7) >> 3;
let stride = buf.get_stride(plane_no);
let mut off = buf.get_offset(plane_no);
let (width, height) = buf.get_dimensions(plane_no);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let bw = (width + 7) >> 3;
let bh = (height + 7) >> 3;
}
fn output_frame(&self, buf: &mut NAVideoBuffer<u8>) {
let stride = buf.get_stride(0);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let is_scaled = (self.flags & SMK_FLAG_SCALED) != 0;
let is_interlaced = (self.flags & SMK_FLAG_INTERLACED) != 0;
is_intra = self.decode_frame(&mut br)?;
self.output_frame(&mut buf);
let paloff = buf.get_offset(1);
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst = data.as_mut_slice();
let palout = &mut dst[paloff..][..PAL_SIZE];
palout.copy_from_slice(&src[0..PAL_SIZE]);
abuf = alloc_audio_buffer(self.ainfo, samples, self.chmap.clone())?;
let mut adata = abuf.get_abuf_i16().unwrap();
let offs: [usize; 2] = [0, adata.get_offset(1)];
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
for ch in 0..nch {
dst[offs[ch]] = pred[ch];
}
samples = unp_size / nch;
abuf = alloc_audio_buffer(self.ainfo, samples, self.chmap.clone())?;
let mut adata = abuf.get_abuf_u8().unwrap();
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
if stereo {
let mut trees: [SmackerTree8; 2] = [SmackerTree8::new(), SmackerTree8::new()];
trees[0].decode(&mut br)?;
for ch in 0..self.mode.get_channels() {
let off = abuf.get_offset(ch + self.start_ch);
let mut adata = abuf.get_abuf_f32().unwrap();
- let mut output = adata.get_data_mut();
+ let output = adata.get_data_mut().unwrap();
let dst = &mut output[off..];
dsp.imdct.imdct(&self.block[ch], &mut dsp.out);
let abuf = alloc_audio_buffer(self.ainfo, duration, self.chmap.clone())?;
let mut adata = abuf.get_abuf_i16().unwrap();
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
for (input, output) in pktbuf.chunks(FRAME_SIZE).zip(dst.chunks_mut(NBLOCKS * BLOCKSIZE)) {
let mut br = BitReader::new(input, input.len(), BitReaderMode::BE);
let abuf = alloc_audio_buffer(self.ainfo, duration, self.chmap.clone())?;
let mut adata = abuf.get_abuf_f32().unwrap();
- let mut dst = adata.get_data_mut();
+ let dst = adata.get_data_mut().unwrap();
for (input, output) in pktbuf.chunks(FRAME_SIZE).zip(dst.chunks_mut(NBLOCKS * BLOCKSIZE)) {
let mut br = BitReader::new(input, input.len(), BitReaderMode::LE);
let ch0 = abuf.get_offset(0) + self.sample_offset;
let ch1 = abuf.get_offset(1) + self.sample_offset;
let mut adata = abuf.get_abuf_i16().unwrap();
- let mut output = adata.get_data_mut();
+ let output = adata.get_data_mut().unwrap();
match dmode {
0 => {
for i in 0..length {
let csize = if comp == 0 { size } else { size >> 1 };
let dstride = buf.get_stride(comp);
let doffset = buf.get_offset(comp) + xoff + yoff * dstride;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
let sstride = avg_buf.get_stride(comp);
}
let stride = buf.get_stride(0);
let mut offset = buf.get_offset(0) + sstate.mb_x * 16 + sstate.mb_y * 16 * stride;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
if is_16 {
for comp in 1..3 {
let stride = buf.get_stride(comp);
let mut offset = buf.get_offset(comp) + sstate.mb_x * 8 + sstate.mb_y * 8 * stride;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
if is_16 {
let im8 = imode.get_pred8_type(sstate.has_top, sstate.has_left);
}
let stride = buf.get_stride(0);
let mut offset = buf.get_offset(0) + sstate.mb_x * 16 + sstate.mb_y * 16 * stride;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
for y in 0..4 {
for comp in 1..3 {
let stride = buf.get_stride(comp);
let mut offset = buf.get_offset(comp) + sstate.mb_x * 8 + sstate.mb_y * 8 * stride;
- let mut data = buf.get_data_mut();
+ let data = buf.get_data_mut().unwrap();
let framebuf: &mut [u8] = data.as_mut_slice();
for _ in 0..2 {
for x in 0..2 {
offs[comp] = frame.get_offset(comp) + start * stride[comp];
}
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
// vertical filter
let size: usize = if use16 { 16 } else { 8 };
let dstride = frame.get_stride(0);
let doffset = frame.get_offset(0) + (if !avg { x + y * dstride } else { 0 });
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
let (w_, h_) = prev_frame.get_dimensions(0);
let size: usize = if use8 { 8 } else { 4 };
let dstride = frame.get_stride(comp);
let doffset = frame.get_offset(comp) + (if !avg { x + y * dstride } else { 0 });
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
let (w_, h_) = prev_frame.get_dimensions(comp);
offs[comp] = frame.get_offset(comp) + start * stride[comp];
}
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
let mut mb_pos: usize = row * mb_w;
let size: usize = if use16 { 16 } else { 8 };
let dstride = frame.get_stride(0);
let doffset = frame.get_offset(0) + (if !avg { x + y * dstride } else { 0 });
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
let (w_, h_) = prev_frame.get_dimensions(0);
let size: usize = if use8 { 8 } else { 4 };
let dstride = frame.get_stride(comp);
let doffset = frame.get_offset(comp) + (if !avg { x + y * dstride } else { 0 });
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
let (w_, h_) = prev_frame.get_dimensions(comp);
if !split_i4x4 {
let dstride = buf.get_stride(0);
let off = xpos + ypos * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let dst = &mut data;
self.populate_ipred(hdr, dst, 0, dstride, 0, 0, size, true);
self.ipred.pred_angle(dst, off, dstride, size, itype as usize, true);
let dstride = buf.get_stride(comp);
let soff = buf.get_offset(comp);
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut 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.dsp.transform4x4(&mut self.y_coeffs[i * 16..][..16]);
let dstride = buf.get_stride(0);
let off = xpos + x * 4 + (ypos + y * 4) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs[i*16..][..16], 4);
}
self.dsp.transform4x4(&mut self.u_coeffs[i * 16..][..16]);
let dstride = buf.get_stride(1);
let off = buf.get_offset(1) + xoff + yoff * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs[i * 16..][..16], 4);
}
self.dsp.transform4x4(&mut self.v_coeffs[i * 16..][..16]);
let dstride = buf.get_stride(2);
let off = buf.get_offset(2) + xoff + yoff * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs[i * 16..][..16], 4);
}
if split_i4x4 {
let dstride = buf.get_stride(0);
let off = xpos + xoff + (ypos + yoff) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut 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;
let dstride = buf.get_stride(0);
let soff = buf.get_offset(0);
let off = soff + xpos + xoff + (ypos + yoff) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, blk, 4);
}
let dstride = buf.get_stride(1);
let soff = buf.get_offset(1);
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 4);
}
let dstride = buf.get_stride(2);
let soff = buf.get_offset(2);
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 4);
}
self.dsp.transform8x8(&mut self.y_coeffs);
let dstride = buf.get_stride(0);
let off = xpos + ypos * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs, 8);
}
let dstride = buf.get_stride(1);
let soff = buf.get_offset(1);
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 4);
}
let dstride = buf.get_stride(2);
let soff = buf.get_offset(2);
let off = soff + (xpos >> 1) + (ypos >> 1) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 4);
}
self.dsp.transform16x16(&mut self.y_coeffs);
let dstride = buf.get_stride(0);
let off = xpos + x * 16 + (ypos + y * 16) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.y_coeffs, 16);
}
let dstride = buf.get_stride(1);
let soff = buf.get_offset(1);
let off = soff + (xpos >> 1) + x * 8 + ((ypos >> 1) + y * 8) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.u_coeffs, 8);
}
let dstride = buf.get_stride(2);
let soff = buf.get_offset(2);
let off = soff + (xpos >> 1) + x * 8 + ((ypos >> 1) + y * 8) * dstride;
- let mut data = buf.get_data_mut();
+ let mut data = buf.get_data_mut().unwrap();
let mut dst = &mut data;
self.dsp.add_block(&mut dst, off, dstride, &self.v_coeffs, 8);
}
let sstride = prev_frame.get_stride(comp);
let doff = if comp == 0 { x + y * dstride } else { frame.get_offset(comp) + (x >> 1) + (y >> 1) * dstride };
let soff = prev_frame.get_offset(comp);
- let mut ddata = frame.get_data_mut();
+ let ddata = frame.get_data_mut().unwrap();
let dst: &mut [u8] = ddata.as_mut_slice();
let sdata = prev_frame.get_data();
let src: &[u8] = sdata.as_slice();
{ // luma
let dstride = frame.get_stride(0);
let doffset = frame.get_offset(0) + (if !avg { x + y * dstride } else { 0 });
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
let (w_, h_) = prev_frame.get_dimensions(0);
for comp in 1..3 { // chroma
let dstride = frame.get_stride(comp);
let doffset = frame.get_offset(comp) + (if !avg { (x >> 1) + (y >> 1) * dstride } else { 0 });
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
if check_pos(x >> 1, y >> 1, cw, ch, fw, fh, dx, dy, 0, 1, 0, 1) {
let sstride = prev_frame.get_stride(comp);
{
let stride = frame.get_stride(0);
let offset = frame.get_offset(0) + xpos + ypos * stride;
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
filter_luma_edge(dst, offset, 1, stride, mode_l, mode_r, lim1, lim2);
}
for comp in 1..2 {
let stride = frame.get_stride(comp);
let offset = frame.get_offset(comp) + (xpos >> 1) + (ypos >> 1) * stride;
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
filter_chroma_edge(dst, offset, 1, stride, mode_l, mode_r, lim1, lim2);
}
{
let stride = frame.get_stride(0);
let offset = frame.get_offset(0) + xpos + ypos * stride;
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
filter_luma_edge(dst, offset, stride, 1, mode_t, mode_d, lim1, lim2);
}
for comp in 1..2 {
let stride = frame.get_stride(comp);
let offset = frame.get_offset(comp) + (xpos >> 1) + (ypos >> 1) * stride;
- let mut data = frame.get_data_mut();
+ let data = frame.get_data_mut().unwrap();
let dst: &mut [u8] = data.as_mut_slice();
filter_chroma_edge(dst, offset, stride, 1, mode_t, mode_d, lim1, lim2);
}