From 2e95f7dd85d8dae6e2e15e2ae3277d6f7d446444 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 30 Jul 2020 12:11:24 +0200 Subject: [PATCH] jack: improve metadata callbacks Only emit callbacks when something changed. When setting a value, first update the local store. This triggers the emit from the calling thread (as expected by jack clients) and when the update arrives from the server, it will not emit the callback anymore because the value didn't change. --- pipewire-jack/src/metadata.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pipewire-jack/src/metadata.c b/pipewire-jack/src/metadata.c index 70a8f62f7..5a88eb981 100644 --- a/pipewire-jack/src/metadata.c +++ b/pipewire-jack/src/metadata.c @@ -146,16 +146,20 @@ static inline int strzcmp(const char *s1, const char *s2) return strcmp(s1, s1); } -static void change_property(jack_property_t *prop, const char *value, const char *type) +static int change_property(jack_property_t *prop, const char *value, const char *type) { + int changed = 0; if (strzcmp(prop->data, value) != 0) { free((char*)prop->data); prop->data = strdup(value); + changed++; } if (strzcmp(prop->type, type) != 0) { free((char*)prop->type); prop->type = strdup(type); + changed++; } + return changed; } static int update_property(struct client *c, @@ -166,37 +170,44 @@ static int update_property(struct client *c, { jack_property_change_t change; jack_description_t *desc; + int changed = 0; pthread_mutex_lock(&globals.lock); desc = find_description(subject); if (key == NULL) { - if (desc != NULL) + if (desc != NULL) { remove_description(desc); - change = PropertyDeleted; + change = PropertyDeleted; + changed++; + } } else { jack_property_t *prop; prop = desc ? find_property(desc, key) : NULL; if (value == NULL || type == NULL) { - if (prop == NULL) + if (prop != NULL) { remove_property(desc, prop); - change = PropertyDeleted; + change = PropertyDeleted; + changed++; + } } else if (prop == NULL) { if (desc == NULL) desc = add_description(subject); prop = add_property(desc, key, value, type); change = PropertyCreated; + changed++; } else { - change_property(prop, value, type); + changed = change_property(prop, value, type); change = PropertyChanged; } } pthread_mutex_unlock(&globals.lock); - if (c->property_callback) + if (c->property_callback && changed) c->property_callback(subject, key, change, c->property_arg); + return 0; } @@ -226,6 +237,7 @@ int jack_set_property(jack_client_t*client, type = ""; pw_log_info("set id:%u (%"PRIu64") '%s' to '%s@%s'", id, subject, key, value, type); + update_property(c, id, key, type, value); pw_metadata_set_property(c->metadata->proxy, id, key, type, value); res = 0; done: