[Mplayer-cvslog] CVS: main configure,1.44,1.45 dec_audio.c,1.10,1.11 demuxer.c,1.6,1.7 demuxer.h,1.2,1.3 dll_init.c,1.16,1.17 mplayer.c,1.108,1.109 stheader.h,1.7,1.8

GEREOFFY arpi_esp at users.sourceforge.net
Thu May 10 05:39:56 CEST 2001


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

Modified Files:
	configure dec_audio.c demuxer.c demuxer.h dll_init.c mplayer.c 
	stheader.h 
Log Message:
new audio playback and A-V sync code

Index: configure
===================================================================
RCS file: /cvsroot/mplayer/main/configure,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -r1.44 -r1.45
*** configure	2001/05/09 07:52:03	1.44
--- configure	2001/05/10 03:39:54	1.45
***************
*** 1059,1062 ****
--- 1059,1063 ----
  
  /* set up audio OUTBURST. Do not change this! */
+ #define MAX_OUTBURST 32768
  #ifdef USE_XMMP_AUDIO
  #define OUTBURST 4096

Index: dec_audio.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_audio.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** dec_audio.c	2001/05/08 21:49:00	1.10
--- dec_audio.c	2001/05/10 03:39:54	1.11
***************
*** 53,66 ****
  //sh_audio->pcm_bswap=0;
  
! sh_audio->a_buffer_size=16384;  // default size, maybe not enough for Win32/ACM
  sh_audio->a_buffer=NULL;
  
  if(driver==4){
    // Win32 ACM audio codec:
    if(init_acm_audio_codec(sh_audio)){
      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+OUTBURST)
!         sh_audio->a_buffer_size=sh_audio->audio_out_minsize+OUTBURST;
    } else {
      printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n");
--- 53,69 ----
  //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)){
+     sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
      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");
***************
*** 81,84 ****
--- 84,88 ----
      driver=0;
    } else {
+     sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
      sh_audio->channels=sh_audio->wf->nChannels;
      sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
***************
*** 112,115 ****
--- 116,120 ----
      // AVI PCM Audio:
      WAVEFORMATEX *h=sh_audio->wf;
+     sh_audio->i_bps=h->nAvgBytesPerSec;
      sh_audio->channels=h->nChannels;
      sh_audio->samplerate=h->nSamplesPerSec;
***************
*** 121,124 ****
--- 126,130 ----
      sh_audio->channels=2;
      sh_audio->samplerate=48000;
+     sh_audio->i_bps=2*2*48000;
  //    sh_audio->pcm_bswap=1;
      break;
***************
*** 139,144 ****
    sh_audio->ac3_frame = ac3_decode_frame();
    if(sh_audio->ac3_frame){
!     sh_audio->samplerate=((ac3_frame_t*)sh_audio->ac3_frame)->sampling_rate;
      sh_audio->channels=2;
    } else {
      driver=0; // bad frame -> disable audio
--- 145,154 ----
    sh_audio->ac3_frame = ac3_decode_frame();
    if(sh_audio->ac3_frame){
!     ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame;
!     sh_audio->samplerate=fr->sampling_rate;
      sh_audio->channels=2;
+     // 1 frame: 6*256 samples     1 sec: sh_audio->samplerate samples
+     //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256);
+     sh_audio->i_bps=fr->bit_rate*(1000/8);
    } else {
      driver=0; // bad frame -> disable audio
***************
*** 151,154 ****
--- 161,165 ----
    sh_audio->channels=sh_audio->wf->nChannels;
    sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
+   sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate;
    break;
  }
***************
*** 158,161 ****
--- 169,176 ----
    sh_audio->channels=sh_audio->wf->nChannels;
    sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
+   // decodes 65 byte -> 320 short
+   // 1 sec: sh_audio->channels*sh_audio->samplerate  samples
+   // 1 frame: 320 samples
+   sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320;  // 1:10
    break;
  }
***************
*** 173,176 ****
--- 188,192 ----
    sh_audio->channels=2; // hack
    sh_audio->samplerate=MP3_samplerate;
+   sh_audio->i_bps=MP3_bitrate*(1000/8);
    break;
  }
***************
*** 191,198 ****
    return driver;
  }
  
