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