1 use std::collections::HashMap;
16 pub const SND_U8_FORMAT: NASoniton = NASoniton { bits: 8, is_be: false, packed: false, planar: false, float: false, signed: false };
18 pub const SND_S16_FORMAT: NASoniton = NASoniton { bits: 16, is_be: false, packed: false, planar: false, float: false, signed: true };
20 #[derive(Debug,Clone,Copy)]
21 pub enum NAChannelType {
22 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
26 pub fn is_center(&self) -> bool {
28 NAChannelType::C => true, NAChannelType::Ch => true,
29 NAChannelType::Cl => true, NAChannelType::Ov => true,
30 NAChannelType::LFE => true, NAChannelType::LFE2 => true,
34 pub fn is_left(&self) -> bool {
36 NAChannelType::L => true, NAChannelType::Ls => true,
37 NAChannelType::Lss => true, NAChannelType::Lc => true,
38 NAChannelType::Lh => true, NAChannelType::Lw => true,
39 NAChannelType::Lhs => true, NAChannelType::Ll => true,
40 NAChannelType::Lt => true, NAChannelType::Lo => true,
44 pub fn is_right(&self) -> bool {
46 NAChannelType::R => true, NAChannelType::Rs => true,
47 NAChannelType::Rss => true, NAChannelType::Rc => true,
48 NAChannelType::Rh => true, NAChannelType::Rw => true,
49 NAChannelType::Rhs => true, NAChannelType::Rl => true,
50 NAChannelType::Rt => true, NAChannelType::Ro => true,
56 pub struct NAChannelMap {
57 ids: Vec<NAChannelType>,
61 pub fn new() -> Self { NAChannelMap { ids: Vec::new() } }
62 pub fn add_channel(&mut self, ch: NAChannelType) {
65 pub fn num_channels(&self) -> usize {
68 pub fn get_channel(&self, idx: usize) -> NAChannelType {
71 pub fn find_channel_id(&self, t: NAChannelType) -> Option<u8> {
72 for i in 0..self.ids.len() {
73 if self.ids[i] as i32 == t as i32 { return Some(i as u8); }
81 pub struct NAAudioInfo {
89 pub fn new(sr: u32, ch: u8, fmt: NASoniton, bl: usize) -> Self {
90 NAAudioInfo { sample_rate: sr, channels: ch, format: fmt, block_len: bl }
94 #[derive(Debug,Clone,Copy)]
104 #[derive(Clone,Copy)]
105 pub struct NAPixelChromaton {
116 #[derive(Clone,Copy)]
117 pub struct NAPixelFormaton {
120 comp_info: [Option<NAPixelChromaton>; 5],
126 macro_rules! chromaton {
127 ($hs: expr, $vs: expr, $pck: expr, $d: expr, $sh: expr, $co: expr, $ne: expr) => ({
128 Some(NAPixelChromaton{ h_ss: $hs, v_ss: $vs, is_packed: $pck, depth: $d, shift: $sh, comp_offs: $co, next_elem: $ne })
130 (yuv8; $hs: expr, $vs: expr, $co: expr) => ({
131 Some(NAPixelChromaton{ h_ss: $hs, v_ss: $vs, is_packed: false, depth: 8, shift: 0, comp_offs: $co, next_elem: 1 })
133 (pal8; $co: expr) => ({
134 Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, is_packed: true, depth: 8, shift: 0, comp_offs: $co, next_elem: 3 })
139 pub const YUV420_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::YUV, components: 3,
141 chromaton!(0, 0, false, 8, 0, 0, 1),
142 chromaton!(yuv8; 1, 1, 1),
143 chromaton!(yuv8; 1, 1, 2),
145 elem_size: 0, has_alpha: false, is_palette: false };
148 pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB, components: 3,
154 elem_size: 1, has_alpha: false, is_palette: true };
158 #[derive(Clone,Copy)]
159 pub struct NAVideoInfo {
163 format: NAPixelFormaton,
167 pub fn new(w: u32, h: u32, flip: bool, fmt: NAPixelFormaton) -> Self {
168 NAVideoInfo { width: w, height: h, flipped: flip, format: fmt }
172 #[derive(Clone,Copy)]
173 pub enum NACodecTypeInfo {
180 pub struct NABuffer<'a> {
187 pub struct NACodecInfo {
188 properties: NACodecTypeInfo,
189 extradata: Option<Rc<Vec<u8>>>,
193 pub fn new(p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self {
194 let extradata = match edata {
196 Some(vec) => Some(Rc::new(vec)),
198 NACodecInfo { properties: p, extradata: extradata }
200 pub fn get_properties(&self) -> NACodecTypeInfo { self.properties }
201 pub fn get_extradata(&self) -> Option<Rc<Vec<u8>>> {
202 if let Some(ref vec) = self.extradata { return Some(vec.clone()); }
207 pub trait NABufferAllocator {
208 fn alloc_buf(info: &NACodecInfo) -> NABuffer<'static>;
212 pub enum NAValue<'a> {
221 pub struct NAFrame<'a> {
224 duration: Option<u64>,
225 buffer: &'a mut NABuffer<'a>,
226 info: &'a NACodecInfo,
227 options: HashMap<String, NAValue<'a>>,
231 pub struct NACodecContext<'a> {
232 info: &'a NACodecInfo,