}
impl<T: Clone> NAVideoBuffer<T> {
+ /// Constructs video buffer from the provided components.
+ pub fn from_raw_parts(info: NAVideoInfo, data: NABufferRef<Vec<T>>, offs: Vec<usize>, strides: Vec<usize>) -> Self {
+ Self { info, data, offs, strides }
+ }
/// Returns the component offset (0 for all unavailable offsets).
pub fn get_offset(&self, idx: usize) -> usize {
if idx >= self.offs.len() { 0 }
_ => 0,
}
}
+ /// Truncates audio frame duration if possible.
+ pub fn truncate_audio(&mut self, len: usize) {
+ match *self {
+ NABufferType::AudioU8(ref mut ab) => ab.truncate(len),
+ NABufferType::AudioI16(ref mut ab) => ab.truncate(len),
+ NABufferType::AudioI32(ref mut ab) => ab.truncate(len),
+ NABufferType::AudioF32(ref mut ab) => ab.truncate(len),
+ NABufferType::AudioPacked(ref mut ab) => ab.truncate(len),
+ _ => {},
+ };
+ }
/// Returns the distance between starts of two channels.
pub fn get_audio_stride(&self) -> usize {
match *self {
}
/// Creates a clone of current buffer.
-pub fn copy_buffer(buf: NABufferType) -> NABufferType {
+pub fn copy_buffer(buf: &NABufferType) -> NABufferType {
buf.clone()
}
}
/// Clears the pool from all frames.
pub fn reset(&mut self) {
- self.pool.truncate(0);
+ self.pool.clear();
}
}
pub fn set_duration(&mut self, dur: Option<u64>) { self.duration = dur; }
/// Converts time in given scale into timestamp in given base.
+ #[allow(clippy::collapsible_if)]
pub fn time_to_ts(time: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 {
let tb_num = u64::from(tb_num);
let tb_den = u64::from(tb_den);
pub type NAStreamRef = Arc<NAStream>;
/// Downscales the timebase by its greatest common denominator.
+#[allow(clippy::comparison_chain)]
pub fn reduce_timebase(tb_num: u32, tb_den: u32) -> (u32, u32) {
if tb_num == 0 { return (tb_num, tb_den); }
if (tb_den % tb_num) == 0 { return (1, tb_den / tb_num); }
}
}
+/// Packet with a piece of data for a raw stream.
+pub struct NARawData {
+ stream: NAStreamRef,
+ buffer: NABufferRef<Vec<u8>>,
+}
+
+impl NARawData {
+ /// Constructs a new `NARawData` instance.
+ pub fn new(stream: NAStreamRef, vec: Vec<u8>) -> 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<Vec<u8>>) -> 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<Vec<u8>> { 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::*;