3 #[derive(Debug,Clone,Copy,PartialEq)]
13 impl fmt::Display for CodecType {
14 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16 CodecType::Video => write!(f, "Video"),
17 CodecType::Audio => write!(f, "Audio"),
18 CodecType::Subtitles => write!(f, "Subtitles"),
19 CodecType::Data => write!(f, "Data"),
20 CodecType::None => write!(f, "-"),
25 const CODEC_CAP_INTRAONLY:u32 = 0x000001;
26 const CODEC_CAP_LOSSLESS:u32 = 0x000002;
27 const CODEC_CAP_REORDER:u32 = 0x000004;
28 const CODEC_CAP_HYBRID:u32 = 0x000008;
29 const CODEC_CAP_SCALABLE:u32 = 0x000010;
32 pub struct CodecDescription {
33 pub name: &'static str,
34 pub fname: &'static str,
39 impl CodecDescription {
40 pub fn get_name(&self) -> &'static str { self.name }
41 pub fn get_full_name(&self) -> &'static str { self.fname }
42 pub fn get_codec_type(&self) -> CodecType { self.ctype }
43 pub fn is_intraonly(&self) -> bool { (self.caps & CODEC_CAP_INTRAONLY) != 0 }
44 pub fn is_lossless(&self) -> bool { (self.caps & CODEC_CAP_LOSSLESS) != 0 }
45 pub fn has_reorder(&self) -> bool { (self.caps & CODEC_CAP_REORDER) != 0 }
46 pub fn is_hybrid(&self) -> bool { (self.caps & CODEC_CAP_HYBRID) != 0 }
47 pub fn is_scalable(&self) -> bool { (self.caps & CODEC_CAP_SCALABLE) != 0 }
50 impl fmt::Display for CodecDescription {
51 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52 let mut out = format!("{}", self.fname);
54 let mut capfmt = "".to_string();
55 if (self.caps & CODEC_CAP_INTRAONLY) != 0 {
56 capfmt = format!("{} Intra-only", capfmt);
58 if (self.caps & CODEC_CAP_LOSSLESS) != 0 {
59 capfmt = format!("{} Lossless", capfmt);
61 if (self.caps & CODEC_CAP_REORDER) != 0 {
62 capfmt = format!("{} Frame reorder", capfmt);
64 if (self.caps & CODEC_CAP_HYBRID) != 0 {
65 capfmt = format!("{} Can be lossy and lossless", capfmt);
67 if (self.caps & CODEC_CAP_SCALABLE) != 0 {
68 capfmt = format!("{} Scalable", capfmt);
70 out = format!("{} ({})", out, capfmt);
77 (video; $n:expr, $fn:expr) => ({
78 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
81 (video; $n:expr, $fn:expr, $c:expr) => ({
82 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
85 (video-ll; $n:expr, $fn:expr) => ({
86 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
87 caps: CODEC_CAP_LOSSLESS | CODEC_CAP_INTRAONLY }
89 (video-llp; $n:expr, $fn:expr) => ({
90 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
91 caps: CODEC_CAP_LOSSLESS }
93 (video-im; $n:expr, $fn:expr) => ({
94 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
95 caps: CODEC_CAP_INTRAONLY }
97 (video-modern; $n:expr, $fn:expr) => ({
98 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
99 caps: CODEC_CAP_REORDER | CODEC_CAP_HYBRID }
101 (audio; $n:expr, $fn:expr) => ({
102 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Audio,
105 (audio-ll; $n:expr, $fn:expr) => ({
106 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Audio,
107 caps: CODEC_CAP_LOSSLESS | CODEC_CAP_INTRAONLY }
111 pub fn get_codec_description(name: &str) -> Option<&'static CodecDescription> {
112 for reg in CODEC_REGISTER {
113 if reg.name == name {
120 static CODEC_REGISTER: &'static [CodecDescription] = &[
121 desc!(audio-ll; "pcm", "PCM"),
123 desc!(video-im; "indeo1", "Intel Raw IF09"),
124 desc!(video-im; "indeo2", "Intel Indeo 2"),
125 desc!(video; "indeo3", "Intel Indeo 3"),
126 desc!(video; "indeo4", "Intel Indeo 4", CODEC_CAP_REORDER | CODEC_CAP_SCALABLE),
127 desc!(video; "indeo5", "Intel Indeo 5", CODEC_CAP_REORDER | CODEC_CAP_SCALABLE),
128 desc!(video; "intel263", "Intel I263", CODEC_CAP_REORDER),
129 desc!(audio; "iac", "Intel Indeo audio"),
130 desc!(audio; "imc", "Intel Music Coder"),
132 desc!(video; "realvideo1", "Real Video 1"),
133 desc!(video; "realvideo2", "Real Video 2"),
134 desc!(video; "realvideo3", "Real Video 3", CODEC_CAP_REORDER),
135 desc!(video; "realvideo4", "Real Video 4", CODEC_CAP_REORDER),
136 desc!(video; "realvideo6", "Real Video 6", CODEC_CAP_REORDER),
137 desc!(video; "clearvideo", "ClearVideo"),
138 desc!(video; "clearvideo_rm", "ClearVideo"),
139 desc!(audio; "ra14.4", "RealAudio 14.4"),
140 desc!(audio; "ra28.8", "RealAudio 28.8"),
141 desc!(audio; "cook", "RealAudio Cooker"),
142 desc!(audio; "ralf", "RealAudio Lossless"),
143 desc!(audio; "aac", "AAC"),
144 desc!(audio; "ac3", "ETSI TS 102 366"),
145 desc!(audio; "atrac3", "Sony Atrac3"),
146 desc!(audio; "sipro", "Sipro Labs ADPCM"),
148 desc!(video; "truemotion1", "TrueMotion 1"),
149 desc!(video-im; "truemotionrt", "TrueMotion RT"),
150 desc!(video; "truemotion2", "TrueMotion 2"),
151 desc!(video; "truemotion2x", "TrueMotion 2X"),
152 desc!(video; "vp3", "VP3"),
153 desc!(video; "vp4", "VP4"),
154 desc!(video; "vp5", "VP5"),
155 desc!(video; "vp6", "VP6"),
156 desc!(video; "vp7", "VP7"),
157 desc!(video; "vp8", "VP8"),
158 desc!(video; "vp9", "VP9"),
159 desc!(audio; "adpcm-dk3", "Duck DK3 ADPCM"),
160 desc!(audio; "adpcm-dk4", "Duck DK4 ADPCM"),
161 desc!(audio; "on2-avc-500", "On2 AVC"),
162 desc!(audio; "on2-avc-501", "On2 AVC"),
164 desc!(video; "gdv-video", "Gremlin Digital Video - video"),
165 desc!(audio; "gdv-audio", "Gremlin Digital Video - audio"),
166 desc!(video; "bmv-video", "BMV video"),
167 desc!(audio; "bmv-audio", "BMV audio"),
168 desc!(video; "bmv3-video", "DW Noir BMV video"),
169 desc!(audio; "bmv3-audio", "DW Noir BMV audio"),
170 desc!(video; "vmd-video", "VMD video"),
171 desc!(audio; "vmd-audio", "VMD audio"),
173 desc!(video; "smacker-video", "Smacker video"),
174 desc!(audio; "smacker-audio", "Smacker audio"),
175 desc!(video; "bink-video", "Bink video"),
176 desc!(video; "bink2-video", "Bink2 video"),
177 desc!(audio; "bink-audio-dct", "Bink audio (DCT)"),
178 desc!(audio; "bink-audio-rdft", "Bink audio (RDFT)"),
181 static AVI_VIDEO_CODEC_REGISTER: &'static [(&[u8;4], &str)] = &[
188 (b"I263", "intel263"),
190 (b"UCOD", "clearvideo"),
192 (b"DUCK", "truemotion1"),
193 (b"TR20", "truemotionrt"),
194 (b"TM20", "truemotion2"),
195 (b"TM2A", "truemotion2x"),
196 (b"TM2X", "truemotion2x"),
207 static WAV_CODEC_REGISTER: &'static [(u16, &str)] = &[
211 (0x0061, "adpcm-dk4"),
212 (0x0062, "adpcm-dk3"),
215 (0x0500, "on2avc-500"),
216 (0x0501, "on2avc-501"),
219 pub fn find_codec_from_avi_fourcc(fcc: &[u8;4]) -> Option<&'static str> {
220 for i in 0..AVI_VIDEO_CODEC_REGISTER.len() {
221 let (fourcc, name) = AVI_VIDEO_CODEC_REGISTER[i];
222 if fourcc == fcc { return Some(name); }
227 pub fn find_codec_from_wav_twocc(tcc: u16) -> Option<&'static str> {
228 for i in 0..WAV_CODEC_REGISTER.len() {
229 let (twocc, name) = WAV_CODEC_REGISTER[i];
230 if twocc == tcc { return Some(name); }
241 let c1 = find_codec_from_avi_fourcc(b"IV41").unwrap();
242 let c2 = find_codec_from_wav_twocc(0x401).unwrap();
243 println!("found {} and {}", c1, c2);
244 let cd1 = get_codec_description(c1).unwrap();
245 let cd2 = get_codec_description(c2).unwrap();
246 println!("got {} and {}", cd1, cd2);