Mercurial > mplayer.hg
annotate libaf/format.c @ 35753:9c74edcbbc96
Cosmetic: Adjust indent.
author | ib |
---|---|
date | Thu, 24 Jan 2013 15:27:26 +0000 |
parents | febe300dbfc0 |
children | 389d43c448b3 |
rev | line source |
---|---|
28229
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
1 /* |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
2 * Copyright (C) 2005 Alex Beregszaszi |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
3 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
4 * This file is part of MPlayer. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
5 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
6 * MPlayer is free software; you can redistribute it and/or modify |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
9 * (at your option) any later version. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
10 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
11 * MPlayer is distributed in the hope that it will be useful, |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
14 * GNU General Public License for more details. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
15 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
16 * You should have received a copy of the GNU General Public License along |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24890
diff
changeset
|
19 */ |
16115 | 20 |
14748 | 21 #include <stdio.h> |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 #include <inttypes.h> | |
25 #include <limits.h> | |
26 | |
27 #include "af.h" | |
17863 | 28 #include "help_mp.h" |
14748 | 29 |
30 // 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
|
31 int af_str2fmt(const char* str) |
14748 | 32 { |
33 int format=0; | |
24595 | 34 // Scan for endianness |
14748 | 35 if(strstr(str,"be") || strstr(str,"BE")) |
36 format |= AF_FORMAT_BE; | |
37 else if(strstr(str,"le") || strstr(str,"LE")) | |
38 format |= AF_FORMAT_LE; | |
39 else | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
40 format |= AF_FORMAT_NE; |
14748 | 41 |
42 // Scan for special formats | |
43 if(strstr(str,"mulaw") || strstr(str,"MULAW")){ | |
44 format |= AF_FORMAT_MU_LAW; return format; | |
45 } | |
46 if(strstr(str,"alaw") || strstr(str,"ALAW")){ | |
47 format |= AF_FORMAT_A_LAW; return format; | |
48 } | |
49 if(strstr(str,"ac3") || strstr(str,"AC3")){ | |
30241
02b9c1a452e1
Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents:
30236
diff
changeset
|
50 format |= AF_FORMAT_AC3 | AF_FORMAT_16BIT; return format; |
14748 | 51 } |
52 if(strstr(str,"mpeg2") || strstr(str,"MPEG2")){ | |
53 format |= AF_FORMAT_MPEG2; return format; | |
54 } | |
34103 | 55 if(strstr(str,"iec61937") || strstr(str,"IEC61937")){ |
56 format |= AF_FORMAT_IEC61937 | AF_FORMAT_16BIT; return format; | |
57 } | |
14748 | 58 if(strstr(str,"imaadpcm") || strstr(str,"IMAADPCM")){ |
59 format |= AF_FORMAT_IMA_ADPCM; return format; | |
60 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
61 |
14748 | 62 // Scan for int/float |
63 if(strstr(str,"float") || strstr(str,"FLOAT")){ | |
64 format |= AF_FORMAT_F; return format; | |
65 } | |
66 else | |
67 format |= AF_FORMAT_I; | |
68 | |
69 // Scan for signed/unsigned | |
70 if(strstr(str,"unsigned") || strstr(str,"UNSIGNED")) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
71 format |= AF_FORMAT_US; |
14748 | 72 else |
73 format |= AF_FORMAT_SI; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
74 |
14748 | 75 return format; |
76 } | |
77 | |
24890 | 78 int af_fmt2bits(int format) |
14748 | 79 { |
30236
cb2e10d85c04
Add a hack to af_fmt2bits to recognize AC3 as a 16-bit format, since this
reimar
parents:
29263
diff
changeset
|
80 if (AF_FORMAT_IS_AC3(format)) return 16; |
14748 | 81 return (format & AF_FORMAT_BITS_MASK)+8; |
82 // return (((format & AF_FORMAT_BITS_MASK)>>3)+1) * 8; | |
83 #if 0 | |
84 switch(format & AF_FORMAT_BITS_MASK) | |
85 { | |
86 case AF_FORMAT_8BIT: return 8; | |
87 case AF_FORMAT_16BIT: return 16; | |
88 case AF_FORMAT_24BIT: return 24; | |
89 case AF_FORMAT_32BIT: return 32; | |
90 case AF_FORMAT_48BIT: return 48; | |
91 } | |
92 #endif | |
93 return -1; | |
94 } | |
95 | |
24890 | 96 int af_bits2fmt(int bits) |
14748 | 97 { |
98 return (bits/8 - 1) << 3; | |
99 } | |
100 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
101 /* Convert format to str input str is a buffer for the |
14748 | 102 converted string, size is the size of the buffer */ |
103 char* af_fmt2str(int format, char* str, int size) | |
104 { | |
105 int i=0; | |
106 | |
107 if (size < 1) | |
108 return NULL; | |
109 size--; // reserve one for terminating 0 | |
110 | |
24595 | 111 // Endianness |
14748 | 112 if(AF_FORMAT_LE == (format & AF_FORMAT_END_MASK)) |
113 i+=snprintf(str,size-i,"little-endian "); | |
114 else | |
115 i+=snprintf(str,size-i,"big-endian "); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
116 |
14748 | 117 if(format & AF_FORMAT_SPECIAL_MASK){ |
118 switch(format & AF_FORMAT_SPECIAL_MASK){ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
119 case(AF_FORMAT_MU_LAW): |
14748 | 120 i+=snprintf(&str[i],size-i,"mu-law "); break; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
121 case(AF_FORMAT_A_LAW): |
14748 | 122 i+=snprintf(&str[i],size-i,"A-law "); break; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
123 case(AF_FORMAT_MPEG2): |
14748 | 124 i+=snprintf(&str[i],size-i,"MPEG-2 "); break; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
125 case(AF_FORMAT_AC3): |
14748 | 126 i+=snprintf(&str[i],size-i,"AC3 "); break; |
34103 | 127 case(AF_FORMAT_IEC61937): |
128 i+=snprintf(&str[i],size-i,"IEC61937 "); break; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
129 case(AF_FORMAT_IMA_ADPCM): |
14748 | 130 i+=snprintf(&str[i],size-i,"IMA-ADPCM "); break; |
131 default: | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
132 i+=snprintf(&str[i],size-i,MSGTR_AF_FORMAT_UnknownFormat); |
14748 | 133 } |
134 } | |
135 else{ | |
136 // Bits | |
137 i+=snprintf(&str[i],size-i,"%d-bit ", af_fmt2bits(format)); | |
138 | |
139 // Point | |
140 if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK)) | |
141 i+=snprintf(&str[i],size-i,"float "); | |
142 else{ | |
143 // Sign | |
144 if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK)) | |
145 i+=snprintf(&str[i],size-i,"unsigned "); | |
146 else | |
147 i+=snprintf(&str[i],size-i,"signed "); | |
148 | |
149 i+=snprintf(&str[i],size-i,"int "); | |
150 } | |
151 } | |
152 // remove trailing space | |
153 if (i > 0 && str[i - 1] == ' ') | |
154 i--; | |
155 str[i] = 0; // make sure it is 0 terminated. | |
156 return str; | |
157 } | |
158 | |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
159 static struct { |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
160 const char *name; |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
161 const int format; |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
162 } af_fmtstr_table[] = { |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
163 { "mulaw", AF_FORMAT_MU_LAW }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
164 { "alaw", AF_FORMAT_A_LAW }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
165 { "mpeg2", AF_FORMAT_MPEG2 }, |
30241
02b9c1a452e1
Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents:
30236
diff
changeset
|
166 { "ac3le", AF_FORMAT_AC3_LE }, |
02b9c1a452e1
Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents:
30236
diff
changeset
|
167 { "ac3be", AF_FORMAT_AC3_BE }, |
02b9c1a452e1
Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents:
30236
diff
changeset
|
168 { "ac3ne", AF_FORMAT_AC3_NE }, |
34103 | 169 { "iec61937le", AF_FORMAT_IEC61937_LE }, |
170 { "iec61937be", AF_FORMAT_IEC61937_BE }, | |
171 { "iec61937ne", AF_FORMAT_IEC61937_NE }, | |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
172 { "imaadpcm", AF_FORMAT_IMA_ADPCM }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
173 |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
174 { "u8", AF_FORMAT_U8 }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
175 { "s8", AF_FORMAT_S8 }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
176 { "u16le", AF_FORMAT_U16_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
177 { "u16be", AF_FORMAT_U16_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
178 { "u16ne", AF_FORMAT_U16_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
179 { "s16le", AF_FORMAT_S16_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
180 { "s16be", AF_FORMAT_S16_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
181 { "s16ne", AF_FORMAT_S16_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
182 { "u24le", AF_FORMAT_U24_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
183 { "u24be", AF_FORMAT_U24_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
184 { "u24ne", AF_FORMAT_U24_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
185 { "s24le", AF_FORMAT_S24_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
186 { "s24be", AF_FORMAT_S24_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
187 { "s24ne", AF_FORMAT_S24_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
188 { "u32le", AF_FORMAT_U32_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
189 { "u32be", AF_FORMAT_U32_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
190 { "u32ne", AF_FORMAT_U32_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
191 { "s32le", AF_FORMAT_S32_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
192 { "s32be", AF_FORMAT_S32_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
193 { "s32ne", AF_FORMAT_S32_NE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
194 { "floatle", AF_FORMAT_FLOAT_LE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
195 { "floatbe", AF_FORMAT_FLOAT_BE }, |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
196 { "floatne", AF_FORMAT_FLOAT_NE }, |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
197 |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
198 { NULL, 0 } |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
199 }; |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
200 |
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
|
201 const char *af_fmt2str_short(int format) |
14748 | 202 { |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
203 int i; |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
204 |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
205 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
|
206 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
|
207 return af_fmtstr_table[i].name; |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
208 |
14748 | 209 return "??"; |
210 } | |
211 | |
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
|
212 int af_str2fmt_short(const char* str) |
14748 | 213 { |
214 int i; | |
215 | |
16259
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
216 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
|
217 if (!strcasecmp(str, af_fmtstr_table[i].name)) |
bf5ee9e17e00
code reduction and less error prone, use the same table
alex
parents:
16115
diff
changeset
|
218 return af_fmtstr_table[i].format; |
14748 | 219 |
220 return -1; | |
221 } |