comparison mplayer.c @ 780:24e4e6e5aa1c

audio sync cleanup and -bps fixed
author arpi_esp
date Sun, 13 May 2001 03:00:57 +0000
parents 13c0dfde813b
children 14bac9d91e22
comparison
equal deleted inserted replaced
779:a349510321ff 780:24e4e6e5aa1c
2 2
3 // Enable ALSA emulation (using 32kB audio buffer) - timer testing only 3 // Enable ALSA emulation (using 32kB audio buffer) - timer testing only
4 //#define SIMULATE_ALSA 4 //#define SIMULATE_ALSA
5 5
6 #define RESET_AUDIO(audio_fd) ioctl(audio_fd, SNDCTL_DSP_RESET, NULL) 6 #define RESET_AUDIO(audio_fd) ioctl(audio_fd, SNDCTL_DSP_RESET, NULL)
7 //#define PAUSE_AUDIO(audio_fd) ioctl(audio_fd, SNDCTL_DSP_POST, NULL)
7 //#define RESET_AUDIO(audio_fd) 8 //#define RESET_AUDIO(audio_fd)
8 9
9 #include <stdio.h> 10 #include <stdio.h>
10 #include <stdlib.h> 11 #include <stdlib.h>
11 #include <string.h> 12 #include <string.h>
238 extern int num_elementary_packets101; 239 extern int num_elementary_packets101;
239 240
240 extern picture_t *picture; 241 extern picture_t *picture;
241 242
242 static const int frameratecode2framerate[16] = { 243 static const int frameratecode2framerate[16] = {
243 0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 244 0,
244 60*10000, 0,0,0,0,0,0,0 245 // Official mpeg1/2 framerates:
246 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 60*10000,
247 // libmpeg3's "Unofficial economy rates":
248 1*10000,5*10000,10*10000,12*10000,15*10000,0,0
245 }; 249 };
246 250
247 //**************************************************************************// 251 //**************************************************************************//
248 // Audio codecs: 252 // Audio codecs:
249 //**************************************************************************// 253 //**************************************************************************//
453 int alsa=0; 457 int alsa=0;
454 #endif 458 #endif
455 int audio_id=-1; 459 int audio_id=-1;
456 int video_id=-1; 460 int video_id=-1;
457 int dvdsub_id=-1; 461 int dvdsub_id=-1;
458 float default_max_pts_correction=0.01f; 462 float default_max_pts_correction=-1;//0.01f;
459 int delay_corrected=1; 463 int delay_corrected=1;
460 float force_fps=0; 464 float force_fps=0;
461 float audio_delay=0; 465 float audio_delay=0;
462 int vcd_track=0; 466 int vcd_track=0;
463 #ifdef VCD_CACHE 467 #ifdef VCD_CACHE
971 exit(1); 975 exit(1);
972 } 976 }
973 } 977 }
974 // display info: 978 // display info:
975 sh_video->fps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; 979 sh_video->fps=frameratecode2framerate[picture->frame_rate_code]*0.0001f;
976 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code]; 980 if(!sh_video->fps){
981 if(!force_fps){
982 printf("FPS not specified (or invalid) in the header! Use the -fps option!\n");
983 exit(1);
984 }
985 sh_video->frametime=0;
986 } else {
987 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code];
988 }
977 sh_video->disp_w=picture->display_picture_width; 989 sh_video->disp_w=picture->display_picture_width;
978 sh_video->disp_h=picture->display_picture_height; 990 sh_video->disp_h=picture->display_picture_height;
979 // info: 991 // info:
980 if(verbose) printf("mpeg bitrate: %d (%X)\n",picture->bitrate,picture->bitrate); 992 if(verbose) printf("mpeg bitrate: %d (%X)\n",picture->bitrate,picture->bitrate);
981 printf("VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", 993 printf("VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n",
1320 float frame_correction=0; // A-V timestamp kulonbseg atlagolas 1332 float frame_correction=0; // A-V timestamp kulonbseg atlagolas
1321 int frame_corr_num=0; // 1333 int frame_corr_num=0; //
1322 float a_frame=0; // Audio 1334 float a_frame=0; // Audio
1323 float v_frame=0; // Video 1335 float v_frame=0; // Video
1324 float time_frame=0; // Timer 1336 float time_frame=0; // Timer
1325 float a_pts=0;
1326 float v_pts=0;
1327 float c_total=0; 1337 float c_total=0;
1328 float max_pts_correction=default_max_pts_correction; 1338 float max_pts_correction=0;//default_max_pts_correction;
1329 int eof=0; 1339 int eof=0;
1330 int force_redraw=0; 1340 int force_redraw=0;
1331 float num_frames=0; // number of frames played 1341 float num_frames=0; // number of frames played
1332 double video_time_usage=0; 1342 double video_time_usage=0;
1333 double vout_time_usage=0; 1343 double vout_time_usage=0;
1491 current_module=NULL; 1501 current_module=NULL;
1492 1502
1493 //==================== START PLAYING ======================= 1503 //==================== START PLAYING =======================
1494 1504
1495 if(file_format==DEMUXER_TYPE_AVI && has_audio){ 1505 if(file_format==DEMUXER_TYPE_AVI && has_audio){
1496 a_pts=d_audio->pts; 1506 //a_pts=d_audio->pts;
1497 audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime; 1507 printf("Initial frame delay A: %d V: %d\n",sh_audio->audio.dwInitialFrames,sh_video->video.dwInitialFrames);
1498 // audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)/default_fps; 1508 if(!pts_from_bps){
1509 float x=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime;
1510 audio_delay-=x;
1511 printf("AVI Initial frame delay: %5.3f\n",x);
1512 }
1499 if(verbose){ 1513 if(verbose){
1500 printf("AVI Initial frame delay: %5.3f\n",(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime); 1514 // printf("v: audio_delay=%5.3f buffer_delay=%5.3f a_pts=%5.3f a_frame=%5.3f\n",
1501 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a_pts=%5.3f a_frame=%5.3f\n", 1515 // audio_delay,audio_buffer_delay,a_pts,a_frame);
1502 audio_delay,audio_buffer_delay,a_pts,a_frame);
1503 printf("START: a_pts=%5.3f v_pts=%5.3f \n",d_audio->pts,d_video->pts); 1516 printf("START: a_pts=%5.3f v_pts=%5.3f \n",d_audio->pts,d_video->pts);
1504 } 1517 }
1505 delay_corrected=0; // has to correct PTS diffs 1518 delay_corrected=0; // has to correct PTS diffs
1506 d_video->pts=0;d_audio->pts=0; // PTS is outdated now! 1519 d_video->pts=0;d_audio->pts=0; // PTS is outdated now!
1520 } else {
1521 pts_from_bps=0; // it must be 0 for mpeg/asf !
1507 } 1522 }
1508 if(force_fps){ 1523 if(force_fps){
1509 sh_video->fps=force_fps; 1524 sh_video->fps=force_fps;
1510 sh_video->frametime=1.0f/sh_video->fps; 1525 sh_video->frametime=1.0f/sh_video->fps;
1511 } 1526 }
1801 sh_video->frametime=d; // 1ms 1816 sh_video->frametime=d; // 1ms
1802 sh_video->fps=1.0f/d; 1817 sh_video->fps=1.0f/d;
1803 } 1818 }
1804 } 1819 }
1805 v_frame+=frame_time; 1820 v_frame+=frame_time;
1806 v_pts+=frame_time; 1821 //v_pts+=frame_time;
1807 time_frame+=frame_time; // for nosound 1822 time_frame+=frame_time; // for nosound
1808 1823
1809 // It's time to sleep... 1824 if(file_format==DEMUXER_TYPE_MPEG_PS) d_video->pts+=frame_time;
1810 time_frame-=GetRelativeTime(); // reset timer 1825
1811 1826 if(!drop_frame){
1812 if(has_audio){ 1827
1828 // It's time to sleep...
1829 current_module="sleep";
1830
1831 time_frame-=GetRelativeTime(); // reset timer
1832
1833 if(has_audio){
1813 int delay=get_audio_delay(audio_fd); 1834 int delay=get_audio_delay(audio_fd);
1814 if(verbose>1)printf("delay=%d\n",delay); 1835 if(verbose>1)printf("delay=%d\n",delay);
1815 time_frame=v_frame; 1836 time_frame=v_frame;
1816 time_frame-=a_frame-(float)delay/(float)sh_audio->o_bps; 1837 time_frame-=a_frame-(float)delay/(float)sh_audio->o_bps;
1817 } else { 1838 } else {
1818 if(time_frame<-0.1 || time_frame>0.1) time_frame=0; 1839 if(time_frame<-0.1 || time_frame>0.1) time_frame=0;
1819 } 1840 }
1820 1841
1821 if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,a_frame,v_frame); 1842 if(verbose>1)printf("sleep: %5.3f a:%6.3f v:%6.3f \n",time_frame,a_frame,v_frame);
1822 1843
1823 while(time_frame>0.005){ 1844 while(time_frame>0.005){
1824 if(time_frame<=0.020) 1845 if(time_frame<=0.020)
1826 else 1847 else
1827 usleep(1000000*(time_frame-0.002)); 1848 usleep(1000000*(time_frame-0.002));
1828 time_frame-=GetRelativeTime(); 1849 time_frame-=GetRelativeTime();
1829 } 1850 }
1830 1851
1831 if(!drop_frame){
1832 current_module="flip_page"; 1852 current_module="flip_page";
1833 video_out->flip_page(); 1853 video_out->flip_page();
1834 current_module=NULL;
1835 // usleep(50000); // test only! 1854 // usleep(50000); // test only!
1836 } 1855
1856 }
1857
1858 current_module=NULL;
1837 1859
1838 if(eof) break; 1860 if(eof) break;
1839 if(force_redraw){ 1861 if(force_redraw){
1840 --force_redraw; 1862 --force_redraw;
1841 if(!force_redraw) osd_function=OSD_PLAY; 1863 if(!force_redraw) osd_function=OSD_PLAY;
1846 // fflush(stdout); 1868 // fflush(stdout);
1847 1869
1848 #if 1 1870 #if 1
1849 /*================ A-V TIMESTAMP CORRECTION: =========================*/ 1871 /*================ A-V TIMESTAMP CORRECTION: =========================*/
1850 if(has_audio){ 1872 if(has_audio){
1873 float a_pts=0;
1874 float v_pts=0;
1875
1851 // unplayed bytes in our and soundcard/dma buffer: 1876 // unplayed bytes in our and soundcard/dma buffer:
1852 int delay_bytes=get_audio_delay(audio_fd)+sh_audio->a_buffer_len; 1877 int delay_bytes=get_audio_delay(audio_fd)+sh_audio->a_buffer_len;
1853 float delay=(float)delay_bytes/(float)sh_audio->o_bps; 1878 float delay=(float)delay_bytes/(float)sh_audio->o_bps;
1854 1879
1855 if(pts_from_bps && (file_format==DEMUXER_TYPE_AVI)){ 1880 if(pts_from_bps){
1856 // a_pts=(float)ds_tell(d_audio)/sh_audio->wf.nAvgBytesPerSec-(buffer_delay+audio_delay); 1881 // PTS = (audio position)/(bytes per sec)
1857 a_pts=(float)ds_tell(d_audio)/sh_audio->wf->nAvgBytesPerSec; 1882 a_pts=(ds_tell(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
1858 delay_corrected=1; // hack 1883 delay_corrected=1; // hack
1859 } else 1884 } else {
1860 if(d_audio->pts){ 1885 if(!delay_corrected && d_audio->pts){
1861 // printf("\n=== APTS a_pts=%5.3f v_pts=%5.3f === \n",d_audio->pts,d_video->pts);
1862 #if 1
1863 if(!delay_corrected){
1864 float x=d_audio->pts-d_video->pts-(delay+audio_delay); 1886 float x=d_audio->pts-d_video->pts-(delay+audio_delay);
1865 float y=-(delay+audio_delay); 1887 float y=-(delay+audio_delay);
1866 printf("Initial PTS delay: %5.3f sec (calculated: %5.3f)\n",x,y); 1888 printf("Initial PTS delay: %5.3f sec (calculated: %5.3f)\n",x,y);
1867 audio_delay+=x; 1889 audio_delay+=x;
1868 //a_pts-=x;
1869 delay_corrected=1; 1890 delay_corrected=1;
1870 if(verbose) 1891 if(verbose)
1871 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a.pts=%5.3f v.pts=%5.3f\n", 1892 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a.pts=%5.3f v.pts=%5.3f\n",
1872 audio_delay,delay,d_audio->pts,d_video->pts); 1893 audio_delay,delay,d_audio->pts,d_video->pts);
1873 } 1894 }
1874 #endif 1895 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
1875 // a_pts=(ds_tell_pts(d_audio)+sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
1876 // printf("a_pts+=%6.3f \n",a_pts);
1877 // a_pts=d_audio->pts-a_pts;
1878
1879 a_pts=d_audio->pts; 1896 a_pts=d_audio->pts;
1880 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; 1897 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
1881 1898 }
1882 //a_pts=d_audio->pts; d_audio->pts=0; 1899
1883 } 1900 v_pts=d_video->pts-frame_time;
1884 if(d_video->pts) v_pts=d_video->pts; 1901
1885 if(frame_corr_num==5){ 1902 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);
1886 float x=(frame_correction/5.0f); 1903
1904 if(frame_corr_num==1){
1905 float x=frame_correction;
1887 if(delay_corrected){ 1906 if(delay_corrected){
1888 // printf("A:%6.1f V:%6.1f A-V:%7.3f",a_pts-audio_delay-delay,v_pts,x); 1907 // printf("A:%6.1f V:%6.1f A-V:%7.3f",a_pts-audio_delay-delay,v_pts,x);
1889 printf("A:%6.1f (%6.1f) V:%6.1f A-V:%7.3f",a_pts,a_pts-audio_delay-delay,v_pts,x); 1908 printf("A:%6.1f (%6.1f) V:%6.1f A-V:%7.3f",a_pts,a_pts-audio_delay-delay,v_pts,x);
1890 x*=0.5f; 1909 x*=0.1f;
1891 if(x<-max_pts_correction) x=-max_pts_correction; else 1910 if(x<-max_pts_correction) x=-max_pts_correction; else
1892 if(x> max_pts_correction) x= max_pts_correction; 1911 if(x> max_pts_correction) x= max_pts_correction;
1893 max_pts_correction=default_max_pts_correction; 1912 if(default_max_pts_correction>=0)
1913 max_pts_correction=default_max_pts_correction;
1914 else
1915 max_pts_correction=sh_video->frametime*0.10; // +-10% of time
1894 a_frame+=x; c_total+=x; 1916 a_frame+=x; c_total+=x;
1895 printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% %d \r",c_total, 1917 printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% \r",c_total,
1896 (int)num_frames, 1918 (int)num_frames,
1897 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, 1919 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
1898 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, 1920 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
1899 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0 1921 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0
1900 ,drop_frame_cnt 1922 // ,drop_frame_cnt
1901 // dbg_es_sent-dbg_es_rcvd 1923 // dbg_es_sent-dbg_es_rcvd
1902 ); 1924 );
1903 fflush(stdout); 1925 fflush(stdout);
1904 } 1926 }
1905 frame_corr_num=0; frame_correction=0; 1927 frame_corr_num=0; frame_correction=0;
1906 } 1928 }
1929
1907 if(frame_corr_num>=0) frame_correction+=(a_pts-delay-audio_delay)-v_pts; 1930 if(frame_corr_num>=0) frame_correction+=(a_pts-delay-audio_delay)-v_pts;
1931
1908 } else { 1932 } else {
1909 // No audio: 1933 // No audio:
1910 if(d_video->pts) v_pts=d_video->pts; 1934 //if(d_video->pts)
1935 int v_pts=d_video->pts;
1911 if(frame_corr_num==5){ 1936 if(frame_corr_num==5){
1912 // printf("A: --- V:%6.1f \r",v_pts); 1937 // printf("A: --- V:%6.1f \r",v_pts);
1913 printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% \r",v_pts, 1938 printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% \r",v_pts,
1914 (int)num_frames, 1939 (int)num_frames,
1915 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, 1940 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
1930 if(!osd_visible) vo_osd_progbar_type=-1; // disable 1955 if(!osd_visible) vo_osd_progbar_type=-1; // disable
1931 } 1956 }
1932 1957
1933 if(osd_function==OSD_PAUSE){ 1958 if(osd_function==OSD_PAUSE){
1934 printf("\n------ PAUSED -------\r");fflush(stdout); 1959 printf("\n------ PAUSED -------\r");fflush(stdout);
1960 RESET_AUDIO(audio_fd); // stop audio
1935 #ifdef HAVE_GUI 1961 #ifdef HAVE_GUI
1936 if ( nogui ) 1962 if ( nogui )
1937 { 1963 {
1938 #endif 1964 #endif
1939 while( 1965 while(
2074 while(video_chunk_pos<demuxer->idx_size){ 2100 while(video_chunk_pos<demuxer->idx_size){
2075 int id=((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].ckid; 2101 int id=((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].ckid;
2076 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame 2102 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
2077 if(avi_stream_id(id)==d_video->id){ // video frame 2103 if(avi_stream_id(id)==d_video->id){ // video frame
2078 if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break; 2104 if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
2079 v_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; 2105 //v_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
2080 ++skip_audio_bytes; 2106 ++skip_audio_bytes;
2081 } 2107 }
2082 ++video_chunk_pos; 2108 ++video_chunk_pos;
2083 } 2109 }
2084 } else { 2110 } else {
2086 while(video_chunk_pos>=0){ 2112 while(video_chunk_pos>=0){
2087 int id=((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].ckid; 2113 int id=((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].ckid;
2088 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame 2114 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
2089 if(avi_stream_id(id)==d_video->id){ // video frame 2115 if(avi_stream_id(id)==d_video->id){ // video frame
2090 if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break; 2116 if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
2091 v_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; 2117 //v_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
2092 --skip_audio_bytes; 2118 --skip_audio_bytes;
2093 } 2119 }
2094 --video_chunk_pos; 2120 --video_chunk_pos;
2095 } 2121 }
2096 } 2122 }
2107 if(avi_stream_id(id)==d_video->id){ // video frame 2133 if(avi_stream_id(id)==d_video->id){ // video frame
2108 avi_video_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; 2134 avi_video_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
2109 } 2135 }
2110 } 2136 }
2111 //printf("v-pts recalc! %5.3f -> %5.3f \n",v_pts,avi_video_pts); 2137 //printf("v-pts recalc! %5.3f -> %5.3f \n",v_pts,avi_video_pts);
2112 v_pts=avi_video_pts; 2138 //v_pts=avi_video_pts;
2113 #else 2139 //#else
2114 avi_video_pts=v_pts; 2140 //avi_video_pts=v_pts;
2115 #endif 2141 #endif
2116 a_pts=avi_video_pts; 2142 //a_pts=avi_video_pts;
2117 //a_pts=v_pts; //-(buffer_delay+audio_delay); 2143 //a_pts=v_pts; //-(buffer_delay+audio_delay);
2118 2144
2119 if(has_audio){ 2145 if(has_audio){
2120 int i; 2146 int i;
2121 int apos=0; 2147 int apos=0;
2225 int newpos; 2251 int newpos;
2226 if(picture->bitrate==0x3FFFF) // unspecified? 2252 if(picture->bitrate==0x3FFFF) // unspecified?
2227 newpos=demuxer->filepos+2324*75*rel_seek_secs; // 174.3 kbyte/sec 2253 newpos=demuxer->filepos+2324*75*rel_seek_secs; // 174.3 kbyte/sec
2228 else 2254 else
2229 newpos=demuxer->filepos+(picture->bitrate*1000/16)*rel_seek_secs; 2255 newpos=demuxer->filepos+(picture->bitrate*1000/16)*rel_seek_secs;
2230 // picture->bitrate=2324*75*8; // standard VCD bitrate (75 sectors / sec)
2231 2256
2232 if(newpos<seek_to_byte) newpos=seek_to_byte; 2257 if(newpos<seek_to_byte) newpos=seek_to_byte;
2233 newpos&=~(STREAM_BUFFER_SIZE-1); /* sector boundary */ 2258 newpos&=~(STREAM_BUFFER_SIZE-1); /* sector boundary */
2234 stream_seek(demuxer->stream,newpos); 2259 stream_seek(demuxer->stream,newpos);
2235 // re-sync video: 2260 // re-sync video:
2237 while(1){ 2262 while(1){
2238 int i=sync_video_packet(d_video); 2263 int i=sync_video_packet(d_video);
2239 if(i==0x1B3 || i==0x1B8) break; // found it! 2264 if(i==0x1B3 || i==0x1B8) break; // found it!
2240 if(!i || !skip_video_packet(d_video)){ eof=1; break;} // EOF 2265 if(!i || !skip_video_packet(d_video)){ eof=1; break;} // EOF
2241 } 2266 }
2242 // re-sync audio: (must read to get actual audio PTS)
2243 // if(has_audio) ds_fill_buffer(d_audio);
2244 } 2267 }
2245 break; 2268 break;
2246 2269
2247 } // switch(file_format) 2270 } // switch(file_format)
2248 2271
2252 if(len>0){ 2275 if(len>0){
2253 osd_visible=sh_video->fps; // 1 sec 2276 osd_visible=sh_video->fps; // 1 sec
2254 vo_osd_progbar_type=0; 2277 vo_osd_progbar_type=0;
2255 vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len; 2278 vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
2256 } 2279 }
2257 //printf("avi filepos = %d \n",vo_osd_progbar_value); 2280 //printf("avi filepos = %d (len=%d)\n",vo_osd_progbar_value,len);
2258 // printf("avi filepos = %d (len=%d) \n",demuxer->filepos,(demuxer->movi_end-demuxer->movi_start));
2259 } 2281 }
2260 2282
2261 //====================== re-sync audio: ===================== 2283 //====================== re-sync audio: =====================
2262 if(has_audio){ 2284 if(has_audio){
2263 2285
2327 } // keyboard event handler 2349 } // keyboard event handler
2328 2350
2329 //================= Update OSD ==================== 2351 //================= Update OSD ====================
2330 { int i; 2352 { int i;
2331 if(osd_level>=2){ 2353 if(osd_level>=2){
2332 int pts=v_pts; 2354 int pts=d_video->pts;
2333 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts; 2355 if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
2334 vo_osd_text=osd_text_buffer; 2356 vo_osd_text=osd_text_buffer;
2335 sprintf(vo_osd_text,"%c %02d:%02d:%02d",osd_function,pts/3600,(pts/60)%60,pts%60); 2357 sprintf(vo_osd_text,"%c %02d:%02d:%02d",osd_function,pts/3600,(pts/60)%60,pts%60);
2336 } else { 2358 } else {
2337 vo_osd_text=NULL; 2359 vo_osd_text=NULL;
2339 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0; 2361 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
2340 // vo_osd_text=osd_text_buffer; 2362 // vo_osd_text=osd_text_buffer;
2341 2363
2342 // find sub 2364 // find sub
2343 if(subtitles){ 2365 if(subtitles){
2366 int pts=d_video->pts;
2344 if(sub_fps==0) sub_fps=sh_video->fps; 2367 if(sub_fps==0) sub_fps=sh_video->fps;
2345 current_module="find_sub"; 2368 current_module="find_sub";
2346 find_sub(subtitles,sub_uses_time?(100*(v_pts+sub_delay)):((v_pts+sub_delay)*sub_fps)); // FIXME! frame counter... 2369 find_sub(subtitles,sub_uses_time?(100*(pts+sub_delay)):((pts+sub_delay)*sub_fps)); // FIXME! frame counter...
2347 current_module=NULL; 2370 current_module=NULL;
2348 } 2371 }
2349 2372
2350 // DVD sub: 2373 // DVD sub:
2351 { unsigned char* packet=NULL; 2374 { unsigned char* packet=NULL;