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