[Mplayer-cvslog] CVS: main dec_audio.c,1.12,1.13 dll_init.c,1.18,1.19 mplayer.c,1.112,1.113 stheader.h,1.8,1.9

GEREOFFY arpi_esp at users.sourceforge.net
Fri May 11 03:22:37 CEST 2001


Update of /cvsroot/mplayer/main
In directory usw-pr-cvs1:/tmp/cvs-serv5470

Modified Files:
	dec_audio.c dll_init.c mplayer.c stheader.h 
Log Message:
better audio out buffering & sample_format added

Index: dec_audio.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_audio.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** dec_audio.c	2001/05/10 18:44:38	1.12
--- dec_audio.c	2001/05/11 01:22:35	1.13
***************
*** 3,6 ****
--- 3,8 ----
  #include <stdlib.h>
  
+ #include <sys/soundcard.h>
+ 
  #include "config.h"
  
***************
*** 47,62 ****
  
  extern int init_acm_audio_codec(sh_audio_t *sh_audio);
! extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len);
  
  sh_audio->samplesize=2;
  sh_audio->samplerate=0;
  //sh_audio->pcm_bswap=0;
  
! sh_audio->a_buffer_size=2*MAX_OUTBURST;  // default size, maybe not enough for Win32/ACM
  sh_audio->a_buffer=NULL;
  
  sh_audio->a_in_buffer_len=0;
  
! if(driver==4){
    // Win32 ACM audio codec:
    if(init_acm_audio_codec(sh_audio)){
--- 49,70 ----
  
  extern int init_acm_audio_codec(sh_audio_t *sh_audio);
! //extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len);
! extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int minlen,int maxlen);
  
  sh_audio->samplesize=2;
+ sh_audio->sample_format=AFMT_S16_LE;
  sh_audio->samplerate=0;
  //sh_audio->pcm_bswap=0;
  
! sh_audio->a_buffer_size=0;
  sh_audio->a_buffer=NULL;
  
  sh_audio->a_in_buffer_len=0;
+ 
+ // setup required min. in/out buffer size:
+ sh_audio->audio_out_minsize=8192;// default size, maybe not enough for Win32/ACM
  
! switch(driver){
! case 4:
    // Win32 ACM audio codec:
    if(init_acm_audio_codec(sh_audio)){
***************
*** 64,76 ****
      sh_audio->channels=sh_audio->o_wf.nChannels;
      sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec;
!     if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST)
!         sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST;
    } else {
      printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n");
      driver=0;
    }
! }
! 
! if(driver==7){
  #ifndef USE_DIRECTSHOW
    printf("Compiled without DirectShow support -> force nosound :(\n");
--- 72,85 ----
      sh_audio->channels=sh_audio->o_wf.nChannels;
      sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec;
! //    if(sh_audio->audio_out_minsize>16384) sh_audio->audio_out_minsize=16384;
! //    sh_audio->a_buffer_size=sh_audio->audio_out_minsize;
! //    if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST)
! //        sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST;
    } else {
      printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n");
      driver=0;
    }
!   break;
! case 7:
  #ifndef USE_DIRECTSHOW
    printf("Compiled without DirectShow support -> force nosound :(\n");
***************
*** 79,83 ****
    // 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)){
      printf("ERROR: Could not load/initialize Win32/DirctShow AUDIO codec: %s\n",sh_audio->codec->dll);
--- 88,91 ----
***************
*** 92,97 ****
--- 100,125 ----
      sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
      sh_audio->a_in_buffer_len=0;
+     sh_audio->audio_out_minsize=16384;
    }
  #endif
+   break;
+ case 2:
+ case 8:
+ case 5:
+   // PCM, aLaw
+   sh_audio->audio_out_minsize=2048;
+   break;
+ case 3:
+   // Dolby AC3 audio:
+   sh_audio->audio_out_minsize=4*256*6;
+   break;
+ case 6:
+   // MS-GSM audio codec:
+   sh_audio->audio_out_minsize=4*320;
+   break;
+ case 1:
+   // MPEG Audio:
+   sh_audio->audio_out_minsize=4608;
+   break;
  }
  
***************
*** 99,103 ****
--- 127,140 ----
  
  // allocate audio out buffer:
+ sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; // worst case calc.
+ 
+ printf("dec_audio: Allocating %d + %d = %d bytes for output buffer\n",
+     sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size);
+ 
  sh_audio->a_buffer=malloc(sh_audio->a_buffer_size);