! // Audio decoding
  
! int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int maxlen){
      int len=-1;
      switch(sh_audio->codec->driver){
--- 207,217 ----
    return driver;
  }
+ 
+ // Audio decoding:
  
! // Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc)
! // buffer length is 'maxlen' bytes, it shouldn't be exceeded...
  
! int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){
      int len=-1;
      switch(sh_audio->codec->driver){
***************
*** 202,212 ****
          break;
        case 2: // AVI PCM
!       { len=demux_read_data(sh_audio->ds,buf,OUTBURST);
          break;
        }
        case 8: // DVD PCM
        { int j;
!         len=demux_read_data(sh_audio->ds,buf,OUTBURST);
            //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];
--- 221,232 ----
          break;
        case 2: // AVI PCM
!       { len=demux_read_data(sh_audio->ds,buf,minlen);
          break;
        }
        case 8: // DVD PCM
        { int j;
!         len=demux_read_data(sh_audio->ds,buf,minlen);
            //if(i&1){ printf("Warning! pcm_audio_size&1 !=0  (%d)\n",i);i&=~1; }
+           // swap endian:
            for(j=0;j<len;j+=2){
              char x=buf[j];
***************
*** 217,221 ****
        }
        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;
--- 237,241 ----
        }
        case 5:  // aLaw decoder
!       { int l=demux_read_data(sh_audio->ds,buf,minlen/2);
          unsigned short *d=(unsigned short *) buf;
          unsigned char *s=buf;
***************
*** 229,239 ****
        case 6:  // MS-GSM decoder
        { unsigned char buf[65]; // 65 bytes / frame
!             len=0;
!             while(len<OUTBURST){
!                 if(demux_read_data(sh_audio->ds,buf,65)!=65) break; // EOF
!                 XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short
! //  		XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short
!                 len+=2*320;
!             }
          break;
        }
--- 249,256 ----
        case 6:  // MS-GSM decoder
        { unsigned char buf[65]; // 65 bytes / frame
!         if(demux_read_data(sh_audio->ds,buf,65)!=65) break; // EOF
!         XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short
! //  	    XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short
!         len=2*320;
          break;
        }
***************
*** 250,256 ****
          break;
        case 4:
!       { len=acm_decode_audio(sh_audio,buf,maxlen);
          break;
!       }
  #ifdef USE_DIRECTSHOW
        case 7: // DirectShow
--- 267,274 ----
          break;
        case 4:
!         len=acm_decode_audio(sh_audio,buf,maxlen);
! //        len=acm_decode_audio(sh_audio,buf,minlen);
          break;
! 
  #ifdef USE_DIRECTSHOW
        case 7: // DirectShow
***************
*** 268,272 ****
          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;
--- 286,291 ----
          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)  %d\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size,ds_tell_pts(sh_audio->ds));
          if(size_in>=sh_audio->a_in_buffer_len){
            sh_audio->a_in_buffer_len=0;

Index: demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/demuxer.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** demuxer.c	2001/04/23 21:25:09	1.6
--- demuxer.c	2001/05/10 03:39:54	1.7
***************
*** 14,17 ****
--- 14,18 ----
    ds->buffer=NULL;
    ds->pts=0;
+   ds->pts_bytes=0;
    ds->eof=0;
    ds->pos=0;
***************
*** 121,125 ****
        ds->pos=p->pos;
        ds->dpos+=p->len; // !!!
!       ds->pts=p->pts;
        // free packet:
        ds->bytes-=p->len;
--- 122,130 ----
        ds->pos=p->pos;
        ds->dpos+=p->len; // !!!
!       if(p->pts){
!         ds->pts=p->pts;
!         ds->pts_bytes=0;
!       }
!       ds->pts_bytes+=p->len; // !!!
        // free packet:
        ds->bytes-=p->len;
***************
*** 164,167 ****
--- 169,190 ----
  return bytes;
  }
+ 
+ int demux_read_data_pack(demux_stream_t *ds,unsigned char* mem,int len){
+ int x;
+ int bytes=0;
+ while(len>0){
+   x=ds->buffer_size-ds->buffer_pos;
+   if(x==0){
+     if(!ds_fill_buffer(ds)) return bytes;
+   } else {
+     if(x>len) x=len;
+     if(mem) memcpy(mem+bytes,&ds->buffer[ds->buffer_pos],x);
+     bytes+=x;len-=x;ds->buffer_pos+=x;
+     return bytes; // stop at end of package! (for correct timestamping)
+   }
+ }
+ return bytes;
+ }
+ 
  
  void ds_free_packs(demux_stream_t *ds){

Index: demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/demuxer.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** demuxer.h	2001/04/26 20:43:12	1.2
--- demuxer.h	2001/05/10 03:39:54	1.3
***************
*** 30,33 ****
--- 30,34 ----
    unsigned char* buffer;   // current buffer
    float pts;               // current buffer's pts
+   int pts_bytes;           // number of bytes read after last pts stamp
    int eof;                 // end of demuxed stream? (true if all buffer empty)
    int pos;                 // position in the input stream (file)
***************
*** 107,111 ****
--- 108,117 ----
  }
  
+ inline static int ds_tell_pts(demux_stream_t *ds){
+   return (ds->pts_bytes-ds->buffer_size)+ds->buffer_pos;
+ }
+ 
  int demux_read_data(demux_stream_t *ds,unsigned char* mem,int len);
+ int demux_read_data_pack(demux_stream_t *ds,unsigned char* mem,int len);
  
  #if 1

Index: dll_init.c
===================================================================
RCS file: /cvsroot/mplayer/main/dll_init.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** dll_init.c	2001/05/06 21:58:44	1.16
--- dll_init.c	2001/05/10 03:39:54	1.17
***************
*** 61,69 ****
  
      acmStreamSize(sh_audio->srcstream, in_fmt->nBlockAlign, &srcsize, ACM_STREAMSIZEF_SOURCE);
!     if(srcsize<OUTBURST) srcsize=OUTBURST;
      sh_audio->audio_out_minsize=srcsize; // audio output min. size
      if(verbose) printf("Audio ACM output buffer min. size: %ld\n",srcsize);
  
!     acmStreamSize(sh_audio->srcstream, 2*srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION);
      sh_audio->audio_in_minsize=srcsize; // audio input min. size
      if(verbose) printf("Audio ACM input buffer min. size: %ld\n",srcsize);
--- 61,70 ----
  
      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);
  
!     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: %ld\n",srcsize);
***************
*** 107,115 ****
          hr=acmStreamConvert(sh_audio->srcstream,&ash,0);
          if(hr){
!           printf("ACM_Decoder: acmStreamConvert error %d\n",(int)hr);
            
  //					return -1;
          }
!         if(verbose>=3) printf("acm converted %d -> %d\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed);
          if(ash.cbSrcLengthUsed>=sh_audio->a_in_buffer_len){
            sh_audio->a_in_buffer_len=0;
--- 108,117 ----
          hr=acmStreamConvert(sh_audio->srcstream,&ash,0);
          if(hr){
!           if(verbose>=2) printf("ACM_Decoder: acmStreamConvert error %d\n",(int)hr);
            
  //					return -1;
          }
!         //if(verbose>=3)
!         printf("acm converted %d -> %d\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed);
          if(ash.cbSrcLengthUsed>=sh_audio->a_in_buffer_len){
            sh_audio->a_in_buffer_len=0;
***************
*** 139,144 ****
  
    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_DECOMPRESS);
    if(!sh_video->hic){
      printf("ICOpen failed! unknown codec / wrong parameters?\n");
--- 141,146 ----
  
    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_DECOMPRESS);
    if(!sh_video->hic){
      printf("ICOpen failed! unknown codec / wrong parameters?\n");
***************
*** 260,276 ****
      return 0;
    }
- 
- #if 0
- 
- //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(sh_video->hic,ICM_USER+i,NULL,NULL);
-     printf(" ret=%d\n",ret);
-   }
- }
- #endif
  
    sh_video->our_out_buffer = shmem_alloc(sh_video->o_bih.biSizeImage);
--- 262,265 ----

Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -C2 -r1.108 -r1.109
*** mplayer.c	2001/05/08 12:17:02	1.108
--- mplayer.c	2001/05/10 03:39:54	1.109
***************
*** 28,32 ****
  #include "config.h"
  
! #ifndef OUTBURST
  #error "============================================="
  #error "Please re-run ./configure and then try again!"
--- 28,32 ----
  #include "config.h"
  
! #ifndef MAX_OUTBURST
  #error "============================================="
  #error "Please re-run ./configure and then try again!"
***************
*** 255,259 ****
  }
  
- 
  //#include "dec_audio.c"
  
--- 255,258 ----
***************
*** 305,308 ****
--- 304,332 ----
  }
  #endif
