From 2422d9699cd56cbb86ac32b3e8dd026e20a89db5 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Mon, 29 Apr 2019 13:02:12 +0200 Subject: [PATCH] switch NACodecInfo to Arc --- nihav-commonfmt/src/codecs/aac.rs | 6 ++-- nihav-commonfmt/src/codecs/atrac3.rs | 6 ++-- nihav-commonfmt/src/codecs/clearvideo.rs | 10 +++---- nihav-commonfmt/src/codecs/pcm.rs | 4 +-- nihav-commonfmt/src/codecs/sipro.rs | 6 ++-- nihav-commonfmt/src/codecs/ts102366.rs | 6 ++-- nihav-core/src/codecs/mod.rs | 3 +- nihav-core/src/frame.rs | 38 +++++++++++++----------- nihav-duck/src/codecs/dkadpcm.rs | 2 +- nihav-duck/src/codecs/truemotion1.rs | 6 ++-- nihav-duck/src/codecs/truemotion2.rs | 6 ++-- nihav-duck/src/codecs/truemotion2x.rs | 6 ++-- nihav-duck/src/codecs/truemotionrt.rs | 6 ++-- nihav-game/src/codecs/bmv.rs | 11 ++++--- nihav-game/src/codecs/bmv3.rs | 11 ++++--- nihav-game/src/codecs/gremlinvideo.rs | 13 ++++---- nihav-game/src/codecs/vmd.rs | 10 +++---- nihav-indeo/src/codecs/imc.rs | 6 ++-- nihav-indeo/src/codecs/indeo2.rs | 10 +++---- nihav-indeo/src/codecs/indeo3.rs | 10 +++---- nihav-indeo/src/codecs/indeo4.rs | 8 ++--- nihav-indeo/src/codecs/indeo5.rs | 8 ++--- nihav-indeo/src/codecs/intel263.rs | 10 +++---- nihav-rad/src/codecs/bink2.rs | 6 ++-- nihav-rad/src/codecs/binkaud.rs | 2 +- nihav-rad/src/codecs/binkvid.rs | 6 ++-- nihav-rad/src/codecs/smacker.rs | 12 ++++---- nihav-realmedia/src/codecs/cook.rs | 6 ++-- nihav-realmedia/src/codecs/ra144.rs | 6 ++-- nihav-realmedia/src/codecs/ra288.rs | 6 ++-- nihav-realmedia/src/codecs/ralf.rs | 6 ++-- nihav-realmedia/src/codecs/rv10.rs | 10 +++---- nihav-realmedia/src/codecs/rv20.rs | 10 +++---- nihav-realmedia/src/codecs/rv30.rs | 10 +++---- nihav-realmedia/src/codecs/rv40.rs | 10 +++---- nihav-realmedia/src/codecs/rv60.rs | 10 +++---- 36 files changed, 128 insertions(+), 174 deletions(-) diff --git a/nihav-commonfmt/src/codecs/aac.rs b/nihav-commonfmt/src/codecs/aac.rs index 8232e07..412bc9c 100644 --- a/nihav-commonfmt/src/codecs/aac.rs +++ b/nihav-commonfmt/src/codecs/aac.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -1107,7 +1105,7 @@ impl DSP { } struct AACDecoder { - info: Rc, + info: NACodecInfoRef, chmap: NAChannelMap, m4ainfo: M4AInfo, pairs: Vec, @@ -1205,7 +1203,7 @@ impl AACDecoder { } impl NADecoder for AACDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(_) = info.get_properties() { let edata = info.get_extradata().unwrap(); validate!(edata.len() >= 2); diff --git a/nihav-commonfmt/src/codecs/atrac3.rs b/nihav-commonfmt/src/codecs/atrac3.rs index 7b543bf..42fbe8a 100644 --- a/nihav-commonfmt/src/codecs/atrac3.rs +++ b/nihav-commonfmt/src/codecs/atrac3.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -387,7 +385,7 @@ impl DSP { } struct Atrac3Decoder { - info: Rc, + info: NACodecInfoRef, channels: usize, chmap: NAChannelMap, samples: usize, @@ -555,7 +553,7 @@ fn interp(a: f32, b: f32, pos: usize) -> f32 { } impl NADecoder for Atrac3Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.info = info.clone(); let edata = info.get_extradata().unwrap(); diff --git a/nihav-commonfmt/src/codecs/clearvideo.rs b/nihav-commonfmt/src/codecs/clearvideo.rs index 3c3ae9a..d485bdb 100644 --- a/nihav-commonfmt/src/codecs/clearvideo.rs +++ b/nihav-commonfmt/src/codecs/clearvideo.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::io::byteio::{ByteReader,MemoryReader}; use nihav_core::io::bitreader::*; use nihav_core::io::codebook::*; @@ -430,7 +428,7 @@ fn extend_edges(buf: &mut NAVideoBuffer, tile_size: usize) { #[allow(dead_code)] struct ClearVideoDecoder { - info: Rc, + info: NACodecInfoRef, dc_cb: Codebook, ac_cb: Codebook, frmmgr: HAMShuffler, @@ -530,7 +528,7 @@ fn decode_tile_info(br: &mut BitReader, lc: &[LevelCodes], level: usize) -> Deco impl ClearVideoDecoder { fn new(is_rm: bool) -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); + let dummy_info = NACodecInfo::new_dummy(); let mut coderead = CLVDCCodeReader{}; let dc_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let mut coderead = CLVACCodeReader{}; @@ -683,7 +681,7 @@ impl ClearVideoDecoder { } impl NADecoder for ClearVideoDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if info.get_extradata().is_none() { return Err(DecoderError::InvalidData); } if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); @@ -691,7 +689,7 @@ impl NADecoder for ClearVideoDecoder { let f = vinfo.is_flipped(); let fmt = formats::YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, f, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.frmmgr.clear(); let edata = info.get_extradata().unwrap(); //todo detect simply by extradata contents? diff --git a/nihav-commonfmt/src/codecs/pcm.rs b/nihav-commonfmt/src/codecs/pcm.rs index edc8124..132d4c3 100644 --- a/nihav-commonfmt/src/codecs/pcm.rs +++ b/nihav-commonfmt/src/codecs/pcm.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::codecs::*; @@ -35,7 +33,7 @@ fn get_duration(ainfo: &NAAudioInfo, duration: Option, data_size: usize) -> } impl NADecoder for PCMDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.chmap = get_default_chmap(ainfo.get_channels()); if self.chmap.num_channels() == 0 { return Err(DecoderError::InvalidData); } diff --git a/nihav-commonfmt/src/codecs/sipro.rs b/nihav-commonfmt/src/codecs/sipro.rs index 1b8d701..05e6816 100644 --- a/nihav-commonfmt/src/codecs/sipro.rs +++ b/nihav-commonfmt/src/codecs/sipro.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -28,7 +26,7 @@ const EXCITATION_OFFSET: usize = 281 + 10 + 1; struct SiproDecoder { chmap: NAChannelMap, ainfo: NAAudioInfo, - info: Rc, + info: NACodecInfoRef, mode: &'static SiproModeInfo, mode_type: SiproMode, @@ -640,7 +638,7 @@ fn synth_filter(dst: &mut [f32], doff: usize, filt: &[f32], src: &[f32], len: us const CHMAP_MONO: [NAChannelType; 1] = [NAChannelType::C]; impl NADecoder for SiproDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { let mut found = false; for i in 0..SIPRO_MODES.len() { diff --git a/nihav-commonfmt/src/codecs/ts102366.rs b/nihav-commonfmt/src/codecs/ts102366.rs index 5d1d66c..f17b431 100644 --- a/nihav-commonfmt/src/codecs/ts102366.rs +++ b/nihav-commonfmt/src/codecs/ts102366.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -116,7 +114,7 @@ fn do_imdct_core(fft: &mut FFT, xsc: &[FFTComplex; BLOCK_LEN/2], size: usize, il } struct AudioDecoder { - info: Rc, + info: NACodecInfoRef, ablk: AudioBlock, imdct512: IMDCTContext, imdct256: IMDCTContext, @@ -1159,7 +1157,7 @@ impl AudioBlock { } impl NADecoder for AudioDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(_) = info.get_properties() { self.info = info.clone(); Ok(()) diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index bf4fbd4..692269e 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -2,7 +2,6 @@ use std::fmt; use std::ops::{Add, AddAssign, Sub, SubAssign}; pub use crate::frame::*; -pub use std::rc::Rc; use std::mem; use crate::io::byteio::ByteIOError; use crate::io::bitreader::BitReaderError; @@ -232,7 +231,7 @@ impl fmt::Display for MV { pub trait NADecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()>; + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()>; fn decode(&mut self, pkt: &NAPacket) -> DecoderResult; } diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 45e05ca..bc3216b 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use std::fmt; pub use std::rc::Rc; pub use std::cell::*; +use std::sync::Arc; pub use crate::formats::*; pub use crate::refs::*; @@ -531,22 +532,25 @@ impl NABufferPool { pub struct NACodecInfo { name: &'static str, properties: NACodecTypeInfo, - extradata: Option>>, + extradata: Option>>, } +pub type NACodecInfoRef = Arc; + impl NACodecInfo { pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option>) -> Self { let extradata = match edata { None => None, - Some(vec) => Some(Rc::new(vec)), + Some(vec) => Some(Arc::new(vec)), }; NACodecInfo { name: name, properties: p, extradata: extradata } } - pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option>>) -> Self { + pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option>>) -> Self { NACodecInfo { name: name, properties: p, extradata: edata } } + pub fn into_ref(self) -> NACodecInfoRef { Arc::new(self) } pub fn get_properties(&self) -> NACodecTypeInfo { self.properties } - pub fn get_extradata(&self) -> Option>> { + pub fn get_extradata(&self) -> Option>> { if let Some(ref vec) = self.extradata { return Some(vec.clone()); } None } @@ -559,11 +563,11 @@ impl NACodecInfo { if let NACodecTypeInfo::Audio(_) = self.properties { return true; } false } - pub fn new_dummy() -> Rc { - Rc::new(DUMMY_CODEC_INFO) + pub fn new_dummy() -> Arc { + Arc::new(DUMMY_CODEC_INFO) } - pub fn replace_info(&self, p: NACodecTypeInfo) -> Rc { - Rc::new(NACodecInfo { name: self.name, properties: p, extradata: self.extradata.clone() }) + pub fn replace_info(&self, p: NACodecTypeInfo) -> Arc { + Arc::new(NACodecInfo { name: self.name, properties: p, extradata: self.extradata.clone() }) } } @@ -592,7 +596,7 @@ pub enum NAValue { Int(i32), Long(i64), String(String), - Data(Rc>), + Data(Arc>), } #[derive(Debug,Clone,Copy,PartialEq)] @@ -643,7 +647,7 @@ impl NATimeInfo { pub struct NAFrame { ts: NATimeInfo, buffer: NABufferType, - info: Rc, + info: NACodecInfoRef, ftype: FrameType, key: bool, options: HashMap, @@ -664,12 +668,12 @@ impl NAFrame { pub fn new(ts: NATimeInfo, ftype: FrameType, keyframe: bool, - info: Rc, + info: NACodecInfoRef, options: HashMap, buffer: NABufferType) -> Self { NAFrame { ts: ts, buffer: buffer, info: info, ftype: ftype, key: keyframe, options: options } } - pub fn get_info(&self) -> Rc { self.info.clone() } + pub fn get_info(&self) -> NACodecInfoRef { self.info.clone() } pub fn get_frame_type(&self) -> FrameType { self.ftype } pub fn is_keyframe(&self) -> bool { self.key } pub fn set_frame_type(&mut self, ftype: FrameType) { self.ftype = ftype; } @@ -730,7 +734,7 @@ pub struct NAStream { media_type: StreamType, id: u32, num: usize, - info: Rc, + info: NACodecInfoRef, tb_num: u32, tb_den: u32, } @@ -753,12 +757,12 @@ pub fn reduce_timebase(tb_num: u32, tb_den: u32) -> (u32, u32) { impl NAStream { pub fn new(mt: StreamType, id: u32, info: NACodecInfo, tb_num: u32, tb_den: u32) -> Self { let (n, d) = reduce_timebase(tb_num, tb_den); - NAStream { media_type: mt, id: id, num: 0, info: Rc::new(info), tb_num: n, tb_den: d } + NAStream { media_type: mt, id: id, num: 0, info: info.into_ref(), tb_num: n, tb_den: d } } pub fn get_id(&self) -> u32 { self.id } pub fn get_num(&self) -> usize { self.num } pub fn set_num(&mut self, num: usize) { self.num = num; } - pub fn get_info(&self) -> Rc { self.info.clone() } + pub fn get_info(&self) -> NACodecInfoRef { self.info.clone() } pub fn get_timebase(&self) -> (u32, u32) { (self.tb_num, self.tb_den) } pub fn set_timebase(&mut self, tb_num: u32, tb_den: u32) { let (n, d) = reduce_timebase(tb_num, tb_den); @@ -814,12 +818,12 @@ impl fmt::Display for NAPacket { } pub trait FrameFromPacket { - fn new_from_pkt(pkt: &NAPacket, info: Rc, buf: NABufferType) -> NAFrame; + fn new_from_pkt(pkt: &NAPacket, info: NACodecInfoRef, buf: NABufferType) -> NAFrame; fn fill_timestamps(&mut self, pkt: &NAPacket); } impl FrameFromPacket for NAFrame { - fn new_from_pkt(pkt: &NAPacket, info: Rc, buf: NABufferType) -> NAFrame { + fn new_from_pkt(pkt: &NAPacket, info: NACodecInfoRef, buf: NABufferType) -> NAFrame { NAFrame::new(pkt.ts, FrameType::Other, pkt.keyframe, info, HashMap::new(), buf) } fn fill_timestamps(&mut self, pkt: &NAPacket) { diff --git a/nihav-duck/src/codecs/dkadpcm.rs b/nihav-duck/src/codecs/dkadpcm.rs index 0410957..0104b30 100644 --- a/nihav-duck/src/codecs/dkadpcm.rs +++ b/nihav-duck/src/codecs/dkadpcm.rs @@ -51,7 +51,7 @@ impl DuckADPCMDecoder { } impl NADecoder for DuckADPCMDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { validate!(ainfo.get_block_len() > 16); self.block_len = ainfo.get_block_len(); diff --git a/nihav-duck/src/codecs/truemotion1.rs b/nihav-duck/src/codecs/truemotion1.rs index a156705..2c8e5d2 100644 --- a/nihav-duck/src/codecs/truemotion1.rs +++ b/nihav-duck/src/codecs/truemotion1.rs @@ -168,7 +168,7 @@ impl Default for FrameBuf { #[derive(Default)] struct TM1Decoder { - info: Rc, + info: NACodecInfoRef, last_delta_set: usize, last_table_idx: usize, delta_tables: DeltaTables, @@ -515,10 +515,10 @@ impl TM1Decoder { } impl NADecoder for TM1Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, YUV410_FORMAT)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-duck/src/codecs/truemotion2.rs b/nihav-duck/src/codecs/truemotion2.rs index 54f0d30..e822545 100644 --- a/nihav-duck/src/codecs/truemotion2.rs +++ b/nihav-duck/src/codecs/truemotion2.rs @@ -331,7 +331,7 @@ impl TM2Frame { #[derive(Default)] struct TM2Decoder { - info: Rc, + info: NACodecInfoRef, streams: [TM2Stream; TM2StreamType::Num as usize], width: usize, height: usize, @@ -546,14 +546,14 @@ impl TM2Decoder { } impl NADecoder for TM2Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, YUV410_FORMAT)); self.width = vinfo.get_width(); self.height = vinfo.get_height(); self.cur_frame = TM2Frame::alloc(self.width, self.height); self.prev_frame = TM2Frame::alloc(self.width, self.height); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-duck/src/codecs/truemotion2x.rs b/nihav-duck/src/codecs/truemotion2x.rs index 6eb3559..fce5fb3 100644 --- a/nihav-duck/src/codecs/truemotion2x.rs +++ b/nihav-duck/src/codecs/truemotion2x.rs @@ -161,7 +161,7 @@ impl Frame { #[derive(Default)] struct TM2XDecoder { - info: Rc, + info: NACodecInfoRef, width: usize, height: usize, dec_buf: Vec, @@ -556,7 +556,7 @@ impl TM2XDecoder { } impl NADecoder for TM2XDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let fmt = NAPixelFormaton::new(ColorModel::YUV(YUVSubmodel::YUVJ), Some(NAPixelChromaton::new(0, 0, false, 8, 0, 0, 1)), @@ -568,7 +568,7 @@ impl NADecoder for TM2XDecoder { self.height = vinfo.get_height(); self.cur_frame.resize(self.width, self.height); self.ref_frame.resize(self.width, self.height); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-duck/src/codecs/truemotionrt.rs b/nihav-duck/src/codecs/truemotionrt.rs index df17047..12548ef 100644 --- a/nihav-duck/src/codecs/truemotionrt.rs +++ b/nihav-duck/src/codecs/truemotionrt.rs @@ -3,7 +3,7 @@ use nihav_core::io::bitreader::*; #[derive(Default)] struct TMRTDecoder { - info: Rc, + info: NACodecInfoRef, } const TMRT_DELTA_TAB: [&[i16]; 3] = [ @@ -35,10 +35,10 @@ impl TMRTDecoder { } impl NADecoder for TMRTDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, YUV410_FORMAT)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-game/src/codecs/bmv.rs b/nihav-game/src/codecs/bmv.rs index 46e5f65..79b8745 100644 --- a/nihav-game/src/codecs/bmv.rs +++ b/nihav-game/src/codecs/bmv.rs @@ -101,16 +101,15 @@ impl<'a> BMVWriter<'a> { } struct BMVVideoDecoder { - info: Rc, + info: NACodecInfoRef, pal: [u8; 768], frame: [u8; FRAME_W * FRAME_H], } impl BMVVideoDecoder { fn new() -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); Self { - info: dummy_info, pal: [0; 768], frame: [0; FRAME_W * FRAME_H], + info: NACodecInfoRef::default(), pal: [0; 768], frame: [0; FRAME_W * FRAME_H], } } fn decode_frame(&mut self, src: &[u8], bufinfo: &mut NABufferType, line: i16) -> DecoderResult<()> { @@ -170,7 +169,7 @@ impl BMVVideoDecoder { } impl NADecoder for BMVVideoDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(_vinfo) = info.get_properties() { let fmt = NAPixelFormaton::new(ColorModel::RGB(RGBSubmodel::RGB), Some(NAPixelChromaton::new(0, 0, true, 8, 0, 0, 3)), @@ -179,7 +178,7 @@ impl NADecoder for BMVVideoDecoder { None, None, FORMATON_FLAG_PALETTE, 3); let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(FRAME_W, FRAME_H, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { @@ -258,7 +257,7 @@ fn scale_sample(samp: u8, scale: i32) -> i16 { } impl NADecoder for BMVAudioDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), ainfo.get_channels(), formats::SND_S16P_FORMAT, 32); self.chmap = NAChannelMap::from_str("L,R").unwrap(); diff --git a/nihav-game/src/codecs/bmv3.rs b/nihav-game/src/codecs/bmv3.rs index 099f070..687ca23 100644 --- a/nihav-game/src/codecs/bmv3.rs +++ b/nihav-game/src/codecs/bmv3.rs @@ -69,7 +69,7 @@ impl NibbleReader { } struct BMV3VideoDecoder { - info: Rc, + info: NACodecInfoRef, stride: usize, height: usize, frame: Vec, @@ -85,7 +85,6 @@ struct BMV3VideoDecoder { impl BMV3VideoDecoder { fn new() -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); let mut frame1 = Vec::with_capacity(BMV_MAX_SIZE); frame1.resize(BMV_MAX_SIZE, 0); let mut frame2 = Vec::with_capacity(BMV_MAX_SIZE); @@ -103,7 +102,7 @@ impl BMV3VideoDecoder { } Self { - info: dummy_info, + info: NACodecInfoRef::default(), stride: 0, height: 0, frame: frame1, @@ -442,10 +441,10 @@ impl BMV3VideoDecoder { } impl NADecoder for BMV3VideoDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, RGB565_FORMAT)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.stride = vinfo.get_width(); self.height = vinfo.get_height(); @@ -553,7 +552,7 @@ fn decode_block(mode: u8, src: &[u8], dst: &mut [i16], mut pred: i16) -> i16 { } impl NADecoder for BMV3AudioDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), ainfo.get_channels(), formats::SND_S16P_FORMAT, 32); self.chmap = NAChannelMap::from_str("L,R").unwrap(); diff --git a/nihav-game/src/codecs/gremlinvideo.rs b/nihav-game/src/codecs/gremlinvideo.rs index 9dd67ca..cf7f7b1 100644 --- a/nihav-game/src/codecs/gremlinvideo.rs +++ b/nihav-game/src/codecs/gremlinvideo.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::frame::*; use nihav_core::formats; use nihav_core::formats::{NAChannelType, NAChannelMap}; @@ -7,7 +5,7 @@ use nihav_core::codecs::*; use nihav_core::io::byteio::*; struct GremlinVideoDecoder { - info: Rc, + info: NACodecInfoRef, pal: [u8; 768], frame: Vec, scale_v: bool, @@ -61,9 +59,8 @@ impl Bits32 { impl GremlinVideoDecoder { fn new() -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); GremlinVideoDecoder { - info: dummy_info, pal: [0; 768], frame: Vec::new(), + info: NACodecInfoRef::default(), pal: [0; 768], frame: Vec::new(), scale_v: false, scale_h: false } } @@ -374,14 +371,14 @@ impl GremlinVideoDecoder { } impl NADecoder for GremlinVideoDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); if !vinfo.get_format().is_paletted() { return Err(DecoderError::NotImplemented); } let fmt = formats::PAL8_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.frame.resize(PREAMBLE_SIZE + w * h, 0); for i in 0..2 { @@ -513,7 +510,7 @@ fn get_default_chmap(nch: u8) -> NAChannelMap { } impl NADecoder for GremlinAudioDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), ainfo.get_channels(), formats::SND_S16P_FORMAT, ainfo.get_block_len()); self.chmap = get_default_chmap(ainfo.get_channels()); diff --git a/nihav-game/src/codecs/vmd.rs b/nihav-game/src/codecs/vmd.rs index bbe5218..dc831c4 100644 --- a/nihav-game/src/codecs/vmd.rs +++ b/nihav-game/src/codecs/vmd.rs @@ -147,7 +147,7 @@ fn decode_frame_data(br: &mut ByteReader, dst: &mut [u8], mut dpos: usize, strid } struct VMDVideoDecoder { - info: Rc, + info: NACodecInfoRef, pal: [u8; 768], buf: Vec, width: usize, @@ -158,7 +158,7 @@ struct VMDVideoDecoder { impl VMDVideoDecoder { fn new() -> Self { Self { - info: Rc::new(NACodecInfo::default()), + info: NACodecInfoRef::default(), pal: [0; 768], buf: Vec::new(), width: 0, @@ -215,12 +215,12 @@ impl VMDVideoDecoder { } impl NADecoder for VMDVideoDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { self.width = vinfo.get_width(); self.height = vinfo.get_height(); let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(self.width, self.height, false, PAL8_FORMAT)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); validate!(info.get_extradata().is_some()); if let Some(ref edata) = info.get_extradata() { @@ -351,7 +351,7 @@ impl VMDAudioDecoder { } impl NADecoder for VMDAudioDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { let fmt; if ainfo.get_format().get_bits() == 8 { diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index 2d65a7c..ceac0d1 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -1,8 +1,6 @@ use std::mem; use std::ptr; use std::f32::consts; -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; @@ -323,7 +321,7 @@ struct IMCDecoder { chmap: NAChannelMap, ainfo: NAAudioInfo, - info: Rc, + info: NACodecInfoRef, codes: [[Codebook; 4]; 4], ch_data: [IMCChannel; 2], @@ -867,7 +865,7 @@ const CHMAP_MONO: [NAChannelType; 1] = [NAChannelType::C]; const CHMAP_STEREO: [NAChannelType; 2] = [NAChannelType::L, NAChannelType::R]; impl NADecoder for IMCDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.chmap = NAChannelMap::new(); match ainfo.get_channels() { diff --git a/nihav-indeo/src/codecs/indeo2.rs b/nihav-indeo/src/codecs/indeo2.rs index c3a8a47..5ea8b3f 100644 --- a/nihav-indeo/src/codecs/indeo2.rs +++ b/nihav-indeo/src/codecs/indeo2.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::io::bitreader::*; use nihav_core::io::codebook::*; use nihav_core::formats; @@ -186,14 +184,14 @@ impl CodebookDescReader for IR2CodeReader { } struct Indeo2Decoder { - info: Rc, + info: NACodecInfoRef, cb: Codebook, frmmgr: HAMShuffler, } impl Indeo2Decoder { fn new() -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); + let dummy_info = NACodecInfo::new_dummy(); let mut coderead = IR2CodeReader{}; let cb = Codebook::new(&mut coderead, CodebookMode::LSB).unwrap(); Indeo2Decoder { info: dummy_info, cb: cb, frmmgr: HAMShuffler::new() } @@ -309,14 +307,14 @@ impl Indeo2Decoder { const IR2_START: usize = 48; impl NADecoder for Indeo2Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); let f = vinfo.is_flipped(); let fmt = formats::YUV410_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, f, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.frmmgr.clear(); Ok(()) } else { diff --git a/nihav-indeo/src/codecs/indeo3.rs b/nihav-indeo/src/codecs/indeo3.rs index a99db74..ebf941c 100644 --- a/nihav-indeo/src/codecs/indeo3.rs +++ b/nihav-indeo/src/codecs/indeo3.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats; use nihav_core::codecs::*; use nihav_core::io::byteio::*; @@ -254,7 +252,7 @@ fn fill_block8x8(bufs: &mut Buffers, doff: usize, stride: usize, h: usize, topli } struct Indeo3Decoder { - info: Rc, + info: NACodecInfoRef, bpos: u8, bbuf: u8, width: u16, @@ -330,7 +328,7 @@ const SKIP_OR_TREE: u8 = 2; impl Indeo3Decoder { fn new() -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); + let dummy_info = NACodecInfo::new_dummy(); Indeo3Decoder { info: dummy_info, bpos: 0, bbuf: 0, width: 0, height: 0, mvs: Vec::new(), altquant: [0; 16], vq_offset: 0, bufs: Buffers::new() } @@ -690,13 +688,13 @@ const FLAG_KEYFRAME: u16 = 1 << 2; const FLAG_NONREF: u16 = 1 << 8; impl NADecoder for Indeo3Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); let fmt = formats::YUV410_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.bufs.reset(); Ok(()) } else { diff --git a/nihav-indeo/src/codecs/indeo4.rs b/nihav-indeo/src/codecs/indeo4.rs index 6311dc9..07f6d67 100644 --- a/nihav-indeo/src/codecs/indeo4.rs +++ b/nihav-indeo/src/codecs/indeo4.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::{Ref, RefCell}; use nihav_core::io::bitreader::*; use nihav_core::formats; use nihav_core::frame::*; @@ -419,7 +417,7 @@ impl IndeoXParser for Indeo4Parser { } struct Indeo4Decoder { - info: Rc, + info: NACodecInfoRef, dec: IVIDecoder, } @@ -433,14 +431,14 @@ impl Indeo4Decoder { } impl NADecoder for Indeo4Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); let f = vinfo.is_flipped(); let fmt = formats::YUV410_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, f, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-indeo/src/codecs/indeo5.rs b/nihav-indeo/src/codecs/indeo5.rs index 98bd340..1f77081 100644 --- a/nihav-indeo/src/codecs/indeo5.rs +++ b/nihav-indeo/src/codecs/indeo5.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::{Ref, RefCell}; use nihav_core::io::bitreader::*; use nihav_core::formats; use nihav_core::frame::*; @@ -493,7 +491,7 @@ impl IndeoXParser for Indeo5Parser { } struct Indeo5Decoder { - info: Rc, + info: NACodecInfoRef, dec: IVIDecoder, ip: Indeo5Parser, } @@ -509,14 +507,14 @@ impl Indeo5Decoder { } impl NADecoder for Indeo5Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); let f = vinfo.is_flipped(); let fmt = formats::YUV410_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, f, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-indeo/src/codecs/intel263.rs b/nihav-indeo/src/codecs/intel263.rs index d84aff5..3b95c5f 100644 --- a/nihav-indeo/src/codecs/intel263.rs +++ b/nihav-indeo/src/codecs/intel263.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::io::bitreader::*; use nihav_core::io::codebook::*; use nihav_core::formats; @@ -21,7 +19,7 @@ struct Tables { } struct Intel263Decoder { - info: Rc, + info: NACodecInfoRef, dec: H263BaseDecoder, tables: Tables, bdsp: H263BlockDSP, @@ -357,7 +355,7 @@ impl Intel263Decoder { }; Intel263Decoder{ - info: Rc::new(DUMMY_CODEC_INFO), + info: NACodecInfo::new_dummy(), dec: H263BaseDecoder::new(true), tables: tables, bdsp: H263BlockDSP::new(), @@ -366,13 +364,13 @@ impl Intel263Decoder { } impl NADecoder for Intel263Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); let fmt = formats::YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-rad/src/codecs/bink2.rs b/nihav-rad/src/codecs/bink2.rs index 719608d..60d42a4 100644 --- a/nihav-rad/src/codecs/bink2.rs +++ b/nihav-rad/src/codecs/bink2.rs @@ -996,7 +996,7 @@ impl Default for Bink2Codes { #[derive(Default)] struct Bink2Decoder { - info: Rc, + info: NACodecInfoRef, ips: IPShuffler, version: u32, @@ -1858,7 +1858,7 @@ fn decode_acs_4blocks_old(br: &mut BitReader, codes: &Bink2Codes, dst: &mut [[f3 const KB2H_NUM_SLICES: [usize; 4] = [ 2, 3, 4, 8 ]; impl NADecoder for Bink2Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); @@ -1907,7 +1907,7 @@ impl NADecoder for Bink2Decoder { if self.has_alpha { FORMATON_FLAG_ALPHA } else { 0 }, if self.has_alpha { 4 } else { 3 }); let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { diff --git a/nihav-rad/src/codecs/binkaud.rs b/nihav-rad/src/codecs/binkaud.rs index c38f6d4..182c6c9 100644 --- a/nihav-rad/src/codecs/binkaud.rs +++ b/nihav-rad/src/codecs/binkaud.rs @@ -178,7 +178,7 @@ const CRITICAL_FREQS: [usize; MAX_BANDS] = [ const RUN_TAB: [usize; 16] = [ 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64 ]; impl NADecoder for BinkAudioDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { let srate = ainfo.get_sample_rate(); let channels = ainfo.get_channels(); diff --git a/nihav-rad/src/codecs/binkvid.rs b/nihav-rad/src/codecs/binkvid.rs index dc9a469..2f95ed6 100644 --- a/nihav-rad/src/codecs/binkvid.rs +++ b/nihav-rad/src/codecs/binkvid.rs @@ -474,7 +474,7 @@ impl Default for QuantMats { #[derive(Default)] struct BinkDecoder { - info: Rc, + info: NACodecInfoRef, ips: IPShuffler, hams: HAMShuffler, @@ -1157,7 +1157,7 @@ const BINK_FLAG_ALPHA: u32 = 0x00100000; const BINK_FLAG_GRAY: u32 = 0x00020000; impl NADecoder for BinkDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); @@ -1192,7 +1192,7 @@ impl NADecoder for BinkDecoder { None, None, None, None, 0, 1); } let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); //self.init_bundle_lengths(w.max(8), (w + 7) >> 3); self.init_bundle_bufs((w + 7) >> 3, (h + 7) >> 3); diff --git a/nihav-rad/src/codecs/smacker.rs b/nihav-rad/src/codecs/smacker.rs index bbf4846..bc27ab0 100644 --- a/nihav-rad/src/codecs/smacker.rs +++ b/nihav-rad/src/codecs/smacker.rs @@ -210,7 +210,7 @@ const SMK_BLOCK_RUNS: [usize; 64] = [ ]; struct SmackerVideoDecoder { - info: Rc, + info: NACodecInfoRef, mmap_tree: SmackerTree16, mclr_tree: SmackerTree16, full_tree: SmackerTree16, @@ -227,9 +227,8 @@ struct SmackerVideoDecoder { impl SmackerVideoDecoder { fn new() -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); Self { - info: dummy_info, + info: NACodecInfoRef::default(), mmap_tree: SmackerTree16::new(), mclr_tree: SmackerTree16::new(), full_tree: SmackerTree16::new(), @@ -388,7 +387,7 @@ impl SmackerVideoDecoder { } impl NADecoder for SmackerVideoDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); @@ -428,8 +427,7 @@ impl NADecoder for SmackerVideoDecoder { out_h <<= 1; } let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, out_h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); - + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); Ok(()) } else { @@ -494,7 +492,7 @@ impl SmackerAudioDecoder { } impl NADecoder for SmackerAudioDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.bits = ainfo.get_format().get_bits(); let fmt = if self.bits == 8 { SND_U8_FORMAT } else { SND_S16P_FORMAT }; diff --git a/nihav-realmedia/src/codecs/cook.rs b/nihav-realmedia/src/codecs/cook.rs index 6d7877b..6303724 100644 --- a/nihav-realmedia/src/codecs/cook.rs +++ b/nihav-realmedia/src/codecs/cook.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -523,7 +521,7 @@ impl RND { } struct CookDecoder { - info: Rc, + info: NACodecInfoRef, chmap: NAChannelMap, src: [u8; 65536], num_pairs: usize, @@ -553,7 +551,7 @@ impl CookDecoder { } impl NADecoder for CookDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { let edata = info.get_extradata().unwrap(); validate!(edata.len() >= 4); diff --git a/nihav-realmedia/src/codecs/ra144.rs b/nihav-realmedia/src/codecs/ra144.rs index 19cf38b..38d76c3 100644 --- a/nihav-realmedia/src/codecs/ra144.rs +++ b/nihav-realmedia/src/codecs/ra144.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -14,7 +12,7 @@ const FRAME_SIZE: usize = 20; struct RA144Decoder { chmap: NAChannelMap, ainfo: NAAudioInfo, - info: Rc, + info: NACodecInfoRef, old_energy: u16, lpc_data: [[i32; LPC_ORDER]; 2], @@ -244,7 +242,7 @@ fn clip_out(sample: i16) -> i16 { } impl NADecoder for RA144Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.chmap.add_channels(&CHMAP_MONO); self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), diff --git a/nihav-realmedia/src/codecs/ra288.rs b/nihav-realmedia/src/codecs/ra288.rs index 8538f85..142cf2a 100644 --- a/nihav-realmedia/src/codecs/ra288.rs +++ b/nihav-realmedia/src/codecs/ra288.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -17,7 +15,7 @@ const GAIN_START: usize = 28; struct RA288Decoder { chmap: NAChannelMap, ainfo: NAAudioInfo, - info: Rc, + info: NACodecInfoRef, speech_lpc: [f32; SP_LPC_ORDER], speech_hist: [f32; 111], @@ -153,7 +151,7 @@ impl RA288Decoder { } impl NADecoder for RA288Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.chmap.add_channels(&CHMAP_MONO); self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), diff --git a/nihav-realmedia/src/codecs/ralf.rs b/nihav-realmedia/src/codecs/ralf.rs index 76bf3df..307436c 100644 --- a/nihav-realmedia/src/codecs/ralf.rs +++ b/nihav-realmedia/src/codecs/ralf.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::*; use nihav_core::frame::*; use nihav_core::codecs::*; @@ -246,7 +244,7 @@ struct Block { const RALF_MAX_PACKET_SIZE: usize = 8192; struct RALFDecoder { - info: Rc, + info: NACodecInfoRef, chmap: NAChannelMap, channels: u8, @@ -357,7 +355,7 @@ fn read_block_length(br: &mut BitReader) -> DecoderResult { } impl NADecoder for RALFDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { let edata = info.get_extradata().unwrap(); diff --git a/nihav-realmedia/src/codecs/rv10.rs b/nihav-realmedia/src/codecs/rv10.rs index 348a7ff..1d93a01 100644 --- a/nihav-realmedia/src/codecs/rv10.rs +++ b/nihav-realmedia/src/codecs/rv10.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::io::bitreader::*; use nihav_core::io::codebook::*; use nihav_core::formats; @@ -23,7 +21,7 @@ struct Tables { } struct RealVideo10Decoder { - info: Rc, + info: NACodecInfoRef, dec: H263BaseDecoder, tables: Tables, w: usize, @@ -392,7 +390,7 @@ impl RealVideo10Decoder { }; RealVideo10Decoder{ - info: Rc::new(DUMMY_CODEC_INFO), + info: NACodecInfoRef::default(), dec: H263BaseDecoder::new_with_opts(false, false, false), tables: tables, w: 0, @@ -405,13 +403,13 @@ impl RealVideo10Decoder { } impl NADecoder for RealVideo10Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); let fmt = formats::YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.w = w; self.h = h; diff --git a/nihav-realmedia/src/codecs/rv20.rs b/nihav-realmedia/src/codecs/rv20.rs index eeb56cf..36ccc67 100644 --- a/nihav-realmedia/src/codecs/rv20.rs +++ b/nihav-realmedia/src/codecs/rv20.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::io::bitreader::*; use nihav_core::io::codebook::*; use nihav_core::formats; @@ -32,7 +30,7 @@ struct RPRInfo { } struct RealVideo20Decoder { - info: Rc, + info: NACodecInfoRef, dec: H263BaseDecoder, tables: Tables, w: usize, @@ -445,7 +443,7 @@ impl RealVideo20Decoder { }; RealVideo20Decoder{ - info: Rc::new(DUMMY_CODEC_INFO), + info: NACodecInfoRef::default(), dec: H263BaseDecoder::new_b_frames(false), tables: tables, w: 0, @@ -459,13 +457,13 @@ impl RealVideo20Decoder { impl NADecoder for RealVideo20Decoder { #[allow(unused_variables)] - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); let fmt = formats::YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.w = w; self.h = h; diff --git a/nihav-realmedia/src/codecs/rv30.rs b/nihav-realmedia/src/codecs/rv30.rs index acdefb6..a2d7090 100644 --- a/nihav-realmedia/src/codecs/rv30.rs +++ b/nihav-realmedia/src/codecs/rv30.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats; use nihav_core::io::bitreader::*; use nihav_core::io::intcode::*; @@ -104,7 +102,7 @@ impl RV34BitstreamDecoder for RealVideo30BR { struct RealVideo30Decoder { bd: RealVideo30BR, - info: Rc, + info: NACodecInfoRef, dec: RV34Decoder, } @@ -112,18 +110,18 @@ impl RealVideo30Decoder { fn new() -> Self { RealVideo30Decoder{ bd: RealVideo30BR::new(), - info: Rc::new(DUMMY_CODEC_INFO), + info: NACodecInfoRef::default(), dec: RV34Decoder::new(true, Box::new(RV30DSP::new())), } } } impl NADecoder for RealVideo30Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let fmt = formats::YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); let edata = info.get_extradata().unwrap(); let src: &[u8] = &edata; diff --git a/nihav-realmedia/src/codecs/rv40.rs b/nihav-realmedia/src/codecs/rv40.rs index d664dce..eb45164 100644 --- a/nihav-realmedia/src/codecs/rv40.rs +++ b/nihav-realmedia/src/codecs/rv40.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats; use nihav_core::frame::*; use nihav_core::io::bitreader::*; @@ -301,7 +299,7 @@ impl RV34BitstreamDecoder for RealVideo40BR { struct RealVideo40Decoder { bd: RealVideo40BR, - info: Rc, + info: NACodecInfoRef, dec: RV34Decoder, } @@ -309,18 +307,18 @@ impl RealVideo40Decoder { fn new() -> Self { RealVideo40Decoder{ bd: RealVideo40BR::new(), - info: Rc::new(DUMMY_CODEC_INFO), + info: NACodecInfoRef::default(), dec: RV34Decoder::new(false, Box::new(RV40DSP::new())), } } } impl NADecoder for RealVideo40Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let fmt = formats::YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); let edata = info.get_extradata().unwrap(); let src: &[u8] = &edata; diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index b430b5b..4adbe39 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::formats::YUV420_FORMAT; use nihav_core::frame::*; use nihav_core::codecs::{NADecoder, MV, ZERO_MV, DecoderError, DecoderResult, IPBShuffler}; @@ -610,7 +608,7 @@ impl DeblockInfo { } struct RealVideo60Decoder { - info: Rc, + info: NACodecInfoRef, cbs: RV60Codebooks, ipbs: IPBShuffler, dsp: RV60DSP, @@ -647,7 +645,7 @@ impl RealVideo60Decoder { let vb = vt.get_vbuf(); let avg_buf = vb.unwrap(); RealVideo60Decoder{ - info: Rc::new(DUMMY_CODEC_INFO), + info: NACodecInfoRef::default(), cbs: RV60Codebooks::init(), ipbs: IPBShuffler::new(), ipred: IntraPredContext::new(), @@ -1393,11 +1391,11 @@ println!(" left {} bits", br.left()); } impl NADecoder for RealVideo60Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(_vinfo) = info.get_properties() { let fmt = YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); let edata = info.get_extradata().unwrap(); let src: &[u8] = &edata; -- 2.39.5