X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fframe.rs;h=3af0d1d1af3ba09c11272b4d50702f11695779cf;hb=e64739f87a35f29be0bbbce366876180ba3eb57e;hp=d51d226816394c8488d42f88e5d84b29f6998fa3;hpb=01e2d49645edae06053dfd64142fae861ec0a945;p=nihav.git diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index d51d226..3af0d1d 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -8,10 +8,10 @@ pub use crate::refs::*; #[allow(dead_code)] #[derive(Clone,Copy,PartialEq)] pub struct NAAudioInfo { - sample_rate: u32, - channels: u8, - format: NASoniton, - block_len: usize, + pub sample_rate: u32, + pub channels: u8, + pub format: NASoniton, + pub block_len: usize, } impl NAAudioInfo { @@ -118,6 +118,7 @@ impl NAVideoBuffer { pub fn get_info(&self) -> NAVideoInfo { self.info } pub fn get_data(&self) -> &Vec { self.data.as_ref() } pub fn get_data_mut(&mut self) -> Option<&mut Vec> { self.data.as_mut() } + pub fn get_num_components(&self) -> usize { self.offs.len() } pub fn copy_buffer(&mut self) -> Self { let mut data: Vec = Vec::with_capacity(self.data.len()); data.clone_from(self.data.as_ref()); @@ -158,7 +159,7 @@ impl NAAudioBuffer { } pub fn get_stride(&self) -> usize { self.stride } pub fn get_info(&self) -> NAAudioInfo { self.info } - pub fn get_chmap(&self) -> NAChannelMap { self.chmap.clone() } + pub fn get_chmap(&self) -> &NAChannelMap { &self.chmap } pub fn get_data(&self) -> &Vec { self.data.as_ref() } pub fn get_data_mut(&mut self) -> Option<&mut Vec> { self.data.as_mut() } pub fn copy_buffer(&mut self) -> Self { @@ -166,7 +167,7 @@ impl NAAudioBuffer { data.clone_from(self.data.as_ref()); let mut offs: Vec = Vec::with_capacity(self.offs.len()); offs.clone_from(&self.offs); - NAAudioBuffer { info: self.info, data: NABufferRef::new(data), offs, chmap: self.get_chmap(), len: self.len, stride: self.stride } + NAAudioBuffer { info: self.info, data: NABufferRef::new(data), offs, chmap: self.get_chmap().clone(), len: self.len, stride: self.stride } } pub fn get_length(&self) -> usize { self.len } } @@ -235,6 +236,46 @@ impl NABufferType { _ => None, } } + pub fn get_audio_info(&self) -> Option { + match *self { + NABufferType::AudioU8(ref ab) => Some(ab.get_info()), + NABufferType::AudioI16(ref ab) => Some(ab.get_info()), + NABufferType::AudioI32(ref ab) => Some(ab.get_info()), + NABufferType::AudioF32(ref ab) => Some(ab.get_info()), + NABufferType::AudioPacked(ref ab) => Some(ab.get_info()), + _ => None, + } + } + pub fn get_chmap(&self) -> Option<&NAChannelMap> { + match *self { + NABufferType::AudioU8(ref ab) => Some(ab.get_chmap()), + NABufferType::AudioI16(ref ab) => Some(ab.get_chmap()), + NABufferType::AudioI32(ref ab) => Some(ab.get_chmap()), + NABufferType::AudioF32(ref ab) => Some(ab.get_chmap()), + NABufferType::AudioPacked(ref ab) => Some(ab.get_chmap()), + _ => None, + } + } + pub fn get_audio_length(&self) -> usize { + match *self { + NABufferType::AudioU8(ref ab) => ab.get_length(), + NABufferType::AudioI16(ref ab) => ab.get_length(), + NABufferType::AudioI32(ref ab) => ab.get_length(), + NABufferType::AudioF32(ref ab) => ab.get_length(), + NABufferType::AudioPacked(ref ab) => ab.get_length(), + _ => 0, + } + } + pub fn get_audio_stride(&self) -> usize { + match *self { + NABufferType::AudioU8(ref ab) => ab.get_stride(), + NABufferType::AudioI16(ref ab) => ab.get_stride(), + NABufferType::AudioI32(ref ab) => ab.get_stride(), + NABufferType::AudioF32(ref ab) => ab.get_stride(), + NABufferType::AudioPacked(ref ab) => ab.get_stride(), + _ => 0, + } + } pub fn get_abuf_u8(&self) -> Option> { match *self { NABufferType::AudioU8(ref ab) => Some(ab.clone()),