+ 
+ //**************************************************************************//
+ 
+ int audio_delay_method=2;
+ int audio_buffer_size=-1;
+ 
+ int get_audio_delay(int audio_fd){
+   if(audio_delay_method==2){
+       // 
+       int r=0;
+       if(ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &r)!=-1)
+          return r;
+       audio_delay_method=1; // fallback if not supported
+   }
+   if(audio_delay_method==1){
+       // SNDCTL_DSP_GETOSPACE
+       audio_buf_info zz;
+       if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1)
+          return audio_buffer_size-zz.bytes;
+       audio_delay_method=0; // fallback if not supported
+   }
+   return audio_buffer_size;
+ }
+ 
+ 
  //**************************************************************************//
  
***************
*** 402,406 ****
  extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
  extern int vo_init(void);
! extern int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int maxlen);
  
  char* filename=NULL; //"MI2-Trailer.avi";
--- 426,430 ----
  extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
  extern int vo_init(void);
! extern int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen);
  
  char* filename=NULL; //"MI2-Trailer.avi";
***************
*** 425,429 ****
  int alsa=0;
  #endif
- int audio_buffer_size=-1;
  int audio_id=-1;
  int video_id=-1;
--- 449,452 ----
***************
*** 1032,1036 ****
      has_audio=0;
    } else {
!     printf("AUDIO: samplerate=%d  channels=%d  bps=%d\n",sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize);
    }
  }
