2 use std::collections::HashMap;
6 pub use crate::formats::*;
9 #[derive(Clone,Copy,PartialEq)]
10 pub struct NAAudioInfo {
18 pub fn new(sr: u32, ch: u8, fmt: NASoniton, bl: usize) -> Self {
19 NAAudioInfo { sample_rate: sr, channels: ch, format: fmt, block_len: bl }
21 pub fn get_sample_rate(&self) -> u32 { self.sample_rate }
22 pub fn get_channels(&self) -> u8 { self.channels }
23 pub fn get_format(&self) -> NASoniton { self.format }
24 pub fn get_block_len(&self) -> usize { self.block_len }
27 impl fmt::Display for NAAudioInfo {
28 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29 write!(f, "{} Hz, {} ch", self.sample_rate, self.channels)
34 #[derive(Clone,Copy,PartialEq)]
35 pub struct NAVideoInfo {
39 format: NAPixelFormaton,
43 pub fn new(w: usize, h: usize, flip: bool, fmt: NAPixelFormaton) -> Self {
44 NAVideoInfo { width: w, height: h, flipped: flip, format: fmt }
46 pub fn get_width(&self) -> usize { self.width as usize }
47 pub fn get_height(&self) -> usize { self.height as usize }
48 pub fn is_flipped(&self) -> bool { self.flipped }
49 pub fn get_format(&self) -> NAPixelFormaton { self.format }
50 pub fn set_width(&mut self, w: usize) { self.width = w; }
51 pub fn set_height(&mut self, h: usize) { self.height = h; }
54 impl fmt::Display for NAVideoInfo {
55 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56 write!(f, "{}x{}", self.width, self.height)
60 #[derive(Clone,Copy,PartialEq)]
61 pub enum NACodecTypeInfo {
67 impl NACodecTypeInfo {
68 pub fn get_video_info(&self) -> Option<NAVideoInfo> {
70 NACodecTypeInfo::Video(vinfo) => Some(vinfo),
74 pub fn get_audio_info(&self) -> Option<NAAudioInfo> {
76 NACodecTypeInfo::Audio(ainfo) => Some(ainfo),
80 pub fn is_video(&self) -> bool {
82 NACodecTypeInfo::Video(_) => true,
86 pub fn is_audio(&self) -> bool {
88 NACodecTypeInfo::Audio(_) => true,
94 impl fmt::Display for NACodecTypeInfo {
95 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
96 let ret = match *self {
97 NACodecTypeInfo::None => format!(""),
98 NACodecTypeInfo::Audio(fmt) => format!("{}", fmt),
99 NACodecTypeInfo::Video(fmt) => format!("{}", fmt),
105 pub type NABufferRefT<T> = Rc<RefCell<Vec<T>>>;
108 pub struct NAVideoBuffer<T> {
110 data: NABufferRefT<T>,
115 impl<T: Clone> NAVideoBuffer<T> {
116 pub fn get_offset(&self, idx: usize) -> usize {
117 if idx >= self.offs.len() { 0 }
118 else { self.offs[idx] }
120 pub fn get_info(&self) -> NAVideoInfo { self.info }
121 pub fn get_data(&self) -> Ref<Vec<T>> { self.data.borrow() }
122 pub fn get_data_mut(&mut self) -> RefMut<Vec<T>> { self.data.borrow_mut() }
123 pub fn copy_buffer(&mut self) -> Self {
124 let mut data: Vec<T> = Vec::with_capacity(self.data.borrow().len());
125 data.clone_from(self.data.borrow().as_ref());
126 let mut offs: Vec<usize> = Vec::with_capacity(self.offs.len());
127 offs.clone_from(&self.offs);
128 let mut strides: Vec<usize> = Vec::with_capacity(self.strides.len());
129 strides.clone_from(&self.strides);
130 NAVideoBuffer { info: self.info, data: Rc::new(RefCell::new(data)), offs: offs, strides: strides }
132 pub fn get_stride(&self, idx: usize) -> usize {
133 if idx >= self.strides.len() { return 0; }
136 pub fn get_dimensions(&self, idx: usize) -> (usize, usize) {
137 get_plane_size(&self.info, idx)
142 pub struct NAAudioBuffer<T> {
144 data: NABufferRefT<T>,
150 impl<T: Clone> NAAudioBuffer<T> {
151 pub fn get_offset(&self, idx: usize) -> usize {
152 if idx >= self.offs.len() { 0 }
153 else { self.offs[idx] }
155 pub fn get_info(&self) -> NAAudioInfo { self.info }
156 pub fn get_chmap(&self) -> NAChannelMap { self.chmap.clone() }
157 pub fn get_data(&self) -> Ref<Vec<T>> { self.data.borrow() }
158 pub fn get_data_mut(&mut self) -> RefMut<Vec<T>> { self.data.borrow_mut() }
159 pub fn copy_buffer(&mut self) -> Self {
160 let mut data: Vec<T> = Vec::with_capacity(self.data.borrow().len());
161 data.clone_from(self.data.borrow().as_ref());
162 let mut offs: Vec<usize> = Vec::with_capacity(self.offs.len());
163 offs.clone_from(&self.offs);
164 NAAudioBuffer { info: self.info, data: Rc::new(RefCell::new(data)), offs: offs, chmap: self.get_chmap(), len: self.len }
166 pub fn get_length(&self) -> usize { self.len }
169 impl NAAudioBuffer<u8> {
170 pub fn new_from_buf(info: NAAudioInfo, data: NABufferRefT<u8>, chmap: NAChannelMap) -> Self {
171 let len = data.borrow().len();
172 NAAudioBuffer { info: info, data: data, chmap: chmap, offs: Vec::new(), len: len }
177 pub enum NABufferType {
178 Video (NAVideoBuffer<u8>),
179 Video16 (NAVideoBuffer<u16>),
180 VideoPacked(NAVideoBuffer<u8>),
181 AudioU8 (NAAudioBuffer<u8>),
182 AudioI16 (NAAudioBuffer<i16>),
183 AudioI32 (NAAudioBuffer<i32>),
184 AudioF32 (NAAudioBuffer<f32>),
185 AudioPacked(NAAudioBuffer<u8>),
186 Data (NABufferRefT<u8>),
191 pub fn get_offset(&self, idx: usize) -> usize {
193 NABufferType::Video(ref vb) => vb.get_offset(idx),
194 NABufferType::Video16(ref vb) => vb.get_offset(idx),
195 NABufferType::VideoPacked(ref vb) => vb.get_offset(idx),
196 NABufferType::AudioU8(ref ab) => ab.get_offset(idx),
197 NABufferType::AudioI16(ref ab) => ab.get_offset(idx),
198 NABufferType::AudioF32(ref ab) => ab.get_offset(idx),
199 NABufferType::AudioPacked(ref ab) => ab.get_offset(idx),
203 pub fn get_vbuf(&mut self) -> Option<NAVideoBuffer<u8>> {
205 NABufferType::Video(ref vb) => Some(vb.clone()),
206 NABufferType::VideoPacked(ref vb) => Some(vb.clone()),
210 pub fn get_vbuf16(&mut self) -> Option<NAVideoBuffer<u16>> {
212 NABufferType::Video16(ref vb) => Some(vb.clone()),
216 pub fn get_abuf_u8(&mut self) -> Option<NAAudioBuffer<u8>> {
218 NABufferType::AudioU8(ref ab) => Some(ab.clone()),
219 NABufferType::AudioPacked(ref ab) => Some(ab.clone()),
223 pub fn get_abuf_i16(&mut self) -> Option<NAAudioBuffer<i16>> {
225 NABufferType::AudioI16(ref ab) => Some(ab.clone()),
229 pub fn get_abuf_i32(&mut self) -> Option<NAAudioBuffer<i32>> {
231 NABufferType::AudioI32(ref ab) => Some(ab.clone()),
235 pub fn get_abuf_f32(&mut self) -> Option<NAAudioBuffer<f32>> {
237 NABufferType::AudioF32(ref ab) => Some(ab.clone()),
243 #[derive(Debug,Clone,Copy,PartialEq)]
244 pub enum AllocatorError {
249 pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result<NABufferType, AllocatorError> {
250 let fmt = &vinfo.format;
251 let mut new_size: usize = 0;
252 let mut offs: Vec<usize> = Vec::new();
253 let mut strides: Vec<usize> = Vec::new();
255 for i in 0..fmt.get_num_comp() {
256 if fmt.get_chromaton(i) == None { return Err(AllocatorError::FormatError); }
259 let align_mod = ((1 << align) as usize) - 1;
260 let width = ((vinfo.width as usize) + align_mod) & !align_mod;
261 let height = ((vinfo.height as usize) + align_mod) & !align_mod;
262 let mut max_depth = 0;
263 let mut all_packed = true;
264 for i in 0..fmt.get_num_comp() {
265 let ochr = fmt.get_chromaton(i);
266 if let None = ochr { continue; }
267 let chr = ochr.unwrap();
268 if !chr.is_packed() {
272 max_depth = max(max_depth, chr.get_depth());
275 //todo semi-packed like NV12
276 if fmt.is_paletted() {
277 //todo various-sized palettes?
278 let stride = vinfo.get_format().get_chromaton(0).unwrap().get_linesize(width);
279 let pic_sz = stride.checked_mul(height);
280 if pic_sz == None { return Err(AllocatorError::TooLargeDimensions); }
281 let pal_size = 256 * (fmt.get_elem_size() as usize);
282 let new_size = pic_sz.unwrap().checked_add(pal_size);
283 if new_size == None { return Err(AllocatorError::TooLargeDimensions); }
285 offs.push(stride * height);
286 strides.push(stride);
287 let mut data: Vec<u8> = Vec::with_capacity(new_size.unwrap());
288 data.resize(new_size.unwrap(), 0);
289 let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
290 Ok(NABufferType::Video(buf))
291 } else if !all_packed {
292 for i in 0..fmt.get_num_comp() {
293 let ochr = fmt.get_chromaton(i);
294 if let None = ochr { continue; }
295 let chr = ochr.unwrap();
296 if !vinfo.is_flipped() {
297 offs.push(new_size as usize);
299 let stride = chr.get_linesize(width);
300 let cur_h = chr.get_height(height);
301 let cur_sz = stride.checked_mul(cur_h);
302 if cur_sz == None { return Err(AllocatorError::TooLargeDimensions); }
303 let new_sz = new_size.checked_add(cur_sz.unwrap());
304 if new_sz == None { return Err(AllocatorError::TooLargeDimensions); }
305 new_size = new_sz.unwrap();
306 if vinfo.is_flipped() {
307 offs.push(new_size as usize);
309 strides.push(stride);
312 let mut data: Vec<u8> = Vec::with_capacity(new_size);
313 data.resize(new_size, 0);
314 let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
315 Ok(NABufferType::Video(buf))
317 let mut data: Vec<u16> = Vec::with_capacity(new_size);
318 data.resize(new_size, 0);
319 let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
320 Ok(NABufferType::Video16(buf))
323 let elem_sz = fmt.get_elem_size();
324 let line_sz = width.checked_mul(elem_sz as usize);
325 if line_sz == None { return Err(AllocatorError::TooLargeDimensions); }
326 let new_sz = line_sz.unwrap().checked_mul(height);
327 if new_sz == None { return Err(AllocatorError::TooLargeDimensions); }
328 new_size = new_sz.unwrap();
329 let mut data: Vec<u8> = Vec::with_capacity(new_size);
330 data.resize(new_size, 0);
331 strides.push(line_sz.unwrap());
332 let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: Rc::new(RefCell::new(data)), info: vinfo, offs: offs, strides: strides };
333 Ok(NABufferType::VideoPacked(buf))
337 pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelMap) -> Result<NABufferType, AllocatorError> {
338 let mut offs: Vec<usize> = Vec::new();
339 if ainfo.format.is_planar() || (ainfo.channels == 1 && (ainfo.format.get_bits() % 8) == 0) {
340 let len = nsamples.checked_mul(ainfo.channels as usize);
341 if len == None { return Err(AllocatorError::TooLargeDimensions); }
342 let length = len.unwrap();
343 for i in 0..ainfo.channels {
344 offs.push((i as usize) * nsamples);
346 if ainfo.format.is_float() {
347 if ainfo.format.get_bits() == 32 {
348 let mut data: Vec<f32> = Vec::with_capacity(length);
349 data.resize(length, 0.0);
350 let buf: NAAudioBuffer<f32> = NAAudioBuffer { data: Rc::new(RefCell::new(data)), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
351 Ok(NABufferType::AudioF32(buf))
353 Err(AllocatorError::TooLargeDimensions)
356 if ainfo.format.get_bits() == 8 && !ainfo.format.is_signed() {
357 let mut data: Vec<u8> = Vec::with_capacity(length);
358 data.resize(length, 0);
359 let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: Rc::new(RefCell::new(data)), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
360 Ok(NABufferType::AudioU8(buf))
361 } else if ainfo.format.get_bits() == 16 && ainfo.format.is_signed() {
362 let mut data: Vec<i16> = Vec::with_capacity(length);
363 data.resize(length, 0);
364 let buf: NAAudioBuffer<i16> = NAAudioBuffer { data: Rc::new(RefCell::new(data)), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
365 Ok(NABufferType::AudioI16(buf))
367 Err(AllocatorError::TooLargeDimensions)
371 let len = nsamples.checked_mul(ainfo.channels as usize);
372 if len == None { return Err(AllocatorError::TooLargeDimensions); }
373 let length = ainfo.format.get_audio_size(len.unwrap() as u64);
374 let mut data: Vec<u8> = Vec::with_capacity(length);
375 data.resize(length, 0);
376 let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: Rc::new(RefCell::new(data)), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
377 Ok(NABufferType::AudioPacked(buf))
381 pub fn alloc_data_buffer(size: usize) -> Result<NABufferType, AllocatorError> {
382 let mut data: Vec<u8> = Vec::with_capacity(size);
383 data.resize(size, 0);
384 let buf: NABufferRefT<u8> = Rc::new(RefCell::new(data));
385 Ok(NABufferType::Data(buf))
388 pub fn copy_buffer(buf: NABufferType) -> NABufferType {
394 pub struct NACodecInfo {
396 properties: NACodecTypeInfo,
397 extradata: Option<Rc<Vec<u8>>>,
401 pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self {
402 let extradata = match edata {
404 Some(vec) => Some(Rc::new(vec)),
406 NACodecInfo { name: name, properties: p, extradata: extradata }
408 pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option<Rc<Vec<u8>>>) -> Self {
409 NACodecInfo { name: name, properties: p, extradata: edata }
411 pub fn get_properties(&self) -> NACodecTypeInfo { self.properties }
412 pub fn get_extradata(&self) -> Option<Rc<Vec<u8>>> {
413 if let Some(ref vec) = self.extradata { return Some(vec.clone()); }
416 pub fn get_name(&self) -> &'static str { self.name }
417 pub fn is_video(&self) -> bool {
418 if let NACodecTypeInfo::Video(_) = self.properties { return true; }
421 pub fn is_audio(&self) -> bool {
422 if let NACodecTypeInfo::Audio(_) = self.properties { return true; }
425 pub fn new_dummy() -> Rc<Self> {
426 Rc::new(DUMMY_CODEC_INFO)
428 pub fn replace_info(&self, p: NACodecTypeInfo) -> Rc<Self> {
429 Rc::new(NACodecInfo { name: self.name, properties: p, extradata: self.extradata.clone() })
433 impl fmt::Display for NACodecInfo {
434 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
435 let edata = match self.extradata.clone() {
436 None => format!("no extradata"),
437 Some(v) => format!("{} byte(s) of extradata", v.len()),
439 write!(f, "{}: {} {}", self.name, self.properties, edata)
443 pub const DUMMY_CODEC_INFO: NACodecInfo = NACodecInfo {
445 properties: NACodecTypeInfo::None,
448 #[derive(Debug,Clone)]
457 #[derive(Debug,Clone,Copy,PartialEq)]
467 impl fmt::Display for FrameType {
468 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
470 FrameType::I => write!(f, "I"),
471 FrameType::P => write!(f, "P"),
472 FrameType::B => write!(f, "B"),
473 FrameType::Skip => write!(f, "skip"),
474 FrameType::Other => write!(f, "x"),
479 #[derive(Debug,Clone,Copy)]
480 pub struct NATimeInfo {
483 duration: Option<u64>,
489 pub fn new(pts: Option<u64>, dts: Option<u64>, duration: Option<u64>, tb_num: u32, tb_den: u32) -> Self {
490 NATimeInfo { pts: pts, dts: dts, duration: duration, tb_num: tb_num, tb_den: tb_den }
492 pub fn get_pts(&self) -> Option<u64> { self.pts }
493 pub fn get_dts(&self) -> Option<u64> { self.dts }
494 pub fn get_duration(&self) -> Option<u64> { self.duration }
495 pub fn set_pts(&mut self, pts: Option<u64>) { self.pts = pts; }
496 pub fn set_dts(&mut self, dts: Option<u64>) { self.dts = dts; }
497 pub fn set_duration(&mut self, dur: Option<u64>) { self.duration = dur; }
504 buffer: NABufferType,
505 info: Rc<NACodecInfo>,
508 options: HashMap<String, NAValue>,
511 pub type NAFrameRef = Rc<RefCell<NAFrame>>;
513 fn get_plane_size(info: &NAVideoInfo, idx: usize) -> (usize, usize) {
514 let chromaton = info.get_format().get_chromaton(idx);
515 if let None = chromaton { return (0, 0); }
516 let (hs, vs) = chromaton.unwrap().get_subsampling();
517 let w = (info.get_width() + ((1 << hs) - 1)) >> hs;
518 let h = (info.get_height() + ((1 << vs) - 1)) >> vs;
523 pub fn new(ts: NATimeInfo,
526 info: Rc<NACodecInfo>,
527 options: HashMap<String, NAValue>,
528 buffer: NABufferType) -> Self {
529 NAFrame { ts: ts, buffer: buffer, info: info, ftype: ftype, key: keyframe, options: options }
531 pub fn get_info(&self) -> Rc<NACodecInfo> { self.info.clone() }
532 pub fn get_frame_type(&self) -> FrameType { self.ftype }
533 pub fn is_keyframe(&self) -> bool { self.key }
534 pub fn set_frame_type(&mut self, ftype: FrameType) { self.ftype = ftype; }
535 pub fn set_keyframe(&mut self, key: bool) { self.key = key; }
536 pub fn get_time_information(&self) -> NATimeInfo { self.ts }
537 pub fn get_pts(&self) -> Option<u64> { self.ts.get_pts() }
538 pub fn get_dts(&self) -> Option<u64> { self.ts.get_dts() }
539 pub fn get_duration(&self) -> Option<u64> { self.ts.get_duration() }
540 pub fn set_pts(&mut self, pts: Option<u64>) { self.ts.set_pts(pts); }
541 pub fn set_dts(&mut self, dts: Option<u64>) { self.ts.set_dts(dts); }
542 pub fn set_duration(&mut self, dur: Option<u64>) { self.ts.set_duration(dur); }
544 pub fn get_buffer(&self) -> NABufferType { self.buffer.clone() }
547 impl fmt::Display for NAFrame {
548 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
549 let mut foo = format!("frame type {}", self.ftype);
550 if let Some(pts) = self.ts.pts { foo = format!("{} pts {}", foo, pts); }
551 if let Some(dts) = self.ts.dts { foo = format!("{} dts {}", foo, dts); }
552 if let Some(dur) = self.ts.duration { foo = format!("{} duration {}", foo, dur); }
553 if self.key { foo = format!("{} kf", foo); }
554 write!(f, "[{}]", foo)
558 /// Possible stream types.
559 #[derive(Debug,Clone,Copy)]
561 pub enum StreamType {
568 /// any data stream (or might be an unrecognized audio/video stream)
570 /// nonexistent stream
574 impl fmt::Display for StreamType {
575 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
577 StreamType::Video => write!(f, "Video"),
578 StreamType::Audio => write!(f, "Audio"),
579 StreamType::Subtitles => write!(f, "Subtitles"),
580 StreamType::Data => write!(f, "Data"),
581 StreamType::None => write!(f, "-"),
588 pub struct NAStream {
589 media_type: StreamType,
592 info: Rc<NACodecInfo>,
597 pub fn reduce_timebase(tb_num: u32, tb_den: u32) -> (u32, u32) {
598 if tb_num == 0 { return (tb_num, tb_den); }
599 if (tb_den % tb_num) == 0 { return (1, tb_den / tb_num); }
606 else if b > a { b -= a; }
609 (tb_num / a, tb_den / a)
613 pub fn new(mt: StreamType, id: u32, info: NACodecInfo, tb_num: u32, tb_den: u32) -> Self {
614 let (n, d) = reduce_timebase(tb_num, tb_den);
615 NAStream { media_type: mt, id: id, num: 0, info: Rc::new(info), tb_num: n, tb_den: d }
617 pub fn get_id(&self) -> u32 { self.id }
618 pub fn get_num(&self) -> usize { self.num }
619 pub fn set_num(&mut self, num: usize) { self.num = num; }
620 pub fn get_info(&self) -> Rc<NACodecInfo> { self.info.clone() }
621 pub fn get_timebase(&self) -> (u32, u32) { (self.tb_num, self.tb_den) }
622 pub fn set_timebase(&mut self, tb_num: u32, tb_den: u32) {
623 let (n, d) = reduce_timebase(tb_num, tb_den);
629 impl fmt::Display for NAStream {
630 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
631 write!(f, "({}#{} @ {}/{} - {})", self.media_type, self.id, self.tb_num, self.tb_den, self.info.get_properties())
636 pub struct NAPacket {
637 stream: Rc<NAStream>,
641 // options: HashMap<String, NAValue<'a>>,
645 pub fn new(str: Rc<NAStream>, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
646 // let mut vec: Vec<u8> = Vec::new();
647 // vec.resize(size, 0);
648 NAPacket { stream: str, ts: ts, keyframe: kf, buffer: Rc::new(vec) }
650 pub fn get_stream(&self) -> Rc<NAStream> { self.stream.clone() }
651 pub fn get_time_information(&self) -> NATimeInfo { self.ts }
652 pub fn get_pts(&self) -> Option<u64> { self.ts.get_pts() }
653 pub fn get_dts(&self) -> Option<u64> { self.ts.get_dts() }
654 pub fn get_duration(&self) -> Option<u64> { self.ts.get_duration() }
655 pub fn is_keyframe(&self) -> bool { self.keyframe }
656 pub fn get_buffer(&self) -> Rc<Vec<u8>> { self.buffer.clone() }
659 impl Drop for NAPacket {
660 fn drop(&mut self) {}
663 impl fmt::Display for NAPacket {
664 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
665 let mut foo = format!("[pkt for {} size {}", self.stream, self.buffer.len());
666 if let Some(pts) = self.ts.pts { foo = format!("{} pts {}", foo, pts); }
667 if let Some(dts) = self.ts.dts { foo = format!("{} dts {}", foo, dts); }
668 if let Some(dur) = self.ts.duration { foo = format!("{} duration {}", foo, dur); }
669 if self.keyframe { foo = format!("{} kf", foo); }
675 pub trait FrameFromPacket {
676 fn new_from_pkt(pkt: &NAPacket, info: Rc<NACodecInfo>, buf: NABufferType) -> NAFrame;
677 fn fill_timestamps(&mut self, pkt: &NAPacket);
680 impl FrameFromPacket for NAFrame {
681 fn new_from_pkt(pkt: &NAPacket, info: Rc<NACodecInfo>, buf: NABufferType) -> NAFrame {
682 NAFrame::new(pkt.ts, FrameType::Other, pkt.keyframe, info, HashMap::new(), buf)
684 fn fill_timestamps(&mut self, pkt: &NAPacket) {
685 self.ts = pkt.get_time_information();