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 };
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 #[derive(Debug, Clone, Copy)]
57 pub enum NAChannel<T: Copy> {
79 impl<T: Copy> NAChannel<T> {
80 pub fn num_ch(&self) -> u8 {
84 NAChannel::LFE(_) => 1,
85 NAChannel::Ch(_) => 1,
86 NAChannel::LFE2(_) => 1,
87 NAChannel::Ov(_) => 1,
88 NAChannel::Chr(_) => 1,
89 NAChannel::Cl(_) => 1,
95 pub struct NAChannelMap {
96 ids: Vec<NAChannel<u8>>,
101 pub fn new() -> Self { NAChannelMap { ids: Vec::new(), nch: 0 } }
102 pub fn add_channels(&mut self, ct: NAChannel<u8>) {
103 self.nch += ct.num_ch();
106 pub fn find_channel_id(&self, t: NAChannelType) -> Option<u8> {
112 #[derive(Clone,Copy)]
113 pub struct NAAudioInfo {
121 pub fn new(sr: u32, ch: u8, fmt: NASoniton, bl: usize) -> Self {
122 NAAudioInfo { sample_rate: sr, channels: ch, format: fmt, block_len: bl }
126 #[derive(Debug,Clone,Copy)]
127 pub enum ColorModel {
136 #[derive(Clone,Copy)]
137 pub struct NAPixelChromaton {
148 #[derive(Clone,Copy)]
149 pub struct NAPixelFormaton {
152 comp_info: [Option<NAPixelChromaton>; 5],
158 macro_rules! chromaton {
159 ($hs: expr, $vs: expr, $pck: expr, $d: expr, $sh: expr, $co: expr, $ne: expr) => ({
160 Some(NAPixelChromaton{ h_ss: $hs, v_ss: $vs, is_packed: $pck, depth: $d, shift: $sh, comp_offs: $co, next_elem: $ne })
162 (yuv8; $hs: expr, $vs: expr, $co: expr) => ({
163 Some(NAPixelChromaton{ h_ss: $hs, v_ss: $vs, is_packed: false, depth: 8, shift: 0, comp_offs: $co, next_elem: 1 })
165 (pal8; $co: expr) => ({
166 Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, is_packed: true, depth: 8, shift: 0, comp_offs: $co, next_elem: 3 })
171 pub const YUV420_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::YUV, components: 3,
173 chromaton!(0, 0, false, 8, 0, 0, 1),
174 chromaton!(yuv8; 1, 1, 1),
175 chromaton!(yuv8; 1, 1, 2),
177 elem_size: 0, has_alpha: false, is_palette: false };
180 pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB, components: 3,
186 elem_size: 1, has_alpha: false, is_palette: true };
190 #[derive(Clone,Copy)]
191 pub struct NAVideoInfo {
195 format: NAPixelFormaton,
199 pub fn new(w: u32, h: u32, flip: bool, fmt: NAPixelFormaton) -> Self {
200 NAVideoInfo { width: w, height: h, flipped: flip, format: fmt }
204 #[derive(Clone,Copy)]
205 pub enum NACodecTypeInfo {
212 pub struct NABuffer<'a> {
219 pub struct NACodecInfo {
220 properties: NACodecTypeInfo,
221 extradata: Option<Rc<Vec<u8>>>,
225 pub fn new(p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self {
226 let extradata = match edata {
228 Some(vec) => Some(Rc::new(vec)),
230 NACodecInfo { properties: p, extradata: extradata }
232 pub fn get_properties(&self) -> NACodecTypeInfo { self.properties }
233 pub fn get_extradata(&self) -> Option<Rc<Vec<u8>>> {
234 if let Some(ref vec) = self.extradata { return Some(vec.clone()); }
239 pub trait NABufferAllocator {
240 fn alloc_buf(info: &NACodecInfo) -> NABuffer<'static>;
244 pub enum NAValue<'a> {
253 pub struct NAFrame<'a> {
256 duration: Option<u64>,
257 buffer: &'a mut NABuffer<'a>,
258 info: &'a NACodecInfo,
259 options: HashMap<String, NAValue<'a>>,
263 pub struct NACodecContext<'a> {
264 info: &'a NACodecInfo,