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