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[] = {
|
1293
|
195 "null",
|
301
|
196 "mp3lib",
|
|
197 "pcm",
|
|
198 "libac3",
|
|
199 "acm",
|
|
200 "alaw",
|
|
201 "msgsm",
|
|
202 "dshow",
|
401
|
203 "dvdpcm",
|
301
|
204 NULL
|
|
205 };
|
|
206 static char *videodrv[] = {
|
1293
|
207 "null",
|
301
|
208 "libmpeg2",
|
|
209 "vfw",
|
|
210 "odivx",
|
|
211 "dshow",
|
1248
|
212 "ffmpeg",
|
1297
|
213 "vfwex",
|
301
|
214 NULL
|
|
215 };
|
|
216 char **drv=audioflag?audiodrv:videodrv;
|
|
217 int i;
|
|
218
|
1293
|
219 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i;
|
301
|
220
|
1293
|
221 return -1;
|
297
|
222 }
|
|
223
|
328
|
224 static int validate_codec(codecs_t *c, int type)
|
319
|
225 {
|
329
|
226 #if 0
|
328
|
227 int i;
|
|
228
|
|
229 for (i = 0; i < strlen(c->name) && isalnum(c->name[i]); i++)
|
|
230 /* NOTHING */;
|
|
231 if (i < strlen(c->name)) {
|
|
232 printf("\ncodec(%s)->name is not valid!\n", c->name);
|
|
233 return 0;
|
|
234 }
|
|
235 #warning codec->info = codec->name; ez ok, vagy strdup()?
|
|
236 if (!c->info)
|
|
237 c->info = c->name;
|
|
238 if (c->fourcc[0] == 0xffffffff) {
|
|
239 printf("\ncodec(%s) does not have fourcc/format!\n", c->name);
|
|
240 return 0;
|
|
241 }
|
|
242 if (!c->driver) {
|
|
243 printf("\ncodec(%s) does not have a driver!\n", c->name);
|
|
244 return 0;
|
|
245 }
|
|
246 #warning codec->driver == 4;... <- ezt nem kellene belehegeszteni...
|
|
247 #warning HOL VANNAK DEFINIALVA????????????
|
|
248 if (!c->dll && (c->driver == 4 ||
|
|
249 (c->driver == 2 && type == TYPE_VIDEO))) {
|
|
250 printf("\ncodec(%s) needs a 'dll'!\n", c->name);
|
|
251 return 0;
|
|
252 }
|
|
253 #warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg?
|
|
254 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4)
|
|
255
|
|
256 if (type == TYPE_VIDEO)
|
|
257 if (c->outfmt[0] == 0xffffffff) {
|
|
258 printf("\ncodec(%s) needs an 'outfmt'!\n", c->name);
|
|
259 return 0;
|
|
260 }
|
329
|
261 #endif
|
319
|
262 return 1;
|
|
263 }
|
|
264
|
|
265 static int add_comment(char *s, char **d)
|
|
266 {
|
|
267 int pos;
|
|
268
|
|
269 if (!*d)
|
|
270 pos = 0;
|
|
271 else {
|
|
272 pos = strlen(*d);
|
|
273 (*d)[pos++] = '\n';
|
|
274 }
|
|
275 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) {
|
361
|
276 printf("can't allocate mem for comment. ");
|
319
|
277 return 0;
|
|
278 }
|
|
279 strcpy(*d + pos, s);
|
|
280 return 1;
|
|
281 }
|
297
|
282
|
361
|
283 static short get_cpuflags(char *s)
|
|
284 {
|
|
285 static char *flagstr[] = {
|
|
286 "mmx",
|
|
287 "sse",
|
|
288 "3dnow",
|
|
289 NULL
|
|
290 };
|
|
291 int i;
|
|
292 short flags = 0;
|
|
293
|
|
294 do {
|
|
295 for (i = 0; flagstr[i]; i++)
|
|
296 if (!strncmp(s, flagstr[i], strlen(flagstr[i])))
|
|
297 break;
|
|
298 if (!flagstr[i])
|
|
299 goto err_out_parse_error;
|
|
300 flags |= 1<<i;
|
|
301 s += strlen(flagstr[i]);
|
|
302 } while (*(s++) == ',');
|
|
303
|
|
304 if (*(--s) != '\0')
|
|
305 goto err_out_parse_error;
|
|
306
|
|
307 return flags;
|
|
308 err_out_parse_error:
|
|
309 return 0;
|
|
310 }
|
|
311
|
328
|
312 static FILE *fp;
|
|
313 static int line_num = 0;
|
|
314 static char *line;
|
|
315 static char *token[MAX_NR_TOKEN];
|
|
316
|
|
317 static int get_token(int min, int max)
|
297
|
318 {
|
328
|
319 static int read_nextline = 1;
|
|
320 static int line_pos;
|
|
321 int i;
|
|
322 char c;
|
|
323
|
|
324 if (max >= MAX_NR_TOKEN) {
|
361
|
325 printf("get_token(): max >= MAX_NR_TOKEN!");
|
328
|
326 goto out_eof;
|
|
327 }
|
|
328
|
|
329 memset(token, 0x00, sizeof(*token) * max);
|
|
330
|
|
331 if (read_nextline) {
|
|
332 if (!fgets(line, MAX_LINE_LEN, fp))
|
|
333 goto out_eof;
|
|
334 line_pos = 0;
|
|
335 ++line_num;
|
|
336 read_nextline = 0;
|
|
337 }
|
|
338 for (i = 0; i < max; i++) {
|
|
339 while (isspace(line[line_pos]))
|
|
340 ++line_pos;
|
|
341 if (line[line_pos] == '\0' || line[line_pos] == '#' ||
|
|
342 line[line_pos] == ';') {
|
|
343 read_nextline = 1;
|
|
344 if (i >= min)
|
|
345 goto out_ok;
|
|
346 goto out_eol;
|
|
347 }
|
|
348 token[i] = line + line_pos;
|
|
349 c = line[line_pos];
|
|
350 if (c == '"' || c == '\'') {
|
|
351 token[i]++;
|
|
352 while (line[++line_pos] != c && line[line_pos])
|
|
353 /* NOTHING */;
|
|
354 } else {
|
|
355 for (/* NOTHING */; !isspace(line[line_pos]) &&
|
|
356 line[line_pos]; line_pos++)
|
|
357 /* NOTHING */;
|
|
358 }
|
|
359 if (!line[line_pos]) {
|
|
360 read_nextline = 1;
|
|
361 if (i >= min - 1)
|
|
362 goto out_ok;
|
|
363 goto out_eol;
|
|
364 }
|
|
365 line[line_pos] = '\0';
|
|
366 line_pos++;
|
|
367 }
|
|
368 out_ok:
|
|
369 return i;
|
|
370 out_eof:
|
|
371 return RET_EOF;
|
|
372 out_eol:
|
|
373 return RET_EOL;
|
|
374 }
|
|
375
|
|
376 static codecs_t *video_codecs=NULL;
|
|
377 static codecs_t *audio_codecs=NULL;
|
|
378 static int nr_vcodecs = 0;
|
|
379 static int nr_acodecs = 0;
|
|
380
|
|
381 codecs_t **parse_codec_cfg(char *cfgfile)
|
|
382 {
|
|
383 codecs_t *codec = NULL; // current codec
|
|
384 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs
|
|
385 static codecs_t *ret_codecs[2] = {NULL,NULL};
|
335
|
386 char *endptr; // strtoul()...
|
328
|
387 int *nr_codecsp;
|
|
388 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */
|
297
|
389 int tmp, i;
|
|
390
|
|
391 #ifdef DEBUG
|
|
392 assert(cfgfile != NULL);
|
|
393 #endif
|
|
394
|
361
|
395 printf("Reading %s: ", cfgfile);
|
297
|
396
|
301
|
397 if ((fp = fopen(cfgfile, "r")) == NULL) {
|
328
|
398 printf("can't open '%s': %s\n", cfgfile, strerror(errno));
|
297
|
399 return NULL;
|
|
400 }
|
|
401
|
301
|
402 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
|
361
|
403 printf("can't get memory for 'line': %s\n", strerror(errno));
|
297
|
404 return NULL;
|
|
405 }
|
|
406
|
328
|
407 /*
|
|
408 * check if the cfgfile starts with 'audiocodec' or
|
|
409 * with 'videocodec'
|
|
410 */
|
|
411 while ((tmp = get_token(1, 1)) == RET_EOL)
|
|
412 /* NOTHING */;
|
361
|
413 if (tmp == RET_EOF)
|
|
414 goto out;
|
|
415 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec"))
|
328
|
416 goto loop_enter;
|
361
|
417 goto err_out_parse_error;
|
328
|
418
|
319
|
419 while ((tmp = get_token(1, 1)) != RET_EOF) {
|
297
|
420 if (tmp == RET_EOL)
|
|
421 continue;
|
328
|
422 if (!strcmp(token[0], "audiocodec") ||
|
|
423 !strcmp(token[0], "videocodec")) {
|
|
424 if (!validate_codec(codec, codec_type))
|
|
425 goto err_out_not_valid;
|
|
426 loop_enter:
|
|
427 if (*token[0] == 'v') {
|
|
428 codec_type = TYPE_VIDEO;
|
|
429 nr_codecsp = &nr_vcodecs;
|
|
430 codecsp = &video_codecs;
|
|
431 } else if (*token[0] == 'a') {
|
|
432 codec_type = TYPE_AUDIO;
|
|
433 nr_codecsp = &nr_acodecs;
|
|
434 codecsp = &audio_codecs;
|
361
|
435 #ifdef DEBUG
|
328
|
436 } else {
|
361
|
437 printf("picsba\n");
|
328
|
438 goto err_out;
|
361
|
439 #endif
|
328
|
440 }
|
|
441 if (!(*codecsp = (codecs_t *) realloc(*codecsp,
|
332
|
442 sizeof(codecs_t) * (*nr_codecsp + 2)))) {
|
361
|
443 printf("can't realloc '*codecsp': %s\n", strerror(errno));
|
300
|
444 goto err_out;
|
|
445 }
|
328
|
446 codec=*codecsp + *nr_codecsp;
|
|
447 ++*nr_codecsp;
|
300
|
448 memset(codec,0,sizeof(codecs_t));
|
|
449 memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
|
|
450 memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
|
|
451
|
319
|
452 if (get_token(1, 1) < 0)
|
328
|
453 goto err_out_parse_error;
|
|
454 for (i = 0; i < *nr_codecsp - 1; i++) {
|
|
455 if (!strcmp(token[0], (*codecsp)[i].name)) {
|
361
|
456 printf("codec name '%s' isn't unique", token[0]);
|
|
457 goto err_out_print_linenum;
|
319
|
458 }
|
|
459 }
|
328
|
460 if (!(codec->name = strdup(token[0]))) {
|
361
|
461 printf("can't strdup -> 'name': %s\n", strerror(errno));
|
328
|
462 goto err_out;
|
|
463 }
|
319
|
464 } else if (!strcmp(token[0], "info")) {
|
328
|
465 if (codec->info || get_token(1, 1) < 0)
|
|
466 goto err_out_parse_error;
|
|
467 if (!(codec->info = strdup(token[0]))) {
|
361
|
468 printf("can't strdup -> 'info': %s\n", strerror(errno));
|
328
|
469 goto err_out;
|
|
470 }
|
319
|
471 } else if (!strcmp(token[0], "comment")) {
|
|
472 if (get_token(1, 1) < 0)
|
328
|
473 goto err_out_parse_error;
|
361
|
474 add_comment(token[0], &codec->comment);
|
319
|
475 } else if (!strcmp(token[0], "fourcc")) {
|
|
476 if (get_token(1, 2) < 0)
|
328
|
477 goto err_out_parse_error;
|
319
|
478 if (!add_to_fourcc(token[0], token[1],
|
300
|
479 codec->fourcc,
|
|
480 codec->fourccmap))
|
361
|
481 goto err_out_print_linenum;
|
319
|
482 } else if (!strcmp(token[0], "format")) {
|
|
483 if (get_token(1, 1) < 0)
|
328
|
484 goto err_out_parse_error;
|
319
|
485 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap))
|
361
|
486 goto err_out_print_linenum;
|
319
|
487 } else if (!strcmp(token[0], "driver")) {
|
|
488 if (get_token(1, 1) < 0)
|
328
|
489 goto err_out_parse_error;
|
1293
|
490 if ((codec->driver = get_driver(token[0],codec_type))<0)
|
361
|
491 goto err_out_parse_error;
|
319
|
492 } else if (!strcmp(token[0], "dll")) {
|
|
493 if (get_token(1, 1) < 0)
|
328
|
494 goto err_out_parse_error;
|
|
495 if (!(codec->dll = strdup(token[0]))) {
|
361
|
496 printf("can't strdup -> 'dll': %s\n", strerror(errno));
|
328
|
497 goto err_out;
|
|
498 }
|
319
|
499 } else if (!strcmp(token[0], "guid")) {
|
328
|
500 if (get_token(11, 11) < 0)
|
|
501 goto err_out_parse_error;
|
335
|
502 codec->guid.f1=strtoul(token[0],&endptr,0);
|
361
|
503 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
504 *endptr != '\0')
|
335
|
505 goto err_out_parse_error;
|
|
506 codec->guid.f2=strtoul(token[1],&endptr,0);
|
361
|
507 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
508 *endptr != '\0')
|
335
|
509 goto err_out_parse_error;
|
|
510 codec->guid.f3=strtoul(token[2],&endptr,0);
|
361
|
511 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
512 *endptr != '\0')
|
335
|
513 goto err_out_parse_error;
|
|
514 for (i = 0; i < 8; i++) {
|
|
515 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0);
|
361
|
516 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
517 *endptr != '\0')
|
328
|
518 goto err_out_parse_error;
|
297
|
519 }
|
319
|
520 } else if (!strcmp(token[0], "out")) {
|
|
521 if (get_token(1, 2) < 0)
|
328
|
522 goto err_out_parse_error;
|
319
|
523 if (!add_to_out(token[0], token[1], codec->outfmt,
|
300
|
524 codec->outflags))
|
361
|
525 goto err_out_print_linenum;
|
319
|
526 } else if (!strcmp(token[0], "flags")) {
|
|
527 if (get_token(1, 1) < 0)
|
328
|
528 goto err_out_parse_error;
|
321
|
529 if (!strcmp(token[0], "seekable"))
|
|
530 codec->flags |= CODECS_FLAG_SEEKABLE;
|
|
531 else
|
328
|
532 goto err_out_parse_error;
|
319
|
533 } else if (!strcmp(token[0], "status")) {
|
|
534 if (get_token(1, 1) < 0)
|
328
|
535 goto err_out_parse_error;
|
332
|
536 if (!strcasecmp(token[0], "working"))
|
316
|
537 codec->status = CODECS_STATUS_WORKING;
|
332
|
538 else if (!strcasecmp(token[0], "crashing"))
|
316
|
539 codec->status = CODECS_STATUS_NOT_WORKING;
|
332
|
540 else if (!strcasecmp(token[0], "untested"))
|
316
|
541 codec->status = CODECS_STATUS_UNTESTED;
|
332
|
542 else if (!strcasecmp(token[0], "buggy"))
|
316
|
543 codec->status = CODECS_STATUS_PROBLEMS;
|
|
544 else
|
328
|
545 goto err_out_parse_error;
|
361
|
546 } else if (!strcmp(token[0], "cpuflags")) {
|
|
547 if (get_token(1, 1) < 0)
|
|
548 goto err_out_parse_error;
|
|
549 if (!(codec->cpuflags = get_cpuflags(token[0])))
|
|
550 goto err_out_parse_error;
|
297
|
551 } else
|
328
|
552 goto err_out_parse_error;
|
297
|
553 }
|
328
|
554 if (!validate_codec(codec, codec_type))
|
|
555 goto err_out_not_valid;
|
361
|
556 printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs);
|
895
|
557 if(video_codecs) video_codecs[nr_vcodecs].name = NULL;
|
|
558 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL;
|
328
|
559 ret_codecs[0] = video_codecs;
|
|
560 ret_codecs[1] = audio_codecs;
|
297
|
561 out:
|
|
562 free(line);
|
|
563 fclose(fp);
|
328
|
564 return ret_codecs;
|
|
565 err_out_parse_error:
|
361
|
566 printf("parse error");
|
|
567 err_out_print_linenum:
|
297
|
568 PRINT_LINENUM;
|
|
569 err_out:
|
328
|
570 if (audio_codecs)
|
|
571 free(audio_codecs);
|
|
572 if (video_codecs)
|
|
573 free(video_codecs);
|
|
574 free(line);
|
|
575 free(fp);
|
|
576 return NULL;
|
|
577 err_out_not_valid:
|
361
|
578 printf("codec is not definied correctly");
|
|
579 goto err_out_print_linenum;
|
297
|
580 }
|
|
581
|
332
|
582 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
|
|
583 codecs_t *start)
|
328
|
584 {
|
332
|
585 return find_codec(fourcc, fourccmap, start, 1);
|
328
|
586 }
|
|
587
|
332
|
588 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap,
|
|
589 codecs_t *start)
|
328
|
590 {
|
332
|
591 return find_codec(fourcc, fourccmap, start, 0);
|
328
|
592 }
|
|
593
|
332
|
594 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,
|
|
595 codecs_t *start, int audioflag)
|
328
|
596 {
|
|
597 int i, j;
|
|
598 codecs_t *c;
|
|
599
|
628
|
600 #if 0
|
332
|
601 if (start) {
|
|
602 for (/* NOTHING */; start->name; start++) {
|
|
603 for (j = 0; j < CODECS_MAX_FOURCC; j++) {
|
|
604 if (start->fourcc[j] == fourcc) {
|
|
605 if (fourccmap)
|
|
606 *fourccmap = start->fourccmap[j];
|
|
607 return start;
|
|
608 }
|
|
609 }
|
|
610 }
|
628
|
611 } else
|
|
612 #endif
|
|
613 {
|
332
|
614 if (audioflag) {
|
|
615 i = nr_acodecs;
|
|
616 c = audio_codecs;
|
|
617 } else {
|
|
618 i = nr_vcodecs;
|
|
619 c = video_codecs;
|
|
620 }
|
895
|
621 if(!i) return NULL;
|
332
|
622 for (/* NOTHING */; i--; c++) {
|
628
|
623 if(start && c<=start) continue;
|
332
|
624 for (j = 0; j < CODECS_MAX_FOURCC; j++) {
|
|
625 if (c->fourcc[j] == fourcc) {
|
|
626 if (fourccmap)
|
|
627 *fourccmap = c->fourccmap[j];
|
|
628 return c;
|
|
629 }
|
328
|
630 }
|
|
631 }
|
|
632 }
|
|
633 return NULL;
|
303
|
634 }
|
|
635
|
607
|
636 #ifdef CODECS2HTML
|
|
637
|
|
638 void wrapline(FILE *f2,char *s){
|
|
639 int c;
|
|
640 if(!s){
|
|
641 fprintf(f2,"-");
|
|
642 return;
|
|
643 }
|
|
644 while((c=*s++)){
|
|
645 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2);
|
|
646 }
|
|
647 }
|
|
648
|
|
649 void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){
|
|
650 int c,d;
|
|
651 while((c=fgetc(f1))>=0){
|
|
652 if(c!='%'){
|
|
653 fputc(c,f2);
|
|
654 continue;
|
|
655 }
|
|
656 d=fgetc(f1);
|
|
657
|
|
658 switch(d){
|
|
659 case '.':
|
613
|
660 return; // end of section
|
607
|
661 case 'n':
|
|
662 wrapline(f2,codec->name); break;
|
|
663 case 'i':
|
|
664 wrapline(f2,codec->info); break;
|
|
665 case 'c':
|
|
666 wrapline(f2,codec->comment); break;
|
|
667 case 'd':
|
|
668 wrapline(f2,codec->dll); break;
|
|
669 case 'D':
|
|
670 fprintf(f2,"%c",codec->driver==dshow?'+':'-'); break;
|
|
671 case 'F':
|
|
672 for(d=0;d<CODECS_MAX_FOURCC;d++)
|
|
673 if(codec->fourcc[d]!=0xFFFFFFFF)
|
|
674 fprintf(f2,"%s%.4s",d?"<br>":"",codec->fourcc[d]<0x20202020?"-":(char*) &codec->fourcc[d]);
|
|
675 break;
|
|
676 case 'f':
|
|
677 for(d=0;d<CODECS_MAX_FOURCC;d++)
|
|
678 if(codec->fourcc[d]!=0xFFFFFFFF)
|
|
679 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]);
|
|
680 break;
|
|
681 case 'Y':
|
|
682 for(d=0;d<CODECS_MAX_OUTFMT;d++)
|
|
683 if(codec->outfmt[d]!=0xFFFFFFFF){
|
|
684 for (c=0; fmt_table[c].name; c++)
|
|
685 if(fmt_table[c].num==codec->outfmt[d]) break;
|
|
686 if(fmt_table[c].name)
|
|
687 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name);
|
|
688 }
|
|
689 break;
|
|
690 default:
|
|
691 fputc(c,f2);
|
|
692 fputc(d,f2);
|
|
693 }
|
|
694 }
|
|
695
|
|
696 }
|
|
697
|
|
698 void skiphtml(FILE *f1){
|
|
699 int c,d;
|
|
700 while((c=fgetc(f1))>=0){
|
|
701 if(c!='%'){
|
|
702 continue;
|
|
703 }
|
|
704 d=fgetc(f1);
|
|
705 if(d=='.') return; // end of section
|
|
706 }
|
|
707 }
|
|
708
|
|
709 int main(void)
|
|
710 {
|
|
711 codecs_t **codecs, *cl;
|
|
712 FILE *f1;
|
|
713 FILE *f2;
|
|
714 int c,d,i;
|
|
715 int pos;
|
|
716 int section=-1;
|
|
717 int nr_codecs;
|
|
718 int win32=-1;
|
|
719 int dshow=-1;
|
|
720
|
|
721 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
|
|
722 return 0;
|
|
723 if (!codecs[0])
|
|
724 printf("no videoconfig.\n");
|
|
725 if (!codecs[1])
|
|
726 printf("no audioconfig.\n");
|
|
727
|
|
728 f1=fopen("DOCS/codecs-in.html","rb"); if(!f1) exit(1);
|
|
729 f2=fopen("DOCS/codecs.html","wb"); if(!f2) exit(1);
|
|
730
|
|
731 while((c=fgetc(f1))>=0){
|
|
732 if(c!='%'){
|
|
733 fputc(c,f2);
|
|
734 continue;
|
|
735 }
|
|
736 d=fgetc(f1);
|
|
737 if(d>='0' && d<='9'){
|
|
738 // begin section
|
|
739 section=d-'0';
|
|
740 printf("BEGIN %d\n",section);
|
|
741 if(section>=5){
|
|
742 // audio
|
|
743 cl = codecs[1];
|
|
744 nr_codecs = nr_acodecs;
|
|
745 dshow=7;win32=4;
|
|
746 } else {
|
|
747 // video
|
|
748 cl = codecs[0];
|
|
749 nr_codecs = nr_vcodecs;
|
|
750 dshow=4;win32=2;
|
|
751 }
|
|
752 pos=ftell(f1);
|
|
753 for(i=0;i<nr_codecs;i++){
|
|
754 fseek(f1,pos,SEEK_SET);
|
|
755 switch(section){
|
|
756 case 0:
|
|
757 case 5:
|
|
758 if(cl[i].status==CODECS_STATUS_WORKING)
|
|
759 if(!(cl[i].driver==win32 || cl[i].driver==dshow))
|
|
760 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
761 break;
|
|
762 case 1:
|
|
763 case 6:
|
|
764 if(cl[i].status==CODECS_STATUS_WORKING)
|
|
765 if(cl[i].driver==win32 || cl[i].driver==dshow)
|
|
766 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
767 break;
|
|
768 case 2:
|
|
769 case 7:
|
|
770 if(cl[i].status==CODECS_STATUS_PROBLEMS)
|
|
771 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
772 break;
|
|
773 case 3:
|
|
774 case 8:
|
|
775 if(cl[i].status==CODECS_STATUS_NOT_WORKING)
|
|
776 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
777 break;
|
|
778 case 4:
|
|
779 case 9:
|
|
780 if(cl[i].status==CODECS_STATUS_UNTESTED)
|
|
781 parsehtml(f1,f2,&cl[i],section,dshow);
|
|
782 break;
|
|
783 default:
|
|
784 printf("Warning! unimplemented section: %d\n",section);
|
|
785 }
|
|
786 }
|
|
787 fseek(f1,pos,SEEK_SET);
|
|
788 skiphtml(f1);
|
|
789 //void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){
|
|
790
|
|
791 continue;
|
|
792 }
|
|
793 fputc(c,f2);
|
|
794 fputc(d,f2);
|
|
795 }
|
|
796
|
|
797 fclose(f2);
|
|
798 fclose(f1);
|
|
799 return 0;
|
|
800 }
|
|
801
|
|
802 #endif
|
|
803
|
297
|
804 #ifdef TESTING
|
|
805 int main(void)
|
|
806 {
|
328
|
807 codecs_t **codecs, *c;
|
|
808 int i,j, nr_codecs, state;
|
297
|
809
|
319
|
810 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
|
|
811 return 0;
|
328
|
812 if (!codecs[0])
|
|
813 printf("no videoconfig.\n");
|
|
814 if (!codecs[1])
|
|
815 printf("no audioconfig.\n");
|
|
816
|
|
817 printf("videocodecs:\n");
|
|
818 c = codecs[0];
|
|
819 nr_codecs = nr_vcodecs;
|
|
820 state = 0;
|
|
821 next:
|
|
822 if (c) {
|
|
823 printf("number of codecs: %d\n", nr_codecs);
|
|
824 for(i=0;i<nr_codecs;i++, c++){
|
|
825 printf("\n============== codec %02d ===============\n",i);
|
|
826 printf("name='%s'\n",c->name);
|
|
827 printf("info='%s'\n",c->info);
|
|
828 printf("comment='%s'\n",c->comment);
|
|
829 printf("dll='%s'\n",c->dll);
|
361
|
830 printf("flags=%X driver=%d status=%d cpuflags=%d\n",
|
|
831 c->flags, c->driver, c->status, c->cpuflags);
|
300
|
832
|
328
|
833 for(j=0;j<CODECS_MAX_FOURCC;j++){
|
|
834 if(c->fourcc[j]!=0xFFFFFFFF){
|
361
|
835 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]);
|
328
|
836 }
|
|
837 }
|
|
838
|
|
839 for(j=0;j<CODECS_MAX_OUTFMT;j++){
|
|
840 if(c->outfmt[j]!=0xFFFFFFFF){
|
361
|
841 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]);
|
328
|
842 }
|
|
843 }
|
300
|
844
|
328
|
845 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3);
|
|
846 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]);
|
|
847 printf("\n");
|
300
|
848
|
328
|
849
|
|
850 }
|
|
851 }
|
|
852 if (!state) {
|
|
853 printf("audiocodecs:\n");
|
|
854 c = codecs[1];
|
|
855 nr_codecs = nr_acodecs;
|
|
856 state = 1;
|
|
857 goto next;
|
|
858 }
|
297
|
859 return 0;
|
|
860 }
|
|
861
|
|
862 #endif
|