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