--- 1055,1060 ----
      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);
    }
  }
***************
*** 1283,1287 ****
  {
  int audio_fd=-1;
! float buffer_delay=0;
  float frame_correction=0; // A-V timestamp kulonbseg atlagolas
  int frame_corr_num=0;   //
--- 1307,1314 ----
  {
  int audio_fd=-1;
! int outburst=OUTBURST;
! float audio_buffer_delay=0;
! 
! //float buffer_delay=0;
  float frame_correction=0; // A-V timestamp kulonbseg atlagolas
  int frame_corr_num=0;   //
***************
*** 1363,1384 ****
    if(audio_buffer_size==-1){
      // Measuring buffer size:
!     buffer_delay=pSound->QueryDelay(pSound, 0);
    } else {
      // -abs commandline option
!     buffer_delay=audio_buffer_size/(float)(sh_audio->o_bps);
    }
  #else
    int r;
    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\n",r);
  
! #if 0
! //  r = (64 << 16) + 1024;
!   r = (65536 << 16) + 512;
!     if(ioctl (audio_fd, SNDCTL_DSP_SETFRAGMENT, &r)==-1)
!       printf("audio_setup: your card doesn't support setting fragments\n",r);
! #endif
  
    if(audio_buffer_size==-1){
--- 1390,1425 ----
    if(audio_buffer_size==-1){
      // Measuring buffer size:
!     audio_buffer_delay=pSound->QueryDelay(pSound, 0);
    } else {
      // -abs commandline option
!     audio_buffer_delay=audio_buffer_size/(float)(sh_audio->o_bps);
    }
  #else
    int r;
+   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);
!       has_audio=0;
!   } else
!       printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r,sh_audio->samplerate);
  
