X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fframe.rs;h=fbdbdf5e391f533e5c75c2fb90b4cd5f11d07248;hb=6f2630992fe340ad1a122ec10c649f756e478185;hp=31cf8e81991a519d26827e13913175a6d3cd1dd6;hpb=a1298b7a5dcf1656dfc9bdbf3d6c80df89a70fc8;p=nihav.git diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 31cf8e8..fbdbdf5 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -112,17 +112,11 @@ impl NACodecTypeInfo { } /// Reports whether the current stream is video stream. pub fn is_video(&self) -> bool { - match *self { - NACodecTypeInfo::Video(_) => true, - _ => false, - } + matches!(*self, NACodecTypeInfo::Video(_)) } /// Reports whether the current stream is audio stream. pub fn is_audio(&self) -> bool { - match *self { - NACodecTypeInfo::Audio(_) => true, - _ => false, - } + matches!(*self, NACodecTypeInfo::Audio(_)) } } @@ -168,7 +162,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()); @@ -560,10 +554,7 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result false, - _ => true, - }; + let unfit_elem_size = !matches!(fmt.get_elem_size(), 2 | 4); //todo semi-packed like NV12 if fmt.is_paletted() { @@ -752,7 +743,7 @@ impl NAVideoBufferPool { } /// Clears the pool from all frames. pub fn reset(&mut self) { - self.pool.truncate(0); + self.pool.clear(); } } @@ -827,11 +818,7 @@ pub type NACodecInfoRef = Arc; impl NACodecInfo { /// Constructs a new instance of `NACodecInfo`. pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option>) -> Self { - let extradata = match edata { - None => None, - Some(vec) => Some(Arc::new(vec)), - }; - NACodecInfo { name, properties: p, extradata } + NACodecInfo { name, properties: p, extradata: edata.map(Arc::new) } } /// Constructs a new reference-counted instance of `NACodecInfo`. pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option>>) -> Self { @@ -1145,7 +1132,7 @@ impl FromStr for NATimePoint { let mut mval = 0; let mut base = 0; for ch in val.chars() { - if ch >= '0' && ch <= '9' { + if ('0'..='9').contains(&ch) { mval = mval * 10 + u64::from((ch as u8) - b'0'); base += 1; if base > 3 { break; } @@ -1357,7 +1344,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 +1431,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::*;