lots of changes

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@320 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
szabii 2001-04-09 20:21:07 +00:00
parent 7087dc33ee
commit d90e255e2c
2 changed files with 195 additions and 198 deletions

View File

@ -1,8 +1,18 @@
/*
* codec.conf parser
* by Szabolcs Berecz <szabi@inf.elte.hu>
* (C) 2001
*/
//#define DEBUG #define DEBUG
#define PRINT_LINENUM
// printf("%s(%d): ", cfgfile, line_num)
#ifdef DEBUG
#define DBG(str, args...) printf(str, ##args)
#else
#define DBG(str, args...) do {} while (0)
#endif
#define PRINT_LINENUM printf("%s(%d): ", cfgfile, line_num)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -16,7 +26,7 @@
#include "libvo/video_out.h" #include "libvo/video_out.h"
#include "codec-cfg.h" #include "codec-cfg.h"
#define MALLOC_ADD 10 #define MAX_NR_TOKEN 16
#define MAX_LINE_LEN 1000 #define MAX_LINE_LEN 1000
@ -32,21 +42,28 @@
#define RET_EOF -1 #define RET_EOF -1
#define RET_EOL -2 #define RET_EOL -2
#define RET_OK 0
static FILE *fp; static FILE *fp;
static int line_num = 0; static int line_num = 0;
static int line_pos; /* line pos */ static int line_pos; /* line pos */
static int firstdef = 1;
static char *line; static char *line;
static char *token; static char *token[MAX_NR_TOKEN];
static codecs_t *codecs=NULL; static codecs_t *codecs=NULL;
static int nr_codecs = 0; static int nr_codecs = 0;
static int get_token(void) static int get_token(int min, int max)
{ {
static int read_nextline = 1; static int read_nextline = 1;
int i;
char c;
if (max >= MAX_NR_TOKEN) {
printf("\nget_token(): max >= MAX_NR_TOKEN!\n");
goto ret_eof;
}
memset(token, 0x00, sizeof(*token) * max);
if (read_nextline) { if (read_nextline) {
if (!fgets(line, MAX_LINE_LEN, fp)) if (!fgets(line, MAX_LINE_LEN, fp))
@ -55,106 +72,103 @@ static int get_token(void)
++line_num; ++line_num;
read_nextline = 0; read_nextline = 0;
} }
while (isspace(line[line_pos])) for (i = 0; i < max; i++) {
++line_pos; while (isspace(line[line_pos]))
if (line[line_pos] == '\0' || line[line_pos] == '#' || ++line_pos;
line[line_pos] == ';') { if (line[line_pos] == '\0' || line[line_pos] == '#' ||
read_nextline = 1; line[line_pos] == ';') {
goto ret_eol;
}
token = line + line_pos;
if (line[line_pos] == '"') {
token++;
for (/* NOTHING */; line[++line_pos] != '"' && line[line_pos];)
/* NOTHING */;
if (!line[line_pos]) {
read_nextline = 1; read_nextline = 1;
if (i >= min)
goto ret_ok;
goto ret_eol; goto ret_eol;
} }
} else { token[i] = line + line_pos;
for (/* NOTHING */; !isspace(line[line_pos]); line_pos++) c = line[line_pos];
/* NOTHING */; if (c == '"' || c == '\'') {
token[i]++;
while (line[++line_pos] != c && line[line_pos])
/* NOTHING */;
} else {
for (/* NOTHING */; !isspace(line[line_pos]) &&
line[line_pos]; line_pos++)
/* NOTHING */;
}
if (!line[line_pos]) {
read_nextline = 1;
if (i >= min - 1)
goto ret_ok;
goto ret_eol;
}
line[line_pos] = '\0';
line_pos++;
} }
line[line_pos] = '\0'; ret_ok:
line_pos++; return i;
#ifdef DEBUG
printf("get_token ok\n");
#endif
return RET_OK;
ret_eof: ret_eof:
#ifdef DEBUG
printf("get_token EOF\n");
#endif
token = NULL;
return RET_EOF; return RET_EOF;
ret_eol: ret_eol:
#ifdef DEBUG
printf("get_token EOL\n");
#endif
token = NULL;
return RET_EOL; return RET_EOL;
} }
static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc, static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc,
unsigned int *map) unsigned int *map)
{ {
int i; int i, j, freeslots;
char **aliasp; char **aliasp;
unsigned int tmp;
/* find first unused slot */ /* find first unused slot */
for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
/* NOTHING */; /* NOTHING */;
if (i == CODECS_MAX_FOURCC) { freeslots = CODECS_MAX_FOURCC - i;
printf("too many fourcc...\n"); if (!freeslots)
return 0; goto too_many_error_out;
}
#if 1 aliasp = (alias) ? &alias : &s;
if (alias) {
do {
fourcc[i] = *((unsigned int *) s);
map[i] = *((unsigned int *) alias);
s += 4;
i++;
} while (*(s++) == ',');
} else {
do {
fourcc[i] = *((unsigned int *) s);
map[i] = *((unsigned int *) s);
s += 4;
i++;
} while (*(s++) == ',');
}
#else
if (alias)
aliasp = &alias;
else
aliasp = &s;
do { do {
fourcc[i] = *((unsigned int *) s); tmp = *((unsigned int *) s);
map[i++] = *((unsigned int *) (*aliasp)); for (j = 0; j < i; j++)
if (tmp == fourcc[j])
goto duplicated_error_out;
fourcc[i] = tmp;
map[i] = *((unsigned int *) (*aliasp));
s += 4; s += 4;
} while (*(s++) == ','); i++;
#endif } while ((*(s++) == ',') && --freeslots);
if (!freeslots)
goto too_many_error_out;
if (*(--s) != '\0') if (*(--s) != '\0')
return 0; return 0;
return 1; return 1;
duplicated_error_out:
printf("\nduplicated fourcc/format\n");
return 0;
too_many_error_out:
printf("\ntoo many fourcc/format...\n");
return 0;
} }
static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap) static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap)
{ {
// printf("\n-----[%s][%s]-----\n",s,format); //printf("\n-----[%s][%s]-----\n",s,format);
int i; int i, j;
/* find first unused slot */ /* find first unused slot */
for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
/* NOTHING */; /* NOTHING */;
if (i == CODECS_MAX_FOURCC) { if (i == CODECS_MAX_FOURCC) {
printf("too many fourcc...\n"); printf("\ntoo many fourcc/format...\n");
return 0; return 0;
} }
fourcc[i]=fourccmap[i]=strtoul(s,NULL,0); fourcc[i]=fourccmap[i]=strtoul(s,NULL,0);
for (j = 0; j < i; j++)
if (fourcc[j] == fourcc[i]) {
printf("\nduplicated fourcc/format\n");
return 0;
}
return 1; return 1;
} }
@ -199,17 +213,16 @@ static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt,
NULL NULL
}; };
int i, j; int i, j, freeslots;
unsigned char flags; unsigned char flags;
for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++)
/* NOTHING */; /* NOTHING */;
if (i == CODECS_MAX_FOURCC) { freeslots = CODECS_MAX_OUTFMT - i;
printf("too many out...\n"); if (!freeslots)
return 0; goto too_many_error_out;
}
flags = 0; //get_flags(sflags); flags = 0;
if(sflags) do { if(sflags) do {
for (j = 0; flagstr[j] != NULL; j++) for (j = 0; flagstr[j] != NULL; j++)
if (!strncmp(sflags, flagstr[j], strlen(flagstr[j]))) if (!strncmp(sflags, flagstr[j], strlen(flagstr[j])))
@ -218,7 +231,6 @@ static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt,
flags|=(1<<j); flags|=(1<<j);
sflags+=strlen(flagstr[j]); sflags+=strlen(flagstr[j]);
} while (*(sflags++) == ','); } while (*(sflags++) == ',');
do { do {
for (j = 0; fmtstr[j] != NULL; j++) for (j = 0; fmtstr[j] != NULL; j++)
@ -230,10 +242,17 @@ static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt,
outflags[i] = flags; outflags[i] = flags;
++i; ++i;
sfmt+=strlen(fmtstr[j]); sfmt+=strlen(fmtstr[j]);
} while (*(sfmt++) == ','); } while ((*(sfmt++) == ',') && --freeslots);
if (!freeslots)
goto too_many_error_out;
if (*(--sfmt) != '\0') return 0; if (*(--sfmt) != '\0') return 0;
return 1; return 1;
too_many_error_out:
printf("\ntoo many out...\n");
return 0;
} }
static short get_driver(char *s,int audioflag) static short get_driver(char *s,int audioflag)
@ -263,16 +282,35 @@ static short get_driver(char *s,int audioflag)
return 0; return 0;
} }
static int valid_codec(codecs_t *codec)
{
#warning FIXME mi is kell egy codec-be?
return 1;
}
static int add_comment(char *s, char **d)
{
int pos;
if (!*d)
pos = 0;
else {
pos = strlen(*d);
(*d)[pos++] = '\n';
}
if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) {
printf("can't allocate mem for comment\n");
return 0;
}
strcpy(*d + pos, s);
return 1;
}
codecs_t *parse_codec_cfg(char *cfgfile) codecs_t *parse_codec_cfg(char *cfgfile)
{ {
codecs_t *codec = NULL; // current codec
// codecs_t *codecs = NULL; // array of codecs
codecs_t *codec = NULL; // currect codec
int free_slots = 0;
int tmp, i; int tmp, i;
int state = 0; int state = 0;
char *param1;
#ifdef DEBUG #ifdef DEBUG
assert(cfgfile != NULL); assert(cfgfile != NULL);
@ -289,180 +327,141 @@ codecs_t *parse_codec_cfg(char *cfgfile)
perror("parse_codec_cfg: can't get memory for 'line'"); perror("parse_codec_cfg: can't get memory for 'line'");
return NULL; return NULL;
} }
line_pos = 0;
line[0] = '\0'; /* forces get_token to read next line */
for (;;) { while ((tmp = get_token(1, 1)) != RET_EOF) {
tmp = get_token();
if (tmp == RET_EOF)
goto eof_out;
if (tmp == RET_EOL) if (tmp == RET_EOL)
continue; continue;
if (!strcmp(token, "audiocodec") || !strcmp(token, "videocodec")) { if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) {
PRINT_LINENUM; if (nr_codecs)
if (!valid_codec(codec))
goto not_valid_error_out;
if (!(codecs = (codecs_t *) realloc(codecs, if (!(codecs = (codecs_t *) realloc(codecs,
sizeof(codecs_t) * (nr_codecs + 1)))) { sizeof(codecs_t) * (nr_codecs + 1)))) {
perror("parse_codec_cfg: can't realloc 'codecs'"); perror("parse_codec_cfg: can't realloc 'codecs'");
goto err_out; goto err_out;
} }
codec=&codecs[nr_codecs]; codec=&codecs[nr_codecs];
nr_codecs++; nr_codecs++;
memset(codec,0,sizeof(codecs_t)); memset(codec,0,sizeof(codecs_t));
memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
state = 0; state = 0;
if (*token == 'a') { /* audiocodec */ if (*token[0] == 'a') { /* audiocodec */
//printf("audio");
codec->flags |= CODECS_FLAG_AUDIO; codec->flags |= CODECS_FLAG_AUDIO;
} else if (*token == 'v') { /* videocodec */ } else if (*token[0] == 'v') { /* videocodec */
//printf("video");
codec->flags &= !CODECS_FLAG_AUDIO; codec->flags &= !CODECS_FLAG_AUDIO;
} else { } else {
printf("itt valami nagyon el van baszva\n"); printf("itt valami nagyon el van baszva\n");
goto err_out; goto err_out;
} }
if (get_token() < 0) if (get_token(1, 1) < 0)
goto parse_error_out; goto parse_error_out;
codec->name = strdup(token); for (i = 0; i < nr_codecs - 1; i++) {
#warning audio meg videocodecnek lehet ugyanaz a neve?
if ((codec->flags & CODECS_FLAG_AUDIO) !=
(codecs[i].flags & CODECS_FLAG_AUDIO))
continue;
if (!strcmp(token[0], codecs[i].name)) {
PRINT_LINENUM;
printf("codec name '%s' isn't unique\n", token[0]);
goto err_out;
}
}
codec->name = strdup(token[0]);
state |= GOT_NAME; state |= GOT_NAME;
//printf(" %s\n", codec->name); } else if (!strcmp(token[0], "info")) {
} else if (!strcmp(token, "info")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (state & GOT_INFO || get_token(1, 1) < 0)
//printf("info");
if (state & GOT_INFO || get_token() < 0)
goto parse_error_out; goto parse_error_out;
codec->info = strdup(token); codec->info = strdup(token[0]);
state |= GOT_INFO; state |= GOT_INFO;
//printf(" %s\n", codec->info); } else if (!strcmp(token[0], "comment")) {
} else if (!strcmp(token, "comment")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (get_token(1, 1) < 0)
//printf("comment");
if (get_token() < 0)
goto parse_error_out; goto parse_error_out;
#if 1 if (!add_comment(token[0], &codec->comment)) {
if (!codec->comment) PRINT_LINENUM;
codec->comment = strdup(token); printf("add_comment()-tel valami sux\n");
//printf(" %s\n", codec->comment); }
#else } else if (!strcmp(token[0], "fourcc")) {
add_comment(token, &codec->comment);
printf(" FIXMEEEEEEEEEEEEEEE\n");
#endif
} else if (!strcmp(token, "fourcc")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (get_token(1, 2) < 0)
//printf("fourcc");
// if (codec->flags & CODECS_FLAG_AUDIO) {
// printf("\n'fourcc' in audiocodec definition!\n");
// goto err_out;
// }
if (get_token() < 0)
goto parse_error_out; goto parse_error_out;
param1 = strdup(token); if (!add_to_fourcc(token[0], token[1],
get_token();
if (!add_to_fourcc(param1, token,
codec->fourcc, codec->fourcc,
codec->fourccmap)) codec->fourccmap))
goto err_out; goto parse_error_out;
state |= GOT_FOURCC; state |= GOT_FOURCC;
//printf(" %s: %s\n", param1, token); } else if (!strcmp(token[0], "format")) {
free(param1);
} else if (!strcmp(token, "format")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (get_token(1, 1) < 0)
//printf("format"); goto parse_error_out;
// if (!(codec->flags & CODECS_FLAG_AUDIO)) { if (!add_to_format(token[0], codec->fourcc,codec->fourccmap))
// printf("\n'format' in videocodec definition!\n");
// goto err_out;
// }
if (get_token() < 0)
goto parse_error_out; goto parse_error_out;
if (!add_to_format(token, codec->fourcc,codec->fourccmap))
goto err_out;
state |= GOT_FORMAT; state |= GOT_FORMAT;
//printf(" %s\n", token); } else if (!strcmp(token[0], "driver")) {
} else if (!strcmp(token, "driver")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (get_token(1, 1) < 0)
//printf("driver");
if (get_token() < 0)
goto parse_error_out; goto parse_error_out;
if ((codec->driver = get_driver(token,codec->flags&CODECS_FLAG_AUDIO)) == -1) if ((codec->driver = get_driver(token[0],codec->flags&CODECS_FLAG_AUDIO)) == -1)
goto err_out; goto err_out;
//printf(" %s\n", token); } else if (!strcmp(token[0], "dll")) {
} else if (!strcmp(token, "dll")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (get_token(1, 1) < 0)
//printf("dll");
if (get_token() < 0)
goto parse_error_out; goto parse_error_out;
codec->dll = strdup(token); codec->dll = strdup(token[0]);
//printf(" %s\n", codec->dll); } else if (!strcmp(token[0], "guid")) {
} else if (!strcmp(token, "guid")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (get_token(11, 11) < 0) goto parse_error_out;
//printf("guid"); codec->guid.f1=strtoul(token[0],NULL,0);
if (get_token() < 0) goto parse_error_out; codec->guid.f2=strtoul(token[1],NULL,0);
//printf("'%s'",token); codec->guid.f3=strtoul(token[2],NULL,0);
codec->guid.f1=strtoul(token,NULL,0);
if (get_token() < 0) goto parse_error_out;
codec->guid.f2=strtoul(token,NULL,0);
if (get_token() < 0) goto parse_error_out;
codec->guid.f3=strtoul(token,NULL,0);
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (get_token() < 0) goto parse_error_out; codec->guid.f4[i]=strtoul(token[i + 3],NULL,0);
codec->guid.f4[i]=strtoul(token,NULL,0);
} }
} else if (!strcmp(token, "out")) { } else if (!strcmp(token[0], "out")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (get_token(1, 2) < 0)
//printf("out");
if (get_token() < 0)
goto parse_error_out; goto parse_error_out;
param1 = strdup(token); if (!add_to_out(token[0], token[1], codec->outfmt,
get_token();
if (!add_to_out(param1, token, codec->outfmt,
codec->outflags)) codec->outflags))
goto err_out; goto err_out;
//printf(" %s: %s\n", param1, token); } else if (!strcmp(token[0], "flags")) {
free(param1);
} else if (!strcmp(token, "flags")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
PRINT_LINENUM; if (get_token(1, 1) < 0)
//printf("flags");
if (get_token() < 0)
goto parse_error_out; goto parse_error_out;
//printf(" %s\n", token); #warning FIXME flags meg nincs implementalva...
} else if (!strcmp(token, "status")) { printf("\n\nUssetek!!!\n\n");
} else if (!strcmp(token[0], "status")) {
if (!(state & GOT_NAME)) if (!(state & GOT_NAME))
goto parse_error_out; goto parse_error_out;
if (get_token() < 0) if (get_token(1, 1) < 0)
goto parse_error_out; goto parse_error_out;
if (!strcasecmp(token, "rulz")) if (!strcasecmp(token[0], "rulz"))
codec->status = CODECS_STATUS_WORKING; codec->status = CODECS_STATUS_WORKING;
else if (!strcasecmp(token, "suxx")) else if (!strcasecmp(token[0], "suxx"))
codec->status = CODECS_STATUS_NOT_WORKING; codec->status = CODECS_STATUS_NOT_WORKING;
else if (!strcasecmp(token, "checkthiz")) else if (!strcasecmp(token[0], "checkthiz"))
codec->status = CODECS_STATUS_UNTESTED; codec->status = CODECS_STATUS_UNTESTED;
else if (!strcasecmp(token, "notsogood")) else if (!strcasecmp(token[0], "notsogood"))
codec->status = CODECS_STATUS_PROBLEMS; codec->status = CODECS_STATUS_PROBLEMS;
else else
goto parse_error_out; goto parse_error_out;
} else } else
goto parse_error_out; goto parse_error_out;
} }
if (!valid_codec(codec))
goto not_valid_error_out;
out: out:
free(line); free(line);
fclose(fp); fclose(fp);
@ -476,9 +475,10 @@ err_out:
free(codecs); free(codecs);
codecs = NULL; codecs = NULL;
goto out; goto out;
eof_out: not_valid_error_out:
/* FIXME teljes az utolso config?? */ PRINT_LINENUM;
goto out; printf("codec is not definied correctly\n");
goto err_out;
} }
codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,int audioflag){ codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,int audioflag){
@ -504,7 +504,8 @@ int main(void)
codecs_t *codecs; codecs_t *codecs;
int i,j; int i,j;
codecs = parse_codec_cfg("DOCS/codecs.conf"); if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
return 0;
printf("total %d codecs parsed\n",nr_codecs); printf("total %d codecs parsed\n",nr_codecs);
for(i=0;i<nr_codecs;i++){ for(i=0;i<nr_codecs;i++){
@ -528,7 +529,7 @@ int main(void)
} }
} }
printf("GUID: %08X %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3);
for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]);
printf("\n"); printf("\n");

