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