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