From 9847ca129a543862ee431e27967db15038a1c34e Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Fri, 31 May 2024 17:04:18 +0300 Subject: [PATCH] lib: spa-device: emit object-removed & create-object in sequence when an object is updated In some cases the monitors emit the object_info callback with the same id and non-NULL info multiple times. For example, when an ACP profile changes from output:analog-stereo+input:analog-stereo to just output:analog-stereo, it emits object_info() with NULL info for the input node and object_info() with updated properties and the same id as before for the output node. This causes the spa-device here to emit create-object multiple times for the same object and this breaks the name deduplication logic. To solve this, make sure we emit object-removed before calling create-object a second time. Fixes #500 --- lib/wp/device.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/wp/device.c b/lib/wp/device.c index 5ba98678..46cb0171 100644 --- a/lib/wp/device.c +++ b/lib/wp/device.c @@ -361,10 +361,21 @@ spa_device_event_object_info (void *data, uint32_t id, type = spa_debug_type_short_name (info->type); props = wp_properties_new_wrap_dict (info->props); + wp_debug_object (self, "object info: id:%u type:%s factory:%s", + id, type, info->factory_name); + + if (id < self->managed_objs->len && + g_ptr_array_index (self->managed_objs, id) != NULL) { + wp_debug_object (self, "object already exists, removing"); + g_signal_emit (self, spa_device_signals[SIGNAL_OBJECT_REMOVED], 0, id); + wp_spa_device_store_managed_object (self, id, NULL); + } + g_signal_emit (self, spa_device_signals[SIGNAL_CREATE_OBJECT], 0, id, type, info->factory_name, props); } else { + wp_debug_object (self, "object removed: id:%u", id); g_signal_emit (self, spa_device_signals[SIGNAL_OBJECT_REMOVED], 0, id); wp_spa_device_store_managed_object (self, id, NULL); }