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