Add parent_id

Add parent_id to globals to make hierarchy of interfaces. We can use
this to group interfaces or to describe the owner.
This commit is contained in:
Wim Taymans 2017-07-18 14:58:14 +02:00
parent 1acba78234
commit a003d1a39f
27 changed files with 151 additions and 99 deletions

View file

@ -29,6 +29,7 @@
struct impl {
struct pw_core *core;
struct pw_module *module;
struct pw_properties *properties;
struct pw_listener global_added;
@ -176,9 +177,9 @@ static void try_link_port(struct pw_node *node, struct pw_port *port, struct nod
goto error;
if (port->direction == PW_DIRECTION_OUTPUT)
link = pw_link_new(impl->core, port, target, NULL, NULL, &error);
link = pw_link_new(impl->core, impl->module->global, port, target, NULL, NULL, &error);
else
link = pw_link_new(impl->core, target, port, NULL, NULL, &error);
link = pw_link_new(impl->core, impl->module->global, target, port, NULL, NULL, &error);
if (link == NULL)
goto error;
@ -287,14 +288,16 @@ on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_
*
* Returns: a new #struct impl
*/
static struct impl *module_new(struct pw_core *core, struct pw_properties *properties)
static bool module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = module->core;
struct impl *impl;
impl = calloc(1, sizeof(struct impl));
pw_log_debug("module %p: new", impl);
impl->core = core;
impl->module = module;
impl->properties = properties;
spa_list_init(&impl->node_list);
@ -324,6 +327,5 @@ static void module_destroy(struct impl *impl)
bool pipewire__module_init(struct pw_module *module, const char *args)
{
module->user_data = module_new(module->core, NULL);
return true;
return module_init(module, NULL);
}

View file

@ -67,11 +67,15 @@ static struct pw_node *create_node(struct pw_node_factory *factory,
return NULL;
}
static struct impl *module_new(struct pw_core *core, struct pw_properties *properties)
static bool module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = module->core;
struct impl *impl;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
return false;
pw_log_debug("module %p: new", impl);
impl->properties = properties;
@ -86,10 +90,11 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope
spa_list_insert(core->node_factory_list.prev, &impl->this.link);
pw_core_add_global(core, NULL, core->type.node_factory, 0,
NULL, impl, &impl->this.global);
impl->this.global = pw_core_add_global(core, NULL, module->global,
core->type.node_factory, 0,
NULL, impl);
return impl;
return true;
}
#if 0
@ -103,6 +108,5 @@ static void module_destroy(struct impl *impl)
bool pipewire__module_init(struct pw_module *module, const char *args)
{
module_new(module->core, NULL);
return true;
return module_init(module, NULL);
}

View file

@ -122,7 +122,6 @@ struct impl {
struct pw_listener node_free;
struct pw_listener initialized;
struct pw_listener global_added;
int fds[2];
int other_fds[2];
@ -1056,15 +1055,6 @@ static void on_initialized(struct pw_listener *listener, struct pw_node *node)
readfd, writefd, info.memfd, info.offset, info.size);
}
static void
on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_global *global)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_added);
if (global->object == impl->this.node)
global->owner = impl->this.resource;
}
static int proxy_clear(struct proxy *this)
{
uint32_t i;
@ -1092,7 +1082,6 @@ static void client_node_resource_destroy(struct pw_resource *resource)
impl->proxy.resource = this->resource = NULL;
pw_signal_remove(&impl->global_added);
pw_signal_remove(&impl->initialized);
if (proxy->data_source.fd != -1)
@ -1157,6 +1146,7 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
this->resource = resource;
this->node = pw_spa_node_new(core,
this->resource,
NULL,
name,
true,
&impl->proxy.node,
@ -1173,7 +1163,6 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
pw_signal_add(&this->node->free_signal, &impl->node_free, on_node_free);
pw_signal_add(&this->node->initialized, &impl->initialized, on_initialized);
pw_signal_add(&impl->core->global_added, &impl->global_added, on_global_added);
return this;

View file

@ -78,6 +78,7 @@ struct socket {
struct impl {
struct pw_core *core;
struct pw_module *module;
struct spa_list link;
struct pw_properties *properties;
@ -444,7 +445,7 @@ static struct client *client_new(struct impl *impl, int fd)
ucredp = &ucred;
}
client = pw_client_new(impl->core, ucredp, NULL, sizeof(struct client));
client = pw_client_new(impl->core, impl->module->global, ucredp, NULL, sizeof(struct client));
if (client == NULL)
goto no_client;
@ -695,8 +696,9 @@ static int init_server(struct impl *impl, const char *name, bool promiscuous)
}
static struct impl *module_new(struct pw_core *core, struct pw_properties *properties)
static struct impl *module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = module->core;
struct impl *impl;
const char *name, *str;
bool promiscuous;
@ -705,6 +707,7 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope
pw_log_debug("protocol-jack %p: new", impl);
impl->core = core;
impl->module = module;
impl->properties = properties;
spa_list_init(&impl->socket_list);
@ -749,6 +752,6 @@ static void module_destroy(struct impl *impl)
bool pipewire__module_init(struct pw_module *module, const char *args)
{
module_new(module->core, NULL);
module_init(module, NULL);
return true;
}

View file

@ -32,6 +32,7 @@
struct impl {
struct pw_core *core;
struct pw_module *module;
struct pw_properties *properties;
void *hnd;
@ -109,7 +110,8 @@ static struct pw_node *make_node(struct impl *impl)
}
spa_clock = iface;
node = pw_spa_node_new(impl->core, NULL, "audiomixer", false, spa_node, spa_clock, NULL);
node = pw_spa_node_new(impl->core, NULL, impl->module->global,
"audiomixer", false, spa_node, spa_clock, NULL);
return node;
@ -120,8 +122,9 @@ static struct pw_node *make_node(struct impl *impl)
return NULL;
}
static struct impl *module_new(struct pw_core *core, struct pw_properties *properties)
static bool module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = module->core;
struct impl *impl;
struct pw_node *n;
@ -129,6 +132,7 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope
pw_log_debug("module %p: new", impl);
impl->core = core;
impl->module = module;
impl->properties = properties;
impl->factory = find_factory(impl);
@ -162,7 +166,7 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope
n->idle_used_input_links++;
node->idle_used_output_links++;
pw_link_new(core, op, ip, NULL, NULL, &error);
pw_link_new(core, module->global, op, ip, NULL, NULL, &error);
}
return impl;
}
@ -178,6 +182,5 @@ static void module_destroy(struct impl *impl)
bool pipewire__module_init(struct pw_module *module, const char *args)
{
module_new(module->core, NULL);
return true;
return module_init(module, NULL);
}

