aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Gregan <[email protected]>2012-07-31 15:40:00 +1200
committerMatthew Gregan <[email protected]>2012-07-31 15:40:00 +1200
commitbea7b0ac335f01352e4ccb4caa5f8984cb78c1fb (patch)
tree4770131a704564bb17a1ae2cf6e8f0a4bc8461a4
parent30f0f3120563efdda2c21af5da309430c97def31 (diff)
downloadcubeb-bea7b0ac335f01352e4ccb4caa5f8984cb78c1fb.tar.gz
cubeb-bea7b0ac335f01352e4ccb4caa5f8984cb78c1fb.zip
Revert "Revert "alsa: add a dirty hack to detect the PA plugin and round up the requested latency.""
Resurrect this workaround until a better one is available. This reverts commit 668fb554f6d6d4b48f28bca4a914f595ef038657.
-rw-r--r--src/cubeb_alsa.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/cubeb_alsa.c b/src/cubeb_alsa.c
index 84475c4..d7235b6 100644
--- a/src/cubeb_alsa.c
+++ b/src/cubeb_alsa.c
@@ -20,6 +20,8 @@
#define CUBEB_WATCHDOG_MS 10000
#define UNUSED __attribute__ ((__unused__))
+#define ALSA_PA_PLUGIN "ALSA <-> PulseAudio PCM I/O Plugin"
+
/* ALSA is not thread-safe. snd_pcm_t instances are individually protected
by the owning cubeb_stream's mutex. snd_pcm_t creation and destruction
is not thread-safe until ALSA 1.0.24 (see alsa-lib.git commit 91c9c8f1),
@@ -474,6 +476,24 @@ silent_error_handler(char const * file UNUSED, int line UNUSED, char const * fun
{
}
+static int
+pcm_uses_pulseaudio_plugin(snd_pcm_t * pcm)
+{
+ snd_output_t * out;
+ char * buf;
+ size_t bufsz;
+ int r;
+
+ snd_output_buffer_open(&out);
+ snd_pcm_dump(pcm, out);
+ bufsz = snd_output_buffer_string(out, &buf);
+ r = bufsz >= strlen(ALSA_PA_PLUGIN) &&
+ strncmp(buf, ALSA_PA_PLUGIN, strlen(ALSA_PA_PLUGIN)) == 0;
+ snd_output_close(out);
+
+ return r;
+}
+
int
cubeb_init(cubeb ** context, char const * context_name UNUSED)
{
@@ -627,6 +647,12 @@ cubeb_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name
r = snd_pcm_nonblock(stm->pcm, 1);
assert(r == 0);
+ /* Ugly hack: the PA ALSA plugin allows buffer configurations that can't
+ possibly work. See https://bugzilla.mozilla.org/show_bug.cgi?id=761274 */
+ if (pcm_uses_pulseaudio_plugin(stm->pcm)) {
+ latency = latency < 200 ? 200 : latency;
+ }
+
r = snd_pcm_set_params(stm->pcm, format, SND_PCM_ACCESS_RW_INTERLEAVED,
stm->params.channels, stm->params.rate, 1,
latency * 1000);