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