View file

@ -56,6 +56,10 @@ void pw_protocol_native_init(struct pw_protocol *protocol);
typedef bool(*demarshal_func_t) (void *object, void *data, size_t size);
struct protocol_data {
struct pw_module *module;
};
struct connection {
struct pw_protocol_connection this;
@ -82,10 +86,6 @@ struct listener {
struct spa_loop_control_hooks hooks;
};
struct protocol_data {
void *unused;
};
struct client_data {
int fd;
struct spa_source *source;
@ -198,6 +198,7 @@ static struct pw_client *client_new(struct listener *l, int fd)
struct client_data *this;
struct pw_client *client;
struct pw_protocol *protocol = l->this.protocol;
struct protocol_data *pd = protocol->user_data;
socklen_t len;
struct ucred ucred, *ucredp;
@ -209,7 +210,7 @@ static struct pw_client *client_new(struct listener *l, int fd)
ucredp = &ucred;
}
client = pw_client_new(protocol->core, ucredp, NULL, sizeof(struct client_data));
client = pw_client_new(protocol->core, pd->module->global, ucredp, NULL, sizeof(struct client_data));
if (client == NULL)
goto no_client;
@ -698,14 +699,16 @@ const static struct pw_protocol_native_ext protocol_ext_impl = {
impl_ext_end_resource,
};
static struct pw_protocol *pw_protocol_native_new(struct pw_core *core, struct pw_properties *properties)
static bool module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = module->core;
struct pw_protocol *this;
const char *val;
struct protocol_data *d;
this = pw_protocol_new(core, PW_TYPE_PROTOCOL__Native, sizeof(struct protocol_data));
if (this == NULL)
return NULL;
return false;
this->implementation = &protocol_impl;
this->extension = &protocol_ext_impl;
@ -714,11 +717,14 @@ static struct pw_protocol *pw_protocol_native_new(struct pw_core *core, struct p
pw_log_debug("protocol-native %p: new", this);
d = this->user_data;
d->module = module;
if ((val = pw_properties_get(core->properties, "pipewire.daemon"))) {
if (atoi(val) == 1)
impl_add_listener(this, core, properties);
}
return this;
return true;
}
#if 0
@ -741,6 +747,5 @@ static void pw_protocol_native_destroy(struct impl *impl)
bool pipewire__module_init(struct pw_module *module, const char *args)
{
pw_protocol_native_new(module->core, NULL);
return true;
return module_init(module, NULL);
}

View file

@ -529,7 +529,8 @@ static bool core_demarshal_update_types_server(void *object, void *data, size_t
return true;
}
static void registry_marshal_global(void *object, uint32_t id, uint32_t type, uint32_t version)
static void registry_marshal_global(void *object, uint32_t id, uint32_t parent_id,
uint32_t type, uint32_t version)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
@ -539,6 +540,7 @@ static void registry_marshal_global(void *object, uint32_t id, uint32_t type, ui
spa_pod_builder_struct(b, &f,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_INT, parent_id,
SPA_POD_TYPE_ID, type,
SPA_POD_TYPE_INT, version);
@ -742,7 +744,8 @@ static void client_marshal_info(void *object, struct pw_client_info *info)
spa_pod_builder_add(b,
SPA_POD_TYPE_STRUCT, &f,
SPA_POD_TYPE_LONG, info->change_mask, SPA_POD_TYPE_INT, n_items, 0);
SPA_POD_TYPE_LONG, info->change_mask,
SPA_POD_TYPE_INT, n_items, 0);
for (i = 0; i < n_items; i++) {
spa_pod_builder_add(b,
@ -824,17 +827,18 @@ static bool registry_demarshal_global(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
struct spa_pod_iter it;
uint32_t id, type, version;
uint32_t id, parent_id, type, version;
if (!spa_pod_iter_struct(&it, data, size) ||
!pw_pod_remap_data(SPA_POD_TYPE_STRUCT, data, size, &proxy->remote->types) ||
!spa_pod_iter_get(&it,
SPA_POD_TYPE_INT, &id,
SPA_POD_TYPE_INT, &parent_id,
SPA_POD_TYPE_ID, &type,
SPA_POD_TYPE_INT, &version, 0))
return false;
pw_proxy_notify(proxy, struct pw_registry_events, global, id, type, version);
pw_proxy_notify(proxy, struct pw_registry_events, global, id, parent_id, type, version);
return true;
}

View file

@ -49,7 +49,7 @@ bool pipewire__module_init(struct pw_module *module, const char *args)
if ((dir = getenv("SPA_PLUGIN_DIR")) == NULL)
dir = PLUGINDIR;
pw_spa_monitor_load(module->core, dir, argv[0], argv[1], argv[2]);
pw_spa_monitor_load(module->core, module->global, dir, argv[0], argv[1], argv[2]);
pw_free_strv(argv);

View file

@ -53,6 +53,7 @@ static struct pw_node *create_node(struct pw_node_factory *factory,
goto no_properties;
node = pw_spa_node_load(factory->core,
NULL,
NULL,
lib,
factory_name,
@ -81,11 +82,15 @@ static struct pw_node *create_node(struct pw_node_factory *factory,
return NULL;
}
static struct impl *module_new(struct pw_core *core, struct pw_properties *properties)
static bool module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = module->core;
struct impl *impl;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
return false;
pw_log_debug("module %p: new", impl);
impl->properties = properties;
@ -97,10 +102,10 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope
spa_list_insert(core->node_factory_list.prev, &impl->this.link);
pw_core_add_global(core, NULL, core->type.node_factory, 0,
NULL, impl, &impl->this.global);
impl->this.global = pw_core_add_global(core, NULL, module->global, core->type.node_factory, 0,
NULL, impl);
return impl;
return true;
}
#if 0
@ -114,6 +119,5 @@ static void module_destroy(struct impl *impl)
bool pipewire__module_init(struct pw_module *module, const char *args)
{
module_new(module->core, NULL);
return true;
return module_init(module, NULL);
}

View file

@ -60,7 +60,7 @@ bool pipewire__module_init(struct pw_module *module, const char *args)
pw_free_strv(prop);
}
pw_spa_node_load(module->core, NULL, argv[0], argv[1], argv[2], props);
pw_spa_node_load(module->core, NULL, module->global, argv[0], argv[1], argv[2], props);
pw_free_strv(argv);

View file

@ -47,6 +47,7 @@ struct impl {
struct pw_spa_monitor this;
struct pw_core *core;
struct pw_global *parent;
void *hnd;
@ -110,7 +111,8 @@ static void add_item(struct pw_spa_monitor *this, struct spa_monitor_item *item)
mitem = calloc(1, sizeof(struct monitor_item));
mitem->id = strdup(id);
mitem->node = pw_spa_node_new(impl->core, NULL, name, false, node_iface, clock_iface, props);
mitem->node = pw_spa_node_new(impl->core, NULL, impl->parent, name,
false, node_iface, clock_iface, props);
spa_list_insert(impl->item_list.prev, &mitem->link);
}
@ -203,6 +205,7 @@ static const struct spa_monitor_callbacks callbacks = {
};
struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
struct pw_global *parent,
const char *dir,
const char *lib,
const char *factory_name, const char *system_name)
@ -252,6 +255,7 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
impl = calloc(1, sizeof(struct impl));
impl->core = core;
impl->parent = parent;
impl->hnd = hnd;
this = &impl->this;

View file

@ -41,6 +41,7 @@ struct pw_spa_monitor {
struct pw_spa_monitor *
pw_spa_monitor_load(struct pw_core *core,
struct pw_global *parent,
const char *dir,
const char *lib,
const char *factory_name, const char *system_name);

View file

@ -387,6 +387,7 @@ static const struct spa_node_callbacks node_callbacks = {
struct pw_node *
pw_spa_node_new(struct pw_core *core,
struct pw_resource *owner,
struct pw_global *parent,
const char *name,
bool async,
struct spa_node *node,
@ -411,7 +412,7 @@ pw_spa_node_new(struct pw_core *core,
node->info->items[i].value);
}
this = pw_node_new(core, owner, name, properties, sizeof(struct impl));
this = pw_node_new(core, owner, parent, name, properties, sizeof(struct impl));
if (this == NULL)
return NULL;
@ -498,6 +499,7 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
struct pw_node *pw_spa_node_load(struct pw_core *core,
struct pw_resource *owner,
struct pw_global *parent,
const char *lib,
const char *factory_name,
const char *name,
@ -567,7 +569,7 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
}
}
this = pw_spa_node_new(core, owner, name, async, spa_node, spa_clock, properties);
this = pw_spa_node_new(core, owner, parent, name, async, spa_node, spa_clock, properties);
impl->hnd = hnd;
impl->handle = handle;
impl->lib = filename;

View file

@ -30,6 +30,7 @@ extern "C" {
struct pw_node *
pw_spa_node_new(struct pw_core *core,
struct pw_resource *owner, /**< optional owner */
struct pw_global *parent, /**< optional parent */
const char *name,
bool async,
struct spa_node *node,
@ -39,6 +40,7 @@ pw_spa_node_new(struct pw_core *core,
struct pw_node *
pw_spa_node_load(struct pw_core *core,
struct pw_resource *owner, /**< optional owner */
struct pw_global *parent, /**< optional parent */
const char *lib,
const char *factory_name,
const char *name,