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