summaryrefslogtreecommitdiff
path: root/media-video/wireplumber/files/wireplumber-0.4.10-m-default-nodes-don-t-check-if-all-device-nodes-are.patch
blob: d9c51489a89301f93c3b7f3426019206136e4b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
https://gitlab.freedesktop.org/pipewire/wireplumber/-/commit/392cce2136e81ac3146078eacbbae85b694c917a

From 392cce2136e81ac3146078eacbbae85b694c917a Mon Sep 17 00:00:00 2001
From: Julian Bouzas <julian.bouzas@collabora.com>
Date: Fri, 20 May 2022 07:38:24 -0400
Subject: [PATCH] m-default-nodes: don't check if all device nodes are ready
 when finding default node

This check was originally added to avoid a small audio glitch when changing
default nodes while also changing the device profile (eg Gnome Sound Settings).
The check is removed because it causes issues when disabling alsa nodes. There
are plans to fix the audio glitch issue in the future with the planned
event-dispatcher architecture.

Fixes #279
---
 modules/module-default-nodes.c | 136 ---------------------------------
 1 file changed, 136 deletions(-)

diff --git a/modules/module-default-nodes.c b/modules/module-default-nodes.c
index 0fdaed5..577f9bb 100644
--- a/modules/module-default-nodes.c
+++ b/modules/module-default-nodes.c
@@ -345,135 +345,6 @@ reevaluate_default_node (WpDefaultNodes * self, WpMetadata *m, gint node_t)
   }
 }
 
-static guint
-get_device_total_nodes (WpPipewireObject * proxy)
-{
-  g_autoptr (WpIterator) profiles = NULL;
-  g_auto (GValue) item = G_VALUE_INIT;
-
-  profiles = wp_pipewire_object_enum_params_sync (proxy, "Profile", NULL);
-  if (!profiles)
-    return 0;
-
-  for (; wp_iterator_next (profiles, &item); g_value_unset (&item)) {
-    WpSpaPod *pod = g_value_get_boxed (&item);
-    gint idx = -1;
-    const gchar *name = NULL;
-    g_autoptr (WpSpaPod) classes = NULL;
-
-    /* Parse */
-    if (!wp_spa_pod_get_object (pod, NULL,
-        "index", "i", &idx,
-        "name", "s", &name,
-        "classes", "?P", &classes,
-        NULL))
-      continue;
-    if (!classes)
-      continue;
-
-    /* Parse profile classes */
-    {
-      g_autoptr (WpIterator) it = wp_spa_pod_new_iterator (classes);
-      g_auto (GValue) v = G_VALUE_INIT;
-      gint total_nodes = 0;
-      for (; wp_iterator_next (it, &v); g_value_unset (&v)) {
-        WpSpaPod *entry = g_value_get_boxed (&v);
-        g_autoptr (WpSpaPodParser) pp = NULL;
-        const gchar *media_class = NULL;
-        gint n_nodes = 0;
-        g_return_val_if_fail (entry, 0);
-        if (!wp_spa_pod_is_struct (entry))
-          continue;
-        pp = wp_spa_pod_parser_new_struct (entry);
-        g_return_val_if_fail (pp, 0);
-        g_return_val_if_fail (wp_spa_pod_parser_get_string (pp, &media_class), 0);
-        g_return_val_if_fail (wp_spa_pod_parser_get_int (pp, &n_nodes), 0);
-        wp_spa_pod_parser_end (pp);
-
-        total_nodes += n_nodes;
-      }
-
-      if (total_nodes > 0)
-        return total_nodes;
-    }
-  }
-
-  return 0;
-}
-
-static gboolean
-nodes_ready (WpDefaultNodes * self)
-{
-  g_autoptr (WpIterator) it = NULL;
-  g_auto (GValue) val = G_VALUE_INIT;
-
-  /* Get the total number of nodes for each device and make sure they exist
-   * and have at least 1 port */
-  it = wp_object_manager_new_filtered_iterator (self->rescan_om,
-      WP_TYPE_DEVICE, NULL);
-  for (; wp_iterator_next (it, &val); g_value_unset (&val)) {
-    WpPipewireObject *device = g_value_get_object (&val);
-    guint total_nodes = get_device_total_nodes (device);
-    if (total_nodes > 0) {
-      guint32 device_id = wp_proxy_get_bound_id (WP_PROXY (device));
-      g_autoptr (WpIterator) node_it = NULL;
-      g_auto (GValue) node_val = G_VALUE_INIT;
-      guint ready_nodes = 0;
-
-      node_it = wp_object_manager_new_filtered_iterator (self->rescan_om,
-          WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY,
-          PW_KEY_DEVICE_ID, "=i", device_id, NULL);
-      for (; wp_iterator_next (node_it, &node_val); g_value_unset (&node_val)) {
-        WpPipewireObject *node = g_value_get_object (&node_val);
-        g_autoptr (WpPort) port =
-              wp_object_manager_lookup (self->rescan_om,
-              WP_TYPE_PORT, WP_CONSTRAINT_TYPE_PW_PROPERTY,
-              PW_KEY_NODE_ID, "=u", wp_proxy_get_bound_id (WP_PROXY (node)),
-              NULL);
-        if (port)
-          ready_nodes++;
-      }
-
-      if (ready_nodes < total_nodes) {
-        const gchar *device_name = wp_pipewire_object_get_property (
-            WP_PIPEWIRE_OBJECT (device), PW_KEY_DEVICE_NAME);
-        wp_debug_object (self, "device '%s' is not ready (%d/%d)", device_name,
-            ready_nodes, total_nodes);
-        return FALSE;
-      }
-    }
-  }
-
-  /* Make sure Audio and Video virtual sources have ports */
-  {
-    g_autoptr (WpIterator) node_it = NULL;
-    g_auto (GValue) node_val = G_VALUE_INIT;
-    node_it = wp_object_manager_new_filtered_iterator (self->rescan_om,
-        WP_TYPE_NODE, WP_CONSTRAINT_TYPE_PW_PROPERTY, PW_KEY_DEVICE_ID, "-",
-        NULL);
-    for (; wp_iterator_next (node_it, &node_val); g_value_unset (&node_val)) {
-      WpPipewireObject *node = g_value_get_object (&node_val);
-      const gchar *media_class = wp_pipewire_object_get_property (
-          WP_PIPEWIRE_OBJECT (node), PW_KEY_MEDIA_CLASS);
-      g_autoptr (WpPort) port =
-          wp_object_manager_lookup (self->rescan_om,
-          WP_TYPE_PORT, WP_CONSTRAINT_TYPE_PW_PROPERTY,
-          PW_KEY_NODE_ID, "=u", wp_proxy_get_bound_id (WP_PROXY (node)),
-          NULL);
-      if (!port &&
-          (g_strcmp0 ("Audio/Source/Virtual", media_class) == 0 ||
-           g_strcmp0 ("Video/Source/Virtual", media_class) == 0)) {
-        const gchar *node_name = wp_pipewire_object_get_property (
-            WP_PIPEWIRE_OBJECT (node), PW_KEY_NODE_NAME);
-        wp_debug_object (self, "virtual node '%s' is not ready", node_name);
-        return FALSE;
-      }
-    }
-  }
-
-  return TRUE;
-}
-
 static void
 sync_rescan (WpCore * core, GAsyncResult * res, WpDefaultNodes * self)
 {
@@ -491,10 +362,6 @@ sync_rescan (WpCore * core, GAsyncResult * res, WpDefaultNodes * self)
   if (!metadata)
     return;
 
-  /* Make sure nodes are ready for current profile */
-  if (!nodes_ready (self))
-    return;
-
   wp_trace_object (self, "re-evaluating defaults");
   reevaluate_default_node (self, metadata, AUDIO_SINK);
   reevaluate_default_node (self, metadata, AUDIO_SOURCE);
@@ -584,13 +451,10 @@ on_metadata_added (WpObjectManager *om, WpMetadata *metadata, gpointer d)
   self->rescan_om = wp_object_manager_new ();
   wp_object_manager_add_interest (self->rescan_om, WP_TYPE_DEVICE, NULL);
   wp_object_manager_add_interest (self->rescan_om, WP_TYPE_NODE, NULL);
-  wp_object_manager_add_interest (self->rescan_om, WP_TYPE_PORT, NULL);
   wp_object_manager_request_object_features (self->rescan_om, WP_TYPE_DEVICE,
       WP_OBJECT_FEATURES_ALL);
   wp_object_manager_request_object_features (self->rescan_om, WP_TYPE_NODE,
       WP_OBJECT_FEATURES_ALL);
-  wp_object_manager_request_object_features (self->rescan_om, WP_TYPE_PORT,
-      WP_OBJECT_FEATURES_ALL);
   g_signal_connect_object (self->rescan_om, "objects-changed",
       G_CALLBACK (schedule_rescan), self, G_CONNECT_SWAPPED);
   g_signal_connect_object (self->rescan_om, "object-added",
-- 
2.35.1