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