[gnome-remote-desktop] rdp-pipewire-stream: Properly deinitialize PipeWire upon destruction



commit 42d1890aeb4630de9dadd066585fb4a08785b36e
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Thu May 5 07:35:01 2022 +0200

    rdp-pipewire-stream: Properly deinitialize PipeWire upon destruction
    
    Currently, gnome-remote-desktop never calls pw_deinit(), resulting in
    leaking resources.
    With the current implementation, simply calling pw_deinit() is not
    possible, since multiple remote desktop sessions can run at the same
    time and therefore multiple PipeWire streams too.
    Since PipeWire 0.3.49 pw_init() and pw_deinit() can be called multiple
    times, removing the need of a global variable.
    PipeWire now internally tracks the reference count, which is increased
    by calling pw_init() and decreased by calling pw_deinit().
    
    So, replace the grd_maybe_initialize_pipewire() call with pw_init() and
    also call pw_deinit(), when destructing the PipeWire class instance.
    Also, bump the PipeWire version requirement.

 meson.build                   | 2 +-
 src/grd-rdp-pipewire-stream.c | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/meson.build b/meson.build
index 34c1c505..ce47c189 100644
--- a/meson.build
+++ b/meson.build
@@ -23,7 +23,7 @@ gio_dep = dependency('gio-2.0')
 gio_unix_dep = dependency('gio-unix-2.0')
 libnotify_dep = dependency('libnotify')
 libsecret_dep = dependency('libsecret-1')
-pipewire_dep = dependency('libpipewire-0.3', version: '>= 0.3.0')
+pipewire_dep = dependency('libpipewire-0.3', version: '>= 0.3.49')
 systemd_dep = dependency('systemd', required: get_option('systemd'))
 
 have_rdp = get_option('rdp')
diff --git a/src/grd-rdp-pipewire-stream.c b/src/grd-rdp-pipewire-stream.c
index f2fec6d5..16b7b6c2 100644
--- a/src/grd-rdp-pipewire-stream.c
+++ b/src/grd-rdp-pipewire-stream.c
@@ -1228,13 +1228,13 @@ grd_rdp_pipewire_stream_new (GrdSessionRdp               *session_rdp,
   g_autoptr (GrdRdpPipeWireStream) stream = NULL;
   GrdPipeWireSource *pipewire_source;
 
-  grd_maybe_initialize_pipewire ();
-
   stream = g_object_new (GRD_TYPE_RDP_PIPEWIRE_STREAM, NULL);
   stream->session_rdp = session_rdp;
   stream->rdp_surface = rdp_surface;
   stream->src_node_id = src_node_id;
 
+  pw_init (NULL, NULL);
+
   create_render_source (stream, render_context);
 
   pipewire_source = create_pipewire_source ();
@@ -1327,6 +1327,8 @@ grd_rdp_pipewire_stream_finalize (GObject *object)
 
   g_mutex_clear (&stream->frame_mutex);
 
+  pw_deinit ();
+
   G_OBJECT_CLASS (grd_rdp_pipewire_stream_parent_class)->finalize (object);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]