From d9dc399522e703989335e9558a75a2e9ed26ad25 Mon Sep 17 00:00:00 2001 From: Chris Spencer Date: Sun, 13 Feb 2022 16:59:09 +0000 Subject: [PATCH] [client] audio/pw: request real-time priority This is as per the PipeWire ALSA plugin [1]. The existing `PW_STREAM_FLAG_RT_PROCESS` flag is misleading and doesn't really have anything to do with real-time priority; it just tells PipeWire to pull data from the application synchronously from its main processing thread. More detail at [2]. [1] https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/f5d47c079e4ed23d0aa2d2f2f4ce19ee720bee1b/pipewire-alsa/alsa-plugins/pcm_pipewire.c [2] https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2024 --- client/audiodevs/PipeWire/pipewire.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/client/audiodevs/PipeWire/pipewire.c b/client/audiodevs/PipeWire/pipewire.c index 9b55b1fc..9f2e18ec 100644 --- a/client/audiodevs/PipeWire/pipewire.c +++ b/client/audiodevs/PipeWire/pipewire.c @@ -40,6 +40,7 @@ StreamState; struct PipeWire { struct pw_loop * loop; + struct pw_context * context; struct pw_thread_loop * thread; struct @@ -132,33 +133,38 @@ static bool pipewire_init(void) pw_init(NULL, NULL); pw.loop = pw_loop_new(NULL); - struct pw_context * context = pw_context_new(pw.loop, NULL, 0); - if (!context) + pw.context = pw_context_new( + pw.loop, + pw_properties_new( + // Request real-time priority on the PipeWire threads + PW_KEY_CONFIG_NAME, "client-rt.conf", + NULL + ), + 0); + if (!pw.context) { DEBUG_ERROR("Failed to create a context"); goto err; } /* this is just to test for PipeWire availabillity */ - struct pw_core * core = pw_context_connect(context, NULL, 0); + struct pw_core * core = pw_context_connect(pw.context, NULL, 0); if (!core) goto err_context; - pw_context_destroy(context); - /* PipeWire is available so create the loop thread and start it */ pw.thread = pw_thread_loop_new_full(pw.loop, "PipeWire", NULL); if (!pw.thread) { DEBUG_ERROR("Failed to create the thread loop"); - goto err; + goto err_context; } pw_thread_loop_start(pw.thread); return true; err_context: - pw_context_destroy(context); + pw_context_destroy(pw.context); err: pw_loop_destroy(pw.loop); @@ -502,10 +508,12 @@ static void pipewire_free(void) pipewire_recordStopStream(); pw_thread_loop_stop(pw.thread); pw_thread_loop_destroy(pw.thread); + pw_context_destroy(pw.context); pw_loop_destroy(pw.loop); - pw.loop = NULL; - pw.thread = NULL; + pw.loop = NULL; + pw.context = NULL; + pw.thread = NULL; pw_deinit(); }