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