mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
monitor: return factory_name in the object_info
Pass a factory_name in the object_info of monitor and device. Restructure the factory name to mean something functionaly. With the factory to library mapping this then means that the implementation of certain factories can be configured in the config file.
This commit is contained in:
parent
89a86db0c4
commit
1d1f035e78
26 changed files with 218 additions and 168 deletions
|
|
@ -76,6 +76,7 @@ static void *create_object(void *_data,
|
|||
uint32_t new_id)
|
||||
{
|
||||
struct factory_data *data = _data;
|
||||
struct pw_core *core = data->core;
|
||||
struct pw_device *device;
|
||||
const char *lib, *factory_name, *name;
|
||||
struct device_data *nd;
|
||||
|
|
@ -87,13 +88,15 @@ static void *create_object(void *_data,
|
|||
factory_name = pw_properties_get(properties, "spa.factory.name");
|
||||
name = pw_properties_get(properties, "name");
|
||||
|
||||
if (lib == NULL && factory_name != NULL)
|
||||
lib = pw_core_find_spa_lib(core, factory_name);
|
||||
if (lib == NULL || factory_name == NULL)
|
||||
goto no_properties;
|
||||
|
||||
if (name == NULL)
|
||||
name = "spa-device";
|
||||
|
||||
device = pw_spa_device_load(data->core,
|
||||
device = pw_spa_device_load(core,
|
||||
NULL,
|
||||
pw_factory_get_global(data->this),
|
||||
lib,
|
||||
|
|
@ -120,11 +123,11 @@ static void *create_object(void *_data,
|
|||
return device;
|
||||
|
||||
no_properties:
|
||||
pw_log_error("needed properties: spa.library.name=<library-name> spa.factory.name=<factory-name>");
|
||||
pw_log_error("needed properties: [spa.library.name=<library-name>] spa.factory.name=<factory-name>");
|
||||
if (resource) {
|
||||
pw_resource_error(resource, -EINVAL,
|
||||
"needed properties: "
|
||||
"spa.library.name=<library-name> "
|
||||
"[spa.library.name=<library-name>] "
|
||||
"spa.factory.name=<factory-name>");
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@ const struct pw_module_events module_events = {
|
|||
SPA_EXPORT
|
||||
int pipewire__module_init(struct pw_module *module, const char *args)
|
||||
{
|
||||
const char *dir;
|
||||
struct pw_core *core = pw_module_get_core(module);
|
||||
const char *dir, *lib;
|
||||
char **argv;
|
||||
int n_tokens;
|
||||
struct pw_spa_monitor *monitor;
|
||||
|
|
@ -77,15 +78,21 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
goto wrong_arguments;
|
||||
|
||||
argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens);
|
||||
if (n_tokens < 3)
|
||||
if (n_tokens < 2)
|
||||
goto not_enough_arguments;
|
||||
|
||||
if ((dir = getenv("SPA_PLUGIN_DIR")) == NULL)
|
||||
dir = PLUGINDIR;
|
||||
|
||||
monitor = pw_spa_monitor_load(pw_module_get_core(module),
|
||||
if (n_tokens < 3)
|
||||
lib = pw_core_find_spa_lib(core, argv[0]);
|
||||
else
|
||||
lib = argv[2];
|
||||
|
||||
monitor = pw_spa_monitor_load(core,
|
||||
pw_module_get_global(module),
|
||||
dir, argv[0], argv[1], argv[2],
|
||||
dir, lib, argv[0], argv[1],
|
||||
NULL,
|
||||
sizeof(struct data));
|
||||
if (monitor == NULL)
|
||||
return -ENOMEM;
|
||||
|
|
@ -104,6 +111,6 @@ int pipewire__module_init(struct pw_module *module, const char *args)
|
|||
not_enough_arguments:
|
||||
pw_free_strv(argv);
|
||||
wrong_arguments:
|
||||
pw_log_error("usage: module-spa-monitor <plugin> <factory> <name>");
|
||||
pw_log_error("usage: module-spa-monitor <factory> <name> [<plugin>]");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ static void *create_object(void *_data,
|
|||
uint32_t new_id)
|
||||
{
|
||||
struct factory_data *data = _data;
|
||||
struct pw_core *core = data->core;
|
||||
struct pw_node *node;
|
||||
const char *lib, *factory_name, *name;
|
||||
struct node_data *nd;
|
||||
|
|
@ -87,13 +88,15 @@ static void *create_object(void *_data,
|
|||
factory_name = pw_properties_get(properties, "spa.factory.name");
|
||||
name = pw_properties_get(properties, "name");
|
||||
|
||||
if (lib == NULL && factory_name != NULL)
|
||||
lib = pw_core_find_spa_lib(core, factory_name);
|
||||
if (lib == NULL || factory_name == NULL)
|
||||
goto no_properties;
|
||||
|
||||
if (name == NULL)
|
||||
name = "spa-node";
|
||||
|
||||
node = pw_spa_node_load(data->core,
|
||||
node = pw_spa_node_load(core,
|
||||
NULL,
|
||||
pw_factory_get_global(data->this),
|
||||
lib,
|
||||
|
|
@ -120,11 +123,11 @@ static void *create_object(void *_data,
|
|||
return node;
|
||||
|
||||
no_properties:
|
||||
pw_log_error("needed properties: spa.library.name=<library-name> spa.factory.name=<factory-name>");
|
||||
pw_log_error("needed properties: [spa.library.name=<library-name>] spa.factory.name=<factory-name>");
|
||||
if (resource) {
|
||||
pw_resource_error(resource, -EINVAL,
|
||||
"needed properties: "
|
||||
"spa.library.name=<library-name> "
|
||||
"[spa.library.name=<library-name>] "
|
||||
"spa.factory.name=<factory-name>");
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -72,8 +72,7 @@ static void device_free(void *data)
|
|||
struct monitor_object *obj = data;
|
||||
spa_hook_remove(&obj->object_listener);
|
||||
spa_list_remove(&obj->link);
|
||||
spa_handle_clear(obj->handle);
|
||||
free(obj->handle);
|
||||
pw_unload_spa_handle(obj->handle);
|
||||
free(obj);
|
||||
}
|
||||
|
||||
|
|
@ -86,10 +85,11 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
const struct spa_monitor_object_info *info, uint64_t now)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
|
||||
struct pw_core *core = impl->core;
|
||||
int res;
|
||||
struct spa_handle *handle;
|
||||
struct monitor_object *obj;
|
||||
const char *name, *str;
|
||||
const char *name, *str, *lib;
|
||||
void *iface;
|
||||
struct pw_properties *props = NULL;
|
||||
const struct spa_support *support;
|
||||
|
|
@ -111,23 +111,25 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
if (now != 0 && pw_properties_get(props, PW_KEY_DEVICE_PLUGGED) == NULL)
|
||||
pw_properties_setf(props, PW_KEY_DEVICE_PLUGGED, "%"PRIu64, now);
|
||||
|
||||
support = pw_core_get_support(impl->core, &n_support);
|
||||
lib = pw_core_find_spa_lib(core, info->factory_name);
|
||||
if (lib == NULL) {
|
||||
pw_log_warn("monitor %p: unknown library for %s",
|
||||
this, info->factory_name);
|
||||
goto error_free_props;
|
||||
}
|
||||
|
||||
handle = calloc(1, spa_handle_factory_get_size(info->factory, NULL));
|
||||
if ((res = spa_handle_factory_init(info->factory,
|
||||
handle,
|
||||
&props->dict,
|
||||
support,
|
||||
n_support)) < 0) {
|
||||
pw_properties_free(props);
|
||||
pw_log_error("can't make factory instance: %d", res);
|
||||
return NULL;
|
||||
support = pw_core_get_support(core, &n_support);
|
||||
|
||||
handle = pw_load_spa_handle(lib, info->factory_name,
|
||||
&props->dict, n_support, support);
|
||||
if (handle == NULL) {
|
||||
pw_log_error("can't make factory instance: %m");
|
||||
goto error_free_props;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) {
|
||||
pw_log_error("can't get %d interface: %d", info->type, res);
|
||||
pw_properties_free(props);
|
||||
return NULL;
|
||||
goto error_free_handle;
|
||||
}
|
||||
|
||||
obj = calloc(1, sizeof(struct monitor_object));
|
||||
|
|
@ -140,7 +142,7 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
case SPA_TYPE_INTERFACE_Device:
|
||||
{
|
||||
struct pw_device *device;
|
||||
device = pw_spa_device_new(impl->core, NULL, impl->parent, name,
|
||||
device = pw_spa_device_new(core, NULL, impl->parent, name,
|
||||
0, iface, handle, props, 0);
|
||||
pw_device_add_listener(device, &obj->object_listener,
|
||||
&device_events, obj);
|
||||
|
|
@ -149,14 +151,21 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
|
|||
}
|
||||
default:
|
||||
pw_log_error("interface %d not implemented", obj->type);
|
||||
free(obj->name);
|
||||
free(obj);
|
||||
return NULL;
|
||||
goto error_free_object;
|
||||
}
|
||||
|
||||
spa_list_append(&impl->item_list, &obj->link);
|
||||
|
||||
return obj;
|
||||
|
||||
error_free_object:
|
||||
free(obj->name);
|
||||
free(obj);
|
||||
error_free_handle:
|
||||
pw_unload_spa_handle(handle);
|
||||
error_free_props:
|
||||
pw_properties_free(props);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct monitor_object *find_object(struct pw_spa_monitor *this, uint32_t id)
|
||||
|
|
@ -254,12 +263,13 @@ 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,
|
||||
size_t user_data_size)
|
||||
struct pw_global *parent,
|
||||
const char *dir,
|
||||
const char *lib,
|
||||
const char *factory_name,
|
||||
const char *system_name,
|
||||
struct pw_properties *properties,
|
||||
size_t user_data_size)
|
||||
{
|
||||
struct impl *impl;
|
||||
struct pw_spa_monitor *this;
|
||||
|
|
@ -276,7 +286,7 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
|||
|
||||
handle = pw_load_spa_handle(lib,
|
||||
factory_name,
|
||||
NULL,
|
||||
properties ? &properties->dict : NULL,
|
||||
n_support, support);
|
||||
if (handle == NULL)
|
||||
goto no_mem;
|
||||
|
|
@ -296,6 +306,7 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
|||
this->factory_name = strdup(factory_name);
|
||||
this->system_name = strdup(system_name);
|
||||
this->handle = handle;
|
||||
this->properties = properties;
|
||||
|
||||
if (user_data_size > 0)
|
||||
this->user_data = SPA_MEMBER(impl, sizeof(struct impl), void);
|
||||
|
|
@ -330,6 +341,7 @@ void pw_spa_monitor_destroy(struct pw_spa_monitor *monitor)
|
|||
free(monitor->lib);
|
||||
free(monitor->factory_name);
|
||||
free(monitor->system_name);
|
||||
|
||||
if (monitor->properties)
|
||||
pw_properties_free(monitor->properties);
|
||||
free(impl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ struct pw_spa_monitor {
|
|||
char *factory_name;
|
||||
char *system_name;
|
||||
struct spa_handle *handle;
|
||||
struct pw_properties *properties;
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
|
@ -51,6 +52,7 @@ pw_spa_monitor_load(struct pw_core *core,
|
|||
const char *lib,
|
||||
const char *factory_name,
|
||||
const char *system_name,
|
||||
struct pw_properties *properties,
|
||||
size_t user_data_size);
|
||||
void
|
||||
pw_spa_monitor_destroy(struct pw_spa_monitor *monitor);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue