stream wait for session object

This commit is contained in:
Anthony Ilersich 2022-10-25 18:00:20 -04:00
parent 0a31d58e00
commit c2d0f2e8aa
7 changed files with 56 additions and 74 deletions

View file

@ -283,8 +283,6 @@ int client_session_factory_init(struct pw_impl_module *module)
if (factory == NULL)
return -ENOMEM;
pw_log_error("create \"client-session\" factory from client-session");
data = pw_impl_factory_get_user_data(factory);
data->factory = factory;
data->module = module;

View file

@ -305,8 +305,6 @@ int session_init(struct session *this,
NULL, session_bind, this);
if (!this->global)
goto no_mem;
pw_log_error("create global session object from client-session with id=%u", pw_global_get_id(this->global));
pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
pw_global_get_id(this->global));

View file

@ -168,8 +168,6 @@ struct pw_proxy *pw_core_session_export(struct pw_core *core,
user_data_size + sizeof(struct object_data));
if (proxy == NULL)
return NULL;
pw_log_error("created session proxy from proxy-session-manager with proxy id=%u", pw_proxy_get_id(proxy));
data = pw_proxy_get_user_data(proxy);
data = SPA_PTROFF(data, user_data_size, struct object_data);

View file

@ -556,8 +556,6 @@ int session_factory_init(struct pw_impl_module *module)
sizeof(*data));
if (factory == NULL)
return -errno;
pw_log_error("created session factory from module-session-manager");
data = pw_impl_factory_get_user_data(factory);
data->factory = factory;

View file

