From ebd71c927a698c18ec5d1876043b84ea71fe88e1 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 20 May 2017 17:03:23 +0200 Subject: [PATCH] extend NAFrame functionality --- src/frame.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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)] -- 2.30.2