print more info for streams
[nihav.git] / src / frame.rs
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 properties: NACodecTypeInfo,
77 extradata: Option<Rc<Vec<u8>>>,
78 }
79
80 impl NACodecInfo {
81 pub fn new(p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self {
82 let extradata = match edata {
83 None => None,
84 Some(vec) => Some(Rc::new(vec)),
85 };
86 NACodecInfo { properties: p, extradata: extradata }
87 }
88 pub fn get_properties(&self) -> NACodecTypeInfo { self.properties }
89 pub fn get_extradata(&self) -> Option<Rc<Vec<u8>>> {
90 if let Some(ref vec) = self.extradata { return Some(vec.clone()); }
91 None
92 }
93 }
94
95 pub trait NABufferAllocator {
96 fn alloc_buf(info: &NACodecInfo) -> NABuffer<'static>;
97 }
98
99 #[derive(Debug)]
100 pub enum NAValue<'a> {
101 None,
102 Int(i32),
103 Long(i64),
104 String(String),
105 Data(&'a [u8]),
106 }
107
108 #[allow(dead_code)]
109 pub struct NAFrame<'a> {
110 pts: Option<u64>,
111 dts: Option<u64>,
112 duration: Option<u64>,
113 buffer: &'a mut NABuffer<'a>,
114 info: &'a NACodecInfo,
115 options: HashMap<String, NAValue<'a>>,
116 }
117
118 #[allow(dead_code)]
119 pub struct NACodecContext<'a> {
120 info: &'a NACodecInfo,
121 }