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",
|
|
204 NULL
|
|
205 };
|
|
206 static char *videodrv[] = {
|
|
207 "libmpeg2",
|
|
208 "vfw",
|
|
209 "odivx",
|
|
210 "dshow",
|
|
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);
|
332
|
554 video_codecs[nr_vcodecs].name = NULL;
|
|
555 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
|
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 }
|
328
|
607 } else {
|
332
|
608 if (audioflag) {
|
|
609 i = nr_acodecs;
|
|
610 c = audio_codecs;
|
|
611 } else {
|
|
612 i = nr_vcodecs;
|
|
613 c = video_codecs;
|
|
614 }
|
|
615 for (/* NOTHING */; i--; c++) {
|
|
616 for (j = 0; j < CODECS_MAX_FOURCC; j++) {
|
|
617 if (c->fourcc[j] == fourcc) {
|
|
618 if (fourccmap)
|
|
619 *fourccmap = c->fourccmap[j];
|
|
620 return c;
|
|
621 }
|
328
|
622 }
|
|
623 }
|
|
624 }
|
|
625 return NULL;
|
303
|
626 }
|
|
627
|
297
|
628 #ifdef TESTING
|
|
629 int main(void)
|
|
630 {
|
328
|
631 codecs_t **codecs, *c;
|
|
632 int i,j, nr_codecs, state;
|
297
|
633
|
319
|
634 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
|
|
635 return 0;
|
328
|
636 if (!codecs[0])
|
|
637 printf("no videoconfig.\n");
|
|
638 if (!codecs[1])
|
|
639 printf("no audioconfig.\n");
|
|
640
|
|
641 printf("videocodecs:\n");
|
|
642 c = codecs[0];
|
|
643 nr_codecs = nr_vcodecs;
|
|
644 state = 0;
|
|
645 next:
|
|
646 if (c) {
|
|
647 printf("number of codecs: %d\n", nr_codecs);
|
|
648 for(i=0;i<nr_codecs;i++, c++){
|
|
649 printf("\n============== codec %02d ===============\n",i);
|
|
650 printf("name='%s'\n",c->name);
|
|
651 printf("info='%s'\n",c->info);
|
|
652 printf("comment='%s'\n",c->comment);
|
|
653 printf("dll='%s'\n",c->dll);
|
361
|
654 printf("flags=%X driver=%d status=%d cpuflags=%d\n",
|
|
655 c->flags, c->driver, c->status, c->cpuflags);
|
300
|
656
|
328
|
657 for(j=0;j<CODECS_MAX_FOURCC;j++){
|
|
658 if(c->fourcc[j]!=0xFFFFFFFF){
|
361
|
659 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]);
|
328
|
660 }
|
|
661 }
|
|
662
|
|
663 for(j=0;j<CODECS_MAX_OUTFMT;j++){
|
|
664 if(c->outfmt[j]!=0xFFFFFFFF){
|
361
|
665 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]);
|
328
|
666 }
|
|
667 }
|
300
|
668
|
328
|
669 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3);
|
|
670 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]);
|
|
671 printf("\n");
|
300
|
672
|
328
|
673
|
|
674 }
|
|
675 }
|
|
676 if (!state) {
|
|
677 printf("audiocodecs:\n");
|
|
678 c = codecs[1];
|
|
679 nr_codecs = nr_acodecs;
|
|
680 state = 1;
|
|
681 goto next;
|
|
682 }
|
297
|
683 return 0;
|
|
684 }
|
|
685
|
|
686 #endif
|