summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2019-09-20 13:04:14 +0200
committerWim Taymans <wtaymans@redhat.com>2019-09-20 13:04:14 +0200
commit6756a3c8fc47f46feaafe0373928110dc81124fc (patch)
treec33046495a6efad85246b944069ea3b992c2ebcb /src/modules
parent818fb9e904a3ea43ba313994e404f1b63833c548 (diff)
monitor: remove monitor API and use device
Remove the monitor API, we can use the device API for it. Make sure we support creating devices (like alsa) from another device (udev). Use new object.id to store the object id in the object properties. Use the port.id/node.id etc to make relations to other objects.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/spa/meson.build9
-rw-r--r--src/modules/spa/module-device.c1
-rw-r--r--src/modules/spa/module-monitor.c123
-rw-r--r--src/modules/spa/module-node.c1
-rw-r--r--src/modules/spa/spa-monitor.c336
-rw-r--r--src/modules/spa/spa-monitor.h60
6 files changed, 0 insertions, 530 deletions
diff --git a/src/modules/spa/meson.build b/src/modules/spa/meson.build
index 255588d8..e8bbc9d5 100644
--- a/src/modules/spa/meson.build
+++ b/src/modules/spa/meson.build
@@ -3,15 +3,6 @@ pipewire_module_spa_c_args = [
'-D_GNU_SOURCE',
]
-pipewire_module_spa_monitor = shared_library('pipewire-module-spa-monitor',
- [ 'module-monitor.c', 'spa-monitor.c', 'spa-node.c', 'spa-device.c' ],
- c_args : pipewire_module_spa_c_args,
- include_directories : [configinc, spa_inc],
- install : true,
- install_dir : modules_install_dir,
- dependencies : [mathlib, dl_lib, pipewire_dep],
-)
-
pipewire_module_spa_node = shared_library('pipewire-module-spa-node',
[ 'module-node.c', 'spa-node.c' ],
c_args : pipewire_module_spa_c_args,
diff --git a/src/modules/spa/module-device.c b/src/modules/spa/module-device.c
index 684419a0..921bcd7f 100644
--- a/src/modules/spa/module-device.c
+++ b/src/modules/spa/module-device.c
@@ -35,7 +35,6 @@
#include <pipewire/utils.h>
#include <pipewire/keys.h>
-#include "spa-monitor.h"
#include "spa-device.h"
#define MODULE_USAGE "<factory> [key=value ...]"
diff --git a/src/modules/spa/module-monitor.c b/src/modules/spa/module-monitor.c
deleted file mode 100644
index 8c7228be..00000000
--- a/src/modules/spa/module-monitor.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/* PipeWire
- * Copyright © 2016 Axis Communications <dev-gstreamer@axis.com>
- * @author Linus Svensson <linus.svensson@axis.com>
- * Copyright © 2018 Wim Taymans
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <errno.h>
-#include <getopt.h>
-#include <limits.h>
-
-#include <pipewire/utils.h>
-#include <pipewire/log.h>
-#include <pipewire/core.h>
-#include <pipewire/module.h>
-#include <pipewire/keys.h>
-
-#include "spa-monitor.h"
-
-#define MODULE_USAGE "<factory> <name> [key=value ...]"
-
-static const struct spa_dict_item module_props[] = {
- { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
- { PW_KEY_MODULE_DESCRIPTION, "Manage SPA monitors" },
- { PW_KEY_MODULE_USAGE, MODULE_USAGE },
- { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
-};
-
-struct data {
- struct pw_spa_monitor *monitor;
- struct spa_hook module_listener;
-};
-
-static void module_destroy(void *data)
-{
- struct data *d = data;
-
- spa_hook_remove(&d->module_listener);
-
- pw_spa_monitor_destroy(d->monitor);
-}
-
-const struct pw_module_events module_events = {
- PW_VERSION_MODULE_EVENTS,
- .destroy = module_destroy,
-};
-
-SPA_EXPORT
-int pipewire__module_init(struct pw_module *module, const char *args)
-{
- struct pw_core *core = pw_module_get_core(module);
- struct pw_properties *props = NULL;
- char **argv = NULL;
- int n_tokens, res;
- struct pw_spa_monitor *monitor;
- struct data *data;
-
- if (args == NULL)
- goto error_arguments;
-
- argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens);
- if (n_tokens < 2)
- goto error_arguments;
-
- if (n_tokens == 3) {
- props = pw_properties_new_string(argv[2]);
- if (props == NULL) {
- res = -errno;
- goto error_exit_cleanup;
- }
- }
-
- monitor = pw_spa_monitor_load(core,
- argv[0], argv[1],
- props,
- sizeof(struct data));
- if (monitor == NULL) {
- res = -errno;
- goto error_exit_cleanup;
- }
-
- pw_free_strv(argv);
-
- data = monitor->user_data;
- data->monitor = monitor;
-
- pw_module_add_listener(module, &data->module_listener, &module_events, data);
-
- pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
-
- return 0;
-
-error_arguments:
- res = -EINVAL;
- pw_log_error("usage: module-spa-monitor " MODULE_USAGE);
- goto error_exit_cleanup;
-error_exit_cleanup:
- if (argv)
- pw_free_strv(argv);
- return res;
-}
diff --git a/src/modules/spa/module-node.c b/src/modules/spa/module-node.c
index d4828c25..0b80fadc 100644
--- a/src/modules/spa/module-node.c
+++ b/src/modules/spa/module-node.c
@@ -37,7 +37,6 @@
#include <pipewire/module.h>
#include <pipewire/utils.h>
-#include "spa-monitor.h"
#include "spa-node.h"
#define MODULE_USAGE "<factory> [key=value ...]"
diff --git a/src/modules/spa/spa-monitor.c b/src/modules/spa/spa-monitor.c
deleted file mode 100644
index deff494b..00000000
--- a/src/modules/spa/spa-monitor.c
+++ /dev/null
@@ -1,336 +0,0 @@
-/* PipeWire
- *
- * Copyright © 2018 Wim Taymans
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <dlfcn.h>
-#include <errno.h>
-#include <poll.h>
-#include <string.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <time.h>
-
-#include <spa/node/node.h>
-#include <spa/monitor/monitor.h>
-#include <spa/pod/parser.h>
-#include <spa/debug/pod.h>
-
-#include <pipewire/log.h>
-#include <pipewire/type.h>
-#include <pipewire/node.h>
-#include <pipewire/device.h>
-#include <pipewire/keys.h>
-#include <pipewire/pipewire.h>
-
-#include "spa-monitor.h"
-#include "spa-device.h"
-
-struct monitor_object {
- uint32_t id;
- char *name;
- struct spa_list link;
- struct spa_handle *handle;
- uint32_t type;
- void *object;
- struct spa_hook object_listener;
-};
-
-struct impl {
- struct pw_spa_monitor this;
-
- struct pw_core *core;
-
- struct spa_list item_list;
-};
-
-static void device_free(void *data)
-{
- struct monitor_object *obj = data;
- spa_hook_remove(&obj->object_listener);
- spa_list_remove(&obj->link);
- pw_unload_spa_handle(obj->handle);
- free(obj);
-}
-
-static const struct pw_device_events device_events = {
- PW_VERSION_DEVICE_EVENTS,
- .free = device_free
-};
-
-static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t id,
- 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;
- void *iface;
- struct pw_properties *props = NULL;
-
- if (info->props)
- props = pw_properties_new_dict(info->props);
- else
- props = pw_properties_new(NULL, NULL);
-
- if (props == NULL)
- return NULL;
-
- if ((name = pw_properties_get(props, PW_KEY_DEVICE_NAME)) == NULL)
- name = "unknown";
-
- pw_log_debug("monitor %p: add: \"%s\" (%u)", this, name, id);
-
- if ((str = pw_properties_get(props, PW_KEY_DEVICE_FORM_FACTOR)) != NULL)
- if (strcmp(str, "internal") == 0)
- now = 0;
- if (now != 0 && pw_properties_get(props, PW_KEY_DEVICE_PLUGGED) == NULL)
- pw_properties_setf(props, PW_KEY_DEVICE_PLUGGED, "%"PRIu64, now);
-
- handle = pw_core_load_spa_handle(core, info->factory_name,
- &props->dict);
- if (handle == NULL) {
- res = -errno;
- pw_log_error("can't make factory instance: %m");
- goto error_exit_free_props;
- }
-
- if ((res = spa_handle_get_interface(handle, info->type, &iface)) < 0) {
- pw_log_error("can't get %d interface: %s", info->type, spa_strerror(res));
- goto error_exit_free_handle;
- }
-
- obj = calloc(1, sizeof(struct monitor_object));
- if (obj == NULL) {
- res = -errno;
- goto error_exit_free_handle;
- }
- obj->id = id;
- obj->name = strdup(name);
- obj->handle = handle;
- obj->type = info->type;
-
- switch (obj->type) {
- case SPA_TYPE_INTERFACE_Device:
- {
- struct pw_device *device;
- device = pw_spa_device_new(core,
- 0, iface, handle, props, 0);
- pw_device_add_listener(device, &obj->object_listener,
- &device_events, obj);
- obj->object = device;
- break;
- }
- default:
- res = -ENOTSUP;
- pw_log_error("interface %d not implemented", obj->type);
- goto error_exit_free_object;
- }
-
- spa_list_append(&impl->item_list, &obj->link);
-
- return obj;
-
-error_exit_free_object:
- free(obj->name);
- free(obj);
-error_exit_free_handle:
- pw_unload_spa_handle(handle);
-error_exit_free_props:
- pw_properties_free(props);
- errno = -res;
- return NULL;
-}
-
-static struct monitor_object *find_object(struct pw_spa_monitor *this, uint32_t id)
-{
- struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
- struct monitor_object *obj;
-
- spa_list_for_each(obj, &impl->item_list, link) {
- if (obj->id == id) {
- return obj;
- }
- }
- return NULL;
-}
-
-void destroy_object(struct monitor_object *obj)
-{
- switch (obj->type) {
- case SPA_TYPE_INTERFACE_Node:
- pw_node_destroy(obj->object);
- break;
- case SPA_TYPE_INTERFACE_Device:
- pw_device_destroy(obj->object);
- break;
- default:
- break;
- }
-}
-
-static void change_object(struct pw_spa_monitor *this, struct monitor_object *obj,
- const struct spa_monitor_object_info *info, uint64_t now)
-{
- pw_log_debug("monitor %p: change: \"%s\" (%u)", this, obj->name, obj->id);
-}
-
-static int on_monitor_object_info(void *data, uint32_t id,
- const struct spa_monitor_object_info *info)
-{
- struct impl *impl = data;
- struct pw_spa_monitor *this = &impl->this;
- struct timespec now;
- uint64_t now_nsec;
- struct monitor_object *obj;
-
- clock_gettime(CLOCK_MONOTONIC, &now);
- now_nsec = SPA_TIMESPEC_TO_NSEC(&now);
-
- obj = find_object(this, id);
-
- if (info == NULL) {
- if (obj == NULL)
- return -ENODEV;
-
- pw_log_debug("monitor %p: remove: (%s) %u", this, obj->name, id);
- destroy_object(obj);
- } else if (obj == NULL) {
- obj = add_object(this, id, info, now_nsec);
- if (obj == NULL)
- return -errno;
- } else {
- change_object(this, obj, info, now_nsec);
- }
- return 0;
-}
-
-static void update_monitor(struct pw_core *core, const char *name)
-{
- const char *monitors;
- struct spa_dict_item item;
- const struct pw_properties *props;
- struct spa_dict dict = SPA_DICT_INIT(&item, 1);
-
- props = pw_core_get_properties(core);
-
- if (props)
- monitors = pw_properties_get(props, PW_KEY_CORE_MONITORS);
- else
- monitors = NULL;
-
- item.key = PW_KEY_CORE_MONITORS;
- if (monitors == NULL)
- item.value = name;
- else
- asprintf((char **) &item.value, "%s,%s", monitors, name);
-
- pw_core_update_properties(core, &dict);
-
- if (monitors != NULL)
- free((void *) item.value);
-}
-
-static const struct spa_monitor_callbacks callbacks = {
- SPA_VERSION_MONITOR_CALLBACKS,
- .object_info = on_monitor_object_info,
-};
-
-struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
- 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;
- struct spa_handle *handle;
- int res;
- void *iface;
-
- handle = pw_core_load_spa_handle(core,
- factory_name,
- properties ? &properties->dict : NULL);
- if (handle == NULL) {
- res = -errno;
- goto error_exit;
- }
-
- if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
- pw_log_error("can't get MONITOR interface: %s", spa_strerror(res));
- goto error_exit_unload;
- }
-
- impl = calloc(1, sizeof(struct impl) + user_data_size);
- if (impl == NULL) {
- res = -errno;
- goto error_exit_unload;
- }
-
- impl->core = core;
- spa_list_init(&impl->item_list);
-
- this = &impl->this;
- this->monitor = iface;
- 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);
-
- update_monitor(core, this->system_name);
-
- spa_monitor_set_callbacks(this->monitor, &callbacks, impl);
-
- return this;
-
-error_exit_unload:
- pw_unload_spa_handle(handle);
-error_exit:
- errno = -res;
- return NULL;
-}
-
-void pw_spa_monitor_destroy(struct pw_spa_monitor *monitor)
-{
- struct impl *impl = SPA_CONTAINER_OF(monitor, struct impl, this);
- struct monitor_object *obj, *tmp;
-
- pw_log_debug("spa-monitor %p: destroy", impl);
-
- spa_list_for_each_safe(obj, tmp, &impl->item_list, link)
- destroy_object(obj);
-
- pw_unload_spa_handle(monitor->handle);
- free(monitor->factory_name);
- free(monitor->system_name);
- if (monitor->properties)
- pw_properties_free(monitor->properties);
- free(impl);
-}
diff --git a/src/modules/spa/spa-monitor.h b/src/modules/spa/spa-monitor.h
deleted file mode 100644
index 6bea028b..00000000
--- a/src/modules/spa/spa-monitor.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* PipeWire
- *
- * Copyright © 2018 Wim Taymans
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef PIPEWIRE_SPA_MONITOR_H
-#define PIPEWIRE_SPA_MONITOR_H
-
-#include <spa/monitor/monitor.h>
-
-#include <pipewire/core.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct pw_spa_monitor {
- struct spa_monitor *monitor;
-
- char *factory_name;
- char *system_name;
- struct spa_handle *handle;
- struct pw_properties *properties;
-
- void *user_data;
-};
-
-struct pw_spa_monitor *
-pw_spa_monitor_load(struct pw_core *core,
- 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);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PIPEWIRE_SPA_MONITOR_H */