| 1 | use std::collections::HashMap; |
| 2 | |
| 3 | #[allow(dead_code)] |
| 4 | pub struct NASoniton { |
| 5 | bits: u8, |
| 6 | is_be: bool, |
| 7 | packed: bool, |
| 8 | planar: bool, |
| 9 | float: bool, |
| 10 | } |
| 11 | |
| 12 | #[allow(dead_code)] |
| 13 | pub const SND_U8_FORMAT: NASoniton = NASoniton { bits: 8, is_be: false, packed: false, planar: false, float: false }; |
| 14 | #[allow(dead_code)] |
| 15 | pub const SND_S16_FORMAT: NASoniton = NASoniton { bits: 16, is_be: false, packed: false, planar: false, float: false }; |
| 16 | |
| 17 | #[allow(dead_code)] |
| 18 | pub struct NAAudioInfo { |
| 19 | sample_rate: u32, |
| 20 | channels: u8, |
| 21 | format: NASoniton, |
| 22 | block_len: usize, |
| 23 | } |
| 24 | |
| 25 | impl NAAudioInfo { |
| 26 | pub fn new(sr: u32, ch: u8, fmt: NASoniton, bl: usize) -> Self { |
| 27 | NAAudioInfo { sample_rate: sr, channels: ch, format: fmt, block_len: bl } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | #[derive(Debug)] |
| 32 | pub enum ColorModel { |
| 33 | RGB, |
| 34 | YUV, |
| 35 | CMYK, |
| 36 | HSV, |
| 37 | LAB, |
| 38 | } |
| 39 | |
| 40 | #[allow(dead_code)] |
| 41 | pub struct NAPixelChromaton { |
| 42 | h_ss: u8, |
| 43 | v_ss: u8, |
| 44 | is_packed: bool, |
| 45 | depth: u8, |
| 46 | shift: u8, |
| 47 | comp_offs: u8, |
| 48 | next_elem: u8, |
| 49 | } |
| 50 | |
| 51 | #[allow(dead_code)] |
| 52 | pub struct NAPixelFormaton { |
| 53 | model: ColorModel, |
| 54 | components: u8, |
| 55 | comp_info: [Option<NAPixelChromaton>; 5], |
| 56 | elem_size: u8, |
| 57 | has_alpha: bool, |
| 58 | is_palette: bool, |
| 59 | } |
| 60 | |
| 61 | macro_rules! chromaton { |
| 62 | ($hs: expr, $vs: expr, $pck: expr, $d: expr, $sh: expr, $co: expr, $ne: expr) => ({ |
| 63 | Some(NAPixelChromaton{ h_ss: $hs, v_ss: $vs, is_packed: $pck, depth: $d, shift: $sh, comp_offs: $co, next_elem: $ne }) |
| 64 | }); |
| 65 | (yuv8; $hs: expr, $vs: expr, $co: expr) => ({ |
| 66 | Some(NAPixelChromaton{ h_ss: $hs, v_ss: $vs, is_packed: false, depth: 8, shift: 0, comp_offs: $co, next_elem: 1 }) |
| 67 | }); |
| 68 | (pal8; $co: expr) => ({ |
| 69 | Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, is_packed: true, depth: 8, shift: 0, comp_offs: $co, next_elem: 3 }) |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | #[allow(dead_code)] |
| 74 | pub const YUV420_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::YUV, components: 3, |
| 75 | comp_info: [ |
| 76 | chromaton!(0, 0, false, 8, 0, 0, 1), |
| 77 | chromaton!(yuv8; 1, 1, 1), |
| 78 | chromaton!(yuv8; 1, 1, 2), |
| 79 | None, None], |
| 80 | elem_size: 0, has_alpha: false, is_palette: false }; |
| 81 | |
| 82 | #[allow(dead_code)] |
| 83 | pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB, components: 3, |
| 84 | comp_info: [ |
| 85 | chromaton!(pal8; 0), |
| 86 | chromaton!(pal8; 1), |
| 87 | chromaton!(pal8; 2), |
| 88 | None, None], |
| 89 | elem_size: 1, has_alpha: false, is_palette: true }; |
| 90 | |
| 91 | |
| 92 | #[allow(dead_code)] |
| 93 | pub struct NAVideoInfo { |
| 94 | width: u32, |
| 95 | height: u32, |
| 96 | flipped: bool, |
| 97 | format: NAPixelFormaton, |
| 98 | } |
| 99 | |
| 100 | impl NAVideoInfo { |
| 101 | pub fn new(w: u32, h: u32, flip: bool, fmt: NAPixelFormaton) -> Self { |
| 102 | NAVideoInfo { width: w, height: h, flipped: flip, format: fmt } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | pub enum NACodecTypeInfo { |
| 107 | None, |
| 108 | Audio(NAAudioInfo), |
| 109 | Video(NAVideoInfo), |
| 110 | } |
| 111 | |
| 112 | #[allow(dead_code)] |
| 113 | pub struct NABuffer<'a> { |
| 114 | id: u64, |
| 115 | data: &'a mut [u8], |
| 116 | } |
| 117 | |
| 118 | #[allow(dead_code)] |
| 119 | pub struct NACodecInfo<'a> { |
| 120 | properties: NACodecTypeInfo, |
| 121 | extradata: Option<&'a[u8]>, |
| 122 | } |
| 123 | |
| 124 | impl<'a> NACodecInfo<'a> { |
| 125 | pub fn new(p: NACodecTypeInfo, edata: Option<&'a[u8]>) -> Self { |
| 126 | NACodecInfo { properties: p, extradata: edata } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | pub trait NABufferAllocator { |
| 131 | fn alloc_buf(info: &NACodecInfo) -> NABuffer<'static>; |
| 132 | } |
| 133 | |
| 134 | #[derive(Debug)] |
| 135 | pub enum NAValue<'a> { |
| 136 | None, |
| 137 | Int(i32), |
| 138 | Long(i64), |
| 139 | String(String), |
| 140 | Data(&'a [u8]), |
| 141 | } |
| 142 | |
| 143 | #[allow(dead_code)] |
| 144 | pub struct NAFrame<'a> { |
| 145 | pts: Option<u64>, |
| 146 | dts: Option<u64>, |
| 147 | duration: Option<u64>, |
| 148 | buffer: &'a mut NABuffer<'a>, |
| 149 | info: &'a NACodecInfo<'a>, |
| 150 | options: HashMap<String, NAValue<'a>>, |
| 151 | } |
| 152 | |
| 153 | #[allow(dead_code)] |
| 154 | pub struct NACodecContext<'a> { |
| 155 | info: &'a NACodecInfo<'a>, |
| 156 | } |