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