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