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
|
297
|
9 #include <stdio.h>
|
|
10 #include <stdlib.h>
|
|
11 #include <fcntl.h>
|
|
12 #include <unistd.h>
|
|
13 #include <errno.h>
|
|
14 #include <ctype.h>
|
|
15 #include <assert.h>
|
|
16 #include <string.h>
|
|
17
|
408
|
18 #include "libvo/img_format.h"
|
297
|
19 #include "codec-cfg.h"
|
|
20
|
361
|
21 #define PRINT_LINENUM printf(" at line %d\n", line_num)
|
328
|
22
|
319
|
23 #define MAX_NR_TOKEN 16
|
297
|
24
|
|
25 #define MAX_LINE_LEN 1000
|
|
26
|
|
27 #define RET_EOF -1
|
|
28 #define RET_EOL -2
|
|
29
|
328
|
30 #define TYPE_VIDEO 0
|
|
31 #define TYPE_AUDIO 1
|
297
|
32
|
303
|
33 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc,
|
297
|
34 unsigned int *map)
|
|
35 {
|
319
|
36 int i, j, freeslots;
|
297
|
37 char **aliasp;
|
319
|
38 unsigned int tmp;
|
|
39
|
|
40 /* find first unused slot */
|
|
41 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
|
|
42 /* NOTHING */;
|
|
43 freeslots = CODECS_MAX_FOURCC - i;
|
|
44 if (!freeslots)
|
328
|
45 goto err_out_too_many;
|
319
|
46
|
|
47 aliasp = (alias) ? &alias : &s;
|
|
48 do {
|
|
49 tmp = *((unsigned int *) s);
|
|
50 for (j = 0; j < i; j++)
|
|
51 if (tmp == fourcc[j])
|
328
|
52 goto err_out_duplicated;
|
319
|
53 fourcc[i] = tmp;
|
|
54 map[i] = *((unsigned int *) (*aliasp));
|
|
55 s += 4;
|
|
56 i++;
|
|
57 } while ((*(s++) == ',') && --freeslots);
|
|
58
|
|
59 if (!freeslots)
|
328
|
60 goto err_out_too_many;
|
319
|
61 if (*(--s) != '\0')
|
361
|
62 goto err_out_parse_error;
|
319
|
63 return 1;
|
328
|
64 err_out_duplicated:
|
361
|
65 printf("duplicated fourcc/format");
|
319
|
66 return 0;
|
328
|
67 err_out_too_many:
|
361
|
68 printf("too many fourcc/format...");
|
|
69 return 0;
|
|
70 err_out_parse_error:
|
|
71 printf("parse error");
|
319
|
72 return 0;
|
|
73 }
|
|
74
|
|
75 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap)
|
|
76 {
|
|
77 int i, j;
|
361
|
78 char *endptr;
|
297
|
79
|
|
80 /* find first unused slot */
|
|
81 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
|
|
82 /* NOTHING */;
|
|
83 if (i == CODECS_MAX_FOURCC) {
|
361
|
84 printf("too many fourcc/format...");
|
297
|
85 return 0;
|
|
86 }
|
|
87
|
361
|
88 fourcc[i]=fourccmap[i]=strtoul(s,&endptr,0);
|
|
89 if (*endptr != '\0') {
|
|
90 printf("parse error");
|
|
91 return 0;
|
|
92 }
|
319
|
93 for (j = 0; j < i; j++)
|
|
94 if (fourcc[j] == fourcc[i]) {
|
361
|
95 printf("duplicated fourcc/format");
|
319
|
96 return 0;
|
|
97 }
|
300
|
98
|
297
|
99 return 1;
|
|
100 }
|
|
101
|
408
|
102 static struct {
|
|
103 const char *name;
|
|
104 const unsigned int num;
|
|
105 } fmt_table[] = {
|
415
|
106 {"YV12", IMGFMT_YV12},
|
|
107 {"I420", IMGFMT_I420},
|
|
108 {"IYUV", IMGFMT_IYUV},
|
408
|
109
|
415
|
110 {"YUY2", IMGFMT_YUY2},
|
|
111 {"UYVY", IMGFMT_UYVY},
|
|
112 {"YVYU", IMGFMT_YVYU},
|
408
|
113
|
415
|
114 {"RGB8", IMGFMT_RGB|8},
|
|
115 {"RGB15", IMGFMT_RGB|15},
|
|
116 {"RGB16", IMGFMT_RGB|16},
|
|
117 {"RGB24", IMGFMT_RGB|24},
|
|
118 {"RGB32", IMGFMT_RGB|32},
|
|
119 {"BGR8", IMGFMT_BGR|8},
|
|
120 {"BGR15", IMGFMT_BGR|15},
|
|
121 {"BGR16", IMGFMT_BGR|16},
|
|
122 {"BGR24", IMGFMT_BGR|24},
|
|
123 {"BGR32", IMGFMT_BGR|32},
|
|
124 {NULL, 0}
|
297
|
125 };
|
408
|
126
|
607
|
127
|
|
128 static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt,
|
|
129 unsigned char *outflags)
|
|
130 {
|
|
131
|
299
|
132 static char *flagstr[] = {
|
|
133 "flip",
|
|
134 "noflip",
|
|
135 "yuvhack",
|
|
136 NULL
|
|
137 };
|
|
138
|
319
|
139 int i, j, freeslots;
|
297
|
140 unsigned char flags;
|
|
141
|
|
142 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++)
|
|
143 /* NOTHING */;
|
319
|
144 freeslots = CODECS_MAX_OUTFMT - i;
|
|
145 if (!freeslots)
|
328
|
146 goto err_out_too_many;
|
297
|
147
|
319
|
148 flags = 0;
|
361
|
149 if(sflags) {
|
|
150 do {
|
|
151 for (j = 0; flagstr[j] != NULL; j++)
|
|
152 if (!strncmp(sflags, flagstr[j],
|
|
153 strlen(flagstr[j])))
|
|
154 break;
|
|
155 if (flagstr[j] == NULL)
|
|
156 goto err_out_parse_error;
|
|
157 flags|=(1<<j);
|
|
158 sflags+=strlen(flagstr[j]);
|
|
159 } while (*(sflags++) == ',');
|
|
160
|
|
161 if (*(--sflags) != '\0')
|
|
162 goto err_out_parse_error;
|
|
163 }
|
297
|
164
|
|
165 do {
|
408
|
166 for (j = 0; fmt_table[j].name != NULL; j++)
|
|
167 if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name)))
|
297
|
168 break;
|
408
|
169 if (fmt_table[j].name == NULL)
|
361
|
170 goto err_out_parse_error;
|
408
|
171 outfmt[i] = fmt_table[j].num;
|
297
|
172 outflags[i] = flags;
|
299
|
173 ++i;
|
408
|
174 sfmt+=strlen(fmt_table[j].name);
|
319
|
175 } while ((*(sfmt++) == ',') && --freeslots);
|
|
176
|
|
177 if (!freeslots)
|
328
|
178 goto err_out_too_many;
|
319
|
179
|
361
|
180 if (*(--sfmt) != '\0')
|
|
181 goto err_out_parse_error;
|
299
|
182
|
297
|
183 return 1;
|
328
|
184 err_out_too_many:
|
361
|
185 printf("too many out...");
|
|
186 return 0;
|
|
187 err_out_parse_error:
|
|
188 printf("parse error");
|
319
|
189 return 0;
|
297
|
190 }
|
|
191
|
303
|
192 static short get_driver(char *s,int audioflag)
|
297
|
193 {
|
301
|
194 static char *audiodrv[] = {
|
|
195 "mp3lib",
|
|
196 "pcm",
|
|
197 "libac3",
|
|
198 "acm",
|
|
199 "alaw",
|
|
200 "msgsm",
|
|
201 "dshow",
|
401
|
202 "dvdpcm",
|
301
|
203 NULL
|
|
204 };
|
|
205 static char *videodrv[] = {
|
|
206 "libmpeg2",
|
|
207 "vfw",
|
|
208 "odivx",
|
|
209 "dshow",
|
|
210 NULL
|
|
211 };
|
|
212 char **drv=audioflag?audiodrv:videodrv;
|
|
213 int i;
|
|
214
|
|
215 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i+1;
|
|
216
|
297
|
217 return 0;
|
|
218 }
|
|
219
|
328
|
220 static int validate_codec(codecs_t *c, int type)
|
319
|
221 {
|
329
|
222 #if 0
|
328
|
223 int i;
|
|
224
|
|
225 for (i = 0; i < strlen(c->name) && isalnum(c->name[i]); i++)
|
|
226 /* NOTHING */;
|
|
227 if (i < strlen(c->name)) {
|
|
228 printf("\ncodec(%s)->name is not valid!\n", c->name);
|
|
229 return 0;
|
|
230 }
|
|
231 #warning codec->info = codec->name; ez ok, vagy strdup()?
|
|
232 if (!c->info)
|
|
233 c->info = c->name;
|
|
234 if (c->fourcc[0] == 0xffffffff) {
|
|
235 printf("\ncodec(%s) does not have fourcc/format!\n", c->name);
|
|
236 return 0;
|
|
237 }
|
|
238 if (!c->driver) {
|
|
239 printf("\ncodec(%s) does not have a driver!\n", c->name);
|
|
240 return 0;
|
|
241 }
|
|
242 #warning codec->driver == 4;... <- ezt nem kellene belehegeszteni...
|
|
243 #warning HOL VANNAK DEFINIALVA????????????
|
|
244 if (!c->dll && (c->driver == 4 ||
|
|
245 (c->driver == 2 && type == TYPE_VIDEO))) {
|
|
246 printf("\ncodec(%s) needs a 'dll'!\n", c->name);
|
|
247 return 0;
|
|
248 }
|
|
249 #warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg?
|
|
250 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4)
|
|
251
|
|
252 if (type == TYPE_VIDEO)
|
|
253 if (c->outfmt[0] == 0xffffffff) {
|
|
254 printf("\ncodec(%s) needs an 'outfmt'!\n", c->name);
|
|
255 return 0;
|
|
256 }
|
329
|
257 #endif
|
319
|
258 return 1;
|
|
259 }
|
|
260
|
|
261 static int add_comment(char *s, char **d)
|
|
262 {
|
|
263 int pos;
|
|
264
|
|
265 if (!*d)
|
|
266 pos = 0;
|
|
267 else {
|
|
268 pos = strlen(*d);
|
|
269 (*d)[pos++] = '\n';
|
|
270 }
|
|
271 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) {
|
361
|
272 printf("can't allocate mem for comment. ");
|
319
|
273 return 0;
|
|
274 }
|
|
275 strcpy(*d + pos, s);
|
|
276 return 1;
|
|
277 }
|
297
|
278
|
361
|
279 static short get_cpuflags(char *s)
|
|
280 {
|
|
281 static char *flagstr[] = {
|
|
282 "mmx",
|
|
283 "sse",
|
|
284 "3dnow",
|
|
285 NULL
|
|
286 };
|
|
287 int i;
|
|
288 short flags = 0;
|
|
289
|
|
290 do {
|
|
291 for (i = 0; flagstr[i]; i++)
|
|
292 if (!strncmp(s, flagstr[i], strlen(flagstr[i])))
|
|
293 break;
|
|
294 if (!flagstr[i])
|
|
295 goto err_out_parse_error;
|
|
296 flags |= 1<<i;
|
|
297 s += strlen(flagstr[i]);
|
|
298 } while (*(s++) == ',');
|
|
299
|
|
300 if (*(--s) != '\0')
|
|
301 goto err_out_parse_error;
|
|
302
|
|
303 return flags;
|
|
304 err_out_parse_error:
|
|
305 return 0;
|
|
306 }
|
|
307
|
328
|
308 static FILE *fp;
|
|
309 static int line_num = 0;
|
|
310 static char *line;
|
|
311 static char *token[MAX_NR_TOKEN];
|
|
312
|
|
313 static int get_token(int min, int max)
|
297
|
314 {
|
328
|
315 static int read_nextline = 1;
|
|
316 static int line_pos;
|
|
317 int i;
|
|
318 char c;
|
|
319
|
|
320 if (max >= MAX_NR_TOKEN) {
|
361
|
321 printf("get_token(): max >= MAX_NR_TOKEN!");
|
328
|
322 goto out_eof;
|
|
323 }
|
|
324
|
|
325 memset(token, 0x00, sizeof(*token) * max);
|
|
326
|
|
327 if (read_nextline) {
|
|
328 if (!fgets(line, MAX_LINE_LEN, fp))
|
|
329 goto out_eof;
|
|
330 line_pos = 0;
|
|
331 ++line_num;
|
|
332 read_nextline = 0;
|
|
333 }
|
|
334 for (i = 0; i < max; i++) {
|
|
335 while (isspace(line[line_pos]))
|
|
336 ++line_pos;
|
|
337 if (line[line_pos] == '\0' || line[line_pos] == '#' ||
|
|
338 line[line_pos] == ';') {
|
|
339 read_nextline = 1;
|
|
340 if (i >= min)
|
|
341 goto out_ok;
|
|
342 goto out_eol;
|
|
343 }
|
|
344 token[i] = line + line_pos;
|
|
345 c = line[line_pos];
|
|
346 if (c == '"' || c == '\'') {
|
|
347 token[i]++;
|
|
348 while (line[++line_pos] != c && line[line_pos])
|
|
349 /* NOTHING */;
|
|
350 } else {
|
|
351 for (/* NOTHING */; !isspace(line[line_pos]) &&
|
|
352 line[line_pos]; line_pos++)
|
|
353 /* NOTHING */;
|
|
354 }
|
|
355 if (!line[line_pos]) {
|
|
356 read_nextline = 1;
|
|
357 if (i >= min - 1)
|
|
358 goto out_ok;
|
|
359 goto out_eol;
|
|
360 }
|
|
361 line[line_pos] = '\0';
|
|
362 line_pos++;
|
|
363 }
|
|
364 out_ok:
|
|
365 return i;
|
|
366 out_eof:
|
|
367 return RET_EOF;
|
|
368 out_eol:
|
|
369 return RET_EOL;
|
|
370 }
|
|
371
|
|
372 static codecs_t *video_codecs=NULL;
|
|
373 static codecs_t *audio_codecs=NULL;
|
|
374 static int nr_vcodecs = 0;
|
|
375 static int nr_acodecs = 0;
|
|
376
|
|
377 codecs_t **parse_codec_cfg(char *cfgfile)
|
|
378 {
|
|
379 codecs_t *codec = NULL; // current codec
|
|
380 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs
|
|
381 static codecs_t *ret_codecs[2] = {NULL,NULL};
|
335
|
382 char *endptr; // strtoul()...
|
328
|
383 int *nr_codecsp;
|
|
384 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */
|
297
|
385 int tmp, i;
|
|
386
|
|
387 #ifdef DEBUG
|
|
388 assert(cfgfile != NULL);
|
|
389 #endif
|
|
390
|
361
|
391 printf("Reading %s: ", cfgfile);
|
297
|
392
|
301
|
393 if ((fp = fopen(cfgfile, "r")) == NULL) {
|
328
|
394 printf("can't open '%s': %s\n", cfgfile, strerror(errno));
|
297
|
395 return NULL;
|
|
396 }
|
|
397
|
301
|
398 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
|
361
|
399 printf("can't get memory for 'line': %s\n", strerror(errno));
|
297
|
400 return NULL;
|
|
401 }
|
|
402
|
328
|
403 /*
|
|
404 * check if the cfgfile starts with 'audiocodec' or
|
|
405 * with 'videocodec'
|
|
406 */
|
|
407 while ((tmp = get_token(1, 1)) == RET_EOL)
|
|
408 /* NOTHING */;
|
361
|
409 if (tmp == RET_EOF)
|
|
410 goto out;
|
|
411 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec"))
|
328
|
412 goto loop_enter;
|
361
|
413 goto err_out_parse_error;
|
328
|
414
|
319
|
415 while ((tmp = get_token(1, 1)) != RET_EOF) {
|
297
|
416 if (tmp == RET_EOL)
|
|
417 continue;
|
328
|
418 if (!strcmp(token[0], "audiocodec") ||
|
|
419 !strcmp(token[0], "videocodec")) {
|
|
420 if (!validate_codec(codec, codec_type))
|
|
421 goto err_out_not_valid;
|
|
422 loop_enter:
|
|
423 if (*token[0] == 'v') {
|
|
424 codec_type = TYPE_VIDEO;
|
|
425 nr_codecsp = &nr_vcodecs;
|
|
426 codecsp = &video_codecs;
|
|
427 } else if (*token[0] == 'a') {
|
|
428 codec_type = TYPE_AUDIO;
|
|
429 nr_codecsp = &nr_acodecs;
|
|
430 codecsp = &audio_codecs;
|
361
|
431 #ifdef DEBUG
|
328
|
432 } else {
|
361
|
433 printf("picsba\n");
|
328
|
434 goto err_out;
|
361
|
435 #endif
|
328
|
436 }
|
|
437 if (!(*codecsp = (codecs_t *) realloc(*codecsp,
|
332
|
438 sizeof(codecs_t) * (*nr_codecsp + 2)))) {
|
361
|
439 printf("can't realloc '*codecsp': %s\n", strerror(errno));
|
300
|
440 goto err_out;
|
|
441 }
|
328
|
442 codec=*codecsp + *nr_codecsp;
|
|
443 ++*nr_codecsp;
|
300
|
444 memset(codec,0,sizeof(codecs_t));
|
|
445 memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
|
|
446 memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
|
|
447
|
319
|
448 if (get_token(1, 1) < 0)
|
328
|
449 goto err_out_parse_error;
|
|
450 for (i = 0; i < *nr_codecsp - 1; i++) {
|
|
451 if (!strcmp(token[0], (*codecsp)[i].name)) {
|
361
|
452 printf("codec name '%s' isn't unique", token[0]);
|
|
453 goto err_out_print_linenum;
|
319
|
454 }
|
|
455 }
|
328
|
456 if (!(codec->name = strdup(token[0]))) {
|
361
|
457 printf("can't strdup -> 'name': %s\n", strerror(errno));
|
328
|
458 goto err_out;
|
|
459 }
|
319
|
460 } else if (!strcmp(token[0], "info")) {
|
328
|
461 if (codec->info || get_token(1, 1) < 0)
|
|
462 goto err_out_parse_error;
|
|
463 if (!(codec->info = strdup(token[0]))) {
|
361
|
464 printf("can't strdup -> 'info': %s\n", strerror(errno));
|
328
|
465 goto err_out;
|
|
466 }
|
319
|
467 } else if (!strcmp(token[0], "comment")) {
|
|
468 if (get_token(1, 1) < 0)
|
328
|
469 goto err_out_parse_error;
|
361
|
470 add_comment(token[0], &codec->comment);
|
319
|
471 } else if (!strcmp(token[0], "fourcc")) {
|
|
472 if (get_token(1, 2) < 0)
|
328
|
473 goto err_out_parse_error;
|
319
|
474 if (!add_to_fourcc(token[0], token[1],
|
300
|
475 codec->fourcc,
|
|
476 codec->fourccmap))
|
361
|
477 goto err_out_print_linenum;
|
319
|
478 } else if (!strcmp(token[0], "format")) {
|
|
479 if (get_token(1, 1) < 0)
|
328
|
480 goto err_out_parse_error;
|
319
|
481 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap))
|
361
|
482 goto err_out_print_linenum;
|
319
|
483 } else if (!strcmp(token[0], "driver")) {
|
|
484 if (get_token(1, 1) < 0)
|
328
|
485 goto err_out_parse_error;
|
361
|
486 if (!(codec->driver = get_driver(token[0],codec_type)))
|
|
487 goto err_out_parse_error;
|
319
|
488 } else if (!strcmp(token[0], "dll")) {
|
|
489 if (get_token(1, 1) < 0)
|
328
|
490 goto err_out_parse_error;
|
|
491 if (!(codec->dll = strdup(token[0]))) {
|
361
|
492 printf("can't strdup -> 'dll': %s\n", strerror(errno));
|
328
|
493 goto err_out;
|
|
494 }
|
319
|
495 } else if (!strcmp(token[0], "guid")) {
|
328
|
496 if (get_token(11, 11) < 0)
|
|
497 goto err_out_parse_error;
|
335
|
498 codec->guid.f1=strtoul(token[0],&endptr,0);
|
361
|
499 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
500 *endptr != '\0')
|
335
|
501 goto err_out_parse_error;
|
|
502 codec->guid.f2=strtoul(token[1],&endptr,0);
|
361
|
503 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
504 *endptr != '\0')
|
335
|
505 goto err_out_parse_error;
|
|
506 codec->guid.f3=strtoul(token[2],&endptr,0);
|
361
|
507 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
508 *endptr != '\0')
|
335
|
509 goto err_out_parse_error;
|
|
510 for (i = 0; i < 8; i++) {
|
|
511 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0);
|
361
|
512 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
513 *endptr != '\0')
|
328
|
514 goto err_out_parse_error;
|
297
|
515 }
|
319
|
516 } else if (!strcmp(token[0], "out")) {
|
|
517 if (get_token(1, 2) < 0)
|
328
|
518 goto err_out_parse_error;
|
319
|
519 if (!add_to_out(token[0], token[1], codec->outfmt,
|
300
|
520 codec->outflags))
|
361
|
521 goto err_out_print_linenum;
|
319
|
522 } else if (!strcmp(token[0], "flags")) {
|
|
523 if (get_token(1, 1) < 0)
|
328
|
524 goto err_out_parse_error;
|
321
|
525 if (!strcmp(token[0], "seekable"))
|
|
526 codec->flags |= CODECS_FLAG_SEEKABLE;
|
|
527 else
|
328
|
528 goto err_out_parse_error;
|
319
|
529 } else if (!strcmp(token[0], "status")) {
|
|
530 if (get_token(1, 1) < 0)
|
328
|
531 goto err_out_parse_error;
|
332
|
532 if (!strcasecmp(token[0], "working"))
|
316
|
533 codec->status = CODECS_STATUS_WORKING;
|
332
|
534 else if (!strcasecmp(token[0], "crashing"))
|
316
|
535 codec->status = CODECS_STATUS_NOT_WORKING;
|
332
|
536 else if (!strcasecmp(token[0], "untested"))
|
316
|
537 codec->status = CODECS_STATUS_UNTESTED;
|
332
|
538 else if (!strcasecmp(token[0], "buggy"))
|
316
|
539 codec->status = CODECS_STATUS_PROBLEMS;
|
|
540 else
|
328
|
541 goto err_out_parse_error;
|
361
|
542 } else if (!strcmp(token[0], "cpuflags")) {
|
|
543 if (get_token(1, 1) < 0)
|
|
544 goto err_out_parse_error;
|
|
545 if (!(codec->cpuflags = get_cpuflags(token[0])))
|
|
546 goto err_out_parse_error;
|
297
|
547 } else
|
328
|
548 goto err_out_parse_error;
|
297
|
549 }
|
328
|
550 if (!validate_codec(codec, codec_type))
|
|
551 goto err_out_not_valid;
|
361
|
552 printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs);
|
895
|
553 if(video_codecs) video_codecs[nr_vcodecs].name = NULL;
|
|
554 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL;
|
328
|
555 ret_codecs[0] = video_codecs;
|
|
556 ret_codecs[1] = audio_codecs;
|
297
|
557 out:
|
|
558 free(line);
|
|
559 fclose(fp);
|
328
|
560 return ret_codecs;
|
|
561 err_out_parse_error:
|
361
|
562 printf("parse error");
|
|
563 err_out_print_linenum:
|
297
|
564 PRINT_LINENUM;
|
|
565 err_out:
|
328
|
566 if (audio_codecs)
|
|
567 free(audio_codecs);
|
|
568 if (video_codecs)
|
|
569 free(video_codecs);
|
|
570 free(line);
|
|
571 free(fp);
|
|
572 return NULL;
|
|
573 err_out_not_valid:
|
361
|
574 printf("codec is not definied correctly");
|
|
575 goto err_out_print_linenum;
|
297
|
576 }
|
|
577
|
332
|
578 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
|
|
579 codecs_t *start)
|
328
|
580 {
|
332
|
581 return find_codec(fourcc, fourccmap, start, 1);
|
328
|
582 }
|
|
583
|
332
|
584 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap,
|
|
585 codecs_t *start)
|
328
|
586 {
|
332
|
587 return find_codec(fourcc, fourccmap, start, 0);
|
328
|
588 }
|
|
589
|
332
|
590 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,
|
|
591 codecs_t *start, int audioflag)
|
328
|
592 {
|
|
593 int i, j;
|
|
594 codecs_t *c;
|
|
595
|
628
|
596 #if 0
|
332
|
597 if (start) {
|
|
598 for (/* NOTHING */; start->name; start++) {
|
|
599 for (j = 0; j < CODECS_MAX_FOURCC; j++) {
|
|
600 if (start->fourcc[j] == fourcc) {
|
|
601 if (fourccmap)
|
|
602 *fourccmap = start->fourccmap[j];
|
|
603 return start;
|
|
604 }
|
|
605 }
|
|
606 }
|
628
|
607 } else
|
|
608 #endif
|
|
609 {
|
332
|
610 if (audioflag) {
|
|
611 i = nr_acodecs;
|
|
612 c = audio_codecs;
|
|
613 } else {
|
|
614 i = nr_vcodecs;
|
|
615 c = video_codecs;
|
|
616 }
|
895
|
617 if(!i) return NULL;
|
332
|
618 for (/* NOTHING */; i--; c++) {
|
628
|
619 if(start && c<=start) continue;
|
332
|
620 for (j = 0; j < CODECS_MAX_FOURCC; j++) {
|
|
621 if (c->fourcc[j] == fourcc) {
|
|
622 if (fourccmap)
|
|
623 *fourccmap = c->fourccmap[j];
|
|
624 return c;
|
|
625 }
|
328
|
626 }
|
|
627 }
|
|
628 }
|
|
629 return NULL;
|
303
|
630 }
|
|
631
|
607
|
632 #ifdef CODECS2HTML
|
|
633
|
|
634 void wrapline(FILE *f2,char *s){
|
|
635 int c;
|
|
636 if(!s){
|
|
637 fprintf(f2,"-");
|
|
638 return;
|
|
639 }
|
|
640 while((c=*s++)){
|
|
641 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2);
|
|
642 }
|
|
643 }
|
|
644
|
|
645 void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){
|
|
646 int c,d;
|
|
647 while((c=fgetc(f1))>=0){
|
|
648 if(c!='%'){
|
|
649 fputc(c,f2);
|
|
650 continue;
|
|
651 }
|
|
652 d=fgetc(f1);
|
|
653
|
|
654 switch(d){
|
|
655 case '.':
|
613
|
656 return; // end of section
|
607
|
657 case 'n':
|
|
658 wrapline(f2,codec->name); break;
|
|
659 case 'i':
|
|
660 wrapline(f2,codec->info); break;
|
|
661 case 'c':
|
|
662 wrapline(f2,codec->comment); break;
|
|
663 case 'd':
|
|
664 wrapline(f2,codec->dll); break;
|
|
665 case 'D':
|
|
666 fprintf(f2,"%c",codec->driver==dshow?'+':'-'); break;
|
|
667 case 'F':
|
|
668 for(d=0;d<CODECS_MAX_FOURCC;d++)
|
|
669 if(codec->fourcc[d]!=0xFFFFFFFF)
|
|
670 fprintf(f2,"%s%.4s",d?"<br>":"",codec->fourcc[d]<0x20202020?"-":(char*) &codec->fourcc[d]);
|
|
671 break;
|
|
672 case 'f':
|
|
673 for(d=0;d<CODECS_MAX_FOURCC;d++)
|
|
674 if(codec->fourcc[d]!=0xFFFFFFFF)
|
|
675 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]);
|
|
676 break;
|
|
677 case 'Y':
|
|
678 for(d=0;d<CODECS_MAX_OUTFMT;d++)
|
|
679 if(codec->outfmt[d]!=0xFFFFFFFF){
|
|
680 for (c=0; fmt_table[c].name; c++)
|
|
681 if(fmt_table[c].num==codec->outfmt[d]) break;
|
|
682 if(fmt_table[c].name)
|
|
683 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name);
|
|
684 }
|
|
685 break;
|
|
686 default:
|
|
687 fputc(c,f2);
|
|
688 fputc(d,f2);
|
|
689 }
|
|
690 }
|
|
691
|
|
692 }
|
|
693
|
|
694 void skiphtml(FILE *f1){
|
|
695 int c,d;
|
|
696 while((c=fgetc(f1))>=0){
|
|
697 if(c!='%'){
|
|
698 continue;
|
|
699 }
|
|
700 d=fgetc(f1);
|
|
701 if(d=='.') return; // end of section
|
|
702 }
|
|
703 }
|
|
704
|
|
705 int main(void)
|
|
706 {
|
|
707 codecs_t **codecs, *cl;
|
|
708 FILE *f1;
|
|
709 FILE *f2;
|
|
710 int c,d,i;
|
|
711 int pos;
|
|
712 int section=-1;
|
|
713 int nr_codecs;
|
|
714 int win32=-1;
|
|
715 int dshow=-1;
|
|
716
|
|
717 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
|
|
718 return 0;
|
|
719 if (!codecs[0])
|
|
720 printf("no videoconfig.\n");
|
|
721 if (!codecs[1])
|
|
722 printf("no audioconfig.\n");
|
|
723
|
|
724 f1=fopen("DOCS/codecs-in.html","rb"); if(!f1) exit(1);
|
|
725 f2=fopen("DOCS/codecs.html","wb"); if(!f2) exit(1);
|
|
726
|
|
727 while((c=fgetc(f1))>=0){
|
|
728 if(c!='%'){
|
|
729 fputc(c,f2);
|
|
730 continue;
|
|
731 }
|
|
732 d=fgetc(f1);
|
|
733 if(d>='0' && d<='9'){
|
|
734 // begin section
|
|
735 section=d-'0';
|
|
736 printf("BEGIN %d\n",section);
|
|
737 if(section>=5){
|
|
738 // audio
|
|
739 cl = codecs[1];
|
|
740 nr_codecs = nr_acodecs;
|
|
741 dshow=7;win32=4;
|
|
742 } else {
|
|
743 // video
|
|
744 cl = codecs[0];
|
|
745 nr_codecs = nr_vcodecs;
|
|
746 dshow=4;win32=2;
|
|
747 }
|
|
748 pos=ftell(f1);
|
|
749 for(i=0;i<nr_codecs;i++){
|
|
750 fseek(f1,pos,SEEK_SET);
|
|
751 switch(section){
|
|
752 case 0:
|
|
753 case 5:
|
|
754 if(cl[i].status==CODECS_STATUS_WORKING)
|
|
755 if(!(cl[i].driver==win32 || cl[i].driver==dshow))
|
|
756 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
757 break;
|
|
758 case 1:
|
|
759 case 6:
|
|
760 if(cl[i].status==CODECS_STATUS_WORKING)
|
|
761 if(cl[i].driver==win32 || cl[i].driver==dshow)
|
|
762 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
763 break;
|
|
764 case 2:
|
|
765 case 7:
|
|
766 if(cl[i].status==CODECS_STATUS_PROBLEMS)
|
|
767 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
768 break;
|
|
769 case 3:
|
|
770 case 8:
|
|
771 if(cl[i].status==CODECS_STATUS_NOT_WORKING)
|
|
772 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
773 break;
|
|
774 case 4:
|
|
775 case 9:
|
|
776 if(cl[i].status==CODECS_STATUS_UNTESTED)
|
|
777 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
778 break;
|
|
779 default:
|
|
780 printf("Warning! unimplemented section: %d\n",section);
|
|
781 }
|
|
782 }
|
|
783 fseek(f1,pos,SEEK_SET);
|
|
784 skiphtml(f1);
|
|
785 //void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){
|
|
786
|
|
787 continue;
|
|
788 }
|
|
789 fputc(c,f2);
|
|
790 fputc(d,f2);
|
|
791 }
|
|
792
|
|
793 fclose(f2);
|
|
794 fclose(f1);
|
|
795 return 0;
|
|
796 }
|
|
797
|
|
798 #endif
|
|
799
|
297
|
800 #ifdef TESTING
|
|
801 int main(void)
|
|
802 {
|
328
|
803 codecs_t **codecs, *c;
|
|
804 int i,j, nr_codecs, state;
|
297
|
805
|
319
|
806 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
|
|
807 return 0;
|
328
|
808 if (!codecs[0])
|
|
809 printf("no videoconfig.\n");
|
|
810 if (!codecs[1])
|
|
811 printf("no audioconfig.\n");
|
|
812
|
|
813 printf("videocodecs:\n");
|
|
814 c = codecs[0];
|
|
815 nr_codecs = nr_vcodecs;
|
|
816 state = 0;
|
|
817 next:
|
|
818 if (c) {
|
|
819 printf("number of codecs: %d\n", nr_codecs);
|
|
820 for(i=0;i<nr_codecs;i++, c++){
|
|
821 printf("\n============== codec %02d ===============\n",i);
|
|
822 printf("name='%s'\n",c->name);
|
|
823 printf("info='%s'\n",c->info);
|
|
824 printf("comment='%s'\n",c->comment);
|
|
825 printf("dll='%s'\n",c->dll);
|
361
|
826 printf("flags=%X driver=%d status=%d cpuflags=%d\n",
|
|
827 c->flags, c->driver, c->status, c->cpuflags);
|
300
|
828
|
328
|
829 for(j=0;j<CODECS_MAX_FOURCC;j++){
|
|
830 if(c->fourcc[j]!=0xFFFFFFFF){
|
361
|
831 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]);
|
328
|
832 }
|
|
833 }
|
|
834
|
|
835 for(j=0;j<CODECS_MAX_OUTFMT;j++){
|
|
836 if(c->outfmt[j]!=0xFFFFFFFF){
|
361
|
837 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]);
|
328
|
838 }
|
|
839 }
|
300
|
840
|
328
|
841 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3);
|
|
842 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]);
|
|
843 printf("\n");
|
300
|
844
|
328
|
845
|
|
846 }
|
|
847 }
|
|
848 if (!state) {
|
|
849 printf("audiocodecs:\n");
|
|
850 c = codecs[1];
|
|
851 nr_codecs = nr_acodecs;
|
|
852 state = 1;
|
|
853 goto next;
|
|
854 }
|
297
|
855 return 0;
|
|
856 }
|
|
857
|
|
858 #endif
|