From: Kostya Shishkov Date: Sun, 25 Jun 2017 07:14:27 +0000 (+0200) Subject: pcm: cleanup a bit X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=12ccce74c5c6e7de1b967bc611d064297ff9eff2;p=nihav.git pcm: cleanup a bit --- diff --git a/src/codecs/pcm.rs b/src/codecs/pcm.rs index c5c3b5b..288930b 100644 --- a/src/codecs/pcm.rs +++ b/src/codecs/pcm.rs @@ -22,21 +22,19 @@ fn get_default_chmap(nch: u8) -> NAChannelMap { chmap } -fn get_duration(ainfo: &NAAudioInfo, duration: Option, data_size: usize) -> usize { -println!("pcm in {:?}, {}", duration, data_size); +fn get_duration(ainfo: &NAAudioInfo, duration: Option, data_size: usize) -> u64 { if duration == None { - let size_bits = data_size * 8; - let blk_size = (ainfo.get_channels() as usize) * (ainfo.get_format().get_bits() as usize); + let size_bits = (data_size as u64) * 8; + let blk_size = (ainfo.get_channels() as u64) * (ainfo.get_format().get_bits() as u64); size_bits / blk_size } else { - duration.unwrap() as usize + duration.unwrap() as u64 } } impl NADecoder for PCMDecoder { fn init(&mut self, info: Rc) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { -println!("got info {}", ainfo); self.chmap = get_default_chmap(ainfo.get_channels()); if self.chmap.num_channels() == 0 { return Err(DecoderError::InvalidData); } Ok(()) @@ -48,12 +46,12 @@ println!("got info {}", ainfo); 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()); -println!("duration = {}", duration); 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 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))) } else {