diff options
Diffstat (limited to 'video/out/vo.c')
-rw-r--r-- | video/out/vo.c | 76 |
1 files changed, 22 insertions, 54 deletions
diff --git a/video/out/vo.c b/video/out/vo.c index 07476ad7c3..aa92d349e5 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -23,11 +23,6 @@ #include <pthread.h> #include <math.h> -#ifndef __MINGW32__ -#include <unistd.h> -#include <poll.h> -#endif - #include "mpv_talloc.h" #include "config.h" @@ -127,9 +122,6 @@ struct vo_internal { bool need_wakeup; bool terminate; - int wakeup_pipe[2]; // used for VOs that use a unix FD for waiting - - bool hasframe; bool hasframe_rendered; bool request_redraw; // redraw request from player to VO @@ -215,8 +207,6 @@ static void dealloc_vo(struct vo *vo) forget_frames(vo); // implicitly synchronized pthread_mutex_destroy(&vo->in->lock); pthread_cond_destroy(&vo->in->wakeup); - for (int n = 0; n < 2; n++) - close(vo->in->wakeup_pipe[n]); talloc_free(vo); } @@ -239,7 +229,6 @@ static struct vo *vo_create(bool probing, struct mpv_global *global, .encode_lavc_ctx = ex->encode_lavc_ctx, .input_ctx = ex->input_ctx, .osd = ex->osd, - .event_fd = -1, .monitor_par = 1, .extra = *ex, .probing = probing, @@ -251,7 +240,6 @@ static struct vo *vo_create(bool probing, struct mpv_global *global, .req_frames = 1, .estimated_vsync_jitter = -1, }; - mp_make_wakeup_pipe(vo->in->wakeup_pipe); mp_dispatch_set_wakeup_fn(vo->in->dispatch, dispatch_wakeup_cb, vo); pthread_mutex_init(&vo->in->lock, NULL); pthread_cond_init(&vo->in->wakeup, NULL); @@ -580,60 +568,34 @@ static void forget_frames(struct vo *vo) } } -#ifndef __MINGW32__ -static void wait_event_fd(struct vo *vo, int64_t until_time) +// VOs which have no special requirements on UI event loops etc. can set the +// vo_driver.wait_events callback to this (and leave vo_driver.wakeup unset). +// This function must not be used or called for other purposes. +void vo_wait_default(struct vo *vo, int64_t until_time) { struct vo_internal *in = vo->in; - struct pollfd fds[2] = { - { .fd = vo->event_fd, .events = POLLIN }, - { .fd = in->wakeup_pipe[0], .events = POLLIN }, - }; - int64_t wait_us = until_time - mp_time_us(); - int timeout_ms = MPCLAMP((wait_us + 500) / 1000, 0, 10000); - - poll(fds, 2, timeout_ms); - - if (fds[1].revents & POLLIN) { - char buf[100]; - (void)read(in->wakeup_pipe[0], buf, sizeof(buf)); // flush + pthread_mutex_lock(&in->lock); + if (!in->need_wakeup) { + struct timespec ts = mp_time_us_to_timespec(until_time); + pthread_cond_timedwait(&in->wakeup, &in->lock, &ts); } + pthread_mutex_unlock(&in->lock); } -static void wakeup_event_fd(struct vo *vo) -{ - struct vo_internal *in = vo->in; - - (void)write(in->wakeup_pipe[1], &(char){0}, 1); -} -#else -static void wait_event_fd(struct vo *vo, int64_t until_time){} -static void wakeup_event_fd(struct vo *vo){} -#endif // Called unlocked. static void wait_vo(struct vo *vo, int64_t until_time) { struct vo_internal *in = vo->in; - if (vo->event_fd >= 0) { - wait_event_fd(vo, until_time); - pthread_mutex_lock(&in->lock); - in->need_wakeup = false; - pthread_mutex_unlock(&in->lock); - } else if (vo->driver->wait_events) { + if (vo->driver->wait_events) { vo->driver->wait_events(vo, until_time); - pthread_mutex_lock(&in->lock); - in->need_wakeup = false; - pthread_mutex_unlock(&in->lock); } else { - pthread_mutex_lock(&in->lock); - if (!in->need_wakeup) { - struct timespec ts = mp_time_us_to_timespec(until_time); - pthread_cond_timedwait(&in->wakeup, &in->lock, &ts); - } - in->need_wakeup = false; - pthread_mutex_unlock(&in->lock); + vo_wait_default(vo, until_time); } + pthread_mutex_lock(&in->lock); + in->need_wakeup = false; + pthread_mutex_unlock(&in->lock); } static void wakeup_locked(struct vo *vo) @@ -641,8 +603,6 @@ static void wakeup_locked(struct vo *vo) struct vo_internal *in = vo->in; pthread_cond_broadcast(&in->wakeup); - if (vo->event_fd >= 0) - wakeup_event_fd(vo); if (vo->driver->wakeup) vo->driver->wakeup(vo); in->need_wakeup = true; @@ -1136,6 +1096,14 @@ double vo_get_delay(struct vo *vo) return res ? (res - mp_time_us()) / 1e6 : 0; } +void vo_discard_timing_info(struct vo *vo) +{ + struct vo_internal *in = vo->in; + pthread_mutex_lock(&in->lock); + reset_vsync_timings(vo); + pthread_mutex_unlock(&in->lock); +} + int64_t vo_get_delayed_count(struct vo *vo) { struct vo_internal *in = vo->in; |