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