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