changeset 432:5251b0c57e39

sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
author arpi_esp
date Sun, 15 Apr 2001 14:33:49 +0000
parents c106cb97db06
children 0969d4ef0a34
files asfheader.c aviheader.c dec_audio.c dll_init.c mplayer.c stheader.h
diffstat 6 files changed, 71 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/asfheader.c	Sun Apr 15 13:57:06 2001 +0000
+++ b/asfheader.c	Sun Apr 15 14:33:49 2001 +0000
@@ -129,8 +129,9 @@
       switch(*((unsigned int*)&streamh.type)){
       case 0xF8699E40: { // guid_audio_stream
         sh_audio_t* sh_audio=new_sh_audio(streamh.stream_no & 0x7F);
-        memcpy(&sh_audio->wf,buffer,streamh.type_size<64?streamh.type_size:64);
-        if(verbose>=1) print_wave_header((WAVEFORMATEX*)buffer);
+        sh_audio->wf=calloc((streamh.type_size<sizeof(WAVEFORMATEX))?sizeof(WAVEFORMATEX):streamh.type_size,1);
+        memcpy(sh_audio->wf,buffer,streamh.type_size);
+        if(verbose>=1) print_wave_header(sh_audio->wf);
 	if((*((unsigned int*)&streamh.concealment))==0xbfc3cd50){
           stream_read(demuxer->stream,(char*) buffer,streamh.stream_size);
           asf_scrambling_h=buffer[0];
@@ -146,10 +147,13 @@
         }
       case 0xBC19EFC0: { // guid_video_stream
         sh_video_t* sh_video=new_sh_video(streamh.stream_no & 0x7F);
-        memcpy(&sh_video->bih,&buffer[4+4+1+2],sizeof(BITMAPINFOHEADER));
+        int len=streamh.type_size-(4+4+1+2);
+//        sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize);
+        sh_video->bih=calloc((len<sizeof(BITMAPINFOHEADER))?sizeof(BITMAPINFOHEADER):len,1);
+        memcpy(sh_video->bih,&buffer[4+4+1+2],len);
         //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]);
+        if(verbose>=1) print_video_header(sh_video->bih);
         //asf_video_id=streamh.stream_no & 0x7F;
 	//if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F;
         break;
--- a/aviheader.c	Sun Apr 15 13:57:06 2001 +0000
+++ b/aviheader.c	Sun Apr 15 14:33:49 2001 +0000
@@ -56,18 +56,20 @@
       break; }
     case ckidSTREAMFORMAT: {      // read 'strf'
       if(last_fccType==streamtypeVIDEO){
-        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;
+        sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize);
+        if(verbose>=2) printf("found 'bih', %d bytes of %d\n",chunksize,sizeof(BITMAPINFOHEADER));
+        stream_read(demuxer->stream,(char*) sh_video->bih,chunksize);
+        chunksize=0;
+//        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){
-        int z=(chunksize<64)?chunksize:64;
+        sh_audio->wf=malloc(chunksize); memset(sh_audio->wf,0,chunksize);
         if(verbose>=2) printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX));
-        stream_read(demuxer->stream,(char*) &sh_audio->wf,z);
-        chunksize-=z;
-        if(verbose>=1) print_wave_header(&sh_audio->wf);
+        stream_read(demuxer->stream,(char*) sh_audio->wf,chunksize);
+        chunksize=0;
+        if(verbose>=1) print_wave_header(sh_audio->wf);
 //        if(demuxer->audio->id==-1) demuxer->audio->id=stream_id;
       }
       break;
--- a/dec_audio.c	Sun Apr 15 13:57:06 2001 +0000
+++ b/dec_audio.c	Sun Apr 15 14:33:49 2001 +0000
@@ -31,13 +31,13 @@
   // Win32 DShow audio codec:
 //  printf("DShow_audio: channs=%d  rate=%d\n",sh_audio->channels,sh_audio->samplerate);
 
-  if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,&sh_audio->wf)){
+  if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)){
     printf("ERROR: Could not load/initialize Win32/DirctShow AUDIO codec: %s\n",sh_audio->codec->dll);
     driver=0;
   } else {
-    sh_audio->channels=sh_audio->wf.nChannels;
-    sh_audio->samplerate=sh_audio->wf.nSamplesPerSec;
-    sh_audio->audio_in_minsize=2*sh_audio->wf.nBlockAlign;
+    sh_audio->channels=sh_audio->wf->nChannels;
+    sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
+    sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign;
     if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
     sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
     sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
@@ -64,7 +64,7 @@
 }
 case 2: {
     // AVI PCM Audio:
-    WAVEFORMATEX *h=&sh_audio->wf;
+    WAVEFORMATEX *h=sh_audio->wf;
     sh_audio->channels=h->nChannels;
     sh_audio->samplerate=h->nSamplesPerSec;
     sh_audio->samplesize=(h->wBitsPerSample+7)/8;
@@ -101,15 +101,15 @@
 case 5: {
   // aLaw audio codec:
   Gen_aLaw_2_Signed(); // init table
-  sh_audio->channels=sh_audio->wf.nChannels;
-  sh_audio->samplerate=sh_audio->wf.nSamplesPerSec;
+  sh_audio->channels=sh_audio->wf->nChannels;
+  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
   break;
 }
 case 6: {
   // MS-GSM audio codec:
   GSM_Init();
-  sh_audio->channels=sh_audio->wf.nChannels;
-  sh_audio->samplerate=sh_audio->wf.nSamplesPerSec;
+  sh_audio->channels=sh_audio->wf->nChannels;
+  sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
   break;
 }
 case 1: {
--- a/dll_init.c	Sun Apr 15 13:57:06 2001 +0000
+++ b/dll_init.c	Sun Apr 15 14:33:49 2001 +0000
@@ -3,7 +3,7 @@
 
 int init_acm_audio_codec(sh_audio_t *sh_audio){
     HRESULT ret;
-    WAVEFORMATEX *in_fmt=&sh_audio->wf;
+    WAVEFORMATEX *in_fmt=sh_audio->wf;
     unsigned long srcsize=0;
 
   if(verbose) printf("======= Win32 (ACM) AUDIO Codec init =======\n");
@@ -110,7 +110,7 @@
   sh_video->o_bih.biSize = sizeof(BITMAPINFOHEADER);
 
   win32_codec_name = sh_video->codec->dll;
-  sh_video->hic = ICOpen( 0x63646976, sh_video->bih.biCompression, ICMODE_FASTDECOMPRESS);
+  sh_video->hic = ICOpen( 0x63646976, sh_video->bih->biCompression, ICMODE_FASTDECOMPRESS);
 //  sh_video->hic = ICOpen( 0x63646976, sh_video->bih.biCompression, ICMODE_DECOMPRESS);
   if(!sh_video->hic){
     printf("ICOpen failed! unknown codec / wrong parameters?\n");
@@ -119,7 +119,7 @@
 
 //  sh_video->bih.biBitCount=32;
 
-  ret = ICDecompressGetFormat(sh_video->hic, &sh_video->bih, &sh_video->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;
@@ -185,7 +185,7 @@
   sh_video->o_bih.biSizeImage = sh_video->o_bih.biWidth * sh_video->o_bih.biHeight * (sh_video->o_bih.biBitCount/8);
 
   if(!(sh_video->codec->outflags[sh_video->outfmtidx]&CODECS_FLAG_FLIP)) {
-      sh_video->o_bih.biHeight=-sh_video->bih.biHeight; // flip image!
+      sh_video->o_bih.biHeight=-sh_video->bih->biHeight; // flip image!
   }
 
   // this looks suspicious :-)
@@ -196,13 +196,13 @@
 
   if(verbose) {
     printf("Starting decompression, format:\n");
-	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);
+	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);
     printf("Dest fmt:\n");
 	printf("  biSize %d\n", sh_video->o_bih.biSize);
 	printf("  biWidth %d\n", sh_video->o_bih.biWidth);
@@ -213,7 +213,7 @@
 	printf("  biSizeImage %d\n", sh_video->o_bih.biSizeImage);
   }
 
-  ret = ICDecompressQuery(sh_video->hic, &sh_video->bih, &sh_video->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;
@@ -221,7 +221,7 @@
   if(verbose) printf("ICDecompressQuery OK\n");
 
   
-  ret = ICDecompressBegin(sh_video->hic, &sh_video->bih, &sh_video->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;
--- a/mplayer.c	Sun Apr 15 13:57:06 2001 +0000
+++ b/mplayer.c	Sun Apr 15 14:33:49 2001 +0000
@@ -697,7 +697,7 @@
       sh_audio=NULL;
     } else {
       sh_audio=d_audio->sh;sh_audio->ds=d_audio;
-      sh_audio->format=sh_audio->wf.wFormatTag;
+      sh_audio->format=sh_audio->wf->wFormatTag;
     }
   }
   // calc. FPS:
@@ -709,10 +709,10 @@
   if(verbose) printf("AVI video length=%d\n",avi_header.bitrate);
   avi_header.bitrate=((float)avi_header.bitrate/(float)sh_video->video.dwLength)*sh_video->fps;
   printf("VIDEO:  [%.4s]  %dx%d  %dbpp  %4.2f fps  %5.1f kbps (%4.1f kbyte/s)\n",
-    &sh_video->bih.biCompression,
-    sh_video->bih.biWidth,
-    sh_video->bih.biHeight,
-    sh_video->bih.biBitCount,
+    &sh_video->bih->biCompression,
+    sh_video->bih->biWidth,
+    sh_video->bih->biHeight,
+    sh_video->bih->biBitCount,
     sh_video->fps,
     avi_header.bitrate*0.008f,
     avi_header.bitrate/1024.0f );
@@ -738,15 +738,15 @@
       sh_audio=NULL;
     } else {
       sh_audio=d_audio->sh;sh_audio->ds=d_audio;
-      sh_audio->format=sh_audio->wf.wFormatTag;
+      sh_audio->format=sh_audio->wf->wFormatTag;
     }
   }
   sh_video->fps=1000.0f; sh_video->frametime=0.001f; // 1ms
   printf("VIDEO:  [%.4s]  %dx%d  %dbpp\n",
-    &sh_video->bih.biCompression,
-    sh_video->bih.biWidth,
-    sh_video->bih.biHeight,
-    sh_video->bih.biBitCount);
+    &sh_video->bih->biCompression,
+    sh_video->bih->biWidth,
+    sh_video->bih->biHeight,
+    sh_video->bih->biBitCount);
   break;
  }
  case DEMUXER_TYPE_MPEG_ES: {
@@ -778,9 +778,9 @@
  case DEMUXER_TYPE_AVI:
  case DEMUXER_TYPE_ASF: {
   // display info:
-  sh_video->format=sh_video->bih.biCompression;
-  sh_video->disp_w=sh_video->bih.biWidth;
-  sh_video->disp_h=abs(sh_video->bih.biHeight);
+  sh_video->format=sh_video->bih->biCompression;
+  sh_video->disp_w=sh_video->bih->biWidth;
+  sh_video->disp_h=abs(sh_video->bih->biHeight);
   break;
  }
  case DEMUXER_TYPE_MPEG_ES:
@@ -868,7 +868,7 @@
 //================== Init VIDEO (codec & libvo) ==========================
 
 // Go through the codec.conf and find the best codec...
-sh_video->codec=find_codec(sh_video->format,(unsigned int*) &sh_video->bih.biCompression,NULL,0);
+sh_video->codec=find_codec(sh_video->format,(unsigned int*) &sh_video->bih->biCompression,NULL,0);
 if(!sh_video->codec){
     printf("Can't find codec for video format 0x%X !\n",sh_video->format);
     exit(1);
@@ -899,7 +899,7 @@
    exit(1);
 #else
    sh_video->our_out_buffer=NULL;
-   if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, &sh_video->bih, 0, &sh_video->our_out_buffer)){
+   if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, &sh_video->our_out_buffer)){
         printf("ERROR: Couldn't open required DirectShow codec: %s\n",sh_video->codec->dll);
         printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n");
         printf("package from:  ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip  !\n");
@@ -926,8 +926,8 @@
    if(verbose) printf("OpenDivX video codec\n");
    { DEC_PARAM dec_param;
      DEC_SET dec_set;
-	dec_param.x_dim = sh_video->bih.biWidth;
-	dec_param.y_dim = sh_video->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;
@@ -1349,13 +1349,14 @@
     if(in_size<0){ eof=1;break;}
     if(in_size>max_framesize) max_framesize=in_size;
     
-      sh_video->bih.biSizeImage = in_size;
+    if(in_size){
+      sh_video->bih->biSizeImage = in_size;
 //      ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL), 
       ret = ICDecompress(sh_video->hic, ICDECOMPRESS_NOTKEYFRAME, 
-                        &sh_video->bih,   start,
+                         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 **)&sh_video->our_out_buffer);
       t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
@@ -1448,7 +1449,7 @@
   if(has_audio){
     if(pts_from_bps && (file_format==DEMUXER_TYPE_AVI)){
 //      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);
+      a_pts=(float)ds_tell(d_audio)/sh_audio->wf->nAvgBytesPerSec-(buffer_delay);
       delay_corrected=1; // hack
     } else
     if(d_audio->pts){
@@ -1663,13 +1664,13 @@
         int len=0;
 
         // calc new audio position in audio stream: (using avg.bps value)
-        curr_audio_pos=(avi_video_pts) * sh_audio->wf.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/=sh_audio->wf.nBlockAlign;
-        curr_audio_pos*=sh_audio->wf.nBlockAlign;
+        curr_audio_pos/=sh_audio->wf->nBlockAlign;
+        curr_audio_pos*=sh_audio->wf->nBlockAlign;
         avi_header.audio_seekable=1;
 #endif
 
@@ -1705,14 +1706,14 @@
           if(!(sh_audio->codec->flags&CODECS_FLAG_SEEKABLE)){
 #if 0
 //             curr_audio_pos=apos; // selected audio codec can't seek in chunk
-             skip_audio_secs=(float)skip_audio_bytes/(float)sh_audio->wf.nAvgBytesPerSec;
+             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 % sh_audio->wf.nBlockAlign;
+             int d=skip_audio_bytes % sh_audio->wf->nBlockAlign;
              skip_audio_bytes-=d;
 //             curr_audio_pos-=d;
-             skip_audio_secs=(float)d/(float)sh_audio->wf.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
           }
--- a/stheader.h	Sun Apr 15 13:57:06 2001 +0000
+++ b/stheader.h	Sun Apr 15 14:33:49 2001 +0000
@@ -26,8 +26,8 @@
   int a_buffer_size;
   // win32 codec stuff:
   AVIStreamHeader audio;
-  WAVEFORMATEX wf;
-  char wf_ext[64];     // in format
+  WAVEFORMATEX *wf;
+//  char wf_ext[64];     // in format
   WAVEFORMATEX o_wf;   // out format
   HACMSTREAM srcstream;  // handle
   int audio_in_minsize;
@@ -52,7 +52,7 @@
   char *our_out_buffer;
   // win32 codec stuff:
   AVIStreamHeader video;
-  BITMAPINFOHEADER bih;   // in format
+  BITMAPINFOHEADER *bih;   // in format
   BITMAPINFOHEADER o_bih; // out format
   HIC hic;  // handle
 } sh_video_t;