+ if(!sh_audio->a_buffer){
+     printf("Cannot allocate audio out buffer\n");
+     return 0;
+ }
  memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size);
  sh_audio->a_buffer_len=0;
***************
*** 105,109 ****
  switch(driver){
  case 4: {
!     int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,sh_audio->a_buffer_size);
      if(ret<0){
          printf("ACM decoding error: %d\n",ret);
--- 142,146 ----
  switch(driver){
  case 4: {
!     int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size);
      if(ret<0){
          printf("ACM decoding error: %d\n",ret);
***************
*** 120,123 ****
--- 157,168 ----
      sh_audio->samplerate=h->nSamplesPerSec;
      sh_audio->samplesize=(h->wBitsPerSample+7)/8;
+     switch(sh_audio->format){ // hardware formats:
+     case 0x6:  sh_audio->sample_format=AFMT_A_LAW;break;
+     case 0x7:  sh_audio->sample_format=AFMT_MU_LAW;break;
+     case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break;
+     case 0x50: sh_audio->sample_format=AFMT_MPEG;break;
+ //    case 0x2000: sh_audio->sample_format=AFMT_AC3;
+     default: sh_audio->sample_format=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8;
+     }
      break;
  }
***************
*** 158,162 ****
  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;
--- 203,210 ----
  case 5: {
    // aLaw audio codec:
!   if(sh_audio->format==6)
!     Gen_aLaw_2_Signed(); // init table
!   else
!     Gen_uLaw_2_Signed(); // init table
    sh_audio->channels=sh_audio->wf->nChannels;
    sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
***************
*** 241,247 ****
          unsigned char *s=buf;
          len=2*l;
!         while(l>0){
!           --l;
!           d[l]=xa_alaw_2_sign[s[l]];
          }
          break;
--- 289,298 ----
          unsigned char *s=buf;
          len=2*l;
!         if(sh_audio->format==6){
!         // aLaw
!           while(l>0){ --l; d[l]=xa_alaw_2_sign[s[l]]; }
!         } else {
!         // uLaw
!           while(l>0){ --l; d[l]=xa_ulaw_2_sign[s[l]]; }
          }
          break;
***************
*** 267,272 ****
          break;
        case 4:
!         len=acm_decode_audio(sh_audio,buf,maxlen);
! //        len=acm_decode_audio(sh_audio,buf,minlen);
          break;
  
--- 318,326 ----
          break;
        case 4:
! //        len=sh_audio->audio_out_minsize; // optimal decoded fragment size
! //        if(len<minlen) len=minlen; else
! //        if(len>maxlen) len=maxlen;
! //        len=acm_decode_audio(sh_audio,buf,len);
!         len=acm_decode_audio(sh_audio,buf,minlen,maxlen);
          break;
  

Index: dll_init.c
===================================================================
RCS file: /cvsroot/mplayer/main/dll_init.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** dll_init.c	2001/05/10 18:44:38	1.18
--- dll_init.c	2001/05/11 01:22:35	1.19
***************
*** 61,66 ****
  
      acmStreamSize(sh_audio->srcstream, in_fmt->nBlockAlign, &srcsize, ACM_STREAMSIZEF_SOURCE);
      srcsize*=2;
!     if(srcsize<MAX_OUTBURST) srcsize=MAX_OUTBURST;
      sh_audio->audio_out_minsize=srcsize; // audio output min. size
      if(verbose) printf("Audio ACM output buffer min. size: %ld\n",srcsize);
--- 61,74 ----
  
      acmStreamSize(sh_audio->srcstream, in_fmt->nBlockAlign, &srcsize, ACM_STREAMSIZEF_SOURCE);
+     //if(verbose) printf("Audio ACM output buffer min. size: %ld (reported by codec)\n",srcsize);
      srcsize*=2;
!     //if(srcsize<MAX_OUTBURST) srcsize=MAX_OUTBURST;
!     if(!srcsize){
!         printf("Warning! ACM codec reports srcsize=0\n");
!         srcsize=16384;
!     }
!     // limit srcsize to 4-16kb
!     //while(srcsize && srcsize<4096) srcsize*=2;
!     //while(srcsize>16384) srcsize/=2;
      sh_audio->audio_out_minsize=srcsize; // audio output min. size
      if(verbose) printf("Audio ACM output buffer min. size: %ld\n",srcsize);
***************
*** 79,88 ****
  }
  
! int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len){
          ACMSTREAMHEADER ash;
          HRESULT hr;
          DWORD srcsize=0;
          acmStreamSize(sh_audio->srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION);
          if(verbose>=3)printf("acm says: srcsize=%ld  (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; // !!!!!!
--- 87,104 ----
  }
  
! int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int minlen,int maxlen){
          ACMSTREAMHEADER ash;
          HRESULT hr;
          DWORD srcsize=0;
+         DWORD len=minlen;
          acmStreamSize(sh_audio->srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION);
          if(verbose>=3)printf("acm says: srcsize=%ld  (buffsize=%d)  out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,len);
+ 
+         if(srcsize<sh_audio->wf->nBlockAlign){
+            srcsize=sh_audio->wf->nBlockAlign;
+            acmStreamSize(sh_audio->srcstream, srcsize, &len, ACM_STREAMSIZEF_SOURCE);
+            if(len>maxlen) len=maxlen;
+         }
+ 
  //        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; // !!!!!!

Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.112
retrieving revision 1.113
diff -C2 -r1.112 -r1.113
*** mplayer.c	2001/05/10 11:56:22	1.112
--- mplayer.c	2001/05/11 01:22:35	1.113
***************
*** 1034,1039 ****
      has_audio=0;
    } else {
!     printf("AUDIO: samplerate=%d  channels=%d  bps=%d  ratio: %d->%d\n",sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize,
!         sh_audio->i_bps,sh_audio->o_bps);
    }
  }
--- 1034,1039 ----
      has_audio=0;
    } else {
!     printf("AUDIO: srate=%d  chans=%d  bps=%d  sfmt=0x%X  ratio: %d->%d\n",sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize,
!         sh_audio->sample_format,sh_audio->i_bps,sh_audio->o_bps);
    }
  }
