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