View File

@ -1,8 +1,6 @@
#ifndef __CODEC_CFG_H #ifndef __CODEC_CFG_H
#define __CODEC_CFG_H #define __CODEC_CFG_H
//#include <inttypes.h>
#ifndef IMGFMT_YV12 #ifndef IMGFMT_YV12
#define IMGFMT_YV12 0x32315659 #define IMGFMT_YV12 0x32315659
#define IMGFMT_YUY2 (('2'<<24)|('Y'<<16)|('U'<<8)|'Y') #define IMGFMT_YUY2 (('2'<<24)|('Y'<<16)|('U'<<8)|'Y')
@ -30,7 +28,6 @@
#define CODECS_STATUS_WORKING 2 #define CODECS_STATUS_WORKING 2
//#warning nem kellene ket typedef GUID-nak...
typedef struct { typedef struct {
unsigned long f1; unsigned long f1;
unsigned short f2; unsigned short f2;
@ -38,7 +35,6 @@ typedef struct {
unsigned char f4[8]; unsigned char f4[8];
} GUID; } GUID;
/* I just rearranged, to use less memory... */
typedef struct { typedef struct {
unsigned int fourcc[CODECS_MAX_FOURCC]; unsigned int fourcc[CODECS_MAX_FOURCC];
unsigned int fourccmap[CODECS_MAX_FOURCC]; unsigned int fourccmap[CODECS_MAX_FOURCC];