From 53548aee7554cde8de472f3b2edd9e87e0588f8b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 22 Nov 2021 16:30:00 +0100 Subject: [PATCH] global: add the object.serial property for globals Make sure the lower 32 bits of the serial are never SPA_ID_INVALID. This makes it possible for applications that need a unique 32 bits number to use the lower bits while still having an invalid 32 bit serial number. --- src/pipewire/global.c | 7 ++++++- src/pipewire/keys.h | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pipewire/global.c b/src/pipewire/global.c index aca3cfaaa..90b13f279 100644 --- a/src/pipewire/global.c +++ b/src/pipewire/global.c @@ -135,7 +135,12 @@ int pw_global_register(struct pw_global *global) spa_list_append(&context->global_list, &global->link); global->registered = true; - global->serial = ++serial; + global->serial = serial++; + if ((uint32_t)serial == SPA_ID_INVALID) + serial++; + + pw_properties_setf(global->properties, + PW_KEY_OBJECT_SERIAL, "%"PRIu64, global->serial); spa_list_for_each(registry, &context->registry_resource_list, link) { uint32_t permissions = pw_global_get_permissions(global, registry->client); diff --git a/src/pipewire/keys.h b/src/pipewire/keys.h index 24cbf4e55..0a00fdcfb 100644 --- a/src/pipewire/keys.h +++ b/src/pipewire/keys.h @@ -64,6 +64,10 @@ extern "C" { /** object properties */ #define PW_KEY_OBJECT_PATH "object.path" /**< unique path to construct the object */ #define PW_KEY_OBJECT_ID "object.id" /**< a global object id */ +#define PW_KEY_OBJECT_SERIAL "object.serial" /**< a 64 bit object serial number. This is a number + * incremented for each object that is created. + * The lower 32 bits are guaranteed to never be + * SPA_ID_INVALID. */ #define PW_KEY_OBJECT_LINGER "object.linger" /**< the object lives on even after the client * that created it has been destroyed */ #define PW_KEY_OBJECT_REGISTER "object.register" /**< If the object should be registered. */