aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-06-16 22:32:19 -0700
committerChris Robinson <[email protected]>2012-06-16 22:32:19 -0700
commit0db9730a502eb38f6b7a6c90dd89f38f73f18880 (patch)
tree4c02d8eb8bfebfc15cc385c9a3f3c4cbecff32f8
parentad2643d8af3a47ad24369e4a9189dd95307e5672 (diff)
Add an option to allow PulseAudio to move streams
This could be made the default, if there's a safe way to update the AL device specifier.
-rw-r--r--Alc/backends/pulseaudio.c31
-rw-r--r--alsoftrc.sample6
2 files changed, 34 insertions, 3 deletions
diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c
index a88321f7..3016283d 100644
--- a/Alc/backends/pulseaudio.c
+++ b/Alc/backends/pulseaudio.c
@@ -546,6 +546,19 @@ static void source_name_callback(pa_context *context, const pa_source_info *info
}
+static void stream_moved_callback(pa_stream *stream, void *pdata)
+{
+ ALCdevice *device = pdata;
+ pulse_data *data = device->ExtraData;
+ (void)stream;
+
+ free(data->device_name);
+ data->device_name = strdup(pa_stream_get_device_name(data->stream));
+
+ TRACE("Stream moved to %s\n", data->device_name);
+}
+
+
static pa_context *connect_context(pa_threaded_mainloop *loop, ALboolean silent)
{
const char *name = "OpenAL Soft";
@@ -887,6 +900,7 @@ static void pulse_close(ALCdevice *device)
if(data->stream)
{
+ pa_stream_set_moved_callback(data->stream, NULL, NULL);
#if PA_CHECK_VERSION(0,9,15)
if(pa_stream_set_buffer_attr_callback)
pa_stream_set_buffer_attr_callback(data->stream, NULL, NULL);
@@ -944,7 +958,9 @@ static ALCenum pulse_open_playback(ALCdevice *device, const ALCchar *device_name
pa_threaded_mainloop_lock(data->loop);
flags = PA_STREAM_FIX_FORMAT | PA_STREAM_FIX_RATE |
- PA_STREAM_FIX_CHANNELS | PA_STREAM_DONT_MOVE;
+ PA_STREAM_FIX_CHANNELS;
+ if(!GetConfigValueBool("pulse", "allow-moves", 0))
+ flags |= PA_STREAM_DONT_MOVE;
spec.format = PA_SAMPLE_S16NE;
spec.rate = 44100;
@@ -964,6 +980,8 @@ static ALCenum pulse_open_playback(ALCdevice *device, const ALCchar *device_name
sink_name_callback, device);
WAIT_FOR_OPERATION(o, data->loop);
+ pa_stream_set_moved_callback(data->stream, stream_moved_callback, device);
+
pa_threaded_mainloop_unlock(data->loop);
return ALC_NO_ERROR;
@@ -984,6 +1002,7 @@ static ALCboolean pulse_reset_playback(ALCdevice *device)
if(data->stream)
{
+ pa_stream_set_moved_callback(data->stream, NULL, NULL);
#if PA_CHECK_VERSION(0,9,15)
if(pa_stream_set_buffer_attr_callback)
pa_stream_set_buffer_attr_callback(data->stream, NULL, NULL);
@@ -1005,7 +1024,8 @@ static ALCboolean pulse_reset_playback(ALCdevice *device)
flags |= PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE;
flags |= PA_STREAM_ADJUST_LATENCY;
flags |= PA_STREAM_START_CORKED;
- flags |= PA_STREAM_DONT_MOVE;
+ if(!GetConfigValueBool("pulse", "allow-moves", 0))
+ flags |= PA_STREAM_DONT_MOVE;
switch(device->FmtType)
{
@@ -1084,6 +1104,7 @@ static ALCboolean pulse_reset_playback(ALCdevice *device)
device->Frequency = data->spec.rate;
}
+ pa_stream_set_moved_callback(data->stream, stream_moved_callback, device);
#if PA_CHECK_VERSION(0,9,15)
if(pa_stream_set_buffer_attr_callback)
pa_stream_set_buffer_attr_callback(data->stream, stream_buffer_attr_callback, device);
@@ -1218,8 +1239,10 @@ static ALCenum pulse_open_capture(ALCdevice *device, const ALCchar *device_name)
data->attr.fragsize = minu(samples, 50*device->Frequency/1000) *
pa_frame_size(&data->spec);
- flags |= PA_STREAM_DONT_MOVE;
flags |= PA_STREAM_START_CORKED|PA_STREAM_ADJUST_LATENCY;
+ if(!GetConfigValueBool("pulse", "allow-moves", 0))
+ flags |= PA_STREAM_DONT_MOVE;
+
data->stream = connect_record_stream(pulse_name, data->loop, data->context,
flags, &data->attr, &data->spec,
&chanmap);
@@ -1235,6 +1258,8 @@ static ALCenum pulse_open_capture(ALCdevice *device, const ALCchar *device_name)
source_name_callback, device);
WAIT_FOR_OPERATION(o, data->loop);
+ pa_stream_set_moved_callback(data->stream, stream_moved_callback, device);
+
pa_threaded_mainloop_unlock(data->loop);
return ALC_NO_ERROR;
diff --git a/alsoftrc.sample b/alsoftrc.sample
index 83c7a5a1..8f1a41dd 100644
--- a/alsoftrc.sample
+++ b/alsoftrc.sample
@@ -291,6 +291,12 @@
# still prevent autospawning even if this is set to true.
#spawn-server = false
+## allow-moves:
+# Allows PulseAudio to move active streams to different devices. Note that the
+# device specifier seen by applications will not be updated when this occurs,
+# and neither will the AL device configuration (sample rate, format, etc).
+#allow-moves = false
+
##
## Wave File Writer stuff
##