3 #[derive(Debug,Clone,Copy)]
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;
31 pub struct CodecDescription {
38 impl CodecDescription {
39 pub fn get_name(&self) -> &'static str { self.name }
40 pub fn get_full_name(&self) -> &'static str { self.fname }
41 pub fn get_codec_type(&self) -> CodecType { self.ctype }
42 pub fn is_intraonly(&self) -> bool { (self.caps & CODEC_CAP_INTRAONLY) != 0 }
43 pub fn is_lossless(&self) -> bool { (self.caps & CODEC_CAP_LOSSLESS) != 0 }
44 pub fn has_reorder(&self) -> bool { (self.caps & CODEC_CAP_REORDER) != 0 }
45 pub fn is_hybrid(&self) -> bool { (self.caps & CODEC_CAP_HYBRID) != 0 }
46 pub fn is_scalable(&self) -> bool { (self.caps & CODEC_CAP_SCALABLE) != 0 }
49 impl fmt::Display for CodecDescription {
50 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51 let mut out = format!("{}", self.fname);
53 let mut capfmt = "".to_string();
54 if (self.caps & CODEC_CAP_INTRAONLY) != 0 {
55 capfmt = format!("{} Intra-only", capfmt);
57 if (self.caps & CODEC_CAP_LOSSLESS) != 0 {
58 capfmt = format!("{} Lossless", capfmt);
60 if (self.caps & CODEC_CAP_REORDER) != 0 {
61 capfmt = format!("{} Frame reorder", capfmt);
63 if (self.caps & CODEC_CAP_HYBRID) != 0 {
64 capfmt = format!("{} Can be lossy and lossless", capfmt);
66 if (self.caps & CODEC_CAP_SCALABLE) != 0 {
67 capfmt = format!("{} Scalable", capfmt);
69 out = format!("{} ({})", out, capfmt);
76 (video; $n:expr, $fn:expr) => ({
77 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
80 (video; $n:expr, $fn:expr, $c:expr) => ({
81 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
84 (video-ll; $n:expr, $fn:expr) => ({
85 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
86 caps: CODEC_CAP_LOSSLESS | CODEC_CAP_INTRAONLY }
88 (video-llp; $n:expr, $fn:expr) => ({
89 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
90 caps: CODEC_CAP_LOSSLESS }
92 (video-im; $n:expr, $fn:expr) => ({
93 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
94 caps: CODEC_CAP_INTRAONLY }
96 (video-modern; $n:expr, $fn:expr) => ({
97 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Video,
98 caps: CODEC_CAP_REORDER | CODEC_CAP_HYBRID }
100 (audio; $n:expr, $fn:expr) => ({
101 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Audio,
104 (audio-ll; $n:expr, $fn:expr) => ({
105 CodecDescription{ name: $n, fname: $fn, ctype: CodecType::Audio,
106 caps: CODEC_CAP_LOSSLESS | CODEC_CAP_INTRAONLY }
110 pub fn get_codec_description(name: &str) -> Option<&'static CodecDescription> {
111 for i in 0..CODEC_REGISTER.len() {
112 if CODEC_REGISTER[i].name == name {
113 return Some(&CODEC_REGISTER[i]);
119 static CODEC_REGISTER: &'static [CodecDescription] = &[
120 desc!(video-im; "indeo1", "Intel Raw IF09"),
121 desc!(video-im; "indeo2", "Intel Indeo 2"),
122 desc!(video; "indeo3", "Intel Indeo 3"),
123 desc!(video; "indeo4", "Intel Indeo 4", CODEC_CAP_REORDER | CODEC_CAP_SCALABLE),
124 desc!(video; "indeo5", "Intel Indeo 5", CODEC_CAP_REORDER | CODEC_CAP_SCALABLE),
125 desc!(audio; "iac", "Intel Indeo audio"),
126 desc!(audio; "imc", "Intel Music Coder"),
129 static AVI_VIDEO_CODEC_REGISTER: &'static [(&[u8;4], &str)] = &[
138 static WAV_CODEC_REGISTER: &'static [(u16, &str)] = &[
146 pub fn find_codec_from_avi_fourcc(fcc: &[u8;4]) -> Option<&'static str> {
147 for i in 0..AVI_VIDEO_CODEC_REGISTER.len() {
148 let (fourcc, name) = AVI_VIDEO_CODEC_REGISTER[i];
149 if fourcc == fcc { return Some(name); }
154 pub fn find_codec_from_wav_twocc(tcc: u16) -> Option<&'static str> {
155 for i in 0..WAV_CODEC_REGISTER.len() {
156 let (twocc, name) = WAV_CODEC_REGISTER[i];
157 if twocc == tcc { return Some(name); }
168 let c1 = find_codec_from_avi_fourcc(b"IV41").unwrap();
169 let c2 = find_codec_from_wav_twocc(0x401).unwrap();
170 println!("found {} and {}", c1, c2);
171 let cd1 = get_codec_description(c1).unwrap();
172 let cd2 = get_codec_description(c2).unwrap();
173 println!("got {} and {}", cd1, cd2);