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