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
|
|
18 #include "libvo/video_out.h"
|
|
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
|
303
|
102 static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt,
|
297
|
103 unsigned char *outflags)
|
|
104 {
|
|
105 static char *fmtstr[] = {
|
|
106 "YUY2",
|
|
107 "YV12",
|
|
108 "RGB8",
|
|
109 "RGB15",
|
|
110 "RGB16",
|
|
111 "RGB24",
|
|
112 "RGB32",
|
|
113 "BGR8",
|
|
114 "BGR15",
|
|
115 "BGR16",
|
|
116 "BGR24",
|
|
117 "BGR32",
|
|
118 NULL
|
|
119 };
|
|
120 static unsigned int fmtnum[] = {
|
|
121 IMGFMT_YUY2,
|
|
122 IMGFMT_YV12,
|
|
123 IMGFMT_RGB|8,
|
|
124 IMGFMT_RGB|15,
|
|
125 IMGFMT_RGB|16,
|
|
126 IMGFMT_RGB|24,
|
|
127 IMGFMT_RGB|32,
|
|
128 IMGFMT_BGR|8,
|
|
129 IMGFMT_BGR|15,
|
|
130 IMGFMT_BGR|16,
|
|
131 IMGFMT_BGR|24,
|
|
132 IMGFMT_BGR|32
|
|
133 };
|
299
|
134 static char *flagstr[] = {
|
|
135 "flip",
|
|
136 "noflip",
|
|
137 "yuvhack",
|
|
138 NULL
|
|
139 };
|
|
140
|
319
|
141 int i, j, freeslots;
|
297
|
142 unsigned char flags;
|
|
143
|
|
144 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++)
|
|
145 /* NOTHING */;
|
319
|
146 freeslots = CODECS_MAX_OUTFMT - i;
|
|
147 if (!freeslots)
|
328
|
148 goto err_out_too_many;
|
297
|
149
|
319
|
150 flags = 0;
|
361
|
151 if(sflags) {
|
|
152 do {
|
|
153 for (j = 0; flagstr[j] != NULL; j++)
|
|
154 if (!strncmp(sflags, flagstr[j],
|
|
155 strlen(flagstr[j])))
|
|
156 break;
|
|
157 if (flagstr[j] == NULL)
|
|
158 goto err_out_parse_error;
|
|
159 flags|=(1<<j);
|
|
160 sflags+=strlen(flagstr[j]);
|
|
161 } while (*(sflags++) == ',');
|
|
162
|
|
163 if (*(--sflags) != '\0')
|
|
164 goto err_out_parse_error;
|
|
165 }
|
297
|
166
|
|
167 do {
|
299
|
168 for (j = 0; fmtstr[j] != NULL; j++)
|
297
|
169 if (!strncmp(sfmt, fmtstr[j], strlen(fmtstr[j])))
|
|
170 break;
|
|
171 if (fmtstr[j] == NULL)
|
361
|
172 goto err_out_parse_error;
|
297
|
173 outfmt[i] = fmtnum[j];
|
|
174 outflags[i] = flags;
|
299
|
175 ++i;
|
297
|
176 sfmt+=strlen(fmtstr[j]);
|
319
|
177 } while ((*(sfmt++) == ',') && --freeslots);
|
|
178
|
|
179 if (!freeslots)
|
328
|
180 goto err_out_too_many;
|
319
|
181
|
361
|
182 if (*(--sfmt) != '\0')
|
|
183 goto err_out_parse_error;
|
299
|
184
|
297
|
185 return 1;
|
328
|
186 err_out_too_many:
|
361
|
187 printf("too many out...");
|
|
188 return 0;
|
|
189 err_out_parse_error:
|
|
190 printf("parse error");
|
319
|
191 return 0;
|
297
|
192 }
|
|
193
|
303
|
194 static short get_driver(char *s,int audioflag)
|
297
|
195 {
|
301
|
196 static char *audiodrv[] = {
|
|
197 "mp3lib",
|
|
198 "pcm",
|
|
199 "libac3",
|
|
200 "acm",
|
|
201 "alaw",
|
|
202 "msgsm",
|
|
203 "dshow",
|
401
|
204 "dvdpcm",
|
301
|
205 NULL
|
|
206 };
|
|
207 static char *videodrv[] = {
|
|
208 "libmpeg2",
|
|
209 "vfw",
|
|
210 "odivx",
|
|
211 "dshow",
|
|
212 NULL
|
|
213 };
|
|
214 char **drv=audioflag?audiodrv:videodrv;
|
|
215 int i;
|
|
216
|
|
217 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i+1;
|
|
218
|
297
|
219 return 0;
|
|
220 }
|
|
221
|
328
|
222 static int validate_codec(codecs_t *c, int type)
|
319
|
223 {
|
329
|
224 #if 0
|
328
|
225 int i;
|
|
226
|
|
227 for (i = 0; i < strlen(c->name) && isalnum(c->name[i]); i++)
|
|
228 /* NOTHING */;
|
|
229 if (i < strlen(c->name)) {
|
|
230 printf("\ncodec(%s)->name is not valid!\n", c->name);
|
|
231 return 0;
|
|
232 }
|
|
233 #warning codec->info = codec->name; ez ok, vagy strdup()?
|
|
234 if (!c->info)
|
|
235 c->info = c->name;
|
|
236 if (c->fourcc[0] == 0xffffffff) {
|
|
237 printf("\ncodec(%s) does not have fourcc/format!\n", c->name);
|
|
238 return 0;
|
|
239 }
|
|
240 if (!c->driver) {
|
|
241 printf("\ncodec(%s) does not have a driver!\n", c->name);
|
|
242 return 0;
|
|
243 }
|
|
244 #warning codec->driver == 4;... <- ezt nem kellene belehegeszteni...
|
|
245 #warning HOL VANNAK DEFINIALVA????????????
|
|
246 if (!c->dll && (c->driver == 4 ||
|
|
247 (c->driver == 2 && type == TYPE_VIDEO))) {
|
|
248 printf("\ncodec(%s) needs a 'dll'!\n", c->name);
|
|
249 return 0;
|
|
250 }
|
|
251 #warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg?
|
|
252 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4)
|
|
253
|
|
254 if (type == TYPE_VIDEO)
|
|
255 if (c->outfmt[0] == 0xffffffff) {
|
|
256 printf("\ncodec(%s) needs an 'outfmt'!\n", c->name);
|
|
257 return 0;
|
|
258 }
|
329
|
259 #endif
|
319
|
260 return 1;
|
|
261 }
|
|
262
|
|
263 static int add_comment(char *s, char **d)
|
|
264 {
|
|
265 int pos;
|
|
266
|
|
267 if (!*d)
|
|
268 pos = 0;
|
|
269 else {
|
|
270 pos = strlen(*d);
|
|
271 (*d)[pos++] = '\n';
|
|
272 }
|
|
273 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) {
|
361
|
274 printf("can't allocate mem for comment. ");
|
319
|
275 return 0;
|
|
276 }
|
|
277 strcpy(*d + pos, s);
|
|
278 return 1;
|
|
279 }
|
297
|
280
|
361
|
281 static short get_cpuflags(char *s)
|
|
282 {
|
|
283 static char *flagstr[] = {
|
|
284 "mmx",
|
|
285 "sse",
|
|
286 "3dnow",
|
|
287 NULL
|
|
288 };
|
|
289 int i;
|
|
290 short flags = 0;
|
|
291
|
|
292 do {
|
|
293 for (i = 0; flagstr[i]; i++)
|
|
294 if (!strncmp(s, flagstr[i], strlen(flagstr[i])))
|
|
295 break;
|
|
296 if (!flagstr[i])
|
|
297 goto err_out_parse_error;
|
|
298 flags |= 1<<i;
|
|
299 s += strlen(flagstr[i]);
|
|
300 } while (*(s++) == ',');
|
|
301
|
|
302 if (*(--s) != '\0')
|
|
303 goto err_out_parse_error;
|
|
304
|
|
305 return flags;
|
|
306 err_out_parse_error:
|
|
307 return 0;
|
|
308 }
|
|
309
|
328
|
310 static FILE *fp;
|
|
311 static int line_num = 0;
|
|
312 static char *line;
|
|
313 static char *token[MAX_NR_TOKEN];
|
|
314
|
|
315 static int get_token(int min, int max)
|
297
|
316 {
|
328
|
317 static int read_nextline = 1;
|
|
318 static int line_pos;
|
|
319 int i;
|
|
320 char c;
|
|
321
|
|
322 if (max >= MAX_NR_TOKEN) {
|
361
|
323 printf("get_token(): max >= MAX_NR_TOKEN!");
|
328
|
324 goto out_eof;
|
|
325 }
|
|
326
|
|
327 memset(token, 0x00, sizeof(*token) * max);
|
|
328
|
|
329 if (read_nextline) {
|
|
330 if (!fgets(line, MAX_LINE_LEN, fp))
|
|
331 goto out_eof;
|
|
332 line_pos = 0;
|
|
333 ++line_num;
|
|
334 read_nextline = 0;
|
|
335 }
|
|
336 for (i = 0; i < max; i++) {
|
|
337 while (isspace(line[line_pos]))
|
|
338 ++line_pos;
|
|
339 if (line[line_pos] == '\0' || line[line_pos] == '#' ||
|
|
340 line[line_pos] == ';') {
|
|
341 read_nextline = 1;
|
|
342 if (i >= min)
|
|
343 goto out_ok;
|
|
344 goto out_eol;
|
|
345 }
|
|
346 token[i] = line + line_pos;
|
|
347 c = line[line_pos];
|
|
348 if (c == '"' || c == '\'') {
|
|
349 token[i]++;
|
|
350 while (line[++line_pos] != c && line[line_pos])
|
|
351 /* NOTHING */;
|
|
352 } else {
|
|
353 for (/* NOTHING */; !isspace(line[line_pos]) &&
|
|
354 line[line_pos]; line_pos++)
|
|
355 /* NOTHING */;
|
|
356 }
|
|
357 if (!line[line_pos]) {
|
|
358 read_nextline = 1;
|
|
359 if (i >= min - 1)
|
|
360 goto out_ok;
|
|
361 goto out_eol;
|
|
362 }
|
|
363 line[line_pos] = '\0';
|
|
364 line_pos++;
|
|
365 }
|
|
366 out_ok:
|
|
367 return i;
|
|
368 out_eof:
|
|
369 return RET_EOF;
|
|
370 out_eol:
|
|
371 return RET_EOL;
|
|
372 }
|
|
373
|
|
374 static codecs_t *video_codecs=NULL;
|
|
375 static codecs_t *audio_codecs=NULL;
|
|
376 static int nr_vcodecs = 0;
|
|
377 static int nr_acodecs = 0;
|
|
378
|
|
379 codecs_t **parse_codec_cfg(char *cfgfile)
|
|
380 {
|
|
381 codecs_t *codec = NULL; // current codec
|
|
382 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs
|
|
383 static codecs_t *ret_codecs[2] = {NULL,NULL};
|
335
|
384 char *endptr; // strtoul()...
|
328
|
385 int *nr_codecsp;
|
|
386 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */
|
297
|
387 int tmp, i;
|
|
388
|
|
389 #ifdef DEBUG
|
|
390 assert(cfgfile != NULL);
|
|
391 #endif
|
|
392
|
361
|
393 printf("Reading %s: ", cfgfile);
|
297
|
394
|
301
|
395 if ((fp = fopen(cfgfile, "r")) == NULL) {
|
328
|
396 printf("can't open '%s': %s\n", cfgfile, strerror(errno));
|
297
|
397 return NULL;
|
|
398 }
|
|
399
|
301
|
400 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
|
361
|
401 printf("can't get memory for 'line': %s\n", strerror(errno));
|
297
|
402 return NULL;
|
|
403 }
|
|
404
|
328
|
405 /*
|
|
406 * check if the cfgfile starts with 'audiocodec' or
|
|
407 * with 'videocodec'
|
|
408 */
|
|
409 while ((tmp = get_token(1, 1)) == RET_EOL)
|
|
410 /* NOTHING */;
|
361
|
411 if (tmp == RET_EOF)
|
|
412 goto out;
|
|
413 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec"))
|
328
|
414 goto loop_enter;
|
361
|
415 goto err_out_parse_error;
|
328
|
416
|
319
|
417 while ((tmp = get_token(1, 1)) != RET_EOF) {
|
297
|
418 if (tmp == RET_EOL)
|
|
419 continue;
|
328
|
420 if (!strcmp(token[0], "audiocodec") ||
|
|
421 !strcmp(token[0], "videocodec")) {
|
|
422 if (!validate_codec(codec, codec_type))
|
|
423 goto err_out_not_valid;
|
|
424 loop_enter:
|
|
425 if (*token[0] == 'v') {
|
|
426 codec_type = TYPE_VIDEO;
|
|
427 nr_codecsp = &nr_vcodecs;
|
|
428 codecsp = &video_codecs;
|
|
429 } else if (*token[0] == 'a') {
|
|
430 codec_type = TYPE_AUDIO;
|
|
431 nr_codecsp = &nr_acodecs;
|
|
432 codecsp = &audio_codecs;
|
361
|
433 #ifdef DEBUG
|
328
|
434 } else {
|
361
|
435 printf("picsba\n");
|
328
|
436 goto err_out;
|
361
|
437 #endif
|
328
|
438 }
|
|
439 if (!(*codecsp = (codecs_t *) realloc(*codecsp,
|
332
|
440 sizeof(codecs_t) * (*nr_codecsp + 2)))) {
|
361
|
441 printf("can't realloc '*codecsp': %s\n", strerror(errno));
|
300
|
442 goto err_out;
|
|
443 }
|
328
|
444 codec=*codecsp + *nr_codecsp;
|
|
445 ++*nr_codecsp;
|
300
|
446 memset(codec,0,sizeof(codecs_t));
|
|
447 memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
|
|
448 memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
|
|
449
|
319
|
450 if (get_token(1, 1) < 0)
|
328
|
451 goto err_out_parse_error;
|
|
452 for (i = 0; i < *nr_codecsp - 1; i++) {
|
|
453 if (!strcmp(token[0], (*codecsp)[i].name)) {
|
361
|
454 printf("codec name '%s' isn't unique", token[0]);
|
|
455 goto err_out_print_linenum;
|
319
|
456 }
|
|
457 }
|
328
|
458 if (!(codec->name = strdup(token[0]))) {
|
361
|
459 printf("can't strdup -> 'name': %s\n", strerror(errno));
|
328
|
460 goto err_out;
|
|
461 }
|
319
|
462 } else if (!strcmp(token[0], "info")) {
|
328
|
463 if (codec->info || get_token(1, 1) < 0)
|
|
464 goto err_out_parse_error;
|
|
465 if (!(codec->info = strdup(token[0]))) {
|
361
|
466 printf("can't strdup -> 'info': %s\n", strerror(errno));
|
328
|
467 goto err_out;
|
|
468 }
|
319
|
469 } else if (!strcmp(token[0], "comment")) {
|
|
470 if (get_token(1, 1) < 0)
|
328
|
471 goto err_out_parse_error;
|
361
|
472 add_comment(token[0], &codec->comment);
|
319
|
473 } else if (!strcmp(token[0], "fourcc")) {
|
|
474 if (get_token(1, 2) < 0)
|
328
|
475 goto err_out_parse_error;
|
319
|
476 if (!add_to_fourcc(token[0], token[1],
|
300
|
477 codec->fourcc,
|
|
478 codec->fourccmap))
|
361
|
479 goto err_out_print_linenum;
|
319
|
480 } else if (!strcmp(token[0], "format")) {
|
|
481 if (get_token(1, 1) < 0)
|
328
|
482 goto err_out_parse_error;
|
319
|
483 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap))
|
361
|
484 goto err_out_print_linenum;
|
319
|
485 } else if (!strcmp(token[0], "driver")) {
|
|
486 if (get_token(1, 1) < 0)
|
328
|
487 goto err_out_parse_error;
|
361
|
488 if (!(codec->driver = get_driver(token[0],codec_type)))
|
|
489 goto err_out_parse_error;
|
319
|
490 } else if (!strcmp(token[0], "dll")) {
|
|
491 if (get_token(1, 1) < 0)
|
328
|
492 goto err_out_parse_error;
|
|
493 if (!(codec->dll = strdup(token[0]))) {
|
361
|
494 printf("can't strdup -> 'dll': %s\n", strerror(errno));
|
328
|
495 goto err_out;
|
|
496 }
|
319
|
497 } else if (!strcmp(token[0], "guid")) {
|
328
|
498 if (get_token(11, 11) < 0)
|
|
499 goto err_out_parse_error;
|
335
|
500 codec->guid.f1=strtoul(token[0],&endptr,0);
|
361
|
501 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
502 *endptr != '\0')
|
335
|
503 goto err_out_parse_error;
|
|
504 codec->guid.f2=strtoul(token[1],&endptr,0);
|
361
|
505 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
506 *endptr != '\0')
|
335
|
507 goto err_out_parse_error;
|
|
508 codec->guid.f3=strtoul(token[2],&endptr,0);
|
361
|
509 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
510 *endptr != '\0')
|
335
|
511 goto err_out_parse_error;
|
|
512 for (i = 0; i < 8; i++) {
|
|
513 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0);
|
361
|
514 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
515 *endptr != '\0')
|
328
|
516 goto err_out_parse_error;
|
297
|
517 }
|
319
|
518 } else if (!strcmp(token[0], "out")) {
|
|
519 if (get_token(1, 2) < 0)
|
328
|
520 goto err_out_parse_error;
|
319
|
521 if (!add_to_out(token[0], token[1], codec->outfmt,
|
300
|
522 codec->outflags))
|
361
|
523 goto err_out_print_linenum;
|
319
|
524 } else if (!strcmp(token[0], "flags")) {
|
|
525 if (get_token(1, 1) < 0)
|
328
|
526 goto err_out_parse_error;
|
321
|
527 if (!strcmp(token[0], "seekable"))
|
|
528 codec->flags |= CODECS_FLAG_SEEKABLE;
|
|
529 else
|
328
|
530 goto err_out_parse_error;
|
319
|
531 } else if (!strcmp(token[0], "status")) {
|
|
532 if (get_token(1, 1) < 0)
|
328
|
533 goto err_out_parse_error;
|
332
|
534 if (!strcasecmp(token[0], "working"))
|
316
|
535 codec->status = CODECS_STATUS_WORKING;
|
332
|
536 else if (!strcasecmp(token[0], "crashing"))
|
316
|
537 codec->status = CODECS_STATUS_NOT_WORKING;
|
332
|
538 else if (!strcasecmp(token[0], "untested"))
|
316
|
539 codec->status = CODECS_STATUS_UNTESTED;
|
332
|
540 else if (!strcasecmp(token[0], "buggy"))
|
316
|
541 codec->status = CODECS_STATUS_PROBLEMS;
|
|
542 else
|
328
|
543 goto err_out_parse_error;
|
361
|
544 } else if (!strcmp(token[0], "cpuflags")) {
|
|
545 if (get_token(1, 1) < 0)
|
|
546 goto err_out_parse_error;
|
|
547 if (!(codec->cpuflags = get_cpuflags(token[0])))
|
|
548 goto err_out_parse_error;
|
297
|
549 } else
|
328
|
550 goto err_out_parse_error;
|
297
|
551 }
|
328
|
552 if (!validate_codec(codec, codec_type))
|
|
553 goto err_out_not_valid;
|
361
|
554 printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs);
|
332
|
555 video_codecs[nr_vcodecs].name = NULL;
|
|
556 audio_codecs[nr_acodecs].name = NULL;
|
328
|
557 ret_codecs[0] = video_codecs;
|
|
558 ret_codecs[1] = audio_codecs;
|
297
|
559 out:
|
|
560 free(line);
|
|
561 fclose(fp);
|
328
|
562 return ret_codecs;
|
|
563 err_out_parse_error:
|
361
|
564 printf("parse error");
|
|
565 err_out_print_linenum:
|
297
|
566 PRINT_LINENUM;
|
|
567 err_out:
|
328
|
568 if (audio_codecs)
|
|
569 free(audio_codecs);
|
|
570 if (video_codecs)
|
|
571 free(video_codecs);
|
|
572 free(line);
|
|
573 free(fp);
|
|
574 return NULL;
|
|
575 err_out_not_valid:
|
361
|
576 printf("codec is not definied correctly");
|
|
577 goto err_out_print_linenum;
|
297
|
578 }
|
|
579
|
332
|
580 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
|
|
581 codecs_t *start)
|
328
|
582 {
|
332
|
583 return find_codec(fourcc, fourccmap, start, 1);
|
328
|
584 }
|
|
585
|
332
|
586 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap,
|
|
587 codecs_t *start)
|
328
|
588 {
|
332
|
589 return find_codec(fourcc, fourccmap, start, 0);
|
328
|
590 }
|
|
591
|
332
|
592 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,
|
|
593 codecs_t *start, int audioflag)
|
328
|
594 {
|
|
595 int i, j;
|
|
596 codecs_t *c;
|
|
597
|
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 }
|
328
|
608 } else {
|
332
|
609 if (audioflag) {
|
|
610 i = nr_acodecs;
|
|
611 c = audio_codecs;
|
|
612 } else {
|
|
613 i = nr_vcodecs;
|
|
614 c = video_codecs;
|
|
615 }
|
|
616 for (/* NOTHING */; i--; c++) {
|
|
617 for (j = 0; j < CODECS_MAX_FOURCC; j++) {
|
|
618 if (c->fourcc[j] == fourcc) {
|
|
619 if (fourccmap)
|
|
620 *fourccmap = c->fourccmap[j];
|
|
621 return c;
|
|
622 }
|
328
|
623 }
|
|
624 }
|
|
625 }
|
|
626 return NULL;
|
303
|
627 }
|
|
628
|
297
|
629 #ifdef TESTING
|
|
630 int main(void)
|
|
631 {
|
328
|
632 codecs_t **codecs, *c;
|
|
633 int i,j, nr_codecs, state;
|
297
|
634
|
319
|
635 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
|
|
636 return 0;
|
328
|
637 if (!codecs[0])
|
|
638 printf("no videoconfig.\n");
|
|
639 if (!codecs[1])
|
|
640 printf("no audioconfig.\n");
|
|
641
|
|
642 printf("videocodecs:\n");
|
|
643 c = codecs[0];
|
|
644 nr_codecs = nr_vcodecs;
|
|
645 state = 0;
|
|
646 next:
|
|
647 if (c) {
|
|
648 printf("number of codecs: %d\n", nr_codecs);
|
|
649 for(i=0;i<nr_codecs;i++, c++){
|
|
650 printf("\n============== codec %02d ===============\n",i);
|
|
651 printf("name='%s'\n",c->name);
|
|
652 printf("info='%s'\n",c->info);
|
|
653 printf("comment='%s'\n",c->comment);
|
|
654 printf("dll='%s'\n",c->dll);
|
361
|
655 printf("flags=%X driver=%d status=%d cpuflags=%d\n",
|
|
656 c->flags, c->driver, c->status, c->cpuflags);
|
300
|
657
|
328
|
658 for(j=0;j<CODECS_MAX_FOURCC;j++){
|
|
659 if(c->fourcc[j]!=0xFFFFFFFF){
|
361
|
660 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]);
|
328
|
661 }
|
|
662 }
|
|
663
|
|
664 for(j=0;j<CODECS_MAX_OUTFMT;j++){
|
|
665 if(c->outfmt[j]!=0xFFFFFFFF){
|
361
|
666 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]);
|
328
|
667 }
|
|
668 }
|
300
|
669
|
328
|
670 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3);
|
|
671 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]);
|
|
672 printf("\n");
|
300
|
673
|
328
|
674
|
|
675 }
|
|
676 }
|
|
677 if (!state) {
|
|
678 printf("audiocodecs:\n");
|
|
679 c = codecs[1];
|
|
680 nr_codecs = nr_acodecs;
|
|
681 state = 1;
|
|
682 goto next;
|
|
683 }
|
297
|
684 return 0;
|
|
685 }
|
|
686
|
|
687 #endif
|