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