summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-25 18:31:06 +0200
committerwm4 <wm4@nowhere>2013-05-26 16:44:20 +0200
commite56d8a200d900066c3da571d92733f66ce6a13ab (patch)
treef43862ec12beee05380da82ebef23bcce83401e7
parent51254a678c386cf48f2caa51e06ad34065c8693a (diff)
downloadmpv-e56d8a200d900066c3da571d92733f66ce6a13ab.tar.bz2
mpv-e56d8a200d900066c3da571d92733f66ce6a13ab.tar.xz
Replace all calls to GetTimer()/GetTimerMS()
GetTimer() is generally replaced with mp_time_us(). Both calls return microseconds, but the latter uses int64_t, us defined to never wrap, and never returns 0 or negative values. GetTimerMS() has no direct replacement. Instead the other functions are used. For some code, switch to mp_time_sec(), which returns the time as double float value in seconds. The returned time is offset to program start time, so there is enough precision left to deliver microsecond resolution for at least 100 years. Unless it's casted to a float (or the CPU reduces precision), which is why we still use mp_time_us() out of paranoia in places where precision is clearly needed. Always switch to the correct time. The whole point of the new timer calls is that they don't wrap, and storing microseconds in unsigned int variables would negate this. In some cases, remove wrap-around handling for time values.
-rw-r--r--audio/out/ao_jack.c4
-rw-r--r--audio/out/ao_null.c8
-rw-r--r--audio/out/ao_sdl.c20
-rw-r--r--core/encode_lavc.c9
-rw-r--r--core/encode_lavc.h2
-rw-r--r--core/input/input.c18
-rw-r--r--core/input/input.h2
-rw-r--r--core/mp_core.h23
-rw-r--r--core/mp_fifo.c6
-rw-r--r--core/mplayer.c81
-rw-r--r--osdep/timer.c10
-rw-r--r--osdep/timer.h2
-rw-r--r--stream/cache2.c6
-rw-r--r--stream/tv.c2
-rw-r--r--video/out/vo.h6
-rw-r--r--video/out/vo_lavc.c2
-rw-r--r--video/out/vo_vdpau.c26
-rw-r--r--video/out/x11_common.c4
-rw-r--r--video/out/x11_common.h2
19 files changed, 108 insertions, 125 deletions
diff --git a/audio/out/ao_jack.c b/audio/out/ao_jack.c
index 0f8baeab86..1807a11c44 100644
--- a/audio/out/ao_jack.c
+++ b/audio/out/ao_jack.c
@@ -170,7 +170,7 @@ static int outputaudio(jack_nframes_t nframes, void *arg) {
if (read_buffer(bufs, nframes, num_ports) < nframes)
underrun = 1;
if (estimate) {
- float now = (float)GetTimer() / 1000000.0;
+ float now = mp_time_us() / 1000000.0;
float diff = callback_time + callback_interval - now;
if ((diff > -0.002) && (diff < 0.002))
callback_time += callback_interval;
@@ -361,7 +361,7 @@ static float get_delay(void) {
int buffered = av_fifo_size(buffer); // could be less
float in_jack = jack_latency;
if (estimate && callback_interval > 0) {
- float elapsed = (float)GetTimer() / 1000000.0 - callback_time;
+ float elapsed = mp_time_us() / 1000000.0 - callback_time;
in_jack += callback_interval - elapsed;
if (in_jack < 0) in_jack = 0;
}
diff --git a/audio/out/ao_null.c b/audio/out/ao_null.c
index 53ec2a9a83..32d02bea31 100644
--- a/audio/out/ao_null.c
+++ b/audio/out/ao_null.c
@@ -29,7 +29,7 @@
#include "ao.h"
struct priv {
- unsigned last_time;
+ double last_time;
float buffered_bytes;
};
@@ -37,8 +37,8 @@ static void drain(struct ao *ao)
{
struct priv *priv = ao->priv;
- unsigned now = GetTimer();
- priv->buffered_bytes -= (now - priv->last_time) / 1e6 * ao->bps;
+ double now = mp_time_sec();
+ priv->buffered_bytes -= (now - priv->last_time) * ao->bps;
if (priv->buffered_bytes < 0)
priv->buffered_bytes = 0;
priv->last_time = now;
@@ -59,7 +59,7 @@ static int init(struct ao *ao, char *params)
// A "buffer" for about 0.2 seconds of audio
ao->buffersize = (int)(ao->samplerate * 0.2 / 256 + 1) * ao->outburst;
ao->bps = ao->channels.num * ao->samplerate * samplesize;
- priv->last_time = GetTimer();
+ priv->last_time = mp_time_sec();
return 0;
}
diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c
index 6678cd3bd3..63b1f3963d 100644
--- a/audio/out/ao_sdl.c
+++ b/audio/out/ao_sdl.c
@@ -42,8 +42,8 @@ struct priv
bool unpause;
bool paused;
#ifdef ESTIMATE_DELAY
- unsigned int callback_time0;
- unsigned int callback_time1;
+ int64_t callback_time0;
+ int64_t callback_time1;
#endif
};
@@ -56,7 +56,7 @@ static void audio_callback(void *userdata, Uint8 *stream, int len)
#ifdef ESTIMATE_DELAY
priv->callback_time1 = priv->callback_time0;
- priv->callback_time0 = GetTimer();
+ priv->callback_time0 = mp_time_us();
#endif
while (len > 0 && !priv->paused) {
@@ -268,7 +268,7 @@ static int init(struct ao *ao, char *params)
priv->unpause = 1;
priv->paused = 1;
- priv->callback_time0 = priv->callback_time1 = GetTimer();
+ priv->callback_time0 = priv->callback_time1 = mp_time_us();
return 1;
}
@@ -340,8 +340,8 @@ static float get_delay(struct ao *ao)
SDL_LockMutex(priv->buffer_mutex);
int sz = av_fifo_size(priv->buffer);
#ifdef ESTIMATE_DELAY
- unsigned int callback_time0 = priv->callback_time0;
- unsigned int callback_time1 = priv->callback_time1;
+ int64_t callback_time0 = priv->callback_time0;
+ int64_t callback_time1 = priv->callback_time1;
#endif
SDL_UnlockMutex(priv->buffer_mutex);
@@ -351,16 +351,16 @@ static float get_delay(struct ao *ao)
#ifdef ESTIMATE_DELAY
// delay component: outstanding audio living in SDL
- unsigned int current_time = GetTimer();
+ int64_t current_time = mp_time_us();
// interval between callbacks
- unsigned int callback_interval = callback_time0 - callback_time1;
- unsigned int elapsed_interval = current_time - callback_time0;
+ int64_t callback_interval = callback_time0 - callback_time1;
+ int64_t elapsed_interval = current_time - callback_time0;
if (elapsed_interval > callback_interval)
elapsed_interval = callback_interval;
// delay subcomponent: remaining audio from the currently played buffer
- unsigned int buffer_interval = callback_interval - elapsed_interval;
+ int64_t buffer_interval = callback_interval - elapsed_interval;
// delay subcomponent: remaining audio from the next played buffer, as
// provided by the callback
diff --git a/core/encode_lavc.c b/core/encode_lavc.c
index 457f6ab987..1677baf838 100644
--- a/core/encode_lavc.c
+++ b/core/encode_lavc.c
@@ -269,7 +269,7 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
}
}
- ctx->t0 = GetTimerMS();
+ ctx->t0 = mp_time_sec();
mp_msg(MSGT_ENCODE, MSGL_INFO, "Opening muxer: %s [%s]\n",
ctx->avc->oformat->long_name, ctx->avc->oformat->name);
@@ -997,6 +997,7 @@ int encode_lavc_getstatus(struct encode_lavc_context *ctx,
char *buf, int bufsize,
float relative_position, float playback_time)
{
+ double now = mp_time_sec();
float minutes, megabytes, fps, x;
float f = FFMAX(0.0001, relative_position);
if (!ctx)
@@ -1004,10 +1005,10 @@ int encode_lavc_getstatus(struct encode_lavc_context *ctx,
CHECK_FAIL(ctx, -1);
- minutes = (GetTimerMS() - ctx->t0) / 60000.0 * (1 - f) / f;
+ minutes = (now - ctx->t0) / 60.0 * (1 - f) / f;
megabytes = ctx->avc->pb ? (avio_size(ctx->avc->pb) / 1048576.0 / f) : 0;
- fps = ctx->frames / ((GetTimerMS() - ctx->t0) / 1000.0);
- x = playback_time / ((GetTimerMS() - ctx->t0) / 1000.0);
+ fps = ctx->frames / ((now - ctx->t0));
+ x = playback_time / ((now - ctx->t0));
if (ctx->frames)
snprintf(buf, bufsize, "{%.1f%% %.1fmin %.1ffps %.1fMB}",
relative_position * 100.0, minutes, fps, megabytes);
diff --git a/core/encode_lavc.h b/core/encode_lavc.h
index a0245c991a..7e53ae6a1d 100644
--- a/core/encode_lavc.h
+++ b/core/encode_lavc.h
@@ -61,7 +61,7 @@ struct encode_lavc_context {
long long vbytes;
struct stream *twopass_bytebuffer_a;
struct stream *twopass_bytebuffer_v;
- unsigned int t0;
+ double t0;
unsigned int frames;
bool expect_video;
diff --git a/core/input/input.c b/core/input/input.c
index c756efcbdc..3d8ba711b7 100644
--- a/core/input/input.c
+++ b/core/input/input.c
@@ -464,7 +464,7 @@ struct input_ctx {
// Autorepeat stuff
short ar_state;
mp_cmd_t *ar_cmd;
- unsigned int last_ar;
+ int64_t last_ar;
// Autorepeat config
unsigned int ar_delay;
unsigned int ar_rate;
@@ -475,7 +475,7 @@ struct input_ctx {
// these are the keys currently down
int key_down[MP_MAX_KEY_DOWN];
unsigned int num_key_down;
- unsigned int last_key_down;
+ int64_t last_key_down;
bool test;
@@ -491,7 +491,7 @@ struct input_ctx {
// events sources. If yes, the sources may have more queued.
bool got_new_events;
- unsigned int last_mouse_event;
+ unsigned int mouse_event_counter;
struct input_fd key_fds[MP_MAX_KEY_FD];
unsigned int num_key_fd;
@@ -1230,7 +1230,7 @@ static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code)
return NULL;
ictx->key_down[ictx->num_key_down] = code;
ictx->num_key_down++;
- ictx->last_key_down = GetTimer();
+ ictx->last_key_down = mp_time_us();
ictx->ar_state = 0;
ret = NULL;
if (!(code & MP_NO_REPEAT_KEY))
@@ -1287,7 +1287,7 @@ static mp_cmd_t *check_autorepeat(struct input_ctx *ictx)
// No input : autorepeat ?
if (ictx->ar_rate > 0 && ictx->ar_state >= 0 && ictx->num_key_down > 0
&& !(ictx->key_down[ictx->num_key_down - 1] & MP_NO_REPEAT_KEY)) {
- unsigned int t = GetTimer();
+ int64_t t = mp_time_us();
if (ictx->last_ar + 2000000 < t)
ictx->last_ar = t;
// First time : wait delay
@@ -1319,7 +1319,7 @@ void mp_input_feed_key(struct input_ctx *ictx, int code)
ictx->got_new_events = true;
int unmod = code & ~(MP_KEY_MODIFIER_MASK | MP_KEY_STATE_DOWN);
if (unmod >= MP_MOUSE_BASE && unmod <= MP_MOUSE_BTN_END)
- ictx->last_mouse_event = GetTimerMS();
+ ictx->mouse_event_counter++;
if (code == MP_INPUT_RELEASE_ALL) {
mp_msg(MSGT_INPUT, MSGL_V, "input: release all\n");
memset(ictx->key_down, 0, sizeof(ictx->key_down));
@@ -1483,7 +1483,7 @@ int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd)
if (!cmd)
return 0;
if (cmd->id == MP_CMD_SET_MOUSE_POS)
- ictx->last_mouse_event = GetTimerMS();
+ ictx->mouse_event_counter++;
queue_add(&ictx->control_cmd_queue, cmd, false);
return 1;
}
@@ -1914,7 +1914,7 @@ int mp_input_check_interrupt(struct input_ctx *ictx, int time)
}
}
-unsigned int mp_input_get_last_mouse_event_time(struct input_ctx *ictx)
+unsigned int mp_input_get_mouse_event_counter(struct input_ctx *ictx)
{
- return ictx->last_mouse_event;
+ return ictx->mouse_event_counter;
}
diff --git a/core/input/input.h b/core/input/input.h
index 1f079e7451..6c33e47fdc 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -209,7 +209,7 @@ void mp_input_set_section(struct input_ctx *ictx, char *name, int flags);
char *mp_input_get_section(struct input_ctx *ictx);
// Used to detect mouse movement.
-unsigned int mp_input_get_last_mouse_event_time(struct input_ctx *ictx);
+unsigned int mp_input_get_mouse_event_counter(struct input_ctx *ictx);
// Initialize the input system
struct input_conf;
diff --git a/core/mp_core.h b/core/mp_core.h
index 6f784b4b7c..3b693d1658 100644
--- a/core/mp_core.h
+++ b/core/mp_core.h
@@ -132,9 +132,10 @@ typedef struct MPContext {
subtitle subs; // subtitle list used when reading subtitles from demuxer
int add_osd_seek_info; // bitfield of enum mp_osd_seek_info
- unsigned int osd_visible; // for the osd bar only
+ double osd_visible; // for the osd bar only
int osd_function;
- unsigned int osd_function_visible;
+ double osd_function_visible;
+ double osd_last_update;
struct playlist *playlist;
char *filename; // currently playing file
@@ -196,11 +197,11 @@ typedef struct MPContext {
// by the audio CPU usage meter.
double delay;
// AV sync: time until next frame should be shown
- float time_frame;
+ double time_frame;
// How long the last vo flip() call took. Used to adjust timing with
// the goal of making flip() calls finish (rather than start) at the
// specified time.
- float last_vo_flip_duration;
+ double last_vo_flip_duration;
// How much video timing has been changed to make it match the audio
// timeline. Used for status line information only.
double total_avsync_change;
@@ -232,23 +233,21 @@ typedef struct MPContext {
uint64_t backstep_start_seek_ts;
bool backstep_active;
- float audio_delay;
+ double audio_delay;
- unsigned int last_heartbeat;
+ double last_heartbeat;
- unsigned int mouse_timer;
- unsigned int mouse_last_time;
+ double mouse_timer;
+ unsigned int mouse_event_ts;
int mouse_waiting_hide;
- unsigned int next_wakup_time;
-
// used to prevent hanging in some error cases
- unsigned int start_timestamp;
+ double start_timestamp;
// 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;
+ int64_t last_time;
// Used to communicate the parameters of a seek between parts
struct seek_params {
diff --git a/core/mp_fifo.c b/core/mp_fifo.c
index 386eda5e80..32036749d1 100644
--- a/core/mp_fifo.c
+++ b/core/mp_fifo.c
@@ -31,7 +31,7 @@ struct mp_fifo {
struct MPOpts *opts;
struct input_ctx *input;
int last_key_down;
- unsigned last_down_time;
+ double last_down_time;
};
struct mp_fifo *mp_fifo_create(struct input_ctx *input, struct MPOpts *opts)
@@ -50,7 +50,7 @@ static void put_double(struct mp_fifo *fifo, int code)
void mplayer_put_key(struct mp_fifo *fifo, int code)
{
- unsigned now = GetTimerMS();
+ double now = mp_time_sec();
int doubleclick_time = fifo->opts->doubleclick_time;
// ignore system-doubleclick if we generate these events ourselves
if (doubleclick_time
@@ -61,7 +61,7 @@ void mplayer_put_key(struct mp_fifo *fifo, int code)
if (code & MP_KEY_STATE_DOWN) {
code &= ~MP_KEY_STATE_DOWN;
if (fifo->last_key_down == code
- && now - fifo->last_down_time < doubleclick_time)
+ && now - fifo->last_down_time < doubleclick_time / 1000.0)
put_double(fifo, code);
fifo->last_key_down = code;
fifo->last_down_time = now;
diff --git a/core/mplayer.c b/core/mplayer.c
index 0b1bee4179..8e077e248d 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -207,10 +207,10 @@ static struct track *open_external_file(struct MPContext *mpctx, char *filename,
char *demuxer_name, int stream_cache,
enum stream_type filter);
-static float get_relative_time(struct MPContext *mpctx)
+static double get_relative_time(struct MPContext *mpctx)
{
- unsigned int new_time = GetTimer();
- unsigned int delta = new_time - mpctx->last_time;
+ int64_t new_time = mp_time_us();
+ int64_t delta = new_time - mpctx->last_time;
mpctx->last_time = new_time;
return delta * 0.000001;
}
@@ -1329,13 +1329,14 @@ struct mp_osd_msg {
/// Message text.
char *msg;
int id, level, started;
- /// Display duration in ms.
- unsigned time;
+ /// Display duration in seconds.
+ double time;
// Show full OSD for duration of message instead of msg
// (osd_show_progression command)
bool show_position;
};
+// time is in ms
static mp_osd_msg_t *add_osd_msg(struct MPContext *mpctx, int id, int level,
int time)
{
@@ -1345,7 +1346,7 @@ static mp_osd_msg_t *add_osd_msg(struct MPContext *mpctx, int id, int level,
.msg = "",
.id = id,
.level = level,
- .time = time,
+ .time = time / 1000.0,
});
mpctx->osd_msg_stack = msg;
return msg;
@@ -1415,32 +1416,25 @@ static mp_osd_msg_t *get_osd_msg(struct MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
mp_osd_msg_t *msg, *prev, *last = NULL;
- static unsigned last_update = 0;
- unsigned now = GetTimerMS();
- unsigned diff;
+ double now = mp_time_sec();
+ double diff;
char hidden_dec_done = 0;
- if (mpctx->osd_visible) {
- // 36000000 means max timed visibility is 1 hour into the future, if
- // the difference is greater assume it's wrapped around from below 0
- if (mpctx->osd_visible - now > 36000000) {
- mpctx->osd_visible = 0;
- mpctx->osd->progbar_type = -1; // disable
- vo_osd_changed(OSDTYPE_PROGBAR);
- }
+ if (mpctx->osd_visible && now >= mpctx->osd_visible) {
+ mpctx->osd_visible = 0;
+ mpctx->osd->progbar_type = -1; // disable
+ vo_osd_changed(OSDTYPE_PROGBAR);
}
- if (mpctx->osd_function_visible) {
- if (mpctx->osd_function_visible - now > 36000000) {
- mpctx->osd_function_visible = 0;
- mpctx->osd_function = 0;
- }
+ if (mpctx->osd_function_visible && now >= mpctx->osd_function_visible) {
+ mpctx->osd_function_visible = 0;
+ mpctx->osd_function = 0;
}
- if (!last_update)
- last_update = now;
- diff = now >= last_update ? now - last_update : 0;
+ if (!mpctx->osd_last_update)
+ mpctx->osd_last_update = now;
+ diff = now >= mpctx->osd_last_update ? now - mpctx->osd_last_update : 0;
- last_update = now;
+ mpctx->osd_last_update = now;
// Look for the first message in the stack with high enough level.
for (msg = mpctx->osd_msg_stack; msg; last = msg, msg = prev) {
@@ -1484,7 +1478,7 @@ void set_osd_bar(struct MPContext *mpctx, int type, const char *name,
return;
if (mpctx->sh_video && opts->term_osd != 1) {
- mpctx->osd_visible = (GetTimerMS() + opts->osd_duration) | 1;
+ mpctx->osd_visible = mp_time_sec() + opts->osd_duration / 1000.0;
mpctx->osd->progbar_type = type;
mpctx->osd->progbar_value = (val - min) / (max - min);
mpctx->osd->progbar_num_stops = 0;
@@ -1535,7 +1529,7 @@ void set_osd_function(struct MPContext *mpctx, int osd_function)
struct MPOpts *opts = &mpctx->opts;
mpctx->osd_function = osd_function;
- mpctx->osd_function_visible = (GetTimerMS() + opts->osd_duration) | 1;
+ mpctx->osd_function_visible = mp_time_sec() + opts->osd_duration / 1000.0;
}
/**
@@ -2028,12 +2022,12 @@ static int check_framedrop(struct MPContext *mpctx, double frame_time)
return 0;
}
-static float timing_sleep(struct MPContext *mpctx, float time_frame)
+static double timing_sleep(struct MPContext *mpctx, double time_frame)
{
// assume kernel HZ=100 for softsleep, works with larger HZ but with
// unnecessarily high CPU usage
struct MPOpts *opts = &mpctx->opts;
- float margin = opts->softsleep ? 0.011 : 0;
+ double margin = opts->softsleep ? 0.011 : 0;
while (time_frame > margin) {
usec_sleep(1000000 * (time_frame - margin));
time_frame -= get_relative_time(mpctx);
@@ -3129,7 +3123,7 @@ static int seek(MPContext *mpctx, struct seek_params seek,
: mpctx->timeline[mpctx->timeline_part].start;
}
- mpctx->start_timestamp = GetTimerMS();
+ mpctx->start_timestamp = mp_time_sec();
return 0;
}
@@ -3507,32 +3501,29 @@ static void run_playloop(struct MPContext *mpctx)
// ================================================================
vo_check_events(vo);
- unsigned int mouse_last_time =
- mp_input_get_last_mouse_event_time(mpctx->input);
- if (mpctx->mouse_last_time != mouse_last_time) {
- mpctx->mouse_last_time = mouse_last_time;
+ double mouse_event_ts = mp_input_get_mouse_event_counter(mpctx->input);
+ if (mpctx->mouse_event_ts != mouse_event_ts) {
+ mpctx->mouse_event_ts = mouse_event_ts;
if (opts->vo.cursor_autohide_delay > -1) {
vo_control(vo, VOCTRL_SET_CURSOR_VISIBILITY, &(bool){true});
if (opts->vo.cursor_autohide_delay >= 0) {
mpctx->mouse_waiting_hide = 1;
mpctx->mouse_timer =
- GetTimerMS() + opts->vo.cursor_autohide_delay;
+ mp_time_sec() + opts->vo.cursor_autohide_delay / 1000.0;
}
}
}
if (mpctx->mouse_waiting_hide == 1 &&
- GetTimerMS() >= mpctx->mouse_timer)
+ mp_time_sec() >= mpctx->mouse_timer)
{
vo_control(vo, VOCTRL_SET_CURSOR_VISIBILITY, &(bool){false});
mpctx->mouse_waiting_hide = 2;
}
if (opts->heartbeat_cmd) {
- unsigned now = GetTimerMS();
- if (now - mpctx->last_heartbeat >
- (unsigned)(opts->heartbeat_interval * 1000))
- {
+ double now = mp_time_sec();
+ if (now - mpctx->last_heartbeat > opts->heartbeat_interval) {
mpctx->last_heartbeat = now;
system(opts->heartbeat_cmd);
}
@@ -3602,12 +3593,12 @@ static void run_playloop(struct MPContext *mpctx)
mpctx->time_frame = timing_sleep(mpctx, mpctx->time_frame);
mpctx->time_frame += vo->flip_queue_offset;
- unsigned int t2 = GetTimer();
+ int64_t t2 = mp_time_us();
/* Playing with playback speed it's possible to get pathological
* cases with mpctx->time_frame negative enough to cause an
* overflow in pts_us calculation, thus the FFMAX. */
double time_frame = FFMAX(mpctx->time_frame, -1);
- unsigned int pts_us = mpctx->last_time + time_frame * 1e6;
+ int64_t pts_us = mpctx->last_time + time_frame * 1e6;
int duration = -1;
double pts2 = vo->next_pts2;
if (pts2 != MP_NOPTS_VALUE && opts->correct_pts &&
@@ -3625,7 +3616,7 @@ static void run_playloop(struct MPContext *mpctx)
}
vo_flip_page(vo, pts_us | 1, duration);
- mpctx->last_vo_flip_duration = (GetTimer() - t2) * 0.000001;
+ mpctx->last_vo_flip_duration = (mp_time_us() - t2) * 0.000001;
if (vo->driver->flip_page_timed) {
// No need to adjust sync based on flip speed
mpctx->last_vo_flip_duration = 0;
@@ -3788,7 +3779,7 @@ static void run_playloop(struct MPContext *mpctx)
* another seek (which could lead to unchanging display). */
if ((mpctx->seek.type && cmd->id != MP_CMD_SEEK) ||
(mpctx->restart_playback && cmd->id == MP_CMD_SEEK &&
- GetTimerMS() - mpctx->start_timestamp < 300))
+ mp_time_sec() - mpctx->start_timestamp < 0.3))
break;
cmd = mp_input_get_cmd(mpctx->input, 0, 0);
run_command(mpctx, cmd);
diff --git a/osdep/timer.c b/osdep/timer.c
index 2304bb1297..c1efeff8b5 100644
--- a/osdep/timer.c
+++ b/osdep/timer.c
@@ -42,16 +42,6 @@ double mp_time_sec(void)
return mp_time_us() / (double)(1000 * 1000);
}
-unsigned int GetTimer(void)
-{
- return mp_time_us();
-}
-
-unsigned int GetTimerMS(void)
-{
- return (mp_time_us() + 500) / 1000;
-}
-
int usec_sleep(int usec_delay)
{
mp_sleep_us(usec_delay);
diff --git a/osdep/timer.h b/osdep/timer.h
index 033b366750..bdddf3d61a 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -39,8 +39,6 @@ uint64_t mp_raw_time_us(void);
void mp_sleep_us(int64_t us);
// Legacy timer functions. These can wrap.
-unsigned int GetTimer(void); // in us
-unsigned int GetTimerMS(void); // in ms
int usec_sleep(int usec_delay);
#endif /* MPLAYER_TIMER_H */
diff --git a/stream/cache2.c b/stream/cache2.c
index 1337e44e37..671bd85c53 100644
--- a/stream/cache2.c
+++ b/stream/cache2.c
@@ -264,7 +264,7 @@ static int cache_execute_control(cache_vars_t *s) {
unsigned uint_res;
uint64_t uint64_res;
int needs_flush = 0;
- static unsigned last;
+ static double last;
int quit = s->control == -2;
uint64_t old_pos = s->stream->pos;
int old_eof = s->stream->eof;
@@ -275,7 +275,7 @@ static int cache_execute_control(cache_vars_t *s) {
s->control = -1;
return !quit;
}
- if (GetTimerMS() - last > 99) {
+ if (mp_time_sec() - last > 0.099) {
double len, pos;
if (s->stream->control(s->stream, STREAM_CTRL_GET_TIME_LENGTH, &len) == STREAM_OK)
s->stream_time_length = len;
@@ -296,7 +296,7 @@ static int cache_execute_control(cache_vars_t *s) {
return 0;
}
#endif
- last = GetTimerMS();
+ last = mp_time_sec();
}
if (s->control == -1) return 1;
switch (s->control) {
diff --git a/stream/tv.c b/stream/tv.c
index 38368d4925..1fcb13037d 100644
--- a/stream/tv.c
+++ b/stream/tv.c
@@ -130,7 +130,7 @@ static void tv_scan(tvi_handle_t *tvh)
}
scan = tvh->scan;
- now=GetTimer();
+ now=(unsigned int)mp_time_us();
if (!scan) {
scan=calloc(1,sizeof(tv_scan_t));
tvh->scan=scan;
diff --git a/video/out/vo.h b/video/out/vo.h
index f357b21797..3dcc58b6c3 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -195,9 +195,13 @@ struct vo_driver {
/*
* Blit/Flip buffer to the screen. Must be called after each frame!
+ * pts_us is the frame presentation time, linked to mp_time_us().
+ * pts_us is 0 if the frame should be presented immediately.
+ * duration is estimated time in us until the next frame is shown.
+ * duration is -1 if it is unknown or unset.
*/
void (*flip_page)(struct vo *vo);
- void (*flip_page_timed)(struct vo *vo, unsigned int pts_us, int duration);
+ void (*flip_page_timed)(struct vo *vo, int64_t pts_us, int duration);
/*
* Closes driver. Should restore the original state of the system.
diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c
index 6d1eb5c6f8..5140720f92 100644
--- a/video/out/vo_lavc.c
+++ b/video/out/vo_lavc.c
@@ -460,7 +460,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi)
}
}
-static void flip_page_timed(struct vo *vo, unsigned int pts_us, int duration)
+static void flip_page_timed(struct vo *vo, int64_t pts_us, int duration)
{
}
diff --git a/video/out/vo_vdpau.c b/video/out/vo_vdpau.c
index d213b33c6f..975ef526c3 100644
--- a/video/out/vo_vdpau.c
+++ b/video/out/vo_vdpau.c
@@ -97,13 +97,13 @@ struct vdpctx {
bool is_preempted;
bool preemption_acked;
bool preemption_user_notified;
- unsigned int last_preemption_retry_fail;
+ double last_preemption_retry_fail;
VdpGetProcAddress *vdp_get_proc_address;
VdpPresentationQueueTarget flip_target;
VdpPresentationQueue flip_queue;
uint64_t last_vdp_time;
- unsigned int last_sync_update;
+ uint64_t last_sync_update;
VdpOutputSurface output_surfaces[MAX_OUTPUT_SURFACES];
VdpOutputSurface screenshot_surface;
@@ -181,15 +181,15 @@ struct vdpctx {
static bool status_ok(struct vo *vo);
-static int change_vdptime_sync(struct vdpctx *vc, unsigned int *t)
+static int change_vdptime_sync(struct vdpctx *vc, int64_t *t)
{
struct vdp_functions *vdp = vc->vdp;
VdpStatus vdp_st;
VdpTime vdp_time;
vdp_st = vdp->presentation_queue_get_time(vc->flip_queue, &vdp_time);
CHECK_ST_ERROR("Error when calling vdp_presentation_queue_get_time");
- unsigned int t1 = *t;
- unsigned int t2 = GetTimer();
+ uint64_t t1 = *t;
+ uint64_t t2 = mp_time_us();
uint64_t old = vc->last_vdp_time + (t1 - vc->last_sync_update) * 1000ULL;
if (vdp_time > old) {
if (vdp_time > old + (t2 - t1) * 1000ULL)
@@ -209,7 +209,7 @@ static uint64_t sync_vdptime(struct vo *vo)
{
struct vdpctx *vc = vo->priv;
- unsigned int t = GetTimer();
+ uint64_t t = mp_time_us();
if (t - vc->last_sync_update > 5000000)
change_vdptime_sync(vc, &t);
uint64_t now = (t - vc->last_sync_update) * 1000ULL + vc->last_vdp_time;
@@ -218,10 +218,10 @@ static uint64_t sync_vdptime(struct vo *vo)
return now;
}
-static uint64_t convert_to_vdptime(struct vo *vo, unsigned int t)
+static uint64_t convert_to_vdptime(struct vo *vo, uint64_t t)
{
struct vdpctx *vc = vo->priv;
- return (int)(t - vc->last_sync_update) * 1000LL + vc->last_vdp_time;
+ return (t - vc->last_sync_update) * 1000LL + vc->last_vdp_time;
}
static int render_video_to_output_surface(struct vo *vo,
@@ -513,7 +513,7 @@ static int win_x11_init_vdpau_flip_queue(struct vo *vo)
vdp_st = vdp->presentation_queue_get_time(vc->flip_queue, &vdp_time);
CHECK_ST_ERROR("Error when calling vdp_presentation_queue_get_time");
vc->last_vdp_time = vdp_time;
- vc->last_sync_update = GetTimer();
+ vc->last_sync_update = mp_time_us();
vc->vsync_interval = 1;
if (vc->composite_detect && vo_x11_screen_is_composited(vo)) {
@@ -822,11 +822,11 @@ static int handle_preemption(struct vo *vo)
}
/* Trying to initialize seems to be quite slow, so only try once a
* second to avoid using 100% CPU. */
- if (vc->last_preemption_retry_fail
- && GetTimerMS() - vc->last_preemption_retry_fail < 1000)
+ if (vc->last_preemption_retry_fail &&
+ mp_time_sec() - vc->last_preemption_retry_fail < 1.0)
return -1;
if (win_x11_init_vdpau_procs(vo) < 0 || initialize_vdpau_objects(vo) < 0) {
- vc->last_preemption_retry_fail = GetTimerMS() | 1;
+ vc->last_preemption_retry_fail = mp_time_sec();
return -1;
}
vc->last_preemption_retry_fail = 0;
@@ -1102,7 +1102,7 @@ static inline uint64_t prev_vs2(struct vdpctx *vc, uint64_t ts, int shift)
return ts - offset;
}
-static void flip_page_timed(struct vo *vo, unsigned int pts_us, int duration)
+static void flip_page_timed(struct vo *vo, int64_t pts_us, int duration)
{
struct vdpctx *vc = vo->priv;
struct vdp_functions *vdp = vc->vdp;
diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index 571bc9032c..5eb6031d66 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -1398,10 +1398,10 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg)
static void xscreensaver_heartbeat(struct vo_x11_state *x11)