mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-14 23:34:08 +00:00
deps/media-playback: Add timeout when waiting for frames
Media files that have a very low framerate or very long interval between frames would cause the media playback to stall indefinitely until the next frame is played. This adds a 200ms timeout to ensure that the media can be destroyed without being forced to wait indefinitely for the next frame.
This commit is contained in:
parent
da9e247964
commit
c1cf44fd91
26
deps/media-playback/media-playback/media.c
vendored
26
deps/media-playback/media-playback/media.c
vendored
|
@ -455,12 +455,25 @@ static bool mp_media_reset(mp_media_t *m)
|
|||
return true;
|
||||
}
|
||||
|
||||
static inline void mp_media_sleepto(mp_media_t *m)
|
||||
static inline bool mp_media_sleepto(mp_media_t *m)
|
||||
{
|
||||
if (!m->next_ns)
|
||||
bool timeout = false;
|
||||
|
||||
if (!m->next_ns) {
|
||||
m->next_ns = os_gettime_ns();
|
||||
else
|
||||
os_sleepto_ns(m->next_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);
|
||||
}
|
||||
}
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
static inline bool mp_media_eof(mp_media_t *m)
|
||||
|
@ -562,6 +575,7 @@ static inline bool mp_media_thread(mp_media_t *m)
|
|||
|
||||
for (;;) {
|
||||
bool reset, kill, is_active;
|
||||
bool timeout = false;
|
||||
|
||||
pthread_mutex_lock(&m->mutex);
|
||||
is_active = m->active;
|
||||
|
@ -571,7 +585,7 @@ static inline bool mp_media_thread(mp_media_t *m)
|
|||
if (os_sem_wait(m->sem) < 0)
|
||||
return false;
|
||||
} else {
|
||||
mp_media_sleepto(m);
|
||||
timeout = mp_media_sleepto(m);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&m->mutex);
|
||||
|
@ -592,7 +606,7 @@ static inline bool mp_media_thread(mp_media_t *m)
|
|||
}
|
||||
|
||||
/* frames are ready */
|
||||
if (is_active) {
|
||||
if (is_active && !timeout) {
|
||||
if (m->has_video)
|
||||
mp_media_next_video(m, false);
|
||||
if (m->has_audio)
|
||||
|
|
Loading…
Reference in a new issue