2017-05-23 19:15:33 +02:00
|
|
|
/* PipeWire
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2015-04-16 16:58:33 +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:
|
2015-04-16 16:58:33 +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.
|
2015-04-16 16:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
#include <stdio.h>
|
2017-09-11 09:48:13 +02:00
|
|
|
#include <signal.h>
|
2020-03-24 16:36:48 +01:00
|
|
|
#include <getopt.h>
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2019-12-06 11:48:40 +01:00
|
|
|
#include <spa/utils/result.h>
|
2021-05-18 11:36:13 +10:00
|
|
|
#include <spa/utils/string.h>
|
2018-08-14 13:05:10 +02:00
|
|
|
#include <spa/debug/pod.h>
|
2018-08-14 12:33:53 +02:00
|
|
|
#include <spa/debug/format.h>
|
2018-08-23 17:47:57 +02:00
|
|
|
#include <spa/debug/types.h>
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#include <pipewire/pipewire.h>
|
2017-07-11 15:57:20 +02:00
|
|
|
|
2018-02-20 10:31:55 +01:00
|
|
|
struct proxy_data;
|
|
|
|
|
|
|
|
|
|
typedef void (*print_func_t) (struct proxy_data *data);
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
struct param {
|
|
|
|
|
struct spa_list link;
|
|
|
|
|
uint32_t id;
|
2019-03-14 16:42:59 +01:00
|
|
|
int seq;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_pod *param;
|
2020-03-06 15:36:57 +01:00
|
|
|
unsigned int changed:1;
|
2019-02-27 16:43:01 +01:00
|
|
|
};
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct data {
|
2017-09-11 09:48:13 +02:00
|
|
|
struct pw_main_loop *loop;
|
2019-12-10 18:19:56 +01:00
|
|
|
struct pw_context *context;
|
2017-08-04 10:18:54 +02:00
|
|
|
|
2019-12-11 07:46:59 +01:00
|
|
|
struct pw_core *core;
|
2019-01-10 10:08:14 +01:00
|
|
|
struct spa_hook core_listener;
|
2017-08-04 10:18:54 +02:00
|
|
|
|
2019-12-11 09:44:48 +01:00
|
|
|
struct pw_registry *registry;
|
2017-08-08 16:56:29 +02:00
|
|
|
struct spa_hook registry_listener;
|
2018-02-20 10:31:55 +01:00
|
|
|
|
|
|
|
|
struct spa_list pending_list;
|
2021-11-03 17:25:11 +01:00
|
|
|
struct spa_list global_list;
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct proxy_data {
|
2017-09-18 09:35:00 +02:00
|
|
|
struct data *data;
|
2018-02-20 10:31:55 +01:00
|
|
|
bool first;
|
2017-08-04 10:18:54 +02:00
|
|
|
struct pw_proxy *proxy;
|
2017-07-13 15:21:52 +02:00
|
|
|
uint32_t id;
|
2017-08-01 17:09:57 +02:00
|
|
|
uint32_t permissions;
|
2017-07-13 15:21:52 +02:00
|
|
|
uint32_t version;
|
2019-12-19 13:15:10 +01:00
|
|
|
char *type;
|
2017-07-11 12:24:03 +02:00
|
|
|
void *info;
|
2017-08-04 10:18:54 +02:00
|
|
|
pw_destroy_t destroy;
|
2017-08-08 16:56:29 +02:00
|
|
|
struct spa_hook proxy_listener;
|
2019-05-29 10:39:24 +02:00
|
|
|
struct spa_hook object_listener;
|
2019-02-25 16:25:27 +01:00
|
|
|
int pending_seq;
|
2021-11-03 17:25:11 +01:00
|
|
|
struct spa_list global_link;
|
2018-02-20 10:31:55 +01:00
|
|
|
struct spa_list pending_link;
|
|
|
|
|
print_func_t print_func;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_list param_list;
|
2017-05-23 19:15:33 +02:00
|
|
|
};
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2018-02-20 10:31:55 +01:00
|
|
|
static void add_pending(struct proxy_data *pd)
|
|
|
|
|
{
|
|
|
|
|
struct data *d = pd->data;
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
if (pd->pending_seq == 0) {
|
|
|
|
|
spa_list_append(&d->pending_list, &pd->pending_link);
|
|
|
|
|
}
|
2019-12-11 07:46:59 +01:00
|
|
|
pd->pending_seq = pw_core_sync(d->core, 0, pd->pending_seq);
|
2018-02-20 10:31:55 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-19 20:02:06 +02:00
|
|
|
static void remove_pending(struct proxy_data *pd)
|
|
|
|
|
{
|
2019-02-25 16:25:27 +01:00
|
|
|
if (pd->pending_seq != 0) {
|
2018-04-19 20:02:06 +02:00
|
|
|
spa_list_remove(&pd->pending_link);
|
2019-02-25 16:25:27 +01:00
|
|
|
pd->pending_seq = 0;
|
2018-04-19 20:02:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void on_core_done(void *data, uint32_t id, int seq)
|
2018-02-20 10:31:55 +01:00
|
|
|
{
|
|
|
|
|
struct data *d = data;
|
2018-04-19 20:02:06 +02:00
|
|
|
struct proxy_data *pd, *t;
|
2018-02-20 10:31:55 +01:00
|
|
|
|
2018-04-19 20:02:06 +02:00
|
|
|
spa_list_for_each_safe(pd, t, &d->pending_list, pending_link) {
|
2018-02-20 10:31:55 +01:00
|
|
|
if (pd->pending_seq == seq) {
|
2018-04-19 20:02:06 +02:00
|
|
|
remove_pending(pd);
|
2018-02-20 10:31:55 +01:00
|
|
|
pd->print_func(pd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void clear_params(struct proxy_data *data)
|
|
|
|
|
{
|
2019-02-27 16:43:01 +01:00
|
|
|
struct param *p;
|
|
|
|
|
spa_list_consume(p, &data->param_list, link) {
|
|
|
|
|
spa_list_remove(&p->link);
|
|
|
|
|
free(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-20 10:31:55 +01:00
|
|
|
|
2019-03-14 16:42:59 +01:00
|
|
|
static void remove_params(struct proxy_data *data, uint32_t id, int seq)
|
2019-02-27 16:43:01 +01:00
|
|
|
{
|
|
|
|
|
struct param *p, *t;
|
2019-03-14 16:42:59 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
spa_list_for_each_safe(p, t, &data->param_list, link) {
|
2019-03-14 16:42:59 +01:00
|
|
|
if (p->id == id && seq != p->seq) {
|
2019-02-27 16:43:01 +01:00
|
|
|
spa_list_remove(&p->link);
|
|
|
|
|
free(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-20 10:31:55 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-14 16:42:59 +01:00
|
|
|
static void event_param(void *object, int seq, uint32_t id,
|
|
|
|
|
uint32_t index, uint32_t next, const struct spa_pod *param)
|
2018-02-20 10:31:55 +01:00
|
|
|
{
|
2019-03-14 16:42:59 +01:00
|
|
|
struct proxy_data *data = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct param *p;
|
2018-02-20 10:31:55 +01:00
|
|
|
|
2019-03-14 16:42:59 +01:00
|
|
|
/* remove all params with the same id and older seq */
|
|
|
|
|
remove_params(data, id, seq);
|
|
|
|
|
|
|
|
|
|
/* add new param */
|
2019-02-27 16:43:01 +01:00
|
|
|
p = malloc(sizeof(struct param) + SPA_POD_SIZE(param));
|
2019-03-14 16:42:59 +01:00
|
|
|
if (p == NULL) {
|
|
|
|
|
pw_log_error("can't add param: %m");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-27 16:43:01 +01:00
|
|
|
|
|
|
|
|
p->id = id;
|
2019-03-14 16:42:59 +01:00
|
|
|
p->seq = seq;
|
2021-05-06 13:41:44 +10:00
|
|
|
p->param = SPA_PTROFF(p, sizeof(struct param), struct spa_pod);
|
2020-03-06 15:36:57 +01:00
|
|
|
p->changed = true;
|
2019-02-27 16:43:01 +01:00
|
|
|
memcpy(p->param, param, SPA_POD_SIZE(param));
|
|
|
|
|
spa_list_append(&data->param_list, &p->link);
|
2019-03-01 12:00:42 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
static void print_params(struct proxy_data *data, char mark)
|
|
|
|
|
{
|
|
|
|
|
struct param *p;
|
|
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\tparams:\n", mark);
|
2019-02-27 16:43:01 +01:00
|
|
|
spa_list_for_each(p, &data->param_list, link) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\t id:%u (%s)\n", p->changed ? mark : ' ', p->id,
|
2020-06-18 12:54:17 +02:00
|
|
|
spa_debug_type_find_name(spa_type_param, p->id));
|
2019-02-27 16:43:01 +01:00
|
|
|
if (spa_pod_is_object_type(p->param, SPA_TYPE_OBJECT_Format))
|
|
|
|
|
spa_debug_format(10, NULL, p->param);
|
|
|
|
|
else
|
|
|
|
|
spa_debug_pod(10, NULL, p->param);
|
2020-03-06 15:36:57 +01:00
|
|
|
p->changed = false;
|
2019-02-27 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 11:18:17 +01:00
|
|
|
static void print_properties(const struct spa_dict *props, char mark)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2017-09-07 19:55:22 +02:00
|
|
|
const struct spa_dict_item *item;
|
2015-07-28 17:05:03 +02:00
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\tproperties:\n", mark);
|
2017-08-27 17:58:25 +02:00
|
|
|
if (props == NULL || props->n_items == 0) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\t\tnone\n");
|
2017-05-26 08:05:01 +02:00
|
|
|
return;
|
2017-08-27 17:58:25 +02:00
|
|
|
}
|
2016-02-01 16:29:56 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_dict_for_each(item, props) {
|
2017-10-17 12:16:53 +02:00
|
|
|
if (item->value)
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\t\t%s = \"%s\"\n", mark, item->key, item->value);
|
2017-10-17 12:16:53 +02:00
|
|
|
else
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\t\t%s = (null)\n", mark, item->key);
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2016-01-07 12:15:57 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-12 14:47:16 +02:00
|
|
|
#define MARK_CHANGE(f) ((print_mark && ((info)->change_mask & (f))) ? '*' : ' ')
|
2016-02-01 16:29:56 +01:00
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void on_core_info(void *data, const struct pw_core_info *info)
|
2016-01-07 12:15:57 +01:00
|
|
|
{
|
2019-08-12 14:47:16 +02:00
|
|
|
bool print_all = true, print_mark = true;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s\n", PW_TYPE_INTERFACE_Core);
|
|
|
|
|
fprintf(stderr, "\tcookie: %u\n", info->cookie);
|
|
|
|
|
fprintf(stderr, "\tuser-name: \"%s\"\n", info->user_name);
|
|
|
|
|
fprintf(stderr, "\thost-name: \"%s\"\n", info->host_name);
|
|
|
|
|
fprintf(stderr, "\tversion: \"%s\"\n", info->version);
|
|
|
|
|
fprintf(stderr, "\tname: \"%s\"\n", info->name);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2019-08-12 14:47:16 +02:00
|
|
|
print_properties(info->props, MARK_CHANGE(PW_CORE_CHANGE_MASK_PROPS));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2016-12-02 13:38:43 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void module_event_info(void *object, const struct pw_module_info *info)
|
2016-12-02 13:38:43 +01:00
|
|
|
{
|
2017-09-18 09:35:00 +02:00
|
|
|
struct proxy_data *data = object;
|
2017-07-11 12:24:03 +02:00
|
|
|
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) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "added:\n");
|
2017-07-11 12:24:03 +02:00
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "changed:\n");
|
2017-07-11 12:24:03 +02:00
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = data->info = pw_module_info_update(data->info, info);
|
2016-12-02 13:38:43 +01:00
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tid: %d\n", data->id);
|
|
|
|
|
fprintf(stderr, "\tpermissions: "PW_PERMISSION_FORMAT"\n",
|
2020-07-30 16:26:29 +02:00
|
|
|
PW_PERMISSION_ARGS(data->permissions));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s (version %d)\n", data->type, data->version);
|
|
|
|
|
fprintf(stderr, "\tname: \"%s\"\n", info->name);
|
|
|
|
|
fprintf(stderr, "\tfilename: \"%s\"\n", info->filename);
|
|
|
|
|
fprintf(stderr, "\targs: \"%s\"\n", info->args);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2019-08-12 14:47:16 +02:00
|
|
|
print_properties(info->props, MARK_CHANGE(PW_MODULE_CHANGE_MASK_PROPS));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 15:16:30 +01:00
|
|
|
static const struct pw_module_events module_events = {
|
|
|
|
|
PW_VERSION_MODULE_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.info = module_event_info,
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
2018-02-20 10:31:55 +01:00
|
|
|
static void print_node(struct proxy_data *data)
|
2016-07-20 17:55:02 +02:00
|
|
|
{
|
2018-02-20 10:31:55 +01:00
|
|
|
struct pw_node_info *info = data->info;
|
2017-07-11 12:24:03 +02:00
|
|
|
bool print_all, print_mark;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
print_all = true;
|
2018-02-20 10:31:55 +01:00
|
|
|
if (data->first) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "added:\n");
|
2017-07-11 12:24:03 +02:00
|
|
|
print_mark = false;
|
2018-02-20 10:31:55 +01:00
|
|
|
data->first = false;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2017-07-11 12:24:03 +02:00
|
|
|
else {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "changed:\n");
|
2017-07-11 12:24:03 +02:00
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tid: %d\n", data->id);
|
|
|
|
|
fprintf(stderr, "\tpermissions: "PW_PERMISSION_FORMAT"\n",
|
2020-07-30 16:26:29 +02:00
|
|
|
PW_PERMISSION_ARGS(data->permissions));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s (version %d)\n", data->type, data->version);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2019-08-12 14:47:16 +02:00
|
|
|
print_params(data, MARK_CHANGE(PW_NODE_CHANGE_MASK_PARAMS));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\tinput ports: %u/%u\n", MARK_CHANGE(PW_NODE_CHANGE_MASK_INPUT_PORTS),
|
2018-02-20 10:31:55 +01:00
|
|
|
info->n_input_ports, info->max_input_ports);
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\toutput ports: %u/%u\n", MARK_CHANGE(PW_NODE_CHANGE_MASK_OUTPUT_PORTS),
|
2018-02-20 10:31:55 +01:00
|
|
|
info->n_output_ports, info->max_output_ports);
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\tstate: \"%s\"", MARK_CHANGE(PW_NODE_CHANGE_MASK_STATE),
|
2019-08-12 14:47:16 +02:00
|
|
|
pw_node_state_as_string(info->state));
|
2017-05-26 08:05:01 +02:00
|
|
|
if (info->state == PW_NODE_STATE_ERROR && info->error)
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, " \"%s\"\n", info->error);
|
2017-05-26 08:05:01 +02:00
|
|
|
else
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\n");
|
2019-08-12 14:47:16 +02:00
|
|
|
print_properties(info->props, MARK_CHANGE(PW_NODE_CHANGE_MASK_PROPS));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2016-07-20 17:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void node_event_info(void *object, const struct pw_node_info *info)
|
2018-02-20 10:31:55 +01:00
|
|
|
{
|
|
|
|
|
struct proxy_data *data = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
uint32_t i;
|
2018-02-20 10:31:55 +01:00
|
|
|
|
2020-03-06 15:36:57 +01:00
|
|
|
info = data->info = pw_node_info_update(data->info, info);
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
if (info->change_mask & PW_NODE_CHANGE_MASK_PARAMS) {
|
|
|
|
|
for (i = 0; i < info->n_params; i++) {
|
2020-03-06 15:36:57 +01:00
|
|
|
if (info->params[i].user == 0)
|
2019-02-27 16:43:01 +01:00
|
|
|
continue;
|
2019-03-14 16:42:59 +01:00
|
|
|
remove_params(data, info->params[i].id, 0);
|
2019-10-02 17:58:04 +02:00
|
|
|
if (!SPA_FLAG_IS_SET(info->params[i].flags, SPA_PARAM_INFO_READ))
|
2019-02-27 16:43:01 +01:00
|
|
|
continue;
|
2019-12-11 15:26:11 +01:00
|
|
|
pw_node_enum_params((struct pw_node*)data->proxy,
|
2019-02-27 16:43:01 +01:00
|
|
|
0, info->params[i].id, 0, 0, NULL);
|
2020-03-06 15:36:57 +01:00
|
|
|
info->params[i].user = 0;
|
2019-02-27 16:43:01 +01:00
|
|
|
}
|
2018-02-20 10:31:55 +01:00
|
|
|
add_pending(data);
|
|
|
|
|
}
|
2019-02-27 16:43:01 +01:00
|
|
|
|
2019-02-25 16:25:27 +01:00
|
|
|
if (data->pending_seq == 0)
|
2018-02-20 10:31:55 +01:00
|
|
|
data->print_func(data);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 15:26:11 +01:00
|
|
|
static const struct pw_node_events node_events = {
|
|
|
|
|
PW_VERSION_NODE_EVENTS,
|
2018-02-20 10:31:55 +01:00
|
|
|
.info = node_event_info,
|
2019-03-01 12:00:42 +01:00
|
|
|
.param = event_param
|
2018-02-20 10:31:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void print_port(struct proxy_data *data)
|
|
|
|
|
{
|
|
|
|
|
struct pw_port_info *info = data->info;
|
|
|
|
|
bool print_all, print_mark;
|
|
|
|
|
|
|
|
|
|
print_all = true;
|
|
|
|
|
if (data->first) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "added:\n");
|
2018-02-20 10:31:55 +01:00
|
|
|
print_mark = false;
|
|
|
|
|
data->first = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "changed:\n");
|
2018-02-20 10:31:55 +01:00
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tid: %d\n", data->id);
|
|
|
|
|
fprintf(stderr, "\tpermissions: "PW_PERMISSION_FORMAT"\n",
|
2020-07-30 16:26:29 +02:00
|
|
|
PW_PERMISSION_ARGS(data->permissions));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s (version %d)\n", data->type, data->version);
|
2019-08-12 14:47:16 +02:00
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tdirection: \"%s\"\n", pw_direction_as_string(info->direction));
|
2018-02-20 10:31:55 +01:00
|
|
|
if (print_all) {
|
2019-08-12 14:47:16 +02:00
|
|
|
print_params(data, MARK_CHANGE(PW_PORT_CHANGE_MASK_PARAMS));
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(PW_PORT_CHANGE_MASK_PROPS));
|
2018-02-20 10:31:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void port_event_info(void *object, const struct pw_port_info *info)
|
2018-02-20 10:31:55 +01:00
|
|
|
{
|
|
|
|
|
struct proxy_data *data = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
uint32_t i;
|
2018-02-20 10:31:55 +01:00
|
|
|
|
2020-03-06 15:36:57 +01:00
|
|
|
info = data->info = pw_port_info_update(data->info, info);
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
if (info->change_mask & PW_PORT_CHANGE_MASK_PARAMS) {
|
|
|
|
|
for (i = 0; i < info->n_params; i++) {
|
2020-03-06 15:36:57 +01:00
|
|
|
if (info->params[i].user == 0)
|
2019-02-27 16:43:01 +01:00
|
|
|
continue;
|
2019-03-14 16:42:59 +01:00
|
|
|
remove_params(data, info->params[i].id, 0);
|
2019-10-02 17:58:04 +02:00
|
|
|
if (!SPA_FLAG_IS_SET(info->params[i].flags, SPA_PARAM_INFO_READ))
|
2019-02-27 16:43:01 +01:00
|
|
|
continue;
|
2019-12-11 15:59:26 +01:00
|
|
|
pw_port_enum_params((struct pw_port*)data->proxy,
|
2019-02-27 16:43:01 +01:00
|
|
|
0, info->params[i].id, 0, 0, NULL);
|
2020-03-06 15:36:57 +01:00
|
|
|
info->params[i].user = 0;
|
2019-02-27 16:43:01 +01:00
|
|
|
}
|
2018-02-20 10:31:55 +01:00
|
|
|
add_pending(data);
|
|
|
|
|
}
|
2019-02-27 16:43:01 +01:00
|
|
|
|
2019-02-25 16:25:27 +01:00
|
|
|
if (data->pending_seq == 0)
|
2018-02-20 10:31:55 +01:00
|
|
|
data->print_func(data);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 15:59:26 +01:00
|
|
|
static const struct pw_port_events port_events = {
|
|
|
|
|
PW_VERSION_PORT_EVENTS,
|
2018-02-20 10:31:55 +01:00
|
|
|
.info = port_event_info,
|
2019-03-01 12:00:42 +01:00
|
|
|
.param = event_param
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void factory_event_info(void *object, const struct pw_factory_info *info)
|
2017-09-18 09:35:00 +02:00
|
|
|
{
|
|
|
|
|
struct proxy_data *data = object;
|
|
|
|
|
bool print_all, print_mark;
|
|
|
|
|
|
|
|
|
|
print_all = true;
|
|
|
|
|
if (data->info == NULL) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "added:\n");
|
2017-09-18 09:35:00 +02:00
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "changed:\n");
|
2017-09-18 09:35:00 +02:00
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = data->info = pw_factory_info_update(data->info, info);
|
|
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tid: %d\n", data->id);
|
|
|
|
|
fprintf(stderr, "\tpermissions: "PW_PERMISSION_FORMAT"\n",
|
2020-07-30 16:26:29 +02:00
|
|
|
PW_PERMISSION_ARGS(data->permissions));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s (version %d)\n", data->type, data->version);
|
2019-08-12 14:47:16 +02:00
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tname: \"%s\"\n", info->name);
|
|
|
|
|
fprintf(stderr, "\tobject-type: %s/%d\n", info->type, info->version);
|
2017-09-18 09:35:00 +02:00
|
|
|
if (print_all) {
|
2019-08-12 14:47:16 +02:00
|
|
|
print_properties(info->props, MARK_CHANGE(PW_FACTORY_CHANGE_MASK_PROPS));
|
2017-09-18 09:35:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 15:06:00 +01:00
|
|
|
static const struct pw_factory_events factory_events = {
|
|
|
|
|
PW_VERSION_FACTORY_EVENTS,
|
2017-09-18 09:35:00 +02:00
|
|
|
.info = factory_event_info
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void client_event_info(void *object, const struct pw_client_info *info)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2017-09-18 09:35:00 +02:00
|
|
|
struct proxy_data *data = object;
|
2017-07-11 12:24:03 +02:00
|
|
|
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) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "added:\n");
|
2017-07-11 12:24:03 +02:00
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "changed:\n");
|
2017-07-11 12:24:03 +02:00
|
|
|
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);
|
|
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tid: %d\n", data->id);
|
|
|
|
|
fprintf(stderr, "\tpermissions: "PW_PERMISSION_FORMAT"\n",
|
2020-07-30 16:26:29 +02:00
|
|
|
PW_PERMISSION_ARGS(data->permissions));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s (version %d)\n", data->type, data->version);
|
2019-08-12 14:47:16 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2019-08-12 14:47:16 +02:00
|
|
|
print_properties(info->props, MARK_CHANGE(PW_CLIENT_CHANGE_MASK_PROPS));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 14:53:39 +01:00
|
|
|
static const struct pw_client_events client_events = {
|
|
|
|
|
PW_VERSION_CLIENT_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.info = client_event_info
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void link_event_info(void *object, const struct pw_link_info *info)
|
2016-07-20 17:55:02 +02:00
|
|
|
{
|
2017-09-18 09:35:00 +02:00
|
|
|
struct proxy_data *data = object;
|
2017-07-11 12:24:03 +02:00
|
|
|
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) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "added:\n");
|
2017-07-11 12:24:03 +02:00
|
|
|
print_mark = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "changed:\n");
|
2017-07-11 12:24:03 +02:00
|
|
|
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);
|
|
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tid: %d\n", data->id);
|
|
|
|
|
fprintf(stderr, "\tpermissions: "PW_PERMISSION_FORMAT"\n",
|
2020-07-30 16:26:29 +02:00
|
|
|
PW_PERMISSION_ARGS(data->permissions));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s (version %d)\n", data->type, data->version);
|
2019-08-12 14:47:16 +02:00
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\toutput-node-id: %u\n", info->output_node_id);
|
|
|
|
|
fprintf(stderr, "\toutput-port-id: %u\n", info->output_port_id);
|
|
|
|
|
fprintf(stderr, "\tinput-node-id: %u\n", info->input_node_id);
|
|
|
|
|
fprintf(stderr, "\tinput-port-id: %u\n", info->input_port_id);
|
2017-07-11 12:24:03 +02:00
|
|
|
if (print_all) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "%c\tstate: \"%s\"", MARK_CHANGE(PW_LINK_CHANGE_MASK_STATE),
|
2019-08-12 14:47:16 +02:00
|
|
|
pw_link_state_as_string(info->state));
|
2018-10-03 19:29:11 +02:00
|
|
|
if (info->state == PW_LINK_STATE_ERROR && info->error)
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, " \"%s\"\n", info->error);
|
2018-10-03 19:29:11 +02:00
|
|
|
else
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
fprintf(stderr, "%c\tformat:\n", MARK_CHANGE(PW_LINK_CHANGE_MASK_FORMAT));
|
2017-06-02 10:40:43 +02:00
|
|
|
if (info->format)
|
2018-08-23 17:47:57 +02:00
|
|
|
spa_debug_format(2, NULL, info->format);
|
2017-06-02 10:40:43 +02:00
|
|
|
else
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\t\tnone\n");
|
2019-08-12 14:47:16 +02:00
|
|
|
print_properties(info->props, MARK_CHANGE(PW_LINK_CHANGE_MASK_PROPS));
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 15:11:56 +01:00
|
|
|
static const struct pw_link_events link_events = {
|
|
|
|
|
PW_VERSION_LINK_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.info = link_event_info
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
static void print_device(struct proxy_data *data)
|
2018-11-23 12:43:47 +01:00
|
|
|
{
|
2019-03-01 12:00:42 +01:00
|
|
|
struct pw_device_info *info = data->info;
|
2018-11-23 12:43:47 +01:00
|
|
|
bool print_all, print_mark;
|
|
|
|
|
|
|
|
|
|
print_all = true;
|
2019-03-01 12:00:42 +01:00
|
|
|
if (data->first) {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "added:\n");
|
2018-11-23 12:43:47 +01:00
|
|
|
print_mark = false;
|
2019-03-01 12:00:42 +01:00
|
|
|
data->first = false;
|
2018-11-23 12:43:47 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "changed:\n");
|
2018-11-23 12:43:47 +01:00
|
|
|
print_mark = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\tid: %d\n", data->id);
|
|
|
|
|
fprintf(stderr, "\tpermissions: "PW_PERMISSION_FORMAT"\n",
|
2020-07-30 16:26:29 +02:00
|
|
|
PW_PERMISSION_ARGS(data->permissions));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s (version %d)\n", data->type, data->version);
|
2019-08-12 14:47:16 +02:00
|
|
|
|
2018-11-23 12:43:47 +01:00
|
|
|
if (print_all) {
|
2019-08-12 14:47:16 +02:00
|
|
|
print_params(data, MARK_CHANGE(PW_DEVICE_CHANGE_MASK_PARAMS));
|
|
|
|
|
print_properties(info->props, MARK_CHANGE(PW_DEVICE_CHANGE_MASK_PROPS));
|
2018-11-23 12:43:47 +01:00
|
|
|
}
|
2019-03-01 12:00:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void device_event_info(void *object, const struct pw_device_info *info)
|
2019-03-01 12:00:42 +01:00
|
|
|
{
|
|
|
|
|
struct proxy_data *data = object;
|
|
|
|
|
uint32_t i;
|
|
|
|
|
|
2020-03-06 15:36:57 +01:00
|
|
|
info = data->info = pw_device_info_update(data->info, info);
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
if (info->change_mask & PW_DEVICE_CHANGE_MASK_PARAMS) {
|
|
|
|
|
for (i = 0; i < info->n_params; i++) {
|
2020-03-06 15:36:57 +01:00
|
|
|
if (info->params[i].user == 0)
|
2019-03-01 12:00:42 +01:00
|
|
|
continue;
|
2019-03-14 16:42:59 +01:00
|
|
|
remove_params(data, info->params[i].id, 0);
|
2019-10-02 17:58:04 +02:00
|
|
|
if (!SPA_FLAG_IS_SET(info->params[i].flags, SPA_PARAM_INFO_READ))
|
2019-03-01 12:00:42 +01:00
|
|
|
continue;
|
2019-12-11 15:00:41 +01:00
|
|
|
pw_device_enum_params((struct pw_device*)data->proxy,
|
2019-03-01 12:00:42 +01:00
|
|
|
0, info->params[i].id, 0, 0, NULL);
|
2020-03-06 15:36:57 +01:00
|
|
|
info->params[i].user = 0;
|
2019-03-01 12:00:42 +01:00
|
|
|
}
|
|
|
|
|
add_pending(data);
|
|
|
|
|
}
|
|
|
|
|
if (data->pending_seq == 0)
|
|
|
|
|
data->print_func(data);
|
2018-11-23 12:43:47 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 15:00:41 +01:00
|
|
|
static const struct pw_device_events device_events = {
|
|
|
|
|
PW_VERSION_DEVICE_EVENTS,
|
2019-03-01 12:00:42 +01:00
|
|
|
.info = device_event_info,
|
|
|
|
|
.param = event_param
|
2018-11-23 12:43:47 +01:00
|
|
|
};
|
|
|
|
|
|
2020-06-04 12:35:16 +02:00
|
|
|
static void
|
|
|
|
|
removed_proxy (void *data)
|
|
|
|
|
{
|
|
|
|
|
struct proxy_data *pd = data;
|
|
|
|
|
pw_proxy_destroy(pd->proxy);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2021-11-03 17:25:11 +01:00
|
|
|
struct proxy_data *pd = data;
|
|
|
|
|
|
|
|
|
|
spa_list_remove(&pd->global_link);
|
2017-07-11 12:24:03 +02:00
|
|
|
|
2018-04-19 20:02:06 +02:00
|
|
|
clear_params(pd);
|
|
|
|
|
remove_pending(pd);
|
2021-11-03 17:25:11 +01:00
|
|
|
free(pd->type);
|
2018-02-20 10:31:55 +01:00
|
|
|
|
2021-11-03 17:25:11 +01:00
|
|
|
if (pd->info == NULL)
|
|
|
|
|
return;
|
2018-04-19 20:02:06 +02:00
|
|
|
if (pd->destroy)
|
|
|
|
|
pd->destroy(pd->info);
|
2021-11-03 17:25:11 +01:00
|
|
|
pd->info = NULL;
|
2017-07-11 12:24:03 +02:00
|
|
|
}
|
2016-12-02 13:38:43 +01:00
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_proxy_events proxy_events = {
|
|
|
|
|
PW_VERSION_PROXY_EVENTS,
|
2020-06-04 12:35:16 +02:00
|
|
|
.removed = removed_proxy,
|
2017-08-04 10:18:54 +02:00
|
|
|
.destroy = destroy_proxy,
|
|
|
|
|
};
|
2017-01-10 17:12:53 +01:00
|
|
|
|
2019-08-16 22:11:42 +02:00
|
|
|
static void registry_event_global(void *data, uint32_t id,
|
2019-12-19 13:15:10 +01:00
|
|
|
uint32_t permissions, const char *type, uint32_t version,
|
2018-01-19 11:18:17 +01:00
|
|
|
const struct spa_dict *props)
|
2017-07-11 12:24:03 +02:00
|
|
|
{
|
2021-11-03 17:25:11 +01:00
|
|
|
struct data *d = data;
|
|
|
|
|
struct pw_proxy *proxy;
|
|
|
|
|
uint32_t client_version;
|
|
|
|
|
const void *events;
|
2017-07-13 15:21:52 +02:00
|
|
|
struct proxy_data *pd;
|
2017-08-04 10:18:54 +02:00
|
|
|
pw_destroy_t destroy;
|
2018-02-20 10:31:55 +01:00
|
|
|
print_func_t print_func = NULL;
|
2017-07-11 12:24:03 +02:00
|
|
|
|
2021-05-18 11:36:13 +10:00
|
|
|
if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
|
2017-07-13 15:21:52 +02:00
|
|
|
events = &node_events;
|
2019-12-11 15:26:11 +01:00
|
|
|
client_version = PW_VERSION_NODE;
|
2017-08-04 10:18:54 +02:00
|
|
|
destroy = (pw_destroy_t) pw_node_info_free;
|
2018-02-20 10:31:55 +01:00
|
|
|
print_func = print_node;
|
2021-05-18 11:36:13 +10:00
|
|
|
} else if (spa_streq(type, PW_TYPE_INTERFACE_Port)) {
|
2018-02-20 10:31:55 +01:00
|
|
|
events = &port_events;
|
2019-12-11 15:59:26 +01:00
|
|
|
client_version = PW_VERSION_PORT;
|
2018-02-20 10:31:55 +01:00
|
|
|
destroy = (pw_destroy_t) pw_port_info_free;
|
|
|
|
|
print_func = print_port;
|
2021-05-18 11:36:13 +10:00
|
|
|
} else if (spa_streq(type, PW_TYPE_INTERFACE_Module)) {
|
2017-07-13 15:21:52 +02:00
|
|
|
events = &module_events;
|
2019-12-11 15:16:30 +01:00
|
|
|
client_version = PW_VERSION_MODULE;
|
2017-08-04 10:18:54 +02:00
|
|
|
destroy = (pw_destroy_t) pw_module_info_free;
|
2021-05-18 11:36:13 +10:00
|
|
|
} else if (spa_streq(type, PW_TYPE_INTERFACE_Device)) {
|
2018-11-23 12:43:47 +01:00
|
|
|
events = &device_events;
|
2019-12-11 15:00:41 +01:00
|
|
|
client_version = PW_VERSION_DEVICE;
|
2018-11-23 12:43:47 +01:00
|
|
|
destroy = (pw_destroy_t) pw_device_info_free;
|
2019-03-01 12:00:42 +01:00
|
|
|
print_func = print_device;
|
2021-05-18 11:36:13 +10:00
|
|
|
} else if (spa_streq(type, PW_TYPE_INTERFACE_Factory)) {
|
2017-09-18 09:35:00 +02:00
|
|
|
events = &factory_events;
|
2019-12-11 15:06:00 +01:00
|
|
|
client_version = PW_VERSION_FACTORY;
|
2017-09-18 09:35:00 +02:00
|
|
|
destroy = (pw_destroy_t) pw_factory_info_free;
|
2021-05-18 11:36:13 +10:00
|
|
|
} else if (spa_streq(type, PW_TYPE_INTERFACE_Client)) {
|
2017-07-13 15:21:52 +02:00
|
|
|
events = &client_events;
|
2019-12-11 14:53:39 +01:00
|
|
|
client_version = PW_VERSION_CLIENT;
|
2017-08-04 10:18:54 +02:00
|
|
|
destroy = (pw_destroy_t) pw_client_info_free;
|
2021-05-18 11:36:13 +10:00
|
|
|
} else if (spa_streq(type, PW_TYPE_INTERFACE_Link)) {
|
2017-07-13 15:21:52 +02:00
|
|
|
events = &link_events;
|
2019-12-11 15:11:56 +01:00
|
|
|
client_version = PW_VERSION_LINK;
|
2017-08-04 10:18:54 +02:00
|
|
|
destroy = (pw_destroy_t) pw_link_info_free;
|
2019-12-19 13:15:10 +01:00
|
|
|
} else {
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "added:\n");
|
|
|
|
|
fprintf(stderr, "\tid: %u\n", id);
|
|
|
|
|
fprintf(stderr, "\tpermissions: "PW_PERMISSION_FORMAT"\n",
|
2020-07-30 16:26:29 +02:00
|
|
|
PW_PERMISSION_ARGS(permissions));
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "\ttype: %s (version %d)\n", type, version);
|
2018-01-19 11:18:17 +01:00
|
|
|
print_properties(props, ' ');
|
2019-03-01 14:04:05 +01:00
|
|
|
return;
|
2017-07-13 15:21:52 +02:00
|
|
|
}
|
2017-07-11 12:24:03 +02:00
|
|
|
|
2021-11-03 17:25:11 +01:00
|
|
|
proxy = pw_registry_bind(d->registry, id, type,
|
2017-08-04 10:18:54 +02:00
|
|
|
client_version,
|
|
|
|
|
sizeof(struct proxy_data));
|
2021-11-03 17:25:11 +01:00
|
|
|
if (proxy == NULL)
|
|
|
|
|
goto no_mem;
|
2017-07-11 12:24:03 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
pd = pw_proxy_get_user_data(proxy);
|
2017-09-18 09:35:00 +02:00
|
|
|
pd->data = d;
|
2018-02-20 10:31:55 +01:00
|
|
|
pd->first = true;
|
2017-08-04 10:18:54 +02:00
|
|
|
pd->proxy = proxy;
|
2017-07-13 15:21:52 +02:00
|
|
|
pd->id = id;
|
2017-08-01 17:09:57 +02:00
|
|
|
pd->permissions = permissions;
|
2017-07-13 15:21:52 +02:00
|
|
|
pd->version = version;
|
2019-12-19 13:15:10 +01:00
|
|
|
pd->type = strdup(type);
|
2017-08-04 10:18:54 +02:00
|
|
|
pd->destroy = destroy;
|
2019-02-25 16:25:27 +01:00
|
|
|
pd->pending_seq = 0;
|
2018-02-20 10:31:55 +01:00
|
|
|
pd->print_func = print_func;
|
2019-02-27 16:43:01 +01:00
|
|
|
spa_list_init(&pd->param_list);
|
2021-11-03 17:25:11 +01:00
|
|
|
pw_proxy_add_object_listener(proxy, &pd->object_listener, events, pd);
|
|
|
|
|
pw_proxy_add_listener(proxy, &pd->proxy_listener, &proxy_events, pd);
|
|
|
|
|
spa_list_append(&d->global_list, &pd->global_link);
|
|
|
|
|
|
|
|
|
|
return;
|
2017-07-11 12:24:03 +02:00
|
|
|
|
2021-11-03 17:25:11 +01:00
|
|
|
no_mem:
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "failed to create proxy");
|
2021-11-03 17:25:11 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct proxy_data *find_proxy(struct data *d, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct proxy_data *pd;
|
|
|
|
|
spa_list_for_each(pd, &d->global_list, global_link) {
|
|
|
|
|
if (pd->id == id)
|
|
|
|
|
return pd;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
2015-04-27 09:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void registry_event_global_remove(void *object, uint32_t id)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2021-11-03 17:25:11 +01:00
|
|
|
struct data *d = object;
|
|
|
|
|
struct proxy_data *pd;
|
|
|
|
|
|
2021-10-27 15:54:21 +10:00
|
|
|
fprintf(stderr, "removed:\n");
|
|
|
|
|
fprintf(stderr, "\tid: %u\n", id);
|
2021-11-03 17:25:11 +01:00
|
|
|
|
|
|
|
|
pd = find_proxy(d, id);
|
|
|
|
|
if (pd == NULL)
|
|
|
|
|
return;
|
|
|
|
|
if (pd->proxy)
|
|
|
|
|
pw_proxy_destroy(pd->proxy);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 09:44:48 +01:00
|
|
|
static const struct pw_registry_events registry_events = {
|
|
|
|
|
PW_VERSION_REGISTRY_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.global = registry_event_global,
|
|
|
|
|
.global_remove = registry_event_global_remove,
|
2017-07-11 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
2019-12-06 11:48:40 +01:00
|
|
|
static void on_core_error(void *_data, uint32_t id, int seq, int res, const char *message)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct data *data = _data;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2019-12-06 11:48:40 +01:00
|
|
|
pw_log_error("error id:%u seq:%d res:%d (%s): %s",
|
|
|
|
|
id, seq, res, spa_strerror(res), message);
|
2020-11-20 12:29:51 +01:00
|
|
|
|
|
|
|
|
if (id == PW_ID_CORE && res == -EPIPE)
|
2017-09-11 09:48:13 +02:00
|
|
|
pw_main_loop_quit(data->loop);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 07:46:59 +01:00
|
|
|
static const struct pw_core_events core_events = {
|
|
|
|
|
PW_VERSION_CORE_EVENTS,
|
2019-12-06 11:48:40 +01:00
|
|
|
.info = on_core_info,
|
|
|
|
|
.done = on_core_done,
|
|
|
|
|
.error = on_core_error,
|
2017-08-04 10:18:54 +02:00
|
|
|
};
|
|
|
|
|
|
2017-09-11 09:48:13 +02:00
|
|
|
static void do_quit(void *data, int signal_number)
|
|
|
|
|
{
|
|
|
|
|
struct data *d = data;
|
|
|
|
|
pw_main_loop_quit(d->loop);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 16:36:48 +01:00
|
|
|
static void show_help(const char *name)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stdout, "%s [options]\n"
|
2020-04-02 14:34:02 +02:00
|
|
|
" -h, --help Show this help\n"
|
|
|
|
|
" --version Show version\n"
|
|
|
|
|
" -r, --remote Remote daemon name\n",
|
|
|
|
|
name);
|
2020-03-24 16:36:48 +01: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 };
|
2017-09-11 09:48:13 +02:00
|
|
|
struct pw_loop *l;
|
2020-03-24 16:36:48 +01:00
|
|
|
const char *opt_remote = NULL;
|
|
|
|
|
static const struct option long_options[] = {
|
2020-04-02 14:34:02 +02:00
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
|
{ "remote", required_argument, NULL, 'r' },
|
|
|
|
|
{ NULL, 0, NULL, 0}
|
2020-03-24 16:36:48 +01:00
|
|
|
};
|
|
|
|
|
int c;
|
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
|
|
|
|
2020-04-02 14:34:02 +02:00
|
|
|
while ((c = getopt_long(argc, argv, "hVr:", long_options, NULL)) != -1) {
|
2020-03-24 16:36:48 +01:00
|
|
|
switch (c) {
|
|
|
|
|
case 'h':
|
|
|
|
|
show_help(argv[0]);
|
|
|
|
|
return 0;
|
2020-04-02 14:34:02 +02:00
|
|
|
case 'V':
|
2020-03-24 16:36:48 +01:00
|
|
|
fprintf(stdout, "%s\n"
|
|
|
|
|
"Compiled with libpipewire %s\n"
|
|
|
|
|
"Linked with libpipewire %s\n",
|
|
|
|
|
argv[0],
|
|
|
|
|
pw_get_headers_version(),
|
|
|
|
|
pw_get_library_version());
|
|
|
|
|
return 0;
|
|
|
|
|
case 'r':
|
|
|
|
|
opt_remote = optarg;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-04-04 20:23:42 +02:00
|
|
|
show_help(argv[0]);
|
2020-03-24 16:36:48 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 09:48:13 +02:00
|
|
|
data.loop = pw_main_loop_new(NULL);
|
2020-04-04 20:23:42 +02:00
|
|
|
if (data.loop == NULL) {
|
|
|
|
|
fprintf(stderr, "can't create main loop: %m\n");
|
2017-09-18 11:54:25 +02:00
|
|
|
return -1;
|
2020-04-04 20:23:42 +02:00
|
|
|
}
|
2017-09-18 11:54:25 +02:00
|
|
|
|
2017-09-11 09:48:13 +02:00
|
|
|
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-12-10 18:19:56 +01:00
|
|
|
data.context = pw_context_new(l, NULL, 0);
|
2020-04-04 20:23:42 +02:00
|
|
|
if (data.context == NULL) {
|
|
|
|
|
fprintf(stderr, "can't create context: %m\n");
|
2017-09-18 11:54:25 +02:00
|
|
|
return -1;
|
2020-04-04 20:23:42 +02:00
|
|
|
}
|
2017-09-18 11:54:25 +02:00
|
|
|
|
2019-12-06 11:48:40 +01:00
|
|
|
spa_list_init(&data.pending_list);
|
2021-11-03 17:25:11 +01:00
|
|
|
spa_list_init(&data.global_list);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2020-03-24 16:36:48 +01:00
|
|
|
data.core = pw_context_connect(data.context,
|
|
|
|
|
pw_properties_new(
|
|
|
|
|
PW_KEY_REMOTE_NAME, opt_remote,
|
|
|
|
|
NULL),
|
|
|
|
|
0);
|
2020-04-04 20:23:42 +02:00
|
|
|
if (data.core == NULL) {
|
|
|
|
|
fprintf(stderr, "can't connect: %m\n");
|
2017-09-18 11:54:25 +02:00
|
|
|
return -1;
|
2020-04-04 20:23:42 +02:00
|
|
|
}
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2019-12-11 07:46:59 +01:00
|
|
|
pw_core_add_listener(data.core,
|
2019-12-06 11:48:40 +01:00
|
|
|
&data.core_listener,
|
|
|
|
|
&core_events, &data);
|
2019-12-11 09:44:48 +01:00
|
|
|
data.registry = pw_core_get_registry(data.core,
|
|
|
|
|
PW_VERSION_REGISTRY, 0);
|
|
|
|
|
pw_registry_add_listener(data.registry,
|
2019-12-06 11:48:40 +01:00
|
|
|
&data.registry_listener,
|
|
|
|
|
®istry_events, &data);
|
2018-02-20 10:31:55 +01:00
|
|
|
|
2017-09-11 09:48:13 +02:00
|
|
|
pw_main_loop_run(data.loop);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2020-06-04 12:35:16 +02:00
|
|
|
pw_proxy_destroy((struct pw_proxy*)data.registry);
|
2019-12-10 18:19:56 +01:00
|
|
|
pw_context_destroy(data.context);
|
2017-09-11 09:48:13 +02:00
|
|
|
pw_main_loop_destroy(data.loop);
|
2020-06-04 12:35:16 +02:00
|
|
|
pw_deinit();
|
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
|
|
|
}
|