diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/alsa/alsa-sink.c | 20 | ||||
-rw-r--r-- | src/modules/alsa/alsa-source.c | 20 | ||||
-rw-r--r-- | src/modules/alsa/alsa-util.c | 72 | ||||
-rw-r--r-- | src/modules/alsa/alsa-util.h | 3 |
4 files changed, 95 insertions, 20 deletions
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index ef51f1db..d4a54fe6 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -306,9 +306,12 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle if (polled) PA_ONCE_BEGIN { - 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 ALSA developers. " - "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail_update() returned 0.")); + char *dn = pa_alsa_get_driver_name_by_pcm(u->pcm_handle); + pa_log(_("ALSA woke us up to write new data to the device, but there was actually nothing to write!\n" + "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers.\n" + "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail."), + pa_strnull(dn)); + pa_xfree(dn); } PA_ONCE_END; #ifdef DEBUG_TIMING @@ -435,9 +438,12 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle if (polled) PA_ONCE_BEGIN { - 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 ALSA developers. " - "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail_update() returned 0.")); + char *dn = pa_alsa_get_driver_name_by_pcm(u->pcm_handle); + pa_log(_("ALSA woke us up to write new data to the device, but there was actually nothing to write!\n" + "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers.\n" + "We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail."), + pa_strnull(dn)); + pa_xfree(dn); } PA_ONCE_END; break; @@ -516,7 +522,7 @@ static void update_smoother(struct userdata *u) { /* Let's update the time smoother */ - if (PA_UNLIKELY((err = snd_pcm_delay(u->pcm_handle, &delay)) < 0)) { + if (PA_UNLIKELY((err = pa_alsa_safe_delay(u->pcm_handle, &delay, u->hwbuf_size, &u->sink->sample_spec)) < 0)) { pa_log_warn("Failed to query DSP status data: %s", snd_strerror(err)); return; } diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index fbc21f74..f2dad4c5 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -289,9 +289,12 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled if (polled) PA_ONCE_BEGIN { - pa_log(_("ALSA woke us up to read new data from the device, but there was actually nothing to read! " - "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. " - "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail_update() returned 0.")); + char *dn = pa_alsa_get_driver_name_by_pcm(u->pcm_handle); + pa_log(_("ALSA woke us up to read new data from the device, but there was actually nothing to read!\n" + "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers.\n" + "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail."), + pa_strnull(dn)); + pa_xfree(dn); } PA_ONCE_END; #ifdef DEBUG_TIMING @@ -410,9 +413,12 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled if (polled) PA_ONCE_BEGIN { - pa_log(_("ALSA woke us up to read new data from the device, but there was actually nothing to read! " - "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers. " - "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail_update() returned 0.")); + char *dn = pa_alsa_get_driver_name_by_pcm(u->pcm_handle); + pa_log(_("ALSA woke us up to read new data from the device, but there was actually nothing to read!\n" + "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers.\n" + "We were woken up with POLLIN set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail."), + pa_strnull(dn)); + pa_xfree(dn); } PA_ONCE_END; break; @@ -486,7 +492,7 @@ static void update_smoother(struct userdata *u) { /* Let's update the time smoother */ - if (PA_UNLIKELY((err = snd_pcm_delay(u->pcm_handle, &delay)) < 0)) { + if (PA_UNLIKELY((err = pa_alsa_safe_delay(u->pcm_handle, &delay, u->hwbuf_size, &u->source->sample_spec)) < 0)) { pa_log_warn("Failed to get delay: %s", snd_strerror(err)); return; } diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c index 016e52ab..8eedeeb5 100644 --- a/src/modules/alsa/alsa-util.c +++ b/src/modules/alsa/alsa-util.c @@ -1578,14 +1578,55 @@ snd_pcm_sframes_t pa_alsa_safe_avail(snd_pcm_t *pcm, size_t hwbuf_size, const pa k >= pa_bytes_per_second(ss)*10) PA_ONCE_BEGIN { - pa_log(_("snd_pcm_avail_update() returned a value that is exceptionally large: %lu bytes (%lu ms). " - "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers."), - (unsigned long) k, (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC)); + char *dn = pa_alsa_get_driver_name_by_pcm(pcm); + pa_log(_("snd_pcm_avail() returned a value that is exceptionally large: %lu bytes (%lu ms).\n" + "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."), + (unsigned long) k, + (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC), + pa_strnull(dn)); + pa_xfree(dn); } PA_ONCE_END; return n; } +int pa_alsa_safe_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delay, size_t hwbuf_size, const pa_sample_spec *ss) { + ssize_t k; + size_t abs_k; + int r; + + pa_assert(pcm); + pa_assert(delay); + pa_assert(hwbuf_size > 0); + pa_assert(ss); + + /* Some ALSA driver expose weird bugs, let's inform the user about + * what is going on */ + + if ((r = snd_pcm_delay(pcm, delay)) < 0) + return r; + + k = (ssize_t) *delay * (ssize_t) pa_frame_size(ss); + + abs_k = k >= 0 ? (size_t) k : (size_t) -k; + + if (abs_k >= hwbuf_size * 3 || + abs_k >= pa_bytes_per_second(ss)*10) + + PA_ONCE_BEGIN { + char *dn = pa_alsa_get_driver_name_by_pcm(pcm); + pa_log(_("snd_pcm_delay() returned a value that is exceptionally large: %li bytes (%s%lu ms).\n" + "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."), + (signed long) k, + k < 0 ? "-" : "", + (unsigned long) (pa_bytes_to_usec(abs_k, ss) / PA_USEC_PER_MSEC), + pa_strnull(dn)); + pa_xfree(dn); + } PA_ONCE_END; + + return 0; +} + int pa_alsa_safe_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames, size_t hwbuf_size, const pa_sample_spec *ss) { int r; snd_pcm_uframes_t before; @@ -1612,9 +1653,13 @@ int pa_alsa_safe_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas k >= pa_bytes_per_second(ss)*10) PA_ONCE_BEGIN { - pa_log(_("snd_pcm_mmap_begin() returned a value that is exceptionally large: %lu bytes (%lu ms). " - "Most likely this is an ALSA driver bug. Please report this issue to the ALSA developers."), - (unsigned long) k, (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC)); + char *dn = pa_alsa_get_driver_name_by_pcm(pcm); + pa_log(_("snd_pcm_mmap_begin() returned a value that is exceptionally large: %lu bytes (%lu ms).\n" + "Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."), + (unsigned long) k, + (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC), + pa_strnull(dn)); + pa_xfree(dn); } PA_ONCE_END; return r; @@ -1637,3 +1682,18 @@ char *pa_alsa_get_driver_name(int card) { return n; } + +char *pa_alsa_get_driver_name_by_pcm(snd_pcm_t *pcm) { + int card; + + snd_pcm_info_t* info; + snd_pcm_info_alloca(&info); + + if (snd_pcm_info(pcm, info) < 0) + return NULL; + + if ((card = snd_pcm_info_get_card(info)) < 0) + return NULL; + + return pa_alsa_get_driver_name(card); +} diff --git a/src/modules/alsa/alsa-util.h b/src/modules/alsa/alsa-util.h index 2d0f407e..eddc41b8 100644 --- a/src/modules/alsa/alsa-util.h +++ b/src/modules/alsa/alsa-util.h @@ -129,8 +129,11 @@ int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents); pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll); snd_pcm_sframes_t pa_alsa_safe_avail(snd_pcm_t *pcm, size_t hwbuf_size, const pa_sample_spec *ss); +int pa_alsa_safe_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delay, size_t hwbuf_size, const pa_sample_spec *ss); int pa_alsa_safe_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames, size_t hwbuf_size, const pa_sample_spec *ss); char *pa_alsa_get_driver_name(int card); +char *pa_alsa_get_driver_name_by_pcm(snd_pcm_t *pcm); + #endif |