X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-commonfmt%2Fsrc%2Fcodecs%2Fpcm.rs;h=b4ded8746bccb11a8f63e392b18bc6f7af40a8de;hb=7d57ae2f680d7a1eba7af2ee831f305b2f0f9324;hp=b718b67bfc7bce4230e0a86ad6d07d87889ed982;hpb=c3904fe5804a28e73822c27c69ba10a716cb290d;p=nihav.git diff --git a/nihav-commonfmt/src/codecs/pcm.rs b/nihav-commonfmt/src/codecs/pcm.rs index b718b67..b4ded87 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::*; @@ -27,15 +25,15 @@ fn get_default_chmap(nch: u8) -> NAChannelMap { fn get_duration(ainfo: &NAAudioInfo, duration: Option, data_size: usize) -> u64 { if duration == None { let size_bits = (data_size as u64) * 8; - let blk_size = (ainfo.get_channels() as u64) * (ainfo.get_format().get_bits() as u64); + let blk_size = u64::from(ainfo.get_channels()) * u64::from(ainfo.get_format().get_bits()); size_bits / blk_size } else { - duration.unwrap() as u64 + duration.unwrap() } } impl NADecoder for PCMDecoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, _supp: &mut NADecoderSupport, 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); } @@ -44,24 +42,30 @@ impl NADecoder for PCMDecoder { Err(DecoderError::InvalidData) } } - fn decode(&mut self, pkt: &NAPacket) -> DecoderResult { + fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let info = pkt.get_stream().get_info(); 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 = 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); - Ok(Rc::new(RefCell::new(frm))) + Ok(frm.into_ref()) } else { Err(DecoderError::InvalidData) } } + fn flush(&mut self) { + } +} + +impl NAOptionHandler for PCMDecoder { + fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] } + fn set_options(&mut self, _options: &[NAOption]) { } + fn query_option_value(&self, _name: &str) -> Option { None } } -pub fn get_decoder() -> Box { +pub fn get_decoder() -> Box { Box::new(PCMDecoder::new()) }