From: Kostya Shishkov Date: Sat, 6 Jun 2020 10:39:46 +0000 (+0200) Subject: core/frame: add helper functions for dealing with reference-counted buffer X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=89f25cd7aaba43aa728c4923c27da59b7285b170;p=nihav.git core/frame: add helper functions for dealing with reference-counted buffer --- diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 4e317fe..26e8640 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -233,6 +233,8 @@ impl NAAudioBuffer { pub fn get_chmap(&self) -> &NAChannelMap { &self.chmap } /// Returns an immutable reference to the data. pub fn get_data(&self) -> &Vec { self.data.as_ref() } + /// Returns reference to the data. + pub fn get_data_ref(&self) -> NABufferRef> { self.data.clone() } /// Returns a mutable reference to the data. pub fn get_data_mut(&mut self) -> Option<&mut Vec> { 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>) -> 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.