mirror of https://github.com/mpv-player/mpv
sh_audio/sh_video added, general codec cleanup
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@292 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
d81123c78b
commit
d9a5713e26
16
asfheader.c
16
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);
|
||||
|
|
20
aviheader.c
20
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;
|
||||
|
|
12
codecs.c
12
codecs.c
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
168
dll_init.c
168
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!!!!
|
||||
|
||||
|
|
351
mplayer.c
351
mplayer.c
|
@ -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.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+(divx_quality?0:64);
|
||||
movie_size_x=avi_header.bih.biWidth;
|
||||
movie_size_y=abs(avi_header.bih.biHeight);
|
||||
// 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: {
|
||||
|
@ -1185,7 +1185,6 @@ char* a_buffer=NULL;
|
|||
int a_buffer_len=0;
|
||||
int a_buffer_size=0;
|
||||
int audio_fd=-1;
|
||||
int pcm_bswap=0;
|
||||
float buffer_delay=0;
|
||||
float frame_correction=0; // A-V timestamp kulonbseg atlagolas
|
||||
int frame_corr_num=0; //
|
||||
|
@ -1198,7 +1197,6 @@ float c_total=0;
|
|||
float max_pts_correction=default_max_pts_correction;
|
||||
int eof=0;
|
||||
int force_redraw=0;
|
||||
ac3_frame_t *ac3_frame=NULL;
|
||||
float num_frames=0; // number of frames played
|
||||
//int real_num_frames=0; // number of frames readed
|
||||
double video_time_usage=0;
|
||||
|
@ -1239,19 +1237,19 @@ if(has_audio){
|
|||
if(verbose) printf("Initializing audio codec...\n");
|
||||
|
||||
MP3_bps=2;
|
||||
pcm_bswap=0;
|
||||
sh_audio->pcm_bswap=0;
|
||||
a_buffer_size=16384; // default size, maybe not enough for Win32/ACM
|
||||
|
||||
if(has_audio==4){
|
||||
// Win32 ACM audio codec:
|
||||
if(init_audio_codec()){
|
||||
MP3_channels=avi_header.wf.nChannels;
|
||||
MP3_samplerate=avi_header.wf.nSamplesPerSec;
|
||||
if(a_buffer_size<avi_header.audio_out_minsize+OUTBURST)
|
||||
a_buffer_size=avi_header.audio_out_minsize+OUTBURST;
|
||||
if(init_audio_codec(sh_audio)){
|
||||
MP3_channels=sh_audio->o_wf.nChannels;
|
||||
MP3_samplerate=sh_audio->o_wf.nSamplesPerSec;
|
||||
if(a_buffer_size<sh_audio->audio_out_minsize+OUTBURST)
|
||||
a_buffer_size=sh_audio->audio_out_minsize+OUTBURST;
|
||||
} else {
|
||||
printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n");
|
||||
if((((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag)==0x55){
|
||||
if((sh_audio->wf.wFormatTag)==0x55){
|
||||
printf("Audio format is MP3 -> fallback to internal mp3lib/mpg123\n");
|
||||
has_audio=1; // fallback to mp3lib
|
||||
} else
|
||||
|
@ -1265,24 +1263,24 @@ if(has_audio==7){
|
|||
has_audio=0;
|
||||
#else
|
||||
// Win32 DShow audio codec:
|
||||
WAVEFORMATEX *in_fmt=(WAVEFORMATEX*)&avi_header.wf_ext;
|
||||
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;
|
||||
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;
|
||||
|
||||
if(!DS_AudioDecoder_Open(avi_header.audio_codec,avi_header.auds_guid,in_fmt)){
|
||||
MP3_channels=avi_header.wf.nChannels;
|
||||
MP3_samplerate=avi_header.wf.nSamplesPerSec;
|
||||
MP3_channels=sh_audio->o_wf.nChannels;
|
||||
MP3_samplerate=sh_audio->o_wf.nSamplesPerSec;
|
||||
|
||||
avi_header.audio_in_minsize=2*avi_header.wf.nBlockAlign;
|
||||
if(avi_header.audio_in_minsize<8192) avi_header.audio_in_minsize=8192;
|
||||
a_in_buffer_size=avi_header.audio_in_minsize;
|
||||
a_in_buffer=malloc(a_in_buffer_size);
|
||||
a_in_buffer_len=0;
|
||||
sh_audio->audio_in_minsize=2*sh_audio->o_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);
|
||||
|
@ -1303,7 +1301,7 @@ memset(a_buffer,0,a_buffer_size);
|
|||
a_buffer_len=0;
|
||||
|
||||
if(has_audio==4){
|
||||
int ret=acm_decode_audio(a_buffer,a_buffer_size);
|
||||
int ret=acm_decode_audio(sh_audio,a_buffer,a_buffer_size);
|
||||
if(ret<0){
|
||||
printf("ACM error %d -> switching to nosound...\n",ret);
|
||||
has_audio=0;
|
||||
|
@ -1316,7 +1314,7 @@ if(has_audio==4){
|
|||
if(has_audio==2){
|
||||
if(file_format==DEMUXER_TYPE_AVI){
|
||||
// AVI PCM Audio:
|
||||
WAVEFORMATEX *h=(WAVEFORMATEX*)&avi_header.wf_ext;
|
||||
WAVEFORMATEX *h=&sh_audio->wf;
|
||||
MP3_channels=h->nChannels;
|
||||
MP3_samplerate=h->nSamplesPerSec;
|
||||
MP3_bps=(h->wBitsPerSample+7)/8;
|
||||
|
@ -1324,7 +1322,7 @@ if(has_audio==2){
|
|||
// DVD PCM audio:
|
||||
MP3_channels=2;
|
||||
MP3_samplerate=48000;
|
||||
pcm_bswap=1;
|
||||
sh_audio->pcm_bswap=1;
|
||||
}
|
||||
} else
|
||||
if(has_audio==3){
|
||||
|
@ -1339,23 +1337,23 @@ if(has_audio==3){
|
|||
ac3_config.flags |= AC3_3DNOW_ENABLE;
|
||||
#endif
|
||||
ac3_init();
|
||||
ac3_frame = ac3_decode_frame();
|
||||
if(ac3_frame){
|
||||
MP3_samplerate=ac3_frame->sampling_rate;
|
||||
sh_audio->ac3_frame = ac3_decode_frame();
|
||||
if(sh_audio->ac3_frame){
|
||||
MP3_samplerate=sh_audio->ac3_frame->sampling_rate;
|
||||
MP3_channels=2;
|
||||
} else has_audio=0; // bad frame -> disable audio
|
||||
} else
|
||||
if(has_audio==5){
|
||||
// aLaw audio codec:
|
||||
Gen_aLaw_2_Signed(); // init table
|
||||
MP3_channels=((WAVEFORMATEX*)&avi_header.wf_ext)->nChannels;
|
||||
MP3_samplerate=((WAVEFORMATEX*)&avi_header.wf_ext)->nSamplesPerSec;
|
||||
MP3_channels=sh_audio->wf.nChannels;
|
||||
MP3_samplerate=sh_audio->wf.nSamplesPerSec;
|
||||
} else
|
||||
if(has_audio==6){
|
||||
// MS-GSM audio codec:
|
||||
GSM_Init();
|
||||
MP3_channels=((WAVEFORMATEX*)&avi_header.wf_ext)->nChannels;
|
||||
MP3_samplerate=((WAVEFORMATEX*)&avi_header.wf_ext)->nSamplesPerSec;
|
||||
MP3_channels=sh_audio->wf.nChannels;
|
||||
MP3_samplerate=sh_audio->wf.nSamplesPerSec;
|
||||
}
|
||||
// must be here for Win32->mp3lib fallbacks
|
||||
if(has_audio==1){
|
||||
|
@ -1465,9 +1463,9 @@ if(has_audio){
|
|||
|
||||
if(file_format==DEMUXER_TYPE_AVI){
|
||||
a_pts=d_audio->pts-(buffer_delay+audio_delay);
|
||||
audio_delay-=(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps;
|
||||
// audio_delay-=(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps;
|
||||
printf("AVI Initial frame delay: %5.3f\n",(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps);
|
||||
audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)/default_fps;
|
||||
// audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)/default_fps;
|
||||
printf("AVI Initial frame delay: %5.3f\n",(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)/default_fps);
|
||||
printf("v: audio_delay=%5.3f buffer_delay=%5.3f a_pts=%5.3f a_frame=%5.3f\n",
|
||||
audio_delay,buffer_delay,a_pts,a_frame);
|
||||
printf("START: a_pts=%5.3f v_pts=%5.3f \n",d_audio->pts,d_video->pts);
|
||||
|
@ -1494,102 +1492,20 @@ while(!eof){
|
|||
/*========================== PLAY AUDIO ============================*/
|
||||
|
||||
while(has_audio){
|
||||
|
||||
// Update buffer if needed
|
||||
unsigned int t=GetTimer();
|
||||
current_module="decode_audio"; // Enter AUDIO decoder module
|
||||
// Update buffer if needed
|
||||
sh_audio->codec.driver=has_audio; // FIXME!
|
||||
while(a_buffer_len<OUTBURST && !d_audio->eof){
|
||||
switch(has_audio){
|
||||
case 1: // MPEG layer 2 or 3
|
||||
a_buffer_len+=MP3_DecodeFrame(&a_buffer[a_buffer_len],-1);
|
||||
MP3_channels=2; // hack
|
||||
break;
|
||||
case 2: // PCM
|
||||
{ int i=demux_read_data(d_audio,&a_buffer[a_buffer_len],OUTBURST);
|
||||
if(pcm_bswap){
|
||||
int j;
|
||||
if(i&3){ printf("Warning! pcm_audio_size&3 !=0 (%d)\n",i);i&=~3; }
|
||||
for(j=0;j<i;j+=2){
|
||||
char x=a_buffer[a_buffer_len+j];
|
||||
a_buffer[a_buffer_len+j]=a_buffer[a_buffer_len+j+1];
|
||||
a_buffer[a_buffer_len+j+1]=x;
|
||||
}
|
||||
}
|
||||
a_buffer_len+=i;
|
||||
break;
|
||||
}
|
||||
case 5: // aLaw decoder
|
||||
{ int l=demux_read_data(d_audio,&a_buffer[a_buffer_len],OUTBURST/2);
|
||||
unsigned short *d=(unsigned short *) &a_buffer[a_buffer_len];
|
||||
unsigned char *s=&a_buffer[a_buffer_len];
|
||||
a_buffer_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
|
||||
while(a_buffer_len<OUTBURST){
|
||||
if(demux_read_data(d_audio,buf,65)!=65) break; // EOF
|
||||
XA_MSGSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 65 byte -> 320 short
|
||||
// XA_GSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 33 byte -> 160 short
|
||||
a_buffer_len+=2*320;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: // AC3 decoder
|
||||
//printf("{1:%d}",avi_header.idx_pos);fflush(stdout);
|
||||
if(!ac3_frame) ac3_frame=ac3_decode_frame();
|
||||
//printf("{2:%d}",avi_header.idx_pos);fflush(stdout);
|
||||
if(ac3_frame){
|
||||
memcpy(&a_buffer[a_buffer_len],ac3_frame->audio_data,256 * 6 *MP3_channels*MP3_bps);
|
||||
a_buffer_len+=256 * 6 *MP3_channels*MP3_bps;
|
||||
ac3_frame=NULL;
|
||||
}
|
||||
//printf("{3:%d}",avi_header.idx_pos);fflush(stdout);
|
||||
break;
|
||||
case 4:
|
||||
{ int ret=acm_decode_audio(&a_buffer[a_buffer_len],a_buffer_size-a_buffer_len);
|
||||
if(ret>0) a_buffer_len+=ret;
|
||||
break;
|
||||
}
|
||||
#ifdef USE_DIRECTSHOW
|
||||
case 7: // DirectShow
|
||||
{ int ret;
|
||||
int len=a_buffer_size-a_buffer_len;
|
||||
int size_in=0;
|
||||
int size_out=0;
|
||||
int srcsize=DS_AudioDecoder_GetSrcSize(len);
|
||||
if(verbose>2)printf("DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,a_in_buffer_size,len);
|
||||
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);
|
||||
}
|
||||
DS_AudioDecoder_Convert(a_in_buffer,a_in_buffer_len,
|
||||
&a_buffer[a_buffer_len],len, &size_in,&size_out);
|
||||
if(verbose>2)printf("DShow: audio %d -> %d converted (in_buf_len=%d of %d)\n",size_in,size_out,a_in_buffer_len,a_in_buffer_size);
|
||||
if(size_in>=a_in_buffer_len){
|
||||
a_in_buffer_len=0;
|
||||
} else {
|
||||
a_in_buffer_len-=size_in;
|
||||
memcpy(a_in_buffer,&a_in_buffer[size_in],a_in_buffer_len);
|
||||
}
|
||||
a_buffer_len+=size_out;
|
||||
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
int ret=decode_audio(sh_audio,&a_buffer[a_buffer_len],a_buffer_size-a_buffer_len);
|
||||
if(ret>0) a_buffer_len+=ret; else break;
|
||||
}
|
||||
current_module=NULL; // Leave AUDIO decoder module
|
||||
t=GetTimer()-t;
|
||||
audio_time_usage+=t*0.000001;
|
||||
t=GetTimer()-t;audio_time_usage+=t*0.000001;
|
||||
|
||||
|
||||
// Play sound from the buffer:
|
||||
|
||||
if(a_buffer_len>=OUTBURST){ // if not EOF
|
||||
#ifdef USE_XMMP_AUDIO
|
||||
pSound->Write( pSound, a_buffer, OUTBURST );
|
||||
|
@ -1696,7 +1612,7 @@ switch(has_video){
|
|||
t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
|
||||
|
||||
++num_frames;
|
||||
v_frame+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
v_frame+=1.0f/default_fps; //(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1716,7 +1632,7 @@ switch(has_video){
|
|||
DS_VideoDecoder_DecodeFrame(start, in_size, 0, 1);
|
||||
|
||||
t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
|
||||
video_out->draw_frame((uint8_t **)&avi_header.our_out_buffer);
|
||||
video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer);
|
||||
// video_out->flip_page();
|
||||
t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
|
||||
|
||||
|
@ -1726,8 +1642,8 @@ switch(has_video){
|
|||
float d=pts2-pts1;
|
||||
if(d>0 && d<0.2) v_frame+=d;
|
||||
} else
|
||||
v_frame+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
//v_pts+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
v_frame+=1.0f/default_fps; //(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
//v_pts+=1.0f/default_fps; //(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1746,16 +1662,16 @@ switch(has_video){
|
|||
// printf("frame len = %5.4f\n",pts2-pts1);
|
||||
|
||||
//if(in_size>0){
|
||||
avi_header.bih.biSizeImage = in_size;
|
||||
ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME,
|
||||
sh_video->bih.biSizeImage = in_size;
|
||||
ret = ICDecompress(sh_video->hic, ICDECOMPRESS_NOTKEYFRAME,
|
||||
// ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL),
|
||||
&avi_header.bih, start,
|
||||
&avi_header.o_bih, avi_header.our_out_buffer);
|
||||
&sh_video->bih, start,
|
||||
&sh_video->o_bih, sh_video->our_out_buffer);
|
||||
if(ret){ printf("Error decompressing frame, err=%d\n",ret);break; }
|
||||
//}
|
||||
|
||||
t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
|
||||
video_out->draw_frame((uint8_t **)&avi_header.our_out_buffer);
|
||||
video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer);
|
||||
// video_out->flip_page();
|
||||
t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
|
||||
|
||||
|
@ -1765,8 +1681,8 @@ switch(has_video){
|
|||
float d=pts2-pts1;
|
||||
if(d>0 && d<0.2) v_frame+=d;
|
||||
} else
|
||||
v_frame+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
//v_pts+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
v_frame+=1.0f/default_fps; //(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
//v_pts+=1.0f/default_fps; //(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1944,8 +1860,8 @@ switch(has_video){
|
|||
/*================ A-V TIMESTAMP CORRECTION: =========================*/
|
||||
if(has_audio){
|
||||
if(pts_from_bps && (file_format==DEMUXER_TYPE_AVI)){
|
||||
// a_pts=(float)ds_tell(d_audio)/((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec-(buffer_delay+audio_delay);
|
||||
a_pts=(float)ds_tell(d_audio)/((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec-(buffer_delay);
|
||||
// a_pts=(float)ds_tell(d_audio)/sh_audio->wf.nAvgBytesPerSec-(buffer_delay+audio_delay);
|
||||
a_pts=(float)ds_tell(d_audio)/sh_audio->wf.nAvgBytesPerSec-(buffer_delay);
|
||||
delay_corrected=1; // hack
|
||||
} else
|
||||
if(d_audio->pts){
|
||||
|
@ -2125,7 +2041,7 @@ switch(file_format){
|
|||
// if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
|
||||
if(avi_stream_id(id)==d_video->id){ // video frame
|
||||
if((--rel_seek_frames)<0 && avi_header.idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
|
||||
v_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
v_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
++skip_audio_bytes;
|
||||
}
|
||||
++video_chunk_pos;
|
||||
|
@ -2137,7 +2053,7 @@ switch(file_format){
|
|||
// if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
|
||||
if(avi_stream_id(id)==d_video->id){ // video frame
|
||||
if((++rel_seek_frames)>0 && avi_header.idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
|
||||
v_pts-=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
v_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
--skip_audio_bytes;
|
||||
}
|
||||
--video_chunk_pos;
|
||||
|
@ -2154,7 +2070,7 @@ switch(file_format){
|
|||
int id=avi_header.idx[i].ckid;
|
||||
// if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
|
||||
if(avi_stream_id(id)==d_video->id){ // video frame
|
||||
avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
avi_video_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
}
|
||||
}
|
||||
//printf("v-pts recalc! %5.3f -> %5.3f \n",v_pts,avi_video_pts);
|
||||
|
@ -2172,13 +2088,13 @@ switch(file_format){
|
|||
int len=0;
|
||||
|
||||
// calc new audio position in audio stream: (using avg.bps value)
|
||||
curr_audio_pos=(avi_video_pts) * ((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
|
||||
curr_audio_pos=(avi_video_pts) * sh_audio->wf.nAvgBytesPerSec;
|
||||
if(curr_audio_pos<0)curr_audio_pos=0;
|
||||
#if 1
|
||||
curr_audio_pos&=~15; // requires for PCM formats!!!
|
||||
#else
|
||||
curr_audio_pos/=((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
|
||||
curr_audio_pos*=((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
|
||||
curr_audio_pos/=sh_audio->wf.nBlockAlign;
|
||||
curr_audio_pos*=sh_audio->wf.nBlockAlign;
|
||||
avi_header.audio_seekable=1;
|
||||
#endif
|
||||
|
||||
|
@ -2214,14 +2130,14 @@ switch(file_format){
|
|||
if(!avi_header.audio_seekable){
|
||||
#if 0
|
||||
// curr_audio_pos=apos; // selected audio codec can't seek in chunk
|
||||
skip_audio_secs=(float)skip_audio_bytes/(float)((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
|
||||
skip_audio_secs=(float)skip_audio_bytes/(float)sh_audio->wf.nAvgBytesPerSec;
|
||||
//printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",skip_audio_bytes,skip_audio_secs);
|
||||
skip_audio_bytes=0;
|
||||
#else
|
||||
int d=skip_audio_bytes % ((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
|
||||
int d=skip_audio_bytes % sh_audio->wf.nBlockAlign;
|
||||
skip_audio_bytes-=d;
|
||||
// curr_audio_pos-=d;
|
||||
skip_audio_secs=(float)d/(float)((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
|
||||
skip_audio_secs=(float)d/(float)sh_audio->wf.nAvgBytesPerSec;
|
||||
//printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",d,skip_audio_secs);
|
||||
#endif
|
||||
}
|
||||
|
@ -2238,7 +2154,7 @@ switch(file_format){
|
|||
if(avi_stream_id(id)==d_video->id){ // video frame
|
||||
++skip_video_frames;
|
||||
// requires for correct audio pts calculation (demuxer):
|
||||
avi_video_pts-=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
|
||||
avi_video_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
@ -2319,11 +2235,12 @@ switch(file_format){
|
|||
case 3:
|
||||
ac3_bitstream_reset(); // reset AC3 bitstream buffer
|
||||
// if(verbose){ printf("Resyncing AC3 audio...");fflush(stdout);}
|
||||
ac3_frame=ac3_decode_frame(); // resync
|
||||
sh_audio->ac3_frame=ac3_decode_frame(); // resync
|
||||
// if(verbose) printf(" OK!\n");
|
||||
break;
|
||||
case 4:
|
||||
a_in_buffer_len=0; // reset ACM audio buffer
|
||||
case 7:
|
||||
sh_audio->a_in_buffer_len=0; // reset ACM/DShow audio buffer
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2336,7 +2253,7 @@ switch(file_format){
|
|||
while(d_video->pts > d_audio->pts){
|
||||
switch(has_audio){
|
||||
case 1: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame
|
||||
case 3: ac3_frame=ac3_decode_frame();break; // skip AC3 frame
|
||||
case 3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame
|
||||
default: ds_fill_buffer(d_audio); // skip PCM frame
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
// Stream headers:
|
||||
|
||||
typedef struct {
|
||||
int driver;
|
||||
// codec descriptor from codec.conf
|
||||
} codecinfo_t;
|
||||
|
||||
typedef struct {
|
||||
demux_stream_t *ds;
|
||||
codecinfo_t codec;
|
||||
// output format:
|
||||
int samplerate;
|
||||
int samplesize;
|
||||
int channels;
|
||||
int o_bps; // == samplerate*samplesize*channels
|
||||
// buffers:
|
||||
char* a_in_buffer;
|
||||
int a_in_buffer_len;
|
||||
int a_in_buffer_size;
|
||||
// win32 codec stuff:
|
||||
AVIStreamHeader audio;
|
||||
WAVEFORMATEX wf;
|
||||
char wf_ext[64]; // in format
|
||||
WAVEFORMATEX o_wf; // out format
|
||||
HACMSTREAM srcstream; // handle
|
||||
int audio_in_minsize;
|
||||
int audio_out_minsize;
|
||||
// other codecs:
|
||||
ac3_frame_t *ac3_frame;
|
||||
int pcm_bswap;
|
||||
} sh_audio_t;
|
||||
|
||||
typedef struct {
|
||||
demux_stream_t *ds;
|
||||
codecinfo_t codec;
|
||||
// output format:
|
||||
float fps;
|
||||
float frametime; // 1/fps
|
||||
unsigned int outfmt;
|
||||
// unsigned int bitrate;
|
||||
// buffers:
|
||||
char *our_out_buffer;
|
||||
// win32 codec stuff:
|
||||
AVIStreamHeader video;
|
||||
BITMAPINFOHEADER bih; // in format
|
||||
BITMAPINFOHEADER o_bih; // out format
|
||||
HIC hic; // handle
|
||||
} sh_video_t;
|
||||
|
Loading…
Reference in New Issue