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