[Mplayer-cvslog] CVS: main mplayer.c,1.115,1.116

GEREOFFY arpi_esp at users.sourceforge.net
Sun May 13 05:00:59 CEST 2001


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

Modified Files:
	mplayer.c 
Log Message:
audio sync cleanup and -bps fixed

Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -C2 -r1.115 -r1.116
*** mplayer.c	2001/05/12 01:57:18	1.115
--- mplayer.c	2001/05/13 03:00:57	1.116
***************
*** 5,8 ****
--- 5,9 ----
  
  #define RESET_AUDIO(audio_fd) ioctl(audio_fd, SNDCTL_DSP_RESET, NULL)
+ //#define PAUSE_AUDIO(audio_fd) ioctl(audio_fd, SNDCTL_DSP_POST, NULL)
  //#define RESET_AUDIO(audio_fd)
  
***************
*** 241,246 ****
  
  static const int frameratecode2framerate[16] = {
!    0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001,
!   60*10000, 0,0,0,0,0,0,0
  };
  
--- 242,250 ----
  
  static const int frameratecode2framerate[16] = {
!   0,
!   // Official mpeg1/2 framerates:
!   24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 60*10000,
!   // libmpeg3's "Unofficial economy rates":
!   1*10000,5*10000,10*10000,12*10000,15*10000,0,0
  };
  
***************
*** 456,460 ****
  int video_id=-1;
  int dvdsub_id=-1;
! float default_max_pts_correction=0.01f;
  int delay_corrected=1;
  float force_fps=0;
--- 460,464 ----
  int video_id=-1;
  int dvdsub_id=-1;
! float default_max_pts_correction=-1;//0.01f;
  int delay_corrected=1;
  float force_fps=0;
***************
*** 974,978 ****
     // display info:
     sh_video->fps=frameratecode2framerate[picture->frame_rate_code]*0.0001f;
!    sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code];
     sh_video->disp_w=picture->display_picture_width;
     sh_video->disp_h=picture->display_picture_height;
--- 978,990 ----
     // display info:
     sh_video->fps=frameratecode2framerate[picture->frame_rate_code]*0.0001f;
!    if(!sh_video->fps){
!      if(!force_fps){
!        printf("FPS not specified (or invalid) in the header! Use the -fps option!\n");
!        exit(1);
!      }
!      sh_video->frametime=0;
!    } else {
!      sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code];
!    }
     sh_video->disp_w=picture->display_picture_width;
     sh_video->disp_h=picture->display_picture_height;
***************
*** 1323,1330 ****
  float v_frame=0;    // Video
  float time_frame=0; // Timer
- float a_pts=0;
- float v_pts=0;
  float c_total=0;
! float max_pts_correction=default_max_pts_correction;
  int eof=0;
  int force_redraw=0;
--- 1335,1340 ----
  float v_frame=0;    // Video
  float time_frame=0; // Timer
  float c_total=0;
! float max_pts_correction=0;//default_max_pts_correction;
  int eof=0;
  int force_redraw=0;
***************
*** 1494,1508 ****
  
  if(file_format==DEMUXER_TYPE_AVI && has_audio){
!   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;
    if(verbose){
!     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);
    }
    delay_corrected=0; // has to correct PTS diffs
    d_video->pts=0;d_audio->pts=0; // PTS is outdated now!
  }
  if(force_fps){
--- 1504,1523 ----
  
  if(file_format==DEMUXER_TYPE_AVI && has_audio){
!   //a_pts=d_audio->pts;
!   printf("Initial frame delay  A: %d  V: %d\n",sh_audio->audio.dwInitialFrames,sh_video->video.dwInitialFrames);
!   if(!pts_from_bps){
!     float x=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime;
!     audio_delay-=x;
!     printf("AVI Initial frame delay: %5.3f\n",x);
!   }
    if(verbose){
! //    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);
    }
    delay_corrected=0; // has to correct PTS diffs
    d_video->pts=0;d_audio->pts=0; // PTS is outdated now!
+ } else {
+   pts_from_bps=0; // it must be 0 for mpeg/asf !
  }
  if(force_fps){
***************
*** 1804,1821 ****
      }
      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>1)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>1)printf("sleep: %5.3f  a:%6.3f  v:%6.3f  \n",time_frame,a_frame,v_frame);
