From ead3a99fd90653610212762ad87f6128c8b58d3c Mon Sep 17 00:00:00 2001 From: Anthony Ilersich Date: Tue, 11 Oct 2022 18:37:34 -0400 Subject: [PATCH] block context_connect for session.services --- src/pipewire/core.c | 33 +++++++++++++++++++++++++++++++++ src/pipewire/core.h | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/src/pipewire/core.c b/src/pipewire/core.c index dd7e05eac..98e617f6b 100644 --- a/src/pipewire/core.c +++ b/src/pipewire/core.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -36,10 +37,14 @@ #include "pipewire/private.h" #include "pipewire/extensions/protocol-native.h" +#include "pipewire/extensions/session-manager/keys.h" PW_LOG_TOPIC_EXTERN(log_core); #define PW_LOG_TOPIC_DEFAULT log_core +static pthread_mutex_t service_added_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t service_added_cv = PTHREAD_COND_INITIALIZER; + static void core_event_ping(void *data, uint32_t id, int seq) { struct pw_core *this = data; @@ -397,18 +402,46 @@ exit_cleanup: return NULL; } +SPA_EXPORT +void +pw_context_add_service(struct pw_context *context, const char *service) +{ + struct pw_properties *props = pw_context_get_properties (context); + const char* old_services = pw_properties_get(props, PW_KEY_SESSION_SERVICES); + // TODO: avoid adding duplicates + pw_properties_setf(props, PW_KEY_SESSION_SERVICES, "%s test", old_services); + pw_log_error("ADDED SERVICE!"); + pw_log_error("session.services: %s", pw_properties_get(props, PW_KEY_SESSION_SERVICES)); + pthread_mutex_lock(&service_added_lock); + pthread_cond_signal(&service_added_cv); + pthread_mutex_unlock(&service_added_lock); +} + SPA_EXPORT struct pw_core * pw_context_connect(struct pw_context *context, struct pw_properties *properties, size_t user_data_size) { struct pw_core *core; + const struct spa_dict_item *session_services; int res; core = core_new(context, properties, user_data_size); if (core == NULL) return NULL; + session_services = spa_dict_lookup_item(&core->properties->dict, PW_KEY_SESSION_SERVICES); + // if the property is present and empty, context creation blocks until services are added + if (session_services != NULL && !strcmp(session_services->value, "")) + { + pw_log_error("pw_context_connect is waiting for session.services to be populated"); + pthread_mutex_lock(&service_added_lock); + pthread_cond_wait(&service_added_cv, &service_added_lock); + pthread_mutex_unlock(&service_added_lock); + pw_log_error("pw_context_connect is resuming"); + pw_log_error("session.services: %s", session_services->value); + } + pw_log_debug("%p: connect", core); if ((res = pw_protocol_client_connect(core->conn, diff --git a/src/pipewire/core.h b/src/pipewire/core.h index 604e7ccdf..ddd248ef7 100644 --- a/src/pipewire/core.h +++ b/src/pipewire/core.h @@ -531,6 +531,10 @@ pw_registry_bind(struct pw_registry *registry, * \{ */ +void +pw_context_add_service(struct pw_context *context, + const char *service); + /** Connect to a PipeWire instance * * \param context a \ref pw_context