From 4c035a1fd8d00a9d364d175f88af1fef0c6c5d66 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 27 Mar 2025 10:58:35 -0400
Subject: [PATCH] audio: Allow PipeWire and PulseAudio streams to migrate to
other sinks.
SDL still manages hotplug and default device management here, but if a user
wants to use an external tool, such as `pactl move-sink-input`, to put it
onto a different device, they probably know what they're doing and we
shouldn't stop them.
If this turns out to have some unexpected consequences, though, we can revisit
the change.
Fixes https://github.com/libsdl-org/sdl2-compat/issues/367
---
src/audio/pipewire/SDL_pipewire.c | 6 +++++-
src/audio/pulseaudio/SDL_pulseaudio.c | 5 ++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c
index e3f9439f73fed..32c93f6188f18 100644
--- a/src/audio/pipewire/SDL_pipewire.c
+++ b/src/audio/pipewire/SDL_pipewire.c
@@ -1187,7 +1187,11 @@ static bool PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
PIPEWIRE_pw_properties_setf(props, PW_KEY_NODE_LATENCY, "%u/%i", device->sample_frames, device->spec.freq);
PIPEWIRE_pw_properties_setf(props, PW_KEY_NODE_RATE, "1/%u", device->spec.freq);
PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_ALWAYS_PROCESS, "true");
- PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_DONT_RECONNECT, "true"); // Requesting a specific device, don't migrate to new default hardware.
+
+ // UPDATE: This prevents users from moving the audio to a new sink (device) using standard tools. This is slightly in conflict
+ // with how SDL wants to manage audio devices, but if people want to do it, we should let them, so this is commented out
+ // for now. We might revisit later.
+ //PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_DONT_RECONNECT, "true"); // Requesting a specific device, don't migrate to new default hardware.
if (node_id != PW_ID_ANY) {
PIPEWIRE_pw_thread_loop_lock(hotplug_loop);
diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c
index 5f63249b93d8c..69e8c1a84c8b3 100644
--- a/src/audio/pulseaudio/SDL_pulseaudio.c
+++ b/src/audio/pulseaudio/SDL_pulseaudio.c
@@ -701,7 +701,10 @@ static bool PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
PULSEAUDIO_pa_stream_set_state_callback(h->stream, PulseStreamStateChangeCallback, NULL);
// SDL manages device moves if the default changes, so don't ever let Pulse automatically migrate this stream.
- flags |= PA_STREAM_DONT_MOVE;
+ // UPDATE: This prevents users from moving the audio to a new sink (device) using standard tools. This is slightly in conflict
+ // with how SDL wants to manage audio devices, but if people want to do it, we should let them, so this is commented out
+ // for now. We might revisit later.
+ //flags |= PA_STREAM_DONT_MOVE;
const char *device_path = ((PulseDeviceHandle *) device->handle)->device_path;
if (recording) {