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