Rename al_string_* functions to alstr_*
[openal-soft.git] / Alc / backends / pulseaudio.c
blob79ca38e5ff4b56b2490a22c06d66000c096be340
1 /**
2 * OpenAL cross platform audio library
3 * Copyright (C) 2009 by Konstantinos Natsakis <konstantinos.natsakis@gmail.com>
4 * Copyright (C) 2010 by Chris Robinson <chris.kcat@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * Or go to http://www.gnu.org/copyleft/lgpl.html
22 #include "config.h"
24 #include <string.h>
26 #include "alMain.h"
27 #include "alu.h"
28 #include "threads.h"
29 #include "compat.h"
31 #include "backends/base.h"
33 #include <pulse/pulseaudio.h>
35 #if PA_API_VERSION == 12
37 #ifdef HAVE_DYNLOAD
38 static void *pa_handle;
39 #define MAKE_FUNC(x) static __typeof(x) * p##x
40 MAKE_FUNC(pa_context_unref);
41 MAKE_FUNC(pa_sample_spec_valid);
42 MAKE_FUNC(pa_frame_size);
43 MAKE_FUNC(pa_stream_drop);
44 MAKE_FUNC(pa_strerror);
45 MAKE_FUNC(pa_context_get_state);
46 MAKE_FUNC(pa_stream_get_state);
47 MAKE_FUNC(pa_threaded_mainloop_signal);
48 MAKE_FUNC(pa_stream_peek);
49 MAKE_FUNC(pa_threaded_mainloop_wait);
50 MAKE_FUNC(pa_threaded_mainloop_unlock);
51 MAKE_FUNC(pa_threaded_mainloop_in_thread);
52 MAKE_FUNC(pa_context_new);
53 MAKE_FUNC(pa_threaded_mainloop_stop);
54 MAKE_FUNC(pa_context_disconnect);
55 MAKE_FUNC(pa_threaded_mainloop_start);
56 MAKE_FUNC(pa_threaded_mainloop_get_api);
57 MAKE_FUNC(pa_context_set_state_callback);
58 MAKE_FUNC(pa_stream_write);
59 MAKE_FUNC(pa_xfree);
60 MAKE_FUNC(pa_stream_connect_record);
61 MAKE_FUNC(pa_stream_connect_playback);
62 MAKE_FUNC(pa_stream_readable_size);
63 MAKE_FUNC(pa_stream_writable_size);
64 MAKE_FUNC(pa_stream_is_corked);
65 MAKE_FUNC(pa_stream_cork);
66 MAKE_FUNC(pa_stream_is_suspended);
67 MAKE_FUNC(pa_stream_get_device_name);
68 MAKE_FUNC(pa_stream_get_latency);
69 MAKE_FUNC(pa_path_get_filename);
70 MAKE_FUNC(pa_get_binary_name);
71 MAKE_FUNC(pa_threaded_mainloop_free);
72 MAKE_FUNC(pa_context_errno);
73 MAKE_FUNC(pa_xmalloc);
74 MAKE_FUNC(pa_stream_unref);
75 MAKE_FUNC(pa_threaded_mainloop_accept);
76 MAKE_FUNC(pa_stream_set_write_callback);
77 MAKE_FUNC(pa_threaded_mainloop_new);
78 MAKE_FUNC(pa_context_connect);
79 MAKE_FUNC(pa_stream_set_buffer_attr);
80 MAKE_FUNC(pa_stream_get_buffer_attr);
81 MAKE_FUNC(pa_stream_get_sample_spec);
82 MAKE_FUNC(pa_stream_get_time);
83 MAKE_FUNC(pa_stream_set_read_callback);
84 MAKE_FUNC(pa_stream_set_state_callback);
85 MAKE_FUNC(pa_stream_set_moved_callback);
86 MAKE_FUNC(pa_stream_set_underflow_callback);
87 MAKE_FUNC(pa_stream_new_with_proplist);
88 MAKE_FUNC(pa_stream_disconnect);
89 MAKE_FUNC(pa_threaded_mainloop_lock);
90 MAKE_FUNC(pa_channel_map_init_auto);
91 MAKE_FUNC(pa_channel_map_parse);
92 MAKE_FUNC(pa_channel_map_snprint);
93 MAKE_FUNC(pa_channel_map_equal);
94 MAKE_FUNC(pa_context_get_server_info);
95 MAKE_FUNC(pa_context_get_sink_info_by_name);
96 MAKE_FUNC(pa_context_get_sink_info_list);
97 MAKE_FUNC(pa_context_get_source_info_by_name);
98 MAKE_FUNC(pa_context_get_source_info_list);
99 MAKE_FUNC(pa_operation_get_state);
100 MAKE_FUNC(pa_operation_unref);
101 MAKE_FUNC(pa_proplist_new);
102 MAKE_FUNC(pa_proplist_free);
103 MAKE_FUNC(pa_proplist_set);
104 MAKE_FUNC(pa_channel_map_superset);
105 MAKE_FUNC(pa_stream_set_buffer_attr_callback);
106 MAKE_FUNC(pa_stream_begin_write);
107 #undef MAKE_FUNC
109 #define pa_context_unref ppa_context_unref
110 #define pa_sample_spec_valid ppa_sample_spec_valid
111 #define pa_frame_size ppa_frame_size
112 #define pa_stream_drop ppa_stream_drop
113 #define pa_strerror ppa_strerror
114 #define pa_context_get_state ppa_context_get_state
115 #define pa_stream_get_state ppa_stream_get_state
116 #define pa_threaded_mainloop_signal ppa_threaded_mainloop_signal
117 #define pa_stream_peek ppa_stream_peek
118 #define pa_threaded_mainloop_wait ppa_threaded_mainloop_wait
119 #define pa_threaded_mainloop_unlock ppa_threaded_mainloop_unlock
120 #define pa_threaded_mainloop_in_thread ppa_threaded_mainloop_in_thread
121 #define pa_context_new ppa_context_new
122 #define pa_threaded_mainloop_stop ppa_threaded_mainloop_stop
123 #define pa_context_disconnect ppa_context_disconnect
124 #define pa_threaded_mainloop_start ppa_threaded_mainloop_start
125 #define pa_threaded_mainloop_get_api ppa_threaded_mainloop_get_api
126 #define pa_context_set_state_callback ppa_context_set_state_callback
127 #define pa_stream_write ppa_stream_write
128 #define pa_xfree ppa_xfree
129 #define pa_stream_connect_record ppa_stream_connect_record
130 #define pa_stream_connect_playback ppa_stream_connect_playback
131 #define pa_stream_readable_size ppa_stream_readable_size
132 #define pa_stream_writable_size ppa_stream_writable_size
133 #define pa_stream_is_corked ppa_stream_is_corked
134 #define pa_stream_cork ppa_stream_cork
135 #define pa_stream_is_suspended ppa_stream_is_suspended
136 #define pa_stream_get_device_name ppa_stream_get_device_name
137 #define pa_stream_get_latency ppa_stream_get_latency
138 #define pa_path_get_filename ppa_path_get_filename
139 #define pa_get_binary_name ppa_get_binary_name
140 #define pa_threaded_mainloop_free ppa_threaded_mainloop_free
141 #define pa_context_errno ppa_context_errno
142 #define pa_xmalloc ppa_xmalloc
143 #define pa_stream_unref ppa_stream_unref
144 #define pa_threaded_mainloop_accept ppa_threaded_mainloop_accept
145 #define pa_stream_set_write_callback ppa_stream_set_write_callback
146 #define pa_threaded_mainloop_new ppa_threaded_mainloop_new
147 #define pa_context_connect ppa_context_connect
148 #define pa_stream_set_buffer_attr ppa_stream_set_buffer_attr
149 #define pa_stream_get_buffer_attr ppa_stream_get_buffer_attr
150 #define pa_stream_get_sample_spec ppa_stream_get_sample_spec
151 #define pa_stream_get_time ppa_stream_get_time
152 #define pa_stream_set_read_callback ppa_stream_set_read_callback
153 #define pa_stream_set_state_callback ppa_stream_set_state_callback
154 #define pa_stream_set_moved_callback ppa_stream_set_moved_callback
155 #define pa_stream_set_underflow_callback ppa_stream_set_underflow_callback
156 #define pa_stream_new_with_proplist ppa_stream_new_with_proplist
157 #define pa_stream_disconnect ppa_stream_disconnect
158 #define pa_threaded_mainloop_lock ppa_threaded_mainloop_lock
159 #define pa_channel_map_init_auto ppa_channel_map_init_auto
160 #define pa_channel_map_parse ppa_channel_map_parse
161 #define pa_channel_map_snprint ppa_channel_map_snprint
162 #define pa_channel_map_equal ppa_channel_map_equal
163 #define pa_context_get_server_info ppa_context_get_server_info
164 #define pa_context_get_sink_info_by_name ppa_context_get_sink_info_by_name
165 #define pa_context_get_sink_info_list ppa_context_get_sink_info_list
166 #define pa_context_get_source_info_by_name ppa_context_get_source_info_by_name
167 #define pa_context_get_source_info_list ppa_context_get_source_info_list
168 #define pa_operation_get_state ppa_operation_get_state
169 #define pa_operation_unref ppa_operation_unref
170 #define pa_proplist_new ppa_proplist_new
171 #define pa_proplist_free ppa_proplist_free
172 #define pa_proplist_set ppa_proplist_set
173 #define pa_channel_map_superset ppa_channel_map_superset
174 #define pa_stream_set_buffer_attr_callback ppa_stream_set_buffer_attr_callback
175 #define pa_stream_begin_write ppa_stream_begin_write
177 #endif
179 static ALCboolean pulse_load(void)
181 ALCboolean ret = ALC_TRUE;
182 #ifdef HAVE_DYNLOAD
183 if(!pa_handle)
185 al_string missing_funcs = AL_STRING_INIT_STATIC();
187 #ifdef _WIN32
188 #define PALIB "libpulse-0.dll"
189 #elif defined(__APPLE__) && defined(__MACH__)
190 #define PALIB "libpulse.0.dylib"
191 #else
192 #define PALIB "libpulse.so.0"
193 #endif
194 pa_handle = LoadLib(PALIB);
195 if(!pa_handle)
197 WARN("Failed to load %s\n", PALIB);
198 return ALC_FALSE;
201 #define LOAD_FUNC(x) do { \
202 p##x = GetSymbol(pa_handle, #x); \
203 if(!(p##x)) { \
204 ret = ALC_FALSE; \
205 alstr_append_cstr(&missing_funcs, "\n" #x); \
207 } while(0)
208 LOAD_FUNC(pa_context_unref);
209 LOAD_FUNC(pa_sample_spec_valid);
210 LOAD_FUNC(pa_stream_drop);
211 LOAD_FUNC(pa_frame_size);
212 LOAD_FUNC(pa_strerror);
213 LOAD_FUNC(pa_context_get_state);
214 LOAD_FUNC(pa_stream_get_state);
215 LOAD_FUNC(pa_threaded_mainloop_signal);
216 LOAD_FUNC(pa_stream_peek);
217 LOAD_FUNC(pa_threaded_mainloop_wait);
218 LOAD_FUNC(pa_threaded_mainloop_unlock);
219 LOAD_FUNC(pa_threaded_mainloop_in_thread);
220 LOAD_FUNC(pa_context_new);
221 LOAD_FUNC(pa_threaded_mainloop_stop);
222 LOAD_FUNC(pa_context_disconnect);
223 LOAD_FUNC(pa_threaded_mainloop_start);
224 LOAD_FUNC(pa_threaded_mainloop_get_api);
225 LOAD_FUNC(pa_context_set_state_callback);
226 LOAD_FUNC(pa_stream_write);
227 LOAD_FUNC(pa_xfree);
228 LOAD_FUNC(pa_stream_connect_record);
229 LOAD_FUNC(pa_stream_connect_playback);
230 LOAD_FUNC(pa_stream_readable_size);
231 LOAD_FUNC(pa_stream_writable_size);
232 LOAD_FUNC(pa_stream_is_corked);
233 LOAD_FUNC(pa_stream_cork);
234 LOAD_FUNC(pa_stream_is_suspended);
235 LOAD_FUNC(pa_stream_get_device_name);
236 LOAD_FUNC(pa_stream_get_latency);
237 LOAD_FUNC(pa_path_get_filename);
238 LOAD_FUNC(pa_get_binary_name);
239 LOAD_FUNC(pa_threaded_mainloop_free);
240 LOAD_FUNC(pa_context_errno);
241 LOAD_FUNC(pa_xmalloc);
242 LOAD_FUNC(pa_stream_unref);
243 LOAD_FUNC(pa_threaded_mainloop_accept);
244 LOAD_FUNC(pa_stream_set_write_callback);
245 LOAD_FUNC(pa_threaded_mainloop_new);
246 LOAD_FUNC(pa_context_connect);
247 LOAD_FUNC(pa_stream_set_buffer_attr);
248 LOAD_FUNC(pa_stream_get_buffer_attr);
249 LOAD_FUNC(pa_stream_get_sample_spec);
250 LOAD_FUNC(pa_stream_get_time);
251 LOAD_FUNC(pa_stream_set_read_callback);
252 LOAD_FUNC(pa_stream_set_state_callback);
253 LOAD_FUNC(pa_stream_set_moved_callback);
254 LOAD_FUNC(pa_stream_set_underflow_callback);
255 LOAD_FUNC(pa_stream_new_with_proplist);
256 LOAD_FUNC(pa_stream_disconnect);
257 LOAD_FUNC(pa_threaded_mainloop_lock);
258 LOAD_FUNC(pa_channel_map_init_auto);
259 LOAD_FUNC(pa_channel_map_parse);
260 LOAD_FUNC(pa_channel_map_snprint);
261 LOAD_FUNC(pa_channel_map_equal);
262 LOAD_FUNC(pa_context_get_server_info);
263 LOAD_FUNC(pa_context_get_sink_info_by_name);
264 LOAD_FUNC(pa_context_get_sink_info_list);
265 LOAD_FUNC(pa_context_get_source_info_by_name);
266 LOAD_FUNC(pa_context_get_source_info_list);
267 LOAD_FUNC(pa_operation_get_state);
268 LOAD_FUNC(pa_operation_unref);
269 LOAD_FUNC(pa_proplist_new);
270 LOAD_FUNC(pa_proplist_free);
271 LOAD_FUNC(pa_proplist_set);
272 LOAD_FUNC(pa_channel_map_superset);
273 LOAD_FUNC(pa_stream_set_buffer_attr_callback);
274 LOAD_FUNC(pa_stream_begin_write);
275 #undef LOAD_FUNC
277 if(ret == ALC_FALSE)
279 WARN("Missing expected functions:%s\n", alstr_get_cstr(missing_funcs));
280 CloseLib(pa_handle);
281 pa_handle = NULL;
283 alstr_reset(&missing_funcs);
285 #endif /* HAVE_DYNLOAD */
286 return ret;
290 /* Global flags and properties */
291 static pa_context_flags_t pulse_ctx_flags;
292 static pa_proplist *prop_filter;
295 /* PulseAudio Event Callbacks */
296 static void context_state_callback(pa_context *context, void *pdata)
298 pa_threaded_mainloop *loop = pdata;
299 pa_context_state_t state;
301 state = pa_context_get_state(context);
302 if(state == PA_CONTEXT_READY || !PA_CONTEXT_IS_GOOD(state))
303 pa_threaded_mainloop_signal(loop, 0);
306 static void stream_state_callback(pa_stream *stream, void *pdata)
308 pa_threaded_mainloop *loop = pdata;
309 pa_stream_state_t state;
311 state = pa_stream_get_state(stream);
312 if(state == PA_STREAM_READY || !PA_STREAM_IS_GOOD(state))
313 pa_threaded_mainloop_signal(loop, 0);
316 static void stream_success_callback(pa_stream *UNUSED(stream), int UNUSED(success), void *pdata)
318 pa_threaded_mainloop *loop = pdata;
319 pa_threaded_mainloop_signal(loop, 0);
322 static void wait_for_operation(pa_operation *op, pa_threaded_mainloop *loop)
324 if(op)
326 while(pa_operation_get_state(op) == PA_OPERATION_RUNNING)
327 pa_threaded_mainloop_wait(loop);
328 pa_operation_unref(op);
333 static pa_context *connect_context(pa_threaded_mainloop *loop, ALboolean silent)
335 const char *name = "OpenAL Soft";
336 char path_name[PATH_MAX];
337 pa_context_state_t state;
338 pa_context *context;
339 int err;
341 if(pa_get_binary_name(path_name, sizeof(path_name)))
342 name = pa_path_get_filename(path_name);
344 context = pa_context_new(pa_threaded_mainloop_get_api(loop), name);
345 if(!context)
347 ERR("pa_context_new() failed\n");
348 return NULL;
351 pa_context_set_state_callback(context, context_state_callback, loop);
353 if((err=pa_context_connect(context, NULL, pulse_ctx_flags, NULL)) >= 0)
355 while((state=pa_context_get_state(context)) != PA_CONTEXT_READY)
357 if(!PA_CONTEXT_IS_GOOD(state))
359 err = pa_context_errno(context);
360 if(err > 0) err = -err;
361 break;
364 pa_threaded_mainloop_wait(loop);
367 pa_context_set_state_callback(context, NULL, NULL);
369 if(err < 0)
371 if(!silent)
372 ERR("Context did not connect: %s\n", pa_strerror(err));
373 pa_context_unref(context);
374 return NULL;
377 return context;
381 static ALCboolean pulse_open(pa_threaded_mainloop **loop, pa_context **context,
382 void(*state_cb)(pa_context*,void*), void *ptr)
384 if(!(*loop = pa_threaded_mainloop_new()))
386 ERR("pa_threaded_mainloop_new() failed!\n");
387 return ALC_FALSE;
389 if(pa_threaded_mainloop_start(*loop) < 0)
391 ERR("pa_threaded_mainloop_start() failed\n");
392 goto error;
395 pa_threaded_mainloop_lock(*loop);
397 *context = connect_context(*loop, AL_FALSE);
398 if(!*context)
400 pa_threaded_mainloop_unlock(*loop);
401 pa_threaded_mainloop_stop(*loop);
402 goto error;
404 pa_context_set_state_callback(*context, state_cb, ptr);
406 pa_threaded_mainloop_unlock(*loop);
407 return ALC_TRUE;
409 error:
410 pa_threaded_mainloop_free(*loop);
411 *loop = NULL;
413 return ALC_FALSE;
416 static void pulse_close(pa_threaded_mainloop *loop, pa_context *context, pa_stream *stream)
418 pa_threaded_mainloop_lock(loop);
420 if(stream)
422 pa_stream_set_state_callback(stream, NULL, NULL);
423 pa_stream_set_moved_callback(stream, NULL, NULL);
424 pa_stream_set_write_callback(stream, NULL, NULL);
425 pa_stream_set_buffer_attr_callback(stream, NULL, NULL);
426 pa_stream_disconnect(stream);
427 pa_stream_unref(stream);
430 pa_context_disconnect(context);
431 pa_context_unref(context);
433 pa_threaded_mainloop_unlock(loop);
435 pa_threaded_mainloop_stop(loop);
436 pa_threaded_mainloop_free(loop);
440 typedef struct {
441 al_string name;
442 al_string device_name;
443 } DevMap;
444 TYPEDEF_VECTOR(DevMap, vector_DevMap)
446 static vector_DevMap PlaybackDevices;
447 static vector_DevMap CaptureDevices;
449 static void clear_devlist(vector_DevMap *list)
451 #define DEINIT_STRS(i) (AL_STRING_DEINIT((i)->name),AL_STRING_DEINIT((i)->device_name))
452 VECTOR_FOR_EACH(DevMap, *list, DEINIT_STRS);
453 #undef DEINIT_STRS
454 VECTOR_RESIZE(*list, 0, 0);
458 typedef struct ALCpulsePlayback {
459 DERIVE_FROM_TYPE(ALCbackend);
461 al_string device_name;
463 pa_buffer_attr attr;
464 pa_sample_spec spec;
466 pa_threaded_mainloop *loop;
468 pa_stream *stream;
469 pa_context *context;
471 volatile ALboolean killNow;
472 althrd_t thread;
473 } ALCpulsePlayback;
475 static void ALCpulsePlayback_deviceCallback(pa_context *context, const pa_sink_info *info, int eol, void *pdata);
476 static void ALCpulsePlayback_probeDevices(void);
478 static void ALCpulsePlayback_bufferAttrCallback(pa_stream *stream, void *pdata);
479 static void ALCpulsePlayback_contextStateCallback(pa_context *context, void *pdata);
480 static void ALCpulsePlayback_streamStateCallback(pa_stream *stream, void *pdata);
481 static void ALCpulsePlayback_streamWriteCallback(pa_stream *p, size_t nbytes, void *userdata);
482 static void ALCpulsePlayback_sinkInfoCallback(pa_context *context, const pa_sink_info *info, int eol, void *pdata);
483 static void ALCpulsePlayback_sinkNameCallback(pa_context *context, const pa_sink_info *info, int eol, void *pdata);
484 static void ALCpulsePlayback_streamMovedCallback(pa_stream *stream, void *pdata);
485 static pa_stream *ALCpulsePlayback_connectStream(const char *device_name, pa_threaded_mainloop *loop,
486 pa_context *context, pa_stream_flags_t flags,
487 pa_buffer_attr *attr, pa_sample_spec *spec,
488 pa_channel_map *chanmap);
489 static int ALCpulsePlayback_mixerProc(void *ptr);
491 static void ALCpulsePlayback_Construct(ALCpulsePlayback *self, ALCdevice *device);
492 static void ALCpulsePlayback_Destruct(ALCpulsePlayback *self);
493 static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name);
494 static void ALCpulsePlayback_close(ALCpulsePlayback *self);
495 static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self);
496 static ALCboolean ALCpulsePlayback_start(ALCpulsePlayback *self);
497 static void ALCpulsePlayback_stop(ALCpulsePlayback *self);
498 static DECLARE_FORWARD2(ALCpulsePlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
499 static DECLARE_FORWARD(ALCpulsePlayback, ALCbackend, ALCuint, availableSamples)
500 static ClockLatency ALCpulsePlayback_getClockLatency(ALCpulsePlayback *self);
501 static void ALCpulsePlayback_lock(ALCpulsePlayback *self);
502 static void ALCpulsePlayback_unlock(ALCpulsePlayback *self);
503 DECLARE_DEFAULT_ALLOCATORS(ALCpulsePlayback)
505 DEFINE_ALCBACKEND_VTABLE(ALCpulsePlayback);
508 static void ALCpulsePlayback_Construct(ALCpulsePlayback *self, ALCdevice *device)
510 ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
511 SET_VTABLE2(ALCpulsePlayback, ALCbackend, self);
513 AL_STRING_INIT(self->device_name);
516 static void ALCpulsePlayback_Destruct(ALCpulsePlayback *self)
518 AL_STRING_DEINIT(self->device_name);
519 ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
523 static void ALCpulsePlayback_deviceCallback(pa_context *UNUSED(context), const pa_sink_info *info, int eol, void *pdata)
525 pa_threaded_mainloop *loop = pdata;
526 const DevMap *iter;
527 DevMap entry;
528 int count;
530 if(eol)
532 pa_threaded_mainloop_signal(loop, 0);
533 return;
536 #define MATCH_INFO_NAME(iter) (alstr_cmp_cstr((iter)->device_name, info->name) == 0)
537 VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_INFO_NAME);
538 if(iter != VECTOR_END(PlaybackDevices)) return;
539 #undef MATCH_INFO_NAME
541 AL_STRING_INIT(entry.name);
542 AL_STRING_INIT(entry.device_name);
544 alstr_copy_cstr(&entry.device_name, info->name);
546 count = 0;
547 while(1)
549 alstr_copy_cstr(&entry.name, info->description);
550 if(count != 0)
552 char str[64];
553 snprintf(str, sizeof(str), " #%d", count+1);
554 alstr_append_cstr(&entry.name, str);
557 #define MATCH_ENTRY(i) (alstr_cmp(entry.name, (i)->name) == 0)
558 VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_ENTRY);
559 if(iter == VECTOR_END(PlaybackDevices)) break;
560 #undef MATCH_ENTRY
561 count++;
564 TRACE("Got device \"%s\", \"%s\"\n", alstr_get_cstr(entry.name), alstr_get_cstr(entry.device_name));
566 VECTOR_PUSH_BACK(PlaybackDevices, entry);
569 static void ALCpulsePlayback_probeDevices(void)
571 pa_threaded_mainloop *loop;
573 clear_devlist(&PlaybackDevices);
575 if((loop=pa_threaded_mainloop_new()) &&
576 pa_threaded_mainloop_start(loop) >= 0)
578 pa_context *context;
580 pa_threaded_mainloop_lock(loop);
581 context = connect_context(loop, AL_FALSE);
582 if(context)
584 pa_operation *o;
585 pa_stream_flags_t flags;
586 pa_sample_spec spec;
587 pa_stream *stream;
589 flags = PA_STREAM_FIX_FORMAT | PA_STREAM_FIX_RATE |
590 PA_STREAM_FIX_CHANNELS | PA_STREAM_DONT_MOVE;
592 spec.format = PA_SAMPLE_S16NE;
593 spec.rate = 44100;
594 spec.channels = 2;
596 stream = ALCpulsePlayback_connectStream(NULL, loop, context, flags,
597 NULL, &spec, NULL);
598 if(stream)
600 o = pa_context_get_sink_info_by_name(context, pa_stream_get_device_name(stream),
601 ALCpulsePlayback_deviceCallback, loop);
602 wait_for_operation(o, loop);
604 pa_stream_disconnect(stream);
605 pa_stream_unref(stream);
606 stream = NULL;
609 o = pa_context_get_sink_info_list(context, ALCpulsePlayback_deviceCallback, loop);
610 wait_for_operation(o, loop);
612 pa_context_disconnect(context);
613 pa_context_unref(context);
615 pa_threaded_mainloop_unlock(loop);
616 pa_threaded_mainloop_stop(loop);
618 if(loop)
619 pa_threaded_mainloop_free(loop);
623 static void ALCpulsePlayback_bufferAttrCallback(pa_stream *stream, void *pdata)
625 ALCpulsePlayback *self = pdata;
627 self->attr = *pa_stream_get_buffer_attr(stream);
628 TRACE("minreq=%d, tlength=%d, prebuf=%d\n", self->attr.minreq, self->attr.tlength, self->attr.prebuf);
631 static void ALCpulsePlayback_contextStateCallback(pa_context *context, void *pdata)
633 ALCpulsePlayback *self = pdata;
634 if(pa_context_get_state(context) == PA_CONTEXT_FAILED)
636 ERR("Received context failure!\n");
637 aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice);
639 pa_threaded_mainloop_signal(self->loop, 0);
642 static void ALCpulsePlayback_streamStateCallback(pa_stream *stream, void *pdata)
644 ALCpulsePlayback *self = pdata;
645 if(pa_stream_get_state(stream) == PA_STREAM_FAILED)
647 ERR("Received stream failure!\n");
648 aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice);
650 pa_threaded_mainloop_signal(self->loop, 0);
653 static void ALCpulsePlayback_streamWriteCallback(pa_stream* UNUSED(p), size_t UNUSED(nbytes), void *pdata)
655 ALCpulsePlayback *self = pdata;
656 pa_threaded_mainloop_signal(self->loop, 0);
659 static void ALCpulsePlayback_sinkInfoCallback(pa_context *UNUSED(context), const pa_sink_info *info, int eol, void *pdata)
661 static const struct {
662 enum DevFmtChannels chans;
663 pa_channel_map map;
664 } chanmaps[] = {
665 { DevFmtX71, { 8, {
666 PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
667 PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE,
668 PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT,
669 PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT
670 } } },
671 { DevFmtX61, { 7, {
672 PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
673 PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE,
674 PA_CHANNEL_POSITION_REAR_CENTER,
675 PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT
676 } } },
677 { DevFmtX51, { 6, {
678 PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
679 PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE,
680 PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT
681 } } },
682 { DevFmtX51Rear, { 6, {
683 PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
684 PA_CHANNEL_POSITION_FRONT_CENTER, PA_CHANNEL_POSITION_LFE,
685 PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT
686 } } },
687 { DevFmtQuad, { 4, {
688 PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT,
689 PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT
690 } } },
691 { DevFmtStereo, { 2, {
692 PA_CHANNEL_POSITION_FRONT_LEFT, PA_CHANNEL_POSITION_FRONT_RIGHT
693 } } },
694 { DevFmtMono, { 1, {PA_CHANNEL_POSITION_MONO} } }
696 ALCpulsePlayback *self = pdata;
697 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
698 size_t i;
700 if(eol)
702 pa_threaded_mainloop_signal(self->loop, 0);
703 return;
706 for(i = 0;i < COUNTOF(chanmaps);i++)
708 if(pa_channel_map_superset(&info->channel_map, &chanmaps[i].map))
710 if(!(device->Flags&DEVICE_CHANNELS_REQUEST))
711 device->FmtChans = chanmaps[i].chans;
712 break;
715 if(i == COUNTOF(chanmaps))
717 char chanmap_str[PA_CHANNEL_MAP_SNPRINT_MAX] = "";
718 pa_channel_map_snprint(chanmap_str, sizeof(chanmap_str), &info->channel_map);
719 WARN("Failed to find format for channel map:\n %s\n", chanmap_str);
722 if(info->active_port)
723 TRACE("Active port: %s (%s)\n", info->active_port->name, info->active_port->description);
724 device->IsHeadphones = (info->active_port &&
725 strcmp(info->active_port->name, "analog-output-headphones") == 0 &&
726 device->FmtChans == DevFmtStereo);
729 static void ALCpulsePlayback_sinkNameCallback(pa_context *UNUSED(context), const pa_sink_info *info, int eol, void *pdata)
731 ALCpulsePlayback *self = pdata;
732 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
734 if(eol)
736 pa_threaded_mainloop_signal(self->loop, 0);
737 return;
740 alstr_copy_cstr(&device->DeviceName, info->description);
744 static void ALCpulsePlayback_streamMovedCallback(pa_stream *stream, void *pdata)
746 ALCpulsePlayback *self = pdata;
748 alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
750 TRACE("Stream moved to %s\n", alstr_get_cstr(self->device_name));
754 static pa_stream *ALCpulsePlayback_connectStream(const char *device_name,
755 pa_threaded_mainloop *loop, pa_context *context,
756 pa_stream_flags_t flags, pa_buffer_attr *attr, pa_sample_spec *spec,
757 pa_channel_map *chanmap)
759 pa_stream_state_t state;
760 pa_stream *stream;
762 stream = pa_stream_new_with_proplist(context, "Playback Stream", spec, chanmap, prop_filter);
763 if(!stream)
765 ERR("pa_stream_new_with_proplist() failed: %s\n", pa_strerror(pa_context_errno(context)));
766 return NULL;
769 pa_stream_set_state_callback(stream, stream_state_callback, loop);
771 if(pa_stream_connect_playback(stream, device_name, attr, flags, NULL, NULL) < 0)
773 ERR("Stream did not connect: %s\n", pa_strerror(pa_context_errno(context)));
774 pa_stream_unref(stream);
775 return NULL;
778 while((state=pa_stream_get_state(stream)) != PA_STREAM_READY)
780 if(!PA_STREAM_IS_GOOD(state))
782 ERR("Stream did not get ready: %s\n", pa_strerror(pa_context_errno(context)));
783 pa_stream_unref(stream);
784 return NULL;
787 pa_threaded_mainloop_wait(loop);
789 pa_stream_set_state_callback(stream, NULL, NULL);
791 return stream;
795 static int ALCpulsePlayback_mixerProc(void *ptr)
797 ALCpulsePlayback *self = ptr;
798 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
799 ALuint buffer_size;
800 ALint update_size;
801 size_t frame_size;
802 ssize_t len;
804 SetRTPriority();
805 althrd_setname(althrd_current(), MIXER_THREAD_NAME);
807 pa_threaded_mainloop_lock(self->loop);
808 frame_size = pa_frame_size(&self->spec);
809 update_size = device->UpdateSize * frame_size;
811 /* Sanitize buffer metrics, in case we actually have less than what we
812 * asked for. */
813 buffer_size = minu(update_size*device->NumUpdates, self->attr.tlength);
814 update_size = minu(update_size, buffer_size/2);
815 do {
816 len = pa_stream_writable_size(self->stream) - self->attr.tlength +
817 buffer_size;
818 if(len < update_size)
820 if(pa_stream_is_corked(self->stream) == 1)
822 pa_operation *o;
823 o = pa_stream_cork(self->stream, 0, NULL, NULL);
824 if(o) pa_operation_unref(o);
826 pa_threaded_mainloop_wait(self->loop);
827 continue;
829 len -= len%update_size;
831 while(len > 0)
833 size_t newlen = len;
834 void *buf;
835 pa_free_cb_t free_func = NULL;
837 if(pa_stream_begin_write(self->stream, &buf, &newlen) < 0)
839 buf = pa_xmalloc(newlen);
840 free_func = pa_xfree;
843 aluMixData(device, buf, newlen/frame_size);
845 pa_stream_write(self->stream, buf, newlen, free_func, 0, PA_SEEK_RELATIVE);
846 len -= newlen;
848 } while(!self->killNow && device->Connected);
849 pa_threaded_mainloop_unlock(self->loop);
851 return 0;
855 static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name)
857 const_al_string dev_name = AL_STRING_INIT_STATIC();
858 const char *pulse_name = NULL;
859 pa_stream_flags_t flags;
860 pa_sample_spec spec;
862 if(name)
864 const DevMap *iter;
866 if(VECTOR_SIZE(PlaybackDevices) == 0)
867 ALCpulsePlayback_probeDevices();
869 #define MATCH_NAME(iter) (alstr_cmp_cstr((iter)->name, name) == 0)
870 VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
871 #undef MATCH_NAME
872 if(iter == VECTOR_END(PlaybackDevices))
873 return ALC_INVALID_VALUE;
874 pulse_name = alstr_get_cstr(iter->device_name);
875 dev_name = iter->name;
878 if(!pulse_open(&self->loop, &self->context, ALCpulsePlayback_contextStateCallback, self))
879 return ALC_INVALID_VALUE;
881 pa_threaded_mainloop_lock(self->loop);
883 flags = PA_STREAM_FIX_FORMAT | PA_STREAM_FIX_RATE |
884 PA_STREAM_FIX_CHANNELS;
885 if(!GetConfigValueBool(NULL, "pulse", "allow-moves", 0))
886 flags |= PA_STREAM_DONT_MOVE;
888 spec.format = PA_SAMPLE_S16NE;
889 spec.rate = 44100;
890 spec.channels = 2;
892 TRACE("Connecting to \"%s\"\n", pulse_name ? pulse_name : "(default)");
893 self->stream = ALCpulsePlayback_connectStream(pulse_name, self->loop, self->context,
894 flags, NULL, &spec, NULL);
895 if(!self->stream)
897 pa_threaded_mainloop_unlock(self->loop);
898 pulse_close(self->loop, self->context, self->stream);
899 self->loop = NULL;
900 self->context = NULL;
901 return ALC_INVALID_VALUE;
903 pa_stream_set_moved_callback(self->stream, ALCpulsePlayback_streamMovedCallback, self);
905 alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
906 if(alstr_empty(dev_name))
908 pa_operation *o = pa_context_get_sink_info_by_name(
909 self->context, alstr_get_cstr(self->device_name),
910 ALCpulsePlayback_sinkNameCallback, self
912 wait_for_operation(o, self->loop);
914 else
916 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
917 alstr_copy(&device->DeviceName, dev_name);
920 pa_threaded_mainloop_unlock(self->loop);
922 return ALC_NO_ERROR;
925 static void ALCpulsePlayback_close(ALCpulsePlayback *self)
927 pulse_close(self->loop, self->context, self->stream);
928 self->loop = NULL;
929 self->context = NULL;
930 self->stream = NULL;
932 alstr_clear(&self->device_name);
935 static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
937 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
938 pa_stream_flags_t flags = 0;
939 const char *mapname = NULL;
940 pa_channel_map chanmap;
941 pa_operation *o;
942 ALuint len;
944 pa_threaded_mainloop_lock(self->loop);
946 if(self->stream)
948 pa_stream_set_state_callback(self->stream, NULL, NULL);
949 pa_stream_set_moved_callback(self->stream, NULL, NULL);
950 pa_stream_set_write_callback(self->stream, NULL, NULL);
951 pa_stream_set_buffer_attr_callback(self->stream, NULL, NULL);
952 pa_stream_disconnect(self->stream);
953 pa_stream_unref(self->stream);
954 self->stream = NULL;
957 o = pa_context_get_sink_info_by_name(self->context, alstr_get_cstr(self->device_name),
958 ALCpulsePlayback_sinkInfoCallback, self);
959 wait_for_operation(o, self->loop);
961 if(GetConfigValueBool(alstr_get_cstr(device->DeviceName), "pulse", "fix-rate", 0) ||
962 !(device->Flags&DEVICE_FREQUENCY_REQUEST))
963 flags |= PA_STREAM_FIX_RATE;
964 flags |= PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE;
965 flags |= PA_STREAM_ADJUST_LATENCY;
966 flags |= PA_STREAM_START_CORKED;
967 if(!GetConfigValueBool(NULL, "pulse", "allow-moves", 0))
968 flags |= PA_STREAM_DONT_MOVE;
970 switch(device->FmtType)
972 case DevFmtByte:
973 device->FmtType = DevFmtUByte;
974 /* fall-through */
975 case DevFmtUByte:
976 self->spec.format = PA_SAMPLE_U8;
977 break;
978 case DevFmtUShort:
979 device->FmtType = DevFmtShort;
980 /* fall-through */
981 case DevFmtShort:
982 self->spec.format = PA_SAMPLE_S16NE;
983 break;
984 case DevFmtUInt:
985 device->FmtType = DevFmtInt;
986 /* fall-through */
987 case DevFmtInt:
988 self->spec.format = PA_SAMPLE_S32NE;
989 break;
990 case DevFmtFloat:
991 self->spec.format = PA_SAMPLE_FLOAT32NE;
992 break;
994 self->spec.rate = device->Frequency;
995 self->spec.channels = ChannelsFromDevFmt(device->FmtChans);
997 if(pa_sample_spec_valid(&self->spec) == 0)
999 ERR("Invalid sample format\n");
1000 pa_threaded_mainloop_unlock(self->loop);
1001 return ALC_FALSE;
1004 switch(device->FmtChans)
1006 case DevFmtMono:
1007 mapname = "mono";
1008 break;
1009 case DevFmtAmbi1:
1010 case DevFmtAmbi2:
1011 case DevFmtAmbi3:
1012 device->FmtChans = DevFmtStereo;
1013 /*fall-through*/
1014 case DevFmtStereo:
1015 mapname = "front-left,front-right";
1016 break;
1017 case DevFmtQuad:
1018 mapname = "front-left,front-right,rear-left,rear-right";
1019 break;
1020 case DevFmtX51:
1021 mapname = "front-left,front-right,front-center,lfe,side-left,side-right";
1022 break;
1023 case DevFmtX51Rear:
1024 mapname = "front-left,front-right,front-center,lfe,rear-left,rear-right";
1025 break;
1026 case DevFmtX61:
1027 mapname = "front-left,front-right,front-center,lfe,rear-center,side-left,side-right";
1028 break;
1029 case DevFmtX71:
1030 mapname = "front-left,front-right,front-center,lfe,rear-left,rear-right,side-left,side-right";
1031 break;
1033 if(!pa_channel_map_parse(&chanmap, mapname))
1035 ERR("Failed to build channel map for %s\n", DevFmtChannelsString(device->FmtChans));
1036 pa_threaded_mainloop_unlock(self->loop);
1037 return ALC_FALSE;
1039 SetDefaultWFXChannelOrder(device);
1041 self->attr.fragsize = -1;
1042 self->attr.prebuf = 0;
1043 self->attr.minreq = device->UpdateSize * pa_frame_size(&self->spec);
1044 self->attr.tlength = self->attr.minreq * maxu(device->NumUpdates, 2);
1045 self->attr.maxlength = -1;
1047 self->stream = ALCpulsePlayback_connectStream(alstr_get_cstr(self->device_name),
1048 self->loop, self->context, flags,
1049 &self->attr, &self->spec, &chanmap);
1050 if(!self->stream)
1052 pa_threaded_mainloop_unlock(self->loop);
1053 return ALC_FALSE;
1055 pa_stream_set_state_callback(self->stream, ALCpulsePlayback_streamStateCallback, self);
1056 pa_stream_set_moved_callback(self->stream, ALCpulsePlayback_streamMovedCallback, self);
1057 pa_stream_set_write_callback(self->stream, ALCpulsePlayback_streamWriteCallback, self);
1059 self->spec = *(pa_stream_get_sample_spec(self->stream));
1060 if(device->Frequency != self->spec.rate)
1062 /* Server updated our playback rate, so modify the buffer attribs
1063 * accordingly. */
1064 device->NumUpdates = (ALuint)clampd(
1065 (ALdouble)device->NumUpdates/device->Frequency*self->spec.rate + 0.5, 2.0, 16.0
1068 self->attr.minreq = device->UpdateSize * pa_frame_size(&self->spec);
1069 self->attr.tlength = self->attr.minreq * device->NumUpdates;
1070 self->attr.maxlength = -1;
1071 self->attr.prebuf = 0;
1073 o = pa_stream_set_buffer_attr(self->stream, &self->attr,
1074 stream_success_callback, self->loop);
1075 wait_for_operation(o, self->loop);
1077 device->Frequency = self->spec.rate;
1080 pa_stream_set_buffer_attr_callback(self->stream, ALCpulsePlayback_bufferAttrCallback, self);
1081 ALCpulsePlayback_bufferAttrCallback(self->stream, self);
1083 len = self->attr.minreq / pa_frame_size(&self->spec);
1084 device->NumUpdates = (ALuint)clampd(
1085 (ALdouble)device->NumUpdates/len*device->UpdateSize + 0.5, 2.0, 16.0
1087 device->UpdateSize = len;
1089 /* HACK: prebuf should be 0 as that's what we set it to. However on some
1090 * systems it comes back as non-0, so we have to make sure the device will
1091 * write enough audio to start playback. The lack of manual start control
1092 * may have unintended consequences, but it's better than not starting at
1093 * all.
1095 if(self->attr.prebuf != 0)
1097 len = self->attr.prebuf / pa_frame_size(&self->spec);
1098 if(len <= device->UpdateSize*device->NumUpdates)
1099 ERR("Non-0 prebuf, %u samples (%u bytes), device has %u samples\n",
1100 len, self->attr.prebuf, device->UpdateSize*device->NumUpdates);
1101 else
1103 ERR("Large prebuf, %u samples (%u bytes), increasing device from %u samples",
1104 len, self->attr.prebuf, device->UpdateSize*device->NumUpdates);
1105 device->NumUpdates = (len+device->UpdateSize-1) / device->UpdateSize;
1109 pa_threaded_mainloop_unlock(self->loop);
1110 return ALC_TRUE;
1113 static ALCboolean ALCpulsePlayback_start(ALCpulsePlayback *self)
1115 self->killNow = AL_FALSE;
1116 if(althrd_create(&self->thread, ALCpulsePlayback_mixerProc, self) != althrd_success)
1117 return ALC_FALSE;
1118 return ALC_TRUE;
1121 static void ALCpulsePlayback_stop(ALCpulsePlayback *self)
1123 pa_operation *o;
1124 int res;
1126 if(!self->stream || self->killNow)
1127 return;
1129 self->killNow = AL_TRUE;
1130 /* Signal the main loop in case PulseAudio isn't sending us audio requests
1131 * (e.g. if the device is suspended). We need to lock the mainloop in case
1132 * the mixer is between checking the killNow flag but before waiting for
1133 * the signal.
1135 pa_threaded_mainloop_lock(self->loop);
1136 pa_threaded_mainloop_unlock(self->loop);
1137 pa_threaded_mainloop_signal(self->loop, 0);
1138 althrd_join(self->thread, &res);
1140 pa_threaded_mainloop_lock(self->loop);
1142 o = pa_stream_cork(self->stream, 1, stream_success_callback, self->loop);
1143 wait_for_operation(o, self->loop);
1145 pa_threaded_mainloop_unlock(self->loop);
1149 static ClockLatency ALCpulsePlayback_getClockLatency(ALCpulsePlayback *self)
1151 pa_usec_t latency = 0;
1152 ClockLatency ret;
1153 int neg, err;
1155 pa_threaded_mainloop_lock(self->loop);
1156 ret.ClockTime = GetDeviceClockTime(STATIC_CAST(ALCbackend,self)->mDevice);
1157 if((err=pa_stream_get_latency(self->stream, &latency, &neg)) != 0)
1159 /* FIXME: if err = -PA_ERR_NODATA, it means we were called too soon
1160 * after starting the stream and no timing info has been received from
1161 * the server yet. Should we wait, possibly stalling the app, or give a
1162 * dummy value? Either way, it shouldn't be 0. */
1163 if(err != -PA_ERR_NODATA)
1164 ERR("Failed to get stream latency: 0x%x\n", err);
1165 latency = 0;
1166 neg = 0;
1168 if(neg) latency = 0;
1169 ret.Latency = minu64(latency, U64(0xffffffffffffffff)/1000) * 1000;
1170 pa_threaded_mainloop_unlock(self->loop);
1172 return ret;
1176 static void ALCpulsePlayback_lock(ALCpulsePlayback *self)
1178 pa_threaded_mainloop_lock(self->loop);
1181 static void ALCpulsePlayback_unlock(ALCpulsePlayback *self)
1183 pa_threaded_mainloop_unlock(self->loop);
1187 typedef struct ALCpulseCapture {
1188 DERIVE_FROM_TYPE(ALCbackend);
1190 al_string device_name;
1192 const void *cap_store;
1193 size_t cap_len;
1194 size_t cap_remain;
1196 ALCuint last_readable;
1198 pa_buffer_attr attr;
1199 pa_sample_spec spec;
1201 pa_threaded_mainloop *loop;
1203 pa_stream *stream;
1204 pa_context *context;
1205 } ALCpulseCapture;
1207 static void ALCpulseCapture_deviceCallback(pa_context *context, const pa_source_info *info, int eol, void *pdata);
1208 static void ALCpulseCapture_probeDevices(void);
1210 static void ALCpulseCapture_contextStateCallback(pa_context *context, void *pdata);
1211 static void ALCpulseCapture_streamStateCallback(pa_stream *stream, void *pdata);
1212 static void ALCpulseCapture_sourceNameCallback(pa_context *context, const pa_source_info *info, int eol, void *pdata);
1213 static void ALCpulseCapture_streamMovedCallback(pa_stream *stream, void *pdata);
1214 static pa_stream *ALCpulseCapture_connectStream(const char *device_name,
1215 pa_threaded_mainloop *loop, pa_context *context,
1216 pa_stream_flags_t flags, pa_buffer_attr *attr,
1217 pa_sample_spec *spec, pa_channel_map *chanmap);
1219 static void ALCpulseCapture_Construct(ALCpulseCapture *self, ALCdevice *device);
1220 static void ALCpulseCapture_Destruct(ALCpulseCapture *self);
1221 static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name);
1222 static void ALCpulseCapture_close(ALCpulseCapture *self);
1223 static DECLARE_FORWARD(ALCpulseCapture, ALCbackend, ALCboolean, reset)
1224 static ALCboolean ALCpulseCapture_start(ALCpulseCapture *self);
1225 static void ALCpulseCapture_stop(ALCpulseCapture *self);
1226 static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *buffer, ALCuint samples);
1227 static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self);
1228 static ClockLatency ALCpulseCapture_getClockLatency(ALCpulseCapture *self);
1229 static void ALCpulseCapture_lock(ALCpulseCapture *self);
1230 static void ALCpulseCapture_unlock(ALCpulseCapture *self);
1231 DECLARE_DEFAULT_ALLOCATORS(ALCpulseCapture)
1233 DEFINE_ALCBACKEND_VTABLE(ALCpulseCapture);
1236 static void ALCpulseCapture_Construct(ALCpulseCapture *self, ALCdevice *device)
1238 ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
1239 SET_VTABLE2(ALCpulseCapture, ALCbackend, self);
1241 AL_STRING_INIT(self->device_name);
1244 static void ALCpulseCapture_Destruct(ALCpulseCapture *self)
1246 AL_STRING_DEINIT(self->device_name);
1247 ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
1251 static void ALCpulseCapture_deviceCallback(pa_context *UNUSED(context), const pa_source_info *info, int eol, void *pdata)
1253 pa_threaded_mainloop *loop = pdata;
1254 const DevMap *iter;
1255 DevMap entry;
1256 int count;
1258 if(eol)
1260 pa_threaded_mainloop_signal(loop, 0);
1261 return;
1264 #define MATCH_INFO_NAME(iter) (alstr_cmp_cstr((iter)->device_name, info->name) == 0)
1265 VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_INFO_NAME);
1266 if(iter != VECTOR_END(CaptureDevices)) return;
1267 #undef MATCH_INFO_NAME
1269 AL_STRING_INIT(entry.name);
1270 AL_STRING_INIT(entry.device_name);
1272 alstr_copy_cstr(&entry.device_name, info->name);
1274 count = 0;
1275 while(1)
1277 alstr_copy_cstr(&entry.name, info->description);
1278 if(count != 0)
1280 char str[64];
1281 snprintf(str, sizeof(str), " #%d", count+1);
1282 alstr_append_cstr(&entry.name, str);
1285 #define MATCH_ENTRY(i) (alstr_cmp(entry.name, (i)->name) == 0)
1286 VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_ENTRY);
1287 if(iter == VECTOR_END(CaptureDevices)) break;
1288 #undef MATCH_ENTRY
1289 count++;
1292 TRACE("Got device \"%s\", \"%s\"\n", alstr_get_cstr(entry.name), alstr_get_cstr(entry.device_name));
1294 VECTOR_PUSH_BACK(CaptureDevices, entry);
1297 static void ALCpulseCapture_probeDevices(void)
1299 pa_threaded_mainloop *loop;
1301 clear_devlist(&CaptureDevices);
1303 if((loop=pa_threaded_mainloop_new()) &&
1304 pa_threaded_mainloop_start(loop) >= 0)
1306 pa_context *context;
1308 pa_threaded_mainloop_lock(loop);
1309 context = connect_context(loop, AL_FALSE);
1310 if(context)
1312 pa_operation *o;
1313 pa_stream_flags_t flags;
1314 pa_sample_spec spec;
1315 pa_stream *stream;
1317 flags = PA_STREAM_FIX_FORMAT | PA_STREAM_FIX_RATE |
1318 PA_STREAM_FIX_CHANNELS | PA_STREAM_DONT_MOVE;
1320 spec.format = PA_SAMPLE_S16NE;
1321 spec.rate = 44100;
1322 spec.channels = 1;
1324 stream = ALCpulseCapture_connectStream(NULL, loop, context, flags,
1325 NULL, &spec, NULL);
1326 if(stream)
1328 o = pa_context_get_source_info_by_name(context, pa_stream_get_device_name(stream),
1329 ALCpulseCapture_deviceCallback, loop);
1330 wait_for_operation(o, loop);
1332 pa_stream_disconnect(stream);
1333 pa_stream_unref(stream);
1334 stream = NULL;
1337 o = pa_context_get_source_info_list(context, ALCpulseCapture_deviceCallback, loop);
1338 wait_for_operation(o, loop);
1340 pa_context_disconnect(context);
1341 pa_context_unref(context);
1343 pa_threaded_mainloop_unlock(loop);
1344 pa_threaded_mainloop_stop(loop);
1346 if(loop)
1347 pa_threaded_mainloop_free(loop);
1351 static void ALCpulseCapture_contextStateCallback(pa_context *context, void *pdata)
1353 ALCpulseCapture *self = pdata;
1354 if(pa_context_get_state(context) == PA_CONTEXT_FAILED)
1356 ERR("Received context failure!\n");
1357 aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice);
1359 pa_threaded_mainloop_signal(self->loop, 0);
1362 static void ALCpulseCapture_streamStateCallback(pa_stream *stream, void *pdata)
1364 ALCpulseCapture *self = pdata;
1365 if(pa_stream_get_state(stream) == PA_STREAM_FAILED)
1367 ERR("Received stream failure!\n");
1368 aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice);
1370 pa_threaded_mainloop_signal(self->loop, 0);
1374 static void ALCpulseCapture_sourceNameCallback(pa_context *UNUSED(context), const pa_source_info *info, int eol, void *pdata)
1376 ALCpulseCapture *self = pdata;
1377 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
1379 if(eol)
1381 pa_threaded_mainloop_signal(self->loop, 0);
1382 return;
1385 alstr_copy_cstr(&device->DeviceName, info->description);
1389 static void ALCpulseCapture_streamMovedCallback(pa_stream *stream, void *pdata)
1391 ALCpulseCapture *self = pdata;
1393 alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
1395 TRACE("Stream moved to %s\n", alstr_get_cstr(self->device_name));
1399 static pa_stream *ALCpulseCapture_connectStream(const char *device_name,
1400 pa_threaded_mainloop *loop, pa_context *context,
1401 pa_stream_flags_t flags, pa_buffer_attr *attr, pa_sample_spec *spec,
1402 pa_channel_map *chanmap)
1404 pa_stream_state_t state;
1405 pa_stream *stream;
1407 stream = pa_stream_new_with_proplist(context, "Capture Stream", spec, chanmap, prop_filter);
1408 if(!stream)
1410 ERR("pa_stream_new_with_proplist() failed: %s\n", pa_strerror(pa_context_errno(context)));
1411 return NULL;
1414 pa_stream_set_state_callback(stream, stream_state_callback, loop);
1416 if(pa_stream_connect_record(stream, device_name, attr, flags) < 0)
1418 ERR("Stream did not connect: %s\n", pa_strerror(pa_context_errno(context)));
1419 pa_stream_unref(stream);
1420 return NULL;
1423 while((state=pa_stream_get_state(stream)) != PA_STREAM_READY)
1425 if(!PA_STREAM_IS_GOOD(state))
1427 ERR("Stream did not get ready: %s\n", pa_strerror(pa_context_errno(context)));
1428 pa_stream_unref(stream);
1429 return NULL;
1432 pa_threaded_mainloop_wait(loop);
1434 pa_stream_set_state_callback(stream, NULL, NULL);
1436 return stream;
1440 static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
1442 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
1443 const char *pulse_name = NULL;
1444 pa_stream_flags_t flags = 0;
1445 pa_channel_map chanmap;
1446 ALuint samples;
1448 if(name)
1450 const DevMap *iter;
1452 if(VECTOR_SIZE(CaptureDevices) == 0)
1453 ALCpulseCapture_probeDevices();
1455 #define MATCH_NAME(iter) (alstr_cmp_cstr((iter)->name, name) == 0)
1456 VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
1457 #undef MATCH_NAME
1458 if(iter == VECTOR_END(CaptureDevices))
1459 return ALC_INVALID_VALUE;
1460 pulse_name = alstr_get_cstr(iter->device_name);
1461 alstr_copy(&device->DeviceName, iter->name);
1464 if(!pulse_open(&self->loop, &self->context, ALCpulseCapture_contextStateCallback, self))
1465 return ALC_INVALID_VALUE;
1467 pa_threaded_mainloop_lock(self->loop);
1469 self->spec.rate = device->Frequency;
1470 self->spec.channels = ChannelsFromDevFmt(device->FmtChans);
1472 switch(device->FmtType)
1474 case DevFmtUByte:
1475 self->spec.format = PA_SAMPLE_U8;
1476 break;
1477 case DevFmtShort:
1478 self->spec.format = PA_SAMPLE_S16NE;
1479 break;
1480 case DevFmtInt:
1481 self->spec.format = PA_SAMPLE_S32NE;
1482 break;
1483 case DevFmtFloat:
1484 self->spec.format = PA_SAMPLE_FLOAT32NE;
1485 break;
1486 case DevFmtByte:
1487 case DevFmtUShort:
1488 case DevFmtUInt:
1489 ERR("%s capture samples not supported\n", DevFmtTypeString(device->FmtType));
1490 pa_threaded_mainloop_unlock(self->loop);
1491 goto fail;
1494 if(pa_sample_spec_valid(&self->spec) == 0)
1496 ERR("Invalid sample format\n");
1497 pa_threaded_mainloop_unlock(self->loop);
1498 goto fail;
1501 if(!pa_channel_map_init_auto(&chanmap, self->spec.channels, PA_CHANNEL_MAP_WAVEEX))
1503 ERR("Couldn't build map for channel count (%d)!\n", self->spec.channels);
1504 pa_threaded_mainloop_unlock(self->loop);
1505 goto fail;
1508 samples = device->UpdateSize * device->NumUpdates;
1509 samples = maxu(samples, 100 * device->Frequency / 1000);
1511 self->attr.minreq = -1;
1512 self->attr.prebuf = -1;
1513 self->attr.maxlength = samples * pa_frame_size(&self->spec);
1514 self->attr.tlength = -1;
1515 self->attr.fragsize = minu(samples, 50*device->Frequency/1000) *
1516 pa_frame_size(&self->spec);
1518 flags |= PA_STREAM_START_CORKED|PA_STREAM_ADJUST_LATENCY;
1519 if(!GetConfigValueBool(NULL, "pulse", "allow-moves", 0))
1520 flags |= PA_STREAM_DONT_MOVE;
1522 TRACE("Connecting to \"%s\"\n", pulse_name ? pulse_name : "(default)");
1523 self->stream = ALCpulseCapture_connectStream(pulse_name, self->loop, self->context,
1524 flags, &self->attr, &self->spec,
1525 &chanmap);
1526 if(!self->stream)
1528 pa_threaded_mainloop_unlock(self->loop);
1529 goto fail;
1531 pa_stream_set_moved_callback(self->stream, ALCpulseCapture_streamMovedCallback, self);
1532 pa_stream_set_state_callback(self->stream, ALCpulseCapture_streamStateCallback, self);
1534 alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
1535 if(alstr_empty(device->DeviceName))
1537 pa_operation *o = pa_context_get_source_info_by_name(
1538 self->context, alstr_get_cstr(self->device_name),
1539 ALCpulseCapture_sourceNameCallback, self
1541 wait_for_operation(o, self->loop);
1544 pa_threaded_mainloop_unlock(self->loop);
1545 return ALC_NO_ERROR;
1547 fail:
1548 pulse_close(self->loop, self->context, self->stream);
1549 self->loop = NULL;
1550 self->context = NULL;
1551 self->stream = NULL;
1553 return ALC_INVALID_VALUE;
1556 static void ALCpulseCapture_close(ALCpulseCapture *self)
1558 pulse_close(self->loop, self->context, self->stream);
1559 self->loop = NULL;
1560 self->context = NULL;
1561 self->stream = NULL;
1563 alstr_clear(&self->device_name);
1566 static ALCboolean ALCpulseCapture_start(ALCpulseCapture *self)
1568 pa_operation *o;
1569 pa_threaded_mainloop_lock(self->loop);
1570 o = pa_stream_cork(self->stream, 0, stream_success_callback, self->loop);
1571 wait_for_operation(o, self->loop);
1572 pa_threaded_mainloop_unlock(self->loop);
1573 return ALC_TRUE;
1576 static void ALCpulseCapture_stop(ALCpulseCapture *self)
1578 pa_operation *o;
1579 pa_threaded_mainloop_lock(self->loop);
1580 o = pa_stream_cork(self->stream, 1, stream_success_callback, self->loop);
1581 wait_for_operation(o, self->loop);
1582 pa_threaded_mainloop_unlock(self->loop);
1585 static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *buffer, ALCuint samples)
1587 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
1588 ALCuint todo = samples * pa_frame_size(&self->spec);
1590 /* Capture is done in fragment-sized chunks, so we loop until we get all
1591 * that's available */
1592 self->last_readable -= todo;
1593 pa_threaded_mainloop_lock(self->loop);
1594 while(todo > 0)
1596 size_t rem = todo;
1598 if(self->cap_len == 0)
1600 pa_stream_state_t state;
1602 state = pa_stream_get_state(self->stream);
1603 if(!PA_STREAM_IS_GOOD(state))
1605 aluHandleDisconnect(device);
1606 break;
1608 if(pa_stream_peek(self->stream, &self->cap_store, &self->cap_len) < 0)
1610 ERR("pa_stream_peek() failed: %s\n",
1611 pa_strerror(pa_context_errno(self->context)));
1612 aluHandleDisconnect(device);
1613 break;
1615 self->cap_remain = self->cap_len;
1617 if(rem > self->cap_remain)
1618 rem = self->cap_remain;
1620 memcpy(buffer, self->cap_store, rem);
1622 buffer = (ALbyte*)buffer + rem;
1623 todo -= rem;
1625 self->cap_store = (ALbyte*)self->cap_store + rem;
1626 self->cap_remain -= rem;
1627 if(self->cap_remain == 0)
1629 pa_stream_drop(self->stream);
1630 self->cap_len = 0;
1633 pa_threaded_mainloop_unlock(self->loop);
1634 if(todo > 0)
1635 memset(buffer, ((device->FmtType==DevFmtUByte) ? 0x80 : 0), todo);
1637 return ALC_NO_ERROR;
1640 static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self)
1642 ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
1643 size_t readable = self->cap_remain;
1645 if(device->Connected)
1647 ssize_t got;
1648 pa_threaded_mainloop_lock(self->loop);
1649 got = pa_stream_readable_size(self->stream);
1650 if(got < 0)
1652 ERR("pa_stream_readable_size() failed: %s\n", pa_strerror(got));
1653 aluHandleDisconnect(device);
1655 else if((size_t)got > self->cap_len)
1656 readable += got - self->cap_len;
1657 pa_threaded_mainloop_unlock(self->loop);
1660 if(self->last_readable < readable)
1661 self->last_readable = readable;
1662 return self->last_readable / pa_frame_size(&self->spec);
1666 static ClockLatency ALCpulseCapture_getClockLatency(ALCpulseCapture *self)
1668 pa_usec_t latency = 0;
1669 ClockLatency ret;
1670 int neg, err;
1672 pa_threaded_mainloop_lock(self->loop);
1673 ret.ClockTime = GetDeviceClockTime(STATIC_CAST(ALCbackend,self)->mDevice);
1674 if((err=pa_stream_get_latency(self->stream, &latency, &neg)) != 0)
1676 ERR("Failed to get stream latency: 0x%x\n", err);
1677 latency = 0;
1678 neg = 0;
1680 if(neg) latency = 0;
1681 ret.Latency = minu64(latency, U64(0xffffffffffffffff)/1000) * 1000;
1682 pa_threaded_mainloop_unlock(self->loop);
1684 return ret;
1688 static void ALCpulseCapture_lock(ALCpulseCapture *self)
1690 pa_threaded_mainloop_lock(self->loop);
1693 static void ALCpulseCapture_unlock(ALCpulseCapture *self)
1695 pa_threaded_mainloop_unlock(self->loop);
1699 typedef struct ALCpulseBackendFactory {
1700 DERIVE_FROM_TYPE(ALCbackendFactory);
1701 } ALCpulseBackendFactory;
1702 #define ALCPULSEBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCpulseBackendFactory, ALCbackendFactory) } }
1704 static ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory *self);
1705 static void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory *self);
1706 static ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory *self, ALCbackend_Type type);
1707 static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory *self, enum DevProbe type);
1708 static ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
1710 DEFINE_ALCBACKENDFACTORY_VTABLE(ALCpulseBackendFactory);
1713 static ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory* UNUSED(self))
1715 ALCboolean ret = ALC_FALSE;
1717 VECTOR_INIT(PlaybackDevices);
1718 VECTOR_INIT(CaptureDevices);
1720 if(pulse_load())
1722 pa_threaded_mainloop *loop;
1724 pulse_ctx_flags = 0;
1725 if(!GetConfigValueBool(NULL, "pulse", "spawn-server", 1))
1726 pulse_ctx_flags |= PA_CONTEXT_NOAUTOSPAWN;
1728 if((loop=pa_threaded_mainloop_new()) &&
1729 pa_threaded_mainloop_start(loop) >= 0)
1731 pa_context *context;
1733 pa_threaded_mainloop_lock(loop);
1734 context = connect_context(loop, AL_TRUE);
1735 if(context)
1737 ret = ALC_TRUE;
1739 /* Some libraries (Phonon, Qt) set some pulseaudio properties
1740 * through environment variables, which causes all streams in
1741 * the process to inherit them. This attempts to filter those
1742 * properties out by setting them to 0-length data. */
1743 prop_filter = pa_proplist_new();
1744 pa_proplist_set(prop_filter, PA_PROP_MEDIA_ROLE, NULL, 0);
1745 pa_proplist_set(prop_filter, "phonon.streamid", NULL, 0);
1747 pa_context_disconnect(context);
1748 pa_context_unref(context);
1750 pa_threaded_mainloop_unlock(loop);
1751 pa_threaded_mainloop_stop(loop);
1753 if(loop)
1754 pa_threaded_mainloop_free(loop);
1757 return ret;
1760 static void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory* UNUSED(self))
1762 clear_devlist(&PlaybackDevices);
1763 VECTOR_DEINIT(PlaybackDevices);
1765 clear_devlist(&CaptureDevices);
1766 VECTOR_DEINIT(CaptureDevices);
1768 if(prop_filter)
1769 pa_proplist_free(prop_filter);
1770 prop_filter = NULL;
1772 /* PulseAudio doesn't like being CloseLib'd sometimes */
1775 static ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory* UNUSED(self), ALCbackend_Type type)
1777 if(type == ALCbackend_Playback || type == ALCbackend_Capture)
1778 return ALC_TRUE;
1779 return ALC_FALSE;
1782 static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe type)
1784 switch(type)
1786 case ALL_DEVICE_PROBE:
1787 ALCpulsePlayback_probeDevices();
1788 #define APPEND_ALL_DEVICES_LIST(e) AppendAllDevicesList(alstr_get_cstr((e)->name))
1789 VECTOR_FOR_EACH(const DevMap, PlaybackDevices, APPEND_ALL_DEVICES_LIST);
1790 #undef APPEND_ALL_DEVICES_LIST
1791 break;
1793 case CAPTURE_DEVICE_PROBE:
1794 ALCpulseCapture_probeDevices();
1795 #define APPEND_CAPTURE_DEVICE_LIST(e) AppendCaptureDeviceList(alstr_get_cstr((e)->name))
1796 VECTOR_FOR_EACH(const DevMap, CaptureDevices, APPEND_CAPTURE_DEVICE_LIST);
1797 #undef APPEND_CAPTURE_DEVICE_LIST
1798 break;
1802 static ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
1804 if(type == ALCbackend_Playback)
1806 ALCpulsePlayback *backend;
1807 NEW_OBJ(backend, ALCpulsePlayback)(device);
1808 if(!backend) return NULL;
1809 return STATIC_CAST(ALCbackend, backend);
1811 if(type == ALCbackend_Capture)
1813 ALCpulseCapture *backend;
1814 NEW_OBJ(backend, ALCpulseCapture)(device);
1815 if(!backend) return NULL;
1816 return STATIC_CAST(ALCbackend, backend);
1819 return NULL;
1823 #else /* PA_API_VERSION == 12 */
1825 #warning "Unsupported API version, backend will be unavailable!"
1827 typedef struct ALCpulseBackendFactory {
1828 DERIVE_FROM_TYPE(ALCbackendFactory);
1829 } ALCpulseBackendFactory;
1830 #define ALCPULSEBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCpulseBackendFactory, ALCbackendFactory) } }
1832 static ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory* UNUSED(self))
1834 return ALC_FALSE;
1837 static void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory* UNUSED(self))
1841 static ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory* UNUSED(self), ALCbackend_Type UNUSED(type))
1843 return ALC_FALSE;
1846 static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe UNUSED(type))
1850 static ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory* UNUSED(self), ALCdevice* UNUSED(device), ALCbackend_Type UNUSED(type))
1852 return NULL;
1855 DEFINE_ALCBACKENDFACTORY_VTABLE(ALCpulseBackendFactory);
1857 #endif /* PA_API_VERSION == 12 */
1859 ALCbackendFactory *ALCpulseBackendFactory_getFactory(void)
1861 static ALCpulseBackendFactory factory = ALCPULSEBACKENDFACTORY_INITIALIZER;
1862 return STATIC_CAST(ALCbackendFactory, &factory);