1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-11 08:37:59 +00:00

vo: use pthread_cond_timedwait() for video timing

Will be used to make video waiting interruptible with Cocoa (see the
following commit).

One worry was that this could cause hangs if the system clock jumps
backwards. Normally we don't support such behavior, because it's
almost impossible to handle it reasonably. E.g. we would have to
change the default clock type for condition variables, which in turn
would require a custom function for creating condition variables,
or so. If the OS even supports different clocks.

But it turns out that this is no issue, because other events seem
to wakeup the wait call anyway, and mpv internal absolute times use
a monotonic clock.
This commit is contained in:
wm4 2015-05-12 22:30:45 +02:00
parent 6b7155c05b
commit 434343d634

View File

@ -561,6 +561,22 @@ void vo_wait_frame(struct vo *vo)
pthread_mutex_unlock(&in->lock);
}
// Wait until realtime is >= ts
// called without lock
static void wait_until(struct vo *vo, int64_t target)
{
struct vo_internal *in = vo->in;
struct timespec ts = mp_time_us_to_timespec(target);
while (1) {
int64_t now = mp_time_us();
if (target <= now)
break;
pthread_mutex_lock(&in->lock);
pthread_cond_timedwait(&in->wakeup, &in->lock, &ts);
pthread_mutex_unlock(&in->lock);
}
}
// needs lock
static int64_t prev_sync(struct vo *vo, int64_t ts)
{
@ -672,12 +688,7 @@ static bool render_frame(struct vo *vo)
vo->driver->draw_image(vo, img);
}
while (1) {
int64_t now = mp_time_us();
if (target <= now)
break;
mp_sleep_us(target - now);
}
wait_until(vo, target);
bool drop = false;
if (vo->driver->flip_page_timed)