Mercurial > mplayer.hg
annotate codec-cfg.c @ 3555:33bbfea73af3
Partial sync with linux stuff (Linux driver is still buggy for me)
author | nick |
---|---|
date | Mon, 17 Dec 2001 09:07:12 +0000 |
parents | 725b3de963eb |
children | fb9fd7e2dd35 |
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 { |
328 | 246 int i; |
3408 | 247 char *tmp_name = strdup(c->name); |
328 | 248 |
3408 | 249 for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++) |
328 | 250 /* NOTHING */; |
3408 | 251 |
252 if (i < strlen(tmp_name)) { | |
253 printf("\ncodec(%s) name is not valid!\n", c->name); | |
328 | 254 return 0; |
255 } | |
3408 | 256 |
328 | 257 if (!c->info) |
3408 | 258 c->info = strdup(c->name); |
259 | |
260 #if 0 | |
328 | 261 if (c->fourcc[0] == 0xffffffff) { |
262 printf("\ncodec(%s) does not have fourcc/format!\n", c->name); | |
263 return 0; | |
264 } | |
3408 | 265 |
266 /* XXX fix this: shitty with 'null' codec */ | |
328 | 267 if (!c->driver) { |
268 printf("\ncodec(%s) does not have a driver!\n", c->name); | |
269 return 0; | |
270 } | |
3408 | 271 #endif |
272 | |
273 #if 0 | |
328 | 274 #warning codec->driver == 4;... <- ezt nem kellene belehegeszteni... |
275 #warning HOL VANNAK DEFINIALVA???????????? | |
276 if (!c->dll && (c->driver == 4 || | |
277 (c->driver == 2 && type == TYPE_VIDEO))) { | |
278 printf("\ncodec(%s) needs a 'dll'!\n", c->name); | |
279 return 0; | |
280 } | |
281 #warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg? | |
282 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4) | |
283 | |
284 if (type == TYPE_VIDEO) | |
285 if (c->outfmt[0] == 0xffffffff) { | |
286 printf("\ncodec(%s) needs an 'outfmt'!\n", c->name); | |
287 return 0; | |
288 } | |
329 | 289 #endif |
319 | 290 return 1; |
291 } | |
292 | |
293 static int add_comment(char *s, char **d) | |
294 { | |
295 int pos; | |
296 | |
297 if (!*d) | |
298 pos = 0; | |
299 else { | |
300 pos = strlen(*d); | |
301 (*d)[pos++] = '\n'; | |
302 } | |
303 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) { | |
361 | 304 printf("can't allocate mem for comment. "); |
319 | 305 return 0; |
306 } | |
307 strcpy(*d + pos, s); | |
308 return 1; | |
309 } | |
297 | 310 |
361 | 311 static short get_cpuflags(char *s) |
312 { | |
313 static char *flagstr[] = { | |
314 "mmx", | |
315 "sse", | |
316 "3dnow", | |
317 NULL | |
318 }; | |
319 int i; | |
320 short flags = 0; | |
321 | |
322 do { | |
323 for (i = 0; flagstr[i]; i++) | |
324 if (!strncmp(s, flagstr[i], strlen(flagstr[i]))) | |
325 break; | |
326 if (!flagstr[i]) | |
327 goto err_out_parse_error; | |
328 flags |= 1<<i; | |
329 s += strlen(flagstr[i]); | |
330 } while (*(s++) == ','); | |
331 | |
332 if (*(--s) != '\0') | |
333 goto err_out_parse_error; | |
334 | |
335 return flags; | |
336 err_out_parse_error: | |
337 return 0; | |
338 } | |
339 | |
328 | 340 static FILE *fp; |
341 static int line_num = 0; | |
342 static char *line; | |
343 static char *token[MAX_NR_TOKEN]; | |
344 | |
345 static int get_token(int min, int max) | |
297 | 346 { |
328 | 347 static int read_nextline = 1; |
348 static int line_pos; | |
349 int i; | |
350 char c; | |
351 | |
352 if (max >= MAX_NR_TOKEN) { | |
361 | 353 printf("get_token(): max >= MAX_NR_TOKEN!"); |
328 | 354 goto out_eof; |
355 } | |
356 | |
357 memset(token, 0x00, sizeof(*token) * max); | |
358 | |
359 if (read_nextline) { | |
360 if (!fgets(line, MAX_LINE_LEN, fp)) | |
361 goto out_eof; | |
362 line_pos = 0; | |
363 ++line_num; | |
364 read_nextline = 0; | |
365 } | |
366 for (i = 0; i < max; i++) { | |
367 while (isspace(line[line_pos])) | |
368 ++line_pos; | |
369 if (line[line_pos] == '\0' || line[line_pos] == '#' || | |
370 line[line_pos] == ';') { | |
371 read_nextline = 1; | |
372 if (i >= min) | |
373 goto out_ok; | |
374 goto out_eol; | |
375 } | |
376 token[i] = line + line_pos; | |
377 c = line[line_pos]; | |
378 if (c == '"' || c == '\'') { | |
379 token[i]++; | |
380 while (line[++line_pos] != c && line[line_pos]) | |
381 /* NOTHING */; | |
382 } else { | |
383 for (/* NOTHING */; !isspace(line[line_pos]) && | |
384 line[line_pos]; line_pos++) | |
385 /* NOTHING */; | |
386 } | |
387 if (!line[line_pos]) { | |
388 read_nextline = 1; | |
389 if (i >= min - 1) | |
390 goto out_ok; | |
391 goto out_eol; | |
392 } | |
393 line[line_pos] = '\0'; | |
394 line_pos++; | |
395 } | |
396 out_ok: | |
397 return i; | |
398 out_eof: | |
399 return RET_EOF; | |
400 out_eol: | |
401 return RET_EOL; | |
402 } | |
403 | |
404 static codecs_t *video_codecs=NULL; | |
405 static codecs_t *audio_codecs=NULL; | |
406 static int nr_vcodecs = 0; | |
407 static int nr_acodecs = 0; | |
408 | |
409 codecs_t **parse_codec_cfg(char *cfgfile) | |
410 { | |
411 codecs_t *codec = NULL; // current codec | |
412 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs | |
413 static codecs_t *ret_codecs[2] = {NULL,NULL}; | |
335 | 414 char *endptr; // strtoul()... |
328 | 415 int *nr_codecsp; |
416 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ | |
297 | 417 int tmp, i; |
418 | |
419 #ifdef DEBUG | |
420 assert(cfgfile != NULL); | |
421 #endif | |
422 | |
361 | 423 printf("Reading %s: ", cfgfile); |
297 | 424 |
301 | 425 if ((fp = fopen(cfgfile, "r")) == NULL) { |
328 | 426 printf("can't open '%s': %s\n", cfgfile, strerror(errno)); |
297 | 427 return NULL; |
428 } | |
429 | |
301 | 430 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { |
361 | 431 printf("can't get memory for 'line': %s\n", strerror(errno)); |
297 | 432 return NULL; |
433 } | |
434 | |
328 | 435 /* |
436 * check if the cfgfile starts with 'audiocodec' or | |
437 * with 'videocodec' | |
438 */ | |
439 while ((tmp = get_token(1, 1)) == RET_EOL) | |
440 /* NOTHING */; | |
361 | 441 if (tmp == RET_EOF) |
442 goto out; | |
443 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) | |
328 | 444 goto loop_enter; |
361 | 445 goto err_out_parse_error; |
328 | 446 |
319 | 447 while ((tmp = get_token(1, 1)) != RET_EOF) { |
297 | 448 if (tmp == RET_EOL) |
449 continue; | |
328 | 450 if (!strcmp(token[0], "audiocodec") || |
451 !strcmp(token[0], "videocodec")) { | |
452 if (!validate_codec(codec, codec_type)) | |
453 goto err_out_not_valid; | |
454 loop_enter: | |
455 if (*token[0] == 'v') { | |
456 codec_type = TYPE_VIDEO; | |
457 nr_codecsp = &nr_vcodecs; | |
458 codecsp = &video_codecs; | |
459 } else if (*token[0] == 'a') { | |
460 codec_type = TYPE_AUDIO; | |
461 nr_codecsp = &nr_acodecs; | |
462 codecsp = &audio_codecs; | |
361 | 463 #ifdef DEBUG |
328 | 464 } else { |
361 | 465 printf("picsba\n"); |
328 | 466 goto err_out; |
361 | 467 #endif |
328 | 468 } |
469 if (!(*codecsp = (codecs_t *) realloc(*codecsp, | |
332 | 470 sizeof(codecs_t) * (*nr_codecsp + 2)))) { |
361 | 471 printf("can't realloc '*codecsp': %s\n", strerror(errno)); |
300 | 472 goto err_out; |
473 } | |
328 | 474 codec=*codecsp + *nr_codecsp; |
475 ++*nr_codecsp; | |
300 | 476 memset(codec,0,sizeof(codecs_t)); |
477 memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); | |
478 memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); | |
479 | |
319 | 480 if (get_token(1, 1) < 0) |
328 | 481 goto err_out_parse_error; |
482 for (i = 0; i < *nr_codecsp - 1; i++) { | |
483 if (!strcmp(token[0], (*codecsp)[i].name)) { | |
361 | 484 printf("codec name '%s' isn't unique", token[0]); |
485 goto err_out_print_linenum; | |
319 | 486 } |
487 } | |
328 | 488 if (!(codec->name = strdup(token[0]))) { |
361 | 489 printf("can't strdup -> 'name': %s\n", strerror(errno)); |
328 | 490 goto err_out; |
491 } | |
319 | 492 } else if (!strcmp(token[0], "info")) { |
328 | 493 if (codec->info || get_token(1, 1) < 0) |
494 goto err_out_parse_error; | |
495 if (!(codec->info = strdup(token[0]))) { | |
361 | 496 printf("can't strdup -> 'info': %s\n", strerror(errno)); |
328 | 497 goto err_out; |
498 } | |
319 | 499 } else if (!strcmp(token[0], "comment")) { |
500 if (get_token(1, 1) < 0) | |
328 | 501 goto err_out_parse_error; |
361 | 502 add_comment(token[0], &codec->comment); |
319 | 503 } else if (!strcmp(token[0], "fourcc")) { |
504 if (get_token(1, 2) < 0) | |
328 | 505 goto err_out_parse_error; |
319 | 506 if (!add_to_fourcc(token[0], token[1], |
300 | 507 codec->fourcc, |
508 codec->fourccmap)) | |
361 | 509 goto err_out_print_linenum; |
319 | 510 } else if (!strcmp(token[0], "format")) { |
511 if (get_token(1, 1) < 0) | |
328 | 512 goto err_out_parse_error; |
319 | 513 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap)) |
361 | 514 goto err_out_print_linenum; |
319 | 515 } else if (!strcmp(token[0], "driver")) { |
516 if (get_token(1, 1) < 0) | |
328 | 517 goto err_out_parse_error; |
1293 | 518 if ((codec->driver = get_driver(token[0],codec_type))<0) |
361 | 519 goto err_out_parse_error; |
319 | 520 } else if (!strcmp(token[0], "dll")) { |
521 if (get_token(1, 1) < 0) | |
328 | 522 goto err_out_parse_error; |
523 if (!(codec->dll = strdup(token[0]))) { | |
361 | 524 printf("can't strdup -> 'dll': %s\n", strerror(errno)); |
328 | 525 goto err_out; |
526 } | |
319 | 527 } else if (!strcmp(token[0], "guid")) { |
328 | 528 if (get_token(11, 11) < 0) |
529 goto err_out_parse_error; | |
335 | 530 codec->guid.f1=strtoul(token[0],&endptr,0); |
361 | 531 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
532 *endptr != '\0') | |
335 | 533 goto err_out_parse_error; |
534 codec->guid.f2=strtoul(token[1],&endptr,0); | |
361 | 535 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
536 *endptr != '\0') | |
335 | 537 goto err_out_parse_error; |
538 codec->guid.f3=strtoul(token[2],&endptr,0); | |
361 | 539 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
540 *endptr != '\0') | |
335 | 541 goto err_out_parse_error; |
542 for (i = 0; i < 8; i++) { | |
543 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); | |
361 | 544 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
545 *endptr != '\0') | |
328 | 546 goto err_out_parse_error; |
297 | 547 } |
319 | 548 } else if (!strcmp(token[0], "out")) { |
549 if (get_token(1, 2) < 0) | |
328 | 550 goto err_out_parse_error; |
319 | 551 if (!add_to_out(token[0], token[1], codec->outfmt, |
300 | 552 codec->outflags)) |
361 | 553 goto err_out_print_linenum; |
319 | 554 } else if (!strcmp(token[0], "flags")) { |
555 if (get_token(1, 1) < 0) | |
328 | 556 goto err_out_parse_error; |
321 | 557 if (!strcmp(token[0], "seekable")) |
558 codec->flags |= CODECS_FLAG_SEEKABLE; | |
559 else | |
328 | 560 goto err_out_parse_error; |
319 | 561 } else if (!strcmp(token[0], "status")) { |
562 if (get_token(1, 1) < 0) | |
328 | 563 goto err_out_parse_error; |
332 | 564 if (!strcasecmp(token[0], "working")) |
316 | 565 codec->status = CODECS_STATUS_WORKING; |
332 | 566 else if (!strcasecmp(token[0], "crashing")) |
316 | 567 codec->status = CODECS_STATUS_NOT_WORKING; |
332 | 568 else if (!strcasecmp(token[0], "untested")) |
316 | 569 codec->status = CODECS_STATUS_UNTESTED; |
332 | 570 else if (!strcasecmp(token[0], "buggy")) |
316 | 571 codec->status = CODECS_STATUS_PROBLEMS; |
572 else | |
328 | 573 goto err_out_parse_error; |
361 | 574 } else if (!strcmp(token[0], "cpuflags")) { |
575 if (get_token(1, 1) < 0) | |
576 goto err_out_parse_error; | |
577 if (!(codec->cpuflags = get_cpuflags(token[0]))) | |
578 goto err_out_parse_error; | |
297 | 579 } else |
328 | 580 goto err_out_parse_error; |
297 | 581 } |
328 | 582 if (!validate_codec(codec, codec_type)) |
583 goto err_out_not_valid; | |
361 | 584 printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs); |
895 | 585 if(video_codecs) video_codecs[nr_vcodecs].name = NULL; |
586 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL; | |
328 | 587 ret_codecs[0] = video_codecs; |
588 ret_codecs[1] = audio_codecs; | |
297 | 589 out: |
590 free(line); | |
591 fclose(fp); | |
328 | 592 return ret_codecs; |
593 err_out_parse_error: | |
361 | 594 printf("parse error"); |
595 err_out_print_linenum: | |
297 | 596 PRINT_LINENUM; |
597 err_out: | |
328 | 598 if (audio_codecs) |
599 free(audio_codecs); | |
600 if (video_codecs) | |
601 free(video_codecs); | |
602 free(line); | |
603 free(fp); | |
604 return NULL; | |
605 err_out_not_valid: | |
3408 | 606 printf("codec is not defined correctly"); |
361 | 607 goto err_out_print_linenum; |
297 | 608 } |
609 | |
332 | 610 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, |
611 codecs_t *start) | |
328 | 612 { |
332 | 613 return find_codec(fourcc, fourccmap, start, 1); |
328 | 614 } |
615 | |
332 | 616 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, |
617 codecs_t *start) | |
328 | 618 { |
332 | 619 return find_codec(fourcc, fourccmap, start, 0); |
328 | 620 } |
621 | |
332 | 622 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, |
623 codecs_t *start, int audioflag) | |
328 | 624 { |
625 int i, j; | |
626 codecs_t *c; | |
627 | |
628 | 628 #if 0 |
332 | 629 if (start) { |
630 for (/* NOTHING */; start->name; start++) { | |
631 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
632 if (start->fourcc[j] == fourcc) { | |
633 if (fourccmap) | |
634 *fourccmap = start->fourccmap[j]; | |
635 return start; | |
636 } | |
637 } | |
638 } | |
628 | 639 } else |
640 #endif | |
641 { | |
332 | 642 if (audioflag) { |
643 i = nr_acodecs; | |
644 c = audio_codecs; | |
645 } else { | |
646 i = nr_vcodecs; | |
647 c = video_codecs; | |
648 } | |
895 | 649 if(!i) return NULL; |
332 | 650 for (/* NOTHING */; i--; c++) { |
628 | 651 if(start && c<=start) continue; |
332 | 652 for (j = 0; j < CODECS_MAX_FOURCC; j++) { |
1391 | 653 if (c->fourcc[j]==fourcc || c->driver==0) { |
332 | 654 if (fourccmap) |
655 *fourccmap = c->fourccmap[j]; | |
656 return c; | |
657 } | |
328 | 658 } |
659 } | |
660 } | |
661 return NULL; | |
303 | 662 } |
663 | |
1983 | 664 void list_codecs(int audioflag){ |
2050 | 665 int i; |
1983 | 666 codecs_t *c; |
667 | |
668 if (audioflag) { | |
669 i = nr_acodecs; | |
670 c = audio_codecs; | |
1984 | 671 printf("ac: afm: status: info: [lib/dll]\n"); |
1983 | 672 } else { |
673 i = nr_vcodecs; | |
674 c = video_codecs; | |
1984 | 675 printf("vc: vfm: status: info: [lib/dll]\n"); |
1983 | 676 } |
2050 | 677 if(!i) return; |
1983 | 678 for (/* NOTHING */; i--; c++) { |
1984 | 679 char* s="unknown "; |
680 switch(c->status){ | |
681 case CODECS_STATUS_WORKING: s="working ";break; | |
682 case CODECS_STATUS_PROBLEMS: s="problems";break; | |
683 case CODECS_STATUS_NOT_WORKING: s="crashing";break; | |
684 case CODECS_STATUS_UNTESTED: s="untested";break; | |
685 } | |
1983 | 686 if(c->dll) |
1984 | 687 printf("%-10s%2d %s %s [%s]\n",c->name,c->driver,s,c->info,c->dll); |
1983 | 688 else |
1984 | 689 printf("%-10s%2d %s %s\n",c->name,c->driver,s,c->info); |
1983 | 690 |
691 } | |
692 | |
693 } | |
694 | |
695 | |
696 | |
607 | 697 #ifdef CODECS2HTML |
698 | |
699 void wrapline(FILE *f2,char *s){ | |
700 int c; | |
701 if(!s){ | |
702 fprintf(f2,"-"); | |
703 return; | |
704 } | |
705 while((c=*s++)){ | |
706 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); | |
707 } | |
708 } | |
709 | |
710 void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ | |
711 int c,d; | |
712 while((c=fgetc(f1))>=0){ | |
713 if(c!='%'){ | |
714 fputc(c,f2); | |
715 continue; | |
716 } | |
717 d=fgetc(f1); | |
718 | |
719 switch(d){ | |
720 case '.': | |
613 | 721 return; // end of section |
607 | 722 case 'n': |
723 wrapline(f2,codec->name); break; | |
724 case 'i': | |
725 wrapline(f2,codec->info); break; | |
726 case 'c': | |
727 wrapline(f2,codec->comment); break; | |
728 case 'd': | |
729 wrapline(f2,codec->dll); break; | |
730 case 'D': | |
731 fprintf(f2,"%c",codec->driver==dshow?'+':'-'); break; | |
732 case 'F': | |
733 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
|
734 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
|
735 fprintf(f2,"%s%.4s",d?"<br>":"",(codec->fourcc[d]==0xFFFFFFFF || codec->fourcc[d]<0x20202020)?!d?"-":"":(char*) &codec->fourcc[d]); |
607 | 736 break; |
737 case 'f': | |
738 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
739 if(codec->fourcc[d]!=0xFFFFFFFF) | |
740 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]); | |
741 break; | |
742 case 'Y': | |
743 for(d=0;d<CODECS_MAX_OUTFMT;d++) | |
744 if(codec->outfmt[d]!=0xFFFFFFFF){ | |
745 for (c=0; fmt_table[c].name; c++) | |
746 if(fmt_table[c].num==codec->outfmt[d]) break; | |
747 if(fmt_table[c].name) | |
748 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name); | |
749 } | |
750 break; | |
751 default: | |
752 fputc(c,f2); | |
753 fputc(d,f2); | |
754 } | |
755 } | |
756 | |
757 } | |
758 | |
759 void skiphtml(FILE *f1){ | |
760 int c,d; | |
761 while((c=fgetc(f1))>=0){ | |
762 if(c!='%'){ | |
763 continue; | |
764 } | |
765 d=fgetc(f1); | |
766 if(d=='.') return; // end of section | |
767 } | |
768 } | |
769 | |
770 int main(void) | |
771 { | |
772 codecs_t **codecs, *cl; | |
773 FILE *f1; | |
774 FILE *f2; | |
775 int c,d,i; | |
776 int pos; | |
777 int section=-1; | |
778 int nr_codecs; | |
779 int win32=-1; | |
780 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
|
781 int win32ex=-1; |
607 | 782 |
1614 | 783 if (!(codecs = parse_codec_cfg("etc/codecs.conf"))) |
607 | 784 return 0; |
785 if (!codecs[0]) | |
786 printf("no videoconfig.\n"); | |
787 if (!codecs[1]) | |
788 printf("no audioconfig.\n"); | |
789 | |
790 f1=fopen("DOCS/codecs-in.html","rb"); if(!f1) exit(1); | |
1689 | 791 f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); |
607 | 792 |
793 while((c=fgetc(f1))>=0){ | |
794 if(c!='%'){ | |
795 fputc(c,f2); | |
796 continue; | |
797 } | |
798 d=fgetc(f1); | |
799 if(d>='0' && d<='9'){ | |
800 // begin section | |
801 section=d-'0'; | |
802 printf("BEGIN %d\n",section); | |
803 if(section>=5){ | |
804 // audio | |
805 cl = codecs[1]; | |
806 nr_codecs = nr_acodecs; | |
807 dshow=7;win32=4; | |
808 } else { | |
809 // video | |
810 cl = codecs[0]; | |
811 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
|
812 dshow=4;win32=2;win32ex=6; |
607 | 813 } |
814 pos=ftell(f1); | |
815 for(i=0;i<nr_codecs;i++){ | |
816 fseek(f1,pos,SEEK_SET); | |
817 switch(section){ | |
818 case 0: | |
819 case 5: | |
820 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
|
821 if(!(cl[i].driver==win32 || cl[i].driver==dshow || cl[i].driver==win32ex)) |
607 | 822 parsehtml(f1,f2,&cl[i],section,dshow); |
823 break; | |
824 case 1: | |
825 case 6: | |
826 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
|
827 if(cl[i].driver==win32 || cl[i].driver==dshow || cl[i].driver==win32ex) |
607 | 828 parsehtml(f1,f2,&cl[i],section,dshow); |
829 break; | |
830 case 2: | |
831 case 7: | |
832 if(cl[i].status==CODECS_STATUS_PROBLEMS) | |
833 parsehtml(f1,f2,&cl[i],section,dshow); | |
834 break; | |
835 case 3: | |
836 case 8: | |
837 if(cl[i].status==CODECS_STATUS_NOT_WORKING) | |
838 parsehtml(f1,f2,&cl[i],section,dshow); | |
839 break; | |
840 case 4: | |
841 case 9: | |
842 if(cl[i].status==CODECS_STATUS_UNTESTED) | |
843 parsehtml(f1,f2,&cl[i],section,dshow); | |
844 break; | |
845 default: | |
846 printf("Warning! unimplemented section: %d\n",section); | |
847 } | |
848 } | |
849 fseek(f1,pos,SEEK_SET); | |
850 skiphtml(f1); | |
851 //void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ | |
852 | |
853 continue; | |
854 } | |
855 fputc(c,f2); | |
856 fputc(d,f2); | |
857 } | |
858 | |
859 fclose(f2); | |
860 fclose(f1); | |
861 return 0; | |
862 } | |
863 | |
864 #endif | |
865 | |
297 | 866 #ifdef TESTING |
867 int main(void) | |
868 { | |
328 | 869 codecs_t **codecs, *c; |
870 int i,j, nr_codecs, state; | |
297 | 871 |
1614 | 872 if (!(codecs = parse_codec_cfg("etc/codecs.conf"))) |
319 | 873 return 0; |
328 | 874 if (!codecs[0]) |
875 printf("no videoconfig.\n"); | |
876 if (!codecs[1]) | |
877 printf("no audioconfig.\n"); | |
878 | |
879 printf("videocodecs:\n"); | |
880 c = codecs[0]; | |
881 nr_codecs = nr_vcodecs; | |
882 state = 0; | |
883 next: | |
884 if (c) { | |
885 printf("number of codecs: %d\n", nr_codecs); | |
886 for(i=0;i<nr_codecs;i++, c++){ | |
887 printf("\n============== codec %02d ===============\n",i); | |
888 printf("name='%s'\n",c->name); | |
889 printf("info='%s'\n",c->info); | |
890 printf("comment='%s'\n",c->comment); | |
891 printf("dll='%s'\n",c->dll); | |
361 | 892 printf("flags=%X driver=%d status=%d cpuflags=%d\n", |
893 c->flags, c->driver, c->status, c->cpuflags); | |
300 | 894 |
328 | 895 for(j=0;j<CODECS_MAX_FOURCC;j++){ |
896 if(c->fourcc[j]!=0xFFFFFFFF){ | |
361 | 897 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]); |
328 | 898 } |
899 } | |
900 | |
901 for(j=0;j<CODECS_MAX_OUTFMT;j++){ | |
902 if(c->outfmt[j]!=0xFFFFFFFF){ | |
361 | 903 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]); |
328 | 904 } |
905 } | |
300 | 906 |
328 | 907 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); |
908 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); | |
909 printf("\n"); | |
300 | 910 |
328 | 911 |
912 } | |
913 } | |
914 if (!state) { | |
915 printf("audiocodecs:\n"); | |
916 c = codecs[1]; | |
917 nr_codecs = nr_acodecs; | |
918 state = 1; | |
919 goto next; | |
920 } | |
297 | 921 return 0; |
922 } | |
923 | |
924 #endif |