2001-02-24 20:28:24 +00:00
|
|
|
// ACM audio and VfW video codecs initialization
|
|
|
|
// based on the avifile library [http://divx.euro.ru]
|
|
|
|
|
2001-04-06 16:31:18 +00:00
|
|
|
int init_acm_audio_codec(sh_audio_t *sh_audio){
|
2001-02-24 20:28:24 +00:00
|
|
|
HRESULT ret;
|
2001-04-15 14:33:49 +00:00
|
|
|
WAVEFORMATEX *in_fmt=sh_audio->wf;
|
2001-02-24 20:28:24 +00:00
|
|
|
unsigned long srcsize=0;
|
|
|
|
|
|
|
|
if(verbose) printf("======= Win32 (ACM) AUDIO Codec init =======\n");
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
sh_audio->srcstream=NULL;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
// if(in_fmt->nSamplesPerSec==0){ printf("Bad WAVE header!\n");exit(1); }
|
|
|
|
// MSACM_RegisterAllDrivers();
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
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;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-07 21:27:57 +00:00
|
|
|
win32_codec_name = sh_audio->codec->dll;
|
2001-04-06 01:18:59 +00:00
|
|
|
ret=acmStreamOpen(&sh_audio->srcstream,(HACMDRIVER)NULL,
|
|
|
|
in_fmt,&sh_audio->o_wf,
|
2001-02-24 20:28:24 +00:00
|
|
|
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);
|
2001-04-06 01:18:59 +00:00
|
|
|
sh_audio->srcstream=NULL;
|
2001-02-24 20:28:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(verbose) printf("Audio codec opened OK! ;-)\n");
|
|
|
|
|
|
|
|
srcsize=in_fmt->nBlockAlign;
|
2001-04-06 01:18:59 +00:00
|
|
|
acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_SOURCE);
|
2001-02-24 20:28:24 +00:00
|
|
|
if(srcsize<OUTBURST) srcsize=OUTBURST;
|
2001-04-06 01:18:59 +00:00
|
|
|
sh_audio->audio_out_minsize=srcsize; // audio output min. size
|
2001-02-24 20:28:24 +00:00
|
|
|
if(verbose) printf("Audio ACM output buffer min. size: %d\n",srcsize);
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION);
|
|
|
|
sh_audio->audio_in_minsize=srcsize; // audio input min. size
|
2001-02-24 20:28:24 +00:00
|
|
|
if(verbose) printf("Audio ACM input buffer min. size: %d\n",srcsize);
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
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;
|
2001-03-12 01:09:35 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len){
|
2001-03-12 01:09:35 +00:00
|
|
|
ACMSTREAMHEADER ash;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD srcsize=0;
|
2001-04-06 01:18:59 +00:00
|
|
|
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);
|
2001-03-12 01:09:35 +00:00
|
|
|
}
|
|
|
|
memset(&ash, 0, sizeof(ash));
|
|
|
|
ash.cbStruct=sizeof(ash);
|
|
|
|
ash.fdwStatus=0;
|
|
|
|
ash.dwUser=0;
|
2001-04-06 01:18:59 +00:00
|
|
|
ash.pbSrc=sh_audio->a_in_buffer;
|
|
|
|
ash.cbSrcLength=sh_audio->a_in_buffer_len;
|
2001-03-12 01:09:35 +00:00
|
|
|
ash.pbDst=a_buffer;
|
|
|
|
ash.cbDstLength=len;
|
2001-04-06 01:18:59 +00:00
|
|
|
hr=acmStreamPrepareHeader(sh_audio->srcstream,&ash,0);
|
2001-03-12 01:09:35 +00:00
|
|
|
if(hr){
|
|
|
|
printf("ACM_Decoder: acmStreamPrepareHeader error %d\n",hr);
|
|
|
|
return -1;
|
|
|
|
}
|
2001-04-06 01:18:59 +00:00
|
|
|
hr=acmStreamConvert(sh_audio->srcstream,&ash,0);
|
2001-03-12 01:09:35 +00:00
|
|
|
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);
|
2001-04-06 01:18:59 +00:00
|
|
|
if(ash.cbSrcLengthUsed>=sh_audio->a_in_buffer_len){
|
|
|
|
sh_audio->a_in_buffer_len=0;
|
2001-03-12 01:09:35 +00:00
|
|
|
} else {
|
2001-04-06 01:18:59 +00:00
|
|
|
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);
|
2001-03-12 01:09:35 +00:00
|
|
|
}
|
|
|
|
len=ash.cbDstLengthUsed;
|
2001-04-06 01:18:59 +00:00
|
|
|
hr=acmStreamUnprepareHeader(sh_audio->srcstream,&ash,0);
|
2001-03-12 01:09:35 +00:00
|
|
|
if(hr){
|
|
|
|
printf("ACM_Decoder: acmStreamUnprepareHeader error %d\n",hr);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-07 21:27:57 +00:00
|
|
|
int init_video_codec(){
|
2001-02-24 20:28:24 +00:00
|
|
|
HRESULT ret;
|
2001-04-17 19:23:47 +00:00
|
|
|
int yuv=0;
|
2001-04-07 21:27:57 +00:00
|
|
|
unsigned int outfmt=sh_video->codec->outfmt[sh_video->outfmtidx];
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
if(verbose) printf("======= Win32 (VFW) VIDEO Codec init =======\n");
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER));
|
|
|
|
sh_video->o_bih.biSize = sizeof(BITMAPINFOHEADER);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-07 21:27:57 +00:00
|
|
|
win32_codec_name = sh_video->codec->dll;
|
2001-04-15 14:33:49 +00:00
|
|
|
sh_video->hic = ICOpen( 0x63646976, sh_video->bih->biCompression, ICMODE_FASTDECOMPRESS);
|
2001-04-06 01:18:59 +00:00
|
|
|
// sh_video->hic = ICOpen( 0x63646976, sh_video->bih.biCompression, ICMODE_DECOMPRESS);
|
|
|
|
if(!sh_video->hic){
|
2001-02-24 20:28:24 +00:00
|
|
|
printf("ICOpen failed! unknown codec / wrong parameters?\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
// sh_video->bih.biBitCount=32;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-15 14:33:49 +00:00
|
|
|
ret = ICDecompressGetFormat(sh_video->hic, sh_video->bih, &sh_video->o_bih);
|
2001-02-24 20:28:24 +00:00
|
|
|
if(ret){
|
|
|
|
printf("ICDecompressGetFormat failed: Error %d\n", ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(verbose) printf("ICDecompressGetFormat OK\n");
|
|
|
|
|
|
|
|
// printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY);
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
// 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;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
|
2001-04-14 17:55:20 +00:00
|
|
|
switch (outfmt) {
|
|
|
|
|
|
|
|
/* planar format */
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
sh_video->o_bih.biBitCount=12;
|
2001-04-17 19:23:47 +00:00
|
|
|
yuv=1;
|
2001-04-16 01:35:44 +00:00
|
|
|
break;
|
2001-04-14 17:55:20 +00:00
|
|
|
|
|
|
|
/* packed format */
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
case IMGFMT_YVYU:
|
|
|
|
sh_video->o_bih.biBitCount=16;
|
2001-04-17 19:23:47 +00:00
|
|
|
yuv=1;
|
2001-04-14 17:55:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* rgb/bgr format */
|
|
|
|
case IMGFMT_RGB8:
|
|
|
|
case IMGFMT_BGR8:
|
|
|
|
sh_video->o_bih.biBitCount=8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMGFMT_RGB15:
|
|
|
|
case IMGFMT_RGB16:
|
|
|
|
case IMGFMT_BGR15:
|
|
|
|
case IMGFMT_BGR16:
|
|
|
|
sh_video->o_bih.biBitCount=16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMGFMT_RGB24:
|
|
|
|
case IMGFMT_BGR24:
|
|
|
|
sh_video->o_bih.biBitCount=24;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMGFMT_RGB32:
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
sh_video->o_bih.biBitCount=32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("unsupported image format: 0x%x\n", outfmt);
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-14 17:55:20 +00:00
|
|
|
sh_video->o_bih.biSizeImage = sh_video->o_bih.biWidth * sh_video->o_bih.biHeight * (sh_video->o_bih.biBitCount/8);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-14 17:55:20 +00:00
|
|
|
if(!(sh_video->codec->outflags[sh_video->outfmtidx]&CODECS_FLAG_FLIP)) {
|
2001-04-15 14:33:49 +00:00
|
|
|
sh_video->o_bih.biHeight=-sh_video->bih->biHeight; // flip image!
|
2001-04-14 17:55:20 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-17 19:23:47 +00:00
|
|
|
if(yuv && !(sh_video->codec->outflags[sh_video->outfmtidx] & CODECS_FLAG_YUVHACK))
|
2001-04-14 17:55:20 +00:00
|
|
|
sh_video->o_bih.biCompression = outfmt;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
if(verbose) {
|
|
|
|
printf("Starting decompression, format:\n");
|
2001-04-15 14:33:49 +00:00
|
|
|
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 0x%x ('%.4s')\n", sh_video->bih->biCompression, &sh_video->bih->biCompression);
|
|
|
|
printf(" biSizeImage %d\n", sh_video->bih->biSizeImage);
|
2001-02-24 20:28:24 +00:00
|
|
|
printf("Dest fmt:\n");
|
2001-04-06 01:18:59 +00:00
|
|
|
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);
|
2001-04-14 17:55:20 +00:00
|
|
|
printf(" biCompression 0x%x ('%.4s')\n", sh_video->o_bih.biCompression, &sh_video->o_bih.biCompression);
|
2001-04-06 01:18:59 +00:00
|
|
|
printf(" biSizeImage %d\n", sh_video->o_bih.biSizeImage);
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2001-04-15 14:33:49 +00:00
|
|
|
ret = ICDecompressQuery(sh_video->hic, sh_video->bih, &sh_video->o_bih);
|
2001-02-24 20:28:24 +00:00
|
|
|
if(ret){
|
|
|
|
printf("ICDecompressQuery failed: Error %d\n", ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(verbose) printf("ICDecompressQuery OK\n");
|
|
|
|
|
|
|
|
|
2001-04-15 14:33:49 +00:00
|
|
|
ret = ICDecompressBegin(sh_video->hic, sh_video->bih, &sh_video->o_bih);
|
2001-02-24 20:28:24 +00:00
|
|
|
if(ret){
|
|
|
|
printf("ICDecompressBegin failed: Error %d\n", ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
2001-04-06 01:18:59 +00:00
|
|
|
//sh_video->hic
|
2001-02-24 20:28:24 +00:00
|
|
|
//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);
|
2001-04-06 01:18:59 +00:00
|
|
|
ret = ICSendMessage(sh_video->hic,ICM_USER+i,NULL,NULL);
|
2001-02-24 20:28:24 +00:00
|
|
|
printf(" ret=%d\n",ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-04-14 19:30:52 +00:00
|
|
|
sh_video->our_out_buffer = shmem_alloc(sh_video->o_bih.biSizeImage);
|
2001-04-06 01:18:59 +00:00
|
|
|
if(!sh_video->our_out_buffer){
|
|
|
|
printf("not enough memory for decoded picture buffer (%d bytes)\n", sh_video->o_bih.biSizeImage);
|
2001-02-24 20:28:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-04-17 19:23:47 +00:00
|
|
|
if(yuv && sh_video->codec->outflags[sh_video->outfmtidx] & CODECS_FLAG_YUVHACK)
|
2001-04-16 03:01:46 +00:00
|
|
|
sh_video->o_bih.biCompression = outfmt;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
// avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!!
|
|
|
|
|
|
|
|
if(verbose) printf("VIDEO CODEC Init OK!!! ;-)\n");
|
|
|
|
return 1;
|
|
|
|
}
|