simplify names in register
[nihav.git] / src / frame.rs
CommitLineData
5869fd63 1use std::collections::HashMap;
83e603fa 2use std::fmt;
8869d452 3use std::rc::Rc;
fba6f8e4 4use formats::*;
94dbb551 5
5869fd63 6#[allow(dead_code)]
8869d452 7#[derive(Clone,Copy)]
5869fd63
KS
8pub struct NAAudioInfo {
9 sample_rate: u32,
10 channels: u8,
11 format: NASoniton,
12 block_len: usize,
13}
14
15impl 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
21impl 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
29pub struct NAVideoInfo {
30 width: u32,
31 height: u32,
32 flipped: bool,
33 format: NAPixelFormaton,
34}
35
36impl 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
42impl 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
49pub enum NACodecTypeInfo {
50 None,
51 Audio(NAAudioInfo),
52 Video(NAVideoInfo),
53}
54
83e603fa
KS
55impl 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)]
68pub struct NABuffer<'a> {
69 id: u64,
70 data: &'a mut [u8],
71}
72
73#[allow(dead_code)]
8869d452
KS
74#[derive(Clone)]
75pub struct NACodecInfo {
ccae5343 76 name: &'static str,
5869fd63 77 properties: NACodecTypeInfo,
8869d452 78 extradata: Option<Rc<Vec<u8>>>,
5869fd63
KS
79}
80
8869d452 81impl 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
96pub trait NABufferAllocator {
97 fn alloc_buf(info: &NACodecInfo) -> NABuffer<'static>;
98}
99
100#[derive(Debug)]
101pub enum NAValue<'a> {
102 None,
103 Int(i32),
104 Long(i64),
105 String(String),
106 Data(&'a [u8]),
107}
108
109#[allow(dead_code)]
110pub 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)]
120pub struct NACodecContext<'a> {
8869d452 121 info: &'a NACodecInfo,
5869fd63 122}