Mercurial > mplayer.hg
comparison mplayer.c @ 20887:bf66030474ae
Split some from main() into separate functions.
author | uau |
---|---|
date | Tue, 14 Nov 2006 01:40:06 +0000 |
parents | 1e78e35b6c7b |
children | 0c750c3c1aed |
comparison
equal
deleted
inserted
replaced
20886:c215b6e501a5 | 20887:bf66030474ae |
---|---|
2802 | 2802 |
2803 mp_msg(MSGT_CPLAYER,MSGL_V, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n", | 2803 mp_msg(MSGT_CPLAYER,MSGL_V, "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n", |
2804 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth, vo_dheight, vo_fs); | 2804 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth, vo_dheight, vo_fs); |
2805 } | 2805 } |
2806 | 2806 |
2807 #ifdef HAVE_RTC | |
2808 int rtc_fd = -1; | |
2809 #endif | |
2810 | |
2811 static float timing_sleep(float time_frame) | |
2812 { | |
2813 #ifdef HAVE_RTC | |
2814 if (rtc_fd >= 0){ | |
2815 // -------- RTC ----------- | |
2816 current_module="sleep_rtc"; | |
2817 while (time_frame > 0.000) { | |
2818 unsigned long rtc_ts; | |
2819 if (read(rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0) | |
2820 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno)); | |
2821 time_frame -= GetRelativeTime(); | |
2822 } | |
2823 } else | |
2824 #endif | |
2825 #ifdef SYS_DARWIN | |
2826 { | |
2827 current_module = "sleep_darwin"; | |
2828 while (time_frame > 0.005) { | |
2829 usec_sleep(1000000*time_frame); | |
2830 time_frame -= GetRelativeTime(); | |
2831 } | |
2832 } | |
2833 #else | |
2834 { | |
2835 // assume kernel HZ=100 for softsleep, works with larger HZ but with | |
2836 // unnecessarily high CPU usage | |
2837 float margin = softsleep ? 0.011 : 0; | |
2838 current_module = "sleep_timer"; | |
2839 while (time_frame > margin) { | |
2840 usec_sleep(1000000 * (time_frame - margin)); | |
2841 time_frame -= GetRelativeTime(); | |
2842 } | |
2843 if (softsleep){ | |
2844 current_module = "sleep_soft"; | |
2845 if (time_frame < 0) | |
2846 mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow); | |
2847 while (time_frame > 0) | |
2848 time_frame-=GetRelativeTime(); // burn the CPU | |
2849 } | |
2850 } | |
2851 #endif /* SYS_DARWIN */ | |
2852 return time_frame; | |
2853 } | |
2854 | |
2855 static void adjust_sync_and_print_status(int between_frames, float timing_error) | |
2856 { | |
2857 current_module="av_sync"; | |
2858 | |
2859 if(sh_audio){ | |
2860 double a_pts, v_pts; | |
2861 | |
2862 if (autosync) | |
2863 /* | |
2864 * If autosync is enabled, the value for delay must be calculated | |
2865 * a bit differently. It is set only to the difference between | |
2866 * the audio and video timers. Any attempt to include the real | |
2867 * or corrected delay causes the pts_correction code below to | |
2868 * try to correct for the changes in delay which autosync is | |
2869 * trying to measure. This keeps the two from competing, but still | |
2870 * allows the code to correct for PTS drift *only*. (Using a delay | |
2871 * value here, even a "corrected" one, would be incompatible with | |
2872 * autosync mode.) | |
2873 */ | |
2874 a_pts = written_audio_pts(sh_audio, d_audio) - sh_audio->delay; | |
2875 else | |
2876 a_pts = playing_audio_pts(sh_audio, d_audio, audio_out); | |
2877 | |
2878 v_pts = sh_video ? sh_video->pts : d_video->pts; | |
2879 | |
2880 { | |
2881 static int drop_message=0; | |
2882 double AV_delay = a_pts - audio_delay - v_pts; | |
2883 double x; | |
2884 if (AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){ | |
2885 ++drop_message; | |
2886 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow); | |
2887 } | |
2888 if (autosync) | |
2889 x = AV_delay*0.1f; | |
2890 else | |
2891 /* Do not correct target time for the next frame if this frame | |
2892 * was late not because of wrong target time but because the | |
2893 * target time could not be met */ | |
2894 x = (AV_delay + timing_error * playback_speed) * 0.1f; | |
2895 if (x < -max_pts_correction) | |
2896 x = -max_pts_correction; | |
2897 else if (x> max_pts_correction) | |
2898 x = max_pts_correction; | |
2899 if (default_max_pts_correction >= 0) | |
2900 max_pts_correction = default_max_pts_correction; | |
2901 else | |
2902 max_pts_correction = sh_video->frametime*0.10; // +-10% of time | |
2903 if (!between_frames) { | |
2904 sh_audio->delay+=x; | |
2905 c_total+=x; | |
2906 } | |
2907 if(!quiet) | |
2908 print_status(a_pts - audio_delay, AV_delay, c_total); | |
2909 } | |
2910 | |
2911 } else { | |
2912 // No audio: | |
2913 | |
2914 if (!quiet) | |
2915 print_status(0, 0, 0); | |
2916 } | |
2917 } | |
2918 | |
2919 | |
2807 int main(int argc,char* argv[]){ | 2920 int main(int argc,char* argv[]){ |
2808 | 2921 |
2809 | 2922 |
2810 char * mem_ptr; | 2923 char * mem_ptr; |
2811 | 2924 |
2812 int file_format=DEMUXER_TYPE_UNKNOWN; | 2925 int file_format=DEMUXER_TYPE_UNKNOWN; |
2813 | 2926 |
2814 // movie info: | 2927 // movie info: |
2815 | |
2816 #ifdef HAVE_RTC | |
2817 int rtc_fd=-1; | |
2818 #endif | |
2819 | 2928 |
2820 /* Flag indicating whether MPlayer should exit without playing anything. */ | 2929 /* Flag indicating whether MPlayer should exit without playing anything. */ |
2821 int opt_exit = 0; | 2930 int opt_exit = 0; |
2822 | 2931 |
2823 //float a_frame=0; // Audio | 2932 //float a_frame=0; // Audio |
4310 //============================== SLEEP: =================================== | 4419 //============================== SLEEP: =================================== |
4311 | 4420 |
4312 time_frame/=playback_speed; | 4421 time_frame/=playback_speed; |
4313 | 4422 |
4314 // flag 256 means: libvo driver does its timing (dvb card) | 4423 // flag 256 means: libvo driver does its timing (dvb card) |
4315 if(time_frame>0.001 && !(vo_flags&256)){ | 4424 if(time_frame>0.001 && !(vo_flags&256)) |
4316 | 4425 time_frame = timing_sleep(time_frame); |
4317 #ifdef HAVE_RTC | |
4318 if(rtc_fd>=0){ | |
4319 // -------- RTC ----------- | |
4320 current_module="sleep_rtc"; | |
4321 while (time_frame > 0.000) { | |
4322 unsigned long rtc_ts; | |
4323 if (read (rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0) | |
4324 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno)); | |
4325 time_frame-=GetRelativeTime(); | |
4326 } | |
4327 } else | |
4328 #endif | |
4329 #ifdef SYS_DARWIN | |
4330 { | |
4331 current_module="sleep_darwin"; | |
4332 while(time_frame>0.005) { | |
4333 usec_sleep(1000000*time_frame); | |
4334 time_frame-=GetRelativeTime(); | |
4335 } | |
4336 } | |
4337 #else | |
4338 { | |
4339 // -------- TIMER + SOFTSLEEP ----------- | |
4340 // assume kernel HZ=100 for softsleep, works with larger HZ but with | |
4341 // unnecessarily high CPU usage | |
4342 float margin = softsleep ? 0.011 : 0; | |
4343 current_module="sleep_timer"; | |
4344 while (time_frame > margin) { | |
4345 usec_sleep(1000000 * (time_frame - margin)); | |
4346 time_frame -= GetRelativeTime(); | |
4347 } | |
4348 if(softsleep){ | |
4349 current_module="sleep_soft"; | |
4350 if(time_frame<0) mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow); | |
4351 while(time_frame>0) time_frame-=GetRelativeTime(); // burn the CPU | |
4352 } | |
4353 } | |
4354 #endif /* SYS_DARWIN */ | |
4355 } | |
4356 | |
4357 //if(!frame_time_remaining){ // should we display the frame now? | |
4358 | 4426 |
4359 //====================== FLIP PAGE (VIDEO BLT): ========================= | 4427 //====================== FLIP PAGE (VIDEO BLT): ========================= |
4360 | 4428 |
4361 current_module="vo_check_events"; | 4429 current_module="vo_check_events"; |
4362 if(vo_config_count) video_out->check_events(); | 4430 if(vo_config_count) video_out->check_events(); |
4401 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL); | 4469 video_out->control(VOCTRL_DUPLICATE_FRAME, NULL); |
4402 } | 4470 } |
4403 } | 4471 } |
4404 //====================== A-V TIMESTAMP CORRECTION: ========================= | 4472 //====================== A-V TIMESTAMP CORRECTION: ========================= |
4405 | 4473 |
4406 current_module="av_sync"; | 4474 adjust_sync_and_print_status(frame_time_remaining, time_frame); |
4407 | |
4408 if(sh_audio){ | |
4409 double a_pts, v_pts; | |
4410 | |
4411 if (autosync) | |
4412 /* | |
4413 * If autosync is enabled, the value for delay must be calculated | |
4414 * a bit differently. It is set only to the difference between | |
4415 * the audio and video timers. Any attempt to include the real | |
4416 * or corrected delay causes the pts_correction code below to | |
4417 * try to correct for the changes in delay which autosync is | |
4418 * trying to measure. This keeps the two from competing, but still | |
4419 * allows the code to correct for PTS drift *only*. (Using a delay | |
4420 * value here, even a "corrected" one, would be incompatible with | |
4421 * autosync mode.) | |
4422 */ | |
4423 a_pts = written_audio_pts(sh_audio, d_audio) - sh_audio->delay; | |
4424 else | |
4425 a_pts = playing_audio_pts(sh_audio, d_audio, audio_out); | |
4426 | |
4427 v_pts=sh_video ? sh_video->pts : d_video->pts; | |
4428 | |
4429 { | |
4430 static int drop_message=0; | |
4431 double AV_delay = a_pts - audio_delay - v_pts; | |
4432 double x; | |
4433 if(AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){ | |
4434 ++drop_message; | |
4435 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow); | |
4436 } | |
4437 if (autosync) | |
4438 x = AV_delay*0.1f; | |
4439 else | |
4440 /* Do not correct target time for the next frame if this frame | |
4441 * was late not because of wrong target time but because the | |
4442 * target time could not be met */ | |
4443 x = (AV_delay + time_frame * playback_speed) * 0.1f; | |
4444 if(x<-max_pts_correction) x=-max_pts_correction; else | |
4445 if(x> max_pts_correction) x= max_pts_correction; | |
4446 if(default_max_pts_correction>=0) | |
4447 max_pts_correction=default_max_pts_correction; | |
4448 else | |
4449 max_pts_correction=sh_video->frametime*0.10; // +-10% of time | |
4450 if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction | |
4451 if(!quiet) | |
4452 print_status(a_pts - audio_delay, AV_delay, c_total); | |
4453 } | |
4454 | |
4455 } else { | |
4456 // No audio: | |
4457 | |
4458 if(!quiet) | |
4459 print_status(0, 0, 0); | |
4460 | |
4461 } | |
4462 | 4475 |
4463 //============================ Auto QUALITY ============================ | 4476 //============================ Auto QUALITY ============================ |
4464 | 4477 |
4465 /*Output quality adjustments:*/ | 4478 /*Output quality adjustments:*/ |
4466 if(auto_quality>0){ | 4479 if(auto_quality>0){ |