diff options
-rw-r--r-- | asfheader.c | 16 | ||||
-rw-r--r-- | aviheader.c | 20 | ||||
-rw-r--r-- | codecs.c | 12 | ||||
-rw-r--r-- | dec_audio.c | 91 | ||||
-rw-r--r-- | demux_avi.c | 4 | ||||
-rw-r--r-- | demuxer.c | 4 | ||||
-rw-r--r-- | dll_init.c | 168 | ||||
-rw-r--r-- | mplayer.c | 351 | ||||
-rw-r--r-- | stheader.h | 49 |
9 files changed, 390 insertions, 325 deletions
diff --git a/asfheader.c b/asfheader.c index 29f71b9698..cc56cb1dd4 100644 --- a/asfheader.c +++ b/asfheader.c @@ -125,8 +125,9 @@ while(!stream_eof(demuxer->stream)){ // type-specific data: stream_read(demuxer->stream,(char*) buffer,streamh.type_size); switch(*((unsigned int*)&streamh.type)){ - case 0xF8699E40: // guid_audio_stream - memcpy(avi_header.wf_ext,buffer,streamh.type_size<64?streamh.type_size:64); + case 0xF8699E40: { // guid_audio_stream + sh_audio_t *sh_audio=&sh_audio_i; // FIXME! + memcpy(&sh_audio->wf,buffer,streamh.type_size<64?streamh.type_size:64); if(verbose>=1) print_wave_header((WAVEFORMATEX*)buffer); if((*((unsigned int*)&streamh.concealment))==0xbfc3cd50){ stream_read(demuxer->stream,(char*) buffer,streamh.stream_size); @@ -140,12 +141,17 @@ while(!stream_eof(demuxer->stream)){ printf("ASF audio scrambling: %d x %d x %d\n",asf_scrambling_h,asf_scrambling_w,asf_scrambling_b); if(demuxer->audio->id==-1) demuxer->audio->id=streamh.stream_no & 0x7F; break; - case 0xBC19EFC0: // guid_video_stream - memcpy(&avi_header.bih,&buffer[4+4+1+2],sizeof(BITMAPINFOHEADER)); + } + case 0xBC19EFC0: { // guid_video_stream + sh_video_t *sh_video=&sh_video_i; // FIXME! + memcpy(&sh_video->bih,&buffer[4+4+1+2],sizeof(BITMAPINFOHEADER)); + sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; + sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; if(verbose>=1) print_video_header((BITMAPINFOHEADER*)&buffer[4+4+1+2]); //asf_video_id=streamh.stream_no & 0x7F; - if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F; + if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F; break; + } } // stream-specific data: // stream_read(demuxer->stream,(char*) buffer,streamh.stream_size); diff --git a/aviheader.c b/aviheader.c index 9fd8c220c1..215fbc1bce 100644 --- a/aviheader.c +++ b/aviheader.c @@ -41,28 +41,28 @@ while(1){ AVIStreamHeader h; stream_read(demuxer->stream,(char*) &h,MIN(size2,sizeof(h))); chunksize-=MIN(size2,sizeof(h)); - if(h.fccType==streamtypeVIDEO) memcpy(&avi_header.video,&h,sizeof(h));else - if(h.fccType==streamtypeAUDIO) memcpy(&avi_header.audio,&h,sizeof(h)); + if(h.fccType==streamtypeVIDEO) memcpy(&sh_video_i.video,&h,sizeof(h));else + if(h.fccType==streamtypeAUDIO) memcpy(&sh_audio_i.audio,&h,sizeof(h)); last_fccType=h.fccType; if(verbose>=1) print_strh(&h); ++stream_id; break; } case ckidSTREAMFORMAT: { // read 'strf' if(last_fccType==streamtypeVIDEO){ - stream_read(demuxer->stream,(char*) &avi_header.bih,MIN(size2,sizeof(avi_header.bih))); - chunksize-=MIN(size2,sizeof(avi_header.bih)); -// init_video_codec(); -// init_video_out(); + sh_video_t *sh_video=&sh_video_i; // FIXME! + stream_read(demuxer->stream,(char*) &sh_video->bih,MIN(size2,sizeof(sh_video->bih))); + chunksize-=MIN(size2,sizeof(sh_video->bih)); + sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; + sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; if(demuxer->video->id==-1) demuxer->video->id=stream_id; } else if(last_fccType==streamtypeAUDIO){ + sh_audio_t *sh_audio=&sh_audio_i; // FIXME! int z=(chunksize<64)?chunksize:64; if(verbose>=2) printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX)); - stream_read(demuxer->stream,(char*) &avi_header.wf_ext,z); + stream_read(demuxer->stream,(char*) &sh_audio->wf,z); chunksize-=z; - if(verbose>=1) print_wave_header((WAVEFORMATEX*)&avi_header.wf_ext); -// init_audio_codec(); -// init_audio_out(); + if(verbose>=1) print_wave_header(&sh_audio->wf); if(demuxer->audio->id==-1) demuxer->audio->id=stream_id; } break; @@ -21,9 +21,9 @@ static GUID CLSID_TM20DecompressorCF={0x4cb63e61, 0xc611, 0x11D0, { 0x83, 0xaa, 0x00, 0x00, 0x92, 0x90, 0x01, 0x84}}; -char* get_vids_codec_name(){ +char* get_vids_codec_name(sh_video_t *sh){ // unsigned long fccHandler=avi_header.video.fccHandler; - unsigned long fccHandler=avi_header.bih.biCompression; + unsigned long fccHandler=sh->bih.biCompression; avi_header.yuv_supported=0; avi_header.yuv_hack_needed=0; avi_header.flipped=0; @@ -47,7 +47,7 @@ char* get_vids_codec_name(){ case mmioFOURCC('M', 'P', '4', '3'): case mmioFOURCC('m', 'p', '4', '3'): printf("Video in MPEG-4 v3 (really DivX) format\n"); - avi_header.bih.biCompression=mmioFOURCC('d', 'i', 'v', '3'); // hack + sh->bih.biCompression=mmioFOURCC('d', 'i', 'v', '3'); // hack avi_header.yuv_supported=1; #ifdef USE_DIRECTSHOW avi_header.vids_guid=&CLSID_DivxDecompressorCF; @@ -69,7 +69,7 @@ char* get_vids_codec_name(){ case mmioFOURCC('d', 'i', 'v', '5'): case mmioFOURCC('D', 'I', 'V', '6'): case mmioFOURCC('d', 'i', 'v', '6'): - avi_header.bih.biCompression-=0x02000000; // div5->div3, div6->div4 + sh->bih.biCompression-=0x02000000; // div5->div3, div6->div4 case mmioFOURCC('D', 'I', 'V', '3'): case mmioFOURCC('d', 'i', 'v', '3'): case mmioFOURCC('D', 'I', 'V', '4'): @@ -195,8 +195,8 @@ char* get_vids_codec_name(){ return NULL; } -char* get_auds_codec_name(){ - int id=((WAVEFORMATEX*)avi_header.wf_ext)->wFormatTag; +char* get_auds_codec_name(sh_audio_t *sh){ + int id=sh->wf.wFormatTag; avi_header.auds_guid=NULL; switch (id){ case 0x161://DivX audio diff --git a/dec_audio.c b/dec_audio.c new file mode 100644 index 0000000000..8501fa2d82 --- /dev/null +++ b/dec_audio.c @@ -0,0 +1,91 @@ + +// Audio decoding + +int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int maxlen){ + int len=-1; + switch(sh_audio->codec.driver){ + case 1: // MPEG layer 2 or 3 + len=MP3_DecodeFrame(buf,-1); + MP3_channels=2; // hack + break; + case 2: // PCM + { len=demux_read_data(sh_audio->ds,buf,OUTBURST); + if(sh_audio->pcm_bswap){ + int j; + //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } + for(j=0;j<len;j+=2){ + char x=buf[j]; + buf[j]=buf[j+1]; + buf[j+1]=x; + } + } + break; + } + case 5: // aLaw decoder + { int l=demux_read_data(sh_audio->ds,buf,OUTBURST/2); + unsigned short *d=(unsigned short *) buf; + unsigned char *s=buf; + len=2*l; + while(l>0){ + --l; + d[l]=xa_alaw_2_sign[s[l]]; + } + break; + } + case 6: // MS-GSM decoder + { unsigned char buf[65]; // 65 bytes / frame + len=0; + while(len<OUTBURST){ + if(demux_read_data(d_audio,buf,65)!=65) break; // EOF + XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short +// XA_GSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 33 byte -> 160 short + len+=2*320; + } + break; + } + case 3: // AC3 decoder + //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); + if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); + //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); + if(sh_audio->ac3_frame){ + len = 256 * 6 *MP3_channels*MP3_bps; + memcpy(buf,sh_audio->ac3_frame->audio_data,len); + sh_audio->ac3_frame=NULL; + } + //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); + break; + case 4: + { len=acm_decode_audio(sh_audio,buf,maxlen); + break; + } +#ifdef USE_DIRECTSHOW + case 7: // DirectShow + { int ret; + int size_in=0; + int size_out=0; + int srcsize=DS_AudioDecoder_GetSrcSize(maxlen); + if(verbose>2)printf("DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen); + 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); + } + DS_AudioDecoder_Convert(sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, + buf,maxlen, &size_in,&size_out); + if(verbose>2)printf("DShow: audio %d -> %d converted (in_buf_len=%d of %d)\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size); + if(size_in>=sh_audio->a_in_buffer_len){ + sh_audio->a_in_buffer_len=0; + } else { + sh_audio->a_in_buffer_len-=size_in; + memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); + } + len=size_out; + break; + } +#endif + } + return len; +} + + diff --git a/demux_avi.c b/demux_avi.c index 5396c43041..9a847fec23 100644 --- a/demux_avi.c +++ b/demux_avi.c @@ -48,7 +48,9 @@ static int demux_avi_read_packet(demuxer_t *demux,unsigned int id,unsigned int l } // ezt a 2 sort lehet hogy fell kell majd cserelni: //avi_video_pts+=avi_pts_frametime; - avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate; + //avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate; + //avi_video_pts+=((sh_video_t*)ds->sh)->frametime; + avi_video_pts+=(float)((sh_video_t*)(demux->video->sh))->video.dwScale/(float)((sh_video_t*)(demux->video->sh))->video.dwRate; avi_audio_pts=avi_video_pts; } @@ -45,6 +45,8 @@ typedef struct { // ---- asf ----- demux_packet_t *asf_packet; // read asf fragments here int asf_seq; +// ---- stream header ---- + void* sh; } demux_stream_t; demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id){ @@ -65,6 +67,8 @@ demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id){ //---------------- ds->asf_seq=-1; ds->asf_packet=NULL; +//---------------- + ds->sh=NULL; return ds; } 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!!!! @@ -184,38 +184,24 @@ typedef struct { int idx_pos_a; int idx_pos_v; int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez -// int a_idx; -// int v_idx; // video: - AVIStreamHeader video; - char *video_codec; - BITMAPINFOHEADER bih; // in format - BITMAPINFOHEADER o_bih; // out format - HIC hic; - char *our_out_buffer; unsigned int bitrate; - // video format flags: (filled by codecs.c) + // 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: - AVIStreamHeader audio; + // audio codec info: (filled by codecs.c) char *audio_codec; int audio_seekable; GUID* auds_guid; - char wf_ext[64]; // in format - WAVEFORMATEX wf; // out format - HACMSTREAM srcstream; - int audio_in_minsize; - int audio_out_minsize; } avi_header_t; avi_header_t avi_header; #include "aviprint.c" -#include "codecs.c" extern picture_t *picture; @@ -229,6 +215,9 @@ int encode_bitrate=0; #include "stream.c" #include "demuxer.c" + +#include "stheader.h" + #include "demux_avi.c" #include "demux_mpg.c" @@ -236,6 +225,11 @@ demuxer_t *demuxer=NULL; demux_stream_t *d_audio=NULL; demux_stream_t *d_video=NULL; +sh_audio_t sh_audio_i; // FIXME later! +sh_video_t sh_video_i; +sh_audio_t *sh_audio=&sh_audio_i; +sh_video_t *sh_video=&sh_video_i; + // MPEG video stream parser: #include "parse_es.c" @@ -244,6 +238,8 @@ static const int frameratecode2framerate[16] = { 60*10000, 0,0,0,0,0,0,0 }; +#include "codecs.c" + //**************************************************************************// // Audio codecs: //**************************************************************************// @@ -251,12 +247,12 @@ static const int frameratecode2framerate[16] = { //int mp3_read(char *buf,int size){ int mplayer_audio_read(char *buf,int size){ int len; - len=demux_read_data(d_audio,buf,size); + len=demux_read_data(sh_audio->ds,buf,size); return len; } static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ - int len=ds_get_packet(d_audio,(char**)start); + int len=ds_get_packet(sh_audio->ds,(char**)start); //printf("<ac3:%d>\n",len); if(len<0) *start = *end = NULL; @@ -268,6 +264,8 @@ static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ #include "xa/xa_gsm.h" +#include "dec_audio.c" + //**************************************************************************// // The OpenDivX stuff: //**************************************************************************// @@ -649,6 +647,8 @@ if(file_format==DEMUXER_TYPE_UNKNOWN){ //====== File format recognized, set up these for compatibility: ========= d_audio=demuxer->audio; d_video=demuxer->video; +d_audio->sh=sh_audio; sh_audio->ds=d_audio; +d_video->sh=sh_video; sh_video->ds=d_video; switch(file_format){ case DEMUXER_TYPE_AVI: { @@ -723,7 +723,7 @@ switch(file_format){ if(audio_format) has_audio=audio_format; // override type else if(has_audio) - switch(((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag){ + switch(sh_audio->wf.wFormatTag){ case 0: has_audio=0;break; // disable/no audio case 6: @@ -750,7 +750,7 @@ switch(file_format){ } if(verbose) printf("detected AVI audio format: %d\n",has_audio); if(has_audio==4){ - if(!avi_header.audio_codec) avi_header.audio_codec=get_auds_codec_name(); + 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); @@ -762,7 +762,7 @@ switch(file_format){ has_audio=0; } } - default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale; + default_fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; break; } case DEMUXER_TYPE_ASF: { @@ -791,7 +791,7 @@ switch(file_format){ if(audio_format) has_audio=audio_format; // override type else if(has_audio) - switch(((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag){ + switch(sh_audio->wf.wFormatTag){ case 0: has_audio=0;break; // disable/no audio case 6: @@ -818,7 +818,7 @@ switch(file_format){ } if(verbose) printf("detected ASF audio format: %d\n",has_audio); if(has_audio==4){ - if(!avi_header.audio_codec) avi_header.audio_codec=get_auds_codec_name(); + 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); @@ -859,15 +859,15 @@ fflush(stdout); //================== Init VIDEO (codec & libvo) ========================== if(has_video==2){ - if(avi_header.video.fccHandler==mmioFOURCC('d', 'v', 'x', '1')) has_video=3; - if(avi_header.video.fccHandler==mmioFOURCC('d', 'i', 'v', 'x')) has_video=3; - if(avi_header.bih.biCompression==mmioFOURCC('d', 'v', 'x', '1')) has_video=3; - if(avi_header.bih.biCompression==mmioFOURCC('d', 'i', 'v', 'x')) has_video=3; -// if(avi_header.bih.biCompression==mmioFOURCC('D', 'I', 'V', 'X')) has_video=3; // Gabucino + 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 } if(has_video==2){ - if(!avi_header.video_codec) avi_header.video_codec=get_vids_codec_name(); + 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]":"", @@ -905,23 +905,23 @@ switch(has_video){ // calculating video bitrate: avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8; - if(avi_header.audio.fccType) avi_header.bitrate-=avi_header.audio.dwLength; + if(sh_audio->audio.fccType) avi_header.bitrate-=sh_audio->audio.dwLength; if(verbose) printf("AVI video length=%d\n",avi_header.bitrate); - avi_header.bitrate=((float)avi_header.bitrate/(float)avi_header.video.dwLength) - *((float)avi_header.video.dwRate/(float)avi_header.video.dwScale); -// default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale; + avi_header.bitrate=((float)avi_header.bitrate/(float)sh_video->video.dwLength) + *((float)sh_video->video.dwRate/(float)sh_video->video.dwScale); +// default_fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; printf("VIDEO: [%.4s] %dx%d %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", - &avi_header.bih.biCompression, - avi_header.bih.biWidth, - avi_header.bih.biHeight, - avi_header.bih.biBitCount, + &sh_video->bih.biCompression, + sh_video->bih.biWidth, + sh_video->bih.biHeight, + sh_video->bih.biBitCount, default_fps, avi_header.bitrate*0.008f, avi_header.bitrate/1024.0f ); // display info: - movie_size_x=avi_header.o_bih.biWidth; - movie_size_y=abs(avi_header.o_bih.biHeight); + movie_size_x=sh_video->o_bih.biWidth; + movie_size_y=abs(sh_video->o_bih.biHeight); break; } #ifdef USE_DIRECTSHOW @@ -939,8 +939,8 @@ switch(has_video){ } //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"); - avi_header.our_out_buffer=NULL; - if(DS_VideoDecoder_Open(avi_header.video_codec,avi_header.vids_guid, &avi_header.bih, 0, &avi_header.our_out_buffer)){ + 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); 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"); @@ -963,23 +963,23 @@ switch(has_video){ // calculating video bitrate: avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8; - if(avi_header.audio.fccType) avi_header.bitrate-=avi_header.audio.dwLength; + if(sh_audio->audio.fccType) avi_header.bitrate-=sh_audio->audio.dwLength; if(verbose) printf("AVI video length=%d\n",avi_header.bitrate); - avi_header.bitrate=((float)avi_header.bitrate/(float)avi_header.video.dwLength) - *((float)avi_header.video.dwRate/(float)avi_header.video.dwScale); -// default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale; + avi_header.bitrate=((float)avi_header.bitrate/(float)sh_video->video.dwLength) + *((float)sh_video->video.dwRate/(float)sh_video->video.dwScale); +// default_fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; printf("VIDEO: [%.4s] %dx%d %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", - &avi_header.bih.biCompression, - avi_header.bih.biWidth, - avi_header.bih.biHeight, - avi_header.bih.biBitCount, + &sh_video->bih.biCompression, + sh_video->bih.biWidth, + sh_video->bih.biHeight, + sh_video->bih.biBitCount, default_fps, avi_header.bitrate*0.008f, avi_header.bitrate/1024.0f ); // display info: - movie_size_x=avi_header.bih.biWidth; - movie_size_y=abs(avi_header.bih.biHeight); + movie_size_x=sh_video->bih.biWidth; + movie_size_y=abs(sh_video->bih.biHeight); break; } #endif @@ -993,8 +993,8 @@ switch(has_video){ if(verbose) printf("OpenDivX video codec\n"); { DEC_PARAM dec_param; DEC_SET dec_set; - dec_param.x_dim = avi_header.bih.biWidth; - dec_param.y_dim = avi_header.bih.biHeight; + dec_param.x_dim = sh_video->bih.biWidth; + dec_param.y_dim = sh_video->bih.biHeight; dec_param.color_depth = 32; decore(0x123, DEC_OPT_INIT, &dec_param, NULL); dec_set.postproc_level = divx_quality; @@ -1004,24 +1004,24 @@ switch(has_video){ // calculating video bitrate: avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8; - if(avi_header.audio.fccType) avi_header.bitrate-=avi_header.audio.dwLength; + if(sh_audio->audio.fccType) avi_header.bitrate-=sh_audio->audio.dwLength; if(verbose) printf("AVI video length=%d\n",avi_header.bitrate); - avi_header.bitrate=((float)avi_header.bitrate/(float)avi_header.video.dwLength) - *((float)avi_header.video.dwRate/(float)avi_header.video |