mirror of
				https://github.com/gnif/LookingGlass.git
				synced 2025-11-03 22:22:08 +00:00 
			
		
		
		
	[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] f5d47c079e/pipewire-alsa/alsa-plugins/pcm_pipewire.c
[2] https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2024
			
			
This commit is contained in:
		
				
					committed by
					
						
						Geoffrey McRae
					
				
			
			
				
	
			
			
			
						parent
						
							70158a64e7
						
					
				
				
					commit
					d9dc399522
				
			@@ -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();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user