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