!   if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){
!       printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
!       r=0;
!       if(ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &r)==-1){
!           printf("audio_setup: %d bytes/frag (config.h)\n",outburst);
!       } else {
!           outburst=r;
!           printf("audio_setup: %d bytes/frag (GETBLKSIZE)\n",outburst);
!       }
!   } else {
!       printf("audio_setup: frags: %3d/%d  (%d bytes/frag)  free: %6d\n",
!           zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes);
!       if(audio_buffer_size==-1) audio_buffer_size=zz.bytes;
!       outburst=zz.fragsize;
!   }
  
    if(audio_buffer_size==-1){
***************
*** 1392,1397 ****
        tv.tv_sec=0; tv.tv_usec = 0;
        if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
!       write(audio_fd,&sh_audio->a_buffer[sh_audio->a_buffer_len],OUTBURST);
!       audio_buffer_size+=OUTBURST;
      }
      if(audio_buffer_size==0){
--- 1433,1438 ----
        tv.tv_sec=0; tv.tv_usec = 0;
        if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
!       write(audio_fd,&sh_audio->a_buffer[sh_audio->a_buffer_len],outburst);
!       audio_buffer_size+=outburst;
      }
      if(audio_buffer_size==0){
***************
*** 1402,1409 ****
  #endif
    }
!   buffer_delay=audio_buffer_size/(float)(sh_audio->o_bps);
  #endif
!   a_frame=-(buffer_delay);
!   printf("Audio buffer size: %d bytes, delay: %5.3fs\n",audio_buffer_size,buffer_delay);
  //  RESET_AUDIO(audio_fd);
  }
--- 1443,1452 ----
  #endif
    }
!   audio_buffer_delay=audio_buffer_size/(float)(sh_audio->o_bps);
  #endif
!   printf("Audio buffer size: %d bytes, delay: %5.3fs\n",audio_buffer_size,audio_buffer_delay);
! 
! //  a_frame=-(audio_buffer_delay);
!   a_frame=0;
  //  RESET_AUDIO(audio_fd);
  }
