X-Git-Url: https://git.nihav.org/?p=nihav.git;a=blobdiff_plain;f=nihav-core%2Fsrc%2Fframe.rs;h=7a09be4c25dfb5076962e18675dd2106ad133226;hp=f596dc95ad2b1d02b684c6563be6bd0492a4e5ec;hb=fafa7da322906def9ed7d924a51d50e39998fe61;hpb=b191eef3e3e1b6bea510c7e64606d8442f974f8b diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index f596dc9..7a09be4 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -168,7 +168,7 @@ impl NAVideoBuffer { /// Returns the number of components in picture format. pub fn get_num_components(&self) -> usize { self.offs.len() } /// Creates a copy of current `NAVideoBuffer`. - pub fn copy_buffer(&mut self) -> Self { + pub fn copy_buffer(&self) -> Self { let mut data: Vec = Vec::with_capacity(self.data.len()); data.clone_from(self.data.as_ref()); let mut offs: Vec = Vec::with_capacity(self.offs.len()); @@ -1357,7 +1357,7 @@ impl NAStream { self.tb_den = d; } /// Returns stream duration. - pub fn get_duration(&self) -> usize { self.num } + pub fn get_duration(&self) -> u64 { self.duration } /// Converts current instance into a reference-counted one. pub fn into_ref(self) -> NAStreamRef { Arc::new(self) } } @@ -1444,6 +1444,37 @@ impl fmt::Display for NAPacket { } } +/// Packet with a piece of data for a raw stream. +pub struct NARawData { + stream: NAStreamRef, + buffer: NABufferRef>, +} + +impl NARawData { + /// Constructs a new `NARawData` instance. + pub fn new(stream: NAStreamRef, vec: Vec) -> Self { + Self { stream, buffer: NABufferRef::new(vec) } + } + /// Constructs a new `NARawData` instance reusing a buffer reference. + pub fn new_from_refbuf(stream: NAStreamRef, buffer: NABufferRef>) -> Self { + Self { stream, buffer } + } + /// Returns information about the stream this data belongs to. + pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() } + /// Returns a reference to packet data. + pub fn get_buffer(&self) -> NABufferRef> { self.buffer.clone() } + /// Assigns raw data to a new stream. + pub fn reassign(&mut self, stream: NAStreamRef) { + self.stream = stream; + } +} + +impl fmt::Display for NARawData { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "[raw data for {} size {}]", self.stream, self.buffer.len()) + } +} + #[cfg(test)] mod test { use super::*;