core/frame: add helper functions for dealing with reference-counted buffer
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 6 Jun 2020 10:39:46 +0000 (12:39 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 6 Jun 2020 10:49:45 +0000 (12:49 +0200)
nihav-core/src/frame.rs

index 4e317fe3e76edc36d02bdb95ee4aa48c3fbe14c1..26e8640aa5dc236ee7ba605cf2126e91c333a957 100644 (file)
@@ -233,6 +233,8 @@ impl<T: Clone> NAAudioBuffer<T> {
     pub fn get_chmap(&self) -> &NAChannelMap { &self.chmap }
     /// Returns an immutable reference to the data.
     pub fn get_data(&self) -> &Vec<T> { self.data.as_ref() }
+    /// Returns reference to the data.
+    pub fn get_data_ref(&self) -> NABufferRef<Vec<T>> { self.data.clone() }
     /// Returns a mutable reference to the data.
     pub fn get_data_mut(&mut self) -> Option<&mut Vec<T>> { self.data.as_mut() }
     /// Clones current `NAAudioBuffer` into a new one.
@@ -1185,6 +1187,10 @@ impl NAPacket {
 //        vec.resize(size, 0);
         NAPacket { stream: str, ts, keyframe: kf, buffer: NABufferRef::new(vec), side_data: Vec::new() }
     }
+    /// Constructs a new `NAPacket` instance reusing a buffer reference.
+    pub fn new_from_refbuf(str: NAStreamRef, ts: NATimeInfo, kf: bool, buffer: NABufferRef<Vec<u8>>) -> Self {
+        NAPacket { stream: str, ts, keyframe: kf, buffer, side_data: Vec::new() }
+    }
     /// Returns information about the stream packet belongs to.
     pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() }
     /// Returns packet timestamp.