--- 1819,1842 ----
      }
      v_frame+=frame_time;
!     //v_pts+=frame_time;
      time_frame+=frame_time;  // for nosound
+ 
+     if(file_format==DEMUXER_TYPE_MPEG_PS) d_video->pts+=frame_time;
+ 
+     if(!drop_frame){
+ 
+       // It's time to sleep...
+       current_module="sleep";
  
!       time_frame-=GetRelativeTime(); // reset timer
  
!       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;
!       } else {
            if(time_frame<-0.1 || time_frame>0.1) time_frame=0;
!       }
      
        if(verbose>1)printf("sleep: %5.3f  a:%6.3f  v:%6.3f  \n",time_frame,a_frame,v_frame);
***************
*** 1829,1838 ****
        }
  
-     if(!drop_frame){
          current_module="flip_page";
          video_out->flip_page();
-         current_module=NULL;
  //        usleep(50000); // test only!
      }
      
      if(eof) break;
--- 1850,1860 ----
        }
  
          current_module="flip_page";
          video_out->flip_page();
  //        usleep(50000); // test only!
+ 
      }
+ 
+     current_module=NULL;
      
      if(eof) break;
***************
*** 1849,1870 ****
  /*================ 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
!     if(d_audio->pts){
! //      printf("\n=== APTS  a_pts=%5.3f  v_pts=%5.3f ===  \n",d_audio->pts,d_video->pts);
! #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;
-         //a_pts-=x;
          delay_corrected=1;
          if(verbose)
--- 1871,1891 ----
  /*================ A-V TIMESTAMP CORRECTION: =========================*/
    if(has_audio){
+     float a_pts=0;
+     float v_pts=0;
+ 
      // 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){
!       // PTS = (audio position)/(bytes per sec)
!       a_pts=(ds_tell(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
        delay_corrected=1; // hack
!     } else {
!       if(!delay_corrected && d_audio->pts){
          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;
          delay_corrected=1;
          if(verbose)
***************
*** 1872,1902 ****
                 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;
!     if(frame_corr_num==5){
!       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
          if(x> max_pts_correction) x= max_pts_correction;
!         max_pts_correction=default_max_pts_correction;
          a_frame+=x; c_total+=x;
!         printf("  ct:%7.3f  %3d  %2d%%  %2d%%  %3.1f%% %d \r",c_total,
          (int)num_frames,
          (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
          (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
          (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0
!         ,drop_frame_cnt
  //        dbg_es_sent-dbg_es_rcvd 
          );
--- 1893,1924 ----
                 audio_delay,delay,d_audio->pts,d_video->pts);
        }
!       // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
        a_pts=d_audio->pts;
        a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
      }
! 
!     v_pts=d_video->pts-frame_time;
! 
!     if(verbose)printf("### A:%8.3f (%8.3f)  V:%8.3f  A-V:%7.4f  \n",a_pts,a_pts-audio_delay-delay,v_pts,(a_pts-delay-audio_delay)-v_pts);
! 
!     if(frame_corr_num==1){
!       float x=frame_correction;
        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.1f;
          if(x<-max_pts_correction) x=-max_pts_correction; else
          if(x> max_pts_correction) x= max_pts_correction;
!         if(default_max_pts_correction>=0)
!           max_pts_correction=default_max_pts_correction;
!         else
!           max_pts_correction=sh_video->frametime*0.10; // +-10% of time
          a_frame+=x; c_total+=x;
!         printf("  ct:%7.3f  %3d  %2d%%  %2d%%  %3.1f%% \r",c_total,
          (int)num_frames,
          (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
          (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
          (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0
! //        ,drop_frame_cnt
  //        dbg_es_sent-dbg_es_rcvd 
          );
***************
*** 1905,1912 ****
        frame_corr_num=0; frame_correction=0;
      }
      if(frame_corr_num>=0) frame_correction+=(a_pts-delay-audio_delay)-v_pts;
    } else {
      // No audio:
!     if(d_video->pts) v_pts=d_video->pts;
      if(frame_corr_num==5){
  //      printf("A: ---   V:%6.1f   \r",v_pts);
--- 1927,1937 ----
        frame_corr_num=0; frame_correction=0;
      }
+     
      if(frame_corr_num>=0) frame_correction+=(a_pts-delay-audio_delay)-v_pts;
+     
    } else {
      // No audio:
!     //if(d_video->pts)
!     int v_pts=d_video->pts;
      if(frame_corr_num==5){
  //      printf("A: ---   V:%6.1f   \r",v_pts);
***************
*** 1933,1936 ****
--- 1958,1962 ----
    if(osd_function==OSD_PAUSE){
        printf("\n------ PAUSED -------\r");fflush(stdout);
+       RESET_AUDIO(audio_fd); // stop audio
  #ifdef HAVE_GUI
        if ( nogui )
***************
*** 2077,2081 ****
            if(avi_stream_id(id)==d_video->id){  // video frame
              if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
!             v_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
              ++skip_audio_bytes;
            }
--- 2103,2107 ----
            if(avi_stream_id(id)==d_video->id){  // video frame
              if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
!             //v_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
              ++skip_audio_bytes;
            }
***************
*** 2089,2093 ****
            if(avi_stream_id(id)==d_video->id){  // video frame
              if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
!             v_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
              --skip_audio_bytes;
            }
--- 2115,2119 ----
            if(avi_stream_id(id)==d_video->id){  // video frame
              if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
!             //v_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
              --skip_audio_bytes;
            }
***************
*** 2110,2118 ****
        }
        //printf("v-pts recalc! %5.3f -> %5.3f  \n",v_pts,avi_video_pts);
!       v_pts=avi_video_pts;
! #else
!       avi_video_pts=v_pts;
  #endif
!       a_pts=avi_video_pts;
        //a_pts=v_pts; //-(buffer_delay+audio_delay);
  
--- 2136,2144 ----
        }
        //printf("v-pts recalc! %5.3f -> %5.3f  \n",v_pts,avi_video_pts);
!       //v_pts=avi_video_pts;
! //#else
!       //avi_video_pts=v_pts;
  #endif
!       //a_pts=avi_video_pts;
        //a_pts=v_pts; //-(buffer_delay+audio_delay);
  
***************
*** 2228,2232 ****
          else
            newpos=demuxer->filepos+(picture->bitrate*1000/16)*rel_seek_secs;
- //       picture->bitrate=2324*75*8; // standard VCD bitrate (75 sectors / sec)
  
          if(newpos<seek_to_byte) newpos=seek_to_byte;
--- 2254,2257 ----
***************
*** 2240,2245 ****
            if(!i || !skip_video_packet(d_video)){ eof=1; break;} // EOF
          }
-         // re-sync audio:  (must read to get actual audio PTS)
-         // if(has_audio) ds_fill_buffer(d_audio);
    }
    break;
--- 2265,2268 ----
***************
*** 2255,2260 ****
            vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
          }
!         //printf("avi filepos = %d  \n",vo_osd_progbar_value);
!   //      printf("avi filepos = %d  (len=%d)  \n",demuxer->filepos,(demuxer->movi_end-demuxer->movi_start));
        }
  
--- 2278,2282 ----
            vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
          }
!         //printf("avi filepos = %d  (len=%d)\n",vo_osd_progbar_value,len);
        }
  
***************
*** 2330,2334 ****
  { int i;
    if(osd_level>=2){
!       int pts=v_pts;
        if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
        vo_osd_text=osd_text_buffer;
--- 2352,2356 ----
  { int i;
    if(osd_level>=2){
!       int pts=d_video->pts;
        if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
        vo_osd_text=osd_text_buffer;
***************
*** 2342,2348 ****
    // find sub
    if(subtitles){
        if(sub_fps==0) sub_fps=sh_video->fps;
        current_module="find_sub";
!       find_sub(subtitles,sub_uses_time?(100*(v_pts+sub_delay)):((v_pts+sub_delay)*sub_fps)); // FIXME! frame counter...
        current_module=NULL;
    }
--- 2364,2371 ----
    // find sub
    if(subtitles){
+       int pts=d_video->pts;
        if(sub_fps==0) sub_fps=sh_video->fps;
        current_module="find_sub";
!       find_sub(subtitles,sub_uses_time?(100*(pts+sub_delay)):((pts+sub_delay)*sub_fps)); // FIXME! frame counter...
        current_module=NULL;
    }


_______________________________________________
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