malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 1 | /* public domain */ |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 2 | |
Peter Maydell | 6086a56 | 2016-01-18 17:33:52 +0000 | [diff] [blame] | 3 | #include "qemu/osdep.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 4 | #include "qemu/module.h" |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 5 | #include "audio.h" |
Kővágó, Zoltán | 2c324b2 | 2019-03-08 23:34:21 +0100 | [diff] [blame] | 6 | #include "qapi/opts-visitor.h" |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 7 | |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 8 | #include <pulse/pulseaudio.h> |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 9 | |
| 10 | #define AUDIO_CAP "pulseaudio" |
| 11 | #include "audio_int.h" |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 12 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 13 | typedef struct PAConnection { |
| 14 | char *server; |
| 15 | int refcount; |
| 16 | QTAILQ_ENTRY(PAConnection) list; |
| 17 | |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 18 | pa_threaded_mainloop *mainloop; |
| 19 | pa_context *context; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 20 | } PAConnection; |
| 21 | |
| 22 | static QTAILQ_HEAD(PAConnectionHead, PAConnection) pa_conns = |
| 23 | QTAILQ_HEAD_INITIALIZER(pa_conns); |
| 24 | |
| 25 | typedef struct { |
| 26 | Audiodev *dev; |
| 27 | PAConnection *conn; |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 28 | } paaudio; |
| 29 | |
| 30 | typedef struct { |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 31 | HWVoiceOut hw; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 32 | pa_stream *stream; |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 33 | paaudio *g; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 34 | } PAVoiceOut; |
| 35 | |
| 36 | typedef struct { |
| 37 | HWVoiceIn hw; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 38 | pa_stream *stream; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 39 | const void *read_data; |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 40 | size_t read_length; |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 41 | paaudio *g; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 42 | } PAVoiceIn; |
| 43 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 44 | static void qpa_conn_fini(PAConnection *c); |
Kővágó, Zoltán | 49dd6d0 | 2015-06-03 23:03:53 +0200 | [diff] [blame] | 45 | |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 46 | static void GCC_FMT_ATTR (2, 3) qpa_logerr (int err, const char *fmt, ...) |
| 47 | { |
| 48 | va_list ap; |
| 49 | |
| 50 | va_start (ap, fmt); |
| 51 | AUD_vlog (AUDIO_CAP, fmt, ap); |
| 52 | va_end (ap); |
| 53 | |
| 54 | AUD_log (AUDIO_CAP, "Reason: %s\n", pa_strerror (err)); |
| 55 | } |
| 56 | |
Gerd Hoffmann | 8f473dd | 2012-05-03 22:41:28 +0200 | [diff] [blame] | 57 | #ifndef PA_CONTEXT_IS_GOOD |
| 58 | static inline int PA_CONTEXT_IS_GOOD(pa_context_state_t x) |
| 59 | { |
| 60 | return |
| 61 | x == PA_CONTEXT_CONNECTING || |
| 62 | x == PA_CONTEXT_AUTHORIZING || |
| 63 | x == PA_CONTEXT_SETTING_NAME || |
| 64 | x == PA_CONTEXT_READY; |
| 65 | } |
| 66 | #endif |
| 67 | |
| 68 | #ifndef PA_STREAM_IS_GOOD |
| 69 | static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x) |
| 70 | { |
| 71 | return |
| 72 | x == PA_STREAM_CREATING || |
| 73 | x == PA_STREAM_READY; |
| 74 | } |
| 75 | #endif |
| 76 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 77 | #define CHECK_SUCCESS_GOTO(c, expression, label, msg) \ |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 78 | do { \ |
| 79 | if (!(expression)) { \ |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 80 | qpa_logerr(pa_context_errno((c)->context), msg); \ |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 81 | goto label; \ |
| 82 | } \ |
Eric Blake | 2562755 | 2017-12-01 17:24:32 -0600 | [diff] [blame] | 83 | } while (0) |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 84 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 85 | #define CHECK_DEAD_GOTO(c, stream, label, msg) \ |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 86 | do { \ |
| 87 | if (!(c)->context || !PA_CONTEXT_IS_GOOD (pa_context_get_state((c)->context)) || \ |
| 88 | !(stream) || !PA_STREAM_IS_GOOD (pa_stream_get_state ((stream)))) { \ |
| 89 | if (((c)->context && pa_context_get_state ((c)->context) == PA_CONTEXT_FAILED) || \ |
| 90 | ((stream) && pa_stream_get_state ((stream)) == PA_STREAM_FAILED)) { \ |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 91 | qpa_logerr(pa_context_errno((c)->context), msg); \ |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 92 | } else { \ |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 93 | qpa_logerr(PA_ERR_BADSTATE, msg); \ |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 94 | } \ |
| 95 | goto label; \ |
| 96 | } \ |
Eric Blake | 2562755 | 2017-12-01 17:24:32 -0600 | [diff] [blame] | 97 | } while (0) |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 98 | |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 99 | static void *qpa_get_buffer_in(HWVoiceIn *hw, size_t *size) |
| 100 | { |
| 101 | PAVoiceIn *p = (PAVoiceIn *) hw; |
| 102 | PAConnection *c = p->g->conn; |
| 103 | int r; |
| 104 | |
| 105 | pa_threaded_mainloop_lock(c->mainloop); |
| 106 | |
| 107 | CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, |
| 108 | "pa_threaded_mainloop_lock failed\n"); |
| 109 | |
| 110 | if (!p->read_length) { |
| 111 | r = pa_stream_peek(p->stream, &p->read_data, &p->read_length); |
| 112 | CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, |
| 113 | "pa_stream_peek failed\n"); |
| 114 | } |
| 115 | |
| 116 | *size = MIN(p->read_length, *size); |
| 117 | |
| 118 | pa_threaded_mainloop_unlock(c->mainloop); |
| 119 | return (void *) p->read_data; |
| 120 | |
| 121 | unlock_and_fail: |
| 122 | pa_threaded_mainloop_unlock(c->mainloop); |
| 123 | *size = 0; |
| 124 | return NULL; |
| 125 | } |
| 126 | |
| 127 | static void qpa_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size) |
| 128 | { |
| 129 | PAVoiceIn *p = (PAVoiceIn *) hw; |
| 130 | PAConnection *c = p->g->conn; |
| 131 | int r; |
| 132 | |
| 133 | pa_threaded_mainloop_lock(c->mainloop); |
| 134 | |
| 135 | CHECK_DEAD_GOTO(c, p->stream, unlock, |
| 136 | "pa_threaded_mainloop_lock failed\n"); |
| 137 | |
| 138 | assert(buf == p->read_data && size <= p->read_length); |
| 139 | |
| 140 | p->read_data += size; |
| 141 | p->read_length -= size; |
| 142 | |
| 143 | if (size && !p->read_length) { |
| 144 | r = pa_stream_drop(p->stream); |
| 145 | CHECK_SUCCESS_GOTO(c, r == 0, unlock, "pa_stream_drop failed\n"); |
| 146 | } |
| 147 | |
| 148 | unlock: |
| 149 | pa_threaded_mainloop_unlock(c->mainloop); |
| 150 | } |
| 151 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 152 | static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length) |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 153 | { |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 154 | PAVoiceIn *p = (PAVoiceIn *) hw; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 155 | PAConnection *c = p->g->conn; |
Volker Rümelin | acc3b63 | 2020-01-04 10:11:21 +0100 | [diff] [blame] | 156 | size_t total = 0; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 157 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 158 | pa_threaded_mainloop_lock(c->mainloop); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 159 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 160 | CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, |
| 161 | "pa_threaded_mainloop_lock failed\n"); |
Volker Rümelin | 7c9eb86 | 2020-01-04 10:11:22 +0100 | [diff] [blame] | 162 | if (pa_stream_get_state(p->stream) != PA_STREAM_READY) { |
| 163 | /* wait for stream to become ready */ |
| 164 | goto unlock; |
| 165 | } |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 166 | |
Volker Rümelin | acc3b63 | 2020-01-04 10:11:21 +0100 | [diff] [blame] | 167 | while (total < length) { |
| 168 | size_t l; |
| 169 | int r; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 170 | |
Volker Rümelin | acc3b63 | 2020-01-04 10:11:21 +0100 | [diff] [blame] | 171 | if (!p->read_length) { |
| 172 | r = pa_stream_peek(p->stream, &p->read_data, &p->read_length); |
| 173 | CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, |
| 174 | "pa_stream_peek failed\n"); |
| 175 | if (!p->read_length) { |
| 176 | /* buffer is empty */ |
| 177 | break; |
| 178 | } |
| 179 | } |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 180 | |
Volker Rümelin | acc3b63 | 2020-01-04 10:11:21 +0100 | [diff] [blame] | 181 | l = MIN(p->read_length, length - total); |
| 182 | memcpy((char *)data + total, p->read_data, l); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 183 | |
Volker Rümelin | acc3b63 | 2020-01-04 10:11:21 +0100 | [diff] [blame] | 184 | p->read_data += l; |
| 185 | p->read_length -= l; |
| 186 | total += l; |
| 187 | |
| 188 | if (!p->read_length) { |
| 189 | r = pa_stream_drop(p->stream); |
| 190 | CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, |
| 191 | "pa_stream_drop failed\n"); |
| 192 | } |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Volker Rümelin | 7c9eb86 | 2020-01-04 10:11:22 +0100 | [diff] [blame] | 195 | unlock: |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 196 | pa_threaded_mainloop_unlock(c->mainloop); |
Volker Rümelin | acc3b63 | 2020-01-04 10:11:21 +0100 | [diff] [blame] | 197 | return total; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 198 | |
| 199 | unlock_and_fail: |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 200 | pa_threaded_mainloop_unlock(c->mainloop); |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 201 | return 0; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 202 | } |
| 203 | |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 204 | static void *qpa_get_buffer_out(HWVoiceOut *hw, size_t *size) |
| 205 | { |
| 206 | PAVoiceOut *p = (PAVoiceOut *) hw; |
| 207 | PAConnection *c = p->g->conn; |
| 208 | void *ret; |
Volker Rümelin | bea29e9 | 2021-01-10 11:02:29 +0100 | [diff] [blame] | 209 | size_t l; |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 210 | int r; |
| 211 | |
| 212 | pa_threaded_mainloop_lock(c->mainloop); |
| 213 | |
| 214 | CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, |
| 215 | "pa_threaded_mainloop_lock failed\n"); |
Volker Rümelin | 7007cd3 | 2021-01-10 11:02:31 +0100 | [diff] [blame] | 216 | if (pa_stream_get_state(p->stream) != PA_STREAM_READY) { |
| 217 | /* wait for stream to become ready */ |
| 218 | l = 0; |
| 219 | ret = NULL; |
| 220 | goto unlock; |
| 221 | } |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 222 | |
Volker Rümelin | bea29e9 | 2021-01-10 11:02:29 +0100 | [diff] [blame] | 223 | l = pa_stream_writable_size(p->stream); |
| 224 | CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail, |
| 225 | "pa_stream_writable_size failed\n"); |
| 226 | |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 227 | *size = -1; |
| 228 | r = pa_stream_begin_write(p->stream, &ret, size); |
| 229 | CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, |
| 230 | "pa_stream_begin_write failed\n"); |
| 231 | |
Volker Rümelin | 7007cd3 | 2021-01-10 11:02:31 +0100 | [diff] [blame] | 232 | unlock: |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 233 | pa_threaded_mainloop_unlock(c->mainloop); |
Volker Rümelin | bea29e9 | 2021-01-10 11:02:29 +0100 | [diff] [blame] | 234 | if (*size > l) { |
| 235 | *size = l; |
| 236 | } |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 237 | return ret; |
| 238 | |
| 239 | unlock_and_fail: |
| 240 | pa_threaded_mainloop_unlock(c->mainloop); |
| 241 | *size = 0; |
| 242 | return NULL; |
| 243 | } |
| 244 | |
Volker Rümelin | bea29e9 | 2021-01-10 11:02:29 +0100 | [diff] [blame] | 245 | static size_t qpa_put_buffer_out(HWVoiceOut *hw, void *data, size_t length) |
| 246 | { |
| 247 | PAVoiceOut *p = (PAVoiceOut *)hw; |
| 248 | PAConnection *c = p->g->conn; |
| 249 | int r; |
| 250 | |
| 251 | pa_threaded_mainloop_lock(c->mainloop); |
| 252 | |
| 253 | CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, |
| 254 | "pa_threaded_mainloop_lock failed\n"); |
| 255 | |
| 256 | r = pa_stream_write(p->stream, data, length, NULL, 0LL, PA_SEEK_RELATIVE); |
| 257 | CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed\n"); |
| 258 | |
| 259 | pa_threaded_mainloop_unlock(c->mainloop); |
| 260 | return length; |
| 261 | |
| 262 | unlock_and_fail: |
| 263 | pa_threaded_mainloop_unlock(c->mainloop); |
| 264 | return 0; |
| 265 | } |
| 266 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 267 | static size_t qpa_write(HWVoiceOut *hw, void *data, size_t length) |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 268 | { |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 269 | PAVoiceOut *p = (PAVoiceOut *) hw; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 270 | PAConnection *c = p->g->conn; |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 271 | size_t l; |
| 272 | int r; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 273 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 274 | pa_threaded_mainloop_lock(c->mainloop); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 275 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 276 | CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, |
| 277 | "pa_threaded_mainloop_lock failed\n"); |
Volker Rümelin | e270c54 | 2021-01-10 11:02:30 +0100 | [diff] [blame] | 278 | if (pa_stream_get_state(p->stream) != PA_STREAM_READY) { |
| 279 | /* wait for stream to become ready */ |
| 280 | l = 0; |
| 281 | goto unlock; |
| 282 | } |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 283 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 284 | l = pa_stream_writable_size(p->stream); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 285 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 286 | CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail, |
| 287 | "pa_stream_writable_size failed\n"); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 288 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 289 | if (l > length) { |
| 290 | l = length; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 291 | } |
| 292 | |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 293 | r = pa_stream_write(p->stream, data, l, NULL, 0LL, PA_SEEK_RELATIVE); |
| 294 | CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed\n"); |
| 295 | |
Volker Rümelin | e270c54 | 2021-01-10 11:02:30 +0100 | [diff] [blame] | 296 | unlock: |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 297 | pa_threaded_mainloop_unlock(c->mainloop); |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 298 | return l; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 299 | |
| 300 | unlock_and_fail: |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 301 | pa_threaded_mainloop_unlock(c->mainloop); |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 302 | return 0; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 305 | static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness) |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 306 | { |
| 307 | int format; |
| 308 | |
| 309 | switch (afmt) { |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 310 | case AUDIO_FORMAT_S8: |
| 311 | case AUDIO_FORMAT_U8: |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 312 | format = PA_SAMPLE_U8; |
| 313 | break; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 314 | case AUDIO_FORMAT_S16: |
| 315 | case AUDIO_FORMAT_U16: |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 316 | format = endianness ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE; |
| 317 | break; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 318 | case AUDIO_FORMAT_S32: |
| 319 | case AUDIO_FORMAT_U32: |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 320 | format = endianness ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE; |
| 321 | break; |
Kővágó, Zoltán | ed2a4a7 | 2020-02-02 20:38:07 +0100 | [diff] [blame] | 322 | case AUDIO_FORMAT_F32: |
| 323 | format = endianness ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE; |
| 324 | break; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 325 | default: |
| 326 | dolog ("Internal logic error: Bad audio format %d\n", afmt); |
| 327 | format = PA_SAMPLE_U8; |
| 328 | break; |
| 329 | } |
| 330 | return format; |
| 331 | } |
| 332 | |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 333 | static AudioFormat pa_to_audfmt (pa_sample_format_t fmt, int *endianness) |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 334 | { |
| 335 | switch (fmt) { |
| 336 | case PA_SAMPLE_U8: |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 337 | return AUDIO_FORMAT_U8; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 338 | case PA_SAMPLE_S16BE: |
| 339 | *endianness = 1; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 340 | return AUDIO_FORMAT_S16; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 341 | case PA_SAMPLE_S16LE: |
| 342 | *endianness = 0; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 343 | return AUDIO_FORMAT_S16; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 344 | case PA_SAMPLE_S32BE: |
| 345 | *endianness = 1; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 346 | return AUDIO_FORMAT_S32; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 347 | case PA_SAMPLE_S32LE: |
| 348 | *endianness = 0; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 349 | return AUDIO_FORMAT_S32; |
Kővágó, Zoltán | ed2a4a7 | 2020-02-02 20:38:07 +0100 | [diff] [blame] | 350 | case PA_SAMPLE_FLOAT32BE: |
| 351 | *endianness = 1; |
| 352 | return AUDIO_FORMAT_F32; |
| 353 | case PA_SAMPLE_FLOAT32LE: |
| 354 | *endianness = 0; |
| 355 | return AUDIO_FORMAT_F32; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 356 | default: |
| 357 | dolog ("Internal logic error: Bad pa_sample_format %d\n", fmt); |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 358 | return AUDIO_FORMAT_U8; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 362 | static void context_state_cb (pa_context *c, void *userdata) |
| 363 | { |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 364 | PAConnection *conn = userdata; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 365 | |
| 366 | switch (pa_context_get_state(c)) { |
| 367 | case PA_CONTEXT_READY: |
| 368 | case PA_CONTEXT_TERMINATED: |
| 369 | case PA_CONTEXT_FAILED: |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 370 | pa_threaded_mainloop_signal(conn->mainloop, 0); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 371 | break; |
| 372 | |
| 373 | case PA_CONTEXT_UNCONNECTED: |
| 374 | case PA_CONTEXT_CONNECTING: |
| 375 | case PA_CONTEXT_AUTHORIZING: |
| 376 | case PA_CONTEXT_SETTING_NAME: |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | static void stream_state_cb (pa_stream *s, void * userdata) |
| 382 | { |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 383 | PAConnection *c = userdata; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 384 | |
| 385 | switch (pa_stream_get_state (s)) { |
| 386 | |
| 387 | case PA_STREAM_READY: |
| 388 | case PA_STREAM_FAILED: |
| 389 | case PA_STREAM_TERMINATED: |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 390 | pa_threaded_mainloop_signal(c->mainloop, 0); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 391 | break; |
| 392 | |
| 393 | case PA_STREAM_UNCONNECTED: |
| 394 | case PA_STREAM_CREATING: |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 399 | static pa_stream *qpa_simple_new ( |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 400 | PAConnection *c, |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 401 | const char *name, |
| 402 | pa_stream_direction_t dir, |
| 403 | const char *dev, |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 404 | const pa_sample_spec *ss, |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 405 | const pa_buffer_attr *attr, |
| 406 | int *rerror) |
| 407 | { |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 408 | int r; |
Kővágó, Zoltán | 0cf13e3 | 2019-10-13 21:58:07 +0200 | [diff] [blame] | 409 | pa_stream *stream = NULL; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 410 | pa_stream_flags_t flags; |
Kővágó, Zoltán | 0cf13e3 | 2019-10-13 21:58:07 +0200 | [diff] [blame] | 411 | pa_channel_map map; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 412 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 413 | pa_threaded_mainloop_lock(c->mainloop); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 414 | |
Kővágó, Zoltán | 0cf13e3 | 2019-10-13 21:58:07 +0200 | [diff] [blame] | 415 | pa_channel_map_init(&map); |
| 416 | map.channels = ss->channels; |
| 417 | |
| 418 | /* |
| 419 | * TODO: This currently expects the only frontend supporting more than 2 |
| 420 | * channels is the usb-audio. We will need some means to set channel |
| 421 | * order when a new frontend gains multi-channel support. |
| 422 | */ |
| 423 | switch (ss->channels) { |
| 424 | case 1: |
| 425 | map.map[0] = PA_CHANNEL_POSITION_MONO; |
| 426 | break; |
| 427 | |
| 428 | case 2: |
| 429 | map.map[0] = PA_CHANNEL_POSITION_LEFT; |
| 430 | map.map[1] = PA_CHANNEL_POSITION_RIGHT; |
| 431 | break; |
| 432 | |
| 433 | case 6: |
| 434 | map.map[0] = PA_CHANNEL_POSITION_FRONT_LEFT; |
| 435 | map.map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT; |
| 436 | map.map[2] = PA_CHANNEL_POSITION_CENTER; |
| 437 | map.map[3] = PA_CHANNEL_POSITION_LFE; |
| 438 | map.map[4] = PA_CHANNEL_POSITION_REAR_LEFT; |
| 439 | map.map[5] = PA_CHANNEL_POSITION_REAR_RIGHT; |
| 440 | break; |
| 441 | |
| 442 | case 8: |
| 443 | map.map[0] = PA_CHANNEL_POSITION_FRONT_LEFT; |
| 444 | map.map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT; |
| 445 | map.map[2] = PA_CHANNEL_POSITION_CENTER; |
| 446 | map.map[3] = PA_CHANNEL_POSITION_LFE; |
| 447 | map.map[4] = PA_CHANNEL_POSITION_REAR_LEFT; |
| 448 | map.map[5] = PA_CHANNEL_POSITION_REAR_RIGHT; |
| 449 | map.map[6] = PA_CHANNEL_POSITION_SIDE_LEFT; |
| 450 | map.map[7] = PA_CHANNEL_POSITION_SIDE_RIGHT; |
Paolo Bonzini | 5608956 | 2019-10-23 10:24:20 +0200 | [diff] [blame] | 451 | break; |
Kővágó, Zoltán | 0cf13e3 | 2019-10-13 21:58:07 +0200 | [diff] [blame] | 452 | |
| 453 | default: |
| 454 | dolog("Internal error: unsupported channel count %d\n", ss->channels); |
| 455 | goto fail; |
| 456 | } |
| 457 | |
| 458 | stream = pa_stream_new(c->context, name, ss, &map); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 459 | if (!stream) { |
| 460 | goto fail; |
| 461 | } |
| 462 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 463 | pa_stream_set_state_callback(stream, stream_state_cb, c); |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 464 | |
Volker Rümelin | 50db82d | 2021-05-17 21:46:02 +0200 | [diff] [blame] | 465 | flags = PA_STREAM_EARLY_REQUESTS; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 466 | |
Kővágó, Zoltán | 8a435f7 | 2019-08-19 01:06:52 +0200 | [diff] [blame] | 467 | if (dev) { |
| 468 | /* don't move the stream if the user specified a sink/source */ |
| 469 | flags |= PA_STREAM_DONT_MOVE; |
| 470 | } |
| 471 | |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 472 | if (dir == PA_STREAM_PLAYBACK) { |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 473 | r = pa_stream_connect_playback(stream, dev, attr, flags, NULL, NULL); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 474 | } else { |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 475 | r = pa_stream_connect_record(stream, dev, attr, flags); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | if (r < 0) { |
Zhang Han | 289db3c | 2021-01-15 09:24:30 +0800 | [diff] [blame] | 479 | goto fail; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 482 | pa_threaded_mainloop_unlock(c->mainloop); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 483 | |
| 484 | return stream; |
| 485 | |
| 486 | fail: |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 487 | pa_threaded_mainloop_unlock(c->mainloop); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 488 | |
| 489 | if (stream) { |
| 490 | pa_stream_unref (stream); |
| 491 | } |
| 492 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 493 | *rerror = pa_context_errno(c->context); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 494 | |
| 495 | return NULL; |
| 496 | } |
| 497 | |
Kővágó, Zoltán | 5706db1 | 2015-06-03 23:03:47 +0200 | [diff] [blame] | 498 | static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as, |
| 499 | void *drv_opaque) |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 500 | { |
| 501 | int error; |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 502 | pa_sample_spec ss; |
| 503 | pa_buffer_attr ba; |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 504 | struct audsettings obt_as = *as; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 505 | PAVoiceOut *pa = (PAVoiceOut *) hw; |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 506 | paaudio *g = pa->g = drv_opaque; |
Kővágó, Zoltán | 2c324b2 | 2019-03-08 23:34:21 +0100 | [diff] [blame] | 507 | AudiodevPaOptions *popts = &g->dev->u.pa; |
| 508 | AudiodevPaPerDirectionOptions *ppdo = popts->out; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 509 | PAConnection *c = g->conn; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 510 | |
| 511 | ss.format = audfmt_to_pa (as->fmt, as->endianness); |
| 512 | ss.channels = as->nchannels; |
| 513 | ss.rate = as->freq; |
| 514 | |
Martin Schrodt | f614277 | 2019-03-15 09:46:52 +0100 | [diff] [blame] | 515 | ba.tlength = pa_usec_to_bytes(ppdo->latency, &ss); |
Volker Rümelin | 00413ed | 2021-01-10 11:02:34 +0100 | [diff] [blame] | 516 | ba.minreq = pa_usec_to_bytes(MIN(ppdo->latency >> 2, |
| 517 | (g->dev->timer_period >> 2) * 3), &ss); |
Gerd Hoffmann | e6d16fa | 2011-01-24 22:07:45 +0100 | [diff] [blame] | 518 | ba.maxlength = -1; |
| 519 | ba.prebuf = -1; |
| 520 | |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 521 | obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness); |
| 522 | |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 523 | pa->stream = qpa_simple_new ( |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 524 | c, |
Kővágó, Zoltán | f47dffe8 | 2019-09-11 01:26:20 +0200 | [diff] [blame] | 525 | ppdo->has_stream_name ? ppdo->stream_name : g->dev->id, |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 526 | PA_STREAM_PLAYBACK, |
Kővágó, Zoltán | 2c324b2 | 2019-03-08 23:34:21 +0100 | [diff] [blame] | 527 | ppdo->has_name ? ppdo->name : NULL, |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 528 | &ss, |
Gerd Hoffmann | e6d16fa | 2011-01-24 22:07:45 +0100 | [diff] [blame] | 529 | &ba, /* buffering attributes */ |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 530 | &error |
| 531 | ); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 532 | if (!pa->stream) { |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 533 | qpa_logerr (error, "pa_simple_new for playback failed\n"); |
| 534 | goto fail1; |
| 535 | } |
| 536 | |
| 537 | audio_pcm_init_info (&hw->info, &obt_as); |
Volker Rümelin | cffd2fd | 2021-01-10 11:02:33 +0100 | [diff] [blame] | 538 | /* |
| 539 | * This is wrong. hw->samples counts in frames. hw->samples will be |
| 540 | * number of channels times larger than expected. |
| 541 | */ |
Volker Rümelin | a76e6b8 | 2020-01-23 08:49:37 +0100 | [diff] [blame] | 542 | hw->samples = audio_buffer_samples( |
Volker Rümelin | 521ce71 | 2021-01-10 11:02:32 +0100 | [diff] [blame] | 543 | qapi_AudiodevPaPerDirectionOptions_base(ppdo), &obt_as, 46440); |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 544 | |
| 545 | return 0; |
| 546 | |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 547 | fail1: |
| 548 | return -1; |
| 549 | } |
| 550 | |
Kővágó, Zoltán | 5706db1 | 2015-06-03 23:03:47 +0200 | [diff] [blame] | 551 | static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 552 | { |
| 553 | int error; |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 554 | pa_sample_spec ss; |
Martin Schrodt | ade1030 | 2019-03-15 09:46:53 +0100 | [diff] [blame] | 555 | pa_buffer_attr ba; |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 556 | struct audsettings obt_as = *as; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 557 | PAVoiceIn *pa = (PAVoiceIn *) hw; |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 558 | paaudio *g = pa->g = drv_opaque; |
Kővágó, Zoltán | 2c324b2 | 2019-03-08 23:34:21 +0100 | [diff] [blame] | 559 | AudiodevPaOptions *popts = &g->dev->u.pa; |
| 560 | AudiodevPaPerDirectionOptions *ppdo = popts->in; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 561 | PAConnection *c = g->conn; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 562 | |
| 563 | ss.format = audfmt_to_pa (as->fmt, as->endianness); |
| 564 | ss.channels = as->nchannels; |
| 565 | ss.rate = as->freq; |
| 566 | |
Volker Rümelin | d9a8b27 | 2021-01-10 11:02:35 +0100 | [diff] [blame] | 567 | ba.fragsize = pa_usec_to_bytes((g->dev->timer_period >> 1) * 3, &ss); |
| 568 | ba.maxlength = pa_usec_to_bytes( |
| 569 | MAX(ppdo->latency, g->dev->timer_period * 3), &ss); |
Martin Schrodt | ade1030 | 2019-03-15 09:46:53 +0100 | [diff] [blame] | 570 | ba.minreq = -1; |
| 571 | ba.prebuf = -1; |
| 572 | |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 573 | obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness); |
| 574 | |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 575 | pa->stream = qpa_simple_new ( |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 576 | c, |
Kővágó, Zoltán | f47dffe8 | 2019-09-11 01:26:20 +0200 | [diff] [blame] | 577 | ppdo->has_stream_name ? ppdo->stream_name : g->dev->id, |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 578 | PA_STREAM_RECORD, |
Kővágó, Zoltán | 2c324b2 | 2019-03-08 23:34:21 +0100 | [diff] [blame] | 579 | ppdo->has_name ? ppdo->name : NULL, |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 580 | &ss, |
Martin Schrodt | ade1030 | 2019-03-15 09:46:53 +0100 | [diff] [blame] | 581 | &ba, /* buffering attributes */ |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 582 | &error |
| 583 | ); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 584 | if (!pa->stream) { |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 585 | qpa_logerr (error, "pa_simple_new for capture failed\n"); |
| 586 | goto fail1; |
| 587 | } |
| 588 | |
| 589 | audio_pcm_init_info (&hw->info, &obt_as); |
Volker Rümelin | cffd2fd | 2021-01-10 11:02:33 +0100 | [diff] [blame] | 590 | /* |
| 591 | * This is wrong. hw->samples counts in frames. hw->samples will be |
| 592 | * number of channels times larger than expected. |
| 593 | */ |
Volker Rümelin | a76e6b8 | 2020-01-23 08:49:37 +0100 | [diff] [blame] | 594 | hw->samples = audio_buffer_samples( |
Volker Rümelin | 521ce71 | 2021-01-10 11:02:32 +0100 | [diff] [blame] | 595 | qapi_AudiodevPaPerDirectionOptions_base(ppdo), &obt_as, 46440); |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 596 | |
| 597 | return 0; |
| 598 | |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 599 | fail1: |
| 600 | return -1; |
| 601 | } |
| 602 | |
Kővágó, Zoltán | 8692bf7 | 2019-08-19 01:06:53 +0200 | [diff] [blame] | 603 | static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream) |
| 604 | { |
| 605 | int err; |
| 606 | |
Kővágó, Zoltán | 8692bf7 | 2019-08-19 01:06:53 +0200 | [diff] [blame] | 607 | /* |
| 608 | * wait until actually connects. workaround pa bug #247 |
| 609 | * https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/247 |
| 610 | */ |
| 611 | while (pa_stream_get_state(stream) == PA_STREAM_CREATING) { |
| 612 | pa_threaded_mainloop_wait(c->mainloop); |
| 613 | } |
| 614 | |
| 615 | err = pa_stream_disconnect(stream); |
| 616 | if (err != 0) { |
| 617 | dolog("Failed to disconnect! err=%d\n", err); |
| 618 | } |
| 619 | pa_stream_unref(stream); |
Kővágó, Zoltán | 8692bf7 | 2019-08-19 01:06:53 +0200 | [diff] [blame] | 620 | } |
| 621 | |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 622 | static void qpa_fini_out (HWVoiceOut *hw) |
| 623 | { |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 624 | PAVoiceOut *pa = (PAVoiceOut *) hw; |
| 625 | |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 626 | if (pa->stream) { |
Volker Rümelin | 4db3e63 | 2020-01-04 10:11:20 +0100 | [diff] [blame] | 627 | PAConnection *c = pa->g->conn; |
| 628 | |
| 629 | pa_threaded_mainloop_lock(c->mainloop); |
| 630 | qpa_simple_disconnect(c, pa->stream); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 631 | pa->stream = NULL; |
Volker Rümelin | 4db3e63 | 2020-01-04 10:11:20 +0100 | [diff] [blame] | 632 | pa_threaded_mainloop_unlock(c->mainloop); |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 633 | } |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static void qpa_fini_in (HWVoiceIn *hw) |
| 637 | { |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 638 | PAVoiceIn *pa = (PAVoiceIn *) hw; |
| 639 | |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 640 | if (pa->stream) { |
Volker Rümelin | 4db3e63 | 2020-01-04 10:11:20 +0100 | [diff] [blame] | 641 | PAConnection *c = pa->g->conn; |
| 642 | |
| 643 | pa_threaded_mainloop_lock(c->mainloop); |
| 644 | if (pa->read_length) { |
| 645 | int r = pa_stream_drop(pa->stream); |
| 646 | if (r) { |
| 647 | qpa_logerr(pa_context_errno(c->context), |
| 648 | "pa_stream_drop failed\n"); |
| 649 | } |
| 650 | pa->read_length = 0; |
| 651 | } |
| 652 | qpa_simple_disconnect(c, pa->stream); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 653 | pa->stream = NULL; |
Volker Rümelin | 4db3e63 | 2020-01-04 10:11:20 +0100 | [diff] [blame] | 654 | pa_threaded_mainloop_unlock(c->mainloop); |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 655 | } |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 658 | static void qpa_volume_out(HWVoiceOut *hw, Volume *vol) |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 659 | { |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 660 | PAVoiceOut *pa = (PAVoiceOut *) hw; |
| 661 | pa_operation *op; |
| 662 | pa_cvolume v; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 663 | PAConnection *c = pa->g->conn; |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 664 | int i; |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 665 | |
Gerd Hoffmann | 8f473dd | 2012-05-03 22:41:28 +0200 | [diff] [blame] | 666 | #ifdef PA_CHECK_VERSION /* macro is present in 0.9.16+ */ |
| 667 | pa_cvolume_init (&v); /* function is present in 0.9.13+ */ |
| 668 | #endif |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 669 | |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 670 | v.channels = vol->channels; |
| 671 | for (i = 0; i < vol->channels; ++i) { |
| 672 | v.values[i] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * vol->vol[i]) / 255; |
| 673 | } |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 674 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 675 | pa_threaded_mainloop_lock(c->mainloop); |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 676 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 677 | op = pa_context_set_sink_input_volume(c->context, |
| 678 | pa_stream_get_index(pa->stream), |
| 679 | &v, NULL, NULL); |
| 680 | if (!op) { |
| 681 | qpa_logerr(pa_context_errno(c->context), |
| 682 | "set_sink_input_volume() failed\n"); |
| 683 | } else { |
| 684 | pa_operation_unref(op); |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 685 | } |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 686 | |
| 687 | op = pa_context_set_sink_input_mute(c->context, |
| 688 | pa_stream_get_index(pa->stream), |
| 689 | vol->mute, NULL, NULL); |
| 690 | if (!op) { |
| 691 | qpa_logerr(pa_context_errno(c->context), |
| 692 | "set_sink_input_mute() failed\n"); |
| 693 | } else { |
| 694 | pa_operation_unref(op); |
| 695 | } |
| 696 | |
| 697 | pa_threaded_mainloop_unlock(c->mainloop); |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 700 | static void qpa_volume_in(HWVoiceIn *hw, Volume *vol) |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 701 | { |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 702 | PAVoiceIn *pa = (PAVoiceIn *) hw; |
| 703 | pa_operation *op; |
| 704 | pa_cvolume v; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 705 | PAConnection *c = pa->g->conn; |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 706 | int i; |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 707 | |
Gerd Hoffmann | 8f473dd | 2012-05-03 22:41:28 +0200 | [diff] [blame] | 708 | #ifdef PA_CHECK_VERSION |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 709 | pa_cvolume_init (&v); |
Gerd Hoffmann | 8f473dd | 2012-05-03 22:41:28 +0200 | [diff] [blame] | 710 | #endif |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 711 | |
Kővágó, Zoltán | cecc1e7 | 2019-10-13 21:58:01 +0200 | [diff] [blame] | 712 | v.channels = vol->channels; |
| 713 | for (i = 0; i < vol->channels; ++i) { |
| 714 | v.values[i] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * vol->vol[i]) / 255; |
| 715 | } |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 716 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 717 | pa_threaded_mainloop_lock(c->mainloop); |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 718 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 719 | op = pa_context_set_source_output_volume(c->context, |
| 720 | pa_stream_get_index(pa->stream), |
| 721 | &v, NULL, NULL); |
| 722 | if (!op) { |
| 723 | qpa_logerr(pa_context_errno(c->context), |
| 724 | "set_source_output_volume() failed\n"); |
| 725 | } else { |
| 726 | pa_operation_unref(op); |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 727 | } |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 728 | |
| 729 | op = pa_context_set_source_output_mute(c->context, |
| 730 | pa_stream_get_index(pa->stream), |
| 731 | vol->mute, NULL, NULL); |
| 732 | if (!op) { |
| 733 | qpa_logerr(pa_context_errno(c->context), |
| 734 | "set_source_output_mute() failed\n"); |
| 735 | } else { |
| 736 | pa_operation_unref(op); |
| 737 | } |
| 738 | |
| 739 | pa_threaded_mainloop_unlock(c->mainloop); |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Martin Schrodt | baea032 | 2019-03-15 09:46:51 +0100 | [diff] [blame] | 742 | static int qpa_validate_per_direction_opts(Audiodev *dev, |
| 743 | AudiodevPaPerDirectionOptions *pdo) |
| 744 | { |
Martin Schrodt | f614277 | 2019-03-15 09:46:52 +0100 | [diff] [blame] | 745 | if (!pdo->has_latency) { |
| 746 | pdo->has_latency = true; |
| 747 | pdo->latency = 15000; |
| 748 | } |
Martin Schrodt | baea032 | 2019-03-15 09:46:51 +0100 | [diff] [blame] | 749 | return 1; |
| 750 | } |
| 751 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 752 | /* common */ |
| 753 | static void *qpa_conn_init(const char *server) |
| 754 | { |
| 755 | PAConnection *c = g_malloc0(sizeof(PAConnection)); |
| 756 | QTAILQ_INSERT_TAIL(&pa_conns, c, list); |
| 757 | |
| 758 | c->mainloop = pa_threaded_mainloop_new(); |
| 759 | if (!c->mainloop) { |
| 760 | goto fail; |
| 761 | } |
| 762 | |
| 763 | c->context = pa_context_new(pa_threaded_mainloop_get_api(c->mainloop), |
Volker Rümelin | 37a54d0 | 2021-05-17 21:46:03 +0200 | [diff] [blame] | 764 | audio_application_name()); |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 765 | if (!c->context) { |
| 766 | goto fail; |
| 767 | } |
| 768 | |
| 769 | pa_context_set_state_callback(c->context, context_state_cb, c); |
| 770 | |
| 771 | if (pa_context_connect(c->context, server, 0, NULL) < 0) { |
| 772 | qpa_logerr(pa_context_errno(c->context), |
| 773 | "pa_context_connect() failed\n"); |
| 774 | goto fail; |
| 775 | } |
| 776 | |
| 777 | pa_threaded_mainloop_lock(c->mainloop); |
| 778 | |
| 779 | if (pa_threaded_mainloop_start(c->mainloop) < 0) { |
| 780 | goto unlock_and_fail; |
| 781 | } |
| 782 | |
| 783 | for (;;) { |
| 784 | pa_context_state_t state; |
| 785 | |
| 786 | state = pa_context_get_state(c->context); |
| 787 | |
| 788 | if (state == PA_CONTEXT_READY) { |
| 789 | break; |
| 790 | } |
| 791 | |
| 792 | if (!PA_CONTEXT_IS_GOOD(state)) { |
| 793 | qpa_logerr(pa_context_errno(c->context), |
| 794 | "Wrong context state\n"); |
| 795 | goto unlock_and_fail; |
| 796 | } |
| 797 | |
| 798 | /* Wait until the context is ready */ |
| 799 | pa_threaded_mainloop_wait(c->mainloop); |
| 800 | } |
| 801 | |
| 802 | pa_threaded_mainloop_unlock(c->mainloop); |
| 803 | return c; |
| 804 | |
| 805 | unlock_and_fail: |
| 806 | pa_threaded_mainloop_unlock(c->mainloop); |
| 807 | fail: |
| 808 | AUD_log (AUDIO_CAP, "Failed to initialize PA context"); |
| 809 | qpa_conn_fini(c); |
| 810 | return NULL; |
| 811 | } |
| 812 | |
Kővágó, Zoltán | 7183022 | 2019-03-08 23:34:15 +0100 | [diff] [blame] | 813 | static void *qpa_audio_init(Audiodev *dev) |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 814 | { |
Kővágó, Zoltán | 2c324b2 | 2019-03-08 23:34:21 +0100 | [diff] [blame] | 815 | paaudio *g; |
| 816 | AudiodevPaOptions *popts = &dev->u.pa; |
| 817 | const char *server; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 818 | PAConnection *c; |
| 819 | |
| 820 | assert(dev->driver == AUDIODEV_DRIVER_PA); |
Kővágó, Zoltán | 2c324b2 | 2019-03-08 23:34:21 +0100 | [diff] [blame] | 821 | |
| 822 | if (!popts->has_server) { |
Gerd Hoffmann | d175505 | 2019-01-24 12:20:53 +0100 | [diff] [blame] | 823 | char pidfile[64]; |
| 824 | char *runtime; |
| 825 | struct stat st; |
| 826 | |
| 827 | runtime = getenv("XDG_RUNTIME_DIR"); |
| 828 | if (!runtime) { |
| 829 | return NULL; |
| 830 | } |
| 831 | snprintf(pidfile, sizeof(pidfile), "%s/pulse/pid", runtime); |
| 832 | if (stat(pidfile, &st) != 0) { |
| 833 | return NULL; |
| 834 | } |
| 835 | } |
| 836 | |
Martin Schrodt | baea032 | 2019-03-15 09:46:51 +0100 | [diff] [blame] | 837 | if (!qpa_validate_per_direction_opts(dev, popts->in)) { |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 838 | return NULL; |
Martin Schrodt | baea032 | 2019-03-15 09:46:51 +0100 | [diff] [blame] | 839 | } |
| 840 | if (!qpa_validate_per_direction_opts(dev, popts->out)) { |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 841 | return NULL; |
Martin Schrodt | baea032 | 2019-03-15 09:46:51 +0100 | [diff] [blame] | 842 | } |
| 843 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 844 | g = g_malloc0(sizeof(paaudio)); |
| 845 | server = popts->has_server ? popts->server : NULL; |
| 846 | |
Kővágó, Zoltán | 2c324b2 | 2019-03-08 23:34:21 +0100 | [diff] [blame] | 847 | g->dev = dev; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 848 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 849 | QTAILQ_FOREACH(c, &pa_conns, list) { |
| 850 | if (server == NULL || c->server == NULL ? |
| 851 | server == c->server : |
| 852 | strcmp(server, c->server) == 0) { |
| 853 | g->conn = c; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 854 | break; |
| 855 | } |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 856 | } |
| 857 | if (!g->conn) { |
| 858 | g->conn = qpa_conn_init(server); |
| 859 | } |
| 860 | if (!g->conn) { |
| 861 | g_free(g); |
| 862 | return NULL; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 863 | } |
| 864 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 865 | ++g->conn->refcount; |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 866 | return g; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 867 | } |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 868 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 869 | static void qpa_conn_fini(PAConnection *c) |
| 870 | { |
| 871 | if (c->mainloop) { |
| 872 | pa_threaded_mainloop_stop(c->mainloop); |
| 873 | } |
| 874 | |
| 875 | if (c->context) { |
| 876 | pa_context_disconnect(c->context); |
| 877 | pa_context_unref(c->context); |
| 878 | } |
| 879 | |
| 880 | if (c->mainloop) { |
| 881 | pa_threaded_mainloop_free(c->mainloop); |
| 882 | } |
| 883 | |
| 884 | QTAILQ_REMOVE(&pa_conns, c, list); |
| 885 | g_free(c); |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | static void qpa_audio_fini (void *opaque) |
| 889 | { |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 890 | paaudio *g = opaque; |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 891 | PAConnection *c = g->conn; |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 892 | |
Kővágó, Zoltán | 9d34e6d | 2019-08-19 01:06:50 +0200 | [diff] [blame] | 893 | if (--c->refcount == 0) { |
| 894 | qpa_conn_fini(c); |
Marc-André Lureau | ea9ebc2 | 2012-04-17 14:32:41 +0200 | [diff] [blame] | 895 | } |
| 896 | |
Kővágó, Zoltán | 9a644c4 | 2015-06-03 23:03:49 +0200 | [diff] [blame] | 897 | g_free(g); |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 898 | } |
| 899 | |
blueswir1 | 35f4b58 | 2008-10-06 18:08:30 +0000 | [diff] [blame] | 900 | static struct audio_pcm_ops qpa_pcm_ops = { |
Juan Quintela | 1dd3e4d | 2009-08-11 02:31:15 +0200 | [diff] [blame] | 901 | .init_out = qpa_init_out, |
| 902 | .fini_out = qpa_fini_out, |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 903 | .write = qpa_write, |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 904 | .get_buffer_out = qpa_get_buffer_out, |
Volker Rümelin | bea29e9 | 2021-01-10 11:02:29 +0100 | [diff] [blame] | 905 | .put_buffer_out = qpa_put_buffer_out, |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 906 | .volume_out = qpa_volume_out, |
Juan Quintela | 1dd3e4d | 2009-08-11 02:31:15 +0200 | [diff] [blame] | 907 | |
| 908 | .init_in = qpa_init_in, |
| 909 | .fini_in = qpa_fini_in, |
Kővágó, Zoltán | 49ddd7e | 2019-09-19 23:24:15 +0200 | [diff] [blame] | 910 | .read = qpa_read, |
Kővágó, Zoltán | 337e8de | 2019-10-13 21:58:00 +0200 | [diff] [blame] | 911 | .get_buffer_in = qpa_get_buffer_in, |
| 912 | .put_buffer_in = qpa_put_buffer_in, |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 913 | .volume_in = qpa_volume_in |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 914 | }; |
| 915 | |
Gerd Hoffmann | d3893a3 | 2018-03-06 08:40:47 +0100 | [diff] [blame] | 916 | static struct audio_driver pa_audio_driver = { |
Juan Quintela | bee37f3 | 2009-08-11 02:31:14 +0200 | [diff] [blame] | 917 | .name = "pa", |
| 918 | .descr = "http://www.pulseaudio.org/", |
Juan Quintela | bee37f3 | 2009-08-11 02:31:14 +0200 | [diff] [blame] | 919 | .init = qpa_audio_init, |
| 920 | .fini = qpa_audio_fini, |
| 921 | .pcm_ops = &qpa_pcm_ops, |
Michael S. Tsirkin | 1a4ea1e | 2009-10-13 16:08:55 +0200 | [diff] [blame] | 922 | .can_be_default = 1, |
Juan Quintela | bee37f3 | 2009-08-11 02:31:14 +0200 | [diff] [blame] | 923 | .max_voices_out = INT_MAX, |
| 924 | .max_voices_in = INT_MAX, |
| 925 | .voice_size_out = sizeof (PAVoiceOut), |
Marc-André Lureau | 6e7a7f3 | 2012-04-17 14:32:43 +0200 | [diff] [blame] | 926 | .voice_size_in = sizeof (PAVoiceIn), |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 927 | }; |
Gerd Hoffmann | d3893a3 | 2018-03-06 08:40:47 +0100 | [diff] [blame] | 928 | |
| 929 | static void register_audio_pa(void) |
| 930 | { |
| 931 | audio_driver_register(&pa_audio_driver); |
| 932 | } |
| 933 | type_init(register_audio_pa); |