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