X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fframe.rs;h=61741d726f082789e5f2ee5b49c4fd78ebc5fe9b;hb=405cec9eed5d7f58440ec8495f5cbc1f5c6fee40;hp=1ba361041c11c43c584c342a5bfd694ef0a78e0d;hpb=556509ab9495f191dac5531be40930daeb7562d0;p=nihav.git diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 1ba3610..61741d7 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()); @@ -277,7 +271,8 @@ impl NAAudioBuffer { impl NAAudioBuffer { /// Constructs a new `NAAudioBuffer` instance. pub fn new_from_buf(info: NAAudioInfo, data: NABufferRef>, chmap: NAChannelMap) -> Self { - let len = data.len(); + let len = data.len() * 8 / chmap.num_channels() / (info.format.bits as usize); + NAAudioBuffer { info, data, chmap, offs: Vec::new(), len, stride: 0, step: 0 } } } @@ -560,10 +555,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() { @@ -827,11 +819,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 +1133,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; } @@ -1358,6 +1346,10 @@ impl NAStream { } /// Returns stream duration. pub fn get_duration(&self) -> u64 { self.duration } + /// Constructs a new timestamp. + pub fn make_ts(&self, pts: Option, dts: Option, duration: Option) -> NATimeInfo { + NATimeInfo::new(pts, dts, duration, self.tb_num, self.tb_den) + } /// Converts current instance into a reference-counted one. pub fn into_ref(self) -> NAStreamRef { Arc::new(self) } } @@ -1396,14 +1388,14 @@ pub struct NAPacket { impl NAPacket { /// Constructs a new `NAPacket` instance. - pub fn new(str: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec) -> Self { + pub fn new(stream: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec) -> Self { // let mut vec: Vec = Vec::new(); // vec.resize(size, 0); - NAPacket { stream: str, ts, keyframe: kf, buffer: NABufferRef::new(vec), side_data: Vec::new() } + NAPacket { stream, 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() } + pub fn new_from_refbuf(stream: NAStreamRef, ts: NATimeInfo, kf: bool, buffer: NABufferRef>) -> Self { + NAPacket { stream, 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() } @@ -1422,8 +1414,8 @@ impl NAPacket { /// Adds side data for a packet. pub fn add_side_data(&mut self, side_data: NASideData) { self.side_data.push(side_data); } /// Assigns packet to a new stream. - pub fn reassign(&mut self, str: NAStreamRef, ts: NATimeInfo) { - self.stream = str; + pub fn reassign(&mut self, stream: NAStreamRef, ts: NATimeInfo) { + self.stream = stream; self.ts = ts; } }