Mercurial > mplayer.hg
annotate libaf/format.c @ 18701:b45c4e057999
Remove unnecessary rsync exclude.
author | diego |
---|---|
date | Wed, 14 Jun 2006 10:24:41 +0000 |
parents | 4645b9f89237 |
children | 5e767cabf4cd |
rev | line source |
---|---|
16115 | 1 /*============================================================================= |
2 // | |
3 // This software has been released under the terms of the GNU General Public | |
4 // license. See http://www.gnu.org/copyleft/gpl.html for details. | |
5 // | |
6 // Copyright 2005 Alex Beregszaszi | |
7 // | |
8 //============================================================================= | |
9 */ | |
10 | |
14748 | 11 #include <stdio.h> |
12 #include <stdlib.h> | |
13 #include <string.h> | |
14 #include <unistd.h> | |
15 #include <inttypes.h> | |
16 #include <limits.h> | |
17 | |
18 #include "af.h" | |
17863 | 19 #include "help_mp.h" |
14748 | 20 |
21 // Convert from string to format | |
22 int af_str2fmt(char* str) | |
23 { | |
24 int format=0; | |
25 // Scan for endianess | |
26 if(strstr(str,"be") || strstr(str,"BE")) | |
27 format |= AF_FORMAT_BE; | |
28 else if(strstr(str,"le") || strstr(str,"LE")) | |
29 format |= AF_FORMAT_LE; | |
30 else | |
31 format |= AF_FORMAT_NE; | |
32 | |
33 // Scan for special formats | |
34 if(strstr(str,"mulaw") || strstr(str,"MULAW")){ | |
35 format |= AF_FORMAT_MU_LAW; return format; | |
36 } | |
37 if(strstr(str,"alaw") || strstr(str,"ALAW")){ | |
38 format |= AF_FORMAT_A_LAW; return format; | |
39 } | |
40 if(strstr(str,"ac3") || strstr(str,"AC3")){ | |
41 format |= AF_FORMAT_AC3; return format; | |
42 } | |
43 if(strstr(str,"mpeg2") || strstr(str,"MPEG2")){ | |
44 format |= AF_FORMAT_MPEG2; return format; | |
45 } | |
46 if(strstr(str,"imaadpcm") || strstr(str,"IMAADPCM")){ | |
47 format |= AF_FORMAT_IMA_ADPCM; return format; | |
48 } | |
49 | |
50 // Scan for int/float | |
51 if(strstr(str,"float") || strstr(str,"FLOAT")){ | |
52 format |= AF_FORMAT_F; return format; | |
53 } | |
54 else | |
55 format |= AF_FORMAT_I; | |
56 | |
57 // Scan for signed/unsigned | |
58 if(strstr(str,"unsigned") || strstr(str,"UNSIGNED")) | |
59 format |= AF_FORMAT_US; | |
60 else | |
61 format |= AF_FORMAT_SI; | |
62 | |
63 return format; | |
64 } | |
65 | |
66 inline int af_fmt2bits(int format) | |
67 { | |
68 return (format & AF_FORMAT_BITS_MASK)+8; | |
69 // return (((format & AF_FORMAT_BITS_MASK)>>3)+1) * 8; | |
70 #if 0 | |
71 switch(format & AF_FORMAT_BITS_MASK) | |
72 { | |
73 case AF_FORMAT_8BIT: return 8; | |
74 case AF_FORMAT_16BIT: return 16; | |
75 case AF_FORMAT_24BIT: return 24; | |
76 case AF_FORMAT_32BIT: return 32; | |
77 case AF_FORMAT_48BIT: return 48; | |
78 } | |
79 #endif | |
80 return -1; | |
81 } | |
82 | |
83 inline int af_bits2fmt(int bits) | |
84 { | |
85 return (bits/8 - 1) << 3; | |
86 } | |
87 | |
88 /* Convert format to str input str is a buffer for the | |
89 converted string, size is the size of the buffer */ | |
90 char* af_fmt2str(int format, char* str, int size) | |
91 { | |
92 int i=0; | |
93 | |
94 if (size < 1) | |
95 return NULL; | |
96 size--; // reserve one for terminating 0 | |
97 | |
98 // Endianess | |
99 if(AF_FORMAT_LE == (format & AF_FORMAT_END_MASK)) | |
100 i+=snprintf(str,size-i,"little-endian "); | |
101 else | |
102 i+=snprintf(str,size-i,"big-endian "); | |
103 | |
104 if(format & AF_FORMAT_SPECIAL_MASK){ | |
105 switch(format & AF_FORMAT_SPECIAL_MASK){ | |
106 case(AF_FORMAT_MU_LAW): | |
107 i+=snprintf(&str[i],size-i,"mu-law "); break; | |
108 case(AF_FORMAT_A_LAW): | |
109 i+=snprintf(&str[i],size-i,"A-law "); break; | |
110 case(AF_FORMAT_MPEG2): | |
111 i+=snprintf(&str[i],size-i,"MPEG-2 "); break; | |
112 case(AF_FORMAT_AC3): | |
113 i+=snprintf(&str[i],size-i,"AC3 "); break; | |
114 case(AF_FORMAT_IMA_ADPCM): | |
115 i+=snprintf(&str[i],size-i,"IMA-ADPCM "); break; | |
116 default: | |
17876 | 117 i+=snprintf(&str[i],size-i,MSGTR_AF_FORMAT_UnknownFormat); |
14748 | 118 } |
119 } | |
120 else{ | |
121 // Bits | |
122 i+=snprintf(&str[i],size-i,"%d-bit ", af_fmt2bits(format)); | |
123 | |
124 // Point | |
125 if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK)) | |
126 i+=snprintf(&str[i],size-i,"float "); | |
127 else{ | |
128 // Sign | |
129 if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK)) | |
130 i+=snprintf(&str[i],size-i,"unsigned "); | |
131 else | |
132 i+=snprintf(&str[i],size-i,"signed "); | |
133 | |
134 i+=snprintf(&str[i],size-i,"int "); | |
135 } | |
136 } | |
137 // remove trailing space | |
138 if (i > 0 && str[i - 1] == ' ') | |
139 i--; | |
140 str[i] = 0; // make sure it is 0 terminated. | |
141 return str; | |
142 } | |
143 | |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
144 static struct { |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
145 const char *name; |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
146 const int format; |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
147 } af_fmtstr_table[] = { |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
148 { "mulaw", AF_FORMAT_MU_LAW }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
149 { "alaw", AF_FORMAT_A_LAW }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
150 { "mpeg2", AF_FORMAT_MPEG2 }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
151 { "ac3", AF_FORMAT_AC3 }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
152 { "imaadpcm", AF_FORMAT_IMA_ADPCM }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
153 |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
154 { "u8", AF_FORMAT_U8 }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
155 { "s8", AF_FORMAT_S8 }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
156 { "u16le", AF_FORMAT_U16_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
157 { "u16be", AF_FORMAT_U16_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
158 { "u16ne", AF_FORMAT_U16_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
159 { "s16le", AF_FORMAT_S16_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
160 { "s16be", AF_FORMAT_S16_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
161 { "s16ne", AF_FORMAT_S16_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
162 { "u24le", AF_FORMAT_U24_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
163 { "u24be", AF_FORMAT_U24_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
164 { "u24ne", AF_FORMAT_U24_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
165 { "s24le", AF_FORMAT_S24_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
166 { "s24be", AF_FORMAT_S24_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
167 { "s24ne", AF_FORMAT_S24_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
168 { "u32le", AF_FORMAT_U32_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
169 { "u32be", AF_FORMAT_U32_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
170 { "u32ne", AF_FORMAT_U32_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
171 { "s32le", AF_FORMAT_S32_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
172 { "s32be", AF_FORMAT_S32_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
173 { "s32ne", AF_FORMAT_S32_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
174 { "floatle", AF_FORMAT_FLOAT_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
175 { "floatbe", AF_FORMAT_FLOAT_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
176 { "floatne", AF_FORMAT_FLOAT_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
177 |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
178 { NULL, 0 } |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
179 }; |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
180 |
14748 | 181 char *af_fmt2str_short(int format) |
182 { | |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
183 int i; |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
184 |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
185 for (i = 0; af_fmtstr_table[i].name; i++) |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
186 if (af_fmtstr_table[i].format == format) |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
187 return (char*)(af_fmtstr_table[i].name); |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
188 |
14748 | 189 return "??"; |
190 } | |
191 | |
192 int af_str2fmt_short(char* str) | |
193 { | |
194 int i; | |
195 | |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
196 for (i = 0; af_fmtstr_table[i].name; i++) |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
197 if (!strcasecmp(str, af_fmtstr_table[i].name)) |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
198 return af_fmtstr_table[i].format; |
14748 | 199 |
200 return -1; | |
201 } |