2001-04-09 20:21:07 +00:00
|
|
|
/*
|
|
|
|
* codec.conf parser
|
|
|
|
* by Szabolcs Berecz <szabi@inf.elte.hu>
|
|
|
|
* (C) 2001
|
2002-02-12 17:52:30 +00:00
|
|
|
*
|
|
|
|
* to compile tester app: gcc -Iloader/ -DTESTING -o codec-cfg codec-cfg.c
|
|
|
|
* to compile CODECS2HTML: gcc -Iloader/ -DCODECS2HTML -o codecs2html codecs-cfg.c
|
|
|
|
*
|
|
|
|
* TODO: implement informat in CODECS2HTML too
|
2001-04-09 20:21:07 +00:00
|
|
|
*/
|
2001-04-07 21:27:57 +00:00
|
|
|
|
2001-04-09 20:21:07 +00:00
|
|
|
#define DEBUG
|
2001-04-07 21:27:57 +00:00
|
|
|
|
2001-12-27 18:38:10 +00:00
|
|
|
//disable asserts
|
|
|
|
#define NDEBUG
|
|
|
|
|
2001-04-06 23:20:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2002-03-23 18:59:36 +00:00
|
|
|
#include "config.h"
|
2002-05-02 11:00:16 +00:00
|
|
|
#include "mp_msg.h"
|
2002-03-23 18:59:36 +00:00
|
|
|
|
2001-10-02 22:37:28 +00:00
|
|
|
// for mmioFOURCC:
|
2001-07-12 15:10:06 +00:00
|
|
|
#include "wine/avifmt.h"
|
|
|
|
|
2001-04-14 17:55:20 +00:00
|
|
|
#include "libvo/img_format.h"
|
2001-04-06 23:20:46 +00:00
|
|
|
#include "codec-cfg.h"
|
|
|
|
|
2002-05-02 11:00:16 +00:00
|
|
|
#define PRINT_LINENUM mp_msg(MSGT_CODECCFG,MSGL_ERR," at line %d\n", line_num)
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
#define MAX_NR_TOKEN 16
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
#define MAX_LINE_LEN 1000
|
2001-04-06 23:20:46 +00:00
|
|
|
|
|
|
|
#define RET_EOF -1
|
|
|
|
#define RET_EOL -2
|
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
#define TYPE_VIDEO 0
|
|
|
|
#define TYPE_AUDIO 1
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2001-04-07 21:27:57 +00:00
|
|
|
static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc,
|
2001-04-06 23:20:46 +00:00
|
|
|
unsigned int *map)
|
|
|
|
{
|
2001-04-09 20:21:07 +00:00
|
|
|
int i, j, freeslots;
|
|
|
|
unsigned int tmp;
|
2001-04-06 23:20:46 +00:00
|
|
|
|
|
|
|
/* find first unused slot */
|
|
|
|
for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
|
|
|
|
/* NOTHING */;
|
2001-04-09 20:21:07 +00:00
|
|
|
freeslots = CODECS_MAX_FOURCC - i;
|
|
|
|
if (!freeslots)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_too_many;
|
2001-04-09 20:21:07 +00:00
|
|
|
|
2001-04-06 23:20:46 +00:00
|
|
|
do {
|
2001-07-12 15:10:06 +00:00
|
|
|
tmp = mmioFOURCC(s[0], s[1], s[2], s[3]);
|
2001-04-09 20:21:07 +00:00
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
if (tmp == fourcc[j])
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_duplicated;
|
2001-04-09 20:21:07 +00:00
|
|
|
fourcc[i] = tmp;
|
2001-11-04 14:00:53 +00:00
|
|
|
map[i] = alias ? mmioFOURCC(alias[0], alias[1], alias[2], alias[3]) : tmp;
|
2001-04-06 23:20:46 +00:00
|
|
|
s += 4;
|
2001-04-09 20:21:07 +00:00
|
|
|
i++;
|
|
|
|
} while ((*(s++) == ',') && --freeslots);
|
|
|
|
|
|
|
|
if (!freeslots)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_too_many;
|
2001-04-06 23:20:46 +00:00
|
|
|
if (*(--s) != '\0')
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-06 23:20:46 +00:00
|
|
|
return 1;
|
2001-04-10 20:09:23 +00:00
|
|
|
err_out_duplicated:
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"duplicated fourcc/format");
|
2001-04-09 20:21:07 +00:00
|
|
|
return 0;
|
2001-04-10 20:09:23 +00:00
|
|
|
err_out_too_many:
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"too many fourcc/format...");
|
2001-04-11 20:55:14 +00:00
|
|
|
return 0;
|
|
|
|
err_out_parse_error:
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"parse error");
|
2001-04-09 20:21:07 +00:00
|
|
|
return 0;
|
2001-04-06 23:20:46 +00:00
|
|
|
}
|
|
|
|
|
2001-04-07 21:27:57 +00:00
|
|
|
static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap)
|
2001-04-06 23:20:46 +00:00
|
|
|
{
|
2001-04-09 20:21:07 +00:00
|
|
|
int i, j;
|
2001-04-11 20:55:14 +00:00
|
|
|
char *endptr;
|
2001-04-06 23:56:42 +00:00
|
|
|
|
2001-04-07 00:51:38 +00:00
|
|
|
/* find first unused slot */
|
|
|
|
for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
|
|
|
|
/* NOTHING */;
|
|
|
|
if (i == CODECS_MAX_FOURCC) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"too many fourcc/format...");
|
2001-04-06 23:20:46 +00:00
|
|
|
return 0;
|
2001-04-07 00:51:38 +00:00
|
|
|
}
|
2001-04-09 20:21:07 +00:00
|
|
|
|
2001-04-11 20:55:14 +00:00
|
|
|
fourcc[i]=fourccmap[i]=strtoul(s,&endptr,0);
|
|
|
|
if (*endptr != '\0') {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"parse error");
|
2001-04-11 20:55:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-04-09 20:21:07 +00:00
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
if (fourcc[j] == fourcc[i]) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"duplicated fourcc/format");
|
2001-04-09 20:21:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-04-07 00:51:38 +00:00
|
|
|
|
2001-04-06 23:20:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2001-04-07 00:51:38 +00:00
|
|
|
|
2001-04-14 17:55:20 +00:00
|
|
|
static struct {
|
|
|
|
const char *name;
|
|
|
|
const unsigned int num;
|
|
|
|
} fmt_table[] = {
|
2001-04-14 21:09:25 +00:00
|
|
|
{"YV12", IMGFMT_YV12},
|
|
|
|
{"I420", IMGFMT_I420},
|
|
|
|
{"IYUV", IMGFMT_IYUV},
|
|
|
|
|
|
|
|
{"YUY2", IMGFMT_YUY2},
|
|
|
|
{"UYVY", IMGFMT_UYVY},
|
|
|
|
{"YVYU", IMGFMT_YVYU},
|
|
|
|
|
|
|
|
{"RGB8", IMGFMT_RGB|8},
|
|
|
|
{"RGB15", IMGFMT_RGB|15},
|
|
|
|
{"RGB16", IMGFMT_RGB|16},
|
|
|
|
{"RGB24", IMGFMT_RGB|24},
|
|
|
|
{"RGB32", IMGFMT_RGB|32},
|
|
|
|
{"BGR8", IMGFMT_BGR|8},
|
|
|
|
{"BGR15", IMGFMT_BGR|15},
|
|
|
|
{"BGR16", IMGFMT_BGR|16},
|
|
|
|
{"BGR24", IMGFMT_BGR|24},
|
|
|
|
{"BGR32", IMGFMT_BGR|32},
|
2001-09-08 20:48:02 +00:00
|
|
|
|
|
|
|
{"MPES", IMGFMT_MPEGPES},
|
2001-04-14 21:09:25 +00:00
|
|
|
{NULL, 0}
|
2001-04-06 23:20:46 +00:00
|
|
|
};
|
2001-04-14 17:55:20 +00:00
|
|
|
|
2001-04-24 02:14:14 +00:00
|
|
|
|
2002-02-12 17:33:27 +00:00
|
|
|
static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt,
|
2001-04-24 02:14:14 +00:00
|
|
|
unsigned char *outflags)
|
|
|
|
{
|
|
|
|
|
2001-04-06 23:56:42 +00:00
|
|
|
static char *flagstr[] = {
|
|
|
|
"flip",
|
|
|
|
"noflip",
|
|
|
|
"yuvhack",
|
2002-03-21 19:53:31 +00:00
|
|
|
"query",
|
2002-05-16 21:50:38 +00:00
|
|
|
"static",
|
2001-04-06 23:56:42 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2001-04-09 20:21:07 +00:00
|
|
|
int i, j, freeslots;
|
2001-04-06 23:20:46 +00:00
|
|
|
unsigned char flags;
|
|
|
|
|
|
|
|
for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++)
|
|
|
|
/* NOTHING */;
|
2001-04-09 20:21:07 +00:00
|
|
|
freeslots = CODECS_MAX_OUTFMT - i;
|
|
|
|
if (!freeslots)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_too_many;
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2001-04-09 20:21:07 +00:00
|
|
|
flags = 0;
|
2001-04-11 20:55:14 +00:00
|
|
|
if(sflags) {
|
|
|
|
do {
|
|
|
|
for (j = 0; flagstr[j] != NULL; j++)
|
|
|
|
if (!strncmp(sflags, flagstr[j],
|
|
|
|
strlen(flagstr[j])))
|
|
|
|
break;
|
|
|
|
if (flagstr[j] == NULL)
|
|
|
|
goto err_out_parse_error;
|
|
|
|
flags|=(1<<j);
|
|
|
|
sflags+=strlen(flagstr[j]);
|
|
|
|
} while (*(sflags++) == ',');
|
|
|
|
|
|
|
|
if (*(--sflags) != '\0')
|
|
|
|
goto err_out_parse_error;
|
|
|
|
}
|
2001-04-06 23:20:46 +00:00
|
|
|
|
|
|
|
do {
|
2001-04-14 17:55:20 +00:00
|
|
|
for (j = 0; fmt_table[j].name != NULL; j++)
|
|
|
|
if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name)))
|
2001-04-06 23:20:46 +00:00
|
|
|
break;
|
2001-04-14 17:55:20 +00:00
|
|
|
if (fmt_table[j].name == NULL)
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-14 17:55:20 +00:00
|
|
|
outfmt[i] = fmt_table[j].num;
|
2001-04-06 23:20:46 +00:00
|
|
|
outflags[i] = flags;
|
2001-04-06 23:56:42 +00:00
|
|
|
++i;
|
2001-04-14 17:55:20 +00:00
|
|
|
sfmt+=strlen(fmt_table[j].name);
|
2001-04-09 20:21:07 +00:00
|
|
|
} while ((*(sfmt++) == ',') && --freeslots);
|
|
|
|
|
|
|
|
if (!freeslots)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_too_many;
|
2001-04-09 20:21:07 +00:00
|
|
|
|
2001-04-11 20:55:14 +00:00
|
|
|
if (*(--sfmt) != '\0')
|
|
|
|
goto err_out_parse_error;
|
2001-04-06 23:56:42 +00:00
|
|
|
|
2001-04-06 23:20:46 +00:00
|
|
|
return 1;
|
2001-04-10 20:09:23 +00:00
|
|
|
err_out_too_many:
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"too many out...");
|
2001-04-11 20:55:14 +00:00
|
|
|
return 0;
|
|
|
|
err_out_parse_error:
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"parse error");
|
2001-04-09 20:21:07 +00:00
|
|
|
return 0;
|
2001-04-06 23:20:46 +00:00
|
|
|
}
|
|
|
|
|
2001-04-07 21:27:57 +00:00
|
|
|
static short get_driver(char *s,int audioflag)
|
2001-04-06 23:20:46 +00:00
|
|
|
{
|
2001-04-07 01:03:24 +00:00
|
|
|
static char *audiodrv[] = {
|
2001-07-08 12:24:49 +00:00
|
|
|
"null",
|
2001-04-07 01:03:24 +00:00
|
|
|
"mp3lib",
|
|
|
|
"pcm",
|
|
|
|
"libac3",
|
|
|
|
"acm",
|
|
|
|
"alaw",
|
|
|
|
"msgsm",
|
|
|
|
"dshow",
|
2001-04-14 15:25:11 +00:00
|
|
|
"dvdpcm",
|
2001-08-15 11:50:55 +00:00
|
|
|
"hwac3",
|
2001-09-01 19:44:49 +00:00
|
|
|
"libvorbis",
|
2001-09-21 21:40:16 +00:00
|
|
|
"ffmpeg",
|
2001-10-23 12:03:41 +00:00
|
|
|
"libmad",
|
2001-12-27 05:09:43 +00:00
|
|
|
"msadpcm",
|
2001-12-09 16:20:03 +00:00
|
|
|
"liba52",
|
|
|
|
"g72x",
|
2001-12-27 05:09:43 +00:00
|
|
|
"imaadpcm",
|
2002-02-25 02:48:37 +00:00
|
|
|
"dk4adpcm",
|
|
|
|
"dk3adpcm",
|
2002-02-01 05:33:46 +00:00
|
|
|
"roqaudio",
|
2002-03-18 23:30:04 +00:00
|
|
|
"faad",
|
2002-06-08 20:51:50 +00:00
|
|
|
"realaud",
|
2001-04-07 01:03:24 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static char *videodrv[] = {
|
2001-07-08 12:24:49 +00:00
|
|
|
"null",
|
2001-04-07 01:03:24 +00:00
|
|
|
"libmpeg2",
|
|
|
|
"vfw",
|
|
|
|
"odivx",
|
|
|
|
"dshow",
|
2001-06-30 00:16:39 +00:00
|
|
|
"ffmpeg",
|
2001-07-08 17:20:46 +00:00
|
|
|
"vfwex",
|
2001-07-19 22:43:19 +00:00
|
|
|
"divx4",
|
2001-08-11 23:11:16 +00:00
|
|
|
"raw",
|
2002-03-19 07:07:06 +00:00
|
|
|
"msrle",
|
2001-10-22 19:04:09 +00:00
|
|
|
"xanim",
|
2001-11-11 13:35:00 +00:00
|
|
|
"msvidc",
|
2001-11-28 01:35:55 +00:00
|
|
|
"fli",
|
2001-12-21 16:39:54 +00:00
|
|
|
"cinepak",
|
2001-12-23 22:20:46 +00:00
|
|
|
"qtrle",
|
2001-12-27 21:32:17 +00:00
|
|
|
"nuv",
|
2002-01-04 05:57:00 +00:00
|
|
|
"cyuv",
|
2002-01-18 05:43:48 +00:00
|
|
|
"qtsmc",
|
2002-01-22 05:39:34 +00:00
|
|
|
"ducktm1",
|
2002-02-01 05:33:46 +00:00
|
|
|
"roqvideo",
|
2002-02-09 20:05:49 +00:00
|
|
|
"qtrpza",
|
2002-02-11 09:15:59 +00:00
|
|
|
"mpng",
|
2002-03-10 22:49:18 +00:00
|
|
|
"ijpg",
|
2002-03-21 01:21:49 +00:00
|
|
|
"huffyuv",
|
2002-03-22 22:12:09 +00:00
|
|
|
"zlib",
|
2002-04-03 19:09:55 +00:00
|
|
|
"mpegpes",
|
2002-06-08 20:51:50 +00:00
|
|
|
"realvid",
|
2001-04-07 01:03:24 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
char **drv=audioflag?audiodrv:videodrv;
|
|
|
|
int i;
|
|
|
|
|
2001-07-08 12:24:49 +00:00
|
|
|
for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i;
|
2001-04-07 01:03:24 +00:00
|
|
|
|
2001-07-08 12:24:49 +00:00
|
|
|
return -1;
|
2001-04-06 23:20:46 +00:00
|
|
|
}
|
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
static int validate_codec(codecs_t *c, int type)
|
2001-04-09 20:21:07 +00:00
|
|
|
{
|
2002-05-02 11:00:16 +00:00
|
|
|
unsigned int i;
|
2001-12-09 18:25:09 +00:00
|
|
|
char *tmp_name = strdup(c->name);
|
2001-04-10 20:09:23 +00:00
|
|
|
|
2001-12-09 18:25:09 +00:00
|
|
|
for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++)
|
2001-04-10 20:09:23 +00:00
|
|
|
/* NOTHING */;
|
2001-12-09 18:25:09 +00:00
|
|
|
|
|
|
|
if (i < strlen(tmp_name)) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"\ncodec(%s) name is not valid!\n", c->name);
|
2001-04-10 20:09:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-12-09 18:25:09 +00:00
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
if (!c->info)
|
2001-12-09 18:25:09 +00:00
|
|
|
c->info = strdup(c->name);
|
|
|
|
|
|
|
|
#if 0
|
2001-04-10 20:09:23 +00:00
|
|
|
if (c->fourcc[0] == 0xffffffff) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"\ncodec(%s) does not have fourcc/format!\n", c->name);
|
2001-04-10 20:09:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-12-09 18:25:09 +00:00
|
|
|
|
|
|
|
/* XXX fix this: shitty with 'null' codec */
|
2001-04-10 20:09:23 +00:00
|
|
|
if (!c->driver) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"\ncodec(%s) does not have a driver!\n", c->name);
|
2001-04-10 20:09:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-12-09 18:25:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2001-04-10 20:09:23 +00:00
|
|
|
#warning codec->driver == 4;... <- ezt nem kellene belehegeszteni...
|
|
|
|
#warning HOL VANNAK DEFINIALVA????????????
|
|
|
|
if (!c->dll && (c->driver == 4 ||
|
|
|
|
(c->driver == 2 && type == TYPE_VIDEO))) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"\ncodec(%s) needs a 'dll'!\n", c->name);
|
2001-04-10 20:09:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#warning guid.f1 lehet 0? honnan lehet tudni, hogy nem adtak meg?
|
|
|
|
// if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4)
|
|
|
|
|
|
|
|
if (type == TYPE_VIDEO)
|
|
|
|
if (c->outfmt[0] == 0xffffffff) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"\ncodec(%s) needs an 'outfmt'!\n", c->name);
|
2001-04-10 20:09:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-04-10 20:47:37 +00:00
|
|
|
#endif
|
2001-04-09 20:21:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2001-04-09 20:21:07 +00:00
|
|
|
static int add_comment(char *s, char **d)
|
2001-04-06 23:20:46 +00:00
|
|
|
{
|
2001-04-09 20:21:07 +00:00
|
|
|
int pos;
|
|
|
|
|
|
|
|
if (!*d)
|
|
|
|
pos = 0;
|
|
|
|
else {
|
|
|
|
pos = strlen(*d);
|
|
|
|
(*d)[pos++] = '\n';
|
|
|
|
}
|
|
|
|
if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_FATAL,"can't allocate mem for comment. ");
|
2001-04-09 20:21:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strcpy(*d + pos, s);
|
|
|
|
return 1;
|
|
|
|
}
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2001-04-11 20:55:14 +00:00
|
|
|
static short get_cpuflags(char *s)
|
|
|
|
{
|
|
|
|
static char *flagstr[] = {
|
|
|
|
"mmx",
|
|
|
|
"sse",
|
|
|
|
"3dnow",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
short flags = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
for (i = 0; flagstr[i]; i++)
|
|
|
|
if (!strncmp(s, flagstr[i], strlen(flagstr[i])))
|
|
|
|
break;
|
|
|
|
if (!flagstr[i])
|
|
|
|
goto err_out_parse_error;
|
|
|
|
flags |= 1<<i;
|
|
|
|
s += strlen(flagstr[i]);
|
|
|
|
} while (*(s++) == ',');
|
|
|
|
|
|
|
|
if (*(--s) != '\0')
|
|
|
|
goto err_out_parse_error;
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
err_out_parse_error:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
static FILE *fp;
|
|
|
|
static int line_num = 0;
|
|
|
|
static char *line;
|
|
|
|
static char *token[MAX_NR_TOKEN];
|
2002-05-26 22:39:38 +00:00
|
|
|
static int read_nextline = 1;
|
2001-04-10 20:09:23 +00:00
|
|
|
|
|
|
|
static int get_token(int min, int max)
|
|
|
|
{
|
|
|
|
static int line_pos;
|
|
|
|
int i;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (max >= MAX_NR_TOKEN) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"get_token(): max >= MAX_NR_TOKEN!");
|
2001-04-10 20:09:23 +00:00
|
|
|
goto out_eof;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(token, 0x00, sizeof(*token) * max);
|
|
|
|
|
|
|
|
if (read_nextline) {
|
|
|
|
if (!fgets(line, MAX_LINE_LEN, fp))
|
|
|
|
goto out_eof;
|
|
|
|
line_pos = 0;
|
|
|
|
++line_num;
|
|
|
|
read_nextline = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
while (isspace(line[line_pos]))
|
|
|
|
++line_pos;
|
|
|
|
if (line[line_pos] == '\0' || line[line_pos] == '#' ||
|
|
|
|
line[line_pos] == ';') {
|
|
|
|
read_nextline = 1;
|
|
|
|
if (i >= min)
|
|
|
|
goto out_ok;
|
|
|
|
goto out_eol;
|
|
|
|
}
|
|
|
|
token[i] = line + line_pos;
|
|
|
|
c = line[line_pos];
|
|
|
|
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 out_ok;
|
|
|
|
goto out_eol;
|
|
|
|
}
|
|
|
|
line[line_pos] = '\0';
|
|
|
|
line_pos++;
|
|
|
|
}
|
|
|
|
out_ok:
|
|
|
|
return i;
|
|
|
|
out_eof:
|
2001-12-27 18:38:10 +00:00
|
|
|
read_nextline = 1;
|
2001-04-10 20:09:23 +00:00
|
|
|
return RET_EOF;
|
|
|
|
out_eol:
|
|
|
|
return RET_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static codecs_t *video_codecs=NULL;
|
|
|
|
static codecs_t *audio_codecs=NULL;
|
|
|
|
static int nr_vcodecs = 0;
|
|
|
|
static int nr_acodecs = 0;
|
|
|
|
|
2001-12-27 18:38:10 +00:00
|
|
|
int parse_codec_cfg(char *cfgfile)
|
2001-04-09 20:21:07 +00:00
|
|
|
{
|
2001-04-10 20:09:23 +00:00
|
|
|
codecs_t *codec = NULL; // current codec
|
|
|
|
codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs
|
2001-04-10 23:56:38 +00:00
|
|
|
char *endptr; // strtoul()...
|
2001-04-10 20:09:23 +00:00
|
|
|
int *nr_codecsp;
|
|
|
|
int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */
|
2001-04-06 23:20:46 +00:00
|
|
|
int tmp, i;
|
2001-12-27 18:38:10 +00:00
|
|
|
|
|
|
|
// in case we call it secont time
|
|
|
|
if(video_codecs!=NULL)free(video_codecs);
|
|
|
|
else video_codecs=NULL;
|
|
|
|
|
|
|
|
if(audio_codecs!=NULL)free(audio_codecs);
|
|
|
|
else audio_codecs=NULL;
|
|
|
|
|
|
|
|
nr_vcodecs = 0;
|
|
|
|
nr_acodecs = 0;
|
|
|
|
|
|
|
|
if(cfgfile==NULL)return 0;
|
|
|
|
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_INFO,"Reading %s: ", cfgfile);
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2001-04-07 01:03:24 +00:00
|
|
|
if ((fp = fopen(cfgfile, "r")) == NULL) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"can't open '%s': %s\n", cfgfile, strerror(errno));
|
2001-12-27 18:38:10 +00:00
|
|
|
return 0;
|
2001-04-06 23:20:46 +00:00
|
|
|
}
|
|
|
|
|
2001-04-07 01:03:24 +00:00
|
|
|
if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_FATAL,"can't get memory for 'line': %s\n", strerror(errno));
|
2001-12-27 18:38:10 +00:00
|
|
|
return 0;
|
2001-04-06 23:20:46 +00:00
|
|
|
}
|
2002-05-26 22:39:38 +00:00
|
|
|
read_nextline = 1;
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
/*
|
2002-05-26 22:39:38 +00:00
|
|
|
* this only catches release lines at the start of
|
|
|
|
* codecs.conf, before audiocodecs and videocodecs.
|
2001-04-10 20:09:23 +00:00
|
|
|
*/
|
|
|
|
while ((tmp = get_token(1, 1)) == RET_EOL)
|
|
|
|
/* NOTHING */;
|
2001-04-11 20:55:14 +00:00
|
|
|
if (tmp == RET_EOF)
|
|
|
|
goto out;
|
2002-05-26 22:39:38 +00:00
|
|
|
if (!strcmp(token[0], "release")) {
|
|
|
|
if (get_token(1, 2) < 0)
|
|
|
|
goto err_out_parse_error;
|
|
|
|
tmp = atoi(token[0]);
|
|
|
|
if (tmp < CODEC_CFG_MIN)
|
|
|
|
goto err_out_release_num;
|
|
|
|
while ((tmp = get_token(1, 1)) == RET_EOL)
|
|
|
|
/* NOTHING */;
|
|
|
|
if (tmp == RET_EOF)
|
|
|
|
goto out;
|
|
|
|
} else
|
|
|
|
goto err_out_release_num;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check if the next block starts with 'audiocodec' or
|
|
|
|
* with 'videocodec'
|
|
|
|
*/
|
2001-04-11 20:55:14 +00:00
|
|
|
if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec"))
|
2001-04-10 20:09:23 +00:00
|
|
|
goto loop_enter;
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-10 20:09:23 +00:00
|
|
|
|
2001-04-09 20:21:07 +00:00
|
|
|
while ((tmp = get_token(1, 1)) != RET_EOF) {
|
2001-04-06 23:20:46 +00:00
|
|
|
if (tmp == RET_EOL)
|
|
|
|
continue;
|
2001-04-10 20:09:23 +00:00
|
|
|
if (!strcmp(token[0], "audiocodec") ||
|
|
|
|
!strcmp(token[0], "videocodec")) {
|
|
|
|
if (!validate_codec(codec, codec_type))
|
|
|
|
goto err_out_not_valid;
|
|
|
|
loop_enter:
|
|
|
|
if (*token[0] == 'v') {
|
|
|
|
codec_type = TYPE_VIDEO;
|
|
|
|
nr_codecsp = &nr_vcodecs;
|
|
|
|
codecsp = &video_codecs;
|
|
|
|
} else if (*token[0] == 'a') {
|
|
|
|
codec_type = TYPE_AUDIO;
|
|
|
|
nr_codecsp = &nr_acodecs;
|
|
|
|
codecsp = &audio_codecs;
|
2001-04-11 20:55:14 +00:00
|
|
|
#ifdef DEBUG
|
2001-04-10 20:09:23 +00:00
|
|
|
} else {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"picsba\n");
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out;
|
2001-04-11 20:55:14 +00:00
|
|
|
#endif
|
2001-04-10 20:09:23 +00:00
|
|
|
}
|
|
|
|
if (!(*codecsp = (codecs_t *) realloc(*codecsp,
|
2001-04-10 23:18:01 +00:00
|
|
|
sizeof(codecs_t) * (*nr_codecsp + 2)))) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_FATAL,"can't realloc '*codecsp': %s\n", strerror(errno));
|
2001-04-07 00:51:38 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
2001-04-10 20:09:23 +00:00
|
|
|
codec=*codecsp + *nr_codecsp;
|
|
|
|
++*nr_codecsp;
|
2001-04-07 00:51:38 +00:00
|
|
|
memset(codec,0,sizeof(codecs_t));
|
|
|
|
memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
|
|
|
|
memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
|
2002-02-12 17:33:27 +00:00
|
|
|
memset(codec->infmt, 0xff, sizeof(codec->infmt));
|
2001-04-07 00:51:38 +00:00
|
|
|
|
2001-04-09 20:21:07 +00:00
|
|
|
if (get_token(1, 1) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
|
|
|
for (i = 0; i < *nr_codecsp - 1; i++) {
|
2001-12-27 18:38:10 +00:00
|
|
|
if(( (*codecsp)[i].name!=NULL) &&
|
|
|
|
(!strcmp(token[0], (*codecsp)[i].name)) ) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"codec name '%s' isn't unique", token[0]);
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_print_linenum;
|
2001-04-09 20:21:07 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-10 20:09:23 +00:00
|
|
|
if (!(codec->name = strdup(token[0]))) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"can't strdup -> 'name': %s\n", strerror(errno));
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "info")) {
|
2001-04-10 20:09:23 +00:00
|
|
|
if (codec->info || get_token(1, 1) < 0)
|
|
|
|
goto err_out_parse_error;
|
|
|
|
if (!(codec->info = strdup(token[0]))) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"can't strdup -> 'info': %s\n", strerror(errno));
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "comment")) {
|
|
|
|
if (get_token(1, 1) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-11 20:55:14 +00:00
|
|
|
add_comment(token[0], &codec->comment);
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "fourcc")) {
|
|
|
|
if (get_token(1, 2) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-09 20:21:07 +00:00
|
|
|
if (!add_to_fourcc(token[0], token[1],
|
2001-04-07 00:51:38 +00:00
|
|
|
codec->fourcc,
|
|
|
|
codec->fourccmap))
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_print_linenum;
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "format")) {
|
|
|
|
if (get_token(1, 1) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-09 20:21:07 +00:00
|
|
|
if (!add_to_format(token[0], codec->fourcc,codec->fourccmap))
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_print_linenum;
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "driver")) {
|
|
|
|
if (get_token(1, 1) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-07-08 12:24:49 +00:00
|
|
|
if ((codec->driver = get_driver(token[0],codec_type))<0)
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "dll")) {
|
|
|
|
if (get_token(1, 1) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
|
|
|
if (!(codec->dll = strdup(token[0]))) {
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"can't strdup -> 'dll': %s\n", strerror(errno));
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "guid")) {
|
2001-04-10 20:09:23 +00:00
|
|
|
if (get_token(11, 11) < 0)
|
|
|
|
goto err_out_parse_error;
|
2001-04-10 23:56:38 +00:00
|
|
|
codec->guid.f1=strtoul(token[0],&endptr,0);
|
2001-04-11 20:55:14 +00:00
|
|
|
if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
|
|
*endptr != '\0')
|
2001-04-10 23:56:38 +00:00
|
|
|
goto err_out_parse_error;
|
|
|
|
codec->guid.f2=strtoul(token[1],&endptr,0);
|
2001-04-11 20:55:14 +00:00
|
|
|
if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
|
|
*endptr != '\0')
|
2001-04-10 23:56:38 +00:00
|
|
|
goto err_out_parse_error;
|
|
|
|
codec->guid.f3=strtoul(token[2],&endptr,0);
|
2001-04-11 20:55:14 +00:00
|
|
|
if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
|
|
*endptr != '\0')
|
2001-04-10 23:56:38 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-07 00:51:38 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
2001-04-10 23:56:38 +00:00
|
|
|
codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0);
|
2001-04-11 20:55:14 +00:00
|
|
|
if ((*endptr != ',' || *(endptr + 1) != '\0') &&
|
|
|
|
*endptr != '\0')
|
2001-04-10 23:56:38 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-06 23:20:46 +00:00
|
|
|
}
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "out")) {
|
|
|
|
if (get_token(1, 2) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2002-02-12 17:33:27 +00:00
|
|
|
if (!add_to_inout(token[0], token[1], codec->outfmt,
|
2001-04-07 00:51:38 +00:00
|
|
|
codec->outflags))
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_print_linenum;
|
2002-02-12 17:33:27 +00:00
|
|
|
} else if (!strcmp(token[0], "in")) {
|
|
|
|
if (get_token(1, 2) < 0)
|
|
|
|
goto err_out_parse_error;
|
|
|
|
if (!add_to_inout(token[0], token[1], codec->infmt,
|
|
|
|
codec->inflags))
|
|
|
|
goto err_out_print_linenum;
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "flags")) {
|
|
|
|
if (get_token(1, 1) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-09 21:28:44 +00:00
|
|
|
if (!strcmp(token[0], "seekable"))
|
|
|
|
codec->flags |= CODECS_FLAG_SEEKABLE;
|
|
|
|
else
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-09 20:21:07 +00:00
|
|
|
} else if (!strcmp(token[0], "status")) {
|
|
|
|
if (get_token(1, 1) < 0)
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-10 23:18:01 +00:00
|
|
|
if (!strcasecmp(token[0], "working"))
|
2001-04-08 23:42:25 +00:00
|
|
|
codec->status = CODECS_STATUS_WORKING;
|
2001-04-10 23:18:01 +00:00
|
|
|
else if (!strcasecmp(token[0], "crashing"))
|
2001-04-08 23:42:25 +00:00
|
|
|
codec->status = CODECS_STATUS_NOT_WORKING;
|
2001-04-10 23:18:01 +00:00
|
|
|
else if (!strcasecmp(token[0], "untested"))
|
2001-04-08 23:42:25 +00:00
|
|
|
codec->status = CODECS_STATUS_UNTESTED;
|
2001-04-10 23:18:01 +00:00
|
|
|
else if (!strcasecmp(token[0], "buggy"))
|
2001-04-08 23:42:25 +00:00
|
|
|
codec->status = CODECS_STATUS_PROBLEMS;
|
|
|
|
else
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-11 20:55:14 +00:00
|
|
|
} else if (!strcmp(token[0], "cpuflags")) {
|
|
|
|
if (get_token(1, 1) < 0)
|
|
|
|
goto err_out_parse_error;
|
|
|
|
if (!(codec->cpuflags = get_cpuflags(token[0])))
|
|
|
|
goto err_out_parse_error;
|
2001-12-23 11:58:57 +00:00
|
|
|
} else if (!strcasecmp(token[0], "priority")) {
|
|
|
|
if (get_token(1, 1) < 0)
|
|
|
|
goto err_out_parse_error;
|
|
|
|
//printf("\n\n!!!cfg-parse: priority %s (%d) found!!!\n\n", token[0], atoi(token[0])); // ::atmos
|
|
|
|
codec->priority = atoi(token[0]);
|
2001-04-06 23:20:46 +00:00
|
|
|
} else
|
2001-04-10 20:09:23 +00:00
|
|
|
goto err_out_parse_error;
|
2001-04-06 23:20:46 +00:00
|
|
|
}
|
2001-04-10 20:09:23 +00:00
|
|
|
if (!validate_codec(codec, codec_type))
|
|
|
|
goto err_out_not_valid;
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_INFO,"%d audio & %d video codecs\n", nr_acodecs, nr_vcodecs);
|
2001-05-27 23:29:03 +00:00
|
|
|
if(video_codecs) video_codecs[nr_vcodecs].name = NULL;
|
|
|
|
if(audio_codecs) audio_codecs[nr_acodecs].name = NULL;
|
2001-04-06 23:20:46 +00:00
|
|
|
out:
|
|
|
|
free(line);
|
2001-12-27 18:38:10 +00:00
|
|
|
line=NULL;
|
2001-04-06 23:20:46 +00:00
|
|
|
fclose(fp);
|
2001-12-27 18:38:10 +00:00
|
|
|
return 1;
|
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
err_out_parse_error:
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"parse error");
|
2001-04-11 20:55:14 +00:00
|
|
|
err_out_print_linenum:
|
2001-04-06 23:20:46 +00:00
|
|
|
PRINT_LINENUM;
|
|
|
|
err_out:
|
2001-04-10 20:09:23 +00:00
|
|
|
if (audio_codecs)
|
|
|
|
free(audio_codecs);
|
|
|
|
if (video_codecs)
|
|
|
|
free(video_codecs);
|
2001-12-27 18:38:10 +00:00
|
|
|
video_codecs=NULL;
|
|
|
|
audio_codecs=NULL;
|
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
free(line);
|
2001-12-27 18:38:10 +00:00
|
|
|
line=NULL;
|
2002-05-26 22:39:38 +00:00
|
|
|
line_num = 0;
|
2001-12-27 18:38:10 +00:00
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
2001-04-10 20:09:23 +00:00
|
|
|
err_out_not_valid:
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"codec is not defined correctly");
|
2001-04-11 20:55:14 +00:00
|
|
|
goto err_out_print_linenum;
|
2002-05-26 22:39:38 +00:00
|
|
|
err_out_release_num:
|
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_ERR,"this codecs.conf is too old, incompatible with this mplayer release!");
|
|
|
|
goto err_out_print_linenum;
|
2001-04-06 23:20:46 +00:00
|
|
|
}
|
|
|
|
|
2001-04-10 23:18:01 +00:00
|
|
|
codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
|
|
|
|
codecs_t *start)
|
2001-04-10 20:09:23 +00:00
|
|
|
{
|
2001-04-10 23:18:01 +00:00
|
|
|
return find_codec(fourcc, fourccmap, start, 1);
|
2001-04-10 20:09:23 +00:00
|
|
|
}
|
|
|
|
|
2001-04-10 23:18:01 +00:00
|
|
|
codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap,
|
|
|
|
codecs_t *start)
|
2001-04-10 20:09:23 +00:00
|
|
|
{
|
2001-04-10 23:18:01 +00:00
|
|
|
return find_codec(fourcc, fourccmap, start, 0);
|
2001-04-10 20:09:23 +00:00
|
|
|
}
|
|
|
|
|
2001-04-10 23:18:01 +00:00
|
|
|
codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,
|
|
|
|
codecs_t *start, int audioflag)
|
2001-04-10 20:09:23 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
codecs_t *c;
|
|
|
|
|
2001-04-24 22:55:52 +00:00
|
|
|
#if 0
|
2001-04-10 23:18:01 +00:00
|
|
|
if (start) {
|
|
|
|
for (/* NOTHING */; start->name; start++) {
|
|
|
|
for (j = 0; j < CODECS_MAX_FOURCC; j++) {
|
|
|
|
if (start->fourcc[j] == fourcc) {
|
|
|
|
if (fourccmap)
|
|
|
|
*fourccmap = start->fourccmap[j];
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-24 22:55:52 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2001-04-10 23:18:01 +00:00
|
|
|
if (audioflag) {
|
|
|
|
i = nr_acodecs;
|
|
|
|
c = audio_codecs;
|
|
|
|
} else {
|
|
|
|
i = nr_vcodecs;
|
|
|
|
c = video_codecs;
|
|
|
|
}
|
2001-05-27 23:29:03 +00:00
|
|
|
if(!i) return NULL;
|
2001-04-10 23:18:01 +00:00
|
|
|
for (/* NOTHING */; i--; c++) {
|
2001-04-24 22:55:52 +00:00
|
|
|
if(start && c<=start) continue;
|
2001-04-10 23:18:01 +00:00
|
|
|
for (j = 0; j < CODECS_MAX_FOURCC; j++) {
|
2001-07-26 00:30:01 +00:00
|
|
|
if (c->fourcc[j]==fourcc || c->driver==0) {
|
2001-04-10 23:18:01 +00:00
|
|
|
if (fourccmap)
|
|
|
|
*fourccmap = c->fourccmap[j];
|
|
|
|
return c;
|
|
|
|
}
|
2001-04-10 20:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2001-04-07 21:27:57 +00:00
|
|
|
}
|
|
|
|
|
2002-03-25 03:02:57 +00:00
|
|
|
void codecs_reset_selection(int audioflag){
|
|
|
|
int i;
|
|
|
|
codecs_t *c;
|
|
|
|
if (audioflag) {
|
|
|
|
i = nr_acodecs;
|
|
|
|
c = audio_codecs;
|
|
|
|
} else {
|
|
|
|
i = nr_vcodecs;
|
|
|
|
c = video_codecs;
|
|
|
|
}
|
|
|
|
if(i)
|
|
|
|
for (/* NOTHING */; i--; c++)
|
|
|
|
c->flags&=(~CODECS_FLAG_SELECTED);
|
|
|
|
}
|
|
|
|
|
2001-09-27 12:59:35 +00:00
|
|
|
void list_codecs(int audioflag){
|
2001-10-02 21:45:41 +00:00
|
|
|
int i;
|
2001-09-27 12:59:35 +00:00
|
|
|
codecs_t *c;
|
|
|
|
|
|
|
|
if (audioflag) {
|
|
|
|
i = nr_acodecs;
|
|
|
|
c = audio_codecs;
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_INFO,"ac: afm: status: info: [lib/dll]\n");
|
2001-09-27 12:59:35 +00:00
|
|
|
} else {
|
|
|
|
i = nr_vcodecs;
|
|
|
|
c = video_codecs;
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_INFO,"vc: vfm: status: info: [lib/dll]\n");
|
2001-09-27 12:59:35 +00:00
|
|
|
}
|
2001-10-02 21:45:41 +00:00
|
|
|
if(!i) return;
|
2001-09-27 12:59:35 +00:00
|
|
|
for (/* NOTHING */; i--; c++) {
|
2001-09-27 13:19:46 +00:00
|
|
|
char* s="unknown ";
|
|
|
|
switch(c->status){
|
|
|
|
case CODECS_STATUS_WORKING: s="working ";break;
|
|
|
|
case CODECS_STATUS_PROBLEMS: s="problems";break;
|
|
|
|
case CODECS_STATUS_NOT_WORKING: s="crashing";break;
|
|
|
|
case CODECS_STATUS_UNTESTED: s="untested";break;
|
|
|
|
}
|
2001-09-27 12:59:35 +00:00
|
|
|
if(c->dll)
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s%2d %s %s [%s]\n",c->name,c->driver,s,c->info,c->dll);
|
2001-09-27 12:59:35 +00:00
|
|
|
else
|
2002-05-02 11:00:16 +00:00
|
|
|
mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s%2d %s %s\n",c->name,c->driver,s,c->info);
|
2001-09-27 12:59:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-24 02:14:14 +00:00
|
|
|
#ifdef CODECS2HTML
|
|
|
|
|
|
|
|
void wrapline(FILE *f2,char *s){
|
|
|
|
int c;
|
|
|
|
if(!s){
|
|
|
|
fprintf(f2,"-");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while((c=*s++)){
|
|
|
|
if(c==',') fprintf(f2,"<br>"); else fputc(c,f2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){
|
|
|
|
int c,d;
|
|
|
|
while((c=fgetc(f1))>=0){
|
|
|
|
if(c!='%'){
|
|
|
|
fputc(c,f2);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
d=fgetc(f1);
|
|
|
|
|
|
|
|
switch(d){
|
|
|
|
case '.':
|
2001-04-24 10:21:55 +00:00
|
|
|
return; // end of section
|
2001-04-24 02:14:14 +00:00
|
|
|
case 'n':
|
|
|
|
wrapline(f2,codec->name); break;
|
|
|
|
case 'i':
|
|
|
|
wrapline(f2,codec->info); break;
|
|
|
|
case 'c':
|
|
|
|
wrapline(f2,codec->comment); break;
|
|
|
|
case 'd':
|
|
|
|
wrapline(f2,codec->dll); break;
|
|
|
|
case 'D':
|
|
|
|
fprintf(f2,"%c",codec->driver==dshow?'+':'-'); break;
|
|
|
|
case 'F':
|
|
|
|
for(d=0;d<CODECS_MAX_FOURCC;d++)
|
2001-09-23 20:40:16 +00:00
|
|
|
if(!d || codec->fourcc[d]!=0xFFFFFFFF)
|
|
|
|
fprintf(f2,"%s%.4s",d?"<br>":"",(codec->fourcc[d]==0xFFFFFFFF || codec->fourcc[d]<0x20202020)?!d?"-":"":(char*) &codec->fourcc[d]);
|
2001-04-24 02:14:14 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
for(d=0;d<CODECS_MAX_FOURCC;d++)
|
|
|
|
if(codec->fourcc[d]!=0xFFFFFFFF)
|
|
|
|
fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]);
|
|
|
|
break;
|
|
|
|
case 'Y':
|
|
|
|
for(d=0;d<CODECS_MAX_OUTFMT;d++)
|
|
|
|
if(codec->outfmt[d]!=0xFFFFFFFF){
|
|
|
|
for (c=0; fmt_table[c].name; c++)
|
|
|
|
if(fmt_table[c].num==codec->outfmt[d]) break;
|
|
|
|
if(fmt_table[c].name)
|
|
|
|
fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fputc(c,f2);
|
|
|
|
fputc(d,f2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void skiphtml(FILE *f1){
|
|
|
|
int c,d;
|
|
|
|
while((c=fgetc(f1))>=0){
|
|
|
|
if(c!='%'){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
d=fgetc(f1);
|
|
|
|
if(d=='.') return; // end of section
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2002-01-07 00:52:09 +00:00
|
|
|
codecs_t *cl;
|
2001-04-24 02:14:14 +00:00
|
|
|
FILE *f1;
|
|
|
|
FILE *f2;
|
|
|
|
int c,d,i;
|
|
|
|
int pos;
|
|
|
|
int section=-1;
|
|
|
|
int nr_codecs;
|
|
|
|
int win32=-1;
|
|
|
|
int dshow=-1;
|
2001-09-23 20:40:16 +00:00
|
|
|
int win32ex=-1;
|
2001-04-24 02:14:14 +00:00
|
|
|
|
2002-01-07 00:52:09 +00:00
|
|
|
if (!(nr_codecs = parse_codec_cfg("etc/codecs.conf")))
|
2001-04-24 02:14:14 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
f1=fopen("DOCS/codecs-in.html","rb"); if(!f1) exit(1);
|
2001-08-25 19:03:11 +00:00
|
|
|
f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1);
|
2001-04-24 02:14:14 +00:00
|
|
|
|
|
|
|
while((c=fgetc(f1))>=0){
|
|
|
|
if(c!='%'){
|
|
|
|
fputc(c,f2);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
d=fgetc(f1);
|
|
|
|
if(d>='0' && d<='9'){
|
|
|
|
// begin section
|
|
|
|
section=d-'0';
|
|
|
|
printf("BEGIN %d\n",section);
|
|
|
|
if(section>=5){
|
|
|
|
// audio
|
2002-01-07 00:52:09 +00:00
|
|
|
cl = audio_codecs;
|
2001-04-24 02:14:14 +00:00
|
|
|
nr_codecs = nr_acodecs;
|
|
|
|
dshow=7;win32=4;
|
|
|
|
} else {
|
|
|
|
// video
|
2002-01-07 00:52:09 +00:00
|
|
|
cl = video_codecs;
|
2001-04-24 02:14:14 +00:00
|
|
|
nr_codecs = nr_vcodecs;
|
2001-09-23 20:40:16 +00:00
|
|
|
dshow=4;win32=2;win32ex=6;
|
2001-04-24 02:14:14 +00:00
|
|
|
}
|
|
|
|
pos=ftell(f1);
|
|
|
|
for(i=0;i<nr_codecs;i++){
|
|
|
|
fseek(f1,pos,SEEK_SET);
|
|
|
|
switch(section){
|
|
|
|
case 0:
|
|
|
|
case 5:
|
|
|
|
if(cl[i].status==CODECS_STATUS_WORKING)
|
2001-09-23 20:40:16 +00:00
|
|
|
if(!(cl[i].driver==win32 || cl[i].driver==dshow || cl[i].driver==win32ex))
|
2001-04-24 02:14:14 +00:00
|
|
|
parsehtml(f1,f2,&cl[i],section,dshow);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 6:
|
|
|
|
if(cl[i].status==CODECS_STATUS_WORKING)
|
2001-09-23 20:40:16 +00:00
|
|
|
if(cl[i].driver==win32 || cl[i].driver==dshow || cl[i].driver==win32ex)
|
2001-04-24 02:14:14 +00:00
|
|
|
parsehtml(f1,f2,&cl[i],section,dshow);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 7:
|
|
|
|
if(cl[i].status==CODECS_STATUS_PROBLEMS)
|
|
|
|
parsehtml(f1,f2,&cl[i],section,dshow);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 8:
|
|
|
|
if(cl[i].status==CODECS_STATUS_NOT_WORKING)
|
|
|
|
parsehtml(f1,f2,&cl[i],section,dshow);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 9:
|
|
|
|
if(cl[i].status==CODECS_STATUS_UNTESTED)
|
|
|
|
parsehtml(f1,f2,&cl[i],section,dshow);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Warning! unimplemented section: %d\n",section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fseek(f1,pos,SEEK_SET);
|
|
|
|
skiphtml(f1);
|
|
|
|
//void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fputc(c,f2);
|
|
|
|
fputc(d,f2);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f2);
|
|
|
|
fclose(f1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2001-04-06 23:20:46 +00:00
|
|
|
#ifdef TESTING
|
|
|
|
int main(void)
|
|
|
|
{
|
2002-02-12 17:52:30 +00:00
|
|
|
codecs_t *c;
|
2001-04-10 20:09:23 +00:00
|
|
|
int i,j, nr_codecs, state;
|
2001-04-06 23:20:46 +00:00
|
|
|
|
2002-02-12 17:52:30 +00:00
|
|
|
if (!(parse_codec_cfg("etc/codecs.conf")))
|
2001-04-09 20:21:07 +00:00
|
|
|
return 0;
|
2002-02-12 17:52:30 +00:00
|
|
|
if (!video_codecs)
|
2001-04-10 20:09:23 +00:00
|
|
|
printf("no videoconfig.\n");
|
2002-02-12 17:52:30 +00:00
|
|
|
if (!audio_codecs)
|
2001-04-10 20:09:23 +00:00
|
|
|
printf("no audioconfig.\n");
|
|
|
|
|
|
|
|
printf("videocodecs:\n");
|
2002-02-12 17:52:30 +00:00
|
|
|
c = video_codecs;
|
2001-04-10 20:09:23 +00:00
|
|
|
nr_codecs = nr_vcodecs;
|
|
|
|
state = 0;
|
|
|
|
next:
|
|
|
|
if (c) {
|
2002-02-12 17:52:30 +00:00
|
|
|
printf("number of %scodecs: %d\n", state==0?"video":"audio",
|
|
|
|
nr_codecs);
|
2001-04-10 20:09:23 +00:00
|
|
|
for(i=0;i<nr_codecs;i++, c++){
|
2002-02-12 17:52:30 +00:00
|
|
|
printf("\n============== %scodec %02d ===============\n",
|
|
|
|
state==0?"video":"audio",i);
|
2001-04-10 20:09:23 +00:00
|
|
|
printf("name='%s'\n",c->name);
|
|
|
|
printf("info='%s'\n",c->info);
|
|
|
|
printf("comment='%s'\n",c->comment);
|
|
|
|
printf("dll='%s'\n",c->dll);
|
2001-04-11 20:55:14 +00:00
|
|
|
printf("flags=%X driver=%d status=%d cpuflags=%d\n",
|
|
|
|
c->flags, c->driver, c->status, c->cpuflags);
|
2001-04-10 20:09:23 +00:00
|
|
|
|
|
|
|
for(j=0;j<CODECS_MAX_FOURCC;j++){
|
|
|
|
if(c->fourcc[j]!=0xFFFFFFFF){
|
2001-04-11 20:55:14 +00:00
|
|
|
printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]);
|
2001-04-10 20:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(j=0;j<CODECS_MAX_OUTFMT;j++){
|
|
|
|
if(c->outfmt[j]!=0xFFFFFFFF){
|
2001-04-11 20:55:14 +00:00
|
|
|
printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]);
|
2001-04-10 20:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-12 17:52:30 +00:00
|
|
|
for(j=0;j<CODECS_MAX_INFMT;j++){
|
|
|
|
if(c->infmt[j]!=0xFFFFFFFF){
|
|
|
|
printf("infmt %02d: %08X (%.4s) flags: %d\n",j,c->infmt[j],(char *) &c->infmt[j],c->inflags[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-10 20:09:23 +00:00
|
|
|
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]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!state) {
|
|
|
|
printf("audiocodecs:\n");
|
2002-02-12 17:52:30 +00:00
|
|
|
c = audio_codecs;
|
2001-04-10 20:09:23 +00:00
|
|
|
nr_codecs = nr_acodecs;
|
|
|
|
state = 1;
|
|
|
|
goto next;
|
|
|
|
}
|
2001-04-06 23:20:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|