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