]> git.nihav.org Git - nihav.git/blobdiff - src/frame.rs
first stab at channel map
[nihav.git] / src / frame.rs
index 066a0166ec1e005241955f4cdd4efadcc70597f8..1c57d7dccaed725431882e9c9477a53afda1a36c 100644 (file)
 use std::collections::HashMap;
+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 };
+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 };
+pub const SND_S16_FORMAT: NASoniton = NASoniton { bits: 16, is_be: false, packed: false, planar: false, float: false, signed: true };
+
+#[derive(Debug)]
+pub enum NAChannelType {
+    C, L, R, Ls, Rs, Lss, Rss, LFE, Lc, Rc, Lh, Rh, Ch, LFE2, Lw, Rw, Ov, Lhs, Rhs, Chr, Ll, Rl, Cl, Lt, Rt, Lo, Ro
+}
+
+impl NAChannelType {
+    pub fn is_center(&self) -> bool {
+        match *self {
+            NAChannelType::C => true,   NAChannelType::Ch => true,
+            NAChannelType::Cl => true,  NAChannelType::Ov => true,
+            NAChannelType::LFE => true, NAChannelType::LFE2 => true,
+            _ => false,
+        }
+    }
+    pub fn is_left(&self) -> bool {
+        match *self {
+            NAChannelType::L   => true, NAChannelType::Ls => true,
+            NAChannelType::Lss => true, NAChannelType::Lc => true,
+            NAChannelType::Lh  => true, NAChannelType::Lw => true,
+            NAChannelType::Lhs => true, NAChannelType::Ll => true,
+            NAChannelType::Lt  => true, NAChannelType::Lo => true,
+            _ => false,
+        }
+    }
+    pub fn is_right(&self) -> bool {
+        match *self {
+            NAChannelType::R   => true, NAChannelType::Rs => true,
+            NAChannelType::Rss => true, NAChannelType::Rc => true,
+            NAChannelType::Rh  => true, NAChannelType::Rw => true,
+            NAChannelType::Rhs => true, NAChannelType::Rl => true,
+            NAChannelType::Rt  => true, NAChannelType::Ro => true,
+            _ => false,
+        }
+    }
+}
+
+#[derive(Debug, Clone, Copy)]
+pub enum NAChannel<T: Copy> {
+    None,
+    C(T),
+    LR(T, T),
+    LsRs(T, T),
+    LssRss(T, T),
+    LFE(T),
+    LcRc(T, T),
+    LhRh(T, T),
+    Ch(T),
+    LFE2(T),
+    LwRw(T, T),
+    Ov(T),
+    LhsRhs(T, T),
+    LhrRhr(T, T),
+    Chr(T),
+    LlRl(T, T),
+    Cl(T),
+    LtRt(T, T),
+    LoRo(T, T),
+}
+
+impl<T: Copy> NAChannel<T> {
+    pub fn num_ch(&self) -> u8 {
+        match *self {
+           NAChannel::None    => 0, 
+           NAChannel::C(_)    => 1,
+           NAChannel::LFE(_)  => 1,
+           NAChannel::Ch(_)   => 1,
+           NAChannel::LFE2(_) => 1,
+           NAChannel::Ov(_)   => 1,
+           NAChannel::Chr(_)  => 1,
+           NAChannel::Cl(_)   => 1,
+           _                  => 2,
+        }
+    }
+}
+
+pub struct NAChannelMap {
+    ids: Vec<NAChannel<u8>>,
+    nch: u8,
+}
+
+impl NAChannelMap {
+    pub fn new() -> Self { NAChannelMap { ids: Vec::new(), nch: 0 } }
+    pub fn add_channels(&mut self, ct: NAChannel<u8>) {
+        self.nch += ct.num_ch();
+        self.ids.push(ct);
+    }
+    pub fn find_channel_id(&self, t: NAChannelType) -> Option<u8> {
+        None
+    }
+}
 
 #[allow(dead_code)]
+#[derive(Clone,Copy)]
 pub struct NAAudioInfo {
     sample_rate: u32,
     channels:    u8,
@@ -28,7 +123,7 @@ impl NAAudioInfo {
     }
 }
 
-#[derive(Debug)]
+#[derive(Debug,Clone,Copy)]
 pub enum ColorModel {
     RGB,
     YUV,
@@ -38,6 +133,7 @@ pub enum ColorModel {
 }
 
 #[allow(dead_code)]
+#[derive(Clone,Copy)]
 pub struct NAPixelChromaton {
     h_ss:           u8,
     v_ss:           u8,
@@ -49,6 +145,7 @@ pub struct NAPixelChromaton {
 }
 
 #[allow(dead_code)]
+#[derive(Clone,Copy)]
 pub struct NAPixelFormaton {
     model:      ColorModel,
     components: u8,
@@ -90,6 +187,7 @@ pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RG
 
 
 #[allow(dead_code)]
+#[derive(Clone,Copy)]
 pub struct NAVideoInfo {
     width:      u32,
     height:     u32,
@@ -103,6 +201,7 @@ impl NAVideoInfo {
     }
 }
 
+#[derive(Clone,Copy)]
 pub enum NACodecTypeInfo {
     None,
     Audio(NAAudioInfo),
@@ -116,14 +215,24 @@ pub struct NABuffer<'a> {
 }
 
 #[allow(dead_code)]
-pub struct NACodecInfo<'a> {
+#[derive(Clone)]
+pub struct NACodecInfo {
     properties: NACodecTypeInfo,
-    extradata:  Option<&'a[u8]>,
+    extradata:  Option<Rc<Vec<u8>>>,
 }
 
-impl<'a> NACodecInfo<'a> {
-    pub fn new(p: NACodecTypeInfo, edata: Option<&'a[u8]>) -> Self {
-        NACodecInfo { properties: p, extradata: edata }
+impl NACodecInfo {
+    pub fn new(p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self {
+        let extradata = match edata {
+            None => None,
+            Some(vec) => Some(Rc::new(vec)),
+        };
+        NACodecInfo { properties: p, extradata: extradata }
+    }
+    pub fn get_properties(&self) -> NACodecTypeInfo { self.properties }
+    pub fn get_extradata(&self) -> Option<Rc<Vec<u8>>> {
+        if let Some(ref vec) = self.extradata { return Some(vec.clone()); }
+        None
     }
 }
 
@@ -146,11 +255,11 @@ pub struct NAFrame<'a> {
     dts:            Option<u64>,
     duration:       Option<u64>,
     buffer:         &'a mut NABuffer<'a>,
-    info:           &'a NACodecInfo<'a>,
+    info:           &'a NACodecInfo,
     options:        HashMap<String, NAValue<'a>>,
 }
 
 #[allow(dead_code)]
 pub struct NACodecContext<'a> {
-    info:           &'a NACodecInfo<'a>,
+    info:           &'a NACodecInfo,
 }