***************
*** 1429,1433 ****
  
  if(file_format==DEMUXER_TYPE_AVI){
!   a_pts=d_audio->pts-(buffer_delay+audio_delay);
    audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime;
  //  audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)/default_fps;
--- 1472,1476 ----
  
  if(file_format==DEMUXER_TYPE_AVI){
!   a_pts=d_audio->pts;
    audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime;
  //  audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)/default_fps;
***************
*** 1435,1439 ****
      printf("AVI Initial frame delay: %5.3f\n",(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime);
      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);
    }
--- 1478,1482 ----
      printf("AVI Initial frame delay: %5.3f\n",(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime);
      printf("v: audio_delay=%5.3f  buffer_delay=%5.3f  a_pts=%5.3f  a_frame=%5.3f\n",
!              audio_delay,audio_buffer_delay,a_pts,a_frame);
      printf("START:  a_pts=%5.3f  v_pts=%5.3f  \n",d_audio->pts,d_video->pts);
    }
***************
*** 1453,1489 ****
  
  /*========================== PLAY AUDIO ============================*/
  
  while(has_audio){
  
    // Update buffer if needed
!   unsigned int t=GetTimer();
    current_module="decode_audio";   // Enter AUDIO decoder module
!   //sh_audio->codec->driver=has_audio; // FIXME!
!   while(sh_audio->a_buffer_len<OUTBURST && !d_audio->eof){
!     int ret=decode_audio(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len],sh_audio->a_buffer_size-sh_audio->a_buffer_len);
      if(ret>0) sh_audio->a_buffer_len+=ret; else break;
    }
    current_module=NULL;   // Leave AUDIO decoder module
    t=GetTimer()-t;audio_time_usage+=t*0.000001;
! 
  
    // Play sound from the buffer:
!   if(sh_audio->a_buffer_len>=OUTBURST){ // if not EOF
  #ifdef USE_XMMP_AUDIO
!     pSound->Write( pSound, sh_audio->a_buffer, OUTBURST );
  #else
  #ifdef SIMULATE_ALSA
!     fake_ALSA_write(audio_fd,sh_audio->a_buffer,OUTBURST); // for testing purposes
  #else
!     write(audio_fd,sh_audio->a_buffer,OUTBURST);
  #endif
  #endif
!     sh_audio->a_buffer_len-=OUTBURST;
!     memcpy(sh_audio->a_buffer,&sh_audio->a_buffer[OUTBURST],sh_audio->a_buffer_len);
  #ifndef USE_XMMP_AUDIO
  #ifndef SIMULATE_ALSA
      // check buffer
  #ifdef HAVE_AUDIO_SELECT
!     {  fd_set rfds;
         struct timeval tv;
         FD_ZERO(&rfds);
--- 1496,1562 ----
  
  /*========================== PLAY AUDIO ============================*/
+ if(!has_audio){
+   int playsize=512;
+   a_frame+=playsize/(float)(sh_audio->o_bps);
+   a_pts+=playsize/(float)(sh_audio->o_bps);
+   //time_frame+=playsize/(float)(sh_audio->o_bps);
  
+ } else
  while(has_audio){
+   unsigned int t;
+   int playsize=outburst;
+   audio_buf_info zz;
+   int use_select=1;
+   
+   if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)!=-1){
+       // calculate exact buffer space:
+       playsize=zz.fragments*zz.fragsize;
+       if(!playsize) break; // buffer is full, do not block here!!!
+       use_select=0;
+   }
+   
+   if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
+   //if(playsize>outburst) playsize=outburst;
  
    // Update buffer if needed
!   t=GetTimer();
    current_module="decode_audio";   // Enter AUDIO decoder module
!   while(sh_audio->a_buffer_len<playsize && !d_audio->eof){
!     int ret=decode_audio(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len],
!         playsize-sh_audio->a_buffer_len,sh_audio->a_buffer_size-sh_audio->a_buffer_len);
      if(ret>0) sh_audio->a_buffer_len+=ret; else break;
    }
    current_module=NULL;   // Leave AUDIO decoder module
    t=GetTimer()-t;audio_time_usage+=t*0.000001;
!   
!   if(playsize>sh_audio->a_buffer_len) playsize=sh_audio->a_buffer_len;
!   playsize/=outburst; playsize*=outburst; // rounding to fragment boundary
!   
! //  printf("play %d bytes of %d [max: %d]\n",playsize,sh_audio->a_buffer_len,sh_audio->a_buffer_size);
  
    // Play sound from the buffer:
!   if(playsize>0){ // if not EOF
  #ifdef USE_XMMP_AUDIO
!     pSound->Write( pSound, sh_audio->a_buffer, playsize );
  #else
  #ifdef SIMULATE_ALSA
!     fake_ALSA_write(audio_fd,sh_audio->a_buffer,playsize); // for testing purposes
  #else
!     playsize=write(audio_fd,sh_audio->a_buffer,playsize);
  #endif
  #endif
!     if(playsize>0){
!       sh_audio->a_buffer_len-=playsize;
!       memcpy(sh_audio->a_buffer,&sh_audio->a_buffer[playsize],sh_audio->a_buffer_len);
!       a_frame+=playsize/(float)(sh_audio->o_bps);
!       //a_pts+=playsize/(float)(sh_audio->o_bps);
! //      time_frame+=playsize/(float)(sh_audio->o_bps);
!     }
  #ifndef USE_XMMP_AUDIO
  #ifndef SIMULATE_ALSA
      // check buffer
  #ifdef HAVE_AUDIO_SELECT
!     if(use_select){  // do not use this code if SNDCTL_DSP_GETOSPACE works
!        fd_set rfds;
         struct timeval tv;
         FD_ZERO(&rfds);
***************
*** 1493,1497 ****
         if(select(audio_fd+1, NULL, &rfds, NULL, &tv)){
           a_frame+=OUTBURST/(float)(sh_audio->o_bps);
!          a_pts+=OUTBURST/(float)(sh_audio->o_bps);
  //         printf("Filling audio buffer...\n");
           continue;
--- 1566,1570 ----
         if(select(audio_fd+1, NULL, &rfds, NULL, &tv)){
           a_frame+=OUTBURST/(float)(sh_audio->o_bps);
! //         a_pts+=OUTBURST/(float)(sh_audio->o_bps);
  //         printf("Filling audio buffer...\n");
           continue;
***************
*** 1509,1519 ****
  
  /*========================== UPDATE TIMERS ============================*/
! 
!   a_frame+=OUTBURST/(float)(sh_audio->o_bps);
!   a_pts+=OUTBURST/(float)(sh_audio->o_bps);
! 
    if(alsa){
      // Use system timer for sync, not audio card/driver
-     time_frame+=OUTBURST/(float)(sh_audio->o_bps);
      time_frame-=GetRelativeTime();
      if(time_frame<-0.1 || time_frame>0.1){
--- 1582,1588 ----
  
  /*========================== UPDATE TIMERS ============================*/
! #if 0
    if(alsa){
      // Use system timer for sync, not audio card/driver
      time_frame-=GetRelativeTime();
      if(time_frame<-0.1 || time_frame>0.1){
***************
*** 1530,1539 ****
      }
    }
! 
  
  /*========================== PLAY VIDEO ============================*/
  
  if(1)
!   while(v_frame<a_frame || force_redraw){
    
      float frame_time=1;
--- 1599,1608 ----
      }
    }
! #endif
  
  /*========================== PLAY VIDEO ============================*/
  
  if(1)
!   while(1){
    
      float frame_time=1;
***************
*** 1542,1546 ****
      current_module="decode_video";
      
!     if(!force_redraw && v_frame+0.1<a_frame) drop_frame=1; else drop_frame=0;
      drop_frame_cnt+=drop_frame;
  
--- 1611,1615 ----
      current_module="decode_video";
      
! //    if(!force_redraw && v_frame+0.1<a_frame) drop_frame=1; else drop_frame=0;
      drop_frame_cnt+=drop_frame;
  
***************
*** 1715,1719 ****
--- 1784,1811 ----
      v_frame+=frame_time;
      v_pts+=frame_time;
+     time_frame+=frame_time;  // for nosound
  
+     // It's time to sleep...
+     time_frame-=GetRelativeTime(); // reset timer
+ 
+     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;
+     } else {
+           if(time_frame<-0.1 || time_frame>0.1) time_frame=0;
+     }
+     
+       if(verbose)printf("sleep: %5.3f  a:%6.3f  v:%6.3f  \n",stime,a_frame,v_frame);
+       
+       while(time_frame>0.005){
+           if(time_frame<=0.020)
+              usleep(0); // sleep 10ms
+           else
+              usleep(1000000*(time_frame-0.002));
+           time_frame-=GetRelativeTime();
+       }
+ 
      if(!drop_frame){
          current_module="flip_page";
***************
*** 1727,1730 ****
--- 1819,1823 ----
        --force_redraw;
        if(!force_redraw) osd_function=OSD_PLAY;
+       continue;
      }
  
***************
*** 1735,1741 ****
  /*================ A-V TIMESTAMP CORRECTION: =========================*/
    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);
        delay_corrected=1; // hack
      } else
--- 1828,1838 ----
  /*================ A-V TIMESTAMP CORRECTION: =========================*/
    if(has_audio){
+     // unplayed bytes in our and soundcard/dma buffer:
+     int delay_bytes=get_audio_delay(audio_fd)+sh_audio->a_buffer_len;
+     float delay=(float)delay_bytes/(float)sh_audio->o_bps;
+ 
      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;
        delay_corrected=1; // hack
      } else
***************
*** 1744,1749 ****
  #if 1
        if(!delay_corrected){
!         float x=d_audio->pts-d_video->pts-(buffer_delay+audio_delay);
!         float y=-(buffer_delay+audio_delay);
          printf("Initial PTS delay: %5.3f sec  (calculated: %5.3f)\n",x,y);
          audio_delay+=x;
--- 1841,1846 ----
  #if 1
        if(!delay_corrected){
!         float x=d_audio->pts-d_video->pts-(delay+audio_delay);
!         float y=-(delay+audio_delay);
          printf("Initial PTS delay: %5.3f sec  (calculated: %5.3f)\n",x,y);
          audio_delay+=x;
***************
*** 1752,1760 ****
          if(verbose)
          printf("v: audio_delay=%5.3f  buffer_delay=%5.3f  a.pts=%5.3f  v.pts=%5.3f\n",
!                audio_delay,buffer_delay,d_audio->pts,d_video->pts);
        }
  #endif
!       a_pts=d_audio->pts-(buffer_delay+audio_delay);
!       d_audio->pts=0;
      }
      if(d_video->pts) v_pts=d_video->pts;
--- 1849,1863 ----
          if(verbose)
          printf("v: audio_delay=%5.3f  buffer_delay=%5.3f  a.pts=%5.3f  v.pts=%5.3f\n",
!                audio_delay,delay,d_audio->pts,d_video->pts);
        }
  #endif
! //      a_pts=(ds_tell_pts(d_audio)+sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
! //      printf("a_pts+=%6.3f    \n",a_pts);
! //      a_pts=d_audio->pts-a_pts;
! 
!       a_pts=d_audio->pts;
!       a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
! 
!       //a_pts=d_audio->pts; d_audio->pts=0;
      }
      if(d_video->pts) v_pts=d_video->pts;
***************
*** 1762,1766 ****
        float x=(frame_correction/5.0f);
        if(delay_corrected){
!         printf("A:%6.1f  V:%6.1f  A-V:%7.3f",a_pts,v_pts,x);
          x*=0.5f;
          if(x<-max_pts_correction) x=-max_pts_correction; else
--- 1865,1870 ----
        float x=(frame_correction/5.0f);
        if(delay_corrected){
! //        printf("A:%6.1f  V:%6.1f  A-V:%7.3f",a_pts-audio_delay-delay,v_pts,x);
!         printf("A:%6.1f (%6.1f)  V:%6.1f  A-V:%7.3f",a_pts,a_pts-audio_delay-delay,v_pts,x);
          x*=0.5f;
          if(x<-max_pts_correction) x=-max_pts_correction; else
***************
*** 1780,1784 ****
        frame_corr_num=0; frame_correction=0;
      }
!     if(frame_corr_num>=0) frame_correction+=a_pts-v_pts;
    } else {
      // No audio:
--- 1884,1888 ----
        frame_corr_num=0; frame_correction=0;
      }
!     if(frame_corr_num>=0) frame_correction+=(a_pts-delay-audio_delay)-v_pts;
    } else {
      // No audio:
***************
*** 1826,1829 ****
--- 1930,1935 ----
    }
  
+ 
+     if(!force_redraw) break;
    } //  while(v_frame<a_frame || force_redraw)
  