***************
*** 1370,1375 ****
    audio_buf_info zz;
  
!   r=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
    r=sh_audio->channels-1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
    r=sh_audio->samplerate; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1){
        printf("audio_setup: your card doesn't support %d Hz samplerate => nosound\n",r);
--- 1370,1380 ----
    audio_buf_info zz;
  
!   r=sh_audio->sample_format;
! //  (sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8;
!   ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
!   printf("audio_setup: sample format: 0x%X  (requested: 0x%X)\n",r,sh_audio->sample_format);
!   
    r=sh_audio->channels-1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
+   
    r=sh_audio->samplerate; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1){
        printf("audio_setup: your card doesn't support %d Hz samplerate => nosound\n",r);
***************
*** 1418,1421 ****
--- 1423,1432 ----
    printf("Audio buffer size: %d bytes, delay: %5.3fs\n",audio_buffer_size,audio_buffer_delay);
  
+   // fixup audio buffer size:
+   if(outburst<MAX_OUTBURST){
+     sh_audio->a_buffer_size=sh_audio->audio_out_minsize+outburst;
+     printf("Audio out buffer size reduced to %d bytes\n",sh_audio->a_buffer_size);
+   }
+ 
  //  a_frame=-(audio_buffer_delay);
    a_frame=0;
***************
*** 1762,1766 ****
      if(has_audio){
            int delay=get_audio_delay(audio_fd);
!           if(verbose)printf("delay=%d\n",delay);
            time_frame=v_frame;
            time_frame-=a_frame-(float)delay/(float)sh_audio->o_bps;
--- 1773,1777 ----
      if(has_audio){
            int delay=get_audio_delay(audio_fd);
!           if(verbose>1)printf("delay=%d\n",delay);
            time_frame=v_frame;
            time_frame-=a_frame-(float)delay/(float)sh_audio->o_bps;
***************
*** 1769,1773 ****
      }
      
!       if(verbose)printf("sleep: %5.3f  a:%6.3f  v:%6.3f  \n",stime,a_frame,v_frame);
        
        while(time_frame>0.005){
--- 1780,1784 ----
      }
      
!       if(verbose>1)printf("sleep: %5.3f  a:%6.3f  v:%6.3f  \n",time_frame,a_frame,v_frame);
        
        while(time_frame>0.005){

Index: stheader.h
===================================================================
RCS file: /cvsroot/mplayer/main/stheader.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** stheader.h	2001/05/10 03:39:54	1.8
--- stheader.h	2001/05/11 01:22:35	1.9
***************
*** 26,29 ****
--- 26,30 ----
    int a_buffer_len;
    int a_buffer_size;
+   int sample_format;
    // win32 codec stuff:
    AVIStreamHeader audio;


_______________________________________________
Mplayer-cvslog mailing list
Mplayer-cvslog at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-cvslog



More information about the MPlayer-cvslog mailing list