diff options
author | arpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-04-06 01:18:59 +0000 |
---|---|---|
committer | arpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-04-06 01:18:59 +0000 |
commit | d9a5713e26f69230f3dc35a8d9136d2d583f7b7f (patch) | |
tree | 0b23fc29e4255baa3aa03b76c63c11caa95d89cc /dll_init.c | |
parent | d81123c78b8d00d9a9534173ba69dc5c437f80d5 (diff) | |
download | mpv-d9a5713e26f69230f3dc35a8d9136d2d583f7b7f.tar.bz2 mpv-d9a5713e26f69230f3dc35a8d9136d2d583f7b7f.tar.xz |
sh_audio/sh_video added, general codec cleanup
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@292 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'dll_init.c')
-rw-r--r-- | dll_init.c | 168 |
1 files changed, 82 insertions, 86 deletions
diff --git a/dll_init.c b/dll_init.c index deaa29e499..63c8d2ad8f 100644 --- a/dll_init.c +++ b/dll_init.c @@ -1,101 +1,97 @@ // ACM audio and VfW video codecs initialization // based on the avifile library [http://divx.euro.ru] -static char* a_in_buffer=NULL; -static int a_in_buffer_len=0; -static int a_in_buffer_size=0; - -int init_audio_codec(){ +int init_audio_codec(sh_audio_t *sh_audio){ HRESULT ret; - WAVEFORMATEX *in_fmt=(WAVEFORMATEX*)&avi_header.wf_ext; + WAVEFORMATEX *in_fmt=&sh_audio->wf; unsigned long srcsize=0; if(verbose) printf("======= Win32 (ACM) AUDIO Codec init =======\n"); - avi_header.srcstream=NULL; + sh_audio->srcstream=NULL; // if(in_fmt->nSamplesPerSec==0){ printf("Bad WAVE header!\n");exit(1); } // MSACM_RegisterAllDrivers(); - avi_header.wf.nChannels=in_fmt->nChannels; - avi_header.wf.nSamplesPerSec=in_fmt->nSamplesPerSec; - avi_header.wf.nAvgBytesPerSec=2*avi_header.wf.nSamplesPerSec*avi_header.wf.nChannels; - avi_header.wf.wFormatTag=WAVE_FORMAT_PCM; - avi_header.wf.nBlockAlign=2*in_fmt->nChannels; - avi_header.wf.wBitsPerSample=16; - avi_header.wf.cbSize=0; + 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; win32_codec_name = avi_header.audio_codec; - ret=acmStreamOpen(&avi_header.srcstream,(HACMDRIVER)NULL, - in_fmt,&avi_header.wf, + ret=acmStreamOpen(&sh_audio->srcstream,(HACMDRIVER)NULL, + in_fmt,&sh_audio->o_wf, NULL,0,0,0); if(ret){ if(ret==ACMERR_NOTPOSSIBLE) printf("ACM_Decoder: Unappropriate audio format\n"); else printf("ACM_Decoder: acmStreamOpen error %d", ret); - avi_header.srcstream=NULL; + sh_audio->srcstream=NULL; return 0; } if(verbose) printf("Audio codec opened OK! ;-)\n"); srcsize=in_fmt->nBlockAlign; - acmStreamSize(avi_header.srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_SOURCE); + acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_SOURCE); if(srcsize<OUTBURST) srcsize=OUTBURST; - avi_header.audio_out_minsize=srcsize; // audio output min. size + sh_audio->audio_out_minsize=srcsize; // audio output min. size if(verbose) printf("Audio ACM output buffer min. size: %d\n",srcsize); - acmStreamSize(avi_header.srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); - avi_header.audio_in_minsize=srcsize; // audio input min. size + acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); + sh_audio->audio_in_minsize=srcsize; // audio input min. size if(verbose) printf("Audio ACM input buffer min. size: %d\n",srcsize); - a_in_buffer_size=avi_header.audio_in_minsize; - a_in_buffer=malloc(a_in_buffer_size); - a_in_buffer_len=0; + 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; return 1; } -int acm_decode_audio(void* a_buffer,int len){ +int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len){ ACMSTREAMHEADER ash; HRESULT hr; DWORD srcsize=0; - acmStreamSize(avi_header.srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION); - if(verbose>=3)printf("acm says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,a_in_buffer_size,len); -// if(srcsize==0) srcsize=((WAVEFORMATEX *)&avi_header.wf_ext)->nBlockAlign; - if(srcsize>a_in_buffer_size) srcsize=a_in_buffer_size; // !!!!!! - if(a_in_buffer_len<srcsize){ - a_in_buffer_len+= - demux_read_data(d_audio,&a_in_buffer[a_in_buffer_len], - srcsize-a_in_buffer_len); + acmStreamSize(sh_audio->srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION); + if(verbose>=3)printf("acm says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,len); +// if(srcsize==0) srcsize=((WAVEFORMATEX *)&sh_audio->o_wf_ext)->nBlockAlign; + if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! + if(sh_audio->a_in_buffer_len<srcsize){ + sh_audio->a_in_buffer_len+= + demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], + srcsize-sh_audio->a_in_buffer_len); } memset(&ash, 0, sizeof(ash)); ash.cbStruct=sizeof(ash); ash.fdwStatus=0; ash.dwUser=0; - ash.pbSrc=a_in_buffer; - ash.cbSrcLength=a_in_buffer_len; + ash.pbSrc=sh_audio->a_in_buffer; + ash.cbSrcLength=sh_audio->a_in_buffer_len; ash.pbDst=a_buffer; ash.cbDstLength=len; - hr=acmStreamPrepareHeader(avi_header.srcstream,&ash,0); + hr=acmStreamPrepareHeader(sh_audio->srcstream,&ash,0); if(hr){ printf("ACM_Decoder: acmStreamPrepareHeader error %d\n",hr); return -1; } - hr=acmStreamConvert(avi_header.srcstream,&ash,0); + hr=acmStreamConvert(sh_audio->srcstream,&ash,0); if(hr){ printf("ACM_Decoder: acmStreamConvert error %d\n",hr); return -1; } //printf("ACM convert %d -> %d (buf=%d)\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed,a_in_buffer_len); - if(ash.cbSrcLengthUsed>=a_in_buffer_len){ - a_in_buffer_len=0; + if(ash.cbSrcLengthUsed>=sh_audio->a_in_buffer_len){ + sh_audio->a_in_buffer_len=0; } else { - a_in_buffer_len-=ash.cbSrcLengthUsed; - memcpy(a_in_buffer,&a_in_buffer[ash.cbSrcLengthUsed],a_in_buffer_len); + sh_audio->a_in_buffer_len-=ash.cbSrcLengthUsed; + memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[ash.cbSrcLengthUsed],sh_audio->a_in_buffer_len); } len=ash.cbDstLengthUsed; - hr=acmStreamUnprepareHeader(avi_header.srcstream,&ash,0); + hr=acmStreamUnprepareHeader(sh_audio->srcstream,&ash,0); if(hr){ printf("ACM_Decoder: acmStreamUnprepareHeader error %d\n",hr); } @@ -109,20 +105,20 @@ int init_video_codec(int outfmt){ if(verbose) printf("======= Win32 (VFW) VIDEO Codec init =======\n"); - memset(&avi_header.o_bih, 0, sizeof(BITMAPINFOHEADER)); - avi_header.o_bih.biSize = sizeof(BITMAPINFOHEADER); + memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); + sh_video->o_bih.biSize = sizeof(BITMAPINFOHEADER); win32_codec_name = avi_header.video_codec; - avi_header.hic = ICOpen( 0x63646976, avi_header.bih.biCompression, ICMODE_FASTDECOMPRESS); -// avi_header.hic = ICOpen( 0x63646976, avi_header.bih.biCompression, ICMODE_DECOMPRESS); - if(!avi_header.hic){ + 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){ printf("ICOpen failed! unknown codec / wrong parameters?\n"); return 0; } -// avi_header.bih.biBitCount=32; +// sh_video->bih.biBitCount=32; - ret = ICDecompressGetFormat(avi_header.hic, &avi_header.bih, &avi_header.o_bih); + ret = ICDecompressGetFormat(sh_video->hic, &sh_video->bih, &sh_video->o_bih); if(ret){ printf("ICDecompressGetFormat failed: Error %d\n", ret); return 0; @@ -131,52 +127,52 @@ int init_video_codec(int outfmt){ // printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY); -// avi_header.o_bih.biWidth=avi_header.bih.biWidth; -// avi_header.o_bih.biCompression = 0x32315659; // mmioFOURCC('U','Y','V','Y'); -// ret=ICDecompressGetFormatSize(avi_header.hic,&avi_header.o_bih); -// avi_header.o_bih.biCompression = 3; //0x32315659; -// avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); -// avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); -// avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); -// avi_header.o_bih.biPlanes=3; -// avi_header.o_bih.biBitCount=16; +// sh_video->o_bih.biWidth=sh_video->bih.biWidth; +// sh_video->o_bih.biCompression = 0x32315659; // mmioFOURCC('U','Y','V','Y'); +// ret=ICDecompressGetFormatSize(sh_video->hic,&sh_video->o_bih); +// sh_video->o_bih.biCompression = 3; //0x32315659; +// sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); +// sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); +// sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); +// sh_video->o_bih.biPlanes=3; +// sh_video->o_bih.biBitCount=16; if(outfmt==IMGFMT_YUY2) - avi_header.o_bih.biBitCount=16; + sh_video->o_bih.biBitCount=16; else - avi_header.o_bih.biBitCount=outfmt&0xFF;// //24; + sh_video->o_bih.biBitCount=outfmt&0xFF;// //24; - avi_header.o_bih.biSizeImage=avi_header.o_bih.biWidth*avi_header.o_bih.biHeight*(avi_header.o_bih.biBitCount/8); + 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) - avi_header.o_bih.biHeight=-avi_header.bih.biHeight; // flip image! + sh_video->o_bih.biHeight=-sh_video->bih.biHeight; // flip image! if(outfmt==IMGFMT_YUY2 && !avi_header.yuv_hack_needed) - avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); + sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); -// avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); +// sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); if(verbose) { printf("Starting decompression, format:\n"); - printf(" biSize %d\n", avi_header.bih.biSize); - printf(" biWidth %d\n", avi_header.bih.biWidth); - printf(" biHeight %d\n", avi_header.bih.biHeight); - printf(" biPlanes %d\n", avi_header.bih.biPlanes); - printf(" biBitCount %d\n", avi_header.bih.biBitCount); - printf(" biCompression %d='%.4s'\n", avi_header.bih.biCompression, &avi_header.bih.biCompression); - printf(" biSizeImage %d\n", avi_header.bih.biSizeImage); + printf(" biSize %d\n", sh_video->bih.biSize); + printf(" biWidth %d\n", sh_video->bih.biWidth); + printf(" biHeight %d\n", sh_video->bih.biHeight); + printf(" biPlanes %d\n", sh_video->bih.biPlanes); + printf(" biBitCount %d\n", sh_video->bih.biBitCount); + printf(" biCompression %d='%.4s'\n", sh_video->bih.biCompression, &sh_video->bih.biCompression); + printf(" biSizeImage %d\n", sh_video->bih.biSizeImage); printf("Dest fmt:\n"); - printf(" biSize %d\n", avi_header.o_bih.biSize); - printf(" biWidth %d\n", avi_header.o_bih.biWidth); - printf(" biHeight %d\n", avi_header.o_bih.biHeight); - printf(" biPlanes %d\n", avi_header.o_bih.biPlanes); - printf(" biBitCount %d\n", avi_header.o_bih.biBitCount); - printf(" biCompression %d='%.4s'\n", avi_header.o_bih.biCompression, &avi_header.o_bih.biCompression); - printf(" biSizeImage %d\n", avi_header.o_bih.biSizeImage); + printf(" biSize %d\n", sh_video->o_bih.biSize); + printf(" biWidth %d\n", sh_video->o_bih.biWidth); + printf(" biHeight %d\n", sh_video->o_bih.biHeight); + printf(" biPlanes %d\n", sh_video->o_bih.biPlanes); + printf(" biBitCount %d\n", sh_video->o_bih.biBitCount); + printf(" biCompression %d='%.4s'\n", sh_video->o_bih.biCompression, &sh_video->o_bih.biCompression); + printf(" biSizeImage %d\n", sh_video->o_bih.biSizeImage); } - ret = ICDecompressQuery(avi_header.hic, &avi_header.bih, &avi_header.o_bih); + ret = ICDecompressQuery(sh_video->hic, &sh_video->bih, &sh_video->o_bih); if(ret){ printf("ICDecompressQuery failed: Error %d\n", ret); return 0; @@ -184,7 +180,7 @@ int init_video_codec(int outfmt){ if(verbose) printf("ICDecompressQuery OK\n"); - ret = ICDecompressBegin(avi_header.hic, &avi_header.bih, &avi_header.o_bih); + ret = ICDecompressBegin(sh_video->hic, &sh_video->bih, &sh_video->o_bih); if(ret){ printf("ICDecompressBegin failed: Error %d\n", ret); return 0; @@ -192,25 +188,25 @@ int init_video_codec(int outfmt){ #if 0 -//avi_header.hic +//sh_video->hic //ICSendMessage(HIC hic,unsigned int msg,long lParam1,long lParam2) { int i; for(i=73;i<256;i++){ printf("Calling ICM_USER+%d function...",i);fflush(stdout); - ret = ICSendMessage(avi_header.hic,ICM_USER+i,NULL,NULL); + ret = ICSendMessage(sh_video->hic,ICM_USER+i,NULL,NULL); printf(" ret=%d\n",ret); } } #endif - avi_header.our_out_buffer = malloc(avi_header.o_bih.biSizeImage); - if(!avi_header.our_out_buffer){ - printf("not enough memory for decoded picture buffer (%d bytes)\n", avi_header.o_bih.biSizeImage); + sh_video->our_out_buffer = malloc(sh_video->o_bih.biSizeImage); + if(!sh_video->our_out_buffer){ + printf("not enough memory for decoded picture buffer (%d bytes)\n", sh_video->o_bih.biSizeImage); return 0; } if(outfmt==IMGFMT_YUY2 && avi_header.yuv_hack_needed) - avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); + sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); // avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!! |