Browse Source

linux-pulseaudio: Use DONT_MOVE for non-default devices

Ask the PA server to kindly not migrate our streams to the default
device unless the user chose the default device for input/output
captures.

Fixes #3211
Kurt Kartaltepe 3 years ago
parent
commit
84687813e3
1 changed files with 12 additions and 4 deletions
  1. 12 4
      plugins/linux-pulseaudio/pulse-input.c

+ 12 - 4
plugins/linux-pulseaudio/pulse-input.c

@@ -34,6 +34,7 @@ struct pulse_data {
 
 	/* user settings */
 	char *device;
+	bool is_default;
 	bool input;
 
 	/* server info */
@@ -236,9 +237,9 @@ static void pulse_server_info(pa_context *c, const pa_server_info *i,
 	blog(LOG_INFO, "Server name: '%s %s'", i->server_name,
 	     i->server_version);
 
-	if (data->device && strcmp("default", data->device) == 0) {
+	if (data->is_default) {
+		bfree(data->device);
 		if (data->input) {
-			bfree(data->device);
 			data->device = bstrdup(i->default_source_name);
 
 			blog(LOG_DEBUG, "Default input device: '%s'",
@@ -249,7 +250,6 @@ static void pulse_server_info(pa_context *c, const pa_server_info *i,
 			strcat(monitor, i->default_sink_name);
 			strcat(monitor, ".monitor");
 
-			bfree(data->device);
 			data->device = bstrdup(monitor);
 
 			blog(LOG_DEBUG, "Default output device: '%s'",
@@ -379,6 +379,8 @@ static int_fast32_t pulse_start_recording(struct pulse_data *data)
 	attr.tlength = (uint32_t)-1;
 
 	pa_stream_flags_t flags = PA_STREAM_ADJUST_LATENCY;
+	if (!data->is_default)
+		flags |= PA_STREAM_DONT_MOVE;
 
 	pulse_lock();
 	int_fast32_t ret = pa_stream_connect_record(data->stream, data->device,
@@ -390,7 +392,12 @@ static int_fast32_t pulse_start_recording(struct pulse_data *data)
 		return -1;
 	}
 
-	blog(LOG_INFO, "Started recording from '%s'", data->device);
+	if (data->is_default)
+		blog(LOG_INFO, "Started recording from '%s' (default)",
+		     data->device);
+	else
+		blog(LOG_INFO, "Started recording from '%s'", data->device);
+
 	return 0;
 }
 
@@ -547,6 +554,7 @@ static void pulse_update(void *vptr, obs_data_t *settings)
 		if (data->device)
 			bfree(data->device);
 		data->device = bstrdup(new_device);
+		data->is_default = strcmp("default", data->device) == 0;
 		restart = true;
 	}