summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mp_core.h5
-rw-r--r--mplayer.c24
-rw-r--r--osdep/timer-darwin.c21
-rw-r--r--osdep/timer-linux.c13
-rw-r--r--osdep/timer-win2.c11
-rw-r--r--osdep/timer.h1
6 files changed, 24 insertions, 51 deletions
diff --git a/mp_core.h b/mp_core.h
index aaede73586..3c9e8e56b1 100644
--- a/mp_core.h
+++ b/mp_core.h
@@ -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;
diff --git a/mplayer.c b/mplayer.c
index a2e3c4c57a..f429bb6c79 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -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;
diff --git a/osdep/timer-darwin.c b/osdep/timer-darwin.c
index 38de7dea9d..e087b33f12 100644
--- a/osdep/timer-darwin.c
+++ b/osdep/timer-darwin.c
@@ -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
diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c
index 27e245c850..efcc612627 100644
--- a/osdep/timer-linux.c
+++ b/osdep/timer-linux.c
@@ -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();
}
diff --git a/osdep/timer-win2.c b/osdep/timer-win2.c
index ef52a665d3..43c4b07fa9 100644
--- a/osdep/timer-win2.c
+++ b/osdep/timer-win2.c
@@ -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();
}
diff --git a/osdep/timer.h b/osdep/timer.h
index 44e26cdafc..b0f289c00a 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -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);