# HG changeset patch # User arpi_esp # Date 986678877 0 # Node ID 828ec81e0d64e4d2f597de03d2a5b3236630b265 # Parent a1fe76547e8fa64cac836c69613f279d6382735c codecs.conf support diff -r a1fe76547e8f -r 828ec81e0d64 DOCS/codecs.conf --- a/DOCS/codecs.conf Sat Apr 07 16:59:51 2001 +0000 +++ b/DOCS/codecs.conf Sat Apr 07 21:27:57 2001 +0000 @@ -2,6 +2,12 @@ ; It is not functional yet! until we finish config loader, ; mplayer will use codecs.c!!! +videocodec mpeg12 + info "MPEG 1 or 2" + format 0x1 + driver libmpeg2 + out YV12 + videocodec mpeg4 info "Microsoft MPEG-4 v1/v2" comment "No postprocessing" @@ -9,21 +15,9 @@ fourcc MP42,mp42 driver vfw dll "mpg4c32.dll" - out YUY2 noflip,yuvhack - out RGB32,RGB24,RGB15 + out YUY2 yuvhack + out BGR32,BGR24,BGR15 -videocodec divx - info "DivX ;-) (MS MPEG-4 v3)" - comment "DivX rulez ;-)" - fourcc MP43,mp43 div3 ; fourcc mapping to div3 - fourcc DIV5,div5 div3 - fourcc DIV6,div6 div4 - fourcc DIV3,div3,DIV4,div3 - driver vfw - dll "divxc32.dll" - out YUY2 noflip,yuvhack - out RGB32,RGB24,RGB15 - videocodec divxds info "DivX ;-) (MS MPEG-4 v3)" comment "DivX rulez ;-)" @@ -34,23 +28,35 @@ driver dshow dll "divx_c32.ax" guid 0x82CCd3E0, 0xF71A, 0x11D0, 0x9f, 0xe5, 0x00, 0x60, 0x97, 0x78, 0xaa, 0xaa - out YUY2 noflip - out RGB32,RGB24,RGB16,RGB15 noflip + out YUY2 + out BGR32,BGR24,BGR16,BGR15 +videocodec divx + info "DivX ;-) (MS MPEG-4 v3)" + comment "DivX rulez ;-)" + fourcc MP43,mp43 div3 ; fourcc mapping to div3 + fourcc DIV5,div5 div3 + fourcc DIV6,div6 div4 + fourcc DIV3,div3,DIV4,div3 + driver vfw + dll "divxc32.dll" + out YUY2 yuvhack + out BGR32,BGR24,BGR15 + videocodec odivx info "OpenDivX (MPEG-4 v2)" fourcc DIVX,divx fourcc DIV1,div1 divx driver odivx - out YV12 noflip + out YV12 videocodec indeo5 info "Intel Indeo 5" fourcc IV50,iv50 driver vfw dll "ir50_32.dll" - out YUY2 noflip - out RGB32,RGB24,RGB15 noflip + out YUY2 + out BGR32,BGR24,BGR15 videocodec indeo4 info "Intel Indeo 4.1" @@ -58,7 +64,7 @@ fourcc IV41,iv41 driver vfw dll "ir41_32.dll" - out RGB24,RGB15 flip + out BGR24,BGR15 flip videocodec indeo3 info "Intel Indeo 3.1/3.2" @@ -67,30 +73,30 @@ fourcc IV32,iv32 driver vfw dll "ir32_32.dll" - out RGB24,RGB15 flip + out BGR24,BGR15 flip videocodec cvid info "Cinepak Video" fourcc cvid driver vfw dll "msvidc32.dll" - out YUY2 noflip - out RGB24,RGB15 noflip + out YUY2 + out BGR24,BGR15 videocodec cram info "CRAM" fourcc cram,CRAM driver vfw dll "msvidc32.dll" - out RGB24,RGB15 noflip + out BGR24,BGR15 videocodec vcr2 info "ATI VCR-2" fourcc VCR2 driver vfw dll "ativcr2.dll" - out YUY2 noflip - out RGB32,RGB24,RGB15 noflip + out YUY2 + out BGR32,BGR24,BGR15 videocodec i263 info "I263" @@ -98,7 +104,7 @@ fourcc I263,i263 driver vfw dll "i263_32.drv" - out RGB32,RGB24,RGB15 noflip + out BGR32,BGR24,BGR15 videocodec mjpeg info "Motion JPEG" @@ -106,8 +112,8 @@ driver vfw dll "mcmjpg32.dll" ; dll "m3jpeg32.dll" - out YUY2 noflip - out RGB32,RGB24,RGB15 noflip + out YUY2 + out BGR32,BGR24,BGR15 videocodec wmv1 info "Windows Media Video 7" @@ -115,8 +121,8 @@ driver dshow dll "wmvds32.ax" guid 0x4facbba1, 0xffd8, 0x4cd7, 0x82, 0x28, 0x61, 0xe2, 0xf6, 0x5c, 0xb1, 0xae - out YUY2 noflip - out RGB32,RGB24,RGB16,RGB15 noflip + out YUY2 + out BGR32,BGR24,BGR16,BGR15 audiocodec divx info "DivX audio (WMA)" @@ -166,6 +172,21 @@ format 0x32 driver msgsm +audiocodec alaw + info "aLaw" + format 0x6 + driver alaw + +audiocodec pcm + info "Uncompressed PCM" + format 0x1 + driver pcm + +audiocodec ac3 + info "AC3" + format 0x2000 + driver libac3 + audiocodec voxware info "VoxWare" format 0x75 diff -r a1fe76547e8f -r 828ec81e0d64 Makefile --- a/Makefile Sat Apr 07 16:59:51 2001 +0000 +++ b/Makefile Sat Apr 07 21:27:57 2001 +0000 @@ -22,8 +22,8 @@ prefix = /usr/local BINDIR = ${prefix}/bin # BINDIR = /usr/local/bin -SRCS = subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c -OBJS = subreader.o linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o cfgparser.o +SRCS = codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c +OBJS = codec-cfg.o subreader.o linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o cfgparser.o CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo # -Wall A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 VO_LIBS = -Llibvo -lvo $(X_LIBS) @@ -77,7 +77,7 @@ $(CC) $(CFLAGS) -o $(PRG_TV) tvision.o $(OBJS) -lm $(TERMCAP_LIB) $(VO_LIBS) $(PRG_CFG): codec-cfg.c codec-cfg.h - $(CC) $(CFLAGS) codec-cfg.c -o $(PRG_CFG) -DTESTING + $(CC) $(CFLAGS) -g codec-cfg.c -o $(PRG_CFG) -DTESTING install: $(PRG) install -g $(GROUP) -o $(OWNER) -m $(PERM) -s $(PRG) $(BINDIR) diff -r a1fe76547e8f -r 828ec81e0d64 cfg-mplayer.h --- a/cfg-mplayer.h Sat Apr 07 16:59:51 2001 +0000 +++ b/cfg-mplayer.h Sat Apr 07 21:27:57 2001 +0000 @@ -34,8 +34,8 @@ {"noni", &force_ni, CONF_TYPE_FLAG, 0, 1, 0}, {"aid", &audio_id, CONF_TYPE_INT, CONF_RANGE, 0, 256}, {"vid", &video_id, CONF_TYPE_INT, CONF_RANGE, 0, 256}, - {"auds", &avi_header.audio_codec, CONF_TYPE_STRING, 0, 0, 0}, - {"vids", &avi_header.video_codec, CONF_TYPE_STRING, 0, 0, 0}, +// {"auds", &avi_header.audio_codec, CONF_TYPE_STRING, 0, 0, 0}, +// {"vids", &avi_header.video_codec, CONF_TYPE_STRING, 0, 0, 0}, {"mc", &default_max_pts_correction, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10}, {"fps", &force_fps, CONF_TYPE_FLOAT, CONF_MIN, 0, 0}, {"afm", &audio_format, CONF_TYPE_INT, CONF_RANGE, 1, 6}, diff -r a1fe76547e8f -r 828ec81e0d64 codec-cfg.c --- a/codec-cfg.c Sat Apr 07 16:59:51 2001 +0000 +++ b/codec-cfg.c Sat Apr 07 21:27:57 2001 +0000 @@ -1,3 +1,9 @@ + +//#define DEBUG +#define PRINT_LINENUM +// printf("%s(%d): ", cfgfile, line_num) + + #include #include #include @@ -28,16 +34,17 @@ #define RET_EOL -2 #define RET_OK 0 -FILE *fp; -int line_num = 0; -int line_pos; /* line pos */ -int firstdef = 1; -char *line; -char *token; +static FILE *fp; +static int line_num = 0; +static int line_pos; /* line pos */ +static int firstdef = 1; +static char *line; +static char *token; -int nr_codecs = 0; +static codecs_t *codecs=NULL; +static int nr_codecs = 0; -int get_token(void) +static int get_token(void) { static int read_nextline = 1; @@ -88,7 +95,7 @@ return RET_EOL; } -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) { int i; @@ -133,7 +140,7 @@ return 1; } -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); @@ -153,7 +160,7 @@ } -int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt, +static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt, unsigned char *outflags) { static char *fmtstr[] = { @@ -229,7 +236,7 @@ return 1; } -short get_driver(char *s,int audioflag) +static short get_driver(char *s,int audioflag) { static char *audiodrv[] = { "mp3lib", @@ -256,13 +263,11 @@ return 0; } -//#define DEBUG codecs_t *parse_codec_cfg(char *cfgfile) { -#define PRINT_LINENUM printf("%s(%d): ", cfgfile, line_num) - codecs_t *codecs = NULL; // array of codecs +// codecs_t *codecs = NULL; // array of codecs codecs_t *codec = NULL; // currect codec int free_slots = 0; int tmp, i; @@ -309,10 +314,10 @@ state = 0; if (*token == 'a') { /* audiocodec */ - printf("audio"); + //printf("audio"); codec->flags |= CODECS_FLAG_AUDIO; } else if (*token == 'v') { /* videocodec */ - printf("video"); + //printf("video"); codec->flags &= !CODECS_FLAG_AUDIO; } else { printf("itt valami nagyon el van baszva\n"); @@ -322,28 +327,28 @@ goto parse_error_out; codec->name = strdup(token); state |= GOT_NAME; - printf(" %s\n", codec->name); + //printf(" %s\n", codec->name); } else if (!strcmp(token, "info")) { if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("info"); + //printf("info"); if (state & GOT_INFO || get_token() < 0) goto parse_error_out; codec->info = strdup(token); state |= GOT_INFO; - printf(" %s\n", codec->info); + //printf(" %s\n", codec->info); } else if (!strcmp(token, "comment")) { if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("comment"); + //printf("comment"); if (get_token() < 0) goto parse_error_out; #if 1 if (!codec->comment) codec->comment = strdup(token); - printf(" %s\n", codec->comment); + //printf(" %s\n", codec->comment); #else add_comment(token, &codec->comment); printf(" FIXMEEEEEEEEEEEEEEE\n"); @@ -352,11 +357,11 @@ if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("fourcc"); - if (codec->flags & CODECS_FLAG_AUDIO) { - printf("\n'fourcc' in audiocodec definition!\n"); - goto err_out; - } + //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; param1 = strdup(token); @@ -366,49 +371,49 @@ codec->fourccmap)) goto err_out; state |= GOT_FOURCC; - printf(" %s: %s\n", param1, token); + //printf(" %s: %s\n", param1, token); free(param1); } else if (!strcmp(token, "format")) { if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("format"); - if (!(codec->flags & CODECS_FLAG_AUDIO)) { - printf("\n'format' in videocodec definition!\n"); - goto err_out; - } + //printf("format"); +// if (!(codec->flags & CODECS_FLAG_AUDIO)) { +// printf("\n'format' in videocodec definition!\n"); +// goto err_out; +// } if (get_token() < 0) goto parse_error_out; if (!add_to_format(token, codec->fourcc,codec->fourccmap)) goto err_out; state |= GOT_FORMAT; - printf(" %s\n", token); + //printf(" %s\n", token); } else if (!strcmp(token, "driver")) { if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("driver"); + //printf("driver"); if (get_token() < 0) goto parse_error_out; if ((codec->driver = get_driver(token,codec->flags&CODECS_FLAG_AUDIO)) == -1) goto err_out; - printf(" %s\n", token); + //printf(" %s\n", token); } else if (!strcmp(token, "dll")) { if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("dll"); + //printf("dll"); if (get_token() < 0) goto parse_error_out; codec->dll = strdup(token); - printf(" %s\n", codec->dll); + //printf(" %s\n", codec->dll); } else if (!strcmp(token, "guid")) { if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("guid"); + //printf("guid"); if (get_token() < 0) goto parse_error_out; - printf("'%s'",token); + //printf("'%s'",token); codec->guid.f1=strtoul(token,NULL,0); if (get_token() < 0) goto parse_error_out; codec->guid.f2=strtoul(token,NULL,0); @@ -422,7 +427,7 @@ if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("out"); + //printf("out"); if (get_token() < 0) goto parse_error_out; param1 = strdup(token); @@ -430,16 +435,16 @@ if (!add_to_out(param1, token, codec->outfmt, codec->outflags)) goto err_out; - printf(" %s: %s\n", param1, token); + //printf(" %s: %s\n", param1, token); free(param1); } else if (!strcmp(token, "flags")) { if (!(state & GOT_NAME)) goto parse_error_out; PRINT_LINENUM; - printf("flags"); + //printf("flags"); if (get_token() < 0) goto parse_error_out; - printf(" %s\n", token); + //printf(" %s\n", token); } else goto parse_error_out; } @@ -461,6 +466,23 @@ goto out; } +codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,int audioflag){ + int i,j; + for(i=0;iflags&CODECS_FLAG_AUDIO)) continue; + if(audioflag && !(c->flags&CODECS_FLAG_AUDIO)) continue; + for(j=0;jfourcc[j]==fourcc){ + if(fourccmap) *fourccmap=c->fourccmap[j]; + return c; + } + } + } + return NULL; +} + + #ifdef TESTING int main(void) { diff -r a1fe76547e8f -r 828ec81e0d64 codec-cfg.h --- a/codec-cfg.h Sat Apr 07 16:59:51 2001 +0000 +++ b/codec-cfg.h Sat Apr 07 21:27:57 2001 +0000 @@ -15,14 +15,17 @@ #define CODECS_MAX_FOURCC 16 #define CODECS_MAX_OUTFMT 16 +// Global flags: #define CODECS_FLAG_AUDIO (1<<0) +#define CODECS_FLAG_SEEKABLE (1<<1) +// Outfmt flags: #define CODECS_FLAG_FLIP (1<<0) #define CODECS_FLAG_NOFLIP (1<<1) #define CODECS_FLAG_YUVHACK (1<<2) -#warning nem kellene ket typedef GUID-nak... +//#warning nem kellene ket typedef GUID-nak... typedef struct { unsigned long f1; unsigned short f2; @@ -44,6 +47,7 @@ unsigned char outflags[CODECS_MAX_OUTFMT]; } codecs_t; -codecs_t *parse_codec_cfg(char *cfgfile); +codecs_t* parse_codec_cfg(char *cfgfile); +codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,int audioflag); #endif diff -r a1fe76547e8f -r 828ec81e0d64 dec_audio.c --- a/dec_audio.c Sat Apr 07 16:59:51 2001 +0000 +++ b/dec_audio.c Sat Apr 07 21:27:57 2001 +0000 @@ -1,51 +1,16 @@ - -// FIXME: use codec.conf struct here!!! -int detect_audio_format(sh_audio_t *sh_audio){ - int has_audio=0; -// Decide audio format: - switch(sh_audio->wf.wFormatTag){ - case 0: - has_audio=0;break; // disable/no audio - case 6: - avi_header.audio_seekable=1; - has_audio=5;break; // aLaw - case 0x31: - case 0x32: - has_audio=6;break; // MS-GSM - case 0x50: -#ifdef DEFAULT_MPG123 - case 0x55: -#endif - avi_header.audio_seekable=1; - has_audio=1;break; // MPEG - case 0x01: - avi_header.audio_seekable=1; - has_audio=2;break; // PCM - case 0x2000: - avi_header.audio_seekable=1; - has_audio=3;break; // AC3 - default: - avi_header.audio_seekable=0; - has_audio=4; // Win32/ACM - } - if(has_audio==4){ - if(!avi_header.audio_codec) avi_header.audio_codec=get_auds_codec_name(sh_audio); - if(avi_header.auds_guid) has_audio=7; // force DShow - if(!avi_header.audio_codec) has_audio=0; // unknown win32 codec - if(verbose) printf("win32 audio codec: '%s'\n",avi_header.audio_codec); - } - if(verbose) printf("detected audio format: %d\n",has_audio); - return has_audio; -} int init_audio(sh_audio_t *sh_audio){ -int has_audio=sh_audio->codec.driver; + +int driver=sh_audio->codec->driver; sh_audio->samplesize=2; +sh_audio->samplerate=0; sh_audio->pcm_bswap=0; + sh_audio->a_buffer_size=16384; // default size, maybe not enough for Win32/ACM +sh_audio->a_buffer=NULL; -if(has_audio==4){ +if(driver==4){ // Win32 ACM audio codec: if(init_acm_audio_codec(sh_audio)){ sh_audio->channels=sh_audio->o_wf.nChannels; @@ -54,69 +19,50 @@ sh_audio->a_buffer_size=sh_audio->audio_out_minsize+OUTBURST; } else { printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n"); - if((sh_audio->wf.wFormatTag)==0x55){ - printf("Audio format is MP3 -> fallback to internal mp3lib/mpg123\n"); - has_audio=1; // fallback to mp3lib - } else - has_audio=0; // nosound + driver=0; } } -if(has_audio==7){ +if(driver==7){ #ifndef USE_DIRECTSHOW printf("Compiled without DirectShow support -> force nosound :(\n"); - has_audio=0; + driver=0; #else // Win32 DShow audio codec: - WAVEFORMATEX *in_fmt=&sh_audio->wf; - sh_audio->o_wf.nChannels=in_fmt->nChannels; - sh_audio->o_wf.nSamplesPerSec=in_fmt->nSamplesPerSec; - sh_audio->o_wf.nAvgBytesPerSec=2*sh_audio->o_wf.nSamplesPerSec*sh_audio->o_wf.nChannels; - sh_audio->o_wf.wFormatTag=WAVE_FORMAT_PCM; - sh_audio->o_wf.nBlockAlign=2*in_fmt->nChannels; - sh_audio->o_wf.wBitsPerSample=16; - sh_audio->o_wf.cbSize=0; + printf("DShow_audio: channs=%d rate=%d\n",sh_audio->channels,sh_audio->samplerate); - if(!DS_AudioDecoder_Open(avi_header.audio_codec,avi_header.auds_guid,in_fmt)){ - sh_audio->channels=sh_audio->o_wf.nChannels; - sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec; - - sh_audio->audio_in_minsize=2*sh_audio->o_wf.nBlockAlign; + if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,&sh_audio->wf)){ + printf("ERROR: Could not load/initialize Win32/DirctShow AUDIO codec: %s\n",sh_audio->codec->dll); + driver=0; + } else { + sh_audio->channels=sh_audio->wf.nChannels; + sh_audio->samplerate=sh_audio->wf.nSamplesPerSec; + sh_audio->audio_in_minsize=2*sh_audio->wf.nBlockAlign; if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); sh_audio->a_in_buffer_len=0; - - } else { - printf("ERROR: Could not load/initialize Win32/DirctShow AUDIO codec: %s\n",avi_header.audio_codec); - if((in_fmt->wFormatTag)==0x55){ - printf("Audio format is MP3 -> fallback to internal mp3lib/mpg123\n"); - has_audio=1; // fallback to mp3lib - } else - printf("Audio disabled! Try to upgrade your w32codec.zip package!!!\n"); - has_audio=0; // nosound } #endif } +if(!driver) return 0; // allocate audio out buffer: sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); sh_audio->a_buffer_len=0; -if(has_audio==4){ +switch(driver){ +case 4: { int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,sh_audio->a_buffer_size); if(ret<0){ - printf("ACM error %d -> switching to nosound...\n",ret); - has_audio=0; - } else { - sh_audio->a_buffer_len=ret; - printf("ACM decoding test: %d bytes\n",ret); + printf("ACM decoding error: %d\n",ret); + driver=0; } + break; } - -if(has_audio==2){ +case 2: { // if(file_format==DEMUXER_TYPE_AVI){ // FIXME!!!!!!! // AVI PCM Audio: WAVEFORMATEX *h=&sh_audio->wf; @@ -129,8 +75,9 @@ // sh_audio->samplerate=48000; // sh_audio->pcm_bswap=1; // } -} else -if(has_audio==3){ + break; +} +case 3: { // Dolby AC3 audio: ac3_config.fill_buffer_callback = ac3_fill_buffer; ac3_config.num_output_ch = 2; @@ -146,22 +93,26 @@ if(sh_audio->ac3_frame){ sh_audio->samplerate=sh_audio->ac3_frame->sampling_rate; sh_audio->channels=2; - } else has_audio=0; // bad frame -> disable audio -} else -if(has_audio==5){ + } else { + driver=0; // bad frame -> disable audio + } + break; +} +case 5: { // aLaw audio codec: Gen_aLaw_2_Signed(); // init table sh_audio->channels=sh_audio->wf.nChannels; sh_audio->samplerate=sh_audio->wf.nSamplesPerSec; -} else -if(has_audio==6){ + break; +} +case 6: { // MS-GSM audio codec: GSM_Init(); sh_audio->channels=sh_audio->wf.nChannels; sh_audio->samplerate=sh_audio->wf.nSamplesPerSec; + break; } -// must be here for Win32->mp3lib fallbacks -if(has_audio==1){ +case 1: { // MPEG Audio: MP3_Init(); MP3_samplerate=MP3_channels=0; @@ -170,23 +121,30 @@ // printf("]\n"); sh_audio->channels=2; // hack sh_audio->samplerate=MP3_samplerate; + break; +} } if(!sh_audio->channels || !sh_audio->samplerate){ printf("Unknown/missing audio format, using nosound\n"); - has_audio=0; + driver=0; } - sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; + if(!driver){ + if(sh_audio->a_buffer) free(sh_audio->a_buffer); + sh_audio->o_bps=0; + return 0; + } - return has_audio; + sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; + return driver; } // Audio decoding int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int maxlen){ int len=-1; - switch(sh_audio->codec.driver){ + switch(sh_audio->codec->driver){ case 1: // MPEG layer 2 or 3 len=MP3_DecodeFrame(buf,-1); sh_audio->channels=2; // hack diff -r a1fe76547e8f -r 828ec81e0d64 dll_init.c --- a/dll_init.c Sat Apr 07 16:59:51 2001 +0000 +++ b/dll_init.c Sat Apr 07 21:27:57 2001 +0000 @@ -21,7 +21,7 @@ sh_audio->o_wf.wBitsPerSample=16; sh_audio->o_wf.cbSize=0; - win32_codec_name = avi_header.audio_codec; + win32_codec_name = sh_audio->codec->dll; ret=acmStreamOpen(&sh_audio->srcstream,(HACMDRIVER)NULL, in_fmt,&sh_audio->o_wf, NULL,0,0,0); @@ -100,15 +100,16 @@ -int init_video_codec(int outfmt){ +int init_video_codec(){ HRESULT ret; + unsigned int outfmt=sh_video->codec->outfmt[sh_video->outfmtidx]; if(verbose) printf("======= Win32 (VFW) VIDEO Codec init =======\n"); memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); sh_video->o_bih.biSize = sizeof(BITMAPINFOHEADER); - win32_codec_name = avi_header.video_codec; + win32_codec_name = sh_video->codec->dll; sh_video->hic = ICOpen( 0x63646976, sh_video->bih.biCompression, ICMODE_FASTDECOMPRESS); // sh_video->hic = ICOpen( 0x63646976, sh_video->bih.biCompression, ICMODE_DECOMPRESS); if(!sh_video->hic){ @@ -142,12 +143,14 @@ else sh_video->o_bih.biBitCount=outfmt&0xFF;// //24; + if(sh_video->o_bih.biBitCount==15) ++sh_video->o_bih.biBitCount; + sh_video->o_bih.biSizeImage=sh_video->o_bih.biWidth*sh_video->o_bih.biHeight*(sh_video->o_bih.biBitCount/8); - if(!avi_header.flipped) + if(!(sh_video->codec->outflags[sh_video->outfmtidx]&CODECS_FLAG_FLIP)) sh_video->o_bih.biHeight=-sh_video->bih.biHeight; // flip image! - if(outfmt==IMGFMT_YUY2 && !avi_header.yuv_hack_needed) + if(outfmt==IMGFMT_YUY2 && !(sh_video->codec->outflags[sh_video->outfmtidx]&CODECS_FLAG_YUVHACK)) sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); @@ -205,7 +208,7 @@ return 0; } - if(outfmt==IMGFMT_YUY2 && avi_header.yuv_hack_needed) + if(outfmt==IMGFMT_YUY2 && (sh_video->codec->outflags[sh_video->outfmtidx]&CODECS_FLAG_YUVHACK)) sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); // avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!! diff -r a1fe76547e8f -r 828ec81e0d64 libvo/vo_x11.c --- a/libvo/vo_x11.c Sat Apr 07 16:59:51 2001 +0000 +++ b/libvo/vo_x11.c Sat Apr 07 21:27:57 2001 +0000 @@ -514,11 +514,16 @@ static uint32_t query_format( uint32_t format ) { if( !vo_init() ) return 0; // Can't open X11 - if( ( format&IMGFMT_BGR_MASK )==IMGFMT_BGR && ( format&0xFF )==vo_depthonscreen ) return 1; + if( ( format&IMGFMT_BGR_MASK )==IMGFMT_BGR ){ + int bpp=format&0xFF; + if( bpp==vo_depthonscreen ) return 1; + if( bpp==15 && vo_depthonscreen==16) return 1; // built-in conversion + if( bpp==24 && vo_depthonscreen==32) return 1; // built-in conversion + } switch( format ) - { + { case IMGFMT_YV12: return 1; - } + } return 0; } diff -r a1fe76547e8f -r 828ec81e0d64 mplayer.c --- a/mplayer.c Sat Apr 07 16:59:51 2001 +0000 +++ b/mplayer.c Sat Apr 07 21:27:57 2001 +0000 @@ -51,13 +51,7 @@ #include "loader.h" #include "wine/avifmt.h" -typedef struct -{ - long f1; - short f2; - short f3; - char f4[8]; -} GUID; +#include "codec-cfg.h" #ifdef USE_DIRECTSHOW #include "DirectShow/DS_VideoDec.h" @@ -186,18 +180,6 @@ int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez // video: unsigned int bitrate; - //===== This stuff will be removed when codec.conf reader is finished! ===== - // video codec info: (filled by codecs.c) - char *video_codec; - char yuv_supported; // 1 if codec support YUY2 output format - char yuv_hack_needed; // requires for divx & mpeg4 - char no_32bpp_support; // requires for INDEO 3.x, 4.x - char flipped; // image is upside-down - GUID* vids_guid; - // audio codec info: (filled by codecs.c) - char *audio_codec; - int audio_seekable; - GUID* auds_guid; } avi_header_t; avi_header_t avi_header; @@ -239,8 +221,6 @@ 60*10000, 0,0,0,0,0,0,0 }; -#include "codecs.c" - //**************************************************************************// // Audio codecs: //**************************************************************************// @@ -409,7 +389,7 @@ stream_t* stream=NULL; int file_format=DEMUXER_TYPE_UNKNOWN; int has_audio=1; // audio 0=no 1=mpeg 2=pcm 3=ac3 4=ACM 5=alaw 6=msgsm 7=DShow -int has_video=0; // video 0=no 1=mpeg 2=win32/VfW 3=OpenDivX 4=w32/DShow +int has_video=1; // video 0=no 1=mpeg 2=win32/VfW 3=OpenDivX 4=w32/DShow // int audio_format=0; // override #ifdef ALSA_TIMER @@ -551,6 +531,11 @@ } } +// check codec.conf +if(!parse_codec_cfg(get_path("codecs.conf"))){ + printf("Warning! Couldn't load codecs.conf!"); +} + if(vcd_track){ //============ Open VideoCD track ============== @@ -600,7 +585,6 @@ if(asf_check_header()){ printf("Detected ASF file format!\n"); file_format=DEMUXER_TYPE_ASF; -// printf("!!! ASF files not (yet) supported !!!\n");exit(1); } } //=============== Try to open as MPEG-PS file: ================= @@ -698,7 +682,6 @@ } else { if(force_ni || abs(a_pos-v_pos)>0x100000){ // distance > 1MB printf("Detected NON-INTERLEAVED AVI file-format!\n"); -// file_format=DEMUXER_TYPE_AVI_NI; // HACK!!!! demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!! pts_from_bps=1; // force BPS sync! } @@ -707,7 +690,6 @@ // no index if(force_ni){ printf("Using NON-INTERLEAVED Broken AVI file-format!\n"); -// file_format=DEMUXER_TYPE_AVI_NI; // HACK!!!! demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!! avi_header.idx_pos_a= avi_header.idx_pos_v=avi_header.movi_start; @@ -719,11 +701,7 @@ printf("AVI: missing video stream!? contact the author, it may be a bug :(\n"); exit(1); } - has_video=2; - // Decide audio format: - if(audio_format) - has_audio=audio_format; // override type - else if(has_audio) has_audio=detect_audio_format(sh_audio); + sh_video->format=sh_video->bih.biCompression; if(has_audio){ if(verbose) printf("AVI: Searching for audio stream (id:%d)\n",d_audio->id); if(!ds_fill_buffer(d_audio)){ @@ -731,6 +709,7 @@ has_audio=0; } } + if(has_audio) sh_audio->format=sh_audio->wf.wFormatTag; default_fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; break; } @@ -740,26 +719,12 @@ stream_reset(demuxer->stream); stream_seek(demuxer->stream,avi_header.movi_start); avi_header.idx_pos=0; -#if 0 - if(avi_header.idx_size>0){ - // decide index format: - if(avi_header.idx[0].dwChunkOffsetendpos=avi_header.movi_end; if(!ds_fill_buffer(d_video)){ printf("ASF: missing video stream!? contact the author, it may be a bug :(\n"); exit(1); } - has_video=2; - // Decide audio format: - if(audio_format) - has_audio=audio_format; // override type - else if(has_audio) has_audio=detect_audio_format(sh_audio); + sh_video->format=sh_video->bih.biCompression; if(has_audio){ if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); if(!ds_fill_buffer(d_audio)){ @@ -767,13 +732,26 @@ has_audio=0; } } + if(has_audio) sh_audio->format=sh_audio->wf.wFormatTag; break; } case DEMUXER_TYPE_MPEG_ES: { - demuxer->audio->type=0; - has_audio=0; // ES streams has no audio channel - has_video=1; // mpeg video - break; + demuxer->audio->type=0; + // Find sequence_header first: + if(verbose) printf("Searching for sequence header... ");fflush(stdout); + while(1){ + int i=sync_video_packet(d_video); + if(i==0x1B3) break; // found it! + if(!i || !skip_video_packet(d_video)){ + if(verbose) printf("NONE :(\n"); + printf("MPEG: FATAL: EOF while searching for sequence header\n"); + exit(1); + } + } + if(verbose) printf("OK!\n"); + sh_video->format=1; // mpeg video + has_audio=0; // ES streams has no audio channel + break; } case DEMUXER_TYPE_MPEG_PS: { if(has_audio) @@ -781,10 +759,27 @@ printf("MPEG: No Audio stream found... ->nosound\n"); has_audio=0; } else { - has_audio=d_audio->type; + switch(d_audio->type){ + case 1: sh_audio->format=0x50;break; // mpeg + case 2: sh_audio->format=0x2;break; // pcm + case 3: sh_audio->format=0x2000;break; // ac3 + default: has_audio=0; // unknown type + } } - if(verbose) printf("detected MPG-PS audio format: %d\n",has_audio); - has_video=1; // mpeg video + if(has_audio) if(verbose) printf("detected MPG-PS audio format: %d\n",sh_audio->format); + // Find sequence_header first: + if(verbose) printf("Searching for sequence header... ");fflush(stdout); + while(1){ + int i=sync_video_packet(d_video); + if(i==0x1B3) break; // found it! + if(!i || !skip_video_packet(d_video)){ + if(verbose) printf("NONE :(\n"); + printf("MPEG: FATAL: EOF while searching for sequence header\n"); + exit(1); + } + } + if(verbose) printf("OK!\n"); + sh_video->format=1; // mpeg video break; } } // switch(file_format) @@ -793,52 +788,56 @@ fflush(stdout); -//================== Init VIDEO (codec & libvo) ========================== - -if(has_video==2){ - if(sh_video->video.fccHandler==mmioFOURCC('d', 'v', 'x', '1')) has_video=3; - if(sh_video->video.fccHandler==mmioFOURCC('d', 'i', 'v', 'x')) has_video=3; - if(sh_video->bih.biCompression==mmioFOURCC('d', 'v', 'x', '1')) has_video=3; - if(sh_video->bih.biCompression==mmioFOURCC('d', 'i', 'v', 'x')) has_video=3; -// if(sh_video->bih.biCompression==mmioFOURCC('D', 'I', 'V', 'X')) has_video=3; // Gabucino +//================== Init AUDIO (codec) ========================== +if(has_audio){ + // Go through the codec.conf and find the best codec... + sh_audio->codec=find_codec(sh_audio->format,NULL,1); + if(!sh_audio->codec){ + printf("Can't find codec for audio format 0x%X !\n",sh_audio->format); + has_audio=0; + } else { + printf("Found audio codec: %s drv=%d (%s)\n",sh_audio->codec->name,sh_audio->codec->driver,sh_audio->codec->info); + has_audio=sh_audio->codec->driver; + } } -if(has_video==2){ - if(!avi_header.video_codec) avi_header.video_codec=get_vids_codec_name(sh_video); - if(verbose) - printf("win32 video codec: '%s' %s%s%s\n",avi_header.video_codec, - avi_header.yuv_supported?"[YUV]":"", - avi_header.yuv_hack_needed?"[hack]":"", - avi_header.flipped?"[FLIP]":"" - ); - if(!avi_header.video_codec) exit(1); // unknown video codec - if(avi_header.vids_guid){ -#ifdef USE_DIRECTSHOW - has_video=4; // switching to DirectShow -#else - printf("MPlayer was compiled without DirectShow support!\n");exit(1); -#endif - } +if(has_audio){ + if(verbose) printf("Initializing audio codec...\n"); + has_audio=init_audio(sh_audio); + if(!has_audio){ + printf("Couldn't initialize audio codec! -> nosound\n"); + } else { + printf("AUDIO: samplerate=%d channels=%d bps=%d\n",has_audio,sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize); + } } +//================== Init VIDEO (codec & libvo) ========================== + +// Go through the codec.conf and find the best codec... +sh_video->codec=find_codec(sh_video->format,(unsigned int*) &sh_video->bih.biCompression,0); +if(!sh_video->codec){ + printf("Can't find codec for video format 0x%X !\n",sh_video->format); + exit(1); +} +has_video=sh_video->codec->driver; + +printf("Found video codec: %s drv=%d (%s)\n",sh_video->codec->name,sh_video->codec->driver,sh_video->codec->info); + +for(i=0;icodec->outfmt[i]; + if(video_out->query_format(out_fmt)) break; +} +if(i>=CODECS_MAX_OUTFMT){ + printf("Sorry, selected video_out device is incompatible with this codec.\n"); + exit(1); +} +sh_video->outfmtidx=i; + switch(has_video){ case 2: { - if(avi_header.yuv_supported && video_out->query_format(IMGFMT_YUY2)) out_fmt=IMGFMT_YUY2; else - if(avi_header.no_32bpp_support && video_out->query_format(IMGFMT_BGR|32)) out_fmt=IMGFMT_BGR|24; else - if(video_out->query_format(IMGFMT_BGR|15)) out_fmt=IMGFMT_BGR|16; else - if(video_out->query_format(IMGFMT_BGR|16)) out_fmt=IMGFMT_BGR|16; else - if(video_out->query_format(IMGFMT_BGR|24)) out_fmt=IMGFMT_BGR|24; else - if(video_out->query_format(IMGFMT_BGR|32)) out_fmt=IMGFMT_BGR|32; else { - printf("Sorry, selected video_out device is incompatible with this codec.\n"); - printf("(It can't show 24bpp or 32bpp RGB images. Try to run X at 24/32bpp!)\n"); -// printf("(cannot convert between YUY2, YV12 and RGB colorspace formats)\n"); - exit(1); - } - //if(verbose) printf("AVI out_fmt=%X\n",out_fmt); - if(verbose) if(out_fmt==IMGFMT_YUY2) printf("Using YUV/YUY2 video output format!\n"); if(!init_video_codec(out_fmt)) exit(1); if(verbose) printf("INFO: Win32 video codec init OK!\n"); - if(out_fmt==(IMGFMT_BGR|16)) out_fmt=IMGFMT_BGR|15; // fix bpp + //if(out_fmt==(IMGFMT_BGR|16)) out_fmt=IMGFMT_BGR|15; // fix bpp FIXME! // calculating video bitrate: avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8; @@ -861,24 +860,14 @@ movie_size_y=abs(sh_video->o_bih.biHeight); break; } -#ifdef USE_DIRECTSHOW case 4: { // Win32/DirectShow - if(avi_header.yuv_supported && video_out->query_format(IMGFMT_YUY2)) out_fmt=IMGFMT_YUY2; else -// if(avi_header.no_32bpp_support && video_out->query_format(IMGFMT_BGR|32)) out_fmt=IMGFMT_BGR|24; else - if(video_out->query_format(IMGFMT_BGR|15)) out_fmt=IMGFMT_BGR|15; else - if(video_out->query_format(IMGFMT_BGR|16)) out_fmt=IMGFMT_BGR|16; else - if(video_out->query_format(IMGFMT_BGR|24)) out_fmt=IMGFMT_BGR|24; else - if(video_out->query_format(IMGFMT_BGR|32)) out_fmt=IMGFMT_BGR|32; else { - printf("Sorry, selected video_out device is incompatible with this codec.\n"); - printf("(It can't show 24bpp or 32bpp RGB images. Try to run X at 24/32bpp!)\n"); -// printf("(cannot convert between YUY2, YV12 and RGB colorspace formats)\n"); - exit(1); - } - //if(verbose) printf("AVI out_fmt=%X\n",out_fmt); - if(verbose) if(out_fmt==IMGFMT_YUY2) printf("Using YUV/YUY2 video output format!\n"); +#ifndef USE_DIRECTSHOW + printf("MPlayer was compiled WITHOUT directshow support!\n"); + exit(1); +#else sh_video->our_out_buffer=NULL; - if(DS_VideoDecoder_Open(avi_header.video_codec,avi_header.vids_guid, &sh_video->bih, 0, &sh_video->our_out_buffer)){ - printf("ERROR: Couldn't open required DirectShow codec: %s\n",avi_header.video_codec); + if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, &sh_video->bih, 0, &sh_video->our_out_buffer)){ + printf("ERROR: Couldn't open required DirectShow codec: %s\n",sh_video->codec->dll); printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n"); printf("package from: ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip !\n"); printf("Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n"); @@ -921,12 +910,6 @@ } #endif case 3: { // OpenDivX - out_fmt=IMGFMT_YV12; - if(!video_out->query_format(out_fmt)) { - printf("Sorry, selected video_out device is incompatible with this codec!\n"); - exit(1); - } - if(verbose) printf("OpenDivX video codec\n"); { DEC_PARAM dec_param; DEC_SET dec_set; @@ -956,29 +939,11 @@ avi_header.bitrate/1024.0f ); // display info: -// movie_size_x=sh_video->bih.biWidth+(divx_quality?0:64); movie_size_x=sh_video->bih.biWidth; movie_size_y=abs(sh_video->bih.biHeight); break; } case 1: { - out_fmt=IMGFMT_YV12; - if(!video_out->query_format(out_fmt)) { - printf("Sorry, selected video_out device is incompatible with this codec!\n"); - exit(1); - } - // Find sequence_header first: - if(verbose) printf("Searching for sequence header... ");fflush(stdout); - while(1){ - int i=sync_video_packet(d_video); - if(i==0x1B3) break; // found it! - if(!i || !skip_video_packet(d_video)){ - if(verbose) printf("NONE :(\n"); - printf("MPEG: FATAL: EOF while searching for sequence header\n"); - exit(1); - } - } - if(verbose) printf("FOUND!\n"); // allocate some shared memory for the video packet buffer: videobuffer=shmem_alloc(VIDEOBUFFER_SIZE); if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);} @@ -1017,7 +982,6 @@ picture->bitrate*0.5f, picture->bitrate/16.0f ); // display info: -// movie_size_x=picture->coded_picture_width; movie_size_x=picture->display_picture_width; movie_size_y=picture->display_picture_height; break; @@ -1167,16 +1131,6 @@ current_module="setup_audio"; if(has_audio){ - - if(verbose) printf("Initializing audio codec...\n"); - - sh_audio->codec.driver=has_audio; // FIXME! - has_audio=init_audio(sh_audio); - sh_audio->codec.driver=has_audio; // FIXME! - -if(verbose) printf("Audio: type: %d samplerate=%d channels=%d bps=%d\n",has_audio,sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize); - -if(has_audio){ #ifdef USE_XMMP_AUDIO xmm_Init( &xmm ); xmm.cSound = (XMM_PluginSound *)xmm_PluginRegister( XMMP_AUDIO_DRIVER ); @@ -1247,7 +1201,6 @@ printf("Audio buffer size: %d bytes, delay: %5.3fs\n",audio_buffer_size,buffer_delay); } -} // has_audio if(has_audio){ printf("Audio: type: %d samplerate: %d channels: %d bps: %d\n",has_audio,sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize); @@ -1283,15 +1236,6 @@ printf("Start playing...\n");fflush(stdout); -#if 0 - // ACM debug code -{ DWORD srcsize=0; - DWORD dstsize=16384*8; - int ret=acmStreamSize(avi_header.srcstream,dstsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); - printf("acmStreamSize %d -> %d (err=%d)\n",dstsize,srcsize,ret); -} -#endif - InitTimer(); while(!eof){ @@ -1303,7 +1247,7 @@ // Update buffer if needed unsigned int t=GetTimer(); current_module="decode_audio"; // Enter AUDIO decoder module - sh_audio->codec.driver=has_audio; // FIXME! + sh_audio->codec->driver=has_audio; // FIXME! while(sh_audio->a_buffer_leneof){ int ret=decode_audio(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len],sh_audio->a_buffer_size-sh_audio->a_buffer_len); if(ret>0) sh_audio->a_buffer_len+=ret; else break; @@ -1934,7 +1878,7 @@ avi_header.idx_pos_a=avi_header.idx_pos_v= avi_header.idx_pos=audio_chunk_pos; - if(!avi_header.audio_seekable){ + if(!(sh_audio->codec->flags&CODECS_FLAG_SEEKABLE)){ #if 0 // curr_audio_pos=apos; // selected audio codec can't seek in chunk skip_audio_secs=(float)skip_audio_bytes/(float)sh_audio->wf.nAvgBytesPerSec; diff -r a1fe76547e8f -r 828ec81e0d64 stheader.h --- a/stheader.h Sat Apr 07 16:59:51 2001 +0000 +++ b/stheader.h Sat Apr 07 21:27:57 2001 +0000 @@ -1,13 +1,16 @@ // Stream headers: +/* typedef struct { int driver; // codec descriptor from codec.conf } codecinfo_t; +*/ typedef struct { demux_stream_t *ds; - codecinfo_t codec; + unsigned int format; + codecs_t *codec; // output format: int samplerate; int samplesize; @@ -36,11 +39,12 @@ typedef struct { demux_stream_t *ds; - codecinfo_t codec; + unsigned int format; + codecs_t *codec; // output format: float fps; float frametime; // 1/fps - unsigned int outfmt; + unsigned int outfmtidx; // unsigned int bitrate; // buffers: char *our_out_buffer;