@ -28,7 +28,6 @@
#include <sys/un.h>
#include <errno.h>
#include <sys/mman.h>
#include <pthread.h>
#include <spa/pod/parser.h>
#include <spa/debug/types.h>
@ -42,9 +41,6 @@
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;
@ -297,7 +293,6 @@ struct pw_proxy *pw_core_export(struct pw_core *core,
goto error_proxy_failed;
}
pw_log_debug("%p: export:%s proxy:%p", core, type, proxy);
pw_log_error("%p: export:%s proxy:%p", core, type, proxy);
return proxy;
error_export_type:
@ -403,37 +398,6 @@ exit_cleanup:
return NULL;
}
static void
signal_service_added()
{
pthread_mutex_lock(&service_added_lock);
pthread_cond_signal(&service_added_cv);
pthread_mutex_unlock(&service_added_lock);
}
// /* [registry_event_global] */
// static void registry_event_global(void *_data, uint32_t id,
// uint32_t permissions, const char *type,
// uint32_t version, const struct spa_dict *props)
// {
// struct data *data = _data;
// if (data->client != NULL)
// return;
// if (strcmp(type, PW_TYPE_INTERFACE_Client) == 0) {
// data->client = pw_registry_bind(data->registry,
// id, type, PW_VERSION_CLIENT, 0);
// pw_client_add_listener(data->client,
// &data->client_listener,
// &client_events, data);
// }
// }
// /* [registry_event_global] */
// static const struct pw_registry_events registry_events = {
// PW_VERSION_REGISTRY_EVENTS,
// .global = registry_event_global,
// };
SPA_EXPORT
struct pw_core *
pw_context_connect(struct pw_context *context, struct pw_properties *properties,
@ -442,39 +406,10 @@ pw_context_connect(struct pw_context *context, struct pw_properties *properties,
struct pw_core *core;
int res;
pw_log_error("pw_context_connect");
core = core_new(context, properties, user_data_size);
if (core == NULL)
return NULL;
// struct pw_registry *registry = pw_core_get_registry(core, PW_VERSION_REGISTRY, 0);
// pw_registry_add_listener(registry, &data.registry_listener, &registry_events, &data);
bool should_block_for_services = false; // TODO
if (should_block_for_services)
{
struct spa_dict_item *services = NULL;
struct pw_session_info *info;
struct spa_dict *props;
struct pw_global *global;
uint32_t id = 0; // TODO: how to find id of global for pw_session_info?
global = pw_context_find_global(context, id);
// TODO: are these the properties of the pw_session_info object?
// if not, should we use pw_global_get_object(global), and will this be the pw_session_info object?
props = pw_global_get_properties(global);
services = spa_dict_lookup_item(props, PW_KEY_SESSION_SERVICES);
pthread_mutex_lock(&service_added_lock);
if (services != NULL && spa_streq(services->value, PW_SESSION_SERVICE_NONE))
{
pw_log_error("pw_context_connect is waiting for session.services to be populated");
pthread_cond_wait(&service_added_cv, &service_added_lock);
pw_log_error("pw_context_connect is resuming");
pw_log_error(PW_KEY_SESSION_SERVICES": %s", services->value);
}
pthread_mutex_unlock(&service_added_lock);
}
pw_log_debug("%p: connect", core);
if ((res = pw_protocol_client_connect(core->conn,

View file

@ -1056,6 +1056,12 @@ struct pw_stream {
struct pw_proxy *proxy;
struct spa_hook proxy_listener;
struct pw_registry *registry;
struct spa_hook registry_listener;
struct pw_session *session;
struct spa_hook session_listener;
struct spa_hook node_listener;
struct spa_list controls;

View file

@ -42,6 +42,7 @@
#include "pipewire/pipewire.h"
#include "pipewire/stream.h"
#include "pipewire/private.h"
#include "pipewire/extensions/session-manager.h"
PW_LOG_TOPIC_EXTERN(log_stream);
#define PW_LOG_TOPIC_DEFAULT log_stream
@ -1113,6 +1114,47 @@ static const struct spa_node_methods impl_node = {
.port_reuse_buffer = impl_port_reuse_buffer,
};
static void session_event_info (void *data, const struct pw_session_info *info) {
struct pw_stream *stream = data;
const char *services = spa_dict_lookup(info->props, PW_KEY_SESSION_SERVICES);
if (services == NULL || !strcmp(services, PW_SESSION_SERVICE_NONE)) {
return;
}
// some services are available, so the stream can now be considered
// connected, although more services may become available after this
pw_log_error("%p: stream has received services: %s", stream, services); // TODO: switch to _debug after testing
if (stream->state == PW_STREAM_STATE_CONNECTING) {
stream_set_state(stream, PW_STREAM_STATE_PAUSED, NULL);
}
}
static const struct pw_session_events session_events = {
PW_VERSION_SESSION_EVENTS,
.info = &session_event_info,
};
static void registry_event_global(void *data, uint32_t id,
uint32_t permissions, const char *type,
uint32_t version, const struct spa_dict *props)
{
struct pw_stream *stream = data;
if (stream->session != NULL)
return;
if (strcmp(type, PW_TYPE_INTERFACE_Session) == 0) {
stream->session = pw_registry_bind(stream->registry,
id, type, PW_VERSION_SESSION, 0);
pw_session_add_listener(stream->session,
&stream->session_listener,
&session_events, data);
}
}
static const struct pw_registry_events registry_events = {
PW_VERSION_REGISTRY_EVENTS,
.global = registry_event_global,
};
static void proxy_removed(void *_data)
{
struct pw_stream *stream = _data;
@ -1143,7 +1185,11 @@ static void proxy_bound(void *data, uint32_t global_id)
{
struct pw_stream *stream = data;
stream->node_id = global_id;
stream_set_state(stream, PW_STREAM_STATE_PAUSED, NULL);
stream->registry = pw_core_get_registry(stream->core,
PW_VERSION_REGISTRY,
0 /* user_data size */ );
pw_registry_add_listener(stream->registry, &stream->registry_listener,
&registry_events, data);
}
static const struct pw_proxy_events proxy_events = {
@ -1485,6 +1531,9 @@ stream_new(struct pw_context *context, const char *name,
this->name = name ? strdup(name) : NULL;
this->node_id = SPA_ID_INVALID;
this->registry = NULL;
this->session = NULL;
spa_ringbuffer_init(&impl->dequeued.ring);
spa_ringbuffer_init(&impl->queued.ring);