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