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