aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/backends/pulseaudio.c52
1 files changed, 21 insertions, 31 deletions
diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c
index 78854da7..f2e1c7ba 100644
--- a/Alc/backends/pulseaudio.c
+++ b/Alc/backends/pulseaudio.c
@@ -664,6 +664,16 @@ static pa_stream *connect_record_stream(const char *device_name,
}
+#define WAIT_FOR_OPERATION(x, l) do { \
+ pa_threaded_mainloop *_l = (l); \
+ pa_operation *_o = (x); \
+ if(!_o) break; \
+ while(pa_operation_get_state(_o) == PA_OPERATION_RUNNING) \
+ pa_threaded_mainloop_wait(_l); \
+ pa_operation_unref(_o); \
+} while(0)
+
+
static void probe_devices(ALboolean capture)
{
pa_threaded_mainloop *loop;
@@ -702,9 +712,7 @@ static void probe_devices(ALboolean capture)
if(stream)
{
o = pa_context_get_sink_info_by_name(context, pa_stream_get_device_name(stream), sink_device_callback, loop);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, loop);
pa_stream_disconnect(stream);
pa_stream_unref(stream);
@@ -731,9 +739,7 @@ static void probe_devices(ALboolean capture)
if(stream)
{
o = pa_context_get_source_info_by_name(context, pa_stream_get_device_name(stream), source_device_callback, loop);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, loop);
pa_stream_disconnect(stream);
pa_stream_unref(stream);
@@ -742,9 +748,7 @@ static void probe_devices(ALboolean capture)
o = pa_context_get_source_info_list(context, source_device_callback, loop);
}
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, loop);
pa_context_disconnect(context);
pa_context_unref(context);
@@ -785,7 +789,7 @@ static ALuint PulseProc(ALvoid *param)
{
pa_operation *o;
o = pa_stream_cork(data->stream, 0, NULL, NULL);
- pa_operation_unref(o);
+ if(o) pa_operation_unref(o);
}
pa_threaded_mainloop_unlock(data->loop);
Sleep(1);
@@ -948,9 +952,7 @@ static ALCenum pulse_open_playback(ALCdevice *device, const ALCchar *device_name
data->device_name = strdup(pa_stream_get_device_name(data->stream));
o = pa_context_get_sink_info_by_name(data->context, data->device_name,
sink_name_callback, device);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(data->loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, data->loop);
pa_threaded_mainloop_unlock(data->loop);
@@ -985,9 +987,7 @@ static ALCboolean pulse_reset_playback(ALCdevice *device)
{
pa_operation *o;
o = pa_context_get_sink_info_by_name(data->context, data->device_name, sink_info_callback, device);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(data->loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, data->loop);
}
if(!(device->Flags&DEVICE_FREQUENCY_REQUEST))
flags |= PA_STREAM_FIX_RATE;
@@ -1069,9 +1069,7 @@ static ALCboolean pulse_reset_playback(ALCdevice *device)
o = pa_stream_set_buffer_attr(data->stream, &data->attr,
stream_success_callback, device);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(data->loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, data->loop);
device->Frequency = data->spec.rate;
}
@@ -1121,9 +1119,7 @@ static void pulse_stop_playback(ALCdevice *device)
pa_threaded_mainloop_lock(data->loop);
o = pa_stream_cork(data->stream, 1, stream_success_callback, device);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(data->loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, data->loop);
pa_threaded_mainloop_unlock(data->loop);
}
@@ -1227,9 +1223,7 @@ static ALCenum pulse_open_capture(ALCdevice *device, const ALCchar *device_name)
data->device_name = strdup(pa_stream_get_device_name(data->stream));
o = pa_context_get_source_info_by_name(data->context, data->device_name,
source_name_callback, device);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(data->loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, data->loop);
pa_threaded_mainloop_unlock(data->loop);
return ALC_NO_ERROR;
@@ -1251,9 +1245,7 @@ static void pulse_start_capture(ALCdevice *device)
pa_threaded_mainloop_lock(data->loop);
o = pa_stream_cork(data->stream, 0, stream_success_callback, device);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(data->loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, data->loop);
pa_threaded_mainloop_unlock(data->loop);
}
@@ -1264,9 +1256,7 @@ static void pulse_stop_capture(ALCdevice *device)
pa_threaded_mainloop_lock(data->loop);
o = pa_stream_cork(data->stream, 1, stream_success_callback, device);
- while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(data->loop);
- pa_operation_unref(o);
+ WAIT_FOR_OPERATION(o, data->loop);
pa_threaded_mainloop_unlock(data->loop);
}