warn if ALSA wakes us up and there is actually nothing to do

This commit is contained in:
Lennart Poettering 2008-10-22 23:55:52 +02:00
parent 6ff9c1fb62
commit 3294c89adb
3 changed files with 66 additions and 22 deletions

View file

@ -241,7 +241,7 @@ static size_t check_left_to_play(struct userdata *u, snd_pcm_sframes_t n) {
return left_to_play;
}
static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) {
static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled) {
int work_done = 0;
pa_usec_t max_sleep_usec = 0, process_usec = 0;
size_t left_to_play;
@ -279,14 +279,23 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) {
* need to guarantee that clients only have to keep around
* a single hw buffer length. */
if (pa_bytes_to_usec(left_to_play, &u->sink->sample_spec) > process_usec+max_sleep_usec/2)
if (!polled &&
pa_bytes_to_usec(left_to_play, &u->sink->sample_spec) > process_usec+max_sleep_usec/2)
break;
if (PA_UNLIKELY(n <= u->hwbuf_unused_frames))
if (PA_UNLIKELY(n <= u->hwbuf_unused_frames)) {
if (polled)
pa_log("ALSA woke us up to write new data to the device, but there was actually nothing to write! "
"Most likely this is an ALSA driver bug. Please report this issue to the PulseAudio developers.");
break;
}
n -= u->hwbuf_unused_frames;
polled = FALSE;
/* pa_log_debug("Filling up"); */
for (;;) {
@ -357,7 +366,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) {
return work_done;
}
static int unix_write(struct userdata *u, pa_usec_t *sleep_usec) {
static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled) {
int work_done = 0;
pa_usec_t max_sleep_usec = 0, process_usec = 0;
size_t left_to_play;
@ -392,14 +401,23 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec) {
* need to guarantee that clients only have to keep around
* a single hw buffer length. */
if (pa_bytes_to_usec(left_to_play, &u->sink->sample_spec) > process_usec+max_sleep_usec/2)
if (!polled &&
pa_bytes_to_usec(left_to_play, &u->sink->sample_spec) > process_usec+max_sleep_usec/2)
break;
if (PA_UNLIKELY(n <= u->hwbuf_unused_frames))
if (PA_UNLIKELY(n <= u->hwbuf_unused_frames)) {
if (polled)
pa_log("ALSA woke us up to write new data to the device, but there was actually nothing to write! "
"Most likely this is an ALSA driver bug. Please report this issue to the PulseAudio developers.");
break;
}
n -= u->hwbuf_unused_frames;
polled = FALSE;
for (;;) {
snd_pcm_sframes_t frames;
void *p;
@ -1084,6 +1102,7 @@ finish:
static void thread_func(void *userdata) {
struct userdata *u = userdata;
unsigned short revents = 0;
pa_assert(u);
@ -1110,9 +1129,9 @@ static void thread_func(void *userdata) {
goto fail;
if (u->use_mmap)
work_done = mmap_write(u, &sleep_usec);
work_done = mmap_write(u, &sleep_usec, revents & POLLOUT);
else
work_done = unix_write(u, &sleep_usec);
work_done = unix_write(u, &sleep_usec, revents & POLLOUT);
if (work_done < 0)
goto fail;
@ -1180,7 +1199,6 @@ static void thread_func(void *userdata) {
/* Tell ALSA about this and process its response */
if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
struct pollfd *pollfd;
unsigned short revents = 0;
int err;
unsigned n;
@ -1191,7 +1209,7 @@ static void thread_func(void *userdata) {
goto fail;
}
if (revents & (POLLERR|POLLNVAL|POLLHUP|POLLPRI)) {
if (revents & (POLLIN|POLLERR|POLLNVAL|POLLHUP|POLLPRI)) {
if (pa_alsa_recover_from_poll(u->pcm_handle, revents) < 0)
goto fail;
@ -1201,7 +1219,8 @@ static void thread_func(void *userdata) {
if (revents && u->use_tsched)
pa_log_debug("Wakeup from ALSA!%s%s", (revents & POLLIN) ? " INPUT" : "", (revents & POLLOUT) ? " OUTPUT" : "");
}
} else
revents = 0;
}
fail: