From 874d39d99c472c3fa8963f0078639468a239ad04 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Mon, 4 May 2020 14:14:24 +0300
Subject: [PATCH] si-softdsp-endpoint: use the adapter's stream if it's the
 only one

---
 modules/module-si-audio-softdsp-endpoint.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/modules/module-si-audio-softdsp-endpoint.c b/modules/module-si-audio-softdsp-endpoint.c
index aab84086..5adf5322 100644
--- a/modules/module-si-audio-softdsp-endpoint.c
+++ b/modules/module-si-audio-softdsp-endpoint.c
@@ -52,8 +52,9 @@ si_audio_softdsp_endpoint_get_properties (WpSiEndpoint * item)
 static guint
 si_audio_softdsp_endpoint_get_n_streams (WpSiEndpoint * item)
 {
-  WpSiAudioSoftdspEndpoint *self = WP_SI_AUDIO_SOFTDSP_ENDPOINT (item);
-  return self->num_streams;
+  guint n_streams = wp_session_bin_get_n_children (WP_SESSION_BIN (item));
+  /* n_streams includes the adapter; remove it, unless it's the only one */
+  return (n_streams > 1) ? (n_streams - 1) : 1;
 }
 
 static WpSiStream *
@@ -63,6 +64,9 @@ si_audio_softdsp_endpoint_get_stream (WpSiEndpoint * item, guint index)
   g_autoptr (WpIterator) it = wp_session_bin_iterate (WP_SESSION_BIN (self));
   g_auto (GValue) val = G_VALUE_INIT;
 
+  if (wp_session_bin_get_n_children (WP_SESSION_BIN (item)) == 1)
+    return WP_SI_STREAM (self->adapter);
+
   /* TODO: do not asume the items are always sorted */
   guint i = 0;
   for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
-- 
GitLab