From: Kostya Shishkov Date: Sat, 20 May 2017 15:03:23 +0000 (+0200) Subject: extend NAFrame functionality X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=ebd71c927a698c18ec5d1876043b84ea71fe88e1;p=nihav.git extend NAFrame functionality --- diff --git a/src/frame.rs b/src/frame.rs index c086339..67b68d7 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -235,6 +235,8 @@ pub struct NAFrame { options: HashMap, } +pub type NAFrameRef = Rc>; + fn get_plane_size(info: &NAVideoInfo, idx: usize) -> (usize, usize) { let chromaton = info.get_format().get_chromaton(idx); if let None = chromaton { return (0, 0); } @@ -261,6 +263,13 @@ impl NAFrame { offs.clone_from(&src.offsets); NAFrame { pts: None, dts: None, duration: None, buffer: buf, offsets: offs, info: src.info.clone(), ftype: src.ftype, key: src.key, options: src.options.clone() } } + pub fn from_ref(srcref: NAFrameRef) -> Self { + let src = srcref.borrow(); + let buf = copy_buf(&src.get_buffer()); + let mut offs: Vec = Vec::new(); + offs.clone_from(&src.offsets); + NAFrame { pts: None, dts: None, duration: None, buffer: buf, offsets: offs, info: src.info.clone(), ftype: src.ftype, key: src.key, options: src.options.clone() } + } pub fn get_pts(&self) -> Option { self.pts } pub fn get_dts(&self) -> Option { self.dts } pub fn get_duration(&self) -> Option { self.duration } @@ -291,7 +300,17 @@ impl NAFrame { } } -pub type NAFrameRef = Rc>; +impl fmt::Display for NAFrame { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let (w, h) = self.get_dimensions(0); + let mut foo = format!("frame type {} size {}x{}", self.ftype, w, h); + if let Some(pts) = self.pts { foo = format!("{} pts {}", foo, pts); } + if let Some(dts) = self.dts { foo = format!("{} dts {}", foo, dts); } + if let Some(dur) = self.duration { foo = format!("{} duration {}", foo, dur); } + if self.key { foo = format!("{} kf", foo); } + write!(f, "[{}]", foo) + } +} /// Possible stream types. #[derive(Debug,Clone,Copy)]