***************
*** 1858,1866 ****
      // delay correction:
      case '+':
!       buffer_delay+=0.1;  // increase audio buffer delay
        a_frame-=0.1;
        break;
      case '-':
!       buffer_delay-=0.1;  // decrease audio buffer delay
        a_frame+=0.1;
        break;
--- 1964,1972 ----
      // delay correction:
      case '+':
!       audio_delay+=0.1;  // increase audio buffer delay
        a_frame-=0.1;
        break;
      case '-':
!       audio_delay-=0.1;  // decrease audio buffer delay
        a_frame+=0.1;
        break;
***************
*** 1987,1991 ****
        avi_video_pts=v_pts;
  #endif
!       a_pts=avi_video_pts-(buffer_delay);
        //a_pts=v_pts; //-(buffer_delay+audio_delay);
  
--- 2093,2097 ----
        avi_video_pts=v_pts;
  #endif
!       a_pts=avi_video_pts;
        //a_pts=v_pts; //-(buffer_delay+audio_delay);
  
***************
*** 2190,2194 ****
        frame_corr_num=-5; frame_correction=0;
        force_redraw=5;
!       a_frame=-buffer_delay-skip_audio_secs;
  //      a_frame=-audio_delay-buffer_delay-skip_audio_secs;
        v_frame=0; // !!!!!!
--- 2296,2300 ----
        frame_corr_num=-5; frame_correction=0;
        force_redraw=5;
!       a_frame=-skip_audio_secs;
  //      a_frame=-audio_delay-buffer_delay-skip_audio_secs;
        v_frame=0; // !!!!!!

Index: stheader.h
===================================================================
RCS file: /cvsroot/mplayer/main/stheader.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** stheader.h	2001/04/23 03:42:17	1.7
--- stheader.h	2001/05/10 03:39:54	1.8
***************
*** 16,20 ****
    int samplesize;
    int channels;
!   int o_bps; // == samplerate*samplesize*channels
    // in buffers:
    char* a_in_buffer;
--- 16,21 ----
    int samplesize;
    int channels;
!   int o_bps; // == samplerate*samplesize*channels   (uncompr. bytes/sec)
!   int i_bps; // == bitrate  (compressed bytes/sec)
    // in buffers:
    char* a_in_buffer;


_______________________________________________
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