tags 676167 + patch
thanks

It'd be interesting to know which driver causes the segfault on platforms without ALSA support; it might be alsa there too, or one of the following.

Apparently it is the oss format itself, which passes NULL to fileno().

I've attached a patch to replace the 01_default_audio_driver_fallback.patch file introduced in 14.4.0-3. It restricts using the new try_device() to pulseaudio, where it seems to work well and solves the original problem (bug #664301). It's not ideal of course, as users of OSS still have to manually uninstall libsox-fmt-alsa or set AUDIODRIVER.

Pascal, would you consider replacing the original patch with this one?

Ulrich
--- src/sox.c.old	2012-08-24 08:42:17.840058210 +0200
+++ src/sox.c	2012-08-24 08:41:59.495637788 +0200
@@ -2542,12 +2542,31 @@
   return name? from_env? from_env : name : NULL;
 }
 
+static char const * try_device(char const * name)
+{
+  sox_format_handler_t const * handler = sox_find_format(name, sox_false);
+  if (handler) {
+    sox_format_t format, * ft = &format;
+    lsx_debug("Looking for a default device: trying format `%s'", name);
+    memset(ft, 0, sizeof(*ft));
+    ft->filename = (char *)device_name(name);
+    ft->priv = lsx_calloc(1, handler->priv_size);
+    if (handler->startwrite(ft) == SOX_SUCCESS) {
+      handler->stopwrite(ft);
+      free(ft->priv);
+      return name;
+    }
+    free(ft->priv);
+  }
+  return NULL;
+}
+
 static char const * set_default_device(file_t * f)
 {
   /* Default audio driver type in order of preference: */
   if (!f->filetype) f->filetype = getenv("AUDIODRIVER");
   if (!f->filetype && sox_find_format("coreaudio", sox_false)) f->filetype = "coreaudio";
-  if (!f->filetype && sox_find_format("pulseaudio" , sox_false)) f->filetype = "pulseaudio";
+  if (!f->filetype) f->filetype = try_device("pulseaudio");
   if (!f->filetype && sox_find_format("alsa", sox_false)) f->filetype = "alsa";
   if (!f->filetype && sox_find_format("waveaudio" , sox_false)) f->filetype = "waveaudio";
   if (!f->filetype && sox_find_format("sndio", sox_false)) f->filetype = "sndio";

Reply via email to