comparison codec-cfg.c @ 361:3e0c68209600

dunno :)
author szabii
date Wed, 11 Apr 2001 20:55:14 +0000
parents 901e7f28bb60
children 835fac6382be
comparison
equal deleted inserted replaced
360:fd152aa6fcf3 361:3e0c68209600
16 #include <string.h> 16 #include <string.h>
17 17
18 #include "libvo/video_out.h" 18 #include "libvo/video_out.h"
19 #include "codec-cfg.h" 19 #include "codec-cfg.h"
20 20
21 #ifdef DEBUG 21 #define PRINT_LINENUM printf(" at line %d\n", line_num)
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 22
29 #define MAX_NR_TOKEN 16 23 #define MAX_NR_TOKEN 16
30 24
31 #define MAX_LINE_LEN 1000 25 #define MAX_LINE_LEN 1000
32 26
63 } while ((*(s++) == ',') && --freeslots); 57 } while ((*(s++) == ',') && --freeslots);
64 58
65 if (!freeslots) 59 if (!freeslots)
66 goto err_out_too_many; 60 goto err_out_too_many;
67 if (*(--s) != '\0') 61 if (*(--s) != '\0')
68 return 0; 62 goto err_out_parse_error;
69 return 1; 63 return 1;
70 err_out_duplicated: 64 err_out_duplicated:
71 printf("\nduplicated fourcc/format\n"); 65 printf("duplicated fourcc/format");
72 return 0; 66 return 0;
73 err_out_too_many: 67 err_out_too_many:
74 printf("\ntoo many fourcc/format...\n"); 68 printf("too many fourcc/format...");
69 return 0;
70 err_out_parse_error:
71 printf("parse error");
75 return 0; 72 return 0;
76 } 73 }
77 74
78 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap) 75 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap)
79 { 76 {
80 int i, j; 77 int i, j;
78 char *endptr;
81 79
82 /* find first unused slot */ 80 /* find first unused slot */
83 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) 81 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
84 /* NOTHING */; 82 /* NOTHING */;
85 if (i == CODECS_MAX_FOURCC) { 83 if (i == CODECS_MAX_FOURCC) {
86 printf("\ntoo many fourcc/format...\n"); 84 printf("too many fourcc/format...");
87 return 0; 85 return 0;
88 } 86 }
89 87
90 fourcc[i]=fourccmap[i]=strtoul(s,NULL,0); 88 fourcc[i]=fourccmap[i]=strtoul(s,&endptr,0);
89 if (*endptr != '\0') {
90 printf("parse error");
91 return 0;
92 }
91 for (j = 0; j < i; j++) 93 for (j = 0; j < i; j++)
92 if (fourcc[j] == fourcc[i]) { 94 if (fourcc[j] == fourcc[i]) {
93 printf("\nduplicated fourcc/format\n"); 95 printf("duplicated fourcc/format");
94 return 0; 96 return 0;
95 } 97 }
96 98
97 return 1; 99 return 1;
98 } 100 }
144 freeslots = CODECS_MAX_OUTFMT - i; 146 freeslots = CODECS_MAX_OUTFMT - i;
145 if (!freeslots) 147 if (!freeslots)
146 goto err_out_too_many; 148 goto err_out_too_many;
147 149
148 flags = 0; 150 flags = 0;
149 if(sflags) do { 151 if(sflags) {
150 for (j = 0; flagstr[j] != NULL; j++) 152 do {
151 if (!strncmp(sflags, flagstr[j], strlen(flagstr[j]))) 153 for (j = 0; flagstr[j] != NULL; j++)
152 break; 154 if (!strncmp(sflags, flagstr[j],
153 if (flagstr[j] == NULL) return 0; // error! 155 strlen(flagstr[j])))
154 flags|=(1<<j); 156 break;
155 sflags+=strlen(flagstr[j]); 157 if (flagstr[j] == NULL)
156 } while (*(sflags++) == ','); 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 }
157 166
158 do { 167 do {
159 for (j = 0; fmtstr[j] != NULL; j++) 168 for (j = 0; fmtstr[j] != NULL; j++)
160 if (!strncmp(sfmt, fmtstr[j], strlen(fmtstr[j]))) 169 if (!strncmp(sfmt, fmtstr[j], strlen(fmtstr[j])))
161 break; 170 break;
162 if (fmtstr[j] == NULL) 171 if (fmtstr[j] == NULL)
163 return 0; 172 goto err_out_parse_error;
164 outfmt[i] = fmtnum[j]; 173 outfmt[i] = fmtnum[j];
165 outflags[i] = flags; 174 outflags[i] = flags;
166 ++i; 175 ++i;
167 sfmt+=strlen(fmtstr[j]); 176 sfmt+=strlen(fmtstr[j]);
168 } while ((*(sfmt++) == ',') && --freeslots); 177 } while ((*(sfmt++) == ',') && --freeslots);
169 178
170 if (!freeslots) 179 if (!freeslots)
171 goto err_out_too_many; 180 goto err_out_too_many;
172 181
173 if (*(--sfmt) != '\0') return 0; 182 if (*(--sfmt) != '\0')
183 goto err_out_parse_error;
174 184
175 return 1; 185 return 1;
176 err_out_too_many: 186 err_out_too_many:
177 printf("\ntoo many out...\n"); 187 printf("too many out...");
188 return 0;
189 err_out_parse_error:
190 printf("parse error");
178 return 0; 191 return 0;
179 } 192 }
180 193
181 static short get_driver(char *s,int audioflag) 194 static short get_driver(char *s,int audioflag)
182 { 195 {
255 else { 268 else {
256 pos = strlen(*d); 269 pos = strlen(*d);
257 (*d)[pos++] = '\n'; 270 (*d)[pos++] = '\n';
258 } 271 }
259 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) { 272 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) {
260 printf("can't allocate mem for comment\n"); 273 printf("can't allocate mem for comment. ");
261 return 0; 274 return 0;
262 } 275 }
263 strcpy(*d + pos, s); 276 strcpy(*d + pos, s);
264 return 1; 277 return 1;
278 }
279
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;
265 } 307 }
266 308
267 static FILE *fp; 309 static FILE *fp;
268 static int line_num = 0; 310 static int line_num = 0;
269 static char *line; 311 static char *line;
275 static int line_pos; 317 static int line_pos;
276 int i; 318 int i;
277 char c; 319 char c;
278 320
279 if (max >= MAX_NR_TOKEN) { 321 if (max >= MAX_NR_TOKEN) {
280 printf("\nget_token(): max >= MAX_NR_TOKEN!\n"); 322 printf("get_token(): max >= MAX_NR_TOKEN!");
281 goto out_eof; 323 goto out_eof;
282 } 324 }
283 325
284 memset(token, 0x00, sizeof(*token) * max); 326 memset(token, 0x00, sizeof(*token) * max);
285 327
345 387
346 #ifdef DEBUG 388 #ifdef DEBUG
347 assert(cfgfile != NULL); 389 assert(cfgfile != NULL);
348 #endif 390 #endif
349 391
350 printf("Reading codec config file: %s\n", cfgfile); 392 printf("Reading %s: ", cfgfile);
351 393
352 if ((fp = fopen(cfgfile, "r")) == NULL) { 394 if ((fp = fopen(cfgfile, "r")) == NULL) {
353 printf("can't open '%s': %s\n", cfgfile, strerror(errno)); 395 printf("can't open '%s': %s\n", cfgfile, strerror(errno));
354 return NULL; 396 return NULL;
355 } 397 }
356 398
357 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { 399 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
358 perror("can't get memory for 'line'"); 400 printf("can't get memory for 'line': %s\n", strerror(errno));
359 return NULL; 401 return NULL;
360 } 402 }
361 403
362 /* 404 /*
363 * check if the cfgfile starts with 'audiocodec' or 405 * check if the cfgfile starts with 'audiocodec' or
364 * with 'videocodec' 406 * with 'videocodec'
365 */ 407 */
366 while ((tmp = get_token(1, 1)) == RET_EOL) 408 while ((tmp = get_token(1, 1)) == RET_EOL)
367 /* NOTHING */; 409 /* NOTHING */;
368 if (tmp != RET_EOF && (!strcmp(token[0], "audiocodec") || 410 if (tmp == RET_EOF)
369 !strcmp(token[0], "videocodec"))) 411 goto out;
412 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec"))
370 goto loop_enter; 413 goto loop_enter;
371 goto out; 414 goto err_out_parse_error;
372 415
373 while ((tmp = get_token(1, 1)) != RET_EOF) { 416 while ((tmp = get_token(1, 1)) != RET_EOF) {
374 if (tmp == RET_EOL) 417 if (tmp == RET_EOL)
375 continue; 418 continue;
376 if (!strcmp(token[0], "audiocodec") || 419 if (!strcmp(token[0], "audiocodec") ||
384 codecsp = &video_codecs; 427 codecsp = &video_codecs;
385 } else if (*token[0] == 'a') { 428 } else if (*token[0] == 'a') {
386 codec_type = TYPE_AUDIO; 429 codec_type = TYPE_AUDIO;
387 nr_codecsp = &nr_acodecs; 430 nr_codecsp = &nr_acodecs;
388 codecsp = &audio_codecs; 431 codecsp = &audio_codecs;
432 #ifdef DEBUG
389 } else { 433 } else {
390 printf("rohattkurva\n"); 434 printf("picsba\n");
391 goto err_out; 435 goto err_out;
436 #endif
392 } 437 }
393 if (!(*codecsp = (codecs_t *) realloc(*codecsp, 438 if (!(*codecsp = (codecs_t *) realloc(*codecsp,
394 sizeof(codecs_t) * (*nr_codecsp + 2)))) { 439 sizeof(codecs_t) * (*nr_codecsp + 2)))) {
395 perror("can't realloc '*codecsp'"); 440 printf("can't realloc '*codecsp': %s\n", strerror(errno));
396 goto err_out; 441 goto err_out;
397 } 442 }
398 codec=*codecsp + *nr_codecsp; 443 codec=*codecsp + *nr_codecsp;
399 ++*nr_codecsp; 444 ++*nr_codecsp;
400 memset(codec,0,sizeof(codecs_t)); 445 memset(codec,0,sizeof(codecs_t));
403 448
404 if (get_token(1, 1) < 0) 449 if (get_token(1, 1) < 0)
405 goto err_out_parse_error; 450 goto err_out_parse_error;
406 for (i = 0; i < *nr_codecsp - 1; i++) { 451 for (i = 0; i < *nr_codecsp - 1; i++) {
407 if (!strcmp(token[0], (*codecsp)[i].name)) { 452 if (!strcmp(token[0], (*codecsp)[i].name)) {
408 PRINT_LINENUM; 453 printf("codec name '%s' isn't unique", token[0]);
409 printf("codec name '%s' isn't unique\n", token[0]); 454 goto err_out_print_linenum;
410 goto err_out;
411 } 455 }
412 } 456 }
413 if (!(codec->name = strdup(token[0]))) { 457 if (!(codec->name = strdup(token[0]))) {
414 perror("can't strdup -> 'name'"); 458 printf("can't strdup -> 'name': %s\n", strerror(errno));
415 goto err_out; 459 goto err_out;
416 } 460 }
417 } else if (!strcmp(token[0], "info")) { 461 } else if (!strcmp(token[0], "info")) {
418 if (codec->info || get_token(1, 1) < 0) 462 if (codec->info || get_token(1, 1) < 0)
419 goto err_out_parse_error; 463 goto err_out_parse_error;
420 if (!(codec->info = strdup(token[0]))) { 464 if (!(codec->info = strdup(token[0]))) {
421 perror("can't strdup -> 'info'"); 465 printf("can't strdup -> 'info': %s\n", strerror(errno));
422 goto err_out; 466 goto err_out;
423 } 467 }
424 } else if (!strcmp(token[0], "comment")) { 468 } else if (!strcmp(token[0], "comment")) {
425 if (get_token(1, 1) < 0) 469 if (get_token(1, 1) < 0)
426 goto err_out_parse_error; 470 goto err_out_parse_error;
427 if (!add_comment(token[0], &codec->comment)) { 471 add_comment(token[0], &codec->comment);
428 PRINT_LINENUM;
429 printf("add_comment()-tel valami sux\n");
430 }
431 } else if (!strcmp(token[0], "fourcc")) { 472 } else if (!strcmp(token[0], "fourcc")) {
432 if (get_token(1, 2) < 0) 473 if (get_token(1, 2) < 0)
433 goto err_out_parse_error; 474 goto err_out_parse_error;
434 if (!add_to_fourcc(token[0], token[1], 475 if (!add_to_fourcc(token[0], token[1],
435 codec->fourcc, 476 codec->fourcc,
436 codec->fourccmap)) 477 codec->fourccmap))
437 goto err_out_parse_error; 478 goto err_out_print_linenum;
438 } else if (!strcmp(token[0], "format")) { 479 } else if (!strcmp(token[0], "format")) {
439 if (get_token(1, 1) < 0) 480 if (get_token(1, 1) < 0)
440 goto err_out_parse_error; 481 goto err_out_parse_error;
441 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap)) 482 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap))
442 goto err_out_parse_error; 483 goto err_out_print_linenum;
443 } else if (!strcmp(token[0], "driver")) { 484 } else if (!strcmp(token[0], "driver")) {
444 if (get_token(1, 1) < 0) 485 if (get_token(1, 1) < 0)
445 goto err_out_parse_error; 486 goto err_out_parse_error;
446 if ((codec->driver = get_driver(token[0],codec_type)) == -1) 487 if (!(codec->driver = get_driver(token[0],codec_type)))
447 goto err_out; 488 goto err_out_parse_error;
448 } else if (!strcmp(token[0], "dll")) { 489 } else if (!strcmp(token[0], "dll")) {
449 if (get_token(1, 1) < 0) 490 if (get_token(1, 1) < 0)
450 goto err_out_parse_error; 491 goto err_out_parse_error;
451 if (!(codec->dll = strdup(token[0]))) { 492 if (!(codec->dll = strdup(token[0]))) {
452 perror("can't strdup -> 'dll'"); 493 printf("can't strdup -> 'dll': %s\n", strerror(errno));
453 goto err_out; 494 goto err_out;
454 } 495 }
455 } else if (!strcmp(token[0], "guid")) { 496 } else if (!strcmp(token[0], "guid")) {
456 if (get_token(11, 11) < 0) 497 if (get_token(11, 11) < 0)
457 goto err_out_parse_error; 498 goto err_out_parse_error;
458 codec->guid.f1=strtoul(token[0],&endptr,0); 499 codec->guid.f1=strtoul(token[0],&endptr,0);
459 if (*endptr != '\0' && *endptr != ',') 500 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
501 *endptr != '\0')
460 goto err_out_parse_error; 502 goto err_out_parse_error;
461 codec->guid.f2=strtoul(token[1],&endptr,0); 503 codec->guid.f2=strtoul(token[1],&endptr,0);
462 if (*endptr != '\0' && *endptr != ',') 504 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
505 *endptr != '\0')
463 goto err_out_parse_error; 506 goto err_out_parse_error;
464 codec->guid.f3=strtoul(token[2],&endptr,0); 507 codec->guid.f3=strtoul(token[2],&endptr,0);
465 if (*endptr != '\0' && *endptr != ',') 508 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
509 *endptr != '\0')
466 goto err_out_parse_error; 510 goto err_out_parse_error;
467 for (i = 0; i < 8; i++) { 511 for (i = 0; i < 8; i++) {
468 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); 512 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0);
469 if (*endptr != '\0' && *endptr != ',') 513 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
514 *endptr != '\0')
470 goto err_out_parse_error; 515 goto err_out_parse_error;
471 } 516 }
472 } else if (!strcmp(token[0], "out")) { 517 } else if (!strcmp(token[0], "out")) {
473 if (get_token(1, 2) < 0) 518 if (get_token(1, 2) < 0)
474 goto err_out_parse_error; 519 goto err_out_parse_error;
475 if (!add_to_out(token[0], token[1], codec->outfmt, 520 if (!add_to_out(token[0], token[1], codec->outfmt,
476 codec->outflags)) 521 codec->outflags))
477 goto err_out; 522 goto err_out_print_linenum;
478 } else if (!strcmp(token[0], "flags")) { 523 } else if (!strcmp(token[0], "flags")) {
479 if (get_token(1, 1) < 0) 524 if (get_token(1, 1) < 0)
480 goto err_out_parse_error; 525 goto err_out_parse_error;
481 if (!strcmp(token[0], "seekable")) 526 if (!strcmp(token[0], "seekable"))
482 codec->flags |= CODECS_FLAG_SEEKABLE; 527 codec->flags |= CODECS_FLAG_SEEKABLE;
493 codec->status = CODECS_STATUS_UNTESTED; 538 codec->status = CODECS_STATUS_UNTESTED;
494 else if (!strcasecmp(token[0], "buggy")) 539 else if (!strcasecmp(token[0], "buggy"))
495 codec->status = CODECS_STATUS_PROBLEMS; 540 codec->status = CODECS_STATUS_PROBLEMS;
496 else 541 else
497 goto err_out_parse_error; 542 goto err_out_parse_error;
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;
498 } else 548 } else
499 goto err_out_parse_error; 549 goto err_out_parse_error;
500 } 550 }
501 if (!validate_codec(codec, codec_type)) 551 if (!validate_codec(codec, codec_type))
502 goto err_out_not_valid; 552 goto err_out_not_valid;
553 printf("%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs);
503 video_codecs[nr_vcodecs].name = NULL; 554 video_codecs[nr_vcodecs].name = NULL;
504 audio_codecs[nr_acodecs].name = NULL; 555 audio_codecs[nr_acodecs].name = NULL;
505 ret_codecs[0] = video_codecs; 556 ret_codecs[0] = video_codecs;
506 ret_codecs[1] = audio_codecs; 557 ret_codecs[1] = audio_codecs;
507 out: 558 out:
508 free(line); 559 free(line);
509 fclose(fp); 560 fclose(fp);
510 return ret_codecs; 561 return ret_codecs;
511 err_out_parse_error: 562 err_out_parse_error:
563 printf("parse error");
564 err_out_print_linenum:
512 PRINT_LINENUM; 565 PRINT_LINENUM;
513 printf("parse error\n");
514 err_out: 566 err_out:
515 printf("\nOops\n");
516 if (audio_codecs) 567 if (audio_codecs)
517 free(audio_codecs); 568 free(audio_codecs);
518 if (video_codecs) 569 if (video_codecs)
519 free(video_codecs); 570 free(video_codecs);
520 free(line); 571 free(line);
521 free(fp); 572 free(fp);
522 return NULL; 573 return NULL;
523 err_out_not_valid: 574 err_out_not_valid:
524 PRINT_LINENUM; 575 printf("codec is not definied correctly");
525 printf("codec is not definied correctly\n"); 576 goto err_out_print_linenum;
526 goto err_out;
527 } 577 }
528 578
529 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, 579 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
530 codecs_t *start) 580 codecs_t *start)
531 { 581 {
599 printf("\n============== codec %02d ===============\n",i); 649 printf("\n============== codec %02d ===============\n",i);
600 printf("name='%s'\n",c->name); 650 printf("name='%s'\n",c->name);
601 printf("info='%s'\n",c->info); 651 printf("info='%s'\n",c->info);
602 printf("comment='%s'\n",c->comment); 652 printf("comment='%s'\n",c->comment);
603 printf("dll='%s'\n",c->dll); 653 printf("dll='%s'\n",c->dll);
604 printf("flags=%X driver=%d\n",c->flags,c->driver); 654 printf("flags=%X driver=%d status=%d cpuflags=%d\n",
655 c->flags, c->driver, c->status, c->cpuflags);
605 656
606 for(j=0;j<CODECS_MAX_FOURCC;j++){ 657 for(j=0;j<CODECS_MAX_FOURCC;j++){
607 if(c->fourcc[j]!=0xFFFFFFFF){ 658 if(c->fourcc[j]!=0xFFFFFFFF){
608 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],&c->fourcc[j],c->fourccmap[j],&c->fourccmap[j]); 659 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]);
609 } 660 }
610 } 661 }
611 662
612 for(j=0;j<CODECS_MAX_OUTFMT;j++){ 663 for(j=0;j<CODECS_MAX_OUTFMT;j++){
613 if(c->outfmt[j]!=0xFFFFFFFF){ 664 if(c->outfmt[j]!=0xFFFFFFFF){
614 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],&c->outfmt[j],c->outflags[j]); 665 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]);
615 } 666 }
616 } 667 }
617 668
618 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); 669 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3);
619 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); 670 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]);