audio: fix UB when casting INFINITY to integer

Fixes busy wait, because in practice inf would be casted to 0.

Fixes: 174df99
This commit is contained in:
Kacper Michajłow 2023-11-15 07:00:37 +01:00 committed by Dudemanguy
parent 39cab760b3
commit a6fb9321ea
1 changed files with 3 additions and 3 deletions

View File

@ -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;