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