Mercurial > mplayer.hg
annotate codec-cfg.c @ 3673:34d1094512d6
mplayer-felhasznalok mailing list added (hungarian users)
author | gabucino |
---|---|
date | Sun, 23 Dec 2001 16:56:27 +0000 |
parents | ec943f8ec439 |
children | 7fb817c9060b |
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 | |
2052 | 18 // for mmioFOURCC: |
1305
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 |
2897 | 21 #ifdef USE_LIBVO2 |
22 #include "libvo2/img_format.h" | |
23 #else | |
408 | 24 #include "libvo/img_format.h" |
2897 | 25 #endif |
297 | 26 #include "codec-cfg.h" |
27 | |
361 | 28 #define PRINT_LINENUM printf(" at line %d\n", line_num) |
328 | 29 |
319 | 30 #define MAX_NR_TOKEN 16 |
297 | 31 |
32 #define MAX_LINE_LEN 1000 | |
33 | |
34 #define RET_EOF -1 | |
35 #define RET_EOL -2 | |
36 | |
328 | 37 #define TYPE_VIDEO 0 |
38 #define TYPE_AUDIO 1 | |
297 | 39 |
303 | 40 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc, |
297 | 41 unsigned int *map) |
42 { | |
319 | 43 int i, j, freeslots; |
44 unsigned int tmp; | |
45 | |
46 /* find first unused slot */ | |
47 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
48 /* NOTHING */; | |
49 freeslots = CODECS_MAX_FOURCC - i; | |
50 if (!freeslots) | |
328 | 51 goto err_out_too_many; |
319 | 52 |
53 do { | |
1305
0a8237e28ce0
Use FOURCC macro to encode fcc values. Avoids accessing 32-bit data from
jkeil
parents:
1297
diff
changeset
|
54 tmp = mmioFOURCC(s[0], s[1], s[2], s[3]); |
319 | 55 for (j = 0; j < i; j++) |
56 if (tmp == fourcc[j]) | |
328 | 57 goto err_out_duplicated; |
319 | 58 fourcc[i] = tmp; |
2681 | 59 map[i] = alias ? mmioFOURCC(alias[0], alias[1], alias[2], alias[3]) : tmp; |
319 | 60 s += 4; |
61 i++; | |
62 } while ((*(s++) == ',') && --freeslots); | |
63 | |
64 if (!freeslots) | |
328 | 65 goto err_out_too_many; |
319 | 66 if (*(--s) != '\0') |
361 | 67 goto err_out_parse_error; |
319 | 68 return 1; |
328 | 69 err_out_duplicated: |
361 | 70 printf("duplicated fourcc/format"); |
319 | 71 return 0; |
328 | 72 err_out_too_many: |
361 | 73 printf("too many fourcc/format..."); |
74 return 0; | |
75 err_out_parse_error: | |
76 printf("parse error"); | |
319 | 77 return 0; |
78 } | |
79 | |
80 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap) | |
81 { | |
82 int i, j; | |
361 | 83 char *endptr; |
297 | 84 |
85 /* find first unused slot */ | |
86 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
87 /* NOTHING */; | |
88 if (i == CODECS_MAX_FOURCC) { | |
361 | 89 printf("too many fourcc/format..."); |
297 | 90 return 0; |
91 } | |
92 | |
361 | 93 fourcc[i]=fourccmap[i]=strtoul(s,&endptr,0); |
94 if (*endptr != '\0') { | |
95 printf("parse error"); | |
96 return 0; | |
97 } | |
319 | 98 for (j = 0; j < i; j++) |
99 if (fourcc[j] == fourcc[i]) { | |
361 | 100 printf("duplicated fourcc/format"); |
319 | 101 return 0; |
102 } | |
300 | 103 |
297 | 104 return 1; |
105 } | |
106 | |
408 | 107 static struct { |
108 const char *name; | |
109 const unsigned int num; | |
110 } fmt_table[] = { | |
415 | 111 {"YV12", IMGFMT_YV12}, |
112 {"I420", IMGFMT_I420}, | |
113 {"IYUV", IMGFMT_IYUV}, | |
408 | 114 |
415 | 115 {"YUY2", IMGFMT_YUY2}, |
116 {"UYVY", IMGFMT_UYVY}, | |
117 {"YVYU", IMGFMT_YVYU}, | |
408 | 118 |
415 | 119 {"RGB8", IMGFMT_RGB|8}, |
120 {"RGB15", IMGFMT_RGB|15}, | |
121 {"RGB16", IMGFMT_RGB|16}, | |
122 {"RGB24", IMGFMT_RGB|24}, | |
123 {"RGB32", IMGFMT_RGB|32}, | |
124 {"BGR8", IMGFMT_BGR|8}, | |
125 {"BGR15", IMGFMT_BGR|15}, | |
126 {"BGR16", IMGFMT_BGR|16}, | |
127 {"BGR24", IMGFMT_BGR|24}, | |
128 {"BGR32", IMGFMT_BGR|32}, | |
1871 | 129 |
130 {"MPES", IMGFMT_MPEGPES}, | |
415 | 131 {NULL, 0} |
297 | 132 }; |
408 | 133 |
607 | 134 |
135 static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt, | |
136 unsigned char *outflags) | |
137 { | |
138 | |
299 | 139 static char *flagstr[] = { |
140 "flip", | |
141 "noflip", | |
142 "yuvhack", | |
143 NULL | |
144 }; | |
145 | |
319 | 146 int i, j, freeslots; |
297 | 147 unsigned char flags; |
148 | |
149 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) | |
150 /* NOTHING */; | |
319 | 151 freeslots = CODECS_MAX_OUTFMT - i; |
152 if (!freeslots) | |
328 | 153 goto err_out_too_many; |
297 | 154 |
319 | 155 flags = 0; |
361 | 156 if(sflags) { |
157 do { | |
158 for (j = 0; flagstr[j] != NULL; j++) | |
159 if (!strncmp(sflags, flagstr[j], | |
160 strlen(flagstr[j]))) | |
161 break; | |
162 if (flagstr[j] == NULL) | |
163 goto err_out_parse_error; | |
164 flags|=(1<<j); | |
165 sflags+=strlen(flagstr[j]); | |
166 } while (*(sflags++) == ','); | |
167 | |
168 if (*(--sflags) != '\0') | |
169 goto err_out_parse_error; | |
170 } | |
297 | 171 |
172 do { | |
408 | 173 for (j = 0; fmt_table[j].name != NULL; j++) |
174 if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name))) | |
297 | 175 break; |
408 | 176 if (fmt_table[j].name == NULL) |
361 | 177 goto err_out_parse_error; |
408 | 178 outfmt[i] = fmt_table[j].num; |
297 | 179 outflags[i] = flags; |
299 | 180 ++i; |
408 | 181 sfmt+=strlen(fmt_table[j].name); |
319 | 182 } while ((*(sfmt++) == ',') && --freeslots); |
183 | |
184 if (!freeslots) | |
328 | 185 goto err_out_too_many; |
319 | 186 |
361 | 187 if (*(--sfmt) != '\0') |
188 goto err_out_parse_error; | |
299 | 189 |
297 | 190 return 1; |
328 | 191 err_out_too_many: |
361 | 192 printf("too many out..."); |
193 return 0; | |
194 err_out_parse_error: | |
195 printf("parse error"); | |
319 | 196 return 0; |
297 | 197 } |
198 | |
303 | 199 static short get_driver(char *s,int audioflag) |
297 | 200 { |
301 | 201 static char *audiodrv[] = { |
1293 | 202 "null", |
301 | 203 "mp3lib", |
204 "pcm", | |
205 "libac3", | |
206 "acm", | |
207 "alaw", | |
208 "msgsm", | |
209 "dshow", | |
401 | 210 "dvdpcm", |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1488
diff
changeset
|
211 "hwac3", |
1828 | 212 "libvorbis", |
1929 | 213 "ffmpeg", |
2415 | 214 "libmad", |
2422 | 215 "ima4", |
3400 | 216 "liba52", |
217 "g72x", | |
301 | 218 NULL |
219 }; | |
220 static char *videodrv[] = { | |
1293 | 221 "null", |
301 | 222 "libmpeg2", |
223 "vfw", | |
224 "odivx", | |
225 "dshow", | |
1248 | 226 "ffmpeg", |
1297 | 227 "vfwex", |
1349 | 228 "divx4", |
1488 | 229 "raw", |
1948 | 230 "rle", |
2379 | 231 "xanim", |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
2681
diff
changeset
|
232 "msvidc", |
3172 | 233 "fli", |
3643
fb9fd7e2dd35
native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
3408
diff
changeset
|
234 "cinepak", |
301 | 235 NULL |
236 }; | |
237 char **drv=audioflag?audiodrv:videodrv; | |
238 int i; | |
239 | |
1293 | 240 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i; |
301 | 241 |
1293 | 242 return -1; |
297 | 243 } |
244 | |
328 | 245 static int validate_codec(codecs_t *c, int type) |
319 | 246 { |
328 | 247 int i; |
3408 | 248 char *tmp_name = strdup(c->name); |
328 | 249 |
3408 | 250 for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++) |
328 | 251 /* NOTHING */; |
3408 | 252 |
253 if (i < strlen(tmp_name)) { | |
254 printf("\ncodec(%s) name is not valid!\n", c->name); | |
328 | 255 return 0; |
256 } | |
3408 | 257 |
328 | 258 if (!c->info) |
3408 | 259 c->info = strdup(c->name); |
260 | |
261 #if 0 | |
328 | 262 if (c->fourcc[0] == 0xffffffff) { |
263 printf("\ncodec(%s) does not have fourcc/format!\n", c->name); | |
264 return 0; | |
265 } | |
3408 | 266 |
267 /* XXX fix this: shitty with 'null' codec */ | |
328 | 268 if (!c->driver) { |
269 printf("\ncodec(%s) does not have a driver!\n", c->name); | |
270 return 0; | |
271 } | |
3408 | 272 #endif |
273 | |
274 #if 0 | |
328 | 275 #warning codec->driver == 4;... <- ezt nem kellene belehegeszteni... |
276 #warning HOL VANNAK DEFINIALVA???????????? | |
277 if (!c->dll && (c->driver == 4 || | |
278 (c->driver == 2 && type == TYPE_VIDEO))) { | |
279 printf("\ncodec(%s) needs a 'dll'!\n", c->name); | |
280 return 0; | |
281 } | |
282 #warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg? | |
283 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4) | |
284 | |
285 if (type == TYPE_VIDEO) | |
286 if (c->outfmt[0] == 0xffffffff) { | |
287 printf("\ncodec(%s) needs an 'outfmt'!\n", c->name); | |
288 return 0; | |
289 } | |
329 | 290 #endif |
319 | 291 return 1; |
292 } | |
293 | |
294 static int add_comment(char *s, char **d) | |
295 { | |
296 int pos; | |
297 | |
298 if (!*d) | |
299 pos = 0; | |
300 else { | |
301 pos = strlen(*d); | |
302 (*d)[pos++] = '\n'; | |
303 } | |
304 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) { | |
361 | 305 printf("can't allocate mem for comment. "); |
319 | 306 return 0; |
307 } | |
308 strcpy(*d + pos, s); | |
309 return 1; | |
310 } | |
297 | 311 |
361 | 312 static short get_cpuflags(char *s) |
313 { | |
314 static char *flagstr[] = { | |
315 "mmx", | |
316 "sse", | |
317 "3dnow", | |
318 NULL | |
319 }; | |
320 int i; | |
321 short flags = 0; | |
322 | |
323 do { | |
324 for (i = 0; flagstr[i]; i++) | |
325 if (!strncmp(s, flagstr[i], strlen(flagstr[i]))) | |
326 break; | |
327 if (!flagstr[i]) | |
328 goto err_out_parse_error; | |
329 flags |= 1<<i; | |
330 s += strlen(flagstr[i]); | |
331 } while (*(s++) == ','); | |
332 | |
333 if (*(--s) != '\0') | |
334 goto err_out_parse_error; | |
335 | |
336 return flags; | |
337 err_out_parse_error: | |
338 return 0; | |
339 } | |
340 | |
328 | 341 static FILE *fp; |
342 static int line_num = 0; | |
343 static char *line; | |
344 static char *token[MAX_NR_TOKEN]; | |
345 | |
346 static int get_token(int min, int max) | |
297 | 347 { |
328 | 348 static int read_nextline = 1; |
349 static int line_pos; | |
350 int i; | |
351 char c; | |
352 | |
353 if (max >= MAX_NR_TOKEN) { | |
361 | 354 printf("get_token(): max >= MAX_NR_TOKEN!"); |
328 | 355 goto out_eof; |
356 } | |
357 | |
358 memset(token, 0x00, sizeof(*token) * max); | |
359 | |
360 if (read_nextline) { | |
361 if (!fgets(line, MAX_LINE_LEN, fp)) | |
362 goto out_eof; | |
363 line_pos = 0; | |
364 ++line_num; | |
365 read_nextline = 0; | |
366 } | |
367 for (i = 0; i < max; i++) { | |
368 while (isspace(line[line_pos])) | |
369 ++line_pos; | |
370 if (line[line_pos] == '\0' || line[line_pos] == '#' || | |
371 line[line_pos] == ';') { | |
372 read_nextline = 1; | |
373 if (i >= min) | |
374 goto out_ok; | |
375 goto out_eol; | |
376 } | |
377 token[i] = line + line_pos; | |
378 c = line[line_pos]; | |
379 if (c == '"' || c == '\'') { | |
380 token[i]++; | |
381 while (line[++line_pos] != c && line[line_pos]) | |
382 /* NOTHING */; | |
383 } else { | |
384 for (/* NOTHING */; !isspace(line[line_pos]) && | |
385 line[line_pos]; line_pos++) | |
386 /* NOTHING */; | |
387 } | |
388 if (!line[line_pos]) { | |
389 read_nextline = 1; | |
390 if (i >= min - 1) | |
391 goto out_ok; | |
392 goto out_eol; | |
393 } | |
394 line[line_pos] = '\0'; | |
395 line_pos++; | |
396 } | |
397 out_ok: | |
398 return i; | |
399 out_eof: | |
400 return RET_EOF; | |
401 out_eol: | |
402 return RET_EOL; | |
403 } | |
404 | |
405 static codecs_t *video_codecs=NULL; | |
406 static codecs_t *audio_codecs=NULL; | |
407 static int nr_vcodecs = 0; | |
408 static int nr_acodecs = 0; | |
409 | |
410 codecs_t **parse_codec_cfg(char *cfgfile) | |
411 { | |
412 codecs_t *codec = NULL; // current codec | |
413 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs | |
414 static codecs_t *ret_codecs[2] = {NULL,NULL}; | |
335 | 415 char *endptr; // strtoul()... |
328 | 416 int *nr_codecsp; |
417 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ | |
297 | 418 int tmp, i; |
419 | |
420 #ifdef DEBUG | |
421 assert(cfgfile != NULL); | |
422 #endif | |
423 | |
361 | 424 printf("Reading %s: ", cfgfile); |
297 | 425 |
301 | 426 if ((fp = fopen(cfgfile, "r")) == NULL) { |
328 | 427 printf("can't open '%s': %s\n", cfgfile, strerror(errno)); |
297 | 428 return NULL; |
429 } | |
430 | |
301 | 431 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { |
361 | 432 printf("can't get memory for 'line': %s\n", strerror(errno)); |
297 | 433 return NULL; |
434 } | |
435 | |
328 | 436 /* |
437 * check if the cfgfile starts with 'audiocodec' or | |
438 * with 'videocodec' | |
439 */ | |
440 while ((tmp = get_token(1, 1)) == RET_EOL) | |
441 /* NOTHING */; | |
361 | 442 if (tmp == RET_EOF) |
443 goto out; | |
444 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) | |
328 | 445 goto loop_enter; |
361 | 446 goto err_out_parse_error; |
328 | 447 |
319 | 448 while ((tmp = get_token(1, 1)) != RET_EOF) { |
297 | 449 if (tmp == RET_EOL) |
450 continue; | |
328 | 451 if (!strcmp(token[0], "audiocodec") || |
452 !strcmp(token[0], "videocodec")) { | |
453 if (!validate_codec(codec, codec_type)) | |
454 goto err_out_not_valid; | |
455 loop_enter: | |
456 if (*token[0] == 'v') { | |
457 codec_type = TYPE_VIDEO; | |
458 nr_codecsp = &nr_vcodecs; | |
459 codecsp = &video_codecs; | |
460 } else if (*token[0] == 'a') { | |
461 codec_type = TYPE_AUDIO; | |
462 nr_codecsp = &nr_acodecs; | |
463 codecsp = &audio_codecs; | |
361 | 464 #ifdef DEBUG |
328 | 465 } else { |
361 | 466 printf("picsba\n"); |
328 | 467 goto err_out; |
361 | 468 #endif |
328 | 469 } |
470 if (!(*codecsp = (codecs_t *) realloc(*codecsp, | |
332 | 471 sizeof(codecs_t) * (*nr_codecsp + 2)))) { |
361 | 472 printf("can't realloc '*codecsp': %s\n", strerror(errno)); |
300 | 473 goto err_out; |
474 } | |
328 | 475 codec=*codecsp + *nr_codecsp; |
476 ++*nr_codecsp; | |
300 | 477 memset(codec,0,sizeof(codecs_t)); |
478 memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); | |
479 memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); | |
480 | |
319 | 481 if (get_token(1, 1) < 0) |
328 | 482 goto err_out_parse_error; |
483 for (i = 0; i < *nr_codecsp - 1; i++) { | |
484 if (!strcmp(token[0], (*codecsp)[i].name)) { | |
361 | 485 printf("codec name '%s' isn't unique", token[0]); |
486 goto err_out_print_linenum; | |
319 | 487 } |
488 } | |
328 | 489 if (!(codec->name = strdup(token[0]))) { |
361 | 490 printf("can't strdup -> 'name': %s\n", strerror(errno)); |
328 | 491 goto err_out; |
492 } | |
319 | 493 } else if (!strcmp(token[0], "info")) { |
328 | 494 if (codec->info || get_token(1, 1) < 0) |
495 goto err_out_parse_error; | |
496 if (!(codec->info = strdup(token[0]))) { | |
361 | 497 printf("can't strdup -> 'info': %s\n", strerror(errno)); |
328 | 498 goto err_out; |
499 } | |
319 | 500 } else if (!strcmp(token[0], "comment")) { |
501 if (get_token(1, 1) < 0) | |
328 | 502 goto err_out_parse_error; |
361 | 503 add_comment(token[0], &codec->comment); |
319 | 504 } else if (!strcmp(token[0], "fourcc")) { |
505 if (get_token(1, 2) < 0) | |
328 | 506 goto err_out_parse_error; |
319 | 507 if (!add_to_fourcc(token[0], token[1], |
300 | 508 codec->fourcc, |
509 codec->fourccmap)) | |
361 | 510 goto err_out_print_linenum; |
319 | 511 } else if (!strcmp(token[0], "format")) { |
512 if (get_token(1, 1) < 0) | |
328 | 513 goto err_out_parse_error; |
319 | 514 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap)) |
361 | 515 goto err_out_print_linenum; |
319 | 516 } else if (!strcmp(token[0], "driver")) { |
517 if (get_token(1, 1) < 0) | |
328 | 518 goto err_out_parse_error; |
1293 | 519 if ((codec->driver = get_driver(token[0],codec_type))<0) |
361 | 520 goto err_out_parse_error; |
319 | 521 } else if (!strcmp(token[0], "dll")) { |
522 if (get_token(1, 1) < 0) | |
328 | 523 goto err_out_parse_error; |
524 if (!(codec->dll = strdup(token[0]))) { | |
361 | 525 printf("can't strdup -> 'dll': %s\n", strerror(errno)); |
328 | 526 goto err_out; |
527 } | |
319 | 528 } else if (!strcmp(token[0], "guid")) { |
328 | 529 if (get_token(11, 11) < 0) |
530 goto err_out_parse_error; | |
335 | 531 codec->guid.f1=strtoul(token[0],&endptr,0); |
361 | 532 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
533 *endptr != '\0') | |
335 | 534 goto err_out_parse_error; |
535 codec->guid.f2=strtoul(token[1],&endptr,0); | |
361 | 536 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
537 *endptr != '\0') | |
335 | 538 goto err_out_parse_error; |
539 codec->guid.f3=strtoul(token[2],&endptr,0); | |
361 | 540 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
541 *endptr != '\0') | |
335 | 542 goto err_out_parse_error; |
543 for (i = 0; i < 8; i++) { | |
544 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); | |
361 | 545 if ((*endptr != ',' || *(endptr + 1) != '\0') && |
546 *endptr != '\0') | |
328 | 547 goto err_out_parse_error; |
297 | 548 } |
319 | 549 } else if (!strcmp(token[0], "out")) { |
550 if (get_token(1, 2) < 0) | |
328 | 551 goto err_out_parse_error; |
319 | 552 if (!add_to_out(token[0], token[1], codec->outfmt, |
300 | 553 codec->outflags)) |
361 | 554 goto err_out_print_linenum; |
319 | 555 } else if (!strcmp(token[0], "flags")) { |
556 if (get_token(1, 1) < 0) | |
328 | 557 goto err_out_parse_error; |
321 | 558 if (!strcmp(token[0], "seekable")) |
559 codec->flags |= CODECS_FLAG_SEEKABLE; | |
560 else | |
328 | 561 goto err_out_parse_error; |
319 | 562 } else if (!strcmp(token[0], "status")) { |
563 if (get_token(1, 1) < 0) | |
328 | 564 goto err_out_parse_error; |
332 | 565 if (!strcasecmp(token[0], "working")) |
316 | 566 codec->status = CODECS_STATUS_WORKING; |
332 | 567 else if (!strcasecmp(token[0], "crashing")) |
316 | 568 codec->status = CODECS_STATUS_NOT_WORKING; |
332 | 569 else if (!strcasecmp(token[0], "untested")) |
316 | 570 codec->status = CODECS_STATUS_UNTESTED; |
332 | 571 else if (!strcasecmp(token[0], "buggy")) |
316 | 572 codec->status = CODECS_STATUS_PROBLEMS; |
573 else | |
328 | 574 goto err_out_parse_error; |
361 | 575 } else if (!strcmp(token[0], "cpuflags")) { |
576 if (get_token(1, 1) < 0) | |
577 goto err_out_parse_error; | |
578 if (!(codec->cpuflags = get_cpuflags(token[0]))) | |
579 goto err_out_parse_error; | |
3667
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
580 } else if (!strcasecmp(token[0], "priority")) { |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
581 if (get_token(1, 1) < 0) |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
582 goto err_out_parse_error; |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
583 //printf("\n\n!!!cfg-parse: priority %s (%d) found!!!\n\n", token[0], atoi(token[0])); // ::atmos |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3643
diff
changeset
|
584 codec->priority = atoi(token[0]); |
297 | 585 } else |
328 | 586 goto err_out_parse_error; |
297 | 587 } |
328 | 588 if (!validate_codec(codec, codec_type)) |
589 goto err_out_not_valid; | |
361 | 590 printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs); |
895 | 591 if(video_codecs) video_codecs[nr_vcodecs].name = NULL; |
592 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL; | |
328 | 593 ret_codecs[0] = video_codecs; |
594 ret_codecs[1] = audio_codecs; | |
297 | 595 out: |
596 free(line); | |
597 fclose(fp); | |
328 | 598 return ret_codecs; |
599 err_out_parse_error: | |
361 | 600 printf("parse error"); |
601 err_out_print_linenum: | |
297 | 602 PRINT_LINENUM; |
603 err_out: | |
328 | 604 if (audio_codecs) |
605 free(audio_codecs); | |
606 if (video_codecs) | |
607 free(video_codecs); | |
608 free(line); | |
609 free(fp); | |
610 return NULL; | |
611 err_out_not_valid: | |
3408 | 612 printf("codec is not defined correctly"); |
361 | 613 goto err_out_print_linenum; |
297 | 614 } |
615 | |
332 | 616 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, |
617 codecs_t *start) | |
328 | 618 { |
332 | 619 return find_codec(fourcc, fourccmap, start, 1); |
328 | 620 } |
621 | |
332 | 622 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, |
623 codecs_t *start) | |
328 | 624 { |
332 | 625 return find_codec(fourcc, fourccmap, start, 0); |
328 | 626 } |
627 | |
332 | 628 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, |
629 codecs_t *start, int audioflag) | |
328 | 630 { |
631 int i, j; | |
632 codecs_t *c; | |
633 | |
628 | 634 #if 0 |
332 | 635 if (start) { |
636 for (/* NOTHING */; start->name; start++) { | |
637 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
638 if (start->fourcc[j] == fourcc) { | |
639 if (fourccmap) | |
640 *fourccmap = start->fourccmap[j]; | |
641 return start; | |
642 } | |
643 } | |
644 } | |
628 | 645 } else |
646 #endif | |
647 { | |
332 | 648 if (audioflag) { |
649 i = nr_acodecs; | |
650 c = audio_codecs; | |
651 } else { | |
652 i = nr_vcodecs; | |
653 c = video_codecs; | |
654 } | |
895 | 655 if(!i) return NULL; |
332 | 656 for (/* NOTHING */; i--; c++) { |
628 | 657 if(start && c<=start) continue; |
332 | 658 for (j = 0; j < CODECS_MAX_FOURCC; j++) { |
1391 | 659 if (c->fourcc[j]==fourcc || c->driver==0) { |
332 | 660 if (fourccmap) |
661 *fourccmap = c->fourccmap[j]; | |
662 return c; | |
663 } | |
328 | 664 } |
665 } | |
666 } | |
667 return NULL; | |
303 | 668 } |
669 | |
1983 | 670 void list_codecs(int audioflag){ |
2050 | 671 int i; |
1983 | 672 codecs_t *c; |
673 | |
674 if (audioflag) { | |
675 i = nr_acodecs; | |
676 c = audio_codecs; | |
1984 | 677 printf("ac: afm: status: info: [lib/dll]\n"); |
1983 | 678 } else { |
679 i = nr_vcodecs; | |
680 c = video_codecs; | |
1984 | 681 printf("vc: vfm: status: info: [lib/dll]\n"); |
1983 | 682 } |
2050 | 683 if(!i) return; |
1983 | 684 for (/* NOTHING */; i--; c++) { |
1984 | 685 char* s="unknown "; |
686 switch(c->status){ | |
687 case CODECS_STATUS_WORKING: s="working ";break; | |
688 case CODECS_STATUS_PROBLEMS: s="problems";break; | |
689 case CODECS_STATUS_NOT_WORKING: s="crashing";break; | |
690 case CODECS_STATUS_UNTESTED: s="untested";break; | |
691 } | |
1983 | 692 if(c->dll) |
1984 | 693 printf("%-10s%2d %s %s [%s]\n",c->name,c->driver,s,c->info,c->dll); |
1983 | 694 else |
1984 | 695 printf("%-10s%2d %s %s\n",c->name,c->driver,s,c->info); |
1983 | 696 |
697 } | |
698 | |
699 } | |
700 | |
701 | |
702 | |
607 | 703 #ifdef CODECS2HTML |
704 | |
705 void wrapline(FILE *f2,char *s){ | |
706 int c; | |
707 if(!s){ | |
708 fprintf(f2,"-"); | |
709 return; | |
710 } | |
711 while((c=*s++)){ | |
712 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); | |
713 } | |
714 } | |
715 | |
716 void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ | |
717 int c,d; | |
718 while((c=fgetc(f1))>=0){ | |
719 if(c!='%'){ | |
720 fputc(c,f2); | |
721 continue; | |
722 } | |
723 d=fgetc(f1); | |
724 | |
725 switch(d){ | |
726 case '.': | |
613 | 727 return; // end of section |
607 | 728 case 'n': |
729 wrapline(f2,codec->name); break; | |
730 case 'i': | |
731 wrapline(f2,codec->info); break; | |
732 case 'c': | |
733 wrapline(f2,codec->comment); break; | |
734 case 'd': | |
735 wrapline(f2,codec->dll); break; | |
736 case 'D': | |
737 fprintf(f2,"%c",codec->driver==dshow?'+':'-'); break; | |
738 case 'F': | |
739 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
|
740 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
|
741 fprintf(f2,"%s%.4s",d?"<br>":"",(codec->fourcc[d]==0xFFFFFFFF || codec->fourcc[d]<0x20202020)?!d?"-":"":(char*) &codec->fourcc[d]); |
607 | 742 break; |
743 case 'f': | |
744 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
745 if(codec->fourcc[d]!=0xFFFFFFFF) | |
746 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]); | |
747 break; | |
748 case 'Y': | |
749 for(d=0;d<CODECS_MAX_OUTFMT;d++) | |
750 if(codec->outfmt[d]!=0xFFFFFFFF){ | |
751 for (c=0; fmt_table[c].name; c++) | |
752 if(fmt_table[c].num==codec->outfmt[d]) break; | |
753 if(fmt_table[c].name) | |
754 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name); | |
755 } | |
756 break; | |
757 default: | |
758 fputc(c,f2); | |
759 fputc(d,f2); | |
760 } | |
761 } | |
762 | |
763 } | |
764 | |
765 void skiphtml(FILE *f1){ | |
766 int c,d; | |
767 while((c=fgetc(f1))>=0){ | |
768 if(c!='%'){ | |
769 continue; | |
770 } | |
771 d=fgetc(f1); | |
772 if(d=='.') return; // end of section | |
773 } | |
774 } | |
775 | |
776 int main(void) | |
777 { | |
778 codecs_t **codecs, *cl; | |
779 FILE *f1; | |
780 FILE *f2; | |
781 int c,d,i; | |
782 int pos; | |
783 int section=-1; | |
784 int nr_codecs; | |
785 int win32=-1; | |
786 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
|
787 int win32ex=-1; |
607 | 788 |
1614 | 789 if (!(codecs = parse_codec_cfg("etc/codecs.conf"))) |
607 | 790 return 0; |
791 if (!codecs[0]) | |
792 printf("no videoconfig.\n"); | |
793 if (!codecs[1]) | |
794 printf("no audioconfig.\n"); | |
795 | |
796 f1=fopen("DOCS/codecs-in.html","rb"); if(!f1) exit(1); | |
1689 | 797 f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); |
607 | 798 |
799 while((c=fgetc(f1))>=0){ | |
800 if(c!='%'){ | |
801 fputc(c,f2); | |
802 continue; | |
803 } | |
804 d=fgetc(f1); | |
805 if(d>='0' && d<='9'){ | |
806 // begin section | |
807 section=d-'0'; | |
808 printf("BEGIN %d\n",section); | |
809 if(section>=5){ | |
810 // audio | |
811 cl = codecs[1]; | |
812 nr_codecs = nr_acodecs; | |
813 dshow=7;win32=4; | |
814 } else { | |
815 // video | |
816 cl = codecs[0]; | |
817 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
|
818 dshow=4;win32=2;win32ex=6; |
607 | 819 } |
820 pos=ftell(f1); | |
821 for(i=0;i<nr_codecs;i++){ | |
822 fseek(f1,pos,SEEK_SET); | |
823 switch(section){ | |
824 case 0: | |
825 case 5: | |
826 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
|
827 if(!(cl[i].driver==win32 || cl[i].driver==dshow || cl[i].driver==win32ex)) |
607 | 828 parsehtml(f1,f2,&cl[i],section,dshow); |
829 break; | |
830 case 1: | |
831 case 6: | |
832 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
|
833 if(cl[i].driver==win32 || cl[i].driver==dshow || cl[i].driver==win32ex) |
607 | 834 parsehtml(f1,f2,&cl[i],section,dshow); |
835 break; | |
836 case 2: | |
837 case 7: | |
838 if(cl[i].status==CODECS_STATUS_PROBLEMS) | |
839 parsehtml(f1,f2,&cl[i],section,dshow); | |
840 break; | |
841 case 3: | |
842 case 8: | |
843 if(cl[i].status==CODECS_STATUS_NOT_WORKING) | |
844 parsehtml(f1,f2,&cl[i],section,dshow); | |
845 break; | |
846 case 4: | |
847 case 9: | |
848 if(cl[i].status==CODECS_STATUS_UNTESTED) | |
849 parsehtml(f1,f2,&cl[i],section,dshow); | |
850 break; | |
851 default: | |
852 printf("Warning! unimplemented section: %d\n",section); | |
853 } | |
854 } | |
855 fseek(f1,pos,SEEK_SET); | |
856 skiphtml(f1); | |
857 //void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){ | |
858 | |
859 continue; | |
860 } | |
861 fputc(c,f2); | |
862 fputc(d,f2); | |
863 } | |
864 | |
865 fclose(f2); | |
866 fclose(f1); | |
867 return 0; | |
868 } | |
869 | |
870 #endif | |
871 | |
297 | 872 #ifdef TESTING |
873 int main(void) | |
874 { | |
328 | 875 codecs_t **codecs, *c; |
876 int i,j, nr_codecs, state; | |
297 | 877 |
1614 | 878 if (!(codecs = parse_codec_cfg("etc/codecs.conf"))) |
319 | 879 return 0; |
328 | 880 if (!codecs[0]) |
881 printf("no videoconfig.\n"); | |
882 if (!codecs[1]) | |
883 printf("no audioconfig.\n"); | |
884 | |
885 printf("videocodecs:\n"); | |
886 c = codecs[0]; | |
887 nr_codecs = nr_vcodecs; | |
888 state = 0; | |
889 next: | |
890 if (c) { | |
891 printf("number of codecs: %d\n", nr_codecs); | |
892 for(i=0;i<nr_codecs;i++, c++){ | |
893 printf("\n============== codec %02d ===============\n",i); | |
894 printf("name='%s'\n",c->name); | |
895 printf("info='%s'\n",c->info); | |
896 printf("comment='%s'\n",c->comment); | |
897 printf("dll='%s'\n",c->dll); | |
361 | 898 printf("flags=%X driver=%d status=%d cpuflags=%d\n", |
899 c->flags, c->driver, c->status, c->cpuflags); | |
300 | 900 |
328 | 901 for(j=0;j<CODECS_MAX_FOURCC;j++){ |
902 if(c->fourcc[j]!=0xFFFFFFFF){ | |
361 | 903 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]); |
328 | 904 } |
905 } | |
906 | |
907 for(j=0;j<CODECS_MAX_OUTFMT;j++){ | |
908 if(c->outfmt[j]!=0xFFFFFFFF){ | |
361 | 909 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]); |
328 | 910 } |
911 } | |
300 | 912 |
328 | 913 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); |
914 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); | |
915 printf("\n"); | |
300 | 916 |
328 | 917 |
918 } | |
919 } | |
920 if (!state) { | |
921 printf("audiocodecs:\n"); | |
922 c = codecs[1]; | |
923 nr_codecs = nr_acodecs; | |
924 state = 1; | |
925 goto next; | |
926 } | |
297 | 927 return 0; |
928 } | |
929 | |
930 #endif |