2017-06-19 15:49:13 +02:00
|
|
|
/* PipeWire
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2016 Axis Communications <dev-gstreamer@axis.com>
|
|
|
|
|
* @author Linus Svensson <linus.svensson@axis.com>
|
|
|
|
|
* Copyright © 2018 Wim Taymans
|
2017-06-19 15:49:13 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* 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:
|
2017-06-19 15:49:13 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
2017-06-19 15:49:13 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* 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.
|
2017-06-19 15:49:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-12-18 11:38:30 +01:00
|
|
|
#include <errno.h>
|
2017-06-19 15:49:13 +02:00
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
2017-07-11 15:57:20 +02:00
|
|
|
#include <pipewire/utils.h>
|
2017-08-08 19:55:14 +02:00
|
|
|
#include <pipewire/log.h>
|
2017-07-11 15:57:20 +02:00
|
|
|
#include <pipewire/core.h>
|
|
|
|
|
#include <pipewire/module.h>
|
2019-05-24 15:47:48 +02:00
|
|
|
#include <pipewire/keys.h>
|
2017-06-19 15:49:13 +02:00
|
|
|
|
|
|
|
|
#include "spa-monitor.h"
|
|
|
|
|
|
2018-06-01 11:23:02 +02:00
|
|
|
static const struct spa_dict_item module_props[] = {
|
2019-05-24 15:47:48 +02:00
|
|
|
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
|
|
|
|
|
{ PW_KEY_MODULE_DESCRIPTION, "Manage SPA monitors" },
|
|
|
|
|
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
|
2018-06-01 11:23:02 +02:00
|
|
|
};
|
|
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-06 13:24:41 +01:00
|
|
|
SPA_EXPORT
|
2017-12-18 11:38:30 +01:00
|
|
|
int pipewire__module_init(struct pw_module *module, const char *args)
|
2017-06-19 15:49:13 +02:00
|
|
|
{
|
2019-05-31 15:06:44 +02:00
|
|
|
struct pw_core *core = pw_module_get_core(module);
|
|
|
|
|
const char *dir, *lib;
|
2017-06-19 15:49:13 +02:00
|
|
|
char **argv;
|
|
|
|
|
int n_tokens;
|
2017-08-22 18:30:10 +02:00
|
|
|
struct pw_spa_monitor *monitor;
|
|
|
|
|
struct data *data;
|
2017-06-19 15:49:13 +02:00
|
|
|
|
|
|
|
|
if (args == NULL)
|
|
|
|
|
goto wrong_arguments;
|
|
|
|
|
|
|
|
|
|
argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens);
|
2019-05-31 15:06:44 +02:00
|
|
|
if (n_tokens < 2)
|
2017-06-19 15:49:13 +02:00
|
|
|
goto not_enough_arguments;
|
|
|
|
|
|
|
|
|
|
if ((dir = getenv("SPA_PLUGIN_DIR")) == NULL)
|
|
|
|
|
dir = PLUGINDIR;
|
|
|
|
|
|
2019-05-31 15:06:44 +02:00
|
|
|
if (n_tokens < 3)
|
|
|
|
|
lib = pw_core_find_spa_lib(core, argv[0]);
|
|
|
|
|
else
|
|
|
|
|
lib = argv[2];
|
|
|
|
|
|
|
|
|
|
monitor = pw_spa_monitor_load(core,
|
2017-08-22 18:30:10 +02:00
|
|
|
pw_module_get_global(module),
|
2019-05-31 15:06:44 +02:00
|
|
|
dir, lib, argv[0], argv[1],
|
|
|
|
|
NULL,
|
2017-08-22 18:30:10 +02:00
|
|
|
sizeof(struct data));
|
2017-12-18 11:38:30 +01:00
|
|
|
if (monitor == NULL)
|
|
|
|
|
return -ENOMEM;
|
2017-08-22 18:30:10 +02:00
|
|
|
|
|
|
|
|
data = monitor->user_data;
|
|
|
|
|
data->monitor = monitor;
|
2017-06-19 15:49:13 +02:00
|
|
|
|
|
|
|
|
pw_free_strv(argv);
|
|
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
pw_module_add_listener(module, &data->module_listener, &module_events, data);
|
|
|
|
|
|
2018-06-01 11:23:02 +02:00
|
|
|
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
|
|
|
|
|
2017-12-18 11:38:30 +01:00
|
|
|
return 0;
|
2017-06-19 15:49:13 +02:00
|
|
|
|
|
|
|
|
not_enough_arguments:
|
|
|
|
|
pw_free_strv(argv);
|
|
|
|
|
wrong_arguments:
|
2019-05-31 15:06:44 +02:00
|
|
|
pw_log_error("usage: module-spa-monitor <factory> <name> [<plugin>]");
|
2017-12-18 11:38:30 +01:00
|
|
|
return -EINVAL;
|
2017-06-19 15:49:13 +02:00
|
|
|
}
|