Mercurial > mplayer.hg
annotate codec-cfg.c @ 5264:d3846ebe974d
added zlib
author | alex |
---|---|
date | Fri, 22 Mar 2002 22:14:01 +0000 |
parents | da664f9894e8 |
children | 0a58c2ef1da1 |
rev | line source |
---|---|
319 | 1 /* |
2 * codec.conf parser | |
3 * by Szabolcs Berecz <szabi@inf.elte.hu> | |
4 * (C) 2001 | |
4676 | 5 * |
6 * to compile tester app: gcc -Iloader/ -DTESTING -o codec-cfg codec-cfg.c | |
7 * to compile CODECS2HTML: gcc -Iloader/ -DCODECS2HTML -o codecs2html codecs-cfg.c | |
8 * | |
9 * TODO: implement informat in CODECS2HTML too | |
319 | 10 */ |
303 | 11 |
319 | 12 #define DEBUG |
303 | 13 |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
14 //disable asserts |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
15 #define NDEBUG |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
16 |
297 | 17 #include <stdio.h> |
18 #include <stdlib.h> | |
19 #include <fcntl.h> | |
20 #include <unistd.h> | |
21 #include <errno.h> | |
22 #include <ctype.h> | |
23 #include <assert.h> | |
24 #include <string.h> | |
25 | |
2052 | 26 // for mmioFOURCC: |
1305
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
27 #include "wine/avifmt.h" |
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
28 |
2897 | 29 #ifdef USE_LIBVO2 |
30 #include "libvo2/img_format.h" | |
31 #else | |
408 | 32 #include "libvo/img_format.h" |
2897 | 33 #endif |
297 | 34 #include "codec-cfg.h" |
35 | |
361 | 36 #define PRINT_LINENUM printf(" at line %d\n", line_num) |
328 | 37 |
319 | 38 #define MAX_NR_TOKEN 16 |
297 | 39 |
40 #define MAX_LINE_LEN 1000 | |
41 | |
42 #define RET_EOF -1 | |
43 #define RET_EOL -2 | |
44 | |
328 | 45 #define TYPE_VIDEO 0 |
46 #define TYPE_AUDIO 1 | |
297 | 47 |
303 | 48 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc, |
297 | 49 unsigned int *map) |
50 { | |
319 | 51 int i, j, freeslots; |
52 unsigned int tmp; | |
53 | |
54 /* find first unused slot */ | |
55 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
56 /* NOTHING */; | |
57 freeslots = CODECS_MAX_FOURCC - i; | |
58 if (!freeslots) | |
328 | 59 goto err_out_too_many; |
319 | 60 |
61 do { | |
1305
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
62 tmp = mmioFOURCC(s[0], s[1], s[2], s[3]); |
319 | 63 for (j = 0; j < i; j++) |
64 if (tmp == fourcc[j]) | |
328 | 65 goto err_out_duplicated; |
319 | 66 fourcc[i] = tmp; |
2681 | 67 map[i] = alias ? mmioFOURCC(alias[0], alias[1], alias[2], alias[3]) : tmp; |
319 | 68 s += 4; |
69 i++; | |
70 } while ((*(s++) == ',') && --freeslots); | |
71 | |
72 if (!freeslots) | |
328 | 73 goto err_out_too_many; |
319 | 74 if (*(--s) != '\0') |
361 | 75 goto err_out_parse_error; |
319 | 76 return 1; |
328 | 77 err_out_duplicated: |
361 | 78 printf("duplicated fourcc/format"); |
319 | 79 return 0; |
328 | 80 err_out_too_many: |
361 | 81 printf("too many fourcc/format..."); |
82 return 0; | |
83 err_out_parse_error: | |
84 printf("parse error"); | |
319 | 85 return 0; |
86 } | |
87 | |
88 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap) | |
89 { | |
90 int i, j; | |
361 | 91 char *endptr; |
297 | 92 |
93 /* find first unused slot */ | |
94 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
95 /* NOTHING */; | |
96 if (i == CODECS_MAX_FOURCC) { | |
361 | 97 printf("too many fourcc/format..."); |
297 | 98 return 0; |
99 } | |
100 | |
361 | 101 fourcc[i]=fourccmap[i]=strtoul(s,&endptr,0); |
102 if (*endptr != '\0') { | |
103 printf("parse error"); | |
104 return 0; | |
105 } | |
319 | 106 for (j = 0; j < i; j++) |
107 if (fourcc[j] == fourcc[i]) { | |
361 | 108 printf("duplicated fourcc/format"); |
319 | 109 return 0; |
110 } | |
300 | 111 |
297 | 112 return 1; |
113 } | |
114 | |
408 | 115 static struct { |
116 const char *name; | |
117 const unsigned int num; | |
118 } fmt_table[] = { | |
415 | 119 {"YV12", IMGFMT_YV12}, |
120 {"I420", IMGFMT_I420}, | |
121 {"IYUV", IMGFMT_IYUV}, | |
408 | 122 |
415 | 123 {"YUY2", IMGFMT_YUY2}, |
124 {"UYVY", IMGFMT_UYVY}, | |
125 {"YVYU", IMGFMT_YVYU}, | |
408 | 126 |
415 | 127 {"RGB8", IMGFMT_RGB|8}, |
128 {"RGB15", IMGFMT_RGB|15}, | |
129 {"RGB16", IMGFMT_RGB|16}, | |
130 {"RGB24", IMGFMT_RGB|24}, | |
131 {"RGB32", IMGFMT_RGB|32}, | |
132 {"BGR8", IMGFMT_BGR|8}, | |
133 {"BGR15", IMGFMT_BGR|15}, | |
134 {"BGR16", IMGFMT_BGR|16}, | |
135 {"BGR24", IMGFMT_BGR|24}, | |
136 {"BGR32", IMGFMT_BGR|32}, | |
1871 | 137 |
138 {"MPES", IMGFMT_MPEGPES}, | |
415 | 139 {NULL, 0} |
297 | 140 }; |
408 | 141 |
607 | 142 |
4675 | 143 static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt, |
607 | 144 unsigned char *outflags) |
145 { | |
146 | |
299 | 147 static char *flagstr[] = { |
148 "flip", | |
149 "noflip", | |
150 "yuvhack", | |
5249 | 151 "query", |
299 | 152 NULL |
153 }; | |
154 | |
319 | 155 int i, j, freeslots; |
297 | 156 unsigned char flags; |
157 | |
158 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) | |
159 /* NOTHING */; | |
319 | 160 freeslots = CODECS_MAX_OUTFMT - i; |
161 if (!freeslots) | |
328 | 162 goto err_out_too_many; |
297 | 163 |
319 | 164 flags = 0; |
361 | 165 if(sflags) { |
166 do { | |
167 for (j = 0; flagstr[j] != NULL; j++) | |
168 if (!strncmp(sflags, flagstr[j], | |
169 strlen(flagstr[j]))) | |
170 break; | |
171 if (flagstr[j] == NULL) | |
172 goto err_out_parse_error; | |
173 flags|=(1<<j); | |
174 sflags+=strlen(flagstr[j]); | |
175 } while (*(sflags++) == ','); | |
176 | |
177 if (*(--sflags) != '\0') | |
178 goto err_out_parse_error; | |
179 } | |
297 | 180 |
181 do { | |
408 | 182 for (j = 0; fmt_table[j].name != NULL; j++) |
183 if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name))) | |
297 | 184 break; |
408 | 185 if (fmt_table[j].name == NULL) |
361 | 186 goto err_out_parse_error; |
408 | 187 outfmt[i] = fmt_table[j].num; |
297 | 188 outflags[i] = flags; |
299 | 189 ++i; |
408 | 190 sfmt+=strlen(fmt_table[j].name); |
319 | 191 } while ((*(sfmt++) == ',') && --freeslots); |
192 | |
193 if (!freeslots) | |
328 | 194 goto err_out_too_many; |
319 | 195 |
361 | 196 if (*(--sfmt) != '\0') |
197 goto err_out_parse_error; | |
299 | 198 |
297 | 199 return 1; |
328 | 200 err_out_too_many: |
361 | 201 printf("too many out..."); |
202 return 0; | |
203 err_out_parse_error: | |
204 printf("parse error"); | |
319 | 205 return 0; |
297 | 206 } |
207 | |
303 | 208 static short get_driver(char *s,int audioflag) |
297 | 209 { |
301 | 210 static char *audiodrv[] = { |
1293 | 211 "null", |
301 | 212 "mp3lib", |
213 "pcm", | |
214 "libac3", | |
215 "acm", | |
216 "alaw", | |
217 "msgsm", | |
218 "dshow", | |
401 | 219 "dvdpcm", |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1488
diff
changeset
|
220 "hwac3", |
1828 | 221 "libvorbis", |
1929 | 222 "ffmpeg", |
2415 | 223 "libmad", |
3787 | 224 "msadpcm", |
3400 | 225 "liba52", |
226 "g72x", | |
3787 | 227 "imaadpcm", |
4854
4a6dde59834c
fixed, strengthened, rewrote, and renamed a variety of the ADPCM decoders
melanson
parents:
4676
diff
changeset
|
228 "dk4adpcm", |
4a6dde59834c
fixed, strengthened, rewrote, and renamed a variety of the ADPCM decoders
melanson
parents:
4676
diff
changeset
|
229 "dk3adpcm", |
4450
3da8c5706371
added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
4301
diff
changeset
|
230 "roqaudio", |
5190
59df6b778d78
Beta AAC decoding support, seeking totally broken yet, add philipps mpeg4 video in qt to ffmpeg4 although it's still buggy in decoding
atmos4
parents:
5029
diff
changeset
|
231 "faad", |
301 | 232 NULL |
233 }; | |
234 static char *videodrv[] = { | |
1293 | 235 "null", |
301 | 236 "libmpeg2", |
237 "vfw", | |
238 "odivx", | |
239 "dshow", | |
1248 | 240 "ffmpeg", |
1297 | 241 "vfwex", |
1349 | 242 "divx4", |
1488 | 243 "raw", |
5193
abea2deab4d6
MPlayer now has a Microsoft RLE decoder to call its own...only supports
melanson
parents:
5190
diff
changeset
|
244 "msrle", |
2379 | 245 "xanim", |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
2681
diff
changeset
|
246 "msvidc", |
3172 | 247 "fli", |
3643
fb9fd7e2dd35
native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
3408
diff
changeset
|
248 "cinepak", |
3687
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
3667
diff
changeset
|
249 "qtrle", |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
3798
diff
changeset
|
250 "nuv", |
3969 | 251 "cyuv", |
4227 | 252 "qtsmc", |
4301
8f43b10f387f
added skeleton for Duck Truemotion v1 decoder (doesn't do anything yet)
melanson
parents:
4227
diff
changeset
|
253 "ducktm1", |
4450
3da8c5706371
added skeleton decoders for RoQ audio and video format decoders
melanson
parents:
4301
diff
changeset
|
254 "roqvideo", |
4615
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
4450
diff
changeset
|
255 "qtrpza", |
4656 | 256 "mpng", |
5029 | 257 "ijpg", |
5235
3e04fd1074d3
added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
5193
diff
changeset
|
258 "huffyuv", |
5263 | 259 "zlib", |
301 | 260 NULL |
261 }; | |
262 char **drv=audioflag?audiodrv:videodrv; | |
263 int i; | |
264 | |
1293 | 265 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i; |
301 | 266 |
1293 | 267 return -1; |
297 | 268 } |
269 | |
328 | 270 static int validate_codec(codecs_t *c, int type) |
319 | 271 { |
328 | 272 int i; |
3408 | 273 char *tmp_name = strdup(c->name); |
328 | 274 |
3408 | 275 for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++) |
328 | 276 /* NOTHING */; |
3408 | 277 |
278 if (i < strlen(tmp_name)) { | |
279 printf("\ncodec(%s) name is not valid!\n", c->name); | |
328 | 280 return 0; |
281 } | |
3408 | 282 |
328 | 283 if (!c->info) |
3408 | 284 c->info = strdup(c->name); |
285 | |
286 #if 0 | |
328 | 287 if (c->fourcc[0] == 0xffffffff) { |
288 printf("\ncodec(%s) does not have fourcc/format!\n", c->name); | |
289 return 0; | |
290 } | |
3408 | 291 |
292 /* XXX fix this: shitty with 'null' codec */ | |
328 | 293 if (!c->driver) { |
294 printf("\ncodec(%s) does not have a driver!\n", c->name); | |
295 return 0; | |
296 } | |
3408 | 297 #endif |
298 | |
299 #if 0 | |
328 | 300 #warning codec->driver == 4;... <- ezt nem kellene belehegeszteni... |
301 #warning HOL VANNAK DEFINIALVA???????????? | |
302 if (!c->dll && (c->driver == 4 || | |
303 (c->driver == 2 && type == TYPE_VIDEO))) { | |
304 printf("\ncodec(%s) needs a 'dll'!\n", c->name); | |
305 return 0; | |
306 } | |
307 #warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg? | |
308 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4) | |
309 | |
310 if (type == TYPE_VIDEO) | |
311 if (c->outfmt[0] == 0xffffffff) { | |
312 printf("\ncodec(%s) needs an 'outfmt'!\n", c->name); | |
313 return 0; | |
314 } | |
329 | 315 #endif |
319 | 316 return 1; |
317 } | |
318 | |
319 static int add_comment(char *s, char **d) | |
320 { | |
321 int pos; | |
322 | |
323 if (!*d) | |
324 pos = 0; | |
325 else { | |
326 pos = strlen(*d); | |
327 (*d)[pos++] = '\n'; | |
328 } | |
329 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) { | |
361 | 330 printf("can't allocate mem for comment. "); |
319 | 331 return 0; |
332 } | |
333 strcpy(*d + pos, s); | |
334 return 1; | |
335 } | |
297 | 336 |
361 | 337 static short get_cpuflags(char *s) |
338 { | |
339 static char *flagstr[] = { | |
340 "mmx", | |
341 "sse", | |
342 "3dnow", | |
343 NULL | |
344 }; | |
345 int i; | |
346 short flags = 0; | |
347 | |
348 do { | |
349 for (i = 0; flagstr[i]; i++) | |
350 if (!strncmp(s, flagstr[i], strlen(flagstr[i]))) | |
351 break; | |
352 if (!flagstr[i]) | |
353 goto err_out_parse_error; | |
354 flags |= 1<<i; | |
355 s += strlen(flagstr[i]); | |
356 } while (*(s++) == ','); | |
357 | |
358 if (*(--s) != '\0') | |
359 goto err_out_parse_error; | |
360 | |
361 return flags; | |
362 err_out_parse_error: | |
363 return 0; | |
364 } | |
365 | |
328 | 366 static FILE *fp; |
367 static int line_num = 0; | |
368 static char *line; | |
369 static char *token[MAX_NR_TOKEN]; | |
370 | |
371 static int get_token(int min, int max) | |
297 | 372 { |
328 | 373 static int read_nextline = 1; |
374 static int line_pos; | |
375 int i; | |
376 char c; | |
377 | |
378 if (max >= MAX_NR_TOKEN) { | |
361 | 379 printf("get_token(): max >= MAX_NR_TOKEN!"); |
328 | 380 goto out_eof; |
381 } | |
382 | |
383 memset(token, 0x00, sizeof(*token) * max); | |
384 | |
385 if (read_nextline) { | |
386 if (!fgets(line, MAX_LINE_LEN, fp)) | |
387 goto out_eof; | |
388 line_pos = 0; | |
389 ++line_num; | |
390 read_nextline = 0; | |
391 } | |
392 for (i = 0; i < max; i++) { | |
393 while (isspace(line[line_pos])) | |
394 ++line_pos; | |
395 if (line[line_pos] == '\0' || line[line_pos] == '#' || | |
396 line[line_pos] == ';') { | |
397 read_nextline = 1; | |
398 if (i >= min) | |
399 goto out_ok; | |
400 goto out_eol; | |
401 } | |
402 token[i] = line + line_pos; | |
403 c = line[line_pos]; | |
404 if (c == '"' || c == '\'') { | |
405 token[i]++; | |
406 while (line[++line_pos] != c && line[line_pos]) | |
407 /* NOTHING */; | |
408 } else { | |
409 for (/* NOTHING */; !isspace(line[line_pos]) && | |
410 line[line_pos]; line_pos++) | |
411 /* NOTHING */; | |
412 } | |
413 if (!line[line_pos]) { | |
414 read_nextline = 1; | |
415 if (i >= min - 1) | |
416 goto out_ok; | |
417 goto out_eol; | |
418 } | |
419 line[line_pos] = '\0'; | |
420 line_pos++; | |
421 } | |
422 out_ok: | |
423 return i; | |
424 out_eof: | |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
425 read_nextline = 1; |
328 | 426 return RET_EOF; |
427 out_eol: | |
428 return RET_EOL; | |
429 } | |
430 | |
431 static codecs_t *video_codecs=NULL; | |
432 static codecs_t *audio_codecs=NULL; | |
433 static int nr_vcodecs = 0; | |
434 static int nr_acodecs = 0; | |
435 | |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
436 int parse_codec_cfg(char *cfgfile) |
328 | 437 { |
438 codecs_t *codec = NULL; // current codec | |
439 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs | |
335 | 440 char *endptr; // strtoul()... |
328 | 441 int *nr_codecsp; |
442 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ | |
297 | 443 int tmp, i; |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
444 |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
445 // in case we call it secont time |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
446 if(video_codecs!=NULL)free(video_codecs); |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
447 else video_codecs=NULL; |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
448 |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
449 if(audio_codecs!=NULL)free(audio_codecs); |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
450 else audio_codecs=NULL; |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
451 |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
452 nr_vcodecs = 0; |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
453 nr_acodecs = 0; |
297 | 454 |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
455 if(cfgfile==NULL)return 0; |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
456 |
361 | 457 printf("Reading %s: ", cfgfile); |
297 | 458 |
301 | 459 if ((fp = fopen(cfgfile, "r")) == NULL) { |
328 | 460 printf("can't open '%s': %s\n", cfgfile, strerror(errno)); |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
461 return 0; |
297 | 462 } |
463 | |
301 | 464 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { |
361 | 465 printf("can't get memory for 'line': %s\n", strerror(errno)); |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
466 return 0; |
297 | 467 } |
468 | |
328 | 469 /* |
470 * check if the cfgfile starts with 'audiocodec' or | |
471 * with 'videocodec' | |
472 */ | |
473 while ((tmp = get_token(1, 1)) == RET_EOL) | |
474 /* NOTHING */; | |
361 | 475 if (tmp == RET_EOF) |
476 goto out; | |
477 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) | |
328 | 478 goto loop_enter; |
361 | 479 goto err_out_parse_error; |
328 | 480 |
319 | 481 while ((tmp = get_token(1, 1)) != RET_EOF) { |
297 | 482 if (tmp == RET_EOL) |
483 continue; | |
328 | 484 if (!strcmp(token[0], "audiocodec") || |
485 !strcmp(token[0], "videocodec")) { | |
486 if (!validate_codec(codec, codec_type)) | |
487 goto err_out_not_valid; | |
488 loop_enter: | |
489 if (*token[0] == 'v') { | |
490 codec_type = TYPE_VIDEO; | |
491 nr_codecsp = &nr_vcodecs; | |
492 codecsp = &video_codecs; | |
493 } else if (*token[0] == 'a') { | |
494 codec_type = TYPE_AUDIO; | |
495 nr_codecsp = &nr_acodecs; | |
496 codecsp = &audio_codecs; | |
361 | 497 #ifdef DEBUG |
328 | 498 } else { |
361 | 499 printf("picsba\n"); |
328 | 500 goto err_out; |
361 | 501 #endif |
328 | 502 } |
503 if (!(*codecsp = (codecs_t *) realloc(*codecsp, | |
332 | 504 sizeof(codecs_t) * (*nr_codecsp + 2)))) { |
361 | 505 printf("can't realloc '*codecsp': %s\n", strerror(errno)); |
300 | 506 goto err_out; |
507 } | |
328 | 508 codec=*codecsp + *nr_codecsp; |
509 ++*nr_codecsp; | |
300 | 510 memset(codec,0,sizeof(codecs_t)); |
511 memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); | |
512 memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); | |
4675 | 513 memset(codec->infmt, 0xff, sizeof(codec->infmt)); |
300 | 514 |
319 | 515 if (get_token(1, 1) < 0) |
328 | 516 goto err_out_parse_error; |
517 for (i = 0; i < *nr_codecsp - 1; i++) { | |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
518 if(( (*codecsp)[i].name!=NULL) && |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
519 (!strcmp(token[0], (*codecsp)[i].name)) ) { |
361 | 520 printf("codec name '%s' isn't unique", token[0]); |
521 goto err_out_print_linenum; | |
319 | 522 } |
523 } | |
328 | 524 if (!(codec->name = strdup(token[0]))) { |
361 | 525 printf("can't strdup -> 'name': %s\n", strerror(errno)); |
328 | 526 goto err_out; |
527 } | |
319 | 528 } else if (!strcmp(token[0], "info")) { |
328 | 529 if (codec->info || get_token(1, 1) < 0) |
530 goto err_out_parse_error; | |
531 if (!(codec->info = strdup(token[0]))) { | |
361 | 532 printf("can't strdup -> 'info': %s\n", strerror(errno)); |
328 | 533 goto err_out; |
534 } | |
319 | 535 } else if (!strcmp(token[0], "comment")) { |
536 if (get_token(1, 1) < 0) | |
328 | 537 goto err_out_parse_error; |
361 | 538 add_comment(token[0], &codec->comment); |
319 | 539 } else if (!strcmp(token[0], "fourcc")) { |
540 if (get_token(1, 2) < 0) | |
328 | 541 goto err_out_parse_error; |
319 | 542 if (!add_to_fourcc(token[0], token[1], |
300 | 543 codec->fourcc, |
544 codec->fourccmap)) | |
361 | 545 goto err_out_print_linenum; |
319 | 546 } else if (!strcmp(token[0], "format")) { |
547 if (get_token(1, 1) < 0) | |
328 | 548 goto err_out_parse_error; |
319 | 549 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap)) |
361 | 550 goto err_out_print_linenum; |
319 | 551 } else if (!strcmp(token[0], "driver")) { |
552 if (get_token(1, 1) < 0) | |
328 | 553 goto err_out_parse_error; |
1293 | 554 if ((codec->driver = get_driver(token[0],codec_type))<0) |
361 | 555 goto err_out_parse_error; |
319 | 556 } else if (!strcmp(token[0], "dll")) { |
557 if (get_token(1, 1) < 0) | |
328 | 558 goto err_out_parse_error; |
559 if (!(codec->dll = strdup(token[0]))) { | |
361 | 560 printf("can't strdup -> 'dll': %s\n", strerror(errno)); |
328 | 561 goto err_out; |
562 } | |
319 | 563 } else if (!strcmp(token[0], "guid")) { |
328 | 564 if (get_token(11, 11) < 0) |
565 goto err_out_parse_error; | |
335 | 566 codec->guid.f1=strtoul(token[0],&endptr,0); |
361 | 567 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
568 *endptr != '\0') | |
335 | 569 goto err_out_parse_error; |
570 codec->guid.f2=strtoul(token[1],&endptr,0); | |
361 | 571 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
572 *endptr != '\0') | |
335 | 573 goto err_out_parse_error; |
574 codec->guid.f3=strtoul(token[2],&endptr,0); | |
361 | 575 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
576 *endptr != '\0') | |
335 | 577 goto err_out_parse_error; |
578 for (i = 0; i < 8; i++) { | |
579 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); | |
361 | 580 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
581 *endptr != '\0') | |
328 | 582 goto err_out_parse_error; |
297 | 583 } |
319 | 584 } else if (!strcmp(token[0], "out")) { |
585 if (get_token(1, 2) < 0) | |
328 | 586 goto err_out_parse_error; |
4675 | 587 if (!add_to_inout(token[0], token[1], codec->outfmt, |
300 | 588 codec->outflags)) |
361 | 589 goto err_out_print_linenum; |
4675 | 590 } else if (!strcmp(token[0], "in")) { |
591 if (get_token(1, 2) < 0) | |
592 goto err_out_parse_error; | |
593 if (!add_to_inout(token[0], token[1], codec->infmt, | |
594 codec->inflags)) | |
595 goto err_out_print_linenum; | |
319 | 596 } else if (!strcmp(token[0], "flags")) { |
597 if (get_token(1, 1) < 0) | |
328 | 598 goto err_out_parse_error; |
321 | 599 if (!strcmp(token[0], "seekable")) |
600 codec->flags |= CODECS_FLAG_SEEKABLE; | |
601 else | |
328 | 602 goto err_out_parse_error; |
319 | 603 } else if (!strcmp(token[0], "status")) { |
604 if (get_token(1, 1) < 0) | |
328 | 605 goto err_out_parse_error; |
332 | 606 if (!strcasecmp(token[0], "working")) |
316 | 607 codec->status = CODECS_STATUS_WORKING; |
332 | 608 else if (!strcasecmp(token[0], "crashing")) |
316 | 609 codec->status = CODECS_STATUS_NOT_WORKING; |
332 | 610 else if (!strcasecmp(token[0], "untested")) |
316 | 611 codec->status = CODECS_STATUS_UNTESTED; |
332 | 612 else if (!strcasecmp(token[0], "buggy")) |
316 | 613 codec->status = CODECS_STATUS_PROBLEMS; |
614 else | |
328 | 615 goto err_out_parse_error; |
361 | 616 } else if (!strcmp(token[0], "cpuflags")) { |
617 if (get_token(1, 1) < 0) | |
618 goto err_out_parse_error; | |
619 if (!(codec->cpuflags = get_cpuflags(token[0]))) | |
620 goto err_out_parse_error; | |
3667
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
621 } else if (!strcasecmp(token[0], "priority")) { |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
622 if (get_token(1, 1) < 0) |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
623 goto err_out_parse_error; |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
624 //printf("\n\n!!!cfg-parse: priority %s (%d) found!!!\n\n", token[0], atoi(token[0])); // ::atmos |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
625 codec->priority = atoi(token[0]); |
297 | 626 } else |
328 | 627 goto err_out_parse_error; |
297 | 628 } |
328 | 629 if (!validate_codec(codec, codec_type)) |
630 goto err_out_not_valid; | |
361 | 631 printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs); |
895 | 632 if(video_codecs) video_codecs[nr_vcodecs].name = NULL; |
633 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL; | |
297 | 634 out: |
635 free(line); | |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
636 line=NULL; |
297 | 637 fclose(fp); |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
638 return 1; |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
639 |
328 | 640 err_out_parse_error: |
361 | 641 printf("parse error"); |
642 err_out_print_linenum: | |
297 | 643 PRINT_LINENUM; |
644 err_out: | |
328 | 645 if (audio_codecs) |
646 free(audio_codecs); | |
647 if (video_codecs) | |
648 free(video_codecs); | |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
649 video_codecs=NULL; |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
650 audio_codecs=NULL; |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
651 |
328 | 652 free(line); |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
653 line=NULL; |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
654 fclose(fp); |
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
655 return 0; |
328 | 656 err_out_not_valid: |
3408 | 657 printf("codec is not defined correctly"); |
361 | 658 goto err_out_print_linenum; |
297 | 659 } |
660 | |
332 | 661 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, |
662 codecs_t *start) | |
328 | 663 { |
332 | 664 return find_codec(fourcc, fourccmap, start, 1); |
328 | 665 } |
666 | |
332 | 667 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, |
668 codecs_t *start) | |
328 | 669 { |
332 | 670 return find_codec(fourcc, fourccmap, start, 0); |
328 | 671 } |
672 | |
332 | 673 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, |
674 codecs_t *start, int audioflag) | |
328 | 675 { |
676 int i, j; | |
677 codecs_t *c; | |
678 | |
628 | 679 #if 0 |
332 | 680 if (start) { |
681 for (/* NOTHING */; start->name; start++) { | |
682 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
683 if (start->fourcc[j] == fourcc) { | |
684 if (fourccmap) | |
685 *fourccmap = start->fourccmap[j]; | |
686 return start; | |
687 } | |
688 } | |
689 } | |
628 | 690 } else |
691 #endif | |
692 { | |
332 | 693 if (audioflag) { |
694 i = nr_acodecs; | |
695 c = audio_codecs; | |
696 } else { | |
697 i = nr_vcodecs; | |
698 c = video_codecs; | |
699 } | |
895 | 700 if(!i) return NULL; |
332 | 701 for (/* NOTHING */; i--; c++) { |
628 | 702 if(start && c<=start) continue; |
332 | 703 for (j = 0; j < CODECS_MAX_FOURCC; j++) { |
1391 | 704 if (c->fourcc[j]==fourcc || c->driver==0) { |
332 | 705 if (fourccmap) |
706 *fourccmap = c->fourccmap[j]; | |
707 return c; | |
708 } | |
328 | 709 } |
710 } | |
711 } | |
712 return NULL; | |
303 | 713 } |
714 | |
1983 | 715 void list_codecs(int audioflag){ |
2050 | 716 int i; |
1983 | 717 codecs_t *c; |
718 | |
719 if (audioflag) { | |
720 i = nr_acodecs; | |
721 c = audio_codecs; | |
1984 | 722 printf("ac: afm: status: info: [lib/dll]\n"); |
1983 | 723 } else { |
724 i = nr_vcodecs; | |
725 c = video_codecs; | |
1984 | 726 printf("vc: vfm: status: info: [lib/dll]\n"); |
1983 | 727 } |
2050 | 728 if(!i) return; |
1983 | 729 for (/* NOTHING */; i--; c++) { |
1984 | 730 char* s="unknown "; |
731 switch(c->status){ | |
732 case CODECS_STATUS_WORKING: s="working ";break; | |
733 case CODECS_STATUS_PROBLEMS: s="problems";break; | |
734 case CODECS_STATUS_NOT_WORKING: s="crashing";break; | |
735 case CODECS_STATUS_UNTESTED: s="untested";break; | |
736 } | |
1983 | 737 if(c->dll) |
3918 | 738 printf("%-11s%2d %s %s [%s]\n",c->name,c->driver,s,c->info,c->dll); |
1983 | 739 else |
3918 | 740 printf("%-11s%2d %s %s\n",c->name,c->driver,s,c->info); |
1983 | 741 |
742 } | |
743 | |
744 } | |
745 | |
746 | |
747 | |
607 | 748 #ifdef CODECS2HTML |
749 | |
750 void wrapline(FILE *f2,char *s){ | |
751 int c; | |
752 if(!s){ | |
753 fprintf(f2,"-"); | |
754 return; | |
755 } | |
756 while((c=*s++)){ | |
757 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); | |
758 } | |
759 } | |
760 | |
761 void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ | |
762 int c,d; | |
763 while((c=fgetc(f1))>=0){ | |
764 if(c!='%'){ | |
765 fputc(c,f2); | |
766 continue; | |
767 } | |
768 d=fgetc(f1); | |
769 | |
770 switch(d){ | |
771 case '.': | |
613 | 772 return; // end of section |
607 | 773 case 'n': |
774 wrapline(f2,codec->name); break; | |
775 case 'i': | |
776 wrapline(f2,codec->info); break; | |
777 case 'c': | |
778 wrapline(f2,codec->comment); break; | |
779 case 'd': | |
780 wrapline(f2,codec->dll); break; | |
781 case 'D': | |
782 fprintf(f2,"%c",codec->driver==dshow?'+':'-'); break; | |
783 case 'F': | |
784 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
1944
4d8123ae7b4b
Fixed vfwex section, null codec and other fourcc issues and improved codecs-in.html usability.
atmos4
parents:
1929
diff
changeset
|
785 if(!d || codec->fourcc[d]!=0xFFFFFFFF) |
4d8123ae7b4b
Fixed vfwex section, null codec and other fourcc issues and improved codecs-in.html usability.
atmos4
parents:
1929
diff
changeset
|
786 fprintf(f2,"%s%.4s",d?"<br>":"",(codec->fourcc[d]==0xFFFFFFFF || codec->fourcc[d]<0x20202020)?!d?"-":"":(char*) &codec->fourcc[d]); |
607 | 787 break; |
788 case 'f': | |
789 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
790 if(codec->fourcc[d]!=0xFFFFFFFF) | |
791 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]); | |
792 break; | |
793 case 'Y': | |
794 for(d=0;d<CODECS_MAX_OUTFMT;d++) | |
795 if(codec->outfmt[d]!=0xFFFFFFFF){ | |
796 for (c=0; fmt_table[c].name; c++) | |
797 if(fmt_table[c].num==codec->outfmt[d]) break; | |
798 if(fmt_table[c].name) | |
799 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name); | |
800 } | |
801 break; | |
802 default: | |
803 fputc(c,f2); | |
804 fputc(d,f2); | |
805 } | |
806 } | |
807 | |
808 } | |
809 | |
810 void skiphtml(FILE *f1){ | |
811 int c,d; | |
812 while((c=fgetc(f1))>=0){ | |
813 if(c!='%'){ | |
814 continue; | |
815 } | |
816 d=fgetc(f1); | |
817 if(d=='.') return; // end of section | |
818 } | |
819 } | |
820 | |
821 int main(void) | |
822 { | |
4027 | 823 codecs_t *cl; |
607 | 824 FILE *f1; |
825 FILE *f2; | |
826 int c,d,i; | |
827 int pos; | |
828 int section=-1; | |
829 int nr_codecs; | |
830 int win32=-1; | |
831 int dshow=-1; | |
1944
4d8123ae7b4b
Fixed vfwex section, null codec and other fourcc issues and improved codecs-in.html usability.
atmos4
parents:
1929
diff
changeset
|
832 int win32ex=-1; |
607 | 833 |
4027 | 834 if (!(nr_codecs = parse_codec_cfg("etc/codecs.conf"))) |
607 | 835 return 0; |
836 | |
837 f1=fopen("DOCS/codecs-in.html","rb"); if(!f1) exit(1); | |
1689 | 838 f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); |
607 | 839 |
840 while((c=fgetc(f1))>=0){ | |
841 if(c!='%'){ | |
842 fputc(c,f2); | |
843 continue; | |
844 } | |
845 d=fgetc(f1); | |
846 if(d>='0' && d<='9'){ | |
847 // begin section | |
848 section=d-'0'; | |
849 printf("BEGIN %d\n",section); | |
850 if(section>=5){ | |
851 // audio | |
4027 | 852 cl = audio_codecs; |
607 | 853 nr_codecs = nr_acodecs; |
854 dshow=7;win32=4; | |
855 } else { | |
856 // video | |
4027 | 857 cl = video_codecs; |
607 | 858 nr_codecs = nr_vcodecs; |
1944
4d8123ae7b4b
Fixed vfwex section, null codec and other fourcc issues and improved codecs-in.html usability.
atmos4
parents:
1929
diff
changeset
|
859 dshow=4;win32=2;win32ex=6; |
607 | 860 } |
861 pos=ftell(f1); | |
862 for(i=0;i<nr_codecs;i++){ | |
863 fseek(f1,pos,SEEK_SET); | |
864 switch(section){ | |
865 case 0: | |
866 case 5: | |
867 if(cl[i].status==CODECS_STATUS_WORKING) | |
1944
4d8123ae7b4b
Fixed vfwex section, null codec and other fourcc issues and improved codecs-in.html usability.
atmos4
parents:
1929
diff
changeset
|
868 if(!(cl[i].driver==win32 || cl[i].driver==dshow || cl[i].driver==win32ex)) |
607 | 869 parsehtml(f1,f2,&cl[i],section,dshow); |
870 break; | |
871 case 1: | |
872 case 6: | |
873 if(cl[i].status==CODECS_STATUS_WORKING) | |
1944
4d8123ae7b4b
Fixed vfwex section, null codec and other fourcc issues and improved codecs-in.html usability.
atmos4
parents:
1929
diff
changeset
|
874 if(cl[i].driver==win32 || cl[i].driver==dshow || cl[i].driver==win32ex) |
607 | 875 parsehtml(f1,f2,&cl[i],section,dshow); |
876 break; | |
877 case 2: | |
878 case 7: | |
879 if(cl[i].status==CODECS_STATUS_PROBLEMS) | |
880 parsehtml(f1,f2,&cl[i],section,dshow); | |
881 break; | |
882 case 3: | |
883 case 8: | |
884 if(cl[i].status==CODECS_STATUS_NOT_WORKING) | |
885 parsehtml(f1,f2,&cl[i],section,dshow); | |
886 break; | |
887 case 4: | |
888 case 9: | |
889 if(cl[i].status==CODECS_STATUS_UNTESTED) | |
890 parsehtml(f1,f2,&cl[i],section,dshow); | |
891 break; | |
892 default: | |
893 printf("Warning! unimplemented section: %d\n",section); | |
894 } | |
895 } | |
896 fseek(f1,pos,SEEK_SET); | |
897 skiphtml(f1); | |
898 //void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ | |
899 | |
900 continue; | |
901 } | |
902 fputc(c,f2); | |
903 fputc(d,f2); | |
904 } | |
905 | |
906 fclose(f2); | |
907 fclose(f1); | |
908 return 0; | |
909 } | |
910 | |
911 #endif | |
912 | |
297 | 913 #ifdef TESTING |
914 int main(void) | |
915 { | |
4676 | 916 codecs_t *c; |
328 | 917 int i,j, nr_codecs, state; |
297 | 918 |
4676 | 919 if (!(parse_codec_cfg("etc/codecs.conf"))) |
319 | 920 return 0; |
4676 | 921 if (!video_codecs) |
328 | 922 printf("no videoconfig.\n"); |
4676 | 923 if (!audio_codecs) |
328 | 924 printf("no audioconfig.\n"); |
925 | |
926 printf("videocodecs:\n"); | |
4676 | 927 c = video_codecs; |
328 | 928 nr_codecs = nr_vcodecs; |
929 state = 0; | |
930 next: | |
931 if (c) { | |
4676 | 932 printf("number of %scodecs: %d\n", state==0?"video":"audio", |
933 nr_codecs); | |
328 | 934 for(i=0;i<nr_codecs;i++, c++){ |
4676 | 935 printf("\n============== %scodec %02d ===============\n", |
936 state==0?"video":"audio",i); | |
328 | 937 printf("name='%s'\n",c->name); |
938 printf("info='%s'\n",c->info); | |
939 printf("comment='%s'\n",c->comment); | |
940 printf("dll='%s'\n",c->dll); | |
361 | 941 printf("flags=%X driver=%d status=%d cpuflags=%d\n", |
942 c->flags, c->driver, c->status, c->cpuflags); | |
300 | 943 |
328 | 944 for(j=0;j<CODECS_MAX_FOURCC;j++){ |
945 if(c->fourcc[j]!=0xFFFFFFFF){ | |
361 | 946 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]); |
328 | 947 } |
948 } | |
949 | |
950 for(j=0;j<CODECS_MAX_OUTFMT;j++){ | |
951 if(c->outfmt[j]!=0xFFFFFFFF){ | |
361 | 952 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]); |
328 | 953 } |
954 } | |
300 | 955 |
4676 | 956 for(j=0;j<CODECS_MAX_INFMT;j++){ |
957 if(c->infmt[j]!=0xFFFFFFFF){ | |
958 printf("infmt %02d: %08X (%.4s) flags: %d\n",j,c->infmt[j],(char *) &c->infmt[j],c->inflags[j]); | |
959 } | |
960 } | |
961 | |
328 | 962 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); |
963 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); | |
964 printf("\n"); | |
300 | 965 |
328 | 966 |
967 } | |
968 } | |
969 if (!state) { | |
970 printf("audiocodecs:\n"); | |
4676 | 971 c = audio_codecs; |
328 | 972 nr_codecs = nr_acodecs; |
973 state = 1; | |
974 goto next; | |
975 } | |
297 | 976 return 0; |
977 } | |
978 | |
979 #endif |