+ /// Prints internal buffer layout.
+ pub fn print_buffer_metadata(&self) {
+ match *self {
+ NABufferType::Video(ref buf) => buf.print_contents("8-bit"),
+ NABufferType::Video16(ref buf) => buf.print_contents("16-bit"),
+ NABufferType::Video32(ref buf) => buf.print_contents("32-bit"),
+ NABufferType::VideoPacked(ref buf) => buf.print_contents("packed"),
+ NABufferType::AudioU8(ref buf) => buf.print_contents("8-bit unsigned integer"),
+ NABufferType::AudioI16(ref buf) => buf.print_contents("16-bit integer"),
+ NABufferType::AudioI32(ref buf) => buf.print_contents("32-bit integer"),
+ NABufferType::AudioF32(ref buf) => buf.print_contents("32-bit float"),
+ NABufferType::AudioPacked(ref buf) => buf.print_contents("packed"),
+ NABufferType::Data(ref buf) => { println!("Data buffer, len = {}", buf.len()); },
+ NABufferType::None => { println!("No buffer"); },
+ };
+ }
+}
+
+const NA_SIMPLE_VFRAME_COMPONENTS: usize = 4;
+/// Simplified decoded frame data.
+pub struct NASimpleVideoFrame<'a, T: Copy> {
+ /// Widths of each picture component.
+ pub width: [usize; NA_SIMPLE_VFRAME_COMPONENTS],
+ /// Heights of each picture component.
+ pub height: [usize; NA_SIMPLE_VFRAME_COMPONENTS],
+ /// Orientation (upside-down or downside-up) flag.
+ pub flip: bool,
+ /// Strides for each component.
+ pub stride: [usize; NA_SIMPLE_VFRAME_COMPONENTS],
+ /// Start of each component.
+ pub offset: [usize; NA_SIMPLE_VFRAME_COMPONENTS],
+ /// Number of components.
+ pub components: usize,
+ /// Pointer to the picture pixel data.
+ pub data: &'a mut [T],
+}
+
+impl<'a, T:Copy> NASimpleVideoFrame<'a, T> {
+ /// Constructs a new instance of `NASimpleVideoFrame` from `NAVideoBuffer`.
+ pub fn from_video_buf(vbuf: &'a mut NAVideoBuffer<T>) -> Option<Self> {
+ let vinfo = vbuf.get_info();
+ let components = vinfo.format.components as usize;
+ if components > NA_SIMPLE_VFRAME_COMPONENTS {
+ return None;
+ }
+ let mut w: [usize; NA_SIMPLE_VFRAME_COMPONENTS] = [0; NA_SIMPLE_VFRAME_COMPONENTS];
+ let mut h: [usize; NA_SIMPLE_VFRAME_COMPONENTS] = [0; NA_SIMPLE_VFRAME_COMPONENTS];
+ let mut s: [usize; NA_SIMPLE_VFRAME_COMPONENTS] = [0; NA_SIMPLE_VFRAME_COMPONENTS];
+ let mut o: [usize; NA_SIMPLE_VFRAME_COMPONENTS] = [0; NA_SIMPLE_VFRAME_COMPONENTS];
+ for comp in 0..components {
+ let (width, height) = vbuf.get_dimensions(comp);
+ w[comp] = width;
+ h[comp] = height;
+ s[comp] = vbuf.get_stride(comp);
+ o[comp] = vbuf.get_offset(comp);
+ }
+ let flip = vinfo.flipped;
+ Some(NASimpleVideoFrame {
+ width: w,
+ height: h,
+ flip,
+ stride: s,
+ offset: o,
+ components,
+ data: vbuf.data.as_mut_slice(),
+ })
+ }