2017-07-25 19:52:31 +02:00
|
|
|
/* PipeWire
|
|
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2017-07-25 19:52:31 +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-07-25 19:52:31 +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.
|
|
|
|
|
*
|
|
|
|
|
* 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-07-25 19:52:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <sys/mman.h>
|
2017-08-27 12:12:14 +02:00
|
|
|
#include <signal.h>
|
2017-07-25 19:52:31 +02:00
|
|
|
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/param/video/format-utils.h>
|
|
|
|
|
#include <spa/param/props.h>
|
|
|
|
|
|
2017-07-25 19:52:31 +02:00
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
|
|
|
|
|
|
struct data {
|
2017-09-07 10:22:32 +02:00
|
|
|
struct pw_main_loop *loop;
|
2017-07-25 19:52:31 +02:00
|
|
|
|
|
|
|
|
struct pw_core *core;
|
|
|
|
|
|
|
|
|
|
struct pw_remote *remote;
|
2017-08-08 16:56:29 +02:00
|
|
|
struct spa_hook remote_listener;
|
2017-07-25 19:52:31 +02:00
|
|
|
|
|
|
|
|
struct pw_node *node;
|
2017-09-07 19:55:22 +02:00
|
|
|
const char *library;
|
|
|
|
|
const char *factory;
|
|
|
|
|
const char *path;
|
2017-07-25 19:52:31 +02:00
|
|
|
};
|
|
|
|
|
|
2017-09-07 19:55:22 +02:00
|
|
|
static int make_node(struct data *data)
|
2017-07-25 19:52:31 +02:00
|
|
|
{
|
2017-09-17 16:47:03 +02:00
|
|
|
struct pw_factory *factory;
|
2017-07-25 19:52:31 +02:00
|
|
|
struct pw_properties *props;
|
|
|
|
|
|
2017-09-17 16:47:03 +02:00
|
|
|
factory = pw_core_find_factory(data->core, "spa-node-factory");
|
2017-09-07 19:55:22 +02:00
|
|
|
if (factory == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
props = pw_properties_new("spa.library.name", data->library,
|
|
|
|
|
"spa.factory.name", data->factory, NULL);
|
|
|
|
|
|
|
|
|
|
if (data->path) {
|
2019-05-24 15:47:48 +02:00
|
|
|
pw_properties_set(props, PW_KEY_NODE_AUTOCONNECT, "1");
|
|
|
|
|
pw_properties_set(props, PW_KEY_NODE_TARGET, data->path);
|
2017-09-07 19:55:22 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:47:03 +02:00
|
|
|
data->node = pw_factory_create_object(factory,
|
|
|
|
|
NULL,
|
2018-08-27 15:03:11 +02:00
|
|
|
PW_TYPE_INTERFACE_Node,
|
2019-05-20 16:11:23 +02:00
|
|
|
PW_VERSION_NODE_PROXY,
|
2017-09-17 16:47:03 +02:00
|
|
|
props, SPA_ID_INVALID);
|
2017-07-25 19:52:31 +02:00
|
|
|
|
2017-10-13 16:18:42 +02:00
|
|
|
pw_node_set_active(data->node, true);
|
|
|
|
|
|
2019-05-30 16:11:31 +02:00
|
|
|
pw_remote_export(data->remote, PW_TYPE_INTERFACE_Node, NULL, data->node, 0);
|
2017-09-07 19:55:22 +02:00
|
|
|
|
|
|
|
|
return 0;
|
2017-07-25 19:52:31 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remote_state state, const char *error)
|
2017-07-25 19:52:31 +02:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct data *data = _data;
|
2017-07-25 19:52:31 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
switch (state) {
|
2017-07-25 19:52:31 +02:00
|
|
|
case PW_REMOTE_STATE_ERROR:
|
2017-08-04 10:18:54 +02:00
|
|
|
printf("remote error: %s\n", error);
|
2017-09-07 10:22:32 +02:00
|
|
|
pw_main_loop_quit(data->loop);
|
2017-07-25 19:52:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PW_REMOTE_STATE_CONNECTED:
|
2017-08-25 18:59:01 +02:00
|
|
|
printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
|
2017-09-07 19:55:22 +02:00
|
|
|
if (make_node(data) < 0) {
|
|
|
|
|
pw_log_error("can't make node");
|
|
|
|
|
pw_main_loop_quit(data->loop);
|
|
|
|
|
}
|
2017-07-25 19:52:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2017-08-04 10:18:54 +02:00
|
|
|
printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
|
2017-07-25 19:52:31 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_remote_events remote_events = {
|
|
|
|
|
PW_VERSION_REMOTE_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.state_changed = on_state_changed,
|
|
|
|
|
};
|
2017-07-25 19:52:31 +02:00
|
|
|
|
2017-08-27 12:12:14 +02:00
|
|
|
static void do_quit(void *data, int signal_number)
|
|
|
|
|
{
|
|
|
|
|
struct data *d = data;
|
2017-09-07 10:22:32 +02:00
|
|
|
pw_main_loop_quit(d->loop);
|
2017-08-27 12:12:14 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-25 19:52:31 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
struct data data = { 0, };
|
2017-09-07 10:22:32 +02:00
|
|
|
struct pw_loop *l;
|
2017-07-25 19:52:31 +02:00
|
|
|
|
|
|
|
|
pw_init(&argc, &argv);
|
|
|
|
|
|
2017-09-07 19:55:22 +02:00
|
|
|
if (argc < 3) {
|
|
|
|
|
fprintf(stderr, "usage: %s <library> <factory> [path]\n\n"
|
|
|
|
|
"\texample: %s v4l2/libspa-v4l2 v4l2-source\n\n",
|
|
|
|
|
argv[0], argv[0]);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 10:22:32 +02:00
|
|
|
data.loop = pw_main_loop_new(NULL);
|
|
|
|
|
l = pw_main_loop_get_loop(data.loop);
|
|
|
|
|
pw_loop_add_signal(l, SIGINT, do_quit, &data);
|
|
|
|
|
pw_loop_add_signal(l, SIGTERM, do_quit, &data);
|
2019-01-08 17:30:12 +01:00
|
|
|
data.core = pw_core_new(l, NULL, 0);
|
2017-09-15 14:51:39 +02:00
|
|
|
data.remote = pw_remote_new(data.core, NULL, 0);
|
2017-09-07 19:55:22 +02:00
|
|
|
data.library = argv[1];
|
|
|
|
|
data.factory = argv[2];
|
|
|
|
|
if (argc > 3)
|
|
|
|
|
data.path = argv[3];
|
2017-07-25 19:52:31 +02:00
|
|
|
|
2018-01-23 15:25:48 +01:00
|
|
|
pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL, NULL, NULL, NULL);
|
2017-07-25 19:52:31 +02:00
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
|
2017-07-25 19:52:31 +02:00
|
|
|
|
|
|
|
|
pw_remote_connect(data.remote);
|
|
|
|
|
|
2017-09-07 10:22:32 +02:00
|
|
|
pw_main_loop_run(data.loop);
|
2017-07-25 19:52:31 +02:00
|
|
|
|
2017-08-27 12:12:14 +02:00
|
|
|
pw_core_destroy(data.core);
|
2017-09-07 10:22:32 +02:00
|
|
|
pw_main_loop_destroy(data.loop);
|
2017-07-25 19:52:31 +02:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|