mirror of
https://github.com/mpv-player/mpv
synced 2024-12-25 08:12:17 +00:00
client API: change mpv_wait_event() timeout semantics
Now a negative timeout mean an infinite timeout. This is similar to the poll() system call. Apparently this is more intuitive and less confusing than specifying a "very high" value as timeout if you want to wait forever. For callers that never pass negative timeouts, nothing changes.
This commit is contained in:
parent
60e0833f1f
commit
a1000962e3
@ -1122,7 +1122,8 @@ int mpv_request_log_messages(mpv_handle *ctx, const char *min_level);
|
||||
*
|
||||
* @param timeout Timeout in seconds, after which the function returns even if
|
||||
* no event was received. A MPV_EVENT_NONE is returned on
|
||||
* timeout. Values <= 0 will disable waiting.
|
||||
* timeout. A value of 0 will disable waiting. Negative values
|
||||
* will wait with an infinite timeout.
|
||||
* @return A struct containing the event ID and other data. The pointer (and
|
||||
* fields in the struct) stay valid until the next mpv_wait_event()
|
||||
* call, or until mpv_destroy() is called. You must not write to
|
||||
|
@ -495,6 +495,9 @@ mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout)
|
||||
{
|
||||
mpv_event *event = ctx->cur_event;
|
||||
|
||||
if (timeout < 0)
|
||||
timeout = 1e20;
|
||||
|
||||
int64_t deadline = mp_add_timeout(mp_time_us(), timeout);
|
||||
|
||||
pthread_mutex_lock(&ctx->lock);
|
||||
@ -535,7 +538,7 @@ mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout)
|
||||
}
|
||||
if (ctx->queued_wakeup)
|
||||
break;
|
||||
if (timeout <= 0)
|
||||
if (timeout == 0)
|
||||
break;
|
||||
int r = mpthread_cond_timedwait(&ctx->wakeup, &ctx->lock, deadline);
|
||||
if (r == ETIMEDOUT)
|
||||
|
@ -360,7 +360,7 @@ function mp.dispatch_events(allow_wait)
|
||||
if wait == nil then
|
||||
wait = 1e20 -- infinity for all practical purposes
|
||||
end
|
||||
if more_events then
|
||||
if more_events or wait < 0 then
|
||||
wait = 0
|
||||
end
|
||||
-- Resume playloop - important especially if an error happened while
|
||||
|
Loading…
Reference in New Issue
Block a user