SDL: pulseaudio: Only use PA_STREAM_ADJUST_LATENCY if buffer isn't super small.

From d8b1ef42aee52dad4ac3de69795ca2e8d2fd7704 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 15 Nov 2022 22:18:51 -0500
Subject: [PATCH] pulseaudio: Only use PA_STREAM_ADJUST_LATENCY if buffer isn't
 super small.

Fixes #6121.
---
 src/audio/pulseaudio/SDL_pulseaudio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c
index 288c3d98a26f..9934a5626760 100644
--- a/src/audio/pulseaudio/SDL_pulseaudio.c
+++ b/src/audio/pulseaudio/SDL_pulseaudio.c
@@ -630,7 +630,13 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname)
     paattr.prebuf = -1;
     paattr.maxlength = -1;
     paattr.minreq = -1;
-    flags |= PA_STREAM_ADJUST_LATENCY;
+
+    /* don't let this change the global device's latency if the number is
+       extremely small, as it will affect other applications. Without this
+       flag, it only affects this specific stream. */
+    if (this->spec.samples >= 512) {
+        flags |= PA_STREAM_ADJUST_LATENCY;
+    }
 
     if (ConnectToPulseServer(&h->mainloop, &h->context) < 0) {
         return SDL_SetError("Could not connect to PulseAudio server");