2017-05-23 19:15:33 +02:00
|
|
|
/* PipeWire
|
2015-04-16 16:58:33 +02:00
|
|
|
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2017-02-24 09:28:18 +01:00
|
|
|
#include <spa/lib/debug.h>
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2017-07-11 15:57:20 +02:00
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
|
#include <pipewire/sig.h>
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct data {
|
2017-05-26 08:05:01 +02:00
|
|
|
bool running;
|
|
|
|
|
struct pw_loop *loop;
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_core *core;
|
|
|
|
|
struct pw_remote *remote;
|
|
|
|
|
struct pw_proxy *registry_proxy;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_listener on_info_changed;
|
2017-05-26 08:05:01 +02:00
|
|
|
struct pw_listener on_state_changed;
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct proxy_data {
|
|
|
|
|
void *info;
|
2017-05-23 19:15:33 +02:00
|
|
|
};
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static void print_properties(struct spa_dict *props, char mark)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_dict_item *item;
|
2015-07-28 17:05:03 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (props == NULL)
|
|
|
|
|
return;
|
2016-02-01 16:29:56 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\tproperties:\n", mark);
|
|
|
|
|
spa_dict_for_each(item, props) {
|
|
|
|
|
printf("%c\t\t%s = \"%s\"\n", mark, item->key, item->value);
|
|
|
|
|
}
|
2016-01-07 12:15:57 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
#define MARK_CHANGE(f) ((print_mark && ((info)->change_mask & (1 << (f)))) ? '*' : ' ')
|
2016-02-01 16:29:56 +01:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static void on_info_changed(struct pw_listener *listener, struct pw_remote *remote)
|
2016-01-07 12:15:57 +01:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_core_info *info = remote->info;
|
|
|
|
|
bool print_all = true, print_mark = false;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
printf("\tid: %u\n", info->id);
|
|
|
|
|
printf("\ttype: %s\n", PIPEWIRE_TYPE__Core);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\tuser-name: \"%s\"\n", MARK_CHANGE(0), info->user_name);
|
|
|
|
|
printf("%c\thost-name: \"%s\"\n", MARK_CHANGE(1), info->host_name);
|
|
|
|
|
printf("%c\tversion: \"%s\"\n", MARK_CHANGE(2), info->version);
|
|
|
|
|
printf("%c\tname: \"%s\"\n", MARK_CHANGE(3), info->name);
|
|
|
|
|
printf("%c\tcookie: %u\n", MARK_CHANGE(4), info->cookie);
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(5));
|
|
|
|
|
}
|
2016-12-02 13:38:43 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static void module_event_info(void *object, struct pw_module_info *info)
|
2016-12-02 13:38:43 +01:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = object;
|
|
|
|
|
struct proxy_data *data = proxy->user_data;
|
|
|
|
|
bool print_all, print_mark;
|
2016-12-02 13:38:43 +01:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("changed:\n");
|
|
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = data->info = pw_module_info_update(data->info, info);
|
2016-12-02 13:38:43 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("\tid: %u\n", info->id);
|
2017-07-11 12:24:03 +02:00
|
|
|
printf("\ttype: %s\n", PIPEWIRE_TYPE__Module);
|
|
|
|
|
if (print_all) {
|
|
|
|
|
printf("%c\tname: \"%s\"\n", MARK_CHANGE(0), info->name);
|
|
|
|
|
printf("%c\tfilename: \"%s\"\n", MARK_CHANGE(1), info->filename);
|
|
|
|
|
printf("%c\targs: \"%s\"\n", MARK_CHANGE(2), info->args);
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(3));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static const struct pw_module_events module_events = {
|
|
|
|
|
&module_event_info,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void node_event_info(void *object, struct pw_node_info *info)
|
2016-07-20 17:55:02 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = object;
|
|
|
|
|
struct proxy_data *data = proxy->user_data;
|
|
|
|
|
bool print_all, print_mark;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
print_mark = false;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2017-07-11 12:24:03 +02:00
|
|
|
else {
|
|
|
|
|
printf("changed:\n");
|
|
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = data->info = pw_node_info_update(data->info, info);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
printf("\tid: %u\n", info->id);
|
|
|
|
|
printf("\ttype: %s\n", PIPEWIRE_TYPE__Node);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2017-05-26 08:05:01 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
printf("%c\tname: \"%s\"\n", MARK_CHANGE(0), info->name);
|
2017-06-02 10:40:43 +02:00
|
|
|
printf("%c\tinput ports: %u/%u\n", MARK_CHANGE(1), info->n_input_ports, info->max_input_ports);
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\tinput formats:\n", MARK_CHANGE(2));
|
|
|
|
|
for (i = 0; i < info->n_input_formats; i++)
|
2017-06-06 13:30:34 +02:00
|
|
|
spa_debug_format(info->input_formats[i]);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-06-02 10:40:43 +02:00
|
|
|
printf("%c\toutput ports: %u/%u\n", MARK_CHANGE(3), info->n_output_ports, info->max_output_ports);
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\toutput formats:\n", MARK_CHANGE(4));
|
|
|
|
|
for (i = 0; i < info->n_output_formats; i++)
|
2017-06-06 13:30:34 +02:00
|
|
|
spa_debug_format(info->output_formats[i]);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
printf("%c\tstate: \"%s\"", MARK_CHANGE(5), pw_node_state_as_string(info->state));
|
|
|
|
|
if (info->state == PW_NODE_STATE_ERROR && info->error)
|
|
|
|
|
printf(" \"%s\"\n", info->error);
|
|
|
|
|
else
|
|
|
|
|
printf("\n");
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(6));
|
|
|
|
|
}
|
2016-07-20 17:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static const struct pw_node_events node_events = {
|
|
|
|
|
&node_event_info
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void client_event_info(void *object, struct pw_client_info *info)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = object;
|
|
|
|
|
struct proxy_data *data = proxy->user_data;
|
|
|
|
|
bool print_all, print_mark;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("changed:\n");
|
|
|
|
|
print_mark = true;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
info = data->info = pw_client_info_update(data->info, info);
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("\tid: %u\n", info->id);
|
2017-07-11 12:24:03 +02:00
|
|
|
printf("\ttype: %s\n", PIPEWIRE_TYPE__Client);
|
|
|
|
|
if (print_all) {
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(0));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static const struct pw_client_events client_events = {
|
|
|
|
|
&client_event_info
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void link_event_info(void *object, struct pw_link_info *info)
|
2016-07-20 17:55:02 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = object;
|
|
|
|
|
struct proxy_data *data = proxy->user_data;
|
|
|
|
|
bool print_all, print_mark;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
|
|
|
|
printf("added:\n");
|
|
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("changed:\n");
|
|
|
|
|
print_mark = true;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
info = data->info = pw_link_info_update(data->info, info);
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("\tid: %u\n", info->id);
|
|
|
|
|
printf("\ttype: %s\n", PIPEWIRE_TYPE__Link);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2017-05-26 08:05:01 +02:00
|
|
|
printf("%c\toutput-node-id: %u\n", MARK_CHANGE(0), info->output_node_id);
|
|
|
|
|
printf("%c\toutput-port-id: %u\n", MARK_CHANGE(1), info->output_port_id);
|
|
|
|
|
printf("%c\tinput-node-id: %u\n", MARK_CHANGE(2), info->input_node_id);
|
|
|
|
|
printf("%c\tinput-port-id: %u\n", MARK_CHANGE(3), info->input_port_id);
|
2017-06-02 10:40:43 +02:00
|
|
|
printf("%c\tformat:\n", MARK_CHANGE(4));
|
|
|
|
|
if (info->format)
|
2017-06-06 13:30:34 +02:00
|
|
|
spa_debug_format(info->format);
|
2017-06-02 10:40:43 +02:00
|
|
|
else
|
|
|
|
|
printf("\t none\n");
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static const struct pw_link_events link_events = {
|
|
|
|
|
&link_event_info
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
static void
|
2017-07-11 12:24:03 +02:00
|
|
|
destroy_proxy (void *data)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_proxy *proxy = data;
|
|
|
|
|
struct proxy_data *user_data = proxy->user_data;
|
|
|
|
|
struct pw_core *core = proxy->remote->core;
|
|
|
|
|
|
|
|
|
|
if (user_data->info == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (proxy->type == core->type.core) {
|
|
|
|
|
pw_core_info_free (user_data->info);
|
|
|
|
|
} else if (proxy->type == core->type.node) {
|
|
|
|
|
pw_node_info_free (user_data->info);
|
|
|
|
|
} else if (proxy->type == core->type.module) {
|
|
|
|
|
pw_module_info_free (user_data->info);
|
|
|
|
|
} else if (proxy->type == core->type.client) {
|
|
|
|
|
pw_client_info_free (user_data->info);
|
|
|
|
|
} else if (proxy->type == core->type.link) {
|
|
|
|
|
pw_link_info_free (user_data->info);
|
|
|
|
|
}
|
|
|
|
|
user_data->info = NULL;
|
|
|
|
|
}
|
2016-12-02 13:38:43 +01:00
|
|
|
|
2017-01-10 17:12:53 +01:00
|
|
|
|
2017-07-11 18:41:22 +02:00
|
|
|
static void registry_event_global(void *object, uint32_t id, uint32_t type, uint32_t version)
|
2017-07-11 12:24:03 +02:00
|
|
|
{
|
|
|
|
|
struct pw_proxy *registry_proxy = object;
|
|
|
|
|
struct data *data = registry_proxy->object;
|
|
|
|
|
struct pw_core *core = data->core;
|
|
|
|
|
struct pw_remote *remote = registry_proxy->remote;
|
|
|
|
|
struct pw_proxy *proxy = NULL;
|
2017-07-11 18:41:22 +02:00
|
|
|
uint32_t client_version;
|
2017-07-11 12:24:03 +02:00
|
|
|
const void *implementation;
|
|
|
|
|
|
2017-07-11 18:41:22 +02:00
|
|
|
if (type == core->type.node) {
|
2017-07-11 12:24:03 +02:00
|
|
|
implementation = &node_events;
|
|
|
|
|
client_version = PW_VERSION_NODE;
|
2017-07-11 18:41:22 +02:00
|
|
|
}
|
|
|
|
|
else if (type == core->type.module) {
|
2017-07-11 12:24:03 +02:00
|
|
|
implementation = &module_events;
|
|
|
|
|
client_version = PW_VERSION_MODULE;
|
2017-07-11 18:41:22 +02:00
|
|
|
}
|
|
|
|
|
else if (type == core->type.client) {
|
2017-07-11 12:24:03 +02:00
|
|
|
implementation = &client_events;
|
|
|
|
|
client_version = PW_VERSION_CLIENT;
|
2017-07-11 18:41:22 +02:00
|
|
|
}
|
|
|
|
|
else if (type == core->type.link) {
|
2017-07-11 12:24:03 +02:00
|
|
|
implementation = &link_events;
|
|
|
|
|
client_version = PW_VERSION_LINK;
|
|
|
|
|
} else
|
|
|
|
|
return;
|
|
|
|
|
|
2017-07-11 18:41:22 +02:00
|
|
|
proxy = pw_proxy_new(remote, SPA_ID_INVALID, type, sizeof(struct proxy_data));
|
2017-07-11 12:24:03 +02:00
|
|
|
if (proxy == NULL)
|
|
|
|
|
goto no_mem;
|
|
|
|
|
|
|
|
|
|
pw_proxy_set_implementation(proxy, data, client_version, implementation, destroy_proxy);
|
|
|
|
|
|
|
|
|
|
pw_registry_do_bind(registry_proxy, id, version, proxy->id);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
no_mem:
|
|
|
|
|
printf("failed to create proxy");
|
|
|
|
|
return;
|
2015-04-27 09:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static void registry_event_global_remove(void *object, uint32_t id)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
printf("removed:\n");
|
|
|
|
|
printf("\tid: %u\n", id);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
static const struct pw_registry_events registry_events = {
|
|
|
|
|
registry_event_global,
|
|
|
|
|
registry_event_global_remove,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void on_state_changed(struct pw_listener *listener, struct pw_remote *remote)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct data *data = SPA_CONTAINER_OF(listener, struct data, on_state_changed);
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
switch (remote->state) {
|
2017-07-11 15:57:20 +02:00
|
|
|
case PW_REMOTE_STATE_ERROR:
|
2017-07-11 12:24:03 +02:00
|
|
|
printf("remote error: %s\n", remote->error);
|
2017-05-26 08:05:01 +02:00
|
|
|
data->running = false;
|
|
|
|
|
break;
|
|
|
|
|
|
2017-07-11 15:57:20 +02:00
|
|
|
case PW_REMOTE_STATE_CONNECTED:
|
2017-07-11 12:24:03 +02:00
|
|
|
printf("remote state: \"%s\"\n", pw_remote_state_as_string(remote->state));
|
|
|
|
|
|
|
|
|
|
data->registry_proxy = pw_proxy_new(data->remote,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
data->core->type.registry,
|
|
|
|
|
0);
|
|
|
|
|
pw_proxy_set_implementation(data->registry_proxy, data, PW_VERSION_REGISTRY,
|
|
|
|
|
®istry_events, NULL);
|
|
|
|
|
|
2017-07-11 19:50:26 +02:00
|
|
|
pw_core_do_get_registry(data->remote->core_proxy, PW_VERSION_REGISTRY,
|
2017-07-11 12:24:03 +02:00
|
|
|
data->registry_proxy->id);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
default:
|
2017-07-11 12:24:03 +02:00
|
|
|
printf("remote state: \"%s\"\n", pw_remote_state_as_string(remote->state));
|
2017-05-26 08:05:01 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
int main(int argc, char *argv[])
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2017-07-11 12:24:03 +02:00
|
|
|
struct data data = { 0 };
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_init(&argc, &argv);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
data.loop = pw_loop_new();
|
|
|
|
|
data.running = true;
|
2017-07-11 12:24:03 +02:00
|
|
|
data.core = pw_core_new(data.loop, NULL);
|
|
|
|
|
data.remote = pw_remote_new(data.core, NULL);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
pw_signal_add(&data.remote->info_changed, &data.on_info_changed, on_info_changed);
|
|
|
|
|
pw_signal_add(&data.remote->state_changed, &data.on_state_changed, on_state_changed);
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
pw_remote_connect(data.remote);
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_loop_enter(data.loop);
|
|
|
|
|
while (data.running) {
|
|
|
|
|
pw_loop_iterate(data.loop, -1);
|
|
|
|
|
}
|
|
|
|
|
pw_loop_leave(data.loop);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
pw_remote_destroy(data.remote);
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_loop_destroy(data.loop);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return 0;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|