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