Commit | Line | Data |
---|---|---|
5869fd63 | 1 | use std::collections::HashMap; |
8869d452 | 2 | use std::rc::Rc; |
5869fd63 KS |
3 | |
4 | #[allow(dead_code)] | |
8869d452 | 5 | #[derive(Copy,Clone)] |
5869fd63 KS |
6 | pub struct NASoniton { |
7 | bits: u8, | |
8 | is_be: bool, | |
9 | packed: bool, | |
10 | planar: bool, | |
11 | float: bool, | |
34e4b617 | 12 | signed: bool, |
5869fd63 KS |
13 | } |
14 | ||
15 | #[allow(dead_code)] | |
34e4b617 | 16 | pub const SND_U8_FORMAT: NASoniton = NASoniton { bits: 8, is_be: false, packed: false, planar: false, float: false, signed: false }; |
5869fd63 | 17 | #[allow(dead_code)] |
34e4b617 | 18 | pub const SND_S16_FORMAT: NASoniton = NASoniton { bits: 16, is_be: false, packed: false, planar: false, float: false, signed: true }; |
5869fd63 | 19 | |
94dbb551 KS |
20 | #[derive(Debug)] |
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 | |
23 | } | |
24 | ||
25 | impl NAChannelType { | |
26 | pub fn is_center(&self) -> bool { | |
27 | match *self { | |
28 | NAChannelType::C => true, NAChannelType::Ch => true, | |
29 | NAChannelType::Cl => true, NAChannelType::Ov => true, | |
30 | NAChannelType::LFE => true, NAChannelType::LFE2 => true, | |
31 | _ => false, | |
32 | } | |
33 | } | |
34 | pub fn is_left(&self) -> bool { | |
35 | match *self { | |
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, | |
41 | _ => false, | |
42 | } | |
43 | } | |
44 | pub fn is_right(&self) -> bool { | |
45 | match *self { | |
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, | |
51 | _ => false, | |
52 | } | |
53 | } | |
54 | } | |
55 | ||
56 | #[derive(Debug, Clone, Copy)] | |
57 | pub enum NAChannel<T: Copy> { | |
58 | None, | |
59 | C(T), | |
60 | LR(T, T), | |
61 | LsRs(T, T), | |
62 | LssRss(T, T), | |
63 | LFE(T), | |
64 | LcRc(T, T), | |
65 | LhRh(T, T), | |
66 | Ch(T), | |
67 | LFE2(T), | |
68 | LwRw(T, T), | |
69 | Ov(T), | |
70 | LhsRhs(T, T), | |
71 | LhrRhr(T, T), | |
72 | Chr(T), | |
73 | LlRl(T, T), | |
74 | Cl(T), | |
75 | LtRt(T, T), | |
76 | LoRo(T, T), | |
77 | } | |
78 | ||
79 | impl<T: Copy> NAChannel<T> { | |
80 | pub fn num_ch(&self) -> u8 { | |
81 | match *self { | |
82 | NAChannel::None => 0, | |
83 | NAChannel::C(_) => 1, | |
84 | NAChannel::LFE(_) => 1, | |
85 | NAChannel::Ch(_) => 1, | |
86 | NAChannel::LFE2(_) => 1, | |
87 | NAChannel::Ov(_) => 1, | |
88 | NAChannel::Chr(_) => 1, | |
89 | NAChannel::Cl(_) => 1, | |
90 | _ => 2, | |
91 | } | |
92 | } | |
93 | } | |
94 | ||
95 | pub struct NAChannelMap { | |
96 | ids: Vec<NAChannel<u8>>, | |
97 | nch: u8, | |
98 | } | |
99 | ||
100 | impl NAChannelMap { | |
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(); | |
104 | self.ids.push(ct); | |
105 | } | |
106 | pub fn find_channel_id(&self, t: NAChannelType) -> Option<u8> { | |
107 | None | |
108 | } | |
109 | } | |
110 | ||
5869fd63 | 111 | #[allow(dead_code)] |
8869d452 | 112 | #[derive(Clone,Copy)] |
5869fd63 KS |
113 | pub struct NAAudioInfo { |
114 | sample_rate: u32, | |
115 | channels: u8, | |
116 | format: NASoniton, | |
117 | block_len: usize, | |
118 | } | |
119 | ||
120 | impl 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 } | |
123 | } | |
124 | } | |
125 | ||
8869d452 | 126 | #[derive(Debug,Clone,Copy)] |
5869fd63 KS |
127 | pub enum ColorModel { |
128 | RGB, | |
129 | YUV, | |
130 | CMYK, | |
131 | HSV, | |
132 | LAB, | |
133 | } | |
134 | ||
135 | #[allow(dead_code)] | |
8869d452 | 136 | #[derive(Clone,Copy)] |
5869fd63 KS |
137 | pub struct NAPixelChromaton { |
138 | h_ss: u8, | |
139 | v_ss: u8, | |
140 | is_packed: bool, | |
141 | depth: u8, | |
142 | shift: u8, | |
143 | comp_offs: u8, | |
144 | next_elem: u8, | |
145 | } | |
146 | ||
147 | #[allow(dead_code)] | |
8869d452 | 148 | #[derive(Clone,Copy)] |
5869fd63 KS |
149 | pub struct NAPixelFormaton { |
150 | model: ColorModel, | |
151 | components: u8, | |
152 | comp_info: [Option<NAPixelChromaton>; 5], | |
153 | elem_size: u8, | |
154 | has_alpha: bool, | |
155 | is_palette: bool, | |
156 | } | |
157 | ||
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 }) | |
161 | }); | |
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 }) | |
164 | }); | |
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 }) | |
167 | }); | |
168 | } | |
169 | ||
170 | #[allow(dead_code)] | |
171 | pub const YUV420_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::YUV, components: 3, | |
172 | comp_info: [ | |
173 | chromaton!(0, 0, false, 8, 0, 0, 1), | |
174 | chromaton!(yuv8; 1, 1, 1), | |
175 | chromaton!(yuv8; 1, 1, 2), | |
176 | None, None], | |
177 | elem_size: 0, has_alpha: false, is_palette: false }; | |
178 | ||
179 | #[allow(dead_code)] | |
180 | pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB, components: 3, | |
181 | comp_info: [ | |
182 | chromaton!(pal8; 0), | |
183 | chromaton!(pal8; 1), | |
184 | chromaton!(pal8; 2), | |
185 | None, None], | |
186 | elem_size: 1, has_alpha: false, is_palette: true }; | |
187 | ||
188 | ||
189 | #[allow(dead_code)] | |
8869d452 | 190 | #[derive(Clone,Copy)] |
5869fd63 KS |
191 | pub struct NAVideoInfo { |
192 | width: u32, | |
193 | height: u32, | |
194 | flipped: bool, | |
195 | format: NAPixelFormaton, | |
196 | } | |
197 | ||
198 | impl NAVideoInfo { | |
199 | pub fn new(w: u32, h: u32, flip: bool, fmt: NAPixelFormaton) -> Self { | |
200 | NAVideoInfo { width: w, height: h, flipped: flip, format: fmt } | |
201 | } | |
202 | } | |
203 | ||
8869d452 | 204 | #[derive(Clone,Copy)] |
5869fd63 KS |
205 | pub enum NACodecTypeInfo { |
206 | None, | |
207 | Audio(NAAudioInfo), | |
208 | Video(NAVideoInfo), | |
209 | } | |
210 | ||
211 | #[allow(dead_code)] | |
212 | pub struct NABuffer<'a> { | |
213 | id: u64, | |
214 | data: &'a mut [u8], | |
215 | } | |
216 | ||
217 | #[allow(dead_code)] | |
8869d452 KS |
218 | #[derive(Clone)] |
219 | pub struct NACodecInfo { | |
5869fd63 | 220 | properties: NACodecTypeInfo, |
8869d452 | 221 | extradata: Option<Rc<Vec<u8>>>, |
5869fd63 KS |
222 | } |
223 | ||
8869d452 KS |
224 | impl NACodecInfo { |
225 | pub fn new(p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self { | |
226 | let extradata = match edata { | |
227 | None => None, | |
228 | Some(vec) => Some(Rc::new(vec)), | |
229 | }; | |
230 | NACodecInfo { properties: p, extradata: extradata } | |
231 | } | |
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()); } | |
235 | None | |
5869fd63 KS |
236 | } |
237 | } | |
238 | ||
239 | pub trait NABufferAllocator { | |
240 | fn alloc_buf(info: &NACodecInfo) -> NABuffer<'static>; | |
241 | } | |
242 | ||
243 | #[derive(Debug)] | |
244 | pub enum NAValue<'a> { | |
245 | None, | |
246 | Int(i32), | |
247 | Long(i64), | |
248 | String(String), | |
249 | Data(&'a [u8]), | |
250 | } | |
251 | ||
252 | #[allow(dead_code)] | |
253 | pub struct NAFrame<'a> { | |
254 | pts: Option<u64>, | |
255 | dts: Option<u64>, | |
256 | duration: Option<u64>, | |
257 | buffer: &'a mut NABuffer<'a>, | |
8869d452 | 258 | info: &'a NACodecInfo, |
5869fd63 KS |
259 | options: HashMap<String, NAValue<'a>>, |
260 | } | |
261 | ||
262 | #[allow(dead_code)] | |
263 | pub struct NACodecContext<'a> { | |
8869d452 | 264 | info: &'a NACodecInfo, |
5869fd63 | 265 | } |