summaryrefslogtreecommitdiff
path: root/testing/sox/sox_default_audio_driver_fallback.patch
blob: 9f9060e173a5b8f673c5a18ce8667c454c00214a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--- src/sox.c.old	2012-05-06 22:45:45.380564154 -0400
+++ src/sox.c	2012-05-06 22:47:11.948248987 -0400
@@ -2538,20 +2538,38 @@
   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;
+    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 && 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";
-  if (!f->filetype && sox_find_format("oss" , sox_false)) f->filetype = "oss";
-  if (!f->filetype && sox_find_format("sunau",sox_false)) f->filetype = "sunau";
-  if (!f->filetype && sox_find_format("ao"  , sox_false) && file_count) /*!rec*/
-    f->filetype = "ao";
-
+  if (!f->filetype) f->filetype = try_device("coreaudio");
+  if (!f->filetype) f->filetype = try_device("pulseaudio");
+  if (!f->filetype) f->filetype = try_device("alsa");
+  if (!f->filetype) f->filetype = try_device("waveaudio");
+  if (!f->filetype) f->filetype = try_device("sndio");
+  if (!f->filetype) f->filetype = try_device("oss");
+  if (!f->filetype) f->filetype = try_device("sunau");
+  if (!f->filetype && file_count) /*!rec*/
+    f->filetype = try_device("ao");
+ 
   if (!f->filetype) {
     lsx_fail("Sorry, there is no default audio device configured");
     exit(1);