Mercurial > mplayer.hg
annotate codec-cfg.c @ 1930:87319ece31f9
range increased to 11 (ffmp3)
author | gabucino |
---|---|
date | Fri, 21 Sep 2001 22:32:58 +0000 |
parents | af7b3e83d47b |
children | 4d8123ae7b4b |
rev | line source |
---|---|
319 | 1 /* |
2 * codec.conf parser | |
3 * by Szabolcs Berecz <szabi@inf.elte.hu> | |
4 * (C) 2001 | |
5 */ | |
303 | 6 |
319 | 7 #define DEBUG |
303 | 8 |
297 | 9 #include <stdio.h> |
10 #include <stdlib.h> | |
11 #include <fcntl.h> | |
12 #include <unistd.h> | |
13 #include <errno.h> | |
14 #include <ctype.h> | |
15 #include <assert.h> | |
16 #include <string.h> | |
17 | |
1305
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
18 #include "loader.h" // loader+avifmt for mmioFOURCC |
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
19 #include "wine/avifmt.h" |
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
20 |
408 | 21 #include "libvo/img_format.h" |
297 | 22 #include "codec-cfg.h" |
23 | |
361 | 24 #define PRINT_LINENUM printf(" at line %d\n", line_num) |
328 | 25 |
319 | 26 #define MAX_NR_TOKEN 16 |
297 | 27 |
28 #define MAX_LINE_LEN 1000 | |
29 | |
30 #define RET_EOF -1 | |
31 #define RET_EOL -2 | |
32 | |
328 | 33 #define TYPE_VIDEO 0 |
34 #define TYPE_AUDIO 1 | |
297 | 35 |
303 | 36 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc, |
297 | 37 unsigned int *map) |
38 { | |
319 | 39 int i, j, freeslots; |
1305
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
40 char *aliasp; |
319 | 41 unsigned int tmp; |
42 | |
43 /* find first unused slot */ | |
44 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
45 /* NOTHING */; | |
46 freeslots = CODECS_MAX_FOURCC - i; | |
47 if (!freeslots) | |
328 | 48 goto err_out_too_many; |
319 | 49 |
1305
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
50 aliasp = (alias) ? alias : s; |
319 | 51 do { |
1305
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
52 tmp = mmioFOURCC(s[0], s[1], s[2], s[3]); |
319 | 53 for (j = 0; j < i; j++) |
54 if (tmp == fourcc[j]) | |
328 | 55 goto err_out_duplicated; |
319 | 56 fourcc[i] = tmp; |
1305
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
57 map[i] = mmioFOURCC(aliasp[0], aliasp[1], aliasp[2], aliasp[3]); |
319 | 58 s += 4; |
59 i++; | |
60 } while ((*(s++) == ',') && --freeslots); | |
61 | |
62 if (!freeslots) | |
328 | 63 goto err_out_too_many; |
319 | 64 if (*(--s) != '\0') |
361 | 65 goto err_out_parse_error; |
319 | 66 return 1; |
328 | 67 err_out_duplicated: |
361 | 68 printf("duplicated fourcc/format"); |
319 | 69 return 0; |
328 | 70 err_out_too_many: |
361 | 71 printf("too many fourcc/format..."); |
72 return 0; | |
73 err_out_parse_error: | |
74 printf("parse error"); | |
319 | 75 return 0; |
76 } | |
77 | |
78 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap) | |
79 { | |
80 int i, j; | |
361 | 81 char *endptr; |
297 | 82 |
83 /* find first unused slot */ | |
84 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
85 /* NOTHING */; | |
86 if (i == CODECS_MAX_FOURCC) { | |
361 | 87 printf("too many fourcc/format..."); |
297 | 88 return 0; |
89 } | |
90 | |
361 | 91 fourcc[i]=fourccmap[i]=strtoul(s,&endptr,0); |
92 if (*endptr != '\0') { | |
93 printf("parse error"); | |
94 return 0; | |
95 } | |
319 | 96 for (j = 0; j < i; j++) |
97 if (fourcc[j] == fourcc[i]) { | |
361 | 98 printf("duplicated fourcc/format"); |
319 | 99 return 0; |
100 } | |
300 | 101 |
297 | 102 return 1; |
103 } | |
104 | |
408 | 105 static struct { |
106 const char *name; | |
107 const unsigned int num; | |
108 } fmt_table[] = { | |
415 | 109 {"YV12", IMGFMT_YV12}, |
110 {"I420", IMGFMT_I420}, | |
111 {"IYUV", IMGFMT_IYUV}, | |
408 | 112 |
415 | 113 {"YUY2", IMGFMT_YUY2}, |
114 {"UYVY", IMGFMT_UYVY}, | |
115 {"YVYU", IMGFMT_YVYU}, | |
408 | 116 |
415 | 117 {"RGB8", IMGFMT_RGB|8}, |
118 {"RGB15", IMGFMT_RGB|15}, | |
119 {"RGB16", IMGFMT_RGB|16}, | |
120 {"RGB24", IMGFMT_RGB|24}, | |
121 {"RGB32", IMGFMT_RGB|32}, | |
122 {"BGR8", IMGFMT_BGR|8}, | |
123 {"BGR15", IMGFMT_BGR|15}, | |
124 {"BGR16", IMGFMT_BGR|16}, | |
125 {"BGR24", IMGFMT_BGR|24}, | |
126 {"BGR32", IMGFMT_BGR|32}, | |
1871 | 127 |
128 {"MPES", IMGFMT_MPEGPES}, | |
415 | 129 {NULL, 0} |
297 | 130 }; |
408 | 131 |
607 | 132 |
133 static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt, | |
134 unsigned char *outflags) | |
135 { | |
136 | |
299 | 137 static char *flagstr[] = { |
138 "flip", | |
139 "noflip", | |
140 "yuvhack", | |
141 NULL | |
142 }; | |
143 | |
319 | 144 int i, j, freeslots; |
297 | 145 unsigned char flags; |
146 | |
147 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) | |
148 /* NOTHING */; | |
319 | 149 freeslots = CODECS_MAX_OUTFMT - i; |
150 if (!freeslots) | |
328 | 151 goto err_out_too_many; |
297 | 152 |
319 | 153 flags = 0; |
361 | 154 if(sflags) { |
155 do { | |
156 for (j = 0; flagstr[j] != NULL; j++) | |
157 if (!strncmp(sflags, flagstr[j], | |
158 strlen(flagstr[j]))) | |
159 break; | |
160 if (flagstr[j] == NULL) | |
161 goto err_out_parse_error; | |
162 flags|=(1<<j); | |
163 sflags+=strlen(flagstr[j]); | |
164 } while (*(sflags++) == ','); | |
165 | |
166 if (*(--sflags) != '\0') | |
167 goto err_out_parse_error; | |
168 } | |
297 | 169 |
170 do { | |
408 | 171 for (j = 0; fmt_table[j].name != NULL; j++) |
172 if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name))) | |
297 | 173 break; |
408 | 174 if (fmt_table[j].name == NULL) |
361 | 175 goto err_out_parse_error; |
408 | 176 outfmt[i] = fmt_table[j].num; |
297 | 177 outflags[i] = flags; |
299 | 178 ++i; |
408 | 179 sfmt+=strlen(fmt_table[j].name); |
319 | 180 } while ((*(sfmt++) == ',') && --freeslots); |
181 | |
182 if (!freeslots) | |
328 | 183 goto err_out_too_many; |
319 | 184 |
361 | 185 if (*(--sfmt) != '\0') |
186 goto err_out_parse_error; | |
299 | 187 |
297 | 188 return 1; |
328 | 189 err_out_too_many: |
361 | 190 printf("too many out..."); |
191 return 0; | |
192 err_out_parse_error: | |
193 printf("parse error"); | |
319 | 194 return 0; |
297 | 195 } |
196 | |
303 | 197 static short get_driver(char *s,int audioflag) |
297 | 198 { |
301 | 199 static char *audiodrv[] = { |
1293 | 200 "null", |
301 | 201 "mp3lib", |
202 "pcm", | |
203 "libac3", | |
204 "acm", | |
205 "alaw", | |
206 "msgsm", | |
207 "dshow", | |
401 | 208 "dvdpcm", |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1488
diff
changeset
|
209 "hwac3", |
1828 | 210 "libvorbis", |
1929 | 211 "ffmpeg", |
301 | 212 NULL |
213 }; | |
214 static char *videodrv[] = { | |
1293 | 215 "null", |
301 | 216 "libmpeg2", |
217 "vfw", | |
218 "odivx", | |
219 "dshow", | |
1248 | 220 "ffmpeg", |
1297 | 221 "vfwex", |
1349 | 222 "divx4", |
1488 | 223 "raw", |
301 | 224 NULL |
225 }; | |
226 char **drv=audioflag?audiodrv:videodrv; | |
227 int i; | |
228 | |
1293 | 229 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i; |
301 | 230 |
1293 | 231 return -1; |
297 | 232 } |
233 | |
328 | 234 static int validate_codec(codecs_t *c, int type) |
319 | 235 { |
329 | 236 #if 0 |
328 | 237 int i; |
238 | |
239 for (i = 0; i < strlen(c->name) && isalnum(c->name[i]); i++) | |
240 /* NOTHING */; | |
241 if (i < strlen(c->name)) { | |
242 printf("\ncodec(%s)->name is not valid!\n", c->name); | |
243 return 0; | |
244 } | |
245 #warning codec->info = codec->name; ez ok, vagy strdup()? | |
246 if (!c->info) | |
247 c->info = c->name; | |
248 if (c->fourcc[0] == 0xffffffff) { | |
249 printf("\ncodec(%s) does not have fourcc/format!\n", c->name); | |
250 return 0; | |
251 } | |
252 if (!c->driver) { | |
253 printf("\ncodec(%s) does not have a driver!\n", c->name); | |
254 return 0; | |
255 } | |
256 #warning codec->driver == 4;... <- ezt nem kellene belehegeszteni... | |
257 #warning HOL VANNAK DEFINIALVA???????????? | |
258 if (!c->dll && (c->driver == 4 || | |
259 (c->driver == 2 && type == TYPE_VIDEO))) { | |
260 printf("\ncodec(%s) needs a 'dll'!\n", c->name); | |
261 return 0; | |
262 } | |
263 #warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg? | |
264 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4) | |
265 | |
266 if (type == TYPE_VIDEO) | |
267 if (c->outfmt[0] == 0xffffffff) { | |
268 printf("\ncodec(%s) needs an 'outfmt'!\n", c->name); | |
269 return 0; | |
270 } | |
329 | 271 #endif |
319 | 272 return 1; |
273 } | |
274 | |
275 static int add_comment(char *s, char **d) | |
276 { | |
277 int pos; | |
278 | |
279 if (!*d) | |
280 pos = 0; | |
281 else { | |
282 pos = strlen(*d); | |
283 (*d)[pos++] = '\n'; | |
284 } | |
285 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) { | |
361 | 286 printf("can't allocate mem for comment. "); |
319 | 287 return 0; |
288 } | |
289 strcpy(*d + pos, s); | |
290 return 1; | |
291 } | |
297 | 292 |
361 | 293 static short get_cpuflags(char *s) |
294 { | |
295 static char *flagstr[] = { | |
296 "mmx", | |
297 "sse", | |
298 "3dnow", | |
299 NULL | |
300 }; | |
301 int i; | |
302 short flags = 0; | |
303 | |
304 do { | |
305 for (i = 0; flagstr[i]; i++) | |
306 if (!strncmp(s, flagstr[i], strlen(flagstr[i]))) | |
307 break; | |
308 if (!flagstr[i]) | |
309 goto err_out_parse_error; | |
310 flags |= 1<<i; | |
311 s += strlen(flagstr[i]); | |
312 } while (*(s++) == ','); | |
313 | |
314 if (*(--s) != '\0') | |
315 goto err_out_parse_error; | |
316 | |
317 return flags; | |
318 err_out_parse_error: | |
319 return 0; | |
320 } | |
321 | |
328 | 322 static FILE *fp; |
323 static int line_num = 0; | |
324 static char *line; | |
325 static char *token[MAX_NR_TOKEN]; | |
326 | |
327 static int get_token(int min, int max) | |
297 | 328 { |
328 | 329 static int read_nextline = 1; |
330 static int line_pos; | |
331 int i; | |
332 char c; | |
333 | |
334 if (max >= MAX_NR_TOKEN) { | |
361 | 335 printf("get_token(): max >= MAX_NR_TOKEN!"); |
328 | 336 goto out_eof; |
337 } | |
338 | |
339 memset(token, 0x00, sizeof(*token) * max); | |
340 | |
341 if (read_nextline) { | |
342 if (!fgets(line, MAX_LINE_LEN, fp)) | |
343 goto out_eof; | |
344 line_pos = 0; | |
345 ++line_num; | |
346 read_nextline = 0; | |
347 } | |
348 for (i = 0; i < max; i++) { | |
349 while (isspace(line[line_pos])) | |
350 ++line_pos; | |
351 if (line[line_pos] == '\0' || line[line_pos] == '#' || | |
352 line[line_pos] == ';') { | |
353 read_nextline = 1; | |
354 if (i >= min) | |
355 goto out_ok; | |
356 goto out_eol; | |
357 } | |
358 token[i] = line + line_pos; | |
359 c = line[line_pos]; | |
360 if (c == '"' || c == '\'') { | |
361 token[i]++; | |
362 while (line[++line_pos] != c && line[line_pos]) | |
363 /* NOTHING */; | |
364 } else { | |
365 for (/* NOTHING */; !isspace(line[line_pos]) && | |
366 line[line_pos]; line_pos++) | |
367 /* NOTHING */; | |
368 } | |
369 if (!line[line_pos]) { | |
370 read_nextline = 1; | |
371 if (i >= min - 1) | |
372 goto out_ok; | |
373 goto out_eol; | |
374 } | |
375 line[line_pos] = '\0'; | |
376 line_pos++; | |
377 } | |
378 out_ok: | |
379 return i; | |
380 out_eof: | |
381 return RET_EOF; | |
382 out_eol: | |
383 return RET_EOL; | |
384 } | |
385 | |
386 static codecs_t *video_codecs=NULL; | |
387 static codecs_t *audio_codecs=NULL; | |
388 static int nr_vcodecs = 0; | |
389 static int nr_acodecs = 0; | |
390 | |
391 codecs_t **parse_codec_cfg(char *cfgfile) | |
392 { | |
393 codecs_t *codec = NULL; // current codec | |
394 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs | |
395 static codecs_t *ret_codecs[2] = {NULL,NULL}; | |
335 | 396 char *endptr; // strtoul()... |
328 | 397 int *nr_codecsp; |
398 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ | |
297 | 399 int tmp, i; |
400 | |
401 #ifdef DEBUG | |
402 assert(cfgfile != NULL); | |
403 #endif | |
404 | |
361 | 405 printf("Reading %s: ", cfgfile); |
297 | 406 |
301 | 407 if ((fp = fopen(cfgfile, "r")) == NULL) { |
328 | 408 printf("can't open '%s': %s\n", cfgfile, strerror(errno)); |
297 | 409 return NULL; |
410 } | |
411 | |
301 | 412 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { |
361 | 413 printf("can't get memory for 'line': %s\n", strerror(errno)); |
297 | 414 return NULL; |
415 } | |
416 | |
328 | 417 /* |
418 * check if the cfgfile starts with 'audiocodec' or | |
419 * with 'videocodec' | |
420 */ | |
421 while ((tmp = get_token(1, 1)) == RET_EOL) | |
422 /* NOTHING */; | |
361 | 423 if (tmp == RET_EOF) |
424 goto out; | |
425 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) | |
328 | 426 goto loop_enter; |
361 | 427 goto err_out_parse_error; |
328 | 428 |
319 | 429 while ((tmp = get_token(1, 1)) != RET_EOF) { |
297 | 430 if (tmp == RET_EOL) |
431 continue; | |
328 | 432 if (!strcmp(token[0], "audiocodec") || |
433 !strcmp(token[0], "videocodec")) { | |
434 if (!validate_codec(codec, codec_type)) | |
435 goto err_out_not_valid; | |
436 loop_enter: | |
437 if (*token[0] == 'v') { | |
438 codec_type = TYPE_VIDEO; | |
439 nr_codecsp = &nr_vcodecs; | |
440 codecsp = &video_codecs; | |
441 } else if (*token[0] == 'a') { | |
442 codec_type = TYPE_AUDIO; | |
443 nr_codecsp = &nr_acodecs; | |
444 codecsp = &audio_codecs; | |
361 | 445 #ifdef DEBUG |
328 | 446 } else { |
361 | 447 printf("picsba\n"); |
328 | 448 goto err_out; |
361 | 449 #endif |
328 | 450 } |
451 if (!(*codecsp = (codecs_t *) realloc(*codecsp, | |
332 | 452 sizeof(codecs_t) * (*nr_codecsp + 2)))) { |
361 | 453 printf("can't realloc '*codecsp': %s\n", strerror(errno)); |
300 | 454 goto err_out; |
455 } | |
328 | 456 codec=*codecsp + *nr_codecsp; |
457 ++*nr_codecsp; | |
300 | 458 memset(codec,0,sizeof(codecs_t)); |
459 memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); | |
460 memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); | |
461 | |
319 | 462 if (get_token(1, 1) < 0) |
328 | 463 goto err_out_parse_error; |
464 for (i = 0; i < *nr_codecsp - 1; i++) { | |
465 if (!strcmp(token[0], (*codecsp)[i].name)) { | |
361 | 466 printf("codec name '%s' isn't unique", token[0]); |
467 goto err_out_print_linenum; | |
319 | 468 } |
469 } | |
328 | 470 if (!(codec->name = strdup(token[0]))) { |
361 | 471 printf("can't strdup -> 'name': %s\n", strerror(errno)); |
328 | 472 goto err_out; |
473 } | |
319 | 474 } else if (!strcmp(token[0], "info")) { |
328 | 475 if (codec->info || get_token(1, 1) < 0) |
476 goto err_out_parse_error; | |
477 if (!(codec->info = strdup(token[0]))) { | |
361 | 478 printf("can't strdup -> 'info': %s\n", strerror(errno)); |
328 | 479 goto err_out; |
480 } | |
319 | 481 } else if (!strcmp(token[0], "comment")) { |
482 if (get_token(1, 1) < 0) | |
328 | 483 goto err_out_parse_error; |
361 | 484 add_comment(token[0], &codec->comment); |
319 | 485 } else if (!strcmp(token[0], "fourcc")) { |
486 if (get_token(1, 2) < 0) | |
328 | 487 goto err_out_parse_error; |
319 | 488 if (!add_to_fourcc(token[0], token[1], |
300 | 489 codec->fourcc, |
490 codec->fourccmap)) | |
361 | 491 goto err_out_print_linenum; |
319 | 492 } else if (!strcmp(token[0], "format")) { |
493 if (get_token(1, 1) < 0) | |
328 | 494 goto err_out_parse_error; |
319 | 495 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap)) |
361 | 496 goto err_out_print_linenum; |
319 | 497 } else if (!strcmp(token[0], "driver")) { |
498 if (get_token(1, 1) < 0) | |
328 | 499 goto err_out_parse_error; |
1293 | 500 if ((codec->driver = get_driver(token[0],codec_type))<0) |
361 | 501 goto err_out_parse_error; |
319 | 502 } else if (!strcmp(token[0], "dll")) { |
503 if (get_token(1, 1) < 0) | |
328 | 504 goto err_out_parse_error; |
505 if (!(codec->dll = strdup(token[0]))) { | |
361 | 506 printf("can't strdup -> 'dll': %s\n", strerror(errno)); |
328 | 507 goto err_out; |
508 } | |
319 | 509 } else if (!strcmp(token[0], "guid")) { |
328 | 510 if (get_token(11, 11) < 0) |
511 goto err_out_parse_error; | |
335 | 512 codec->guid.f1=strtoul(token[0],&endptr,0); |
361 | 513 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
514 *endptr != '\0') | |
335 | 515 goto err_out_parse_error; |
516 codec->guid.f2=strtoul(token[1],&endptr,0); | |
361 | 517 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
518 *endptr != '\0') | |
335 | 519 goto err_out_parse_error; |
520 codec->guid.f3=strtoul(token[2],&endptr,0); | |
361 | 521 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
522 *endptr != '\0') | |
335 | 523 goto err_out_parse_error; |
524 for (i = 0; i < 8; i++) { | |
525 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); | |
361 | 526 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
527 *endptr != '\0') | |
328 | 528 goto err_out_parse_error; |
297 | 529 } |
319 | 530 } else if (!strcmp(token[0], "out")) { |
531 if (get_token(1, 2) < 0) | |
328 | 532 goto err_out_parse_error; |
319 | 533 if (!add_to_out(token[0], token[1], codec->outfmt, |
300 | 534 codec->outflags)) |
361 | 535 goto err_out_print_linenum; |
319 | 536 } else if (!strcmp(token[0], "flags")) { |
537 if (get_token(1, 1) < 0) | |
328 | 538 goto err_out_parse_error; |
321 | 539 if (!strcmp(token[0], "seekable")) |
540 codec->flags |= CODECS_FLAG_SEEKABLE; | |
541 else | |
328 | 542 goto err_out_parse_error; |
319 | 543 } else if (!strcmp(token[0], "status")) { |
544 if (get_token(1, 1) < 0) | |
328 | 545 goto err_out_parse_error; |
332 | 546 if (!strcasecmp(token[0], "working")) |
316 | 547 codec->status = CODECS_STATUS_WORKING; |
332 | 548 else if (!strcasecmp(token[0], "crashing")) |
316 | 549 codec->status = CODECS_STATUS_NOT_WORKING; |
332 | 550 else if (!strcasecmp(token[0], "untested")) |
316 | 551 codec->status = CODECS_STATUS_UNTESTED; |
332 | 552 else if (!strcasecmp(token[0], "buggy")) |
316 | 553 codec->status = CODECS_STATUS_PROBLEMS; |
554 else | |
328 | 555 goto err_out_parse_error; |
361 | 556 } else if (!strcmp(token[0], "cpuflags")) { |
557 if (get_token(1, 1) < 0) | |
558 goto err_out_parse_error; | |
559 if (!(codec->cpuflags = get_cpuflags(token[0]))) | |
560 goto err_out_parse_error; | |
297 | 561 } else |
328 | 562 goto err_out_parse_error; |
297 | 563 } |
328 | 564 if (!validate_codec(codec, codec_type)) |
565 goto err_out_not_valid; | |
361 | 566 printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs); |
895 | 567 if(video_codecs) video_codecs[nr_vcodecs].name = NULL; |
568 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL; | |
328 | 569 ret_codecs[0] = video_codecs; |
570 ret_codecs[1] = audio_codecs; | |
297 | 571 out: |
572 free(line); | |
573 fclose(fp); | |
328 | 574 return ret_codecs; |
575 err_out_parse_error: | |
361 | 576 printf("parse error"); |
577 err_out_print_linenum: | |
297 | 578 PRINT_LINENUM; |
579 err_out: | |
328 | 580 if (audio_codecs) |
581 free(audio_codecs); | |
582 if (video_codecs) | |
583 free(video_codecs); | |
584 free(line); | |
585 free(fp); | |
586 return NULL; | |
587 err_out_not_valid: | |
361 | 588 printf("codec is not definied correctly"); |
589 goto err_out_print_linenum; | |
297 | 590 } |
591 | |
332 | 592 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, |
593 codecs_t *start) | |
328 | 594 { |
332 | 595 return find_codec(fourcc, fourccmap, start, 1); |
328 | 596 } |
597 | |
332 | 598 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, |
599 codecs_t *start) | |
328 | 600 { |
332 | 601 return find_codec(fourcc, fourccmap, start, 0); |
328 | 602 } |
603 | |
332 | 604 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, |
605 codecs_t *start, int audioflag) | |
328 | 606 { |
607 int i, j; | |
608 codecs_t *c; | |
609 | |
628 | 610 #if 0 |
332 | 611 if (start) { |
612 for (/* NOTHING */; start->name; start++) { | |
613 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
614 if (start->fourcc[j] == fourcc) { | |
615 if (fourccmap) | |
616 *fourccmap = start->fourccmap[j]; | |
617 return start; | |
618 } | |
619 } | |
620 } | |
628 | 621 } else |
622 #endif | |
623 { | |
332 | 624 if (audioflag) { |
625 i = nr_acodecs; | |
626 c = audio_codecs; | |
627 } else { | |
628 i = nr_vcodecs; | |
629 c = video_codecs; | |
630 } | |
895 | 631 if(!i) return NULL; |
332 | 632 for (/* NOTHING */; i--; c++) { |
628 | 633 if(start && c<=start) continue; |
332 | 634 for (j = 0; j < CODECS_MAX_FOURCC; j++) { |
1391 | 635 if (c->fourcc[j]==fourcc || c->driver==0) { |
332 | 636 if (fourccmap) |
637 *fourccmap = c->fourccmap[j]; | |
638 return c; | |
639 } | |
328 | 640 } |
641 } | |
642 } | |
643 return NULL; | |
303 | 644 } |
645 | |
607 | 646 #ifdef CODECS2HTML |
647 | |
648 void wrapline(FILE *f2,char *s){ | |
649 int c; | |
650 if(!s){ | |
651 fprintf(f2,"-"); | |
652 return; | |
653 } | |
654 while((c=*s++)){ | |
655 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); | |
656 } | |
657 } | |
658 | |
659 void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ | |
660 int c,d; | |
661 while((c=fgetc(f1))>=0){ | |
662 if(c!='%'){ | |
663 fputc(c,f2); | |
664 continue; | |
665 } | |
666 d=fgetc(f1); | |
667 | |
668 switch(d){ | |
669 case '.': | |
613 | 670 return; // end of section |
607 | 671 case 'n': |
672 wrapline(f2,codec->name); break; | |
673 case 'i': | |
674 wrapline(f2,codec->info); break; | |
675 case 'c': | |
676 wrapline(f2,codec->comment); break; | |
677 case 'd': | |
678 wrapline(f2,codec->dll); break; | |
679 case 'D': | |
680 fprintf(f2,"%c",codec->driver==dshow?'+':'-'); break; | |
681 case 'F': | |
682 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
683 if(codec->fourcc[d]!=0xFFFFFFFF) | |
684 fprintf(f2,"%s%.4s",d?"<br>":"",codec->fourcc[d]<0x20202020?"-":(char*) &codec->fourcc[d]); | |
685 break; | |
686 case 'f': | |
687 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
688 if(codec->fourcc[d]!=0xFFFFFFFF) | |
689 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]); | |
690 break; | |
691 case 'Y': | |
692 for(d=0;d<CODECS_MAX_OUTFMT;d++) | |
693 if(codec->outfmt[d]!=0xFFFFFFFF){ | |
694 for (c=0; fmt_table[c].name; c++) | |
695 if(fmt_table[c].num==codec->outfmt[d]) break; | |
696 if(fmt_table[c].name) | |
697 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name); | |
698 } | |
699 break; | |
700 default: | |
701 fputc(c,f2); | |
702 fputc(d,f2); | |
703 } | |
704 } | |
705 | |
706 } | |
707 | |
708 void skiphtml(FILE *f1){ | |
709 int c,d; | |
710 while((c=fgetc(f1))>=0){ | |
711 if(c!='%'){ | |
712 continue; | |
713 } | |
714 d=fgetc(f1); | |
715 if(d=='.') return; // end of section | |
716 } | |
717 } | |
718 | |
719 int main(void) | |
720 { | |
721 codecs_t **codecs, *cl; | |
722 FILE *f1; | |
723 FILE *f2; | |
724 int c,d,i; | |
725 int pos; | |
726 int section=-1; | |
727 int nr_codecs; | |
728 int win32=-1; | |
729 int dshow=-1; | |
730 | |
1614 | 731 if (!(codecs = parse_codec_cfg("etc/codecs.conf"))) |
607 | 732 return 0; |
733 if (!codecs[0]) | |
734 printf("no videoconfig.\n"); | |
735 if (!codecs[1]) | |
736 printf("no audioconfig.\n"); | |
737 | |
738 f1=fopen("DOCS/codecs-in.html","rb"); if(!f1) exit(1); | |
1689 | 739 f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); |
607 | 740 |
741 while((c=fgetc(f1))>=0){ | |
742 if(c!='%'){ | |
743 fputc(c,f2); | |
744 continue; | |
745 } | |
746 d=fgetc(f1); | |
747 if(d>='0' && d<='9'){ | |
748 // begin section | |
749 section=d-'0'; | |
750 printf("BEGIN %d\n",section); | |
751 if(section>=5){ | |
752 // audio | |
753 cl = codecs[1]; | |
754 nr_codecs = nr_acodecs; | |
755 dshow=7;win32=4; | |
756 } else { | |
757 // video | |
758 cl = codecs[0]; | |
759 nr_codecs = nr_vcodecs; | |
760 dshow=4;win32=2; | |
761 } | |
762 pos=ftell(f1); | |
763 for(i=0;i<nr_codecs;i++){ | |
764 fseek(f1,pos,SEEK_SET); | |
765 switch(section){ | |
766 case 0: | |
767 case 5: | |
768 if(cl[i].status==CODECS_STATUS_WORKING) | |
769 if(!(cl[i].driver==win32 || cl[i].driver==dshow)) | |
770 parsehtml(f1,f2,&cl[i],section,dshow); | |
771 break; | |
772 case 1: | |
773 case 6: | |
774 if(cl[i].status==CODECS_STATUS_WORKING) | |
775 if(cl[i].driver==win32 || cl[i].driver==dshow) | |
776 parsehtml(f1,f2,&cl[i],section,dshow); | |
777 break; | |
778 case 2: | |
779 case 7: | |
780 if(cl[i].status==CODECS_STATUS_PROBLEMS) | |
781 parsehtml(f1,f2,&cl[i],section,dshow); | |
782 break; | |
783 case 3: | |
784 case 8: | |
785 if(cl[i].status==CODECS_STATUS_NOT_WORKING) | |
786 parsehtml(f1,f2,&cl[i],section,dshow); | |
787 break; | |
788 case 4: | |
789 case 9: | |
790 if(cl[i].status==CODECS_STATUS_UNTESTED) | |
791 parsehtml(f1,f2,&cl[i],section,dshow); | |
792 break; | |
793 default: | |
794 printf("Warning! unimplemented section: %d\n",section); | |
795 } | |
796 } | |
797 fseek(f1,pos,SEEK_SET); | |
798 skiphtml(f1); | |
799 //void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ | |
800 | |
801 continue; | |
802 } | |
803 fputc(c,f2); | |
804 fputc(d,f2); | |
805 } | |
806 | |
807 fclose(f2); | |
808 fclose(f1); | |
809 return 0; | |
810 } | |
811 | |
812 #endif | |
813 | |
297 | 814 #ifdef TESTING |
815 int main(void) | |
816 { | |
328 | 817 codecs_t **codecs, *c; |
818 int i,j, nr_codecs, state; | |
297 | 819 |
1614 | 820 if (!(codecs = parse_codec_cfg("etc/codecs.conf"))) |
319 | 821 return 0; |
328 | 822 if (!codecs[0]) |
823 printf("no videoconfig.\n"); | |
824 if (!codecs[1]) | |
825 printf("no audioconfig.\n"); | |
826 | |
827 printf("videocodecs:\n"); | |
828 c = codecs[0]; | |
829 nr_codecs = nr_vcodecs; | |
830 state = 0; | |
831 next: | |
832 if (c) { | |
833 printf("number of codecs: %d\n", nr_codecs); | |
834 for(i=0;i<nr_codecs;i++, c++){ | |
835 printf("\n============== codec %02d ===============\n",i); | |
836 printf("name='%s'\n",c->name); | |
837 printf("info='%s'\n",c->info); | |
838 printf("comment='%s'\n",c->comment); | |
839 printf("dll='%s'\n",c->dll); | |
361 | 840 printf("flags=%X driver=%d status=%d cpuflags=%d\n", |
841 c->flags, c->driver, c->status, c->cpuflags); | |
300 | 842 |
328 | 843 for(j=0;j<CODECS_MAX_FOURCC;j++){ |
844 if(c->fourcc[j]!=0xFFFFFFFF){ | |
361 | 845 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]); |
328 | 846 } |
847 } | |
848 | |
849 for(j=0;j<CODECS_MAX_OUTFMT;j++){ | |
850 if(c->outfmt[j]!=0xFFFFFFFF){ | |
361 | 851 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]); |
328 | 852 } |
853 } | |
300 | 854 |
328 | 855 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); |
856 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); | |
857 printf("\n"); | |
300 | 858 |
328 | 859 |
860 } | |
861 } | |
862 if (!state) { | |
863 printf("audiocodecs:\n"); | |
864 c = codecs[1]; | |
865 nr_codecs = nr_acodecs; | |
866 state = 1; | |
867 goto next; | |
868 } | |
297 | 869 return 0; |
870 } | |
871 | |
872 #endif |