aboutsummaryrefslogtreecommitdiff
path: root/www/firefox-esr/files/patch-cubeb-sndio
blob: 974af005402b17ae3b06ae036c355aab262cd602 (plain) (blame)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
https://github.com/kinetiknz/cubeb/commit/a71f116501fe39962599c435ef65066f7e7ea9f5
https://github.com/kinetiknz/cubeb/commit/3025cbec70f3ed097ec9a2f33a4823316a29efc4
https://github.com/kinetiknz/cubeb/commit/bb2735fa2ff680fdc615edbb363b19ff4a759503
https://github.com/kinetiknz/cubeb/pull/564

diff --git a/src/cubeb_sndio.c b/src/cubeb_sndio.c
index 4a05bd84..34b3513d 100644
--- media/libcubeb/src/cubeb_sndio.c
+++ media/libcubeb/src/cubeb_sndio.c
@@ -32,6 +32,7 @@
   X(sio_eof)                                 \
   X(sio_getpar)                              \
   X(sio_initpar)                             \
+  X(sio_nfds)                                \
   X(sio_onmove)                              \
   X(sio_open)                                \
   X(sio_pollfd)                              \
@@ -124,6 +125,23 @@ s16_to_float(void *ptr, long nsamp)
     *(--dst) = (1. / 32768) * *(--src);
 }
 
+static const char *
+sndio_get_device()
+{
+#ifdef __linux__
+  /*
+   * On other platforms default to sndio devices,
+   * so cubebs other backends can be used instead.
+   */
+  const char *dev = getenv("AUDIODEVICE");
+  if (dev == NULL || *dev == '\0')
+	return "snd/0";
+  return dev;
+#else
+  return SIO_DEVANY;
+#endif
+}
+
 static void
 sndio_onmove(void *arg, int delta)
 {
@@ -135,18 +153,23 @@ sndio_onmove(void *arg, int delta)
 static void *
 sndio_mainloop(void *arg)
 {
-#define MAXFDS 8
-  struct pollfd pfds[MAXFDS];
+  struct pollfd *pfds;
   cubeb_stream *s = arg;
   int n, eof = 0, prime, nfds, events, revents, state = CUBEB_STATE_STARTED;
   size_t pstart = 0, pend = 0, rstart = 0, rend = 0;
   long nfr;
 
+  nfds = WRAP(sio_nfds)(s->hdl);
+  pfds = calloc(nfds, sizeof (struct pollfd));
+  if (pfds == NULL)
+	  return NULL;
+
   DPR("sndio_mainloop()\n");
   s->state_cb(s, s->arg, CUBEB_STATE_STARTED);
   pthread_mutex_lock(&s->mtx);
   if (!WRAP(sio_start)(s->hdl)) {
     pthread_mutex_unlock(&s->mtx);
+    free(pfds);
     return NULL;
   }
   DPR("sndio_mainloop(), started\n");
@@ -274,6 +297,7 @@ sndio_mainloop(void *arg)
   s->hwpos = s->swpos;
   pthread_mutex_unlock(&s->mtx);
   s->state_cb(s, s->arg, state);
+  free(pfds);
   return NULL;
 }
 
@@ -281,6 +305,9 @@ sndio_mainloop(void *arg)
 sndio_init(cubeb **context, char const *context_name)
 {
   void * libsndio = NULL;
+  struct sio_hdl *hdl;
+
+  assert(context);
 
 #ifndef DISABLE_LIBSNDIO_DLOPEN
   libsndio = dlopen("libsndio.so.7.0", RTLD_LAZY);
@@ -305,8 +332,17 @@ sndio_init(cubeb **context, char const *context_name)
 #undef LOAD
 #endif
 
+  /* test if sndio works */
+  hdl = WRAP(sio_open)(sndio_get_device(), SIO_PLAY, 1);
+  if (hdl == NULL) {
+    return CUBEB_ERROR;
+  }
+  WRAP(sio_close)(hdl);
+
   DPR("sndio_init(%s)\n", context_name);
-  *context = malloc(sizeof(*context));
+  *context = malloc(sizeof(**context));
+  if (*context == NULL)
+	return CUBEB_ERROR;
   (*context)->libsndio = libsndio;
   (*context)->ops = &sndio_ops;
   (void)context_name;
@@ -377,7 +413,7 @@ sndio_stream_init(cubeb * context,
     goto err;
   }
   s->context = context;
-  s->hdl = WRAP(sio_open)(NULL, s->mode, 1);
+  s->hdl = WRAP(sio_open)(sndio_get_device(), s->mode, 1);
   if (s->hdl == NULL) {
     DPR("sndio_stream_init(), sio_open() failed\n");
     goto err;