From 8869d4521f334c97c188a7d558e19489b9677ed8 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 11 May 2017 16:06:15 +0200 Subject: [PATCH] get rid of lifetimes in infos --- src/demuxers/gdv.rs | 4 ++-- src/demuxers/mod.rs | 32 ++++++++++++++++---------------- src/frame.rs | 33 +++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/demuxers/gdv.rs b/src/demuxers/gdv.rs index 6055938..b84bc98 100644 --- a/src/demuxers/gdv.rs +++ b/src/demuxers/gdv.rs @@ -12,7 +12,7 @@ enum GDVState { pub struct GremlinVideoDemuxer<'a> { opened: bool, src: &'a mut ByteReader<'a>, - streams: Vec>>, + streams: Vec>, frames: u16, cur_frame: u16, asize: usize, @@ -102,7 +102,7 @@ pktdta: Vec::new(), } } - fn find_stream(&mut self, id: u32) -> Rc> { + fn find_stream(&mut self, id: u32) -> Rc { for i in 0..self.streams.len() { if self.streams[i].get_id() == id { return self.streams[i].clone(); diff --git a/src/demuxers/mod.rs b/src/demuxers/mod.rs index 5c397ac..1eb6cd1 100644 --- a/src/demuxers/mod.rs +++ b/src/demuxers/mod.rs @@ -28,29 +28,29 @@ impl fmt::Display for StreamType { #[allow(dead_code)] -pub struct NAStream<'a> { +pub struct NAStream { media_type: StreamType, id: u32, - info: Rc>, + info: Rc, } -impl<'a> NAStream<'a> { - pub fn new(mt: StreamType, id: u32, info: NACodecInfo<'a>) -> Self { +impl NAStream { + pub fn new(mt: StreamType, id: u32, info: NACodecInfo) -> Self { NAStream { media_type: mt, id: id, info: Rc::new(info) } } pub fn get_id(&self) -> u32 { self.id } - pub fn get_info(&self) -> Rc> { self.info.clone() } + pub fn get_info(&self) -> Rc { self.info.clone() } } -impl<'a> fmt::Display for NAStream<'a> { +impl fmt::Display for NAStream { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "({}#{})", self.media_type, self.id) } } #[allow(dead_code)] -pub struct NAPacket<'a> { - stream: Rc>, +pub struct NAPacket { + stream: Rc, pts: Option, dts: Option, duration: Option, @@ -59,18 +59,18 @@ pub struct NAPacket<'a> { // options: HashMap>, } -impl<'a> NAPacket<'a> { - pub fn new(str: Rc>, pts: Option, dts: Option, dur: Option, kf: bool, vec: Vec) -> Self { +impl NAPacket { + pub fn new(str: Rc, pts: Option, dts: Option, dur: Option, kf: bool, vec: Vec) -> Self { // let mut vec: Vec = Vec::new(); // vec.resize(size, 0); NAPacket { stream: str, pts: pts, dts: dts, duration: dur, keyframe: kf, buffer: Rc::new(vec) } } - pub fn get_stream(&self) -> Rc> { self.stream.clone() } + pub fn get_stream(&self) -> Rc { self.stream.clone() } pub fn get_pts(&self) -> Option { self.pts } pub fn get_buffer(&self) -> Rc> { self.buffer.clone() } } -impl<'a> fmt::Display for NAPacket<'a> { +impl fmt::Display for NAPacket { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut foo = format!("[pkt for {} size {}", self.stream, self.buffer.len()); if let Some(pts) = self.pts { foo = format!("{} pts {}", foo, pts); } @@ -101,13 +101,13 @@ pub trait NADemuxer<'a> { fn seek(&mut self, time: u64) -> DemuxerResult<()>; } -pub trait NAPacketReader<'a> { - fn read_packet(&mut self, str: Rc>, pts: Option, dts: Option, dur: Option, keyframe: bool, size: usize) -> DemuxerResult; +pub trait NAPacketReader { + fn read_packet(&mut self, str: Rc, pts: Option, dts: Option, dur: Option, keyframe: bool, size: usize) -> DemuxerResult; fn fill_packet(&mut self, pkt: &mut NAPacket) -> DemuxerResult<()>; } -impl<'a> NAPacketReader<'a> for ByteReader<'a> { - fn read_packet(&mut self, str: Rc>, pts: Option, dts: Option, dur: Option, kf: bool, size: usize) -> DemuxerResult { +impl<'a> NAPacketReader for ByteReader<'a> { + fn read_packet(&mut self, str: Rc, pts: Option, dts: Option, dur: Option, kf: bool, size: usize) -> DemuxerResult { let mut buf: Vec = Vec::with_capacity(size); if buf.capacity() < size { return Err(DemuxerError::MemoryError); } buf.resize(size, 0); diff --git a/src/frame.rs b/src/frame.rs index 066a016..7b2b5c7 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -1,6 +1,8 @@ use std::collections::HashMap; +use std::rc::Rc; #[allow(dead_code)] +#[derive(Copy,Clone)] pub struct NASoniton { bits: u8, is_be: bool, @@ -15,6 +17,7 @@ pub const SND_U8_FORMAT: NASoniton = NASoniton { bits: 8, is_be: false, packed: pub const SND_S16_FORMAT: NASoniton = NASoniton { bits: 16, is_be: false, packed: false, planar: false, float: false }; #[allow(dead_code)] +#[derive(Clone,Copy)] pub struct NAAudioInfo { sample_rate: u32, channels: u8, @@ -28,7 +31,7 @@ impl NAAudioInfo { } } -#[derive(Debug)] +#[derive(Debug,Clone,Copy)] pub enum ColorModel { RGB, YUV, @@ -38,6 +41,7 @@ pub enum ColorModel { } #[allow(dead_code)] +#[derive(Clone,Copy)] pub struct NAPixelChromaton { h_ss: u8, v_ss: u8, @@ -49,6 +53,7 @@ pub struct NAPixelChromaton { } #[allow(dead_code)] +#[derive(Clone,Copy)] pub struct NAPixelFormaton { model: ColorModel, components: u8, @@ -90,6 +95,7 @@ pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RG #[allow(dead_code)] +#[derive(Clone,Copy)] pub struct NAVideoInfo { width: u32, height: u32, @@ -103,6 +109,7 @@ impl NAVideoInfo { } } +#[derive(Clone,Copy)] pub enum NACodecTypeInfo { None, Audio(NAAudioInfo), @@ -116,14 +123,24 @@ pub struct NABuffer<'a> { } #[allow(dead_code)] -pub struct NACodecInfo<'a> { +#[derive(Clone)] +pub struct NACodecInfo { properties: NACodecTypeInfo, - extradata: Option<&'a[u8]>, + extradata: Option>>, } -impl<'a> NACodecInfo<'a> { - pub fn new(p: NACodecTypeInfo, edata: Option<&'a[u8]>) -> Self { - NACodecInfo { properties: p, extradata: edata } +impl NACodecInfo { + pub fn new(p: NACodecTypeInfo, edata: Option>) -> Self { + let extradata = match edata { + None => None, + Some(vec) => Some(Rc::new(vec)), + }; + NACodecInfo { properties: p, extradata: extradata } + } + pub fn get_properties(&self) -> NACodecTypeInfo { self.properties } + pub fn get_extradata(&self) -> Option>> { + if let Some(ref vec) = self.extradata { return Some(vec.clone()); } + None } } @@ -146,11 +163,11 @@ pub struct NAFrame<'a> { dts: Option, duration: Option, buffer: &'a mut NABuffer<'a>, - info: &'a NACodecInfo<'a>, + info: &'a NACodecInfo, options: HashMap>, } #[allow(dead_code)] pub struct NACodecContext<'a> { - info: &'a NACodecInfo<'a>, + info: &'a NACodecInfo, } -- 2.39.5