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