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