Mercurial > mplayer.hg
annotate codec-cfg.c @ 34044:563038925442
Set up HAVE_VFP_ARGS and CONFIG_THUMB correctly to fix compilation for ARM.
author | reimar |
---|---|
date | Sun, 25 Sep 2011 13:28:25 +0000 |
parents | cf2a4f4cac0e |
children | ab178e06077e |
rev | line source |
---|---|
319 | 1 /* |
2 * codec.conf parser | |
4676 | 3 * |
22501 | 4 * to compile test application: |
5 * cc -I. -DTESTING -o codec-cfg-test codec-cfg.c mp_msg.o osdep/getch2.o -ltermcap | |
15303 | 6 * to compile CODECS2HTML: |
33246 | 7 * gcc -DCODECS2HTML -o codecs2html codec-cfg.c |
4676 | 8 * |
9 * TODO: implement informat in CODECS2HTML too | |
30429
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
10 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
11 * Copyright (C) 2001 Szabolcs Berecz <szabi@inf.elte.hu> |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
12 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
13 * This file is part of MPlayer. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
14 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
15 * MPlayer is free software; you can redistribute it and/or modify |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
16 * it under the terms of the GNU General Public License as published by |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
17 * the Free Software Foundation; either version 2 of the License, or |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
18 * (at your option) any later version. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
19 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
20 * MPlayer is distributed in the hope that it will be useful, |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
23 * GNU General Public License for more details. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
24 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
25 * You should have received a copy of the GNU General Public License along |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
26 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
319 | 28 */ |
303 | 29 |
319 | 30 #define DEBUG |
303 | 31 |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
32 //disable asserts |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
33 #define NDEBUG |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
34 |
297 | 35 #include <stdio.h> |
36 #include <stdlib.h> | |
37 #include <fcntl.h> | |
38 #include <unistd.h> | |
39 #include <errno.h> | |
40 #include <ctype.h> | |
41 #include <assert.h> | |
42 #include <string.h> | |
43 | |
5284
0a58c2ef1da1
added missing #include config.h, removed LIBVO2 ifdef.
arpi
parents:
5263
diff
changeset
|
44 #include "config.h" |
5937 | 45 #include "mp_msg.h" |
17841
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
46 #ifdef CODECS2HTML |
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
47 #ifdef __GNUC__ |
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
48 #define mp_msg(t, l, m, args...) fprintf(stderr, m, ##args) |
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
49 #else |
23910
8fcfdfcd6c41
C99 varargs in macros can not be empty, adjust definition so it compiles
reimar
parents:
23806
diff
changeset
|
50 #define mp_msg(t, l, ...) fprintf(stderr, __VA_ARGS__) |
17841
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
51 #endif |
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
52 #endif |
5284
0a58c2ef1da1
added missing #include config.h, removed LIBVO2 ifdef.
arpi
parents:
5263
diff
changeset
|
53 |
13619 | 54 #include "help_mp.h" |
55 | |
33561
1ff6737f2177
Avoid including aviheader.h only for mmioFOURCC, it has too many
reimar
parents:
33364
diff
changeset
|
56 #include "libavutil/avutil.h" |
15305 | 57 #include "libmpcodecs/img_format.h" |
297 | 58 #include "codec-cfg.h" |
59 | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
60 #ifdef CODECS2HTML |
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
61 #define CODEC_CFG_MIN 20100000 |
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
62 #else |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
63 #include "codecs.conf.h" |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
64 #endif |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
65 |
5937 | 66 #define PRINT_LINENUM mp_msg(MSGT_CODECCFG,MSGL_ERR," at line %d\n", line_num) |
328 | 67 |
31077 | 68 #define MAX_NR_TOKEN 16 |
297 | 69 |
31077 | 70 #define MAX_LINE_LEN 1000 |
297 | 71 |
31077 | 72 #define RET_EOF -1 |
73 #define RET_EOL -2 | |
297 | 74 |
31077 | 75 #define TYPE_VIDEO 0 |
76 #define TYPE_AUDIO 1 | |
297 | 77 |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
78 static int codecs_conf_release; |
11759
29eea271490e
add -codecs-file for selecting a specific codecs.conf on the comand line
attila
parents:
11388
diff
changeset
|
79 char * codecs_file = NULL; |
29eea271490e
add -codecs-file for selecting a specific codecs.conf on the comand line
attila
parents:
11388
diff
changeset
|
80 |
303 | 81 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc, |
31077 | 82 unsigned int *map) |
297 | 83 { |
31077 | 84 int i, j, freeslots; |
85 unsigned int tmp; | |
319 | 86 |
31077 | 87 /* find first unused slot */ |
88 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
89 /* NOTHING */; | |
90 freeslots = CODECS_MAX_FOURCC - i; | |
91 if (!freeslots) | |
92 goto err_out_too_many; | |
319 | 93 |
31077 | 94 do { |
33561
1ff6737f2177
Avoid including aviheader.h only for mmioFOURCC, it has too many
reimar
parents:
33364
diff
changeset
|
95 tmp = MKTAG(s[0], s[1], s[2], s[3]); |
31077 | 96 for (j = 0; j < i; j++) |
97 if (tmp == fourcc[j]) | |
98 goto err_out_duplicated; | |
99 fourcc[i] = tmp; | |
33561
1ff6737f2177
Avoid including aviheader.h only for mmioFOURCC, it has too many
reimar
parents:
33364
diff
changeset
|
100 map[i] = alias ? MKTAG(alias[0], alias[1], alias[2], alias[3]) : tmp; |
31077 | 101 s += 4; |
102 i++; | |
103 } while ((*(s++) == ',') && --freeslots); | |
319 | 104 |
31077 | 105 if (!freeslots) |
106 goto err_out_too_many; | |
107 if (*(--s) != '\0') | |
108 goto err_out_parse_error; | |
109 return 1; | |
328 | 110 err_out_duplicated: |
31077 | 111 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_DuplicateFourcc); |
112 return 0; | |
328 | 113 err_out_too_many: |
31077 | 114 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_TooManyFourccs); |
115 return 0; | |
361 | 116 err_out_parse_error: |
31077 | 117 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseError); |
118 return 0; | |
319 | 119 } |
120 | |
7770 | 121 static int add_to_format(char *s, char *alias,unsigned int *fourcc, unsigned int *fourccmap) |
319 | 122 { |
31077 | 123 int i, j; |
124 char *endptr; | |
297 | 125 |
31077 | 126 /* find first unused slot */ |
127 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
128 /* NOTHING */; | |
129 if (i == CODECS_MAX_FOURCC) { | |
130 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_TooManyFourccs); | |
131 return 0; | |
132 } | |
297 | 133 |
31077 | 134 fourcc[i]=strtoul(s,&endptr,0); |
135 if (*endptr != '\0') { | |
136 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseErrorFIDNotNumber); | |
137 return 0; | |
138 } | |
7770 | 139 |
31077 | 140 if(alias){ |
141 fourccmap[i]=strtoul(alias,&endptr,0); | |
142 if (*endptr != '\0') { | |
143 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseErrorFIDAliasNotNumber); | |
144 return 0; | |
145 } | |
146 } else | |
147 fourccmap[i]=fourcc[i]; | |
7770 | 148 |
31077 | 149 for (j = 0; j < i; j++) |
150 if (fourcc[j] == fourcc[i]) { | |
151 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_DuplicateFID); | |
152 return 0; | |
153 } | |
300 | 154 |
31077 | 155 return 1; |
297 | 156 } |
157 | |
31159 | 158 static const struct { |
159 const char *name; | |
160 const unsigned int num; | |
161 } fmt_table[] = { | |
162 // note: due to parser deficiencies/simplicity, if one format | |
163 // name matches the beginning of another, the longer one _must_ | |
164 // come first in this list. | |
165 {"YV12", IMGFMT_YV12}, | |
166 {"I420", IMGFMT_I420}, | |
167 {"IYUV", IMGFMT_IYUV}, | |
168 {"NV12", IMGFMT_NV12}, | |
169 {"NV21", IMGFMT_NV21}, | |
170 {"YVU9", IMGFMT_YVU9}, | |
171 {"IF09", IMGFMT_IF09}, | |
172 {"444P16LE", IMGFMT_444P16_LE}, | |
173 {"444P16BE", IMGFMT_444P16_BE}, | |
34028 | 174 {"444P10LE", IMGFMT_444P10_LE}, |
175 {"444P10BE", IMGFMT_444P10_BE}, | |
31159 | 176 {"422P16LE", IMGFMT_422P16_LE}, |
177 {"422P16BE", IMGFMT_422P16_BE}, | |
178 {"420P16LE", IMGFMT_420P16_LE}, | |
179 {"420P16BE", IMGFMT_420P16_BE}, | |
180 {"444P16", IMGFMT_444P16}, | |
34028 | 181 {"444P10", IMGFMT_444P10}, |
31159 | 182 {"422P16", IMGFMT_422P16}, |
33364
e1ee4895e500
Support displaying of 9- and 10-bit pixel formats,
cehoyos
parents:
33246
diff
changeset
|
183 {"422P10", IMGFMT_422P10}, |
31159 | 184 {"420P16", IMGFMT_420P16}, |
33364
e1ee4895e500
Support displaying of 9- and 10-bit pixel formats,
cehoyos
parents:
33246
diff
changeset
|
185 {"420P10", IMGFMT_420P10}, |
e1ee4895e500
Support displaying of 9- and 10-bit pixel formats,
cehoyos
parents:
33246
diff
changeset
|
186 {"420P9", IMGFMT_420P9}, |
31159 | 187 {"420A", IMGFMT_420A}, |
188 {"444P", IMGFMT_444P}, | |
189 {"422P", IMGFMT_422P}, | |
190 {"411P", IMGFMT_411P}, | |
191 {"440P", IMGFMT_440P}, | |
192 {"Y800", IMGFMT_Y800}, | |
193 {"Y8", IMGFMT_Y8}, | |
408 | 194 |
31159 | 195 {"YUY2", IMGFMT_YUY2}, |
196 {"UYVY", IMGFMT_UYVY}, | |
197 {"YVYU", IMGFMT_YVYU}, | |
408 | 198 |
31159 | 199 {"RGB48LE", IMGFMT_RGB48LE}, |
200 {"RGB48BE", IMGFMT_RGB48BE}, | |
201 {"RGB4", IMGFMT_RGB4}, | |
202 {"RGB8", IMGFMT_RGB8}, | |
203 {"RGB15", IMGFMT_RGB15}, | |
204 {"RGB16", IMGFMT_RGB16}, | |
205 {"RGB24", IMGFMT_RGB24}, | |
206 {"RGB32", IMGFMT_RGB32}, | |
207 {"BGR4", IMGFMT_BGR4}, | |
208 {"BGR8", IMGFMT_BGR8}, | |
209 {"BGR15", IMGFMT_BGR15}, | |
210 {"BGR16", IMGFMT_BGR16}, | |
211 {"BGR24", IMGFMT_BGR24}, | |
212 {"BGR32", IMGFMT_BGR32}, | |
213 {"RGB1", IMGFMT_RGB1}, | |
214 {"BGR1", IMGFMT_BGR1}, | |
1871 | 215 |
31159 | 216 {"MPES", IMGFMT_MPEGPES}, |
217 {"ZRMJPEGNI", IMGFMT_ZRMJPEGNI}, | |
218 {"ZRMJPEGIT", IMGFMT_ZRMJPEGIT}, | |
219 {"ZRMJPEGIB", IMGFMT_ZRMJPEGIB}, | |
10316 | 220 |
31159 | 221 {"IDCT_MPEG2",IMGFMT_XVMC_IDCT_MPEG2}, |
222 {"MOCO_MPEG2",IMGFMT_XVMC_MOCO_MPEG2}, | |
10316 | 223 |
31159 | 224 {"VDPAU_MPEG1",IMGFMT_VDPAU_MPEG1}, |
225 {"VDPAU_MPEG2",IMGFMT_VDPAU_MPEG2}, | |
226 {"VDPAU_H264",IMGFMT_VDPAU_H264}, | |
227 {"VDPAU_WMV3",IMGFMT_VDPAU_WMV3}, | |
228 {"VDPAU_VC1",IMGFMT_VDPAU_VC1}, | |
229 {"VDPAU_MPEG4",IMGFMT_VDPAU_MPEG4}, | |
28516
79b0bd20433e
Add support for image formats and codecs used by VDPAU
reimar
parents:
27343
diff
changeset
|
230 |
31159 | 231 {NULL, 0} |
232 }; | |
408 | 233 |
607 | 234 |
4675 | 235 static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt, |
31077 | 236 unsigned char *outflags) |
607 | 237 { |
238 | |
31077 | 239 static char *flagstr[] = { |
240 "flip", | |
241 "noflip", | |
242 "yuvhack", | |
243 "query", | |
244 "static", | |
245 NULL | |
246 }; | |
299 | 247 |
31077 | 248 int i, j, freeslots; |
249 unsigned char flags; | |
297 | 250 |
31077 | 251 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) |
252 /* NOTHING */; | |
253 freeslots = CODECS_MAX_OUTFMT - i; | |
254 if (!freeslots) | |
255 goto err_out_too_many; | |
297 | 256 |
31077 | 257 flags = 0; |
258 if(sflags) { | |
259 do { | |
260 for (j = 0; flagstr[j] != NULL; j++) | |
261 if (!strncmp(sflags, flagstr[j], | |
262 strlen(flagstr[j]))) | |
263 break; | |
264 if (flagstr[j] == NULL) | |
265 goto err_out_parse_error; | |
266 flags|=(1<<j); | |
267 sflags+=strlen(flagstr[j]); | |
268 } while (*(sflags++) == ','); | |
361 | 269 |
31077 | 270 if (*(--sflags) != '\0') |
271 goto err_out_parse_error; | |
272 } | |
297 | 273 |
31077 | 274 do { |
275 for (j = 0; fmt_table[j].name != NULL; j++) | |
276 if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name))) | |
277 break; | |
278 if (fmt_table[j].name == NULL) | |
279 goto err_out_parse_error; | |
280 outfmt[i] = fmt_table[j].num; | |
281 outflags[i] = flags; | |
282 ++i; | |
283 sfmt+=strlen(fmt_table[j].name); | |
284 } while ((*(sfmt++) == ',') && --freeslots); | |
319 | 285 |
31077 | 286 if (!freeslots) |
287 goto err_out_too_many; | |
319 | 288 |
31077 | 289 if (*(--sfmt) != '\0') |
290 goto err_out_parse_error; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
291 |
31077 | 292 return 1; |
328 | 293 err_out_too_many: |
31077 | 294 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_TooManyOut); |
295 return 0; | |
361 | 296 err_out_parse_error: |
31077 | 297 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseError); |
298 return 0; | |
297 | 299 } |
300 | |
7180
28677d779205
-afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents:
6927
diff
changeset
|
301 #if 0 |
303 | 302 static short get_driver(char *s,int audioflag) |
297 | 303 { |
31077 | 304 static char *audiodrv[] = { |
305 "null", | |
306 "mp3lib", | |
307 "pcm", | |
308 "libac3", | |
309 "acm", | |
310 "alaw", | |
311 "msgsm", | |
312 "dshow", | |
313 "dvdpcm", | |
314 "hwac3", | |
315 "libvorbis", | |
316 "ffmpeg", | |
317 "libmad", | |
318 "msadpcm", | |
319 "liba52", | |
320 "g72x", | |
321 "imaadpcm", | |
322 "dk4adpcm", | |
323 "dk3adpcm", | |
324 "roqaudio", | |
325 "faad", | |
326 "realaud", | |
327 "libdv", | |
328 NULL | |
329 }; | |
330 static char *videodrv[] = { | |
331 "null", | |
332 "libmpeg2", | |
333 "vfw", | |
334 "dshow", | |
335 "ffmpeg", | |
336 "vfwex", | |
337 "raw", | |
338 "msrle", | |
339 "xanim", | |
340 "msvidc", | |
341 "fli", | |
342 "cinepak", | |
343 "qtrle", | |
344 "nuv", | |
345 "cyuv", | |
346 "qtsmc", | |
347 "ducktm1", | |
348 "roqvideo", | |
349 "qtrpza", | |
350 "mpng", | |
351 "ijpg", | |
352 "zlib", | |
353 "mpegpes", | |
354 "zrmjpeg", | |
355 "realvid", | |
356 "xvid", | |
357 "libdv", | |
358 NULL | |
359 }; | |
360 char **drv=audioflag?audiodrv:videodrv; | |
361 int i; | |
6863 | 362 |
31077 | 363 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i; |
301 | 364 |
31077 | 365 return -1; |
297 | 366 } |
7180
28677d779205
-afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents:
6927
diff
changeset
|
367 #endif |
297 | 368 |
328 | 369 static int validate_codec(codecs_t *c, int type) |
319 | 370 { |
31077 | 371 unsigned int i; |
372 char *tmp_name = c->name; | |
328 | 373 |
31077 | 374 for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++) |
375 /* NOTHING */; | |
3408 | 376 |
31077 | 377 if (i < strlen(tmp_name)) { |
378 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_InvalidCodecName, c->name); | |
379 return 0; | |
380 } | |
3408 | 381 |
31077 | 382 if (!c->info) |
383 c->info = strdup(c->name); | |
3408 | 384 |
385 #if 0 | |
31077 | 386 if (c->fourcc[0] == 0xffffffff) { |
387 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksFourcc, c->name); | |
388 return 0; | |
389 } | |
13936
589b227e3367
fix crash when a "driver" line is missing in codecs.conf.
reimar
parents:
13807
diff
changeset
|
390 #endif |
3408 | 391 |
31077 | 392 if (!c->drv) { |
393 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksDriver, c->name); | |
394 return 0; | |
395 } | |
3408 | 396 |
397 #if 0 | |
32394
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
398 //FIXME: codec->driver == 4;... <- this should not be put in here... |
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
399 //FIXME: Where are they defined ???????????? |
31077 | 400 if (!c->dll && (c->driver == 4 || |
401 (c->driver == 2 && type == TYPE_VIDEO))) { | |
402 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsDLL, c->name); | |
403 return 0; | |
404 } | |
32394
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
405 // FIXME: Can guid.f1 be 0? How does one know that it was not given? |
31077 | 406 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4) |
328 | 407 |
31077 | 408 if (type == TYPE_VIDEO) |
409 if (c->outfmt[0] == 0xffffffff) { | |
410 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsOutfmt, c->name); | |
411 return 0; | |
412 } | |
329 | 413 #endif |
31077 | 414 return 1; |
319 | 415 } |
416 | |
417 static int add_comment(char *s, char **d) | |
418 { | |
31077 | 419 int pos; |
319 | 420 |
31077 | 421 if (!*d) |
422 pos = 0; | |
423 else { | |
424 pos = strlen(*d); | |
425 (*d)[pos++] = '\n'; | |
426 } | |
427 if (!(*d = realloc(*d, pos + strlen(s) + 1))) { | |
428 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantAllocateComment); | |
429 return 0; | |
430 } | |
431 strcpy(*d + pos, s); | |
432 return 1; | |
319 | 433 } |
297 | 434 |
361 | 435 static short get_cpuflags(char *s) |
436 { | |
31077 | 437 static char *flagstr[] = { |
438 "mmx", | |
439 "sse", | |
440 "3dnow", | |
441 NULL | |
442 }; | |
443 int i; | |
444 short flags = 0; | |
361 | 445 |
31077 | 446 do { |
447 for (i = 0; flagstr[i]; i++) | |
448 if (!strncmp(s, flagstr[i], strlen(flagstr[i]))) | |
449 break; | |
450 if (!flagstr[i]) | |
451 goto err_out_parse_error; | |
452 flags |= 1<<i; | |
453 s += strlen(flagstr[i]); | |
454 } while (*(s++) == ','); | |
361 | 455 |
31077 | 456 if (*(--s) != '\0') |
457 goto err_out_parse_error; | |
361 | 458 |
31077 | 459 return flags; |
361 | 460 err_out_parse_error: |
31077 | 461 return 0; |
361 | 462 } |
463 | |
328 | 464 static FILE *fp; |
465 static int line_num = 0; | |
466 static char *line; | |
467 static char *token[MAX_NR_TOKEN]; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
468 static int read_nextline = 1; |
328 | 469 |
470 static int get_token(int min, int max) | |
297 | 471 { |
31077 | 472 static int line_pos; |
473 int i; | |
474 char c; | |
328 | 475 |
31077 | 476 if (max >= MAX_NR_TOKEN) { |
477 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_GetTokenMaxNotLessThanMAX_NR_TOKEN); | |
478 goto out_eof; | |
479 } | |
328 | 480 |
31077 | 481 memset(token, 0x00, sizeof(*token) * max); |
328 | 482 |
31077 | 483 if (read_nextline) { |
484 if (!fgets(line, MAX_LINE_LEN, fp)) | |
485 goto out_eof; | |
486 line_pos = 0; | |
487 ++line_num; | |
488 read_nextline = 0; | |
489 } | |
490 for (i = 0; i < max; i++) { | |
491 while (isspace(line[line_pos])) | |
492 ++line_pos; | |
493 if (line[line_pos] == '\0' || line[line_pos] == '#' || | |
494 line[line_pos] == ';') { | |
495 read_nextline = 1; | |
496 if (i >= min) | |
497 goto out_ok; | |
498 goto out_eol; | |
499 } | |
500 token[i] = line + line_pos; | |
501 c = line[line_pos]; | |
502 if (c == '"' || c == '\'') { | |
503 token[i]++; | |
504 while (line[++line_pos] != c && line[line_pos]) | |
505 /* NOTHING */; | |
506 } else { | |
507 for (/* NOTHING */; !isspace(line[line_pos]) && | |
508 line[line_pos]; line_pos++) | |
509 /* NOTHING */; | |
510 } | |
511 if (!line[line_pos]) { | |
512 read_nextline = 1; | |
513 if (i >= min - 1) | |
514 goto out_ok; | |
515 goto out_eol; | |
516 } | |
517 line[line_pos] = '\0'; | |
518 line_pos++; | |
519 } | |
328 | 520 out_ok: |
31077 | 521 return i; |
328 | 522 out_eof: |
31077 | 523 read_nextline = 1; |
524 return RET_EOF; | |
328 | 525 out_eol: |
31077 | 526 return RET_EOL; |
328 | 527 } |
528 | |
529 static codecs_t *video_codecs=NULL; | |
530 static codecs_t *audio_codecs=NULL; | |
531 static int nr_vcodecs = 0; | |
532 static int nr_acodecs = 0; | |
533 | |
18980
ed69754aa58d
Marks several string parameters as const when they are not modified in the function, Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
18034
diff
changeset
|
534 int parse_codec_cfg(const char *cfgfile) |
328 | 535 { |
31077 | 536 codecs_t *codec = NULL; // current codec |
537 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs | |
538 char *endptr; // strtoul()... | |
539 int *nr_codecsp; | |
540 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ | |
541 int tmp, i; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
542 |
31077 | 543 // in case we call it a second time |
544 codecs_uninit_free(); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
545 |
31077 | 546 nr_vcodecs = 0; |
547 nr_acodecs = 0; | |
297 | 548 |
31077 | 549 if(cfgfile==NULL) { |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
550 #ifdef CODECS2HTML |
31077 | 551 return 0; |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
552 #else |
31077 | 553 video_codecs = builtin_video_codecs; |
554 audio_codecs = builtin_audio_codecs; | |
555 nr_vcodecs = sizeof(builtin_video_codecs)/sizeof(codecs_t); | |
556 nr_acodecs = sizeof(builtin_audio_codecs)/sizeof(codecs_t); | |
557 return 1; | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
558 #endif |
31077 | 559 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
560 |
33844
77bf38091051
Clarify console output when reading optional configuration files.
diego
parents:
33843
diff
changeset
|
561 mp_msg(MSGT_CODECCFG, MSGL_V, "Reading optional codecs config file %s: ", cfgfile); |
297 | 562 |
31077 | 563 if ((fp = fopen(cfgfile, "r")) == NULL) { |
33844
77bf38091051
Clarify console output when reading optional configuration files.
diego
parents:
33843
diff
changeset
|
564 mp_msg(MSGT_CODECCFG, MSGL_V, "%s\n", strerror(errno)); |
31077 | 565 return 0; |
566 } | |
297 | 567 |
31077 | 568 if ((line = malloc(MAX_LINE_LEN + 1)) == NULL) { |
569 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantGetMemoryForLine, strerror(errno)); | |
570 return 0; | |
571 } | |
572 read_nextline = 1; | |
297 | 573 |
31077 | 574 /* |
575 * this only catches release lines at the start of | |
576 * codecs.conf, before audiocodecs and videocodecs. | |
577 */ | |
578 while ((tmp = get_token(1, 1)) == RET_EOL) | |
579 /* NOTHING */; | |
580 if (tmp == RET_EOF) | |
581 goto out; | |
582 if (!strcmp(token[0], "release")) { | |
583 if (get_token(1, 2) < 0) | |
584 goto err_out_parse_error; | |
585 tmp = atoi(token[0]); | |
586 if (tmp < CODEC_CFG_MIN) | |
587 goto err_out_release_num; | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
588 codecs_conf_release = tmp; |
31077 | 589 while ((tmp = get_token(1, 1)) == RET_EOL) |
590 /* NOTHING */; | |
591 if (tmp == RET_EOF) | |
592 goto out; | |
593 } else | |
594 goto err_out_release_num; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
595 |
31077 | 596 /* |
597 * check if the next block starts with 'audiocodec' or | |
598 * with 'videocodec' | |
599 */ | |
600 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) | |
601 goto loop_enter; | |
602 goto err_out_parse_error; | |
328 | 603 |
31077 | 604 while ((tmp = get_token(1, 1)) != RET_EOF) { |
605 if (tmp == RET_EOL) | |
606 continue; | |
607 if (!strcmp(token[0], "audiocodec") || | |
608 !strcmp(token[0], "videocodec")) { | |
609 if (!validate_codec(codec, codec_type)) | |
610 goto err_out_not_valid; | |
611 loop_enter: | |
612 if (*token[0] == 'v') { | |
613 codec_type = TYPE_VIDEO; | |
614 nr_codecsp = &nr_vcodecs; | |
615 codecsp = &video_codecs; | |
616 } else if (*token[0] == 'a') { | |
617 codec_type = TYPE_AUDIO; | |
618 nr_codecsp = &nr_acodecs; | |
619 codecsp = &audio_codecs; | |
361 | 620 #ifdef DEBUG |
31077 | 621 } else { |
622 mp_msg(MSGT_CODECCFG,MSGL_ERR,"picsba\n"); | |
623 goto err_out; | |
361 | 624 #endif |
31077 | 625 } |
626 if (!(*codecsp = realloc(*codecsp, | |
627 sizeof(codecs_t) * (*nr_codecsp + 2)))) { | |
628 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantReallocCodecsp, strerror(errno)); | |
629 goto err_out; | |
630 } | |
631 codec=*codecsp + *nr_codecsp; | |
632 ++*nr_codecsp; | |
633 memset(codec,0,sizeof(codecs_t)); | |
634 memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); | |
635 memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); | |
636 memset(codec->infmt, 0xff, sizeof(codec->infmt)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
637 |
31077 | 638 if (get_token(1, 1) < 0) |
639 goto err_out_parse_error; | |
640 for (i = 0; i < *nr_codecsp - 1; i++) { | |
641 if(( (*codecsp)[i].name!=NULL) && | |
642 (!strcmp(token[0], (*codecsp)[i].name)) ) { | |
643 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNameNotUnique, token[0]); | |
644 goto err_out_print_linenum; | |
645 } | |
646 } | |
647 if (!(codec->name = strdup(token[0]))) { | |
648 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupName, strerror(errno)); | |
649 goto err_out; | |
650 } | |
651 } else if (!strcmp(token[0], "info")) { | |
652 if (codec->info || get_token(1, 1) < 0) | |
653 goto err_out_parse_error; | |
654 if (!(codec->info = strdup(token[0]))) { | |
655 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupInfo, strerror(errno)); | |
656 goto err_out; | |
657 } | |
658 } else if (!strcmp(token[0], "comment")) { | |
659 if (get_token(1, 1) < 0) | |
660 goto err_out_parse_error; | |
661 add_comment(token[0], &codec->comment); | |
662 } else if (!strcmp(token[0], "fourcc")) { | |
663 if (get_token(1, 2) < 0) | |
664 goto err_out_parse_error; | |
665 if (!add_to_fourcc(token[0], token[1], | |
666 codec->fourcc, | |
667 codec->fourccmap)) | |
668 goto err_out_print_linenum; | |
669 } else if (!strcmp(token[0], "format")) { | |
670 if (get_token(1, 2) < 0) | |
671 goto err_out_parse_error; | |
672 if (!add_to_format(token[0], token[1], | |
673 codec->fourcc,codec->fourccmap)) | |
674 goto err_out_print_linenum; | |
675 } else if (!strcmp(token[0], "driver")) { | |
676 if (get_token(1, 1) < 0) | |
677 goto err_out_parse_error; | |
678 if (!(codec->drv = strdup(token[0]))) { | |
679 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupDriver, strerror(errno)); | |
680 goto err_out; | |
681 } | |
682 } else if (!strcmp(token[0], "dll")) { | |
683 if (get_token(1, 1) < 0) | |
684 goto err_out_parse_error; | |
685 if (!(codec->dll = strdup(token[0]))) { | |
686 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupDLL, strerror(errno)); | |
687 goto err_out; | |
688 } | |
689 } else if (!strcmp(token[0], "guid")) { | |
690 if (get_token(11, 11) < 0) | |
691 goto err_out_parse_error; | |
692 codec->guid.f1=strtoul(token[0],&endptr,0); | |
693 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
694 *endptr != '\0') | |
695 goto err_out_parse_error; | |
696 codec->guid.f2=strtoul(token[1],&endptr,0); | |
697 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
698 *endptr != '\0') | |
699 goto err_out_parse_error; | |
700 codec->guid.f3=strtoul(token[2],&endptr,0); | |
701 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
702 *endptr != '\0') | |
703 goto err_out_parse_error; | |
704 for (i = 0; i < 8; i++) { | |
705 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); | |
706 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
707 *endptr != '\0') | |
708 goto err_out_parse_error; | |
709 } | |
710 } else if (!strcmp(token[0], "out")) { | |
711 if (get_token(1, 2) < 0) | |
712 goto err_out_parse_error; | |
713 if (!add_to_inout(token[0], token[1], codec->outfmt, | |
714 codec->outflags)) | |
715 goto err_out_print_linenum; | |
716 } else if (!strcmp(token[0], "in")) { | |
717 if (get_token(1, 2) < 0) | |
718 goto err_out_parse_error; | |
719 if (!add_to_inout(token[0], token[1], codec->infmt, | |
720 codec->inflags)) | |
721 goto err_out_print_linenum; | |
722 } else if (!strcmp(token[0], "flags")) { | |
723 if (get_token(1, 1) < 0) | |
724 goto err_out_parse_error; | |
725 if (!strcmp(token[0], "seekable")) | |
726 codec->flags |= CODECS_FLAG_SEEKABLE; | |
727 else | |
728 if (!strcmp(token[0], "align16")) | |
729 codec->flags |= CODECS_FLAG_ALIGN16; | |
730 else | |
731 goto err_out_parse_error; | |
732 } else if (!strcmp(token[0], "status")) { | |
733 if (get_token(1, 1) < 0) | |
734 goto err_out_parse_error; | |
735 if (!strcasecmp(token[0], "working")) | |
736 codec->status = CODECS_STATUS_WORKING; | |
737 else if (!strcasecmp(token[0], "crashing")) | |
738 codec->status = CODECS_STATUS_NOT_WORKING; | |
739 else if (!strcasecmp(token[0], "untested")) | |
740 codec->status = CODECS_STATUS_UNTESTED; | |
741 else if (!strcasecmp(token[0], "buggy")) | |
742 codec->status = CODECS_STATUS_PROBLEMS; | |
743 else | |
744 goto err_out_parse_error; | |
745 } else if (!strcmp(token[0], "cpuflags")) { | |
746 if (get_token(1, 1) < 0) | |
747 goto err_out_parse_error; | |
748 if (!(codec->cpuflags = get_cpuflags(token[0]))) | |
749 goto err_out_parse_error; | |
750 } else | |
751 goto err_out_parse_error; | |
752 } | |
753 if (!validate_codec(codec, codec_type)) | |
754 goto err_out_not_valid; | |
755 mp_msg(MSGT_CODECCFG,MSGL_INFO,MSGTR_AudioVideoCodecTotals, nr_acodecs, nr_vcodecs); | |
756 if(video_codecs) video_codecs[nr_vcodecs].name = NULL; | |
757 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL; | |
297 | 758 out: |
31077 | 759 free(line); |
760 line=NULL; | |
761 fclose(fp); | |
762 return 1; | |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
763 |
328 | 764 err_out_parse_error: |
31077 | 765 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseError); |
361 | 766 err_out_print_linenum: |
31077 | 767 PRINT_LINENUM; |
297 | 768 err_out: |
31077 | 769 codecs_uninit_free(); |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
770 |
31077 | 771 free(line); |
772 line=NULL; | |
773 line_num = 0; | |
774 fclose(fp); | |
775 return 0; | |
328 | 776 err_out_not_valid: |
31077 | 777 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecDefinitionIncorrect); |
778 goto err_out_print_linenum; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
779 err_out_release_num: |
31077 | 780 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_OutdatedCodecsConf); |
781 goto err_out_print_linenum; | |
297 | 782 } |
783 | |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
784 static void codecs_free(codecs_t* codecs,int count) { |
31077 | 785 int i; |
786 for ( i = 0; i < count; i++) | |
787 if ( codecs[i].name ) { | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
788 free(codecs[i].name); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
789 free(codecs[i].info); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
790 free(codecs[i].comment); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
791 free(codecs[i].dll); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
792 free(codecs[i].drv); |
31077 | 793 } |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
794 free(codecs); |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
795 } |
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
796 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17120
diff
changeset
|
797 void codecs_uninit_free(void) { |
31077 | 798 if (video_codecs) |
799 codecs_free(video_codecs,nr_vcodecs); | |
800 video_codecs=NULL; | |
801 if (audio_codecs) | |
802 codecs_free(audio_codecs,nr_acodecs); | |
803 audio_codecs=NULL; | |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
804 } |
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
805 |
332 | 806 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, |
31077 | 807 codecs_t *start, int force) |
328 | 808 { |
31077 | 809 return find_codec(fourcc, fourccmap, start, 1, force); |
328 | 810 } |
811 | |
332 | 812 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, |
31077 | 813 codecs_t *start, int force) |
328 | 814 { |
31077 | 815 return find_codec(fourcc, fourccmap, start, 0, force); |
328 | 816 } |
817 | |
332 | 818 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, |
31077 | 819 codecs_t *start, int audioflag, int force) |
328 | 820 { |
31077 | 821 int i, j; |
822 codecs_t *c; | |
328 | 823 |
628 | 824 #if 0 |
31077 | 825 if (start) { |
826 for (/* NOTHING */; start->name; start++) { | |
827 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
828 if (start->fourcc[j] == fourcc) { | |
829 if (fourccmap) | |
830 *fourccmap = start->fourccmap[j]; | |
831 return start; | |
832 } | |
833 } | |
834 } | |
835 } else | |
628 | 836 #endif |
31077 | 837 { |
838 if (audioflag) { | |
839 i = nr_acodecs; | |
840 c = audio_codecs; | |
841 } else { | |
842 i = nr_vcodecs; | |
843 c = video_codecs; | |
844 } | |
845 if(!i) return NULL; | |
846 for (/* NOTHING */; i--; c++) { | |
847 if(start && c<=start) continue; | |
848 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
849 // FIXME: do NOT hardwire 'null' name here: | |
850 if (c->fourcc[j]==fourcc || !strcmp(c->drv,"null")) { | |
851 if (fourccmap) | |
852 *fourccmap = c->fourccmap[j]; | |
853 return c; | |
854 } | |
855 } | |
856 if (force) return c; | |
857 } | |
858 } | |
859 return NULL; | |
303 | 860 } |
861 | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
862 void stringset_init(stringset_t *set) { |
31077 | 863 *set = calloc(1, sizeof(char *)); |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
864 } |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
865 |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
866 void stringset_free(stringset_t *set) { |
31077 | 867 int count = 0; |
868 while ((*set)[count]) free((*set)[count++]); | |
869 free(*set); | |
870 *set = NULL; | |
7505 | 871 } |
872 | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
873 void stringset_add(stringset_t *set, const char *str) { |
31077 | 874 int count = 0; |
875 while ((*set)[count]) count++; | |
876 count++; | |
877 *set = realloc(*set, sizeof(char *) * (count + 1)); | |
878 (*set)[count - 1] = strdup(str); | |
879 (*set)[count] = NULL; | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
880 } |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
881 |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
882 int stringset_test(stringset_t *set, const char *str) { |
31077 | 883 stringset_t s; |
884 for (s = *set; *s; s++) | |
885 if (strcmp(*s, str) == 0) | |
886 return 1; | |
887 return 0; | |
5325
9c326f199060
tagging selected codec to avoid trying the same codec several times
arpi
parents:
5284
diff
changeset
|
888 } |
9c326f199060
tagging selected codec to avoid trying the same codec several times
arpi
parents:
5284
diff
changeset
|
889 |
1983 | 890 void list_codecs(int audioflag){ |
31077 | 891 int i; |
892 codecs_t *c; | |
1983 | 893 |
31077 | 894 if (audioflag) { |
895 i = nr_acodecs; | |
896 c = audio_codecs; | |
897 mp_msg(MSGT_CODECCFG,MSGL_INFO,"ac: afm: status: info: [lib/dll]\n"); | |
898 } else { | |
899 i = nr_vcodecs; | |
900 c = video_codecs; | |
901 mp_msg(MSGT_CODECCFG,MSGL_INFO,"vc: vfm: status: info: [lib/dll]\n"); | |
902 } | |
903 if(!i) return; | |
904 for (/* NOTHING */; i--; c++) { | |
905 char* s="unknown "; | |
906 switch(c->status){ | |
907 case CODECS_STATUS_WORKING: s="working ";break; | |
908 case CODECS_STATUS_PROBLEMS: s="problems";break; | |
909 case CODECS_STATUS_NOT_WORKING: s="crashing";break; | |
910 case CODECS_STATUS_UNTESTED: s="untested";break; | |
911 } | |
912 if(c->dll) | |
913 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s [%s]\n",c->name,c->drv,s,c->info,c->dll); | |
914 else | |
915 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s\n",c->name,c->drv,s,c->info); | |
916 } | |
1983 | 917 } |
918 | |
919 | |
607 | 920 #ifdef CODECS2HTML |
31408 | 921 static void wrapline(FILE *f2,char *s){ |
607 | 922 int c; |
923 if(!s){ | |
924 fprintf(f2,"-"); | |
925 return; | |
926 } | |
927 while((c=*s++)){ | |
928 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); | |
929 } | |
930 } | |
931 | |
31409 | 932 static void parsehtml(FILE *f1,FILE *f2,codecs_t *codec){ |
31077 | 933 int c,d; |
934 while((c=fgetc(f1))>=0){ | |
935 if(c!='%'){ | |
936 fputc(c,f2); | |
937 continue; | |
938 } | |
939 d=fgetc(f1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
940 |
31077 | 941 switch(d){ |
942 case '.': | |
943 return; // end of section | |
944 case 'n': | |
945 wrapline(f2,codec->name); break; | |
946 case 'i': | |
947 wrapline(f2,codec->info); break; | |
948 case 'c': | |
949 wrapline(f2,codec->comment); break; | |
950 case 'd': | |
951 wrapline(f2,codec->dll); break; | |
952 case 'D': | |
953 fprintf(f2,"%c",!strcmp(codec->drv,"dshow")?'+':'-'); break; | |
954 case 'F': | |
955 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
956 if(!d || codec->fourcc[d]!=0xFFFFFFFF) | |
957 fprintf(f2,"%s%.4s",d?"<br>":"",(codec->fourcc[d]==0xFFFFFFFF || codec->fourcc[d]<0x20202020)?!d?"-":"":(char*) &codec->fourcc[d]); | |
958 break; | |
959 case 'f': | |
960 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
961 if(codec->fourcc[d]!=0xFFFFFFFF) | |
962 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]); | |
963 break; | |
964 case 'Y': | |
965 for(d=0;d<CODECS_MAX_OUTFMT;d++) | |
966 if(codec->outfmt[d]!=0xFFFFFFFF){ | |
967 for (c=0; fmt_table[c].name; c++) | |
968 if(fmt_table[c].num==codec->outfmt[d]) break; | |
969 if(fmt_table[c].name) | |
970 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name); | |
971 } | |
972 break; | |
973 default: | |
974 fputc(c,f2); | |
975 fputc(d,f2); | |
607 | 976 } |
31077 | 977 } |
607 | 978 } |
979 | |
980 void skiphtml(FILE *f1){ | |
31077 | 981 int c,d; |
982 while((c=fgetc(f1))>=0){ | |
983 if(c!='%'){ | |
984 continue; | |
607 | 985 } |
31077 | 986 d=fgetc(f1); |
987 if(d=='.') return; // end of section | |
988 } | |
607 | 989 } |
990 | |
29115
1e78a310487e
Change type of first argument of the print_int_array function from int to
diego
parents:
28747
diff
changeset
|
991 static void print_int_array(const unsigned int* a, int size) |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
992 { |
31077 | 993 printf("{ "); |
994 while (size--) | |
995 if(abs(*a)<256) | |
996 printf("%d%s", *a++, size?", ":""); | |
997 else | |
998 printf("0x%X%s", *a++, size?", ":""); | |
999 printf(" }"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1000 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1001 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1002 static void print_char_array(const unsigned char* a, int size) |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1003 { |
31077 | 1004 printf("{ "); |
1005 while (size--) | |
1006 if((*a)<10) | |
1007 printf("%d%s", *a++, size?", ":""); | |
1008 else | |
1009 printf("0x%02x%s", *a++, size?", ":""); | |
1010 printf(" }"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1011 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1012 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1013 static void print_string(const char* s) |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1014 { |
31077 | 1015 if (!s) printf("NULL"); |
1016 else printf("\"%s\"", s); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1017 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1018 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1019 int main(int argc, char* argv[]) |
607 | 1020 { |
31077 | 1021 codecs_t *cl; |
1022 FILE *f1; | |
1023 FILE *f2; | |
1024 int c,d,i; | |
1025 int pos; | |
1026 int section=-1; | |
1027 int nr_codecs; | |
1028 int win32=-1; | |
1029 int dshow=-1; | |
1030 int win32ex=-1; | |
607 | 1031 |
31077 | 1032 /* |
1033 * Take path to codecs.conf from command line, or fall back on | |
1034 * etc/codecs.conf | |
1035 */ | |
1036 if (!(nr_codecs = parse_codec_cfg((argc>1)?argv[1]:"etc/codecs.conf"))) | |
1037 exit(1); | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
1038 if (codecs_conf_release < CODEC_CFG_MIN) |
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
1039 exit(1); |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1040 |
31077 | 1041 if (argc > 1) { |
1042 int i, j; | |
1043 const char* nm[2]; | |
1044 codecs_t* cod[2]; | |
1045 int nr[2]; | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1046 |
31077 | 1047 nm[0] = "builtin_video_codecs"; |
1048 cod[0] = video_codecs; | |
1049 nr[0] = nr_vcodecs; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1050 |
31077 | 1051 nm[1] = "builtin_audio_codecs"; |
1052 cod[1] = audio_codecs; | |
1053 nr[1] = nr_acodecs; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1054 |
31077 | 1055 printf("/* GENERATED FROM %s, DO NOT EDIT! */\n\n",argv[1]); |
31407 | 1056 printf("#include <stddef.h>\n"); |
1057 printf("#include \"codec-cfg.h\"\n\n"); | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
1058 printf("#define CODEC_CFG_MIN %i\n\n", codecs_conf_release); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1059 |
31077 | 1060 for (i=0; i<2; i++) { |
1061 printf("const codecs_t %s[] = {\n", nm[i]); | |
1062 for (j = 0; j < nr[i]; j++) { | |
1063 printf("{"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1064 |
31077 | 1065 print_int_array(cod[i][j].fourcc, CODECS_MAX_FOURCC); |
1066 printf(", /* fourcc */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1067 |
31077 | 1068 print_int_array(cod[i][j].fourccmap, CODECS_MAX_FOURCC); |
1069 printf(", /* fourccmap */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1070 |
31077 | 1071 print_int_array(cod[i][j].outfmt, CODECS_MAX_OUTFMT); |
1072 printf(", /* outfmt */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1073 |
31077 | 1074 print_char_array(cod[i][j].outflags, CODECS_MAX_OUTFMT); |
1075 printf(", /* outflags */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1076 |
31077 | 1077 print_int_array(cod[i][j].infmt, CODECS_MAX_INFMT); |
1078 printf(", /* infmt */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1079 |
31077 | 1080 print_char_array(cod[i][j].inflags, CODECS_MAX_INFMT); |
1081 printf(", /* inflags */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1082 |
31077 | 1083 print_string(cod[i][j].name); printf(", /* name */\n"); |
1084 print_string(cod[i][j].info); printf(", /* info */\n"); | |
1085 print_string(cod[i][j].comment); printf(", /* comment */\n"); | |
1086 print_string(cod[i][j].dll); printf(", /* dll */\n"); | |
1087 print_string(cod[i][j].drv); printf(", /* drv */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1088 |
31077 | 1089 printf("{ 0x%08lx, %hu, %hu,", |
1090 cod[i][j].guid.f1, | |
1091 cod[i][j].guid.f2, | |
1092 cod[i][j].guid.f3); | |
1093 print_char_array(cod[i][j].guid.f4, sizeof(cod[i][j].guid.f4)); | |
1094 printf(" }, /* GUID */\n"); | |
1095 printf("%hd /* flags */, %hd /* status */, %hd /* cpuflags */ }\n", | |
1096 cod[i][j].flags, | |
1097 cod[i][j].status, | |
1098 cod[i][j].cpuflags); | |
1099 if (j < nr[i]) printf(",\n"); | |
607 | 1100 } |
31077 | 1101 printf("};\n\n"); |
1102 } | |
1103 exit(0); | |
1104 } | |
1105 | |
1106 f1=fopen("DOCS/tech/codecs-in.html","rb"); if(!f1) exit(1); | |
1107 f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); | |
1108 | |
1109 while((c=fgetc(f1))>=0){ | |
1110 if(c!='%'){ | |
1111 fputc(c,f2); | |
1112 continue; | |
1113 } | |
1114 d=fgetc(f1); | |
1115 if(d>='0' && d<='9'){ | |
1116 // begin section | |
1117 section=d-'0'; | |
1118 //printf("BEGIN %d\n",section); | |
1119 if(section>=5){ | |
1120 // audio | |
1121 cl = audio_codecs; | |
1122 nr_codecs = nr_acodecs; | |
1123 dshow=7;win32=4; | |
1124 } else { | |
1125 // video | |
1126 cl = video_codecs; | |
1127 nr_codecs = nr_vcodecs; | |
1128 dshow=4;win32=2;win32ex=6; | |
1129 } | |
1130 pos=ftell(f1); | |
1131 for(i=0;i<nr_codecs;i++){ | |
1132 fseek(f1,pos,SEEK_SET); | |
1133 switch(section){ | |
1134 case 0: | |
1135 case 5: | |
1136 if(cl[i].status==CODECS_STATUS_WORKING) | |
1137 // if(!(!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm"))) | |
31409 | 1138 parsehtml(f1,f2,&cl[i]); |
31077 | 1139 break; |
8211 | 1140 #if 0 |
31077 | 1141 case 1: |
1142 case 6: | |
1143 if(cl[i].status==CODECS_STATUS_WORKING) | |
1144 if((!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm"))) | |
31409 | 1145 parsehtml(f1,f2,&cl[i]); |
31077 | 1146 break; |
1147 #endif | |
1148 case 2: | |
1149 case 7: | |
1150 if(cl[i].status==CODECS_STATUS_PROBLEMS) | |
31409 | 1151 parsehtml(f1,f2,&cl[i]); |
31077 | 1152 break; |
1153 case 3: | |
1154 case 8: | |
1155 if(cl[i].status==CODECS_STATUS_NOT_WORKING) | |
31409 | 1156 parsehtml(f1,f2,&cl[i]); |
31077 | 1157 break; |
1158 case 4: | |
1159 case 9: | |
1160 if(cl[i].status==CODECS_STATUS_UNTESTED) | |
31409 | 1161 parsehtml(f1,f2,&cl[i]); |
31077 | 1162 break; |
1163 default: | |
1164 printf("Warning! unimplemented section: %d\n",section); | |
607 | 1165 } |
31077 | 1166 } |
1167 fseek(f1,pos,SEEK_SET); | |
1168 skiphtml(f1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1169 |
31077 | 1170 continue; |
607 | 1171 } |
31077 | 1172 fputc(c,f2); |
1173 fputc(d,f2); | |
1174 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1175 |
31077 | 1176 fclose(f2); |
1177 fclose(f1); | |
1178 return 0; | |
607 | 1179 } |
1180 | |
1181 #endif | |
1182 | |
297 | 1183 #ifdef TESTING |
1184 int main(void) | |
1185 { | |
31077 | 1186 codecs_t *c; |
1187 int i,j, nr_codecs, state; | |
297 | 1188 |
31077 | 1189 if (!(parse_codec_cfg("etc/codecs.conf"))) |
1190 return 0; | |
1191 if (!video_codecs) | |
1192 printf("no videoconfig.\n"); | |
1193 if (!audio_codecs) | |
1194 printf("no audioconfig.\n"); | |
328 | 1195 |
31077 | 1196 printf("videocodecs:\n"); |
1197 c = video_codecs; | |
1198 nr_codecs = nr_vcodecs; | |
1199 state = 0; | |
328 | 1200 next: |
31077 | 1201 if (c) { |
1202 printf("number of %scodecs: %d\n", state==0?"video":"audio", | |
1203 nr_codecs); | |
1204 for(i=0;i<nr_codecs;i++, c++){ | |
1205 printf("\n============== %scodec %02d ===============\n", | |
1206 state==0?"video":"audio",i); | |
1207 printf("name='%s'\n",c->name); | |
1208 printf("info='%s'\n",c->info); | |
1209 printf("comment='%s'\n",c->comment); | |
1210 printf("dll='%s'\n",c->dll); | |
1211 /* printf("flags=%X driver=%d status=%d cpuflags=%d\n", | |
1212 c->flags, c->driver, c->status, c->cpuflags); */ | |
1213 printf("flags=%X status=%d cpuflags=%d\n", | |
1214 c->flags, c->status, c->cpuflags); | |
300 | 1215 |
31077 | 1216 for(j=0;j<CODECS_MAX_FOURCC;j++){ |
1217 if(c->fourcc[j]!=0xFFFFFFFF){ | |
1218 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]); | |
1219 } | |
1220 } | |
328 | 1221 |
31077 | 1222 for(j=0;j<CODECS_MAX_OUTFMT;j++){ |
1223 if(c->outfmt[j]!=0xFFFFFFFF){ | |
1224 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]); | |
1225 } | |
1226 } | |
300 | 1227 |
31077 | 1228 for(j=0;j<CODECS_MAX_INFMT;j++){ |
1229 if(c->infmt[j]!=0xFFFFFFFF){ | |
1230 printf("infmt %02d: %08X (%.4s) flags: %d\n",j,c->infmt[j],(char *) &c->infmt[j],c->inflags[j]); | |
1231 } | |
1232 } | |
4676 | 1233 |
31077 | 1234 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); |
1235 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); | |
1236 printf("\n"); | |
300 | 1237 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1238 |
31077 | 1239 } |
1240 } | |
1241 if (!state) { | |
1242 printf("audiocodecs:\n"); | |
1243 c = audio_codecs; | |
1244 nr_codecs = nr_acodecs; | |
1245 state = 1; | |
1246 goto next; | |
1247 } | |
1248 return 0; | |
297 | 1249 } |
1250 | |
1251 #endif |