comparison codec-cfg.c @ 328:fc98b6c3a3dc

lots of changes again
author szabii
date Tue, 10 Apr 2001 20:09:23 +0000
parents 237b5f54bb78
children a476981431f7
comparison
equal deleted inserted replaced
327:e7731f5c76cc 328:fc98b6c3a3dc
3 * by Szabolcs Berecz <szabi@inf.elte.hu> 3 * by Szabolcs Berecz <szabi@inf.elte.hu>
4 * (C) 2001 4 * (C) 2001
5 */ 5 */
6 6
7 #define DEBUG 7 #define DEBUG
8
9 #ifdef DEBUG
10 #define DBG(str, args...) printf(str, ##args)
11 #else
12 #define DBG(str, args...) do {} while (0)
13 #endif
14
15 #define PRINT_LINENUM printf("%s(%d): ", cfgfile, line_num)
16 8
17 #include <stdio.h> 9 #include <stdio.h>
18 #include <stdlib.h> 10 #include <stdlib.h>
19 #include <fcntl.h> 11 #include <fcntl.h>
20 #include <unistd.h> 12 #include <unistd.h>
24 #include <string.h> 16 #include <string.h>
25 17
26 #include "libvo/video_out.h" 18 #include "libvo/video_out.h"
27 #include "codec-cfg.h" 19 #include "codec-cfg.h"
28 20
21 #ifdef DEBUG
22 # define DBG(str, args...) printf(str, ##args)
23 #else
24 # define DBG(str, args...) do {} while (0)
25 #endif
26
27 #define PRINT_LINENUM printf("%s(%d): ", cfgfile, line_num)
28
29 #define MAX_NR_TOKEN 16 29 #define MAX_NR_TOKEN 16
30 30
31 #define MAX_LINE_LEN 1000 31 #define MAX_LINE_LEN 1000
32
33 #define STATE_MASK ((1<<7)-1)
34
35 #define GOT_NAME (1<<0)
36 #define GOT_INFO (1<<1)
37 #define GOT_FOURCC (1<<2)
38 #define GOT_FORMAT (1<<3)
39 #define GOT_DRIVER (1<<4)
40 #define GOT_DLL (1<<5)
41 #define GOT_OUT (1<<6)
42 32
43 #define RET_EOF -1 33 #define RET_EOF -1
44 #define RET_EOL -2 34 #define RET_EOL -2
45 35
46 static FILE *fp; 36 #define TYPE_VIDEO 0
47 static int line_num = 0; 37 #define TYPE_AUDIO 1
48 static int line_pos; /* line pos */
49 static char *line;
50 static char *token[MAX_NR_TOKEN];
51
52 static codecs_t *codecs=NULL;
53 static int nr_codecs = 0;
54
55 static int get_token(int min, int max)
56 {
57 static int read_nextline = 1;
58 int i;
59 char c;
60
61 if (max >= MAX_NR_TOKEN) {
62 printf("\nget_token(): max >= MAX_NR_TOKEN!\n");
63 goto ret_eof;
64 }
65
66 memset(token, 0x00, sizeof(*token) * max);
67
68 if (read_nextline) {
69 if (!fgets(line, MAX_LINE_LEN, fp))
70 goto ret_eof;
71 line_pos = 0;
72 ++line_num;
73 read_nextline = 0;
74 }
75 for (i = 0; i < max; i++) {
76 while (isspace(line[line_pos]))
77 ++line_pos;
78 if (line[line_pos] == '\0' || line[line_pos] == '#' ||
79 line[line_pos] == ';') {
80 read_nextline = 1;
81 if (i >= min)
82 goto ret_ok;
83 goto ret_eol;
84 }
85 token[i] = line + line_pos;
86 c = line[line_pos];
87 if (c == '"' || c == '\'') {
88 token[i]++;
89 while (line[++line_pos] != c && line[line_pos])
90 /* NOTHING */;
91 } else {
92 for (/* NOTHING */; !isspace(line[line_pos]) &&
93 line[line_pos]; line_pos++)
94 /* NOTHING */;
95 }
96 if (!line[line_pos]) {
97 read_nextline = 1;
98 if (i >= min - 1)
99 goto ret_ok;
100 goto ret_eol;
101 }
102 line[line_pos] = '\0';
103 line_pos++;
104 }
105 ret_ok:
106 return i;
107 ret_eof:
108 return RET_EOF;
109 ret_eol:
110 return RET_EOL;
111 }
112 38
113 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc, 39 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc,
114 unsigned int *map) 40 unsigned int *map)
115 { 41 {
116 int i, j, freeslots; 42 int i, j, freeslots;
120 /* find first unused slot */ 46 /* find first unused slot */
121 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) 47 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
122 /* NOTHING */; 48 /* NOTHING */;
123 freeslots = CODECS_MAX_FOURCC - i; 49 freeslots = CODECS_MAX_FOURCC - i;
124 if (!freeslots) 50 if (!freeslots)
125 goto too_many_error_out; 51 goto err_out_too_many;
126 52
127 aliasp = (alias) ? &alias : &s; 53 aliasp = (alias) ? &alias : &s;
128 do { 54 do {
129 tmp = *((unsigned int *) s); 55 tmp = *((unsigned int *) s);
130 for (j = 0; j < i; j++) 56 for (j = 0; j < i; j++)
131 if (tmp == fourcc[j]) 57 if (tmp == fourcc[j])
132 goto duplicated_error_out; 58 goto err_out_duplicated;
133 fourcc[i] = tmp; 59 fourcc[i] = tmp;
134 map[i] = *((unsigned int *) (*aliasp)); 60 map[i] = *((unsigned int *) (*aliasp));
135 s += 4; 61 s += 4;
136 i++; 62 i++;
137 } while ((*(s++) == ',') && --freeslots); 63 } while ((*(s++) == ',') && --freeslots);
138 64
139 if (!freeslots) 65 if (!freeslots)
140 goto too_many_error_out; 66 goto err_out_too_many;
141 if (*(--s) != '\0') 67 if (*(--s) != '\0')
142 return 0; 68 return 0;
143 return 1; 69 return 1;
144 duplicated_error_out: 70 err_out_duplicated:
145 printf("\nduplicated fourcc/format\n"); 71 printf("\nduplicated fourcc/format\n");
146 return 0; 72 return 0;
147 too_many_error_out: 73 err_out_too_many:
148 printf("\ntoo many fourcc/format...\n"); 74 printf("\ntoo many fourcc/format...\n");
149 return 0; 75 return 0;
150 } 76 }
151 77
152 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap) 78 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap)
153 { 79 {
154 //printf("\n-----[%s][%s]-----\n",s,format);
155
156 int i, j; 80 int i, j;
157 81
158 /* find first unused slot */ 82 /* find first unused slot */
159 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) 83 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
160 /* NOTHING */; 84 /* NOTHING */;
170 return 0; 94 return 0;
171 } 95 }
172 96
173 return 1; 97 return 1;
174 } 98 }
175
176 99
177 static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt, 100 static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt,
178 unsigned char *outflags) 101 unsigned char *outflags)
179 { 102 {
180 static char *fmtstr[] = { 103 static char *fmtstr[] = {
218 141
219 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) 142 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++)
220 /* NOTHING */; 143 /* NOTHING */;
221 freeslots = CODECS_MAX_OUTFMT - i; 144 freeslots = CODECS_MAX_OUTFMT - i;
222 if (!freeslots) 145 if (!freeslots)
223 goto too_many_error_out; 146 goto err_out_too_many;
224 147
225 flags = 0; 148 flags = 0;
226 if(sflags) do { 149 if(sflags) do {
227 for (j = 0; flagstr[j] != NULL; j++) 150 for (j = 0; flagstr[j] != NULL; j++)
228 if (!strncmp(sflags, flagstr[j], strlen(flagstr[j]))) 151 if (!strncmp(sflags, flagstr[j], strlen(flagstr[j])))
243 ++i; 166 ++i;
244 sfmt+=strlen(fmtstr[j]); 167 sfmt+=strlen(fmtstr[j]);
245 } while ((*(sfmt++) == ',') && --freeslots); 168 } while ((*(sfmt++) == ',') && --freeslots);
246 169
247 if (!freeslots) 170 if (!freeslots)
248 goto too_many_error_out; 171 goto err_out_too_many;
249 172
250 if (*(--sfmt) != '\0') return 0; 173 if (*(--sfmt) != '\0') return 0;
251 174
252 return 1; 175 return 1;
253 too_many_error_out: 176 err_out_too_many:
254 printf("\ntoo many out...\n"); 177 printf("\ntoo many out...\n");
255 return 0; 178 return 0;
256 } 179 }
257 180
258 static short get_driver(char *s,int audioflag) 181 static short get_driver(char *s,int audioflag)
280 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i+1; 203 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i+1;
281 204
282 return 0; 205 return 0;
283 } 206 }
284 207
285 static int valid_codec(codecs_t *codec) 208 static int validate_codec(codecs_t *c, int type)
286 { 209 {
287 #warning FIXME mi is kell egy codec-be? 210 int i;
211
212 for (i = 0; i < strlen(c->name) && isalnum(c->name[i]); i++)
213 /* NOTHING */;
214 if (i < strlen(c->name)) {
215 printf("\ncodec(%s)->name is not valid!\n", c->name);
216 return 0;
217 }
218 #warning codec->info = codec->name; ez ok, vagy strdup()?
219 if (!c->info)
220 c->info = c->name;
221 if (c->fourcc[0] == 0xffffffff) {
222 printf("\ncodec(%s) does not have fourcc/format!\n", c->name);
223 return 0;
224 }
225 if (!c->driver) {
226 printf("\ncodec(%s) does not have a driver!\n", c->name);
227 return 0;
228 }
229 #warning codec->driver == 4;... <- ezt nem kellene belehegeszteni...
230 #warning HOL VANNAK DEFINIALVA????????????
231 if (!c->dll && (c->driver == 4 ||
232 (c->driver == 2 && type == TYPE_VIDEO))) {
233 printf("\ncodec(%s) needs a 'dll'!\n", c->name);
234 return 0;
235 }
236 #warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg?
237 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4)
238
239 if (type == TYPE_VIDEO)
240 if (c->outfmt[0] == 0xffffffff) {
241 printf("\ncodec(%s) needs an 'outfmt'!\n", c->name);
242 return 0;
243 }
288 return 1; 244 return 1;
289 } 245 }
290 246
291 static int add_comment(char *s, char **d) 247 static int add_comment(char *s, char **d)
292 { 248 {
304 } 260 }
305 strcpy(*d + pos, s); 261 strcpy(*d + pos, s);
306 return 1; 262 return 1;
307 } 263 }
308 264
309 codecs_t *parse_codec_cfg(char *cfgfile) 265 static FILE *fp;
310 { 266 static int line_num = 0;
311 codecs_t *codec = NULL; // current codec 267 static char *line;
268 static char *token[MAX_NR_TOKEN];
269
270 static int get_token(int min, int max)
271 {
272 static int read_nextline = 1;
273 static int line_pos;
274 int i;
275 char c;
276
277 if (max >= MAX_NR_TOKEN) {
278 printf("\nget_token(): max >= MAX_NR_TOKEN!\n");
279 goto out_eof;
280 }
281
282 memset(token, 0x00, sizeof(*token) * max);
283
284 if (read_nextline) {
285 if (!fgets(line, MAX_LINE_LEN, fp))
286 goto out_eof;
287 line_pos = 0;
288 ++line_num;
289 read_nextline = 0;
290 }
291 for (i = 0; i < max; i++) {
292 while (isspace(line[line_pos]))
293 ++line_pos;
294 if (line[line_pos] == '\0' || line[line_pos] == '#' ||
295 line[line_pos] == ';') {
296 read_nextline = 1;
297 if (i >= min)
298 goto out_ok;
299 goto out_eol;
300 }
301 token[i] = line + line_pos;
302 c = line[line_pos];
303 if (c == '"' || c == '\'') {
304 token[i]++;
305 while (line[++line_pos] != c && line[line_pos])
306 /* NOTHING */;
307 } else {
308 for (/* NOTHING */; !isspace(line[line_pos]) &&
309 line[line_pos]; line_pos++)
310 /* NOTHING */;
311 }
312 if (!line[line_pos]) {
313 read_nextline = 1;
314 if (i >= min - 1)
315 goto out_ok;
316 goto out_eol;
317 }
318 line[line_pos] = '\0';
319 line_pos++;
320 }
321 out_ok:
322 return i;
323 out_eof:
324 return RET_EOF;
325 out_eol:
326 return RET_EOL;
327 }
328
329 static codecs_t *video_codecs=NULL;
330 static codecs_t *audio_codecs=NULL;
331 static int nr_vcodecs = 0;
332 static int nr_acodecs = 0;
333
334 codecs_t **parse_codec_cfg(char *cfgfile)
335 {
336 codecs_t *codec = NULL; // current codec
337 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs
338 static codecs_t *ret_codecs[2] = {NULL,NULL};
339 int *nr_codecsp;
340 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */
312 int tmp, i; 341 int tmp, i;
313 int state = 0;
314 342
315 #ifdef DEBUG 343 #ifdef DEBUG
316 assert(cfgfile != NULL); 344 assert(cfgfile != NULL);
317 #endif 345 #endif
318 346
319 printf("Reading codec config file: %s\n", cfgfile); 347 printf("Reading codec config file: %s\n", cfgfile);
320 348
321 if ((fp = fopen(cfgfile, "r")) == NULL) { 349 if ((fp = fopen(cfgfile, "r")) == NULL) {
322 printf("parse_codec_cfg: can't open '%s': %s\n", cfgfile, strerror(errno)); 350 printf("can't open '%s': %s\n", cfgfile, strerror(errno));
323 return NULL; 351 return NULL;
324 } 352 }
325 353
326 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { 354 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
327 perror("parse_codec_cfg: can't get memory for 'line'"); 355 perror("can't get memory for 'line'");
328 return NULL; 356 return NULL;
329 } 357 }
358
359 /*
360 * check if the cfgfile starts with 'audiocodec' or
361 * with 'videocodec'
362 */
363 while ((tmp = get_token(1, 1)) == RET_EOL)
364 /* NOTHING */;
365 if (tmp != RET_EOF && (!strcmp(token[0], "audiocodec") ||
366 !strcmp(token[0], "videocodec")))
367 goto loop_enter;
368 goto out;
330 369
331 while ((tmp = get_token(1, 1)) != RET_EOF) { 370 while ((tmp = get_token(1, 1)) != RET_EOF) {
332 if (tmp == RET_EOL) 371 if (tmp == RET_EOL)
333 continue; 372 continue;
334 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) { 373 if (!strcmp(token[0], "audiocodec") ||
335 if (nr_codecs) 374 !strcmp(token[0], "videocodec")) {
336 if (!valid_codec(codec)) 375 if (!validate_codec(codec, codec_type))
337 goto not_valid_error_out; 376 goto err_out_not_valid;
338 if (!(codecs = (codecs_t *) realloc(codecs, 377 loop_enter:
339 sizeof(codecs_t) * (nr_codecs + 1)))) { 378 if (*token[0] == 'v') {
340 perror("parse_codec_cfg: can't realloc 'codecs'"); 379 codec_type = TYPE_VIDEO;
380 nr_codecsp = &nr_vcodecs;
381 codecsp = &video_codecs;
382 } else if (*token[0] == 'a') {
383 codec_type = TYPE_AUDIO;
384 nr_codecsp = &nr_acodecs;
385 codecsp = &audio_codecs;
386 } else {
387 printf("rohattkurva\n");
388 goto err_out;
389 }
390 if (!(*codecsp = (codecs_t *) realloc(*codecsp,
391 sizeof(codecs_t) * (*nr_codecsp + 1)))) {
392 perror("can't realloc '*codecsp'");
341 goto err_out; 393 goto err_out;
342 } 394 }
343 codec=&codecs[nr_codecs]; 395 codec=*codecsp + *nr_codecsp;
344 nr_codecs++; 396 ++*nr_codecsp;
345 memset(codec,0,sizeof(codecs_t)); 397 memset(codec,0,sizeof(codecs_t));
346 memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); 398 memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
347 memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); 399 memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
348 state = 0;
349 400
350 if (*token[0] == 'a') { /* audiocodec */
351 codec->flags |= CODECS_FLAG_AUDIO;
352 } else if (*token[0] == 'v') { /* videocodec */
353 codec->flags &= !CODECS_FLAG_AUDIO;
354 } else {
355 printf("itt valami nagyon el van baszva\n");
356 goto err_out;
357 }
358 if (get_token(1, 1) < 0) 401 if (get_token(1, 1) < 0)
359 goto parse_error_out; 402 goto err_out_parse_error;
360 for (i = 0; i < nr_codecs - 1; i++) { 403 for (i = 0; i < *nr_codecsp - 1; i++) {
361 #warning audio meg videocodecnek lehet ugyanaz a neve? 404 #warning audio meg videocodecnek lehet ugyanaz a neve? (most lehet...)
362 if ((codec->flags & CODECS_FLAG_AUDIO) != 405 if (!strcmp(token[0], (*codecsp)[i].name)) {
363 (codecs[i].flags & CODECS_FLAG_AUDIO))
364 continue;
365 if (!strcmp(token[0], codecs[i].name)) {
366 PRINT_LINENUM; 406 PRINT_LINENUM;
367 printf("codec name '%s' isn't unique\n", token[0]); 407 printf("codec name '%s' isn't unique\n", token[0]);
368 goto err_out; 408 goto err_out;
369 } 409 }
370 } 410 }
371 codec->name = strdup(token[0]); 411 if (!(codec->name = strdup(token[0]))) {
372 state |= GOT_NAME; 412 perror("can't strdup -> 'name'");
413 goto err_out;
414 }
373 } else if (!strcmp(token[0], "info")) { 415 } else if (!strcmp(token[0], "info")) {
374 if (!(state & GOT_NAME)) 416 if (codec->info || get_token(1, 1) < 0)
375 goto parse_error_out; 417 goto err_out_parse_error;
376 if (state & GOT_INFO || get_token(1, 1) < 0) 418 if (!(codec->info = strdup(token[0]))) {
377 goto parse_error_out; 419 perror("can't strdup -> 'info'");
378 codec->info = strdup(token[0]); 420 goto err_out;
379 state |= GOT_INFO; 421 }
380 } else if (!strcmp(token[0], "comment")) { 422 } else if (!strcmp(token[0], "comment")) {
381 if (!(state & GOT_NAME))
382 goto parse_error_out;
383 if (get_token(1, 1) < 0) 423 if (get_token(1, 1) < 0)
384 goto parse_error_out; 424 goto err_out_parse_error;
385 if (!add_comment(token[0], &codec->comment)) { 425 if (!add_comment(token[0], &codec->comment)) {
386 PRINT_LINENUM; 426 PRINT_LINENUM;
387 printf("add_comment()-tel valami sux\n"); 427 printf("add_comment()-tel valami sux\n");
388 } 428 }
389 } else if (!strcmp(token[0], "fourcc")) { 429 } else if (!strcmp(token[0], "fourcc")) {
390 if (!(state & GOT_NAME))
391 goto parse_error_out;
392 if (get_token(1, 2) < 0) 430 if (get_token(1, 2) < 0)
393 goto parse_error_out; 431 goto err_out_parse_error;
394 if (!add_to_fourcc(token[0], token[1], 432 if (!add_to_fourcc(token[0], token[1],
395 codec->fourcc, 433 codec->fourcc,
396 codec->fourccmap)) 434 codec->fourccmap))
397 goto parse_error_out; 435 goto err_out_parse_error;
398 state |= GOT_FOURCC;
399 } else if (!strcmp(token[0], "format")) { 436 } else if (!strcmp(token[0], "format")) {
400 if (!(state & GOT_NAME))
401 goto parse_error_out;
402 if (get_token(1, 1) < 0) 437 if (get_token(1, 1) < 0)
403 goto parse_error_out; 438 goto err_out_parse_error;
404 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap)) 439 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap))
405 goto parse_error_out; 440 goto err_out_parse_error;
406 state |= GOT_FORMAT;
407 } else if (!strcmp(token[0], "driver")) { 441 } else if (!strcmp(token[0], "driver")) {
408 if (!(state & GOT_NAME))
409 goto parse_error_out;
410 if (get_token(1, 1) < 0) 442 if (get_token(1, 1) < 0)
411 goto parse_error_out; 443 goto err_out_parse_error;
412 if ((codec->driver = get_driver(token[0],codec->flags&CODECS_FLAG_AUDIO)) == -1) 444 if ((codec->driver = get_driver(token[0],codec_type)) == -1)
413 goto err_out; 445 goto err_out;
414 } else if (!strcmp(token[0], "dll")) { 446 } else if (!strcmp(token[0], "dll")) {
415 if (!(state & GOT_NAME))
416 goto parse_error_out;
417 if (get_token(1, 1) < 0) 447 if (get_token(1, 1) < 0)
418 goto parse_error_out; 448 goto err_out_parse_error;
419 codec->dll = strdup(token[0]); 449 if (!(codec->dll = strdup(token[0]))) {
450 perror("can't strdup -> 'dll'");
451 goto err_out;
452 }
420 } else if (!strcmp(token[0], "guid")) { 453 } else if (!strcmp(token[0], "guid")) {
421 if (!(state & GOT_NAME)) 454 if (get_token(11, 11) < 0)
422 goto parse_error_out; 455 goto err_out_parse_error;
423 if (get_token(11, 11) < 0) goto parse_error_out; 456 #warning GUID-nak szammal kell kezdodni!!!!!!!! ez igy ok?
457 for (i = 0; i < 11; i++)
458 if (!isdigit(*token[i]))
459 goto err_out_parse_error;
424 codec->guid.f1=strtoul(token[0],NULL,0); 460 codec->guid.f1=strtoul(token[0],NULL,0);
425 codec->guid.f2=strtoul(token[1],NULL,0); 461 codec->guid.f2=strtoul(token[1],NULL,0);
426 codec->guid.f3=strtoul(token[2],NULL,0); 462 codec->guid.f3=strtoul(token[2],NULL,0);
427 for (i = 0; i < 8; i++) { 463 for (i = 0; i < 8; i++) {
428 codec->guid.f4[i]=strtoul(token[i + 3],NULL,0); 464 codec->guid.f4[i]=strtoul(token[i + 3],NULL,0);
429 } 465 }
430 } else if (!strcmp(token[0], "out")) { 466 } else if (!strcmp(token[0], "out")) {
431 if (!(state & GOT_NAME))
432 goto parse_error_out;
433 if (get_token(1, 2) < 0) 467 if (get_token(1, 2) < 0)
434 goto parse_error_out; 468 goto err_out_parse_error;
435 if (!add_to_out(token[0], token[1], codec->outfmt, 469 if (!add_to_out(token[0], token[1], codec->outfmt,
436 codec->outflags)) 470 codec->outflags))
437 goto err_out; 471 goto err_out;
438 } else if (!strcmp(token[0], "flags")) { 472 } else if (!strcmp(token[0], "flags")) {
439 if (!(state & GOT_NAME))
440 goto parse_error_out;
441 if (get_token(1, 1) < 0) 473 if (get_token(1, 1) < 0)
442 goto parse_error_out; 474 goto err_out_parse_error;
443 if (!strcmp(token[0], "seekable")) 475 if (!strcmp(token[0], "seekable"))
444 codec->flags |= CODECS_FLAG_SEEKABLE; 476 codec->flags |= CODECS_FLAG_SEEKABLE;
445 else 477 else
446 goto parse_error_out; 478 goto err_out_parse_error;
447 } else if (!strcmp(token[0], "status")) { 479 } else if (!strcmp(token[0], "status")) {
448 if (!(state & GOT_NAME))
449 goto parse_error_out;
450 if (get_token(1, 1) < 0) 480 if (get_token(1, 1) < 0)
451 goto parse_error_out; 481 goto err_out_parse_error;
452 if (!strcasecmp(token[0], ":-)")) 482 if (!strcasecmp(token[0], ":-)"))
453 codec->status = CODECS_STATUS_WORKING; 483 codec->status = CODECS_STATUS_WORKING;
454 else if (!strcasecmp(token[0], ":-(")) 484 else if (!strcasecmp(token[0], ":-("))
455 codec->status = CODECS_STATUS_NOT_WORKING; 485 codec->status = CODECS_STATUS_NOT_WORKING;
456 else if (!strcasecmp(token[0], "X-(")) 486 else if (!strcasecmp(token[0], "X-("))
457 codec->status = CODECS_STATUS_UNTESTED; 487 codec->status = CODECS_STATUS_UNTESTED;
458 else if (!strcasecmp(token[0], ":-|")) 488 else if (!strcasecmp(token[0], ":-|"))
459 codec->status = CODECS_STATUS_PROBLEMS; 489 codec->status = CODECS_STATUS_PROBLEMS;
460 else 490 else
461 goto parse_error_out; 491 goto err_out_parse_error;
462 } else 492 } else
463 goto parse_error_out; 493 goto err_out_parse_error;
464 } 494 }
465 if (!valid_codec(codec)) 495 if (!validate_codec(codec, codec_type))
466 goto not_valid_error_out; 496 goto err_out_not_valid;
497 ret_codecs[0] = video_codecs;
498 ret_codecs[1] = audio_codecs;
467 out: 499 out:
468 free(line); 500 free(line);
469 fclose(fp); 501 fclose(fp);
470 return codecs; 502 return ret_codecs;
471 parse_error_out: 503 err_out_parse_error:
472 PRINT_LINENUM; 504 PRINT_LINENUM;
473 printf("parse error\n"); 505 printf("parse error\n");
474 err_out: 506 err_out:
475 printf("\nOops\n"); 507 printf("\nOops\n");
476 if (codecs) 508 if (audio_codecs)
477 free(codecs); 509 free(audio_codecs);
478 codecs = NULL; 510 if (video_codecs)
479 goto out; 511 free(video_codecs);
480 not_valid_error_out: 512 free(line);
513 free(fp);
514 return NULL;
515 err_out_not_valid:
481 PRINT_LINENUM; 516 PRINT_LINENUM;
482 printf("codec is not definied correctly\n"); 517 printf("codec is not definied correctly\n");
483 goto err_out; 518 goto err_out;
484 } 519 }
485 520
486 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,int audioflag){ 521 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap)
487 int i,j; 522 {
488 for(i=0;i<nr_codecs;i++){ 523 return find_codec(fourcc, fourccmap, 1);
489 codecs_t *c=&codecs[i]; 524 }
490 if(!audioflag && (c->flags&CODECS_FLAG_AUDIO)) continue; 525
491 if(audioflag && !(c->flags&CODECS_FLAG_AUDIO)) continue; 526 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap)
492 for(j=0;j<CODECS_MAX_FOURCC;j++){ 527 {
493 if(c->fourcc[j]==fourcc){ 528 return find_codec(fourcc, fourccmap, 0);
494 if(fourccmap) *fourccmap=c->fourccmap[j]; 529 }
495 return c; 530
496 } 531 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,int audioflag)
497 } 532 {
498 } 533 int i, j;
499 return NULL; 534 codecs_t *c;
535
536 if (audioflag) {
537 i = nr_acodecs;
538 c = audio_codecs;
539 } else {
540 i = nr_vcodecs;
541 c = video_codecs;
542 }
543 for (/* NOTHING */; i--; c++) {
544 for (j = 0; j < CODECS_MAX_FOURCC; j++) {
545 if (c->fourcc[j] == fourcc) {
546 if (fourccmap) *fourccmap = c->fourccmap[j];
547 return c;
548 }
549 }
550 }
551 return NULL;
500 } 552 }
501 553
502 554
503 #ifdef TESTING 555 #ifdef TESTING
504 int main(void) 556 int main(void)
505 { 557 {
506 codecs_t *codecs; 558 codecs_t **codecs, *c;
507 int i,j; 559 int i,j, nr_codecs, state;
508 560
509 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf"))) 561 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
510 return 0; 562 return 0;
511 563 if (!codecs[0])
512 printf("total %d codecs parsed\n",nr_codecs); 564 printf("no videoconfig.\n");
513 for(i=0;i<nr_codecs;i++){ 565 if (!codecs[1])
514 codecs_t *c=&codecs[i]; 566 printf("no audioconfig.\n");
515 printf("\n============== codec %02d ===============\n",i); 567
516 printf("name='%s'\n",c->name); 568 printf("videocodecs:\n");
517 printf("info='%s'\n",c->info); 569 c = codecs[0];
518 printf("comment='%s'\n",c->comment); 570 nr_codecs = nr_vcodecs;
519 printf("dll='%s'\n",c->dll); 571 state = 0;
520 printf("flags=%X driver=%d\n",c->flags,c->driver); 572 next:
521 573 if (c) {
522 for(j=0;j<CODECS_MAX_FOURCC;j++){ 574 printf("number of codecs: %d\n", nr_codecs);
523 if(c->fourcc[j]!=0xFFFFFFFF){ 575 for(i=0;i<nr_codecs;i++, c++){
524 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],&c->fourcc[j],c->fourccmap[j],&c->fourccmap[j]); 576 printf("\n============== codec %02d ===============\n",i);
525 } 577 printf("name='%s'\n",c->name);
526 } 578 printf("info='%s'\n",c->info);
527 579 printf("comment='%s'\n",c->comment);
528 for(j=0;j<CODECS_MAX_OUTFMT;j++){ 580 printf("dll='%s'\n",c->dll);
529 if(c->outfmt[j]!=0xFFFFFFFF){ 581 printf("flags=%X driver=%d\n",c->flags,c->driver);
530 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],&c->outfmt[j],c->outflags[j]); 582
531 } 583 for(j=0;j<CODECS_MAX_FOURCC;j++){
532 } 584 if(c->fourcc[j]!=0xFFFFFFFF){
533 585 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],&c->fourcc[j],c->fourccmap[j],&c->fourccmap[j]);
534 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); 586 }
535 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); 587 }
536 printf("\n"); 588
537 589 for(j=0;j<CODECS_MAX_OUTFMT;j++){
538 590 if(c->outfmt[j]!=0xFFFFFFFF){
539 } 591 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],&c->outfmt[j],c->outflags[j]);
540 592 }
593 }
594
595 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3);
596 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]);
597 printf("\n");
598
599
600 }
601 }
602 if (!state) {
603 printf("audiocodecs:\n");
604 c = codecs[1];
605 nr_codecs = nr_acodecs;
606 state = 1;
607 goto next;
608 }
541 return 0; 609 return 0;
542 } 610 }
543 611
544 #endif 612 #endif