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