| 1 | use std::collections::HashMap; |
| 2 | use std::fmt; |
| 3 | use std::rc::Rc; |
| 4 | use formats::*; |
| 5 | |
| 6 | #[allow(dead_code)] |
| 7 | #[derive(Clone,Copy)] |
| 8 | pub struct NAAudioInfo { |
| 9 | sample_rate: u32, |
| 10 | channels: u8, |
| 11 | format: NASoniton, |
| 12 | block_len: usize, |
| 13 | } |
| 14 | |
| 15 | impl NAAudioInfo { |
| 16 | pub fn new(sr: u32, ch: u8, fmt: NASoniton, bl: usize) -> Self { |
| 17 | NAAudioInfo { sample_rate: sr, channels: ch, format: fmt, block_len: bl } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | impl fmt::Display for NAAudioInfo { |
| 22 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 23 | write!(f, "{} Hz, {} ch", self.sample_rate, self.channels) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | #[allow(dead_code)] |
| 28 | #[derive(Clone,Copy)] |
| 29 | pub struct NAVideoInfo { |
| 30 | width: u32, |
| 31 | height: u32, |
| 32 | flipped: bool, |
| 33 | format: NAPixelFormaton, |
| 34 | } |
| 35 | |
| 36 | impl NAVideoInfo { |
| 37 | pub fn new(w: u32, h: u32, flip: bool, fmt: NAPixelFormaton) -> Self { |
| 38 | NAVideoInfo { width: w, height: h, flipped: flip, format: fmt } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | impl fmt::Display for NAVideoInfo { |
| 43 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 44 | write!(f, "{}x{}", self.width, self.height) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | #[derive(Clone,Copy)] |
| 49 | pub enum NACodecTypeInfo { |
| 50 | None, |
| 51 | Audio(NAAudioInfo), |
| 52 | Video(NAVideoInfo), |
| 53 | } |
| 54 | |
| 55 | impl fmt::Display for NACodecTypeInfo { |
| 56 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 57 | let ret = match *self { |
| 58 | NACodecTypeInfo::None => format!(""), |
| 59 | NACodecTypeInfo::Audio(fmt) => format!("{}", fmt), |
| 60 | NACodecTypeInfo::Video(fmt) => format!("{}", fmt), |
| 61 | }; |
| 62 | write!(f, "{}", ret) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | |
| 67 | #[allow(dead_code)] |
| 68 | pub struct NABuffer<'a> { |
| 69 | id: u64, |
| 70 | data: &'a mut [u8], |
| 71 | } |
| 72 | |
| 73 | #[allow(dead_code)] |
| 74 | #[derive(Clone)] |
| 75 | pub struct NACodecInfo { |
| 76 | name: &'static str, |
| 77 | properties: NACodecTypeInfo, |
| 78 | extradata: Option<Rc<Vec<u8>>>, |
| 79 | } |
| 80 | |
| 81 | impl NACodecInfo { |
| 82 | pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self { |
| 83 | let extradata = match edata { |
| 84 | None => None, |
| 85 | Some(vec) => Some(Rc::new(vec)), |
| 86 | }; |
| 87 | NACodecInfo { name: name, properties: p, extradata: extradata } |
| 88 | } |
| 89 | pub fn get_properties(&self) -> NACodecTypeInfo { self.properties } |
| 90 | pub fn get_extradata(&self) -> Option<Rc<Vec<u8>>> { |
| 91 | if let Some(ref vec) = self.extradata { return Some(vec.clone()); } |
| 92 | None |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | pub trait NABufferAllocator { |
| 97 | fn alloc_buf(info: &NACodecInfo) -> NABuffer<'static>; |
| 98 | } |
| 99 | |
| 100 | #[derive(Debug)] |
| 101 | pub enum NAValue<'a> { |
| 102 | None, |
| 103 | Int(i32), |
| 104 | Long(i64), |
| 105 | String(String), |
| 106 | Data(&'a [u8]), |
| 107 | } |
| 108 | |
| 109 | #[allow(dead_code)] |
| 110 | pub struct NAFrame<'a> { |
| 111 | pts: Option<u64>, |
| 112 | dts: Option<u64>, |
| 113 | duration: Option<u64>, |
| 114 | buffer: &'a mut NABuffer<'a>, |
| 115 | info: &'a NACodecInfo, |
| 116 | options: HashMap<String, NAValue<'a>>, |
| 117 | } |
| 118 | |
| 119 | #[allow(dead_code)] |
| 120 | pub struct NACodecContext<'a> { |
| 121 | info: &'a NACodecInfo, |
| 122 | } |