Mercurial > mplayer.hg
annotate codec-cfg.c @ 32764:da6f5584da98
sync with en/mplayer.1 rev. 32842
author | jrash |
---|---|
date | Sat, 05 Feb 2011 03:35:40 +0000 |
parents | b39155e98ac3 |
children | 881d0b46bc62 |
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 | |
32394
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
394 //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
|
395 //FIXME: 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 } | |
32394
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
401 // FIXME: 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 ) { | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
784 free(codecs[i].name); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
785 free(codecs[i].info); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
786 free(codecs[i].comment); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
787 free(codecs[i].dll); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
788 free(codecs[i].drv); |
31077 | 789 } |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
790 free(codecs); |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
791 } |
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
792 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17120
diff
changeset
|
793 void codecs_uninit_free(void) { |
31077 | 794 if (video_codecs) |
795 codecs_free(video_codecs,nr_vcodecs); | |
796 video_codecs=NULL; | |
797 if (audio_codecs) | |
798 codecs_free(audio_codecs,nr_acodecs); | |
799 audio_codecs=NULL; | |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
800 } |
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
801 |
332 | 802 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, |
31077 | 803 codecs_t *start, int force) |
328 | 804 { |
31077 | 805 return find_codec(fourcc, fourccmap, start, 1, force); |
328 | 806 } |
807 | |
332 | 808 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, |
31077 | 809 codecs_t *start, int force) |
328 | 810 { |
31077 | 811 return find_codec(fourcc, fourccmap, start, 0, force); |
328 | 812 } |
813 | |
332 | 814 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, |
31077 | 815 codecs_t *start, int audioflag, int force) |
328 | 816 { |
31077 | 817 int i, j; |
818 codecs_t *c; | |
328 | 819 |
628 | 820 #if 0 |
31077 | 821 if (start) { |
822 for (/* NOTHING */; start->name; start++) { | |
823 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
824 if (start->fourcc[j] == fourcc) { | |
825 if (fourccmap) | |
826 *fourccmap = start->fourccmap[j]; | |
827 return start; | |
828 } | |
829 } | |
830 } | |
831 } else | |
628 | 832 #endif |
31077 | 833 { |
834 if (audioflag) { | |
835 i = nr_acodecs; | |
836 c = audio_codecs; | |
837 } else { | |
838 i = nr_vcodecs; | |
839 c = video_codecs; | |
840 } | |
841 if(!i) return NULL; | |
842 for (/* NOTHING */; i--; c++) { | |
843 if(start && c<=start) continue; | |
844 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
845 // FIXME: do NOT hardwire 'null' name here: | |
846 if (c->fourcc[j]==fourcc || !strcmp(c->drv,"null")) { | |
847 if (fourccmap) | |
848 *fourccmap = c->fourccmap[j]; | |
849 return c; | |
850 } | |
851 } | |
852 if (force) return c; | |
853 } | |
854 } | |
855 return NULL; | |
303 | 856 } |
857 | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
858 void stringset_init(stringset_t *set) { |
31077 | 859 *set = calloc(1, sizeof(char *)); |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
860 } |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
861 |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
862 void stringset_free(stringset_t *set) { |
31077 | 863 int count = 0; |
864 while ((*set)[count]) free((*set)[count++]); | |
865 free(*set); | |
866 *set = NULL; | |
7505 | 867 } |
868 | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
869 void stringset_add(stringset_t *set, const char *str) { |
31077 | 870 int count = 0; |
871 while ((*set)[count]) count++; | |
872 count++; | |
873 *set = realloc(*set, sizeof(char *) * (count + 1)); | |
874 (*set)[count - 1] = strdup(str); | |
875 (*set)[count] = NULL; | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
876 } |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
877 |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
878 int stringset_test(stringset_t *set, const char *str) { |
31077 | 879 stringset_t s; |
880 for (s = *set; *s; s++) | |
881 if (strcmp(*s, str) == 0) | |
882 return 1; | |
883 return 0; | |
5325
9c326f199060
tagging selected codec to avoid trying the same codec several times
arpi
parents:
5284
diff
changeset
|
884 } |
9c326f199060
tagging selected codec to avoid trying the same codec several times
arpi
parents:
5284
diff
changeset
|
885 |
1983 | 886 void list_codecs(int audioflag){ |
31077 | 887 int i; |
888 codecs_t *c; | |
1983 | 889 |
31077 | 890 if (audioflag) { |
891 i = nr_acodecs; | |
892 c = audio_codecs; | |
893 mp_msg(MSGT_CODECCFG,MSGL_INFO,"ac: afm: status: info: [lib/dll]\n"); | |
894 } else { | |
895 i = nr_vcodecs; | |
896 c = video_codecs; | |
897 mp_msg(MSGT_CODECCFG,MSGL_INFO,"vc: vfm: status: info: [lib/dll]\n"); | |
898 } | |
899 if(!i) return; | |
900 for (/* NOTHING */; i--; c++) { | |
901 char* s="unknown "; | |
902 switch(c->status){ | |
903 case CODECS_STATUS_WORKING: s="working ";break; | |
904 case CODECS_STATUS_PROBLEMS: s="problems";break; | |
905 case CODECS_STATUS_NOT_WORKING: s="crashing";break; | |
906 case CODECS_STATUS_UNTESTED: s="untested";break; | |
907 } | |
908 if(c->dll) | |
909 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s [%s]\n",c->name,c->drv,s,c->info,c->dll); | |
910 else | |
911 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s\n",c->name,c->drv,s,c->info); | |
912 } | |
1983 | 913 } |
914 | |
915 | |
607 | 916 #ifdef CODECS2HTML |
31408 | 917 static void wrapline(FILE *f2,char *s){ |
607 | 918 int c; |
919 if(!s){ | |
920 fprintf(f2,"-"); | |
921 return; | |
922 } | |
923 while((c=*s++)){ | |
924 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); | |
925 } | |
926 } | |
927 | |
31409 | 928 static void parsehtml(FILE *f1,FILE *f2,codecs_t *codec){ |
31077 | 929 int c,d; |
930 while((c=fgetc(f1))>=0){ | |
931 if(c!='%'){ | |
932 fputc(c,f2); | |
933 continue; | |
934 } | |
935 d=fgetc(f1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
936 |
31077 | 937 switch(d){ |
938 case '.': | |
939 return; // end of section | |
940 case 'n': | |
941 wrapline(f2,codec->name); break; | |
942 case 'i': | |
943 wrapline(f2,codec->info); break; | |
944 case 'c': | |
945 wrapline(f2,codec->comment); break; | |
946 case 'd': | |
947 wrapline(f2,codec->dll); break; | |
948 case 'D': | |
949 fprintf(f2,"%c",!strcmp(codec->drv,"dshow")?'+':'-'); break; | |
950 case 'F': | |
951 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
952 if(!d || codec->fourcc[d]!=0xFFFFFFFF) | |
953 fprintf(f2,"%s%.4s",d?"<br>":"",(codec->fourcc[d]==0xFFFFFFFF || codec->fourcc[d]<0x20202020)?!d?"-":"":(char*) &codec->fourcc[d]); | |
954 break; | |
955 case 'f': | |
956 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
957 if(codec->fourcc[d]!=0xFFFFFFFF) | |
958 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]); | |
959 break; | |
960 case 'Y': | |
961 for(d=0;d<CODECS_MAX_OUTFMT;d++) | |
962 if(codec->outfmt[d]!=0xFFFFFFFF){ | |
963 for (c=0; fmt_table[c].name; c++) | |
964 if(fmt_table[c].num==codec->outfmt[d]) break; | |
965 if(fmt_table[c].name) | |
966 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name); | |
967 } | |
968 break; | |
969 default: | |
970 fputc(c,f2); | |
971 fputc(d,f2); | |
607 | 972 } |
31077 | 973 } |
607 | 974 } |
975 | |
976 void skiphtml(FILE *f1){ | |
31077 | 977 int c,d; |
978 while((c=fgetc(f1))>=0){ | |
979 if(c!='%'){ | |
980 continue; | |
607 | 981 } |
31077 | 982 d=fgetc(f1); |
983 if(d=='.') return; // end of section | |
984 } | |
607 | 985 } |
986 | |
29115
1e78a310487e
Change type of first argument of the print_int_array function from int to
diego
parents:
28747
diff
changeset
|
987 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
|
988 { |
31077 | 989 printf("{ "); |
990 while (size--) | |
991 if(abs(*a)<256) | |
992 printf("%d%s", *a++, size?", ":""); | |
993 else | |
994 printf("0x%X%s", *a++, size?", ":""); | |
995 printf(" }"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
996 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
997 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
998 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
|
999 { |
31077 | 1000 printf("{ "); |
1001 while (size--) | |
1002 if((*a)<10) | |
1003 printf("%d%s", *a++, size?", ":""); | |
1004 else | |
1005 printf("0x%02x%s", *a++, size?", ":""); | |
1006 printf(" }"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1007 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1008 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1009 static void print_string(const char* s) |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1010 { |
31077 | 1011 if (!s) printf("NULL"); |
1012 else printf("\"%s\"", s); | |
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 int main(int argc, char* argv[]) |
607 | 1016 { |
31077 | 1017 codecs_t *cl; |
1018 FILE *f1; | |
1019 FILE *f2; | |
1020 int c,d,i; | |
1021 int pos; | |
1022 int section=-1; | |
1023 int nr_codecs; | |
1024 int win32=-1; | |
1025 int dshow=-1; | |
1026 int win32ex=-1; | |
607 | 1027 |
31077 | 1028 /* |
1029 * Take path to codecs.conf from command line, or fall back on | |
1030 * etc/codecs.conf | |
1031 */ | |
1032 if (!(nr_codecs = parse_codec_cfg((argc>1)?argv[1]:"etc/codecs.conf"))) | |
1033 exit(1); | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
1034 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
|
1035 exit(1); |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1036 |
31077 | 1037 if (argc > 1) { |
1038 int i, j; | |
1039 const char* nm[2]; | |
1040 codecs_t* cod[2]; | |
1041 int nr[2]; | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1042 |
31077 | 1043 nm[0] = "builtin_video_codecs"; |
1044 cod[0] = video_codecs; | |
1045 nr[0] = nr_vcodecs; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1046 |
31077 | 1047 nm[1] = "builtin_audio_codecs"; |
1048 cod[1] = audio_codecs; | |
1049 nr[1] = nr_acodecs; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1050 |
31077 | 1051 printf("/* GENERATED FROM %s, DO NOT EDIT! */\n\n",argv[1]); |
31407 | 1052 printf("#include <stddef.h>\n"); |
1053 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
|
1054 printf("#define CODEC_CFG_MIN %i\n\n", codecs_conf_release); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1055 |
31077 | 1056 for (i=0; i<2; i++) { |
1057 printf("const codecs_t %s[] = {\n", nm[i]); | |
1058 for (j = 0; j < nr[i]; j++) { | |
1059 printf("{"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1060 |
31077 | 1061 print_int_array(cod[i][j].fourcc, CODECS_MAX_FOURCC); |
1062 printf(", /* fourcc */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1063 |
31077 | 1064 print_int_array(cod[i][j].fourccmap, CODECS_MAX_FOURCC); |
1065 printf(", /* fourccmap */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1066 |
31077 | 1067 print_int_array(cod[i][j].outfmt, CODECS_MAX_OUTFMT); |
1068 printf(", /* outfmt */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1069 |
31077 | 1070 print_char_array(cod[i][j].outflags, CODECS_MAX_OUTFMT); |
1071 printf(", /* outflags */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1072 |
31077 | 1073 print_int_array(cod[i][j].infmt, CODECS_MAX_INFMT); |
1074 printf(", /* infmt */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1075 |
31077 | 1076 print_char_array(cod[i][j].inflags, CODECS_MAX_INFMT); |
1077 printf(", /* inflags */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1078 |
31077 | 1079 print_string(cod[i][j].name); printf(", /* name */\n"); |
1080 print_string(cod[i][j].info); printf(", /* info */\n"); | |
1081 print_string(cod[i][j].comment); printf(", /* comment */\n"); | |
1082 print_string(cod[i][j].dll); printf(", /* dll */\n"); | |
1083 print_string(cod[i][j].drv); printf(", /* drv */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1084 |
31077 | 1085 printf("{ 0x%08lx, %hu, %hu,", |
1086 cod[i][j].guid.f1, | |
1087 cod[i][j].guid.f2, | |
1088 cod[i][j].guid.f3); | |
1089 print_char_array(cod[i][j].guid.f4, sizeof(cod[i][j].guid.f4)); | |
1090 printf(" }, /* GUID */\n"); | |
1091 printf("%hd /* flags */, %hd /* status */, %hd /* cpuflags */ }\n", | |
1092 cod[i][j].flags, | |
1093 cod[i][j].status, | |
1094 cod[i][j].cpuflags); | |
1095 if (j < nr[i]) printf(",\n"); | |
607 | 1096 } |
31077 | 1097 printf("};\n\n"); |
1098 } | |
1099 exit(0); | |
1100 } | |
1101 | |
1102 f1=fopen("DOCS/tech/codecs-in.html","rb"); if(!f1) exit(1); | |
1103 f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); | |
1104 | |
1105 while((c=fgetc(f1))>=0){ | |
1106 if(c!='%'){ | |
1107 fputc(c,f2); | |
1108 continue; | |
1109 } | |
1110 d=fgetc(f1); | |
1111 if(d>='0' && d<='9'){ | |
1112 // begin section | |
1113 section=d-'0'; | |
1114 //printf("BEGIN %d\n",section); | |
1115 if(section>=5){ | |
1116 // audio | |
1117 cl = audio_codecs; | |
1118 nr_codecs = nr_acodecs; | |
1119 dshow=7;win32=4; | |
1120 } else { | |
1121 // video | |
1122 cl = video_codecs; | |
1123 nr_codecs = nr_vcodecs; | |
1124 dshow=4;win32=2;win32ex=6; | |
1125 } | |
1126 pos=ftell(f1); | |
1127 for(i=0;i<nr_codecs;i++){ | |
1128 fseek(f1,pos,SEEK_SET); | |
1129 switch(section){ | |
1130 case 0: | |
1131 case 5: | |
1132 if(cl[i].status==CODECS_STATUS_WORKING) | |
1133 // if(!(!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm"))) | |
31409 | 1134 parsehtml(f1,f2,&cl[i]); |
31077 | 1135 break; |
8211 | 1136 #if 0 |
31077 | 1137 case 1: |
1138 case 6: | |
1139 if(cl[i].status==CODECS_STATUS_WORKING) | |
1140 if((!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm"))) | |
31409 | 1141 parsehtml(f1,f2,&cl[i]); |
31077 | 1142 break; |
1143 #endif | |
1144 case 2: | |
1145 case 7: | |
1146 if(cl[i].status==CODECS_STATUS_PROBLEMS) | |
31409 | 1147 parsehtml(f1,f2,&cl[i]); |
31077 | 1148 break; |
1149 case 3: | |
1150 case 8: | |
1151 if(cl[i].status==CODECS_STATUS_NOT_WORKING) | |
31409 | 1152 parsehtml(f1,f2,&cl[i]); |
31077 | 1153 break; |
1154 case 4: | |
1155 case 9: | |
1156 if(cl[i].status==CODECS_STATUS_UNTESTED) | |
31409 | 1157 parsehtml(f1,f2,&cl[i]); |
31077 | 1158 break; |
1159 default: | |
1160 printf("Warning! unimplemented section: %d\n",section); | |
607 | 1161 } |
31077 | 1162 } |
1163 fseek(f1,pos,SEEK_SET); | |
1164 skiphtml(f1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1165 |
31077 | 1166 continue; |
607 | 1167 } |
31077 | 1168 fputc(c,f2); |
1169 fputc(d,f2); | |
1170 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1171 |
31077 | 1172 fclose(f2); |
1173 fclose(f1); | |
1174 return 0; | |
607 | 1175 } |
1176 | |
1177 #endif | |
1178 | |
297 | 1179 #ifdef TESTING |
1180 int main(void) | |
1181 { | |
31077 | 1182 codecs_t *c; |
1183 int i,j, nr_codecs, state; | |
297 | 1184 |
31077 | 1185 if (!(parse_codec_cfg("etc/codecs.conf"))) |
1186 return 0; | |
1187 if (!video_codecs) | |
1188 printf("no videoconfig.\n"); | |
1189 if (!audio_codecs) | |
1190 printf("no audioconfig.\n"); | |
328 | 1191 |
31077 | 1192 printf("videocodecs:\n"); |
1193 c = video_codecs; | |
1194 nr_codecs = nr_vcodecs; | |
1195 state = 0; | |
328 | 1196 next: |
31077 | 1197 if (c) { |
1198 printf("number of %scodecs: %d\n", state==0?"video":"audio", | |
1199 nr_codecs); | |
1200 for(i=0;i<nr_codecs;i++, c++){ | |
1201 printf("\n============== %scodec %02d ===============\n", | |
1202 state==0?"video":"audio",i); | |
1203 printf("name='%s'\n",c->name); | |
1204 printf("info='%s'\n",c->info); | |
1205 printf("comment='%s'\n",c->comment); | |
1206 printf("dll='%s'\n",c->dll); | |
1207 /* printf("flags=%X driver=%d status=%d cpuflags=%d\n", | |
1208 c->flags, c->driver, c->status, c->cpuflags); */ | |
1209 printf("flags=%X status=%d cpuflags=%d\n", | |
1210 c->flags, c->status, c->cpuflags); | |
300 | 1211 |
31077 | 1212 for(j=0;j<CODECS_MAX_FOURCC;j++){ |
1213 if(c->fourcc[j]!=0xFFFFFFFF){ | |
1214 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]); | |
1215 } | |
1216 } | |
328 | 1217 |
31077 | 1218 for(j=0;j<CODECS_MAX_OUTFMT;j++){ |
1219 if(c->outfmt[j]!=0xFFFFFFFF){ | |
1220 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]); | |
1221 } | |
1222 } | |
300 | 1223 |
31077 | 1224 for(j=0;j<CODECS_MAX_INFMT;j++){ |
1225 if(c->infmt[j]!=0xFFFFFFFF){ | |
1226 printf("infmt %02d: %08X (%.4s) flags: %d\n",j,c->infmt[j],(char *) &c->infmt[j],c->inflags[j]); | |
1227 } | |
1228 } | |
4676 | 1229 |
31077 | 1230 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); |
1231 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); | |
1232 printf("\n"); | |
300 | 1233 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1234 |
31077 | 1235 } |
1236 } | |
1237 if (!state) { | |
1238 printf("audiocodecs:\n"); | |
1239 c = audio_codecs; | |
1240 nr_codecs = nr_acodecs; | |
1241 state = 1; | |
1242 goto next; | |
1243 } | |
1244 return 0; | |
297 | 1245 } |
1246 | |
1247 #endif |