Fix freeze when exiting cmus
authorDebian Multimedia Maintainers <debian-multimedia@lists.debian.org>
Sun, 31 Jul 2022 20:01:04 +0000 (21:01 +0100)
committerPhilippe SWARTVAGHER <phil.swart@gmx.fr>
Sun, 31 Jul 2022 20:01:04 +0000 (21:01 +0100)
Origin: upstream, https://github.com/cmus/cmus/pull/1172
Bug: https://github.com/cmus/cmus/issues/1184

Gbp-Pq: Name 0004-Fix-freeze-on-exit.patch

op/pulse.c

index c8a6d6a470ee741e7c5150a896c283dd48cd25b0..78ec0661c8a4bc1f33e67b96d8c8131dfcce03e0 100644 (file)
@@ -17,7 +17,9 @@
  */
 
 #include <string.h>
+#include <stdbool.h>
 
+#include <pulse/introspect.h>
 #include <pulse/pulseaudio.h>
 
 #include "../op.h"
@@ -33,6 +35,8 @@ static pa_channel_map          pa_cmap;
 static pa_cvolume               pa_vol;
 static pa_sample_spec           pa_ss;
 
+static bool                     is_pipewire = false;
+
 static int                      mixer_notify_in;
 static int                      mixer_notify_out;
 
@@ -175,6 +179,20 @@ static void _pa_sink_input_info_cb(pa_context *c,
        }
 }
 
+static void _pa_server_info_cb(pa_context *c,
+                              const pa_server_info *i,
+                              void *data)
+{
+       is_pipewire = false;
+       if (i) {
+               if (strstr(i->server_name, "PipeWire") != NULL) {
+                       // server is PipeWire
+                       d_print("Pulseaudio server is pipewire. Disabling _pa_stream_drain()\n");
+                       is_pipewire = true;
+               }
+       }
+}
+
 static void _pa_stream_success_cb(pa_stream *s, int success, void *data)
 {
        pa_threaded_mainloop_signal(pa_ml, 0);
@@ -422,6 +440,8 @@ static int op_pulse_open(sample_format_t sf, const channel_position_t *channel_m
        pa_context_get_sink_input_info(pa_ctx, pa_stream_get_index(pa_s),
                        _pa_sink_input_info_cb, NULL);
 
+       pa_context_get_server_info(pa_ctx, _pa_server_info_cb, NULL);
+
        pa_threaded_mainloop_unlock(pa_ml);
 
        return OP_ERROR_SUCCESS;
@@ -440,8 +460,10 @@ static int op_pulse_close(void)
         * If this _pa_stream_drain() will be moved below following
         * pa_threaded_mainloop_lock(), PulseAudio 0.9.19 will hang.
         */
-       if (pa_s)
+
+       if (pa_s && !is_pipewire){
                _pa_stream_drain();
+       }
 
        pa_threaded_mainloop_lock(pa_ml);