aports/community/cmus/1172.patch
Clayton Craft a13a5fd755 community/cmus: add workaround for hang with pipewire
This was submitted upstream: https://github.com/cmus/cmus/pull/1172

It's not merged yet though... however Debian is also shipping it:
2e20a489bc
2022-09-06 06:15:29 +00:00

131 lines
3.3 KiB
Diff

From 8d754c1c0664dfe7caaf7d571710f74ae19b0f01 Mon Sep 17 00:00:00 2001
From: Erfan Khadem <erfankhademerkh@gmail.com>
Date: Tue, 15 Feb 2022 14:50:41 +0330
Subject: [PATCH 1/2] Fixed hanging on exit for pipewire
---
op/pulse.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/op/pulse.c b/op/pulse.c
index c8a6d6a4..c785bfc3 100644
--- a/op/pulse.c
+++ b/op/pulse.c
@@ -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);
@@ -246,6 +264,10 @@ static int _pa_stream_cork(int pause_)
static int _pa_stream_drain(void)
{
+ if (is_pipewire) {
+ return OP_ERROR_SUCCESS;
+ }
+
pa_threaded_mainloop_lock(pa_ml);
return _pa_wait_unlock(pa_stream_drain(pa_s, _pa_stream_success_cb, NULL));
@@ -422,6 +444,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 +464,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);
From 58ef25fe9125584884598bc29f50bcd83239a7b5 Mon Sep 17 00:00:00 2001
From: Erfan Khadem <erfankhademerkh@gmail.com>
Date: Mon, 27 Jun 2022 11:34:52 +0430
Subject: [PATCH 2/2] Fix formatting
---
op/pulse.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/op/pulse.c b/op/pulse.c
index c785bfc3..78ec0661 100644
--- a/op/pulse.c
+++ b/op/pulse.c
@@ -35,7 +35,7 @@ static pa_channel_map pa_cmap;
static pa_cvolume pa_vol;
static pa_sample_spec pa_ss;
-static bool is_pipewire = false;
+static bool is_pipewire = false;
static int mixer_notify_in;
static int mixer_notify_out;
@@ -180,8 +180,8 @@ 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)
+ const pa_server_info *i,
+ void *data)
{
is_pipewire = false;
if (i) {
@@ -264,10 +264,6 @@ static int _pa_stream_cork(int pause_)
static int _pa_stream_drain(void)
{
- if (is_pipewire) {
- return OP_ERROR_SUCCESS;
- }
-
pa_threaded_mainloop_lock(pa_ml);
return _pa_wait_unlock(pa_stream_drain(pa_s, _pa_stream_success_cb, NULL));