summaryrefslogtreecommitdiffstats
path: root/src/modules/module-alsa-sink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/module-alsa-sink.c')
-rw-r--r--src/modules/module-alsa-sink.c58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c
index ced42ee3..5765d780 100644
--- a/src/modules/module-alsa-sink.c
+++ b/src/modules/module-alsa-sink.c
@@ -545,18 +545,23 @@ static void thread_func(void *userdata) {
goto fail;
} else {
- ssize_t l;
-
- if ((err = snd_pcm_status(u->pcm_handle, status)) >= 0)
- l = snd_pcm_status_get_avail(status) * u->frame_size;
- else
- l = u->fragment_size;
-
- while (l > 0) {
+ for (;;) {
void *p;
snd_pcm_sframes_t t;
+ ssize_t l;
+
+ if ((err = snd_pcm_status(u->pcm_handle, status)) < 0) {
+ pa_log("Failed to query DSP status data: %s", snd_strerror(t));
+ goto fail;
+ }
- pa_assert(l > 0);
+ if (snd_pcm_status_get_avail_max(status)*u->frame_size >= u->hwbuf_size)
+ pa_log_debug("Buffer underrun!");
+
+ l = snd_pcm_status_get_avail(status) * u->frame_size;
+
+ if (l <= 0)
+ break;
if (u->memchunk.length <= 0)
pa_sink_render(u->sink, l, &u->memchunk);
@@ -573,10 +578,7 @@ static void thread_func(void *userdata) {
if (t < 0) {
- if (t == -EPIPE) {
- pa_log_debug("Buffer underrun!");
- u->first = 1;
- }
+ pa_assert(t != -EPIPE);
if ((t = snd_pcm_recover(u->pcm_handle, t, 1)) == 0)
continue;
@@ -588,21 +590,20 @@ static void thread_func(void *userdata) {
pa_log("Failed to write data to DSP: %s", snd_strerror(t));
goto fail;
}
+ }
- } else {
-
- u->memchunk.index += t * u->frame_size;
- u->memchunk.length -= t * u->frame_size;
-
- if (u->memchunk.length <= 0) {
- pa_memblock_unref(u->memchunk.memblock);
- pa_memchunk_reset(&u->memchunk);
- }
-
- l -= t * u->frame_size;
-
- work_done = 1;
+ u->memchunk.index += t * u->frame_size;
+ u->memchunk.length -= t * u->frame_size;
+
+ if (u->memchunk.length <= 0) {
+ pa_memblock_unref(u->memchunk.memblock);
+ pa_memchunk_reset(&u->memchunk);
}
+
+ work_done = 1;
+
+ if (t * u->frame_size >= (unsigned) l)
+ break;
}
}
@@ -756,6 +757,11 @@ int pa__init(pa_core *c, pa_module*m) {
if (u->use_mmap)
pa_log_info("Successfully enabled mmap() mode.");
+ if ((err = pa_alsa_set_sw_params(u->pcm_handle)) < 0) {
+ pa_log("Failed to set software parameters: %s", snd_strerror(err));
+ goto fail;
+ }
+
/* ALSA might tweak the sample spec, so recalculate the frame size */
frame_size = pa_frame_size(&ss);