diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-11-15 07:00:37 +0100 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-11-15 14:57:18 +0000 |
commit | a6fb9321ea137e01fb1a702a31d2c6b40b2509a3 (patch) | |
tree | b95c6f778b2423c00d2605a6f899eac3ba821de8 /audio | |
parent | 39cab760b3a335942219bf0534ebcc35e2a924a2 (diff) | |
download | mpv-a6fb9321ea137e01fb1a702a31d2c6b40b2509a3.tar.bz2 mpv-a6fb9321ea137e01fb1a702a31d2c6b40b2509a3.tar.xz |
audio: fix UB when casting INFINITY to integer
Fixes busy wait, because in practice inf would be casted to 0.
Fixes: 174df99
Diffstat (limited to 'audio')
-rw-r--r-- | audio/out/buffer.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/audio/out/buffer.c b/audio/out/buffer.c index 71367e47fd..5b8b523081 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -698,12 +698,12 @@ static MP_THREAD_VOID playthread(void *arg) // Wait until the device wants us to write more data to it. // Fallback to guessing. - double timeout = INFINITY; + int64_t timeout = INT64_MAX; if (p->streaming && !retry && (!p->paused || ao->stream_silence)) { // Wake up again if half of the audio buffer has been played. // Since audio could play at a faster or slower pace, wake up twice // as often as ideally needed. - timeout = ao->device_buffer / (double)ao->samplerate * 0.25; + timeout = MP_TIME_S_TO_NS(ao->device_buffer / (double)ao->samplerate * 0.25); } mp_mutex_unlock(&p->lock); @@ -715,7 +715,7 @@ static MP_THREAD_VOID playthread(void *arg) } if (!p->need_wakeup && !retry) { MP_STATS(ao, "start audio wait"); - mp_cond_timedwait(&p->pt_wakeup, &p->pt_lock, MP_TIME_S_TO_NS(timeout)); + mp_cond_timedwait(&p->pt_wakeup, &p->pt_lock, timeout); MP_STATS(ao, "end audio wait"); } p->need_wakeup = false; |