X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=src%2Fframe.rs;h=7455b72a393bd298819b054a680a2d0187f60fc3;hb=b58d7656167205d9e8f48739f58637689d369314;hp=6431bc2e944cf5eb13eca58f5a9d5b2bead3f9a0;hpb=34e4b6177aee170ab36ba9a91185cab1d51266ff;p=nihav.git diff --git a/src/frame.rs b/src/frame.rs index 6431bc2..7455b72 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -1,21 +1,7 @@ use std::collections::HashMap; +use std::fmt; use std::rc::Rc; - -#[allow(dead_code)] -#[derive(Copy,Clone)] -pub struct NASoniton { - bits: u8, - is_be: bool, - packed: bool, - planar: bool, - float: bool, - signed: bool, -} - -#[allow(dead_code)] -pub const SND_U8_FORMAT: NASoniton = NASoniton { bits: 8, is_be: false, packed: false, planar: false, float: false, signed: false }; -#[allow(dead_code)] -pub const SND_S16_FORMAT: NASoniton = NASoniton { bits: 16, is_be: false, packed: false, planar: false, float: false, signed: true }; +use formats::*; #[allow(dead_code)] #[derive(Clone,Copy)] @@ -32,69 +18,12 @@ impl NAAudioInfo { } } -#[derive(Debug,Clone,Copy)] -pub enum ColorModel { - RGB, - YUV, - CMYK, - HSV, - LAB, -} - -#[allow(dead_code)] -#[derive(Clone,Copy)] -pub struct NAPixelChromaton { - h_ss: u8, - v_ss: u8, - is_packed: bool, - depth: u8, - shift: u8, - comp_offs: u8, - next_elem: u8, -} - -#[allow(dead_code)] -#[derive(Clone,Copy)] -pub struct NAPixelFormaton { - model: ColorModel, - components: u8, - comp_info: [Option; 5], - elem_size: u8, - has_alpha: bool, - is_palette: bool, -} - -macro_rules! chromaton { - ($hs: expr, $vs: expr, $pck: expr, $d: expr, $sh: expr, $co: expr, $ne: expr) => ({ - Some(NAPixelChromaton{ h_ss: $hs, v_ss: $vs, is_packed: $pck, depth: $d, shift: $sh, comp_offs: $co, next_elem: $ne }) - }); - (yuv8; $hs: expr, $vs: expr, $co: expr) => ({ - Some(NAPixelChromaton{ h_ss: $hs, v_ss: $vs, is_packed: false, depth: 8, shift: 0, comp_offs: $co, next_elem: 1 }) - }); - (pal8; $co: expr) => ({ - Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, is_packed: true, depth: 8, shift: 0, comp_offs: $co, next_elem: 3 }) - }); +impl fmt::Display for NAAudioInfo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{} Hz, {} ch", self.sample_rate, self.channels) + } } -#[allow(dead_code)] -pub const YUV420_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::YUV, components: 3, - comp_info: [ - chromaton!(0, 0, false, 8, 0, 0, 1), - chromaton!(yuv8; 1, 1, 1), - chromaton!(yuv8; 1, 1, 2), - None, None], - elem_size: 0, has_alpha: false, is_palette: false }; - -#[allow(dead_code)] -pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB, components: 3, - comp_info: [ - chromaton!(pal8; 0), - chromaton!(pal8; 1), - chromaton!(pal8; 2), - None, None], - elem_size: 1, has_alpha: false, is_palette: true }; - - #[allow(dead_code)] #[derive(Clone,Copy)] pub struct NAVideoInfo { @@ -110,6 +39,12 @@ impl NAVideoInfo { } } +impl fmt::Display for NAVideoInfo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}x{}", self.width, self.height) + } +} + #[derive(Clone,Copy)] pub enum NACodecTypeInfo { None, @@ -117,6 +52,18 @@ pub enum NACodecTypeInfo { Video(NAVideoInfo), } +impl fmt::Display for NACodecTypeInfo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let ret = match *self { + NACodecTypeInfo::None => format!(""), + NACodecTypeInfo::Audio(fmt) => format!("{}", fmt), + NACodecTypeInfo::Video(fmt) => format!("{}", fmt), + }; + write!(f, "{}", ret) + } +} + + #[allow(dead_code)] pub struct NABuffer<'a> { id: u64, @@ -126,17 +73,18 @@ pub struct NABuffer<'a> { #[allow(dead_code)] #[derive(Clone)] pub struct NACodecInfo { + name: &'static str, properties: NACodecTypeInfo, extradata: Option>>, } impl NACodecInfo { - pub fn new(p: NACodecTypeInfo, edata: Option>) -> Self { + pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option>) -> Self { let extradata = match edata { None => None, Some(vec) => Some(Rc::new(vec)), }; - NACodecInfo { properties: p, extradata: extradata } + NACodecInfo { name: name, properties: p, extradata: extradata } } pub fn get_properties(&self) -> NACodecTypeInfo { self.properties } pub fn get_extradata(&self) -> Option>> {