From: Lennart Poettering <lennart@poettering.net>
Date: Sun, 19 Apr 2009 17:22:51 +0000 (+0200)
Subject: alsa: properly convert return values of snd_strerror() to utf8
X-Git-Url: http://git.0pointer.de/?p=pulseaudio.git;a=commitdiff_plain;h=98a25c506e692ab091b4af7e1b37e8432fc08e8f

alsa: properly convert return values of snd_strerror() to utf8
---

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 2fbcd7b..41e8b47 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -281,7 +281,7 @@ static int try_recover(struct userdata *u, const char *call, int err) {
     pa_assert(call);
     pa_assert(err < 0);
 
-    pa_log_debug("%s: %s", call, snd_strerror(err));
+    pa_log_debug("%s: %s", call, pa_alsa_strerror(err));
 
     pa_assert(err != -EAGAIN);
 
@@ -289,7 +289,7 @@ static int try_recover(struct userdata *u, const char *call, int err) {
         pa_log_debug("%s: Buffer underrun!", call);
 
     if ((err = snd_pcm_recover(u->pcm_handle, err, 1)) < 0) {
-        pa_log("%s: %s", call, snd_strerror(err));
+        pa_log("%s: %s", call, pa_alsa_strerror(err));
         return -1;
     }
 
@@ -636,12 +636,12 @@ static void update_smoother(struct userdata *u) {
     /* Let's update the time smoother */
 
     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));
+        pa_log_warn("Failed to query DSP status data: %s", pa_alsa_strerror(err));
         return;
     }
 
     if (PA_UNLIKELY((err = snd_pcm_status(u->pcm_handle, status)) < 0))
-        pa_log_warn("Failed to get timestamp: %s", snd_strerror(err));
+        pa_log_warn("Failed to get timestamp: %s", pa_alsa_strerror(err));
     else {
         snd_htimestamp_t htstamp = { 0, 0 };
         snd_pcm_status_get_htstamp(status, &htstamp);
@@ -764,7 +764,7 @@ static int update_sw_params(struct userdata *u) {
     pa_log_debug("setting avail_min=%lu", (unsigned long) avail_min);
 
     if ((err = pa_alsa_set_sw_params(u->pcm_handle, avail_min)) < 0) {
-        pa_log("Failed to set software parameters: %s", snd_strerror(err));
+        pa_log("Failed to set software parameters: %s", pa_alsa_strerror(err));
         return err;
     }
 
@@ -792,7 +792,7 @@ static int unsuspend(struct userdata *u) {
                             SND_PCM_NO_AUTO_RESAMPLE|
                             SND_PCM_NO_AUTO_CHANNELS|
                             SND_PCM_NO_AUTO_FORMAT)) < 0) {
-        pa_log("Error opening PCM device %s: %s", u->device_name, snd_strerror(err));
+        pa_log("Error opening PCM device %s: %s", u->device_name, pa_alsa_strerror(err));
         goto fail;
     }
 
@@ -803,7 +803,7 @@ static int unsuspend(struct userdata *u) {
     d = u->use_tsched;
 
     if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &nfrags, &period_size, u->hwbuf_size / u->frame_size, &b, &d, TRUE)) < 0) {
-        pa_log("Failed to set hardware parameters: %s", snd_strerror(err));
+        pa_log("Failed to set hardware parameters: %s", pa_alsa_strerror(err));
         goto fail;
     }
 
@@ -1030,7 +1030,7 @@ static void sink_get_volume_cb(pa_sink *s) {
     return;
 
 fail:
-    pa_log_error("Unable to read volume: %s", snd_strerror(err));
+    pa_log_error("Unable to read volume: %s", pa_alsa_strerror(err));
 }
 
 static void sink_set_volume_cb(pa_sink *s) {
@@ -1141,7 +1141,7 @@ static void sink_set_volume_cb(pa_sink *s) {
     return;
 
 fail:
-    pa_log_error("Unable to set volume: %s", snd_strerror(err));
+    pa_log_error("Unable to set volume: %s", pa_alsa_strerror(err));
 }
 
 static void sink_get_mute_cb(pa_sink *s) {
@@ -1152,7 +1152,7 @@ static void sink_get_mute_cb(pa_sink *s) {
     pa_assert(u->mixer_elem);
 
     if ((err = snd_mixer_selem_get_playback_switch(u->mixer_elem, 0, &sw)) < 0) {
-        pa_log_error("Unable to get switch: %s", snd_strerror(err));
+        pa_log_error("Unable to get switch: %s", pa_alsa_strerror(err));
         return;
     }
 
@@ -1167,7 +1167,7 @@ static void sink_set_mute_cb(pa_sink *s) {
     pa_assert(u->mixer_elem);
 
     if ((err = snd_mixer_selem_set_playback_switch_all(u->mixer_elem, !s->muted)) < 0) {
-        pa_log_error("Unable to set switch: %s", snd_strerror(err));
+        pa_log_error("Unable to set switch: %s", pa_alsa_strerror(err));
         return;
     }
 }
@@ -1206,7 +1206,7 @@ static int process_rewind(struct userdata *u) {
     pa_log_debug("Requested to rewind %lu bytes.", (unsigned long) rewind_nbytes);
 
     if (PA_UNLIKELY((unused = pa_alsa_safe_avail(u->pcm_handle, u->hwbuf_size, &u->sink->sample_spec)) < 0)) {
-        pa_log("snd_pcm_avail() failed: %s", snd_strerror((int) unused));
+        pa_log("snd_pcm_avail() failed: %s", pa_alsa_strerror((int) unused));
         return -1;
     }
 
@@ -1228,7 +1228,7 @@ static int process_rewind(struct userdata *u) {
         in_frames = (snd_pcm_sframes_t) (rewind_nbytes / u->frame_size);
         pa_log_debug("before: %lu", (unsigned long) in_frames);
         if ((out_frames = snd_pcm_rewind(u->pcm_handle, (snd_pcm_uframes_t) in_frames)) < 0) {
-            pa_log("snd_pcm_rewind() failed: %s", snd_strerror((int) out_frames));
+            pa_log("snd_pcm_rewind() failed: %s", pa_alsa_strerror((int) out_frames));
             return -1;
         }
         pa_log_debug("after: %lu", (unsigned long) out_frames);
@@ -1359,7 +1359,7 @@ static void thread_func(void *userdata) {
             pollfd = pa_rtpoll_item_get_pollfd(u->alsa_rtpoll_item, &n);
 
             if ((err = snd_pcm_poll_descriptors_revents(u->pcm_handle, pollfd, n, &revents)) < 0) {
-                pa_log("snd_pcm_poll_descriptors_revents() failed: %s", snd_strerror(err));
+                pa_log("snd_pcm_poll_descriptors_revents() failed: %s", pa_alsa_strerror(err));
                 goto fail;
             }
 
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index c59fc75..843f70b 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -278,7 +278,7 @@ static int try_recover(struct userdata *u, const char *call, int err) {
     pa_assert(call);
     pa_assert(err < 0);
 
-    pa_log_debug("%s: %s", call, snd_strerror(err));
+    pa_log_debug("%s: %s", call, pa_alsa_strerror(err));
 
     pa_assert(err != -EAGAIN);
 
@@ -286,7 +286,7 @@ static int try_recover(struct userdata *u, const char *call, int err) {
         pa_log_debug("%s: Buffer overrun!", call);
 
     if ((err = snd_pcm_recover(u->pcm_handle, err, 1)) < 0) {
-        pa_log("%s: %s", call, snd_strerror(err));
+        pa_log("%s: %s", call, pa_alsa_strerror(err));
         return -1;
     }
 
@@ -606,12 +606,12 @@ static void update_smoother(struct userdata *u) {
     /* Let's update the time smoother */
 
     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));
+        pa_log_warn("Failed to get delay: %s", pa_alsa_strerror(err));
         return;
     }
 
     if (PA_UNLIKELY((err = snd_pcm_status(u->pcm_handle, status)) < 0))
-        pa_log_warn("Failed to get timestamp: %s", snd_strerror(err));
+        pa_log_warn("Failed to get timestamp: %s", pa_alsa_strerror(err));
     else {
         snd_htimestamp_t htstamp = { 0, 0 };
         snd_pcm_status_get_htstamp(status, &htstamp);
@@ -721,7 +721,7 @@ static int update_sw_params(struct userdata *u) {
     pa_log_debug("setting avail_min=%lu", (unsigned long) avail_min);
 
     if ((err = pa_alsa_set_sw_params(u->pcm_handle, avail_min)) < 0) {
-        pa_log("Failed to set software parameters: %s", snd_strerror(err));
+        pa_log("Failed to set software parameters: %s", pa_alsa_strerror(err));
         return err;
     }
 
@@ -747,7 +747,7 @@ static int unsuspend(struct userdata *u) {
                             SND_PCM_NO_AUTO_RESAMPLE|
                             SND_PCM_NO_AUTO_CHANNELS|
                             SND_PCM_NO_AUTO_FORMAT)) < 0) {
-        pa_log("Error opening PCM device %s: %s", u->device_name, snd_strerror(err));
+        pa_log("Error opening PCM device %s: %s", u->device_name, pa_alsa_strerror(err));
         goto fail;
     }
 
@@ -758,7 +758,7 @@ static int unsuspend(struct userdata *u) {
     d = u->use_tsched;
 
     if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &nfrags, &period_size, u->hwbuf_size / u->frame_size, &b, &d, TRUE)) < 0) {
-        pa_log("Failed to set hardware parameters: %s", snd_strerror(err));
+        pa_log("Failed to set hardware parameters: %s", pa_alsa_strerror(err));
         goto fail;
     }
 
@@ -988,7 +988,7 @@ static void source_get_volume_cb(pa_source *s) {
     return;
 
 fail:
-    pa_log_error("Unable to read volume: %s", snd_strerror(err));
+    pa_log_error("Unable to read volume: %s", pa_alsa_strerror(err));
 }
 
 static void source_set_volume_cb(pa_source *s) {
@@ -1100,7 +1100,7 @@ static void source_set_volume_cb(pa_source *s) {
     return;
 
 fail:
-    pa_log_error("Unable to set volume: %s", snd_strerror(err));
+    pa_log_error("Unable to set volume: %s", pa_alsa_strerror(err));
 }
 
 static void source_get_mute_cb(pa_source *s) {
@@ -1111,7 +1111,7 @@ static void source_get_mute_cb(pa_source *s) {
     pa_assert(u->mixer_elem);
 
     if ((err = snd_mixer_selem_get_capture_switch(u->mixer_elem, 0, &sw)) < 0) {
-        pa_log_error("Unable to get switch: %s", snd_strerror(err));
+        pa_log_error("Unable to get switch: %s", pa_alsa_strerror(err));
         return;
     }
 
@@ -1126,7 +1126,7 @@ static void source_set_mute_cb(pa_source *s) {
     pa_assert(u->mixer_elem);
 
     if ((err = snd_mixer_selem_set_capture_switch_all(u->mixer_elem, !s->muted)) < 0) {
-        pa_log_error("Unable to set switch: %s", snd_strerror(err));
+        pa_log_error("Unable to set switch: %s", pa_alsa_strerror(err));
         return;
     }
 }
@@ -1218,7 +1218,7 @@ static void thread_func(void *userdata) {
             pollfd = pa_rtpoll_item_get_pollfd(u->alsa_rtpoll_item, &n);
 
             if ((err = snd_pcm_poll_descriptors_revents(u->pcm_handle, pollfd, n, &revents)) < 0) {
-                pa_log("snd_pcm_poll_descriptors_revents() failed: %s", snd_strerror(err));
+                pa_log("snd_pcm_poll_descriptors_revents() failed: %s", pa_alsa_strerror(err));
                 goto fail;
             }
 
diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index d2dc6e8..ddc3c77 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -33,6 +33,7 @@
 #include <pulse/timeval.h>
 #include <pulse/util.h>
 #include <pulse/i18n.h>
+#include <pulse/utf8.h>
 
 #include <pulsecore/log.h>
 #include <pulsecore/macro.h>
@@ -40,6 +41,7 @@
 #include <pulsecore/atomic.h>
 #include <pulsecore/core-error.h>
 #include <pulsecore/once.h>
+#include <pulsecore/thread.h>
 
 #include "alsa-util.h"
 
@@ -106,7 +108,7 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t
     pa_assert(i != fdl->num_fds);
 
     if ((err = snd_mixer_poll_descriptors_revents(fdl->mixer, fdl->work_fds, fdl->num_fds, &revents)) < 0) {
-        pa_log_error("Unable to get poll revent: %s", snd_strerror(err));
+        pa_log_error("Unable to get poll revent: %s", pa_alsa_strerror(err));
         return;
     }
 
@@ -129,7 +131,7 @@ static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) {
     a->defer_enable(fdl->defer, 0);
 
     if ((n = snd_mixer_poll_descriptors_count(fdl->mixer)) < 0) {
-        pa_log("snd_mixer_poll_descriptors_count() failed: %s", snd_strerror(n));
+        pa_log("snd_mixer_poll_descriptors_count() failed: %s", pa_alsa_strerror(n));
         return;
     }
     num_fds = (unsigned) n;
@@ -146,7 +148,7 @@ static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) {
     memset(fdl->work_fds, 0, sizeof(struct pollfd) * num_fds);
 
     if ((err = snd_mixer_poll_descriptors(fdl->mixer, fdl->work_fds, num_fds)) < 0) {
-        pa_log_error("Unable to get poll descriptors: %s", snd_strerror(err));
+        pa_log_error("Unable to get poll descriptors: %s", pa_alsa_strerror(err));
         return;
     }
 
@@ -482,42 +484,42 @@ int pa_alsa_set_sw_params(snd_pcm_t *pcm, snd_pcm_uframes_t avail_min) {
     snd_pcm_sw_params_alloca(&swparams);
 
     if ((err = snd_pcm_sw_params_current(pcm, swparams) < 0)) {
-        pa_log_warn("Unable to determine current swparams: %s\n", snd_strerror(err));
+        pa_log_warn("Unable to determine current swparams: %s\n", pa_alsa_strerror(err));
         return err;
     }
 
     if ((err = snd_pcm_sw_params_set_period_event(pcm, swparams, 0)) < 0) {
-        pa_log_warn("Unable to disable period event: %s\n", snd_strerror(err));
+        pa_log_warn("Unable to disable period event: %s\n", pa_alsa_strerror(err));
         return err;
     }
 
     if ((err = snd_pcm_sw_params_set_tstamp_mode(pcm, swparams, SND_PCM_TSTAMP_ENABLE)) < 0) {
-        pa_log_warn("Unable to enable time stamping: %s\n", snd_strerror(err));
+        pa_log_warn("Unable to enable time stamping: %s\n", pa_alsa_strerror(err));
         return err;
     }
 
     if ((err = snd_pcm_sw_params_get_boundary(swparams, &boundary)) < 0) {
-        pa_log_warn("Unable to get boundary: %s\n", snd_strerror(err));
+        pa_log_warn("Unable to get boundary: %s\n", pa_alsa_strerror(err));
         return err;
     }
 
     if ((err = snd_pcm_sw_params_set_stop_threshold(pcm, swparams, boundary)) < 0) {
-        pa_log_warn("Unable to set stop threshold: %s\n", snd_strerror(err));
+        pa_log_warn("Unable to set stop threshold: %s\n", pa_alsa_strerror(err));
         return err;
     }
 
     if ((err = snd_pcm_sw_params_set_start_threshold(pcm, swparams, (snd_pcm_uframes_t) -1)) < 0) {
-        pa_log_warn("Unable to set start threshold: %s\n", snd_strerror(err));
+        pa_log_warn("Unable to set start threshold: %s\n", pa_alsa_strerror(err));
         return err;
     }
 
     if ((err = snd_pcm_sw_params_set_avail_min(pcm, swparams, avail_min)) < 0) {
-        pa_log_error("snd_pcm_sw_params_set_avail_min() failed: %s", snd_strerror(err));
+        pa_log_error("snd_pcm_sw_params_set_avail_min() failed: %s", pa_alsa_strerror(err));
         return err;
     }
 
     if ((err = snd_pcm_sw_params(pcm, swparams)) < 0) {
-        pa_log_warn("Unable to set sw params: %s\n", snd_strerror(err));
+        pa_log_warn("Unable to set sw params: %s\n", pa_alsa_strerror(err));
         return err;
     }
 
@@ -854,7 +856,7 @@ snd_pcm_t *pa_alsa_open_by_device_string(
                                 SND_PCM_NO_AUTO_RESAMPLE|
                                 SND_PCM_NO_AUTO_CHANNELS|
                                 (reformat ? 0 : SND_PCM_NO_AUTO_FORMAT))) < 0) {
-            pa_log_info("Error opening PCM device %s: %s", d, snd_strerror(err));
+            pa_log_info("Error opening PCM device %s: %s", d, pa_alsa_strerror(err));
             goto fail;
         }
 
@@ -882,7 +884,7 @@ snd_pcm_t *pa_alsa_open_by_device_string(
                 continue;
             }
 
-            pa_log_info("Failed to set hardware parameters on %s: %s", d, snd_strerror(err));
+            pa_log_info("Failed to set hardware parameters on %s: %s", d, pa_alsa_strerror(err));
             snd_pcm_close(pcm_handle);
 
             goto fail;
@@ -1000,17 +1002,17 @@ int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev) {
     pa_assert(dev);
 
     if ((err = snd_mixer_attach(mixer, dev)) < 0) {
-        pa_log_info("Unable to attach to mixer %s: %s", dev, snd_strerror(err));
+        pa_log_info("Unable to attach to mixer %s: %s", dev, pa_alsa_strerror(err));
         return -1;
     }
 
     if ((err = snd_mixer_selem_register(mixer, NULL, NULL)) < 0) {
-        pa_log_warn("Unable to register mixer: %s", snd_strerror(err));
+        pa_log_warn("Unable to register mixer: %s", pa_alsa_strerror(err));
         return -1;
     }
 
     if ((err = snd_mixer_load(mixer)) < 0) {
-        pa_log_warn("Unable to load mixer: %s", snd_strerror(err));
+        pa_log_warn("Unable to load mixer: %s", pa_alsa_strerror(err));
         return -1;
     }
 
@@ -1136,7 +1138,7 @@ int pa_alsa_find_mixer_and_elem(
     }
 
     if ((err = snd_mixer_open(&m, 0)) < 0) {
-        pa_log("Error opening mixer: %s", snd_strerror(err));
+        pa_log("Error opening mixer: %s", pa_alsa_strerror(err));
         return -1;
     }
 
@@ -1338,7 +1340,7 @@ void pa_alsa_dump(pa_log_level_t level, snd_pcm_t *pcm) {
     pa_assert_se(snd_output_buffer_open(&out) == 0);
 
     if ((err = snd_pcm_dump(pcm, out)) < 0)
-        pa_logl(level, "snd_pcm_dump(): %s", snd_strerror(err));
+        pa_logl(level, "snd_pcm_dump(): %s", pa_alsa_strerror(err));
     else {
         char *s = NULL;
         snd_output_buffer_string(out, &s);
@@ -1362,7 +1364,7 @@ void pa_alsa_dump_status(snd_pcm_t *pcm) {
     pa_assert_se(snd_pcm_status(pcm, status) == 0);
 
     if ((err = snd_pcm_status_dump(status, out)) < 0)
-        pa_log_debug("snd_pcm_dump(): %s", snd_strerror(err));
+        pa_log_debug("snd_pcm_dump(): %s", pa_alsa_strerror(err));
     else {
         char *s = NULL;
         snd_output_buffer_string(out, &s);
@@ -1524,7 +1526,7 @@ void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm, snd_m
     snd_pcm_info_alloca(&info);
 
     if ((err = snd_pcm_hw_params_current(pcm, hwparams)) < 0)
-        pa_log_warn("Error fetching hardware parameter info: %s", snd_strerror(err));
+        pa_log_warn("Error fetching hardware parameter info: %s", pa_alsa_strerror(err));
     else {
 
         if ((bits = snd_pcm_hw_params_get_sbits(hwparams)) >= 0)
@@ -1535,7 +1537,7 @@ void pa_alsa_init_proplist_pcm(pa_core *c, pa_proplist *p, snd_pcm_t *pcm, snd_m
         pa_proplist_sets(p, "alsa.mixer_element", snd_mixer_selem_get_name(elem));
 
     if ((err = snd_pcm_info(pcm, info)) < 0)
-        pa_log_warn("Error fetching PCM info: %s", snd_strerror(err));
+        pa_log_warn("Error fetching PCM info: %s", pa_alsa_strerror(err));
     else
         pa_alsa_init_proplist_pcm_info(c, p, info);
 }
@@ -1568,14 +1570,14 @@ int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents) {
 
         case SND_PCM_STATE_XRUN:
             if ((err = snd_pcm_recover(pcm, -EPIPE, 1)) != 0) {
-                pa_log_warn("Could not recover from POLLERR|POLLNVAL|POLLHUP and XRUN: %s", snd_strerror(err));
+                pa_log_warn("Could not recover from POLLERR|POLLNVAL|POLLHUP and XRUN: %s", pa_alsa_strerror(err));
                 return -1;
             }
             break;
 
         case SND_PCM_STATE_SUSPENDED:
             if ((err = snd_pcm_recover(pcm, -ESTRPIPE, 1)) != 0) {
-                pa_log_warn("Could not recover from POLLERR|POLLNVAL|POLLHUP and SUSPENDED: %s", snd_strerror(err));
+                pa_log_warn("Could not recover from POLLERR|POLLNVAL|POLLHUP and SUSPENDED: %s", pa_alsa_strerror(err));
                 return -1;
             }
             break;
@@ -1585,7 +1587,7 @@ int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents) {
             snd_pcm_drop(pcm);
 
             if ((err = snd_pcm_prepare(pcm)) < 0) {
-                pa_log_warn("Could not recover from POLLERR|POLLNVAL|POLLHUP with snd_pcm_prepare(): %s", snd_strerror(err));
+                pa_log_warn("Could not recover from POLLERR|POLLNVAL|POLLHUP with snd_pcm_prepare(): %s", pa_alsa_strerror(err));
                 return -1;
             }
             break;
@@ -1602,7 +1604,7 @@ pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll) {
     pa_assert(pcm);
 
     if ((n = snd_pcm_poll_descriptors_count(pcm)) < 0) {
-        pa_log("snd_pcm_poll_descriptors_count() failed: %s", snd_strerror(n));
+        pa_log("snd_pcm_poll_descriptors_count() failed: %s", pa_alsa_strerror(n));
         return NULL;
     }
 
@@ -1610,7 +1612,7 @@ pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll) {
     pollfd = pa_rtpoll_item_get_pollfd(item, NULL);
 
     if ((err = snd_pcm_poll_descriptors(pcm, pollfd, (unsigned) n)) < 0) {
-        pa_log("snd_pcm_poll_descriptors() failed: %s", snd_strerror(err));
+        pa_log("snd_pcm_poll_descriptors() failed: %s", pa_alsa_strerror(err));
         pa_rtpoll_item_free(item);
         return NULL;
     }
@@ -1819,3 +1821,30 @@ pa_bool_t pa_alsa_pcm_is_modem(snd_pcm_t *pcm) {
 
     return snd_pcm_info_get_class(info) == SND_PCM_CLASS_MODEM;
 }
+
+PA_STATIC_TLS_DECLARE(cstrerror, pa_xfree);
+
+const char* pa_alsa_strerror(int errnum) {
+    const char *original = NULL;
+    char *translated, *t;
+    char errbuf[128];
+
+    if ((t = PA_STATIC_TLS_GET(cstrerror)))
+        pa_xfree(t);
+
+    original = snd_strerror(errnum);
+
+    if (!original) {
+        pa_snprintf(errbuf, sizeof(errbuf), "Unknown error %i", errnum);
+        original = errbuf;
+    }
+
+    if (!(translated = pa_locale_to_utf8(original))) {
+        pa_log_warn("Unable to convert error string to locale, filtering.");
+        translated = pa_utf8_filter(original);
+    }
+
+    PA_STATIC_TLS_SET(cstrerror, translated);
+
+    return translated;
+}
diff --git a/src/modules/alsa/alsa-util.h b/src/modules/alsa/alsa-util.h
index c8acc7c..77ac8a7 100644
--- a/src/modules/alsa/alsa-util.h
+++ b/src/modules/alsa/alsa-util.h
@@ -146,4 +146,6 @@ pa_bool_t pa_alsa_pcm_is_hw(snd_pcm_t *pcm);
 
 pa_bool_t pa_alsa_pcm_is_modem(snd_pcm_t *pcm);
 
+const char* pa_alsa_strerror(int errnum);
+
 #endif
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index fdc952d..51d466e 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -304,7 +304,7 @@ int pa__init(pa_module *m) {
     u->modargs = ma;
 
     if ((alsa_card_index = snd_card_get_index(u->device_id)) < 0) {
-        pa_log("Card '%s' doesn't exist: %s", u->device_id, snd_strerror(alsa_card_index));
+        pa_log("Card '%s' doesn't exist: %s", u->device_id, pa_alsa_strerror(alsa_card_index));
         goto fail;
     }
 
