1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 07:12:39 +00:00

timers: Remove GetRelativeTime()

Move the code calculating time delta since last query out of the
platform-specific drivers and into mplayer.c. The platform-specific
drivers now return absolute values only.

The way the code in timer-darwin.c uses doubles in wrapping arithmetic
looks questionable and this change might make problems in it more
visible.
This commit is contained in:
Uoti Urpala 2008-04-28 12:09:31 +03:00
parent c693b77e93
commit eaf7857b7f
6 changed files with 24 additions and 51 deletions

View File

@ -70,6 +70,11 @@ typedef struct MPContext {
// by the audio CPU usage meter.
double delay;
// Timestamp from the last time some timing functions read the
// current time, in (occasionally wrapping) microseconds. Used
// to turn a new time value to a delta from last time.
unsigned int last_time;
// Used to communicate the parameters of a seek between parts
float rel_seek_secs;
int abs_seek_pos;

View File

@ -369,6 +369,14 @@ int mpctx_get_osd_function(MPContext *mpctx)
return mpctx->osd_function;
}
static float get_relative_time(struct MPContext *mpctx)
{
unsigned int new_time = GetTimer();
unsigned int delta = new_time - mpctx->last_time;
mpctx->last_time = new_time;
return delta * 0.000001;
}
static int is_valid_metadata_type(struct MPContext *mpctx, metadata_t type) {
switch (type)
{
@ -1758,7 +1766,7 @@ static int generate_video_frame(struct MPContext *mpctx)
int rtc_fd = -1;
#endif
static float timing_sleep(float time_frame)
static float timing_sleep(struct MPContext *mpctx, float time_frame)
{
#ifdef HAVE_RTC
if (rtc_fd >= 0){
@ -1768,7 +1776,7 @@ static float timing_sleep(float time_frame)
unsigned long rtc_ts;
if (read(rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0)
mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno));
time_frame -= GetRelativeTime();
time_frame -= get_relative_time(mpctx);
}
} else
#endif
@ -1779,14 +1787,14 @@ static float timing_sleep(float time_frame)
current_module = "sleep_timer";
while (time_frame > margin) {
usec_sleep(1000000 * (time_frame - margin));
time_frame -= GetRelativeTime();
time_frame -= get_relative_time(mpctx);
}
if (softsleep){
current_module = "sleep_soft";
if (time_frame < 0)
mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow);
while (time_frame > 0)
time_frame-=GetRelativeTime(); // burn the CPU
time_frame -= get_relative_time(mpctx); // burn the CPU
}
}
return time_frame;
@ -2073,7 +2081,7 @@ static int sleep_until_update(struct MPContext *mpctx, float *time_frame,
int frame_time_remaining = 0;
current_module="calc_sleep_time";
*time_frame -= GetRelativeTime(); // reset timer
*time_frame -= get_relative_time(mpctx); // reset timer
if (mpctx->sh_audio && !mpctx->d_audio->eof) {
float delay = mpctx->audio_out->get_delay();
@ -2120,7 +2128,7 @@ static int sleep_until_update(struct MPContext *mpctx, float *time_frame,
// flag 256 means: libvo driver does its timing (dvb card)
if (*time_frame > 0.001 && !(mpctx->sh_video->output_flags&256))
*time_frame = timing_sleep(*time_frame);
*time_frame = timing_sleep(mpctx, *time_frame);
return frame_time_remaining;
}
@ -2372,7 +2380,7 @@ static void pause_loop(struct MPContext *mpctx)
mpctx->audio_out->resume(); // resume audio
if (mpctx->video_out && mpctx->sh_video && mpctx->video_out->config_ok)
vo_control(mpctx->video_out, VOCTRL_RESUME, NULL); // resume video
(void)GetRelativeTime(); // ignore time that passed during pause
(void)get_relative_time(mpctx); // ignore time that passed during pause
#ifdef HAVE_NEW_GUI
if (use_gui) {
if (guiIntfStruct.Playing == guiSetStop)
@ -3683,6 +3691,8 @@ if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
}
#endif
get_relative_time(mpctx); // reset current delta
while(!mpctx->eof){
float aq_sleep_time=0;

View File

@ -27,7 +27,6 @@
#include "timer.h"
/* global variables */
static double relative_time, startup_time;
static double timebase_ratio;
const char timer_name[] = "Darwin accurate";
@ -54,30 +53,17 @@ int usec_sleep(int usec_delay)
/* current time in microseconds */
unsigned int GetTimer()
{
return (unsigned int)((mach_absolute_time() * timebase_ratio - startup_time)
return (unsigned int)((mach_absolute_time() * timebase_ratio)
* 1e6);
}
/* current time in milliseconds */
unsigned int GetTimerMS()
{
return (unsigned int)((mach_absolute_time() * timebase_ratio - startup_time)
return (unsigned int)((mach_absolute_time() * timebase_ratio)
* 1e3);
}
/* time spent between now and last call in seconds */
float GetRelativeTime()
{
double last_time = relative_time;
if (!relative_time)
InitTimer();
relative_time = mach_absolute_time() * timebase_ratio;
return (float)(relative_time-last_time);
}
/* initialize timer, must be called at least once at start */
void InitTimer()
{
@ -86,9 +72,6 @@ void InitTimer()
mach_timebase_info(&timebase);
timebase_ratio = (double)timebase.numer / (double)timebase.denom
* (double)1e-9;
relative_time = startup_time =
(double)(mach_absolute_time() * timebase_ratio);
}
#if 0

View File

@ -46,21 +46,8 @@ unsigned int GetTimerMS(void){
return (tv.tv_sec*1000+tv.tv_usec/1000);
}
static unsigned int RelativeTime=0;
// Returns time spent between now and last call in seconds
float GetRelativeTime(void){
unsigned int t,r;
t=GetTimer();
// t*=16;printf("time=%ud\n",t);
r=t-RelativeTime;
RelativeTime=t;
return (float)r * 0.000001F;
}
// Initialize timer, must be called at least once at start
void InitTimer(void){
GetRelativeTime();
}

View File

@ -25,16 +25,5 @@ int usec_sleep(int usec_delay){
return 0;
}
static DWORD RelativeTime = 0;
float GetRelativeTime(){
DWORD t, r;
t = GetTimer();
r = t - RelativeTime;
RelativeTime = t;
return (float) r *0.000001F;
}
void InitTimer(){
GetRelativeTime();
}

View File

@ -7,7 +7,6 @@ void InitTimer(void);
unsigned int GetTimer(void);
unsigned int GetTimerMS(void);
//int uGetTimer();
float GetRelativeTime(void);
int usec_sleep(int usec_delay);