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