mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-14 23:34:08 +00:00
deps/media-playback: Less accurate sleep
Avoid busy-wait for media sources by not caring about sleep precision. Reduces CPU usage in status bar from 1.1% to 0.8% on my machine.
This commit is contained in:
parent
5457524f5a
commit
976d76dfbd
21
deps/media-playback/media-playback/media.c
vendored
21
deps/media-playback/media-playback/media.c
vendored
|
@ -540,21 +540,22 @@ static bool mp_media_reset(mp_media_t *m)
|
|||
return true;
|
||||
}
|
||||
|
||||
static inline bool mp_media_sleepto(mp_media_t *m)
|
||||
static inline bool mp_media_sleep(mp_media_t *m)
|
||||
{
|
||||
bool timeout = false;
|
||||
|
||||
if (!m->next_ns) {
|
||||
m->next_ns = os_gettime_ns();
|
||||
} else {
|
||||
uint64_t t = os_gettime_ns();
|
||||
const uint64_t timeout_ns = 200000000;
|
||||
|
||||
if (m->next_ns > t && (m->next_ns - t) > timeout_ns) {
|
||||
os_sleepto_ns(t + timeout_ns);
|
||||
timeout = true;
|
||||
} else {
|
||||
os_sleepto_ns(m->next_ns);
|
||||
const uint64_t t = os_gettime_ns();
|
||||
if (m->next_ns > t) {
|
||||
const uint32_t delta_ms =
|
||||
(uint32_t)((m->next_ns - t + 500000) / 1000000);
|
||||
if (delta_ms > 0) {
|
||||
static const uint32_t timeout_ms = 200;
|
||||
timeout = delta_ms > timeout_ms;
|
||||
os_sleep_ms(timeout ? timeout_ms : delta_ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -695,7 +696,7 @@ static inline bool mp_media_thread(mp_media_t *m)
|
|||
if (pause)
|
||||
reset_ts(m);
|
||||
} else {
|
||||
timeout = mp_media_sleepto(m);
|
||||
timeout = mp_media_sleep(m);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&m->mutex);
|
||||
|
|
Loading…
Reference in a new issue