[pulseaudio-commits] r1566 - in /branches/lennart/src/modules: alsa-util.c alsa-util.h module-alsa-sink.c module-alsa-source.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Fri Aug 3 16:48:53 PDT 2007
Author: lennart
Date: Sat Aug 4 01:48:52 2007
New Revision: 1566
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1566&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Don't stop hardware on buffer underruns. Instead continue playing to guaran=
tee that our time function stays as linear as possible.
Modified:
branches/lennart/src/modules/alsa-util.c
branches/lennart/src/modules/alsa-util.h
branches/lennart/src/modules/module-alsa-sink.c
branches/lennart/src/modules/module-alsa-source.c
Modified: branches/lennart/src/modules/alsa-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/al=
sa-util.c?rev=3D1566&root=3Dpulseaudio&r1=3D1565&r2=3D1566&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/alsa-util.c (original)
+++ branches/lennart/src/modules/alsa-util.c Sat Aug 4 01:48:52 2007
@@ -289,10 +289,11 @@
pa_assert(periods);
pa_assert(period_size);
=
+ snd_pcm_hw_params_alloca(&hwparams);
+ =
buffer_size =3D *periods * *period_size;
=
- if ((ret =3D snd_pcm_hw_params_malloc(&hwparams)) < 0 ||
- (ret =3D snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0 ||
+ if ((ret =3D snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0 ||
(ret =3D snd_pcm_hw_params_set_rate_resample(pcm_handle, hwparams,=
0)) < 0)
goto finish;
=
@@ -355,10 +356,34 @@
ret =3D 0;
=
finish:
- if (hwparams)
- snd_pcm_hw_params_free(hwparams);
=
return ret;
+}
+
+int pa_alsa_set_sw_params(snd_pcm_t *pcm) {
+ snd_pcm_sw_params_t *swparams;
+ int err;
+ =
+ pa_assert(pcm);
+
+ snd_pcm_sw_params_alloca(&swparams);
+
+ if ((err =3D snd_pcm_sw_params_current(pcm, swparams) < 0)) {
+ pa_log_warn("Unable to determine current swparams: %s\n", snd_stre=
rror(err));
+ return err;
+ }
+
+ if ((err =3D snd_pcm_sw_params_set_stop_threshold(pcm, swparams, (snd_=
pcm_uframes_t) -1)) < 0) {
+ pa_log_warn("Unable to set stop threshold: %s\n", snd_strerror(err=
));
+ return err;
+ }
+ =
+ if ((err =3D snd_pcm_sw_params(pcm, swparams)) < 0) {
+ pa_log_warn("Unable to set sw params: %s\n", snd_strerror(err));
+ return err;
+ }
+
+ return 0;
}
=
int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev) {
Modified: branches/lennart/src/modules/alsa-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/al=
sa-util.h?rev=3D1566&root=3Dpulseaudio&r1=3D1565&r2=3D1566&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/alsa-util.h (original)
+++ branches/lennart/src/modules/alsa-util.h Sat Aug 4 01:48:52 2007
@@ -39,6 +39,7 @@
int pa_alsa_fdlist_set_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixe=
r_handle, pa_mainloop_api* m);
=
int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, pa_sample_spec *ss, uint3=
2_t *periods, snd_pcm_uframes_t *period_size, int *use_mmap);
+int pa_alsa_set_sw_params(snd_pcm_t *pcm);
=
int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev);
snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name, =
const char *fallback);
Modified: branches/lennart/src/modules/module-alsa-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/mo=
dule-alsa-sink.c?rev=3D1566&root=3Dpulseaudio&r1=3D1565&r2=3D1566&view=3Ddi=
ff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/module-alsa-sink.c (original)
+++ branches/lennart/src/modules/module-alsa-sink.c Sat Aug 4 01:48:52 2007
@@ -545,18 +545,23 @@
goto fail;
=
} else {
- ssize_t l;
-
- if ((err =3D snd_pcm_status(u->pcm_handle, status)) >=3D 0)
- l =3D snd_pcm_status_get_avail(status) * u->frame_size;
- else
- l =3D u->fragment_size;
-
- while (l > 0) {
+ for (;;) {
void *p;
snd_pcm_sframes_t t;
-
- pa_assert(l > 0);
+ ssize_t l;
+ =
+ if ((err =3D snd_pcm_status(u->pcm_handle, status)) < =
0) {
+ pa_log("Failed to query DSP status data: %s", snd_=
strerror(t));
+ goto fail;
+ }
+
+ if (snd_pcm_status_get_avail_max(status)*u->frame_size=
>=3D u->hwbuf_size)
+ pa_log_debug("Buffer underrun!");
+ =
+ l =3D snd_pcm_status_get_avail(status) * u->frame_size;
+
+ if (l <=3D 0)
+ break;
=
if (u->memchunk.length <=3D 0)
pa_sink_render(u->sink, l, &u->memchunk);
@@ -573,10 +578,7 @@
=
if (t < 0) {
=
- if (t =3D=3D -EPIPE) {
- pa_log_debug("Buffer underrun!");
- u->first =3D 1;
- }
+ pa_assert(t !=3D -EPIPE);
=
if ((t =3D snd_pcm_recover(u->pcm_handle, t, 1)) =
=3D=3D 0)
continue;
@@ -588,21 +590,20 @@
pa_log("Failed to write data to DSP: %s", snd_=
strerror(t));
goto fail;
}
+ }
=
- } else {
- =
- u->memchunk.index +=3D t * u->frame_size;
- u->memchunk.length -=3D t * u->frame_size;
- =
- if (u->memchunk.length <=3D 0) {
- pa_memblock_unref(u->memchunk.memblock);
- pa_memchunk_reset(&u->memchunk);
- }
- =
- l -=3D t * u->frame_size;
-
- work_done =3D 1;
+ u->memchunk.index +=3D t * u->frame_size;
+ u->memchunk.length -=3D t * u->frame_size;
+ =
+ if (u->memchunk.length <=3D 0) {
+ pa_memblock_unref(u->memchunk.memblock);
+ pa_memchunk_reset(&u->memchunk);
}
+
+ work_done =3D 1;
+
+ if (t * u->frame_size >=3D (unsigned) l)
+ break;
} =
}
=
@@ -756,6 +757,11 @@
if (u->use_mmap)
pa_log_info("Successfully enabled mmap() mode.");
=
+ if ((err =3D 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 =3D pa_frame_size(&ss);
=
Modified: branches/lennart/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/mo=
dule-alsa-source.c?rev=3D1566&root=3Dpulseaudio&r1=3D1565&r2=3D1566&view=3D=
diff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/modules/module-alsa-source.c (original)
+++ branches/lennart/src/modules/module-alsa-source.c Sat Aug 4 01:48:52 2=
007
@@ -533,19 +533,25 @@
goto fail;
=
} else {
- ssize_t l;
-
- if ((err =3D snd_pcm_status(u->pcm_handle, status)) >=3D 0)
- l =3D snd_pcm_status_get_avail(status) * u->frame_size;
- else
- l =3D u->fragment_size;
-
- while (l > 0) {
+
+ for (;;) {
void *p;
snd_pcm_sframes_t t;
-
- pa_assert(l > 0);
-
+ ssize_t l;
+
+ if ((err =3D snd_pcm_status(u->pcm_handle, status)) < =
0) {
+ pa_log("Failed to query DSP status data: %s", snd_=
strerror(t));
+ goto fail;
+ }
+
+ if (snd_pcm_status_get_avail_max(status)*u->frame_size=
>=3D u->hwbuf_size)
+ pa_log_debug("Buffer overrun!");
+ =
+ l =3D snd_pcm_status_get_avail(status) * u->frame_size;
+
+ if (l <=3D 0)
+ break;
+ =
chunk.memblock =3D pa_memblock_new(u->core->mempool, l=
);
=
p =3D pa_memblock_acquire(chunk.memblock);
@@ -559,8 +565,7 @@
if (t < 0) {
pa_memblock_unref(chunk.memblock);
=
- if (t =3D=3D -EPIPE)
- pa_log_debug("Buffer underrun!");
+ pa_assert(t !=3D -EPIPE);
=
if ((t =3D snd_pcm_recover(u->pcm_handle, t, 1)) =
=3D=3D 0)
continue;
@@ -573,18 +578,18 @@
goto fail;
}
=
- } else {
+ } =
=
- chunk.index =3D 0;
- chunk.length =3D t * u->frame_size;
-
- pa_source_post(u->source, &chunk);
- pa_memblock_unref(chunk.memblock);
- =
- l -=3D t * u->frame_size;
-
- work_done =3D 1;
- }
+ chunk.index =3D 0;
+ chunk.length =3D t * u->frame_size;
+
+ pa_source_post(u->source, &chunk);
+ pa_memblock_unref(chunk.memblock);
+ =
+ work_done =3D 1;
+
+ if (t * u->frame_size >=3D (unsigned) l)
+ break;
} =
}
=
@@ -730,6 +735,11 @@
=
if (u->use_mmap)
pa_log_info("Successfully enabled mmap() mode.");
+
+ if ((err =3D 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 =3D pa_frame_size(&ss);
More information about the pulseaudio-commits
mailing list