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