From e43d2d523d75923c84748a71e950b17dbe562032 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Tue, 11 Jun 2019 11:18:53 +0300
Subject: [PATCH] softdsp-endpoint: destroy the DSP->node link when the DSP
 becomes idle

---
 modules/module-pw-audio-softdsp-endpoint.c | 23 +++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/modules/module-pw-audio-softdsp-endpoint.c b/modules/module-pw-audio-softdsp-endpoint.c
index f658f94c..5d2d8231 100644
--- a/modules/module-pw-audio-softdsp-endpoint.c
+++ b/modules/module-pw-audio-softdsp-endpoint.c
@@ -91,6 +91,8 @@ on_dsp_running (WpPwAudioSoftdspEndpoint *self)
     pw_properties_setf(props, PW_LINK_INPUT_PORT_ID, "%d", -1);
   }
 
+  g_debug ("%p linking DSP to node", self);
+
   /* Create the link */
   self->link_proxy = pw_core_proxy_create_object(self->core_proxy,
       "link-factory", PW_TYPE_INTERFACE_Link, PW_VERSION_LINK, &props->dict, 0);
@@ -99,6 +101,16 @@ on_dsp_running (WpPwAudioSoftdspEndpoint *self)
   pw_properties_free(props);
 }
 
+static void
+on_dsp_idle (WpPwAudioSoftdspEndpoint *self)
+{
+  if (self->link_proxy != NULL) {
+    g_debug ("%p unlinking DSP from node", self);
+    pw_proxy_destroy (self->link_proxy);
+    self->link_proxy = NULL;
+  }
+}
+
 static void
 dsp_node_event_info (void *data, const struct pw_node_info *info)
 {
@@ -110,14 +122,15 @@ dsp_node_event_info (void *data, const struct pw_node_info *info)
   /* Handle the different states */
   switch (info->state) {
   case PW_NODE_STATE_IDLE:
-          break;
+    on_dsp_idle (self);
+    break;
   case PW_NODE_STATE_RUNNING:
-          on_dsp_running(self);
-          break;
+    on_dsp_running (self);
+    break;
   case PW_NODE_STATE_SUSPENDED:
-          break;
+    break;
   default:
-          break;
+    break;
   }
 }
 
-- 
GitLab