]>
Commit | Line | Data |
---|---|---|
5869fd63 | 1 | use std::collections::HashMap; |
83e603fa | 2 | use std::fmt; |
8869d452 | 3 | use std::rc::Rc; |
fba6f8e4 | 4 | use formats::*; |
94dbb551 | 5 | |
5869fd63 | 6 | #[allow(dead_code)] |
8869d452 | 7 | #[derive(Clone,Copy)] |
5869fd63 KS |
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 | ||
83e603fa KS |
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 | ||
5869fd63 | 27 | #[allow(dead_code)] |
8869d452 | 28 | #[derive(Clone,Copy)] |
5869fd63 KS |
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 | ||
83e603fa KS |
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 | ||
8869d452 | 48 | #[derive(Clone,Copy)] |
5869fd63 KS |
49 | pub enum NACodecTypeInfo { |
50 | None, | |
51 | Audio(NAAudioInfo), | |
52 | Video(NAVideoInfo), | |
53 | } | |
54 | ||
83e603fa KS |
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 | ||
5869fd63 KS |
67 | #[allow(dead_code)] |
68 | pub struct NABuffer<'a> { | |
69 | id: u64, | |
70 | data: &'a mut [u8], | |
71 | } | |
72 | ||
73 | #[allow(dead_code)] | |
8869d452 KS |
74 | #[derive(Clone)] |
75 | pub struct NACodecInfo { | |
ccae5343 | 76 | name: &'static str, |
5869fd63 | 77 | properties: NACodecTypeInfo, |
8869d452 | 78 | extradata: Option<Rc<Vec<u8>>>, |
5869fd63 KS |
79 | } |
80 | ||
8869d452 | 81 | impl NACodecInfo { |
ccae5343 | 82 | pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self { |
8869d452 KS |
83 | let extradata = match edata { |
84 | None => None, | |
85 | Some(vec) => Some(Rc::new(vec)), | |
86 | }; | |
ccae5343 | 87 | NACodecInfo { name: name, properties: p, extradata: extradata } |
8869d452 KS |
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 | |
5869fd63 KS |
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>, | |
8869d452 | 115 | info: &'a NACodecInfo, |
5869fd63 KS |
116 | options: HashMap<String, NAValue<'a>>, |
117 | } | |
118 | ||
119 | #[allow(dead_code)] | |
120 | pub struct NACodecContext<'a> { | |
8869d452 | 121 | info: &'a NACodecInfo, |
5869fd63 | 122 | } |