mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
ao_alsa: reduce spurious wakeups
Apparently this can happen. So actually only return from waiting if ALSA excplicitly signals that new output is available, or if we are woken up externally.
This commit is contained in:
parent
3053a68d2d
commit
9c9f23eee9
@ -712,14 +712,20 @@ static int audio_wait(struct ao *ao, pthread_mutex_t *lock)
|
||||
err = snd_pcm_poll_descriptors(p->alsa, fds, num_fds);
|
||||
CHECK_ALSA_ERROR("cannot get pollfds");
|
||||
|
||||
int r = ao_wait_poll(ao, fds, num_fds, lock);
|
||||
if (r < 0)
|
||||
return r;
|
||||
while (1) {
|
||||
int r = ao_wait_poll(ao, fds, num_fds, lock);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
unsigned short revents;
|
||||
snd_pcm_poll_descriptors_revents(p->alsa, fds, num_fds, &revents);
|
||||
CHECK_ALSA_ERROR("cannot read poll events");
|
||||
unsigned short revents;
|
||||
snd_pcm_poll_descriptors_revents(p->alsa, fds, num_fds, &revents);
|
||||
CHECK_ALSA_ERROR("cannot read poll events");
|
||||
|
||||
if (revents & POLLERR)
|
||||
return -1;
|
||||
if (revents & POLLOUT)
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
||||
alsa_error:
|
||||
|
@ -410,7 +410,7 @@ int ao_play_silence(struct ao *ao, int samples)
|
||||
// Call poll() for the given fds. This will extend the given fds with the
|
||||
// wakeup pipe, so ao_wakeup_poll() will basically interrupt this function.
|
||||
// Unlocks the lock temporarily.
|
||||
// Returns <0 on error, 0 on success.
|
||||
// Returns <0 on error, 0 on success, 1 if the caller should return immediately.
|
||||
int ao_wait_poll(struct ao *ao, struct pollfd *fds, int num_fds,
|
||||
pthread_mutex_t *lock)
|
||||
{
|
||||
@ -434,13 +434,15 @@ int ao_wait_poll(struct ao *ao, struct pollfd *fds, int num_fds,
|
||||
pthread_mutex_lock(&p->lock);
|
||||
|
||||
memcpy(fds, p_fds, num_fds * sizeof(fds[0]));
|
||||
bool wakeup = false;
|
||||
if (p_fds[num_fds].revents & POLLIN) {
|
||||
wakeup = true;
|
||||
// flush the wakeup pipe contents - might "drown" some wakeups, but
|
||||
// that's ok for our use-case
|
||||
char buf[100];
|
||||
read(p->wakeup_pipe[0], buf, sizeof(buf));
|
||||
}
|
||||
return (r >= 0 || r == -EINTR) ? 0 : -1;
|
||||
return (r >= 0 || r == -EINTR) ? wakeup : -1;
|
||||
}
|
||||
|
||||
void ao_wakeup_poll(struct ao *ao)
|
||||
|
Loading…
Reference in New Issue
Block a user