X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fframe.rs;h=e1529bfe213625f8ed92ceafe088c033b8b93783;hb=049474a0116e080d49c349256da7fae5f1a1b9c3;hp=789088a47d4445e91662565fb314661b3d1aa86d;hpb=3fc28ece6664a34af9b7f6a52dbf8a8809fa9204;p=nihav.git diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 789088a..e1529bf 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -94,7 +94,7 @@ impl NACodecTypeInfo { impl fmt::Display for NACodecTypeInfo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let ret = match *self { - NACodecTypeInfo::None => format!(""), + NACodecTypeInfo::None => "".to_string(), NACodecTypeInfo::Audio(fmt) => format!("{}", fmt), NACodecTypeInfo::Video(fmt) => format!("{}", fmt), }; @@ -125,7 +125,7 @@ impl NAVideoBuffer { offs.clone_from(&self.offs); let mut strides: Vec = Vec::with_capacity(self.strides.len()); strides.clone_from(&self.strides); - NAVideoBuffer { info: self.info, data: NABufferRef::new(data), offs: offs, strides: strides } + NAVideoBuffer { info: self.info, data: NABufferRef::new(data), offs, strides } } pub fn get_stride(&self, idx: usize) -> usize { if idx >= self.strides.len() { return 0; } @@ -146,6 +146,7 @@ pub struct NAAudioBuffer { info: NAAudioInfo, data: NABufferRef>, offs: Vec, + stride: usize, chmap: NAChannelMap, len: usize, } @@ -155,8 +156,9 @@ impl NAAudioBuffer { if idx >= self.offs.len() { 0 } else { self.offs[idx] } } + 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 { @@ -164,7 +166,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: offs, chmap: self.get_chmap(), len: self.len } + 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 } } @@ -172,7 +174,7 @@ impl NAAudioBuffer { impl NAAudioBuffer { pub fn new_from_buf(info: NAAudioInfo, data: NABufferRef>, chmap: NAChannelMap) -> Self { let len = data.len(); - NAAudioBuffer { info: info, data: data, chmap: chmap, offs: Vec::new(), len: len } + NAAudioBuffer { info, data, chmap, offs: Vec::new(), len, stride: 0 } } } @@ -233,6 +235,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()), @@ -268,7 +310,7 @@ pub struct NASimpleVideoFrame<'a, T: Copy> { pub stride: [usize; NA_SIMPLE_VFRAME_COMPONENTS], pub offset: [usize; NA_SIMPLE_VFRAME_COMPONENTS], pub components: usize, - pub data: &'a mut Vec, + pub data: &'a mut [T], } impl<'a, T:Copy> NASimpleVideoFrame<'a, T> { @@ -297,7 +339,7 @@ impl<'a, T:Copy> NASimpleVideoFrame<'a, T> { stride: s, offset: o, components, - data: vbuf.data.as_mut().unwrap(), + data: vbuf.data.as_mut_slice(), }) } } @@ -326,7 +368,7 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result Result = Vec::with_capacity(new_size.unwrap()); - data.resize(new_size.unwrap(), 0); - let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; + let data: Vec = vec![0; new_size.unwrap()]; + let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; Ok(NABufferType::Video(buf.into_ref())) } else if !all_packed { for i in 0..fmt.get_num_comp() { let ochr = fmt.get_chromaton(i); - if let None = ochr { continue; } + if ochr.is_none() { continue; } let chr = ochr.unwrap(); - if !vinfo.is_flipped() { - offs.push(new_size as usize); - } + offs.push(new_size as usize); let stride = chr.get_linesize(width); let cur_h = chr.get_height(height); let cur_sz = stride.checked_mul(cur_h); @@ -371,25 +410,19 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = Vec::with_capacity(new_size); - data.resize(new_size, 0); - let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; + let data: Vec = vec![0; new_size]; + let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; Ok(NABufferType::Video(buf.into_ref())) } else if max_depth <= 16 { - let mut data: Vec = Vec::with_capacity(new_size); - data.resize(new_size, 0); - let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; + let data: Vec = vec![0; new_size]; + let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; Ok(NABufferType::Video16(buf.into_ref())) } else { - let mut data: Vec = Vec::with_capacity(new_size); - data.resize(new_size, 0); - let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; + let data: Vec = vec![0; new_size]; + let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; Ok(NABufferType::Video32(buf.into_ref())) } } else if all_bytealigned || unfit_elem_size { @@ -399,10 +432,9 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = Vec::with_capacity(new_size); - data.resize(new_size, 0); + let data: Vec = vec![0; new_size]; strides.push(line_sz.unwrap()); - let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; + let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; Ok(NABufferType::VideoPacked(buf.into_ref())) } else { let elem_sz = fmt.get_elem_size(); @@ -411,17 +443,15 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result { - let mut data: Vec = Vec::with_capacity(new_size); - data.resize(new_size, 0); + let data: Vec = vec![0; new_size]; strides.push(width); - let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; + let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; Ok(NABufferType::Video16(buf.into_ref())) }, 4 => { - let mut data: Vec = Vec::with_capacity(new_size); - data.resize(new_size, 0); + let data: Vec = vec![0; new_size]; strides.push(width); - let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides }; + let buf: NAVideoBuffer = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; Ok(NABufferType::Video32(buf.into_ref())) }, _ => unreachable!(), @@ -429,34 +459,33 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result Result { let mut offs: Vec = Vec::new(); if ainfo.format.is_planar() || (ainfo.channels == 1 && (ainfo.format.get_bits() % 8) == 0) { let len = nsamples.checked_mul(ainfo.channels as usize); if len == None { return Err(AllocatorError::TooLargeDimensions); } let length = len.unwrap(); + let stride = nsamples; for i in 0..ainfo.channels { - offs.push((i as usize) * nsamples); + offs.push((i as usize) * stride); } if ainfo.format.is_float() { if ainfo.format.get_bits() == 32 { - let mut data: Vec = Vec::with_capacity(length); - data.resize(length, 0.0); - let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples }; + let data: Vec = vec![0.0; length]; + let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride }; Ok(NABufferType::AudioF32(buf)) } else { Err(AllocatorError::TooLargeDimensions) } } else { if ainfo.format.get_bits() == 8 && !ainfo.format.is_signed() { - let mut data: Vec = Vec::with_capacity(length); - data.resize(length, 0); - let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples }; + let data: Vec = vec![0; length]; + let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride }; Ok(NABufferType::AudioU8(buf)) } else if ainfo.format.get_bits() == 16 && ainfo.format.is_signed() { - let mut data: Vec = Vec::with_capacity(length); - data.resize(length, 0); - let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples }; + let data: Vec = vec![0; length]; + let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride }; Ok(NABufferType::AudioI16(buf)) } else { Err(AllocatorError::TooLargeDimensions) @@ -466,16 +495,14 @@ pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelM let len = nsamples.checked_mul(ainfo.channels as usize); if len == None { return Err(AllocatorError::TooLargeDimensions); } let length = ainfo.format.get_audio_size(len.unwrap() as u64); - let mut data: Vec = Vec::with_capacity(length); - data.resize(length, 0); - let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples }; + let data: Vec = vec![0; length]; + let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride: 0 }; Ok(NABufferType::AudioPacked(buf)) } } pub fn alloc_data_buffer(size: usize) -> Result { - let mut data: Vec = Vec::with_capacity(size); - data.resize(size, 0); + let data: Vec = vec![0; size]; let buf: NABufferRef> = NABufferRef::new(data); Ok(NABufferType::Data(buf)) } @@ -484,49 +511,85 @@ pub fn copy_buffer(buf: NABufferType) -> NABufferType { buf.clone() } -pub struct NABufferPool { - pool: Vec>, +pub struct NAVideoBufferPool { + pool: Vec>, max_len: usize, + add_len: usize, } -impl NABufferPool { +impl NAVideoBufferPool { pub fn new(max_len: usize) -> Self { Self { pool: Vec::with_capacity(max_len), max_len, + add_len: 0, + } + } + pub fn set_dec_bufs(&mut self, add_len: usize) { + self.add_len = add_len; + } + pub fn get_free(&mut self) -> Option> { + for e in self.pool.iter() { + if e.get_num_refs() == 1 { + return Some(e.clone()); + } } + None + } + pub fn get_copy(&mut self, rbuf: &NAVideoBufferRef) -> Option> { + let mut dbuf = self.get_free()?; + dbuf.data.copy_from_slice(&rbuf.data); + Some(dbuf) + } + pub fn reset(&mut self) { + self.pool.truncate(0); } +} + +impl NAVideoBufferPool { pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> { - let nbufs = self.max_len - self.pool.len(); + let nbufs = self.max_len + self.add_len - self.pool.len(); for _ in 0..nbufs { - let buf = alloc_video_buffer(vinfo.clone(), align)?; - self.pool.push(NABufferRef::new(buf)); + let vbuf = alloc_video_buffer(vinfo, align)?; + if let NABufferType::Video(buf) = vbuf { + self.pool.push(buf); + } else if let NABufferType::VideoPacked(buf) = vbuf { + self.pool.push(buf); + } else { + return Err(AllocatorError::FormatError); + } } Ok(()) } - pub fn prealloc_audio(&mut self, ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelMap) -> Result<(), AllocatorError> { - let nbufs = self.max_len - self.pool.len(); +} + +impl NAVideoBufferPool { + pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> { + let nbufs = self.max_len + self.add_len - self.pool.len(); for _ in 0..nbufs { - let buf = alloc_audio_buffer(ainfo.clone(), nsamples, chmap.clone())?; - self.pool.push(NABufferRef::new(buf)); + let vbuf = alloc_video_buffer(vinfo, align)?; + if let NABufferType::Video16(buf) = vbuf { + self.pool.push(buf); + } else { + return Err(AllocatorError::FormatError); + } } Ok(()) } - pub fn add(&mut self, buf: NABufferType) -> bool { - if self.pool.len() < self.max_len { - self.pool.push(NABufferRef::new(buf)); - true - } else { - false - } - } - pub fn get_free(&mut self) -> Option> { - for e in self.pool.iter() { - if e.get_num_refs() == 1 { - return Some(e.clone()); +} + +impl NAVideoBufferPool { + pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> { + let nbufs = self.max_len + self.add_len - self.pool.len(); + for _ in 0..nbufs { + let vbuf = alloc_video_buffer(vinfo, align)?; + if let NABufferType::Video32(buf) = vbuf { + self.pool.push(buf); + } else { + return Err(AllocatorError::FormatError); } } - None + Ok(()) } } @@ -546,10 +609,10 @@ impl NACodecInfo { None => None, Some(vec) => Some(Arc::new(vec)), }; - NACodecInfo { name: name, properties: p, extradata: extradata } + NACodecInfo { name, properties: p, extradata } } pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option>>) -> Self { - NACodecInfo { name: name, properties: p, extradata: edata } + NACodecInfo { name, properties: p, extradata: edata } } pub fn into_ref(self) -> NACodecInfoRef { Arc::new(self) } pub fn get_properties(&self) -> NACodecTypeInfo { self.properties } @@ -581,7 +644,7 @@ impl Default for NACodecInfo { impl fmt::Display for NACodecInfo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let edata = match self.extradata.clone() { - None => format!("no extradata"), + None => "no extradata".to_string(), Some(v) => format!("{} byte(s) of extradata", v.len()), }; write!(f, "{}: {} {}", self.name, self.properties, edata) @@ -635,7 +698,7 @@ pub struct NATimeInfo { impl NATimeInfo { pub fn new(pts: Option, dts: Option, duration: Option, tb_num: u32, tb_den: u32) -> Self { - NATimeInfo { pts: pts, dts: dts, duration: duration, tb_num: tb_num, tb_den: tb_den } + NATimeInfo { pts, dts, duration, tb_num, tb_den } } pub fn get_pts(&self) -> Option { self.pts } pub fn get_dts(&self) -> Option { self.dts } @@ -643,12 +706,55 @@ impl NATimeInfo { pub fn set_pts(&mut self, pts: Option) { self.pts = pts; } pub fn set_dts(&mut self, dts: Option) { self.dts = dts; } pub fn set_duration(&mut self, dur: Option) { self.duration = dur; } + + pub fn time_to_ts(time: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 { + let tb_num = tb_num as u64; + let tb_den = tb_den as u64; + let tmp = time.checked_mul(tb_num); + if let Some(tmp) = tmp { + tmp / base / tb_den + } else { + let tmp = time.checked_mul(tb_num); + if let Some(tmp) = tmp { + tmp / base / tb_den + } else { + let coarse = time / base; + let tmp = coarse.checked_mul(tb_num); + if let Some(tmp) = tmp { + tmp / tb_den + } else { + (coarse / tb_den) * tb_num + } + } + } + } + pub fn ts_to_time(ts: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 { + let tb_num = tb_num as u64; + let tb_den = tb_den as u64; + let tmp = ts.checked_mul(base); + if let Some(tmp) = tmp { + let tmp2 = tmp.checked_mul(tb_num); + if let Some(tmp2) = tmp2 { + tmp2 / tb_den + } else { + (tmp / tb_den) * tb_num + } + } else { + let tmp = ts.checked_mul(tb_num); + if let Some(tmp) = tmp { + (tmp / tb_den) * base + } else { + (ts / tb_den) * base * tb_num + } + } + } } #[allow(dead_code)] #[derive(Clone)] pub struct NAFrame { ts: NATimeInfo, + id: i64, buffer: NABufferType, info: NACodecInfoRef, ftype: FrameType, @@ -660,7 +766,7 @@ pub type NAFrameRef = Arc; fn get_plane_size(info: &NAVideoInfo, idx: usize) -> (usize, usize) { let chromaton = info.get_format().get_chromaton(idx); - if let None = chromaton { return (0, 0); } + if chromaton.is_none() { return (0, 0); } let (hs, vs) = chromaton.unwrap().get_subsampling(); let w = (info.get_width() + ((1 << hs) - 1)) >> hs; let h = (info.get_height() + ((1 << vs) - 1)) >> vs; @@ -674,7 +780,7 @@ impl NAFrame { info: NACodecInfoRef, options: HashMap, buffer: NABufferType) -> Self { - NAFrame { ts: ts, buffer: buffer, info: info, ftype: ftype, key: keyframe, options: options } + NAFrame { ts, id: 0, buffer, info, ftype, key: keyframe, options } } pub fn get_info(&self) -> NACodecInfoRef { self.info.clone() } pub fn get_frame_type(&self) -> FrameType { self.ftype } @@ -684,9 +790,11 @@ impl NAFrame { pub fn get_time_information(&self) -> NATimeInfo { self.ts } pub fn get_pts(&self) -> Option { self.ts.get_pts() } pub fn get_dts(&self) -> Option { self.ts.get_dts() } + pub fn get_id(&self) -> i64 { self.id } pub fn get_duration(&self) -> Option { self.ts.get_duration() } pub fn set_pts(&mut self, pts: Option) { self.ts.set_pts(pts); } pub fn set_dts(&mut self, dts: Option) { self.ts.set_dts(dts); } + pub fn set_id(&mut self, id: i64) { self.id = id; } pub fn set_duration(&mut self, dur: Option) { self.ts.set_duration(dur); } pub fn get_buffer(&self) -> NABufferType { self.buffer.clone() } @@ -696,17 +804,17 @@ impl NAFrame { impl fmt::Display for NAFrame { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let mut foo = format!("frame type {}", self.ftype); - if let Some(pts) = self.ts.pts { foo = format!("{} pts {}", foo, pts); } - if let Some(dts) = self.ts.dts { foo = format!("{} dts {}", foo, dts); } - if let Some(dur) = self.ts.duration { foo = format!("{} duration {}", foo, dur); } - if self.key { foo = format!("{} kf", foo); } - write!(f, "[{}]", foo) + let mut ostr = format!("frame type {}", self.ftype); + if let Some(pts) = self.ts.pts { ostr = format!("{} pts {}", ostr, pts); } + if let Some(dts) = self.ts.dts { ostr = format!("{} dts {}", ostr, dts); } + if let Some(dur) = self.ts.duration { ostr = format!("{} duration {}", ostr, dur); } + if self.key { ostr = format!("{} kf", ostr); } + write!(f, "[{}]", ostr) } } /// Possible stream types. -#[derive(Debug,Clone,Copy)] +#[derive(Debug,Clone,Copy,PartialEq)] #[allow(dead_code)] pub enum StreamType { /// video stream @@ -764,9 +872,10 @@ pub fn reduce_timebase(tb_num: u32, tb_den: u32) -> (u32, u32) { impl NAStream { pub fn new(mt: StreamType, id: u32, info: NACodecInfo, tb_num: u32, tb_den: u32) -> Self { let (n, d) = reduce_timebase(tb_num, tb_den); - NAStream { media_type: mt, id: id, num: 0, info: info.into_ref(), tb_num: n, tb_den: d } + NAStream { media_type: mt, id, num: 0, info: info.into_ref(), tb_num: n, tb_den: d } } pub fn get_id(&self) -> u32 { self.id } + pub fn get_media_type(&self) -> StreamType { self.media_type } pub fn get_num(&self) -> usize { self.num } pub fn set_num(&mut self, num: usize) { self.num = num; } pub fn get_info(&self) -> NACodecInfoRef { self.info.clone() } @@ -798,7 +907,7 @@ impl NAPacket { pub fn new(str: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec) -> Self { // let mut vec: Vec = Vec::new(); // vec.resize(size, 0); - NAPacket { stream: str, ts: ts, keyframe: kf, buffer: NABufferRef::new(vec) } + NAPacket { stream: str, ts, keyframe: kf, buffer: NABufferRef::new(vec) } } pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() } pub fn get_time_information(&self) -> NATimeInfo { self.ts } @@ -815,13 +924,13 @@ impl Drop for NAPacket { impl fmt::Display for NAPacket { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let mut foo = format!("[pkt for {} size {}", self.stream, self.buffer.len()); - if let Some(pts) = self.ts.pts { foo = format!("{} pts {}", foo, pts); } - if let Some(dts) = self.ts.dts { foo = format!("{} dts {}", foo, dts); } - if let Some(dur) = self.ts.duration { foo = format!("{} duration {}", foo, dur); } - if self.keyframe { foo = format!("{} kf", foo); } - foo = foo + "]"; - write!(f, "{}", foo) + let mut ostr = format!("[pkt for {} size {}", self.stream, self.buffer.len()); + if let Some(pts) = self.ts.pts { ostr = format!("{} pts {}", ostr, pts); } + if let Some(dts) = self.ts.dts { ostr = format!("{} dts {}", ostr, dts); } + if let Some(dur) = self.ts.duration { ostr = format!("{} duration {}", ostr, dur); } + if self.keyframe { ostr = format!("{} kf", ostr); } + ostr += "]"; + write!(f, "{}", ostr) } }