-
Notifications
You must be signed in to change notification settings - Fork 3
/
pw-cli_0358_mod.c
2410 lines (2052 loc) · 63.3 KB
/
pw-cli_0358_mod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* pw-cli.c for older systems
*
* This is src/tools/pw-cli.c from pipewire 0.3.58 modified to address
* pipewire issue #2709:-
*
* https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2709
*
* This file is only built on older pipewire systems. It is ignored for
* pipewire 0.3.59 and later.
*/
/* 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 "config.h"
#include <spa-0.2/spa/utils/defs.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <ctype.h>
#if !defined(__FreeBSD__) && !defined(__MidnightBSD__)
#include <alloca.h>
#endif
#include <getopt.h>
#include <fnmatch.h>
#ifdef HAVE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include <locale.h>
#if !defined(FNM_EXTMATCH)
#define FNM_EXTMATCH 0
#endif
#define spa_debug(fmt,...) printf(fmt"\n", ## __VA_ARGS__)
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/debug/pod.h>
#include <spa/utils/keys.h>
#include <spa/utils/json-pod.h>
#include <spa/pod/builder.h>
#include <pipewire/impl.h>
#include <pipewire/i18n.h>
#include <pipewire/extensions/session-manager.h>
static const char WHITESPACE[] = " \t";
static char prompt[64];
struct remote_data;
struct proxy_data;
typedef void (*info_func_t) (struct proxy_data *pd);
struct class {
const char *type;
uint32_t version;
const void *events;
pw_destroy_t destroy;
info_func_t info;
const char *name_key;
};
struct data {
struct pw_main_loop *loop;
struct pw_context *context;
struct spa_list remotes;
struct remote_data *current;
struct pw_map vars;
unsigned int interactive:1;
unsigned int monitoring:1;
unsigned int quit:1;
};
struct global {
struct remote_data *rd;
uint32_t id;
uint32_t permissions;
uint32_t version;
char *type;
const struct class *class;
struct pw_proxy *proxy;
bool info_pending;
struct pw_properties *properties;
};
struct remote_data {
struct spa_list link;
struct data *data;
char *name;
uint32_t id;
int prompt_pending;
struct pw_core *core;
struct spa_hook core_listener;
struct spa_hook proxy_core_listener;
struct pw_registry *registry;
struct spa_hook registry_listener;
struct pw_map globals;
};
struct proxy_data {
struct remote_data *rd;
struct global *global;
struct pw_proxy *proxy;
void *info;
const struct class *class;
struct spa_hook proxy_listener;
struct spa_hook object_listener;
};
struct command {
const char *name;
const char *alias;
const char *description;
bool (*func) (struct data *data, const char *cmd, char *args, char **error);
};
static struct spa_dict * global_props(struct global *global);
static struct global * obj_global(struct remote_data *rd, uint32_t id);
static int children_of(struct remote_data *rd, uint32_t parent_id,
const char *child_type, uint32_t **children);
static int pw_split_ip(char *str, const char *delimiter, int max_tokens, char *tokens[])
{
const char *state = NULL;
char *s, *t;
size_t len, l2;
int n = 0;
s = (char *)pw_split_walk(str, delimiter, &len, &state);
while (s && n + 1 < max_tokens) {
t = (char*)pw_split_walk(str, delimiter, &l2, &state);
s[len] = '\0';
tokens[n++] = s;
s = t;
len = l2;
}
if (s)
tokens[n++] = s;
return n;
}
static void print_properties(struct spa_dict *props, char mark, bool header)
{
const struct spa_dict_item *item;
if (header)
printf("%c\tproperties:\n", mark);
if (props == NULL || props->n_items == 0) {
if (header)
printf("\t\tnone\n");
return;
}
spa_dict_for_each(item, props) {
printf("%c\t\t%s = \"%s\"\n", mark, item->key, item->value);
}
}
static void print_params(struct spa_param_info *params, uint32_t n_params, char mark, bool header)
{
uint32_t i;
if (header)
printf("%c\tparams: (%u)\n", mark, n_params);
if (params == NULL || n_params == 0) {
if (header)
printf("\t\tnone\n");
return;
}
for (i = 0; i < n_params; i++) {
const struct spa_type_info *type_info = spa_type_param;
printf("%c\t %d (%s) %c%c\n",
params[i].user > 0 ? mark : ' ', params[i].id,
spa_debug_type_find_name(type_info, params[i].id),
params[i].flags & SPA_PARAM_INFO_READ ? 'r' : '-',
params[i].flags & SPA_PARAM_INFO_WRITE ? 'w' : '-');
params[i].user = 0;
}
}
static bool do_not_implemented(struct data *data, const char *cmd, char *args, char **error)
{
*error = spa_aprintf("Command \"%s\" not yet implemented", cmd);
return false;
}
static bool do_help(struct data *data, const char *cmd, char *args, char **error);
static bool do_load_module(struct data *data, const char *cmd, char *args, char **error);
static bool do_list_objects(struct data *data, const char *cmd, char *args, char **error);
static bool do_connect(struct data *data, const char *cmd, char *args, char **error);
static bool do_disconnect(struct data *data, const char *cmd, char *args, char **error);
static bool do_list_remotes(struct data *data, const char *cmd, char *args, char **error);
static bool do_switch_remote(struct data *data, const char *cmd, char *args, char **error);
static bool do_info(struct data *data, const char *cmd, char *args, char **error);
static bool do_create_device(struct data *data, const char *cmd, char *args, char **error);
static bool do_create_node(struct data *data, const char *cmd, char *args, char **error);
static bool do_destroy(struct data *data, const char *cmd, char *args, char **error);
static bool do_create_link(struct data *data, const char *cmd, char *args, char **error);
static bool do_export_node(struct data *data, const char *cmd, char *args, char **error);
static bool do_enum_params(struct data *data, const char *cmd, char *args, char **error);
static bool do_set_param(struct data *data, const char *cmd, char *args, char **error);
static bool do_permissions(struct data *data, const char *cmd, char *args, char **error);
static bool do_get_permissions(struct data *data, const char *cmd, char *args, char **error);
static bool do_send_command(struct data *data, const char *cmd, char *args, char **error);
static bool do_quit(struct data *data, const char *cmd, char *args, char **error);
#define DUMP_NAMES "Core|Module|Device|Node|Port|Factory|Client|Link|Session|Endpoint|EndpointStream"
static const struct command command_list[] = {
{ "help", "h", "Show this help", do_help },
{ "load-module", "lm", "Load a module. <module-name> [<module-arguments>]", do_load_module },
{ "unload-module", "um", "Unload a module. <module-var>", do_not_implemented },
{ "connect", "con", "Connect to a remote. [<remote-name>]", do_connect },
{ "disconnect", "dis", "Disconnect from a remote. [<remote-var>]", do_disconnect },
{ "list-remotes", "lr", "List connected remotes.", do_list_remotes },
{ "switch-remote", "sr", "Switch between current remotes. [<remote-var>]", do_switch_remote },
{ "list-objects", "ls", "List objects or current remote. [<interface>]", do_list_objects },
{ "info", "i", "Get info about an object. <object-id>|all", do_info },
{ "create-device", "cd", "Create a device from a factory. <factory-name> [<properties>]", do_create_device },
{ "create-node", "cn", "Create a node from a factory. <factory-name> [<properties>]", do_create_node },
{ "destroy", "d", "Destroy a global object. <object-id>", do_destroy },
{ "create-link", "cl", "Create a link between nodes. <node-id> <port-id> <node-id> <port-id> [<properties>]", do_create_link },
{ "export-node", "en", "Export a local node to the current remote. <node-id> [remote-var]", do_export_node },
{ "enum-params", "e", "Enumerate params of an object <object-id> <param-id>", do_enum_params },
{ "set-param", "s", "Set param of an object <object-id> <param-id> <param-json>", do_set_param },
{ "permissions", "sp", "Set permissions for a client <client-id> <object> <permission>", do_permissions },
{ "get-permissions", "gp", "Get permissions of a client <client-id>", do_get_permissions },
{ "send-command", "c", "Send a command <object-id>", do_send_command },
{ "quit", "q", "Quit", do_quit },
};
static bool do_quit(struct data *data, const char *cmd, char *args, char **error)
{
pw_main_loop_quit(data->loop);
data->quit = true;
return true;
}
static bool do_help(struct data *data, const char *cmd, char *args, char **error)
{
size_t i;
printf("Available commands:\n");
for (i = 0; i < SPA_N_ELEMENTS(command_list); i++) {
char cmd[256];
snprintf(cmd, sizeof(cmd), "%s | %s",
command_list[i].name, command_list[i].alias);
printf("\t%-20.20s\t%s\n", cmd, command_list[i].description);
}
return true;
}
static bool do_load_module(struct data *data, const char *cmd, char *args, char **error)
{
struct pw_impl_module *module;
char *a[2];
int n;
uint32_t id;
n = pw_split_ip(args, WHITESPACE, 2, a);
if (n < 1) {
*error = spa_aprintf("%s <module-name> [<module-arguments>]", cmd);
return false;
}
module = pw_context_load_module(data->context, a[0], n == 2 ? a[1] : NULL, NULL);
if (module == NULL) {
*error = spa_aprintf("Could not load module");
return false;
}
id = pw_map_insert_new(&data->vars, module);
printf("%d = @module:%d\n", id, pw_global_get_id(pw_impl_module_get_global(module)));
return true;
}
static void on_core_info(void *_data, const struct pw_core_info *info)
{
struct remote_data *rd = _data;
free(rd->name);
rd->name = info->name ? strdup(info->name) : NULL;
if (rd->data->interactive)
printf("remote %d is named '%s'\n", rd->id, rd->name);
}
static void set_prompt(struct remote_data *rd)
{
snprintf(prompt, sizeof(prompt), "%s>> ", rd->name);
#ifdef HAVE_READLINE
rl_set_prompt(prompt);
#else
printf("%s", prompt);
fflush(stdout);
#endif
}
static void on_core_done(void *_data, uint32_t id, int seq)
{
struct remote_data *rd = _data;
struct data *d = rd->data;
if (seq == rd->prompt_pending) {
if (d->interactive) {
set_prompt(rd);
rd->data->monitoring = true;
} else {
pw_main_loop_quit(d->loop);
}
}
}
static bool global_matches(struct global *g, const char *pattern)
{
const char *str;
if (g->properties == NULL)
return false;
if (strstr(g->type, pattern) != NULL)
return true;
if ((str = pw_properties_get(g->properties, PW_KEY_OBJECT_PATH)) != NULL &&
fnmatch(pattern, str, FNM_EXTMATCH) == 0)
return true;
if ((str = pw_properties_get(g->properties, PW_KEY_OBJECT_SERIAL)) != NULL &&
spa_streq(pattern, str))
return true;
if (g->class != NULL && g->class->name_key != NULL &&
(str = pw_properties_get(g->properties, g->class->name_key)) != NULL &&
fnmatch(pattern, str, FNM_EXTMATCH) == 0)
return true;
return false;
}
static int print_global(void *obj, void *data)
{
struct global *global = obj;
const char *filter = data;
if (global == NULL)
return 0;
if (filter && !global_matches(global, filter))
return 0;
printf("\tid %d, type %s/%d\n", global->id,
global->type, global->version);
if (global->properties)
print_properties(&global->properties->dict, ' ', false);
return 0;
}
static bool bind_global(struct remote_data *rd, struct global *global, char **error);
static void registry_event_global(void *data, uint32_t id,
uint32_t permissions, const char *type, uint32_t version,
const struct spa_dict *props)
{
struct remote_data *rd = data;
struct global *global;
size_t size;
char *error;
bool ret;
global = calloc(1, sizeof(struct global));
global->rd = rd;
global->id = id;
global->permissions = permissions;
global->type = strdup(type);
global->version = version;
global->properties = props ? pw_properties_new_dict(props) : NULL;
if (rd->data->monitoring) {
printf("remote %d added global: ", rd->id);
print_global(global, NULL);
}
size = pw_map_get_size(&rd->globals);
while (id > size)
pw_map_insert_at(&rd->globals, size++, NULL);
pw_map_insert_at(&rd->globals, id, global);
/* immediately bind the object always */
ret = bind_global(rd, global, &error);
if (!ret) {
if (rd->data->interactive)
fprintf(stderr, "Error: \"%s\"\n", error);
free(error);
}
}
static int destroy_global(void *obj, void *data)
{
struct global *global = obj;
if (global == NULL)
return 0;
if (global->proxy)
pw_proxy_destroy(global->proxy);
pw_map_insert_at(&global->rd->globals, global->id, NULL);
pw_properties_free(global->properties);
free(global->type);
free(global);
return 0;
}
static void registry_event_global_remove(void *data, uint32_t id)
{
struct remote_data *rd = data;
struct global *global;
global = pw_map_lookup(&rd->globals, id);
if (global == NULL) {
fprintf(stderr, "remote %d removed unknown global %d\n", rd->id, id);
return;
}
if (rd->data->monitoring) {
printf("remote %d removed global: ", rd->id);
print_global(global, NULL);
}
destroy_global(global, rd);
}
static const struct pw_registry_events registry_events = {
PW_VERSION_REGISTRY_EVENTS,
.global = registry_event_global,
.global_remove = registry_event_global_remove,
};
static struct global *find_global(struct remote_data *rd, const char *pattern)
{
uint32_t id;
union pw_map_item *item;
if (spa_atou32(pattern, &id, 0))
return pw_map_lookup(&rd->globals, id);
pw_array_for_each(item, &rd->globals.items) {
struct global *g = item->data;
if (pw_map_item_is_free(item) || g == NULL)
continue;
if (global_matches(g, pattern))
return g;
}
return NULL;
}
static void on_core_error(void *_data, uint32_t id, int seq, int res, const char *message)
{
struct remote_data *rd = _data;
struct data *data = rd->data;
pw_log_error("remote %p: error id:%u seq:%d res:%d (%s): %s", rd,
id, seq, res, spa_strerror(res), message);
if (id == PW_ID_CORE && res == -EPIPE)
pw_main_loop_quit(data->loop);
}
static const struct pw_core_events remote_core_events = {
PW_VERSION_CORE_EVENTS,
.info = on_core_info,
.done = on_core_done,
.error = on_core_error,
};
static void on_core_destroy(void *_data)
{
struct remote_data *rd = _data;
struct data *data = rd->data;
spa_list_remove(&rd->link);
spa_hook_remove(&rd->core_listener);
spa_hook_remove(&rd->proxy_core_listener);
pw_map_remove(&data->vars, rd->id);
pw_map_for_each(&rd->globals, destroy_global, rd);
pw_map_clear(&rd->globals);
if (data->current == rd)
data->current = NULL;
free(rd->name);
}
static const struct pw_proxy_events proxy_core_events = {
PW_VERSION_PROXY_EVENTS,
.destroy = on_core_destroy,
};
static void remote_data_free(struct remote_data *rd)
{
spa_hook_remove(&rd->registry_listener);
pw_proxy_destroy((struct pw_proxy*)rd->registry);
pw_core_disconnect(rd->core);
}
static bool do_connect(struct data *data, const char *cmd, char *args, char **error)
{
char *a[1];
int n;
struct pw_properties *props = NULL;
struct pw_core *core;
struct remote_data *rd;
n = args ? pw_split_ip(args, WHITESPACE, 1, a) : 0;
if (n == 1) {
props = pw_properties_new(PW_KEY_REMOTE_NAME, a[0], NULL);
}
core = pw_context_connect(data->context, props, sizeof(struct remote_data));
if (core == NULL) {
*error = spa_aprintf("failed to connect: %m");
return false;
}
rd = pw_proxy_get_user_data((struct pw_proxy*)core);
rd->core = core;
rd->data = data;
pw_map_init(&rd->globals, 64, 16);
rd->id = pw_map_insert_new(&data->vars, rd);
spa_list_append(&data->remotes, &rd->link);
if (rd->data->interactive)
printf("%d = @remote:%p\n", rd->id, rd->core);
data->current = rd;
pw_core_add_listener(rd->core,
&rd->core_listener,
&remote_core_events, rd);
pw_proxy_add_listener((struct pw_proxy*)rd->core,
&rd->proxy_core_listener,
&proxy_core_events, rd);
rd->registry = pw_core_get_registry(rd->core, PW_VERSION_REGISTRY, 0);
pw_registry_add_listener(rd->registry,
&rd->registry_listener,
®istry_events, rd);
rd->prompt_pending = pw_core_sync(rd->core, 0, 0);
return true;
}
static bool do_disconnect(struct data *data, const char *cmd, char *args, char **error)
{
char *a[1];
int n;
uint32_t idx;
struct remote_data *rd = data->current;
n = pw_split_ip(args, WHITESPACE, 1, a);
if (n >= 1) {
idx = atoi(a[0]);
rd = pw_map_lookup(&data->vars, idx);
if (rd == NULL)
goto no_remote;
}
if (rd)
remote_data_free(rd);
if (data->current == NULL) {
if (spa_list_is_empty(&data->remotes)) {
return true;
}
data->current = spa_list_last(&data->remotes, struct remote_data, link);
}
return true;
no_remote:
*error = spa_aprintf("Remote %d does not exist", idx);
return false;
}
static bool do_list_remotes(struct data *data, const char *cmd, char *args, char **error)
{
struct remote_data *rd;
spa_list_for_each(rd, &data->remotes, link)
printf("\t%d = @remote:%p '%s'\n", rd->id, rd->core, rd->name);
return true;
}
static bool do_switch_remote(struct data *data, const char *cmd, char *args, char **error)
{
char *a[1];
int n, idx = 0;
struct remote_data *rd;
n = pw_split_ip(args, WHITESPACE, 1, a);
if (n == 1)
idx = atoi(a[0]);
rd = pw_map_lookup(&data->vars, idx);
if (rd == NULL)
goto no_remote;
spa_list_remove(&rd->link);
spa_list_append(&data->remotes, &rd->link);
data->current = rd;
return true;
no_remote:
*error = spa_aprintf("Remote %d does not exist", idx);
return false;
}
#define MARK_CHANGE(f) ((((info)->change_mask & (f))) ? '*' : ' ')
static void info_global(struct proxy_data *pd)
{
struct global *global = pd->global;
if (global == NULL)
return;
printf("\tid: %d\n", global->id);
printf("\tpermissions: "PW_PERMISSION_FORMAT"\n",
PW_PERMISSION_ARGS(global->permissions));
printf("\ttype: %s/%d\n", global->type, global->version);
}
static void info_core(struct proxy_data *pd)
{
struct pw_core_info *info = pd->info;
info_global(pd);
printf("\tcookie: %u\n", info->cookie);
printf("\tuser-name: \"%s\"\n", info->user_name);
printf("\thost-name: \"%s\"\n", info->host_name);
printf("\tversion: \"%s\"\n", info->version);
printf("\tname: \"%s\"\n", info->name);
print_properties(info->props, MARK_CHANGE(PW_CORE_CHANGE_MASK_PROPS), true);
info->change_mask = 0;
}
static void info_module(struct proxy_data *pd)
{
struct pw_module_info *info = pd->info;
info_global(pd);
printf("\tname: \"%s\"\n", info->name);
printf("\tfilename: \"%s\"\n", info->filename);
printf("\targs: \"%s\"\n", info->args);
print_properties(info->props, MARK_CHANGE(PW_MODULE_CHANGE_MASK_PROPS), true);
info->change_mask = 0;
}
static void info_node(struct proxy_data *pd)
{
struct pw_node_info *info = pd->info;
info_global(pd);
printf("%c\tinput ports: %u/%u\n", MARK_CHANGE(PW_NODE_CHANGE_MASK_INPUT_PORTS),
info->n_input_ports, info->max_input_ports);
printf("%c\toutput ports: %u/%u\n", MARK_CHANGE(PW_NODE_CHANGE_MASK_OUTPUT_PORTS),
info->n_output_ports, info->max_output_ports);
printf("%c\tstate: \"%s\"", MARK_CHANGE(PW_NODE_CHANGE_MASK_STATE),
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(PW_NODE_CHANGE_MASK_PROPS), true);
print_params(info->params, info->n_params, MARK_CHANGE(PW_NODE_CHANGE_MASK_PARAMS), true);
info->change_mask = 0;
}
static void info_port(struct proxy_data *pd)
{
struct pw_port_info *info = pd->info;
info_global(pd);
printf("\tdirection: \"%s\"\n", pw_direction_as_string(info->direction));
print_properties(info->props, MARK_CHANGE(PW_PORT_CHANGE_MASK_PROPS), true);
print_params(info->params, info->n_params, MARK_CHANGE(PW_PORT_CHANGE_MASK_PARAMS), true);
info->change_mask = 0;
}
static void info_factory(struct proxy_data *pd)
{
struct pw_factory_info *info = pd->info;
info_global(pd);
printf("\tname: \"%s\"\n", info->name);
printf("\tobject-type: %s/%d\n", info->type, info->version);
print_properties(info->props, MARK_CHANGE(PW_FACTORY_CHANGE_MASK_PROPS), true);
info->change_mask = 0;
}
static void info_client(struct proxy_data *pd)
{
struct pw_client_info *info = pd->info;
info_global(pd);
print_properties(info->props, MARK_CHANGE(PW_CLIENT_CHANGE_MASK_PROPS), true);
info->change_mask = 0;
}
static void info_link(struct proxy_data *pd)
{
struct pw_link_info *info = pd->info;
info_global(pd);
printf("\toutput-node-id: %u\n", info->output_node_id);
printf("\toutput-port-id: %u\n", info->output_port_id);
printf("\tinput-node-id: %u\n", info->input_node_id);
printf("\tinput-port-id: %u\n", info->input_port_id);
printf("%c\tstate: \"%s\"", MARK_CHANGE(PW_LINK_CHANGE_MASK_STATE),
pw_link_state_as_string(info->state));
if (info->state == PW_LINK_STATE_ERROR && info->error)
printf(" \"%s\"\n", info->error);
else
printf("\n");
printf("%c\tformat:\n", MARK_CHANGE(PW_LINK_CHANGE_MASK_FORMAT));
if (info->format)
spa_debug_pod(2, NULL, info->format);
else
printf("\t\tnone\n");
print_properties(info->props, MARK_CHANGE(PW_LINK_CHANGE_MASK_PROPS), true);
info->change_mask = 0;
}
static void info_device(struct proxy_data *pd)
{
struct pw_device_info *info = pd->info;
info_global(pd);
print_properties(info->props, MARK_CHANGE(PW_DEVICE_CHANGE_MASK_PROPS), true);
print_params(info->params, info->n_params, MARK_CHANGE(PW_DEVICE_CHANGE_MASK_PARAMS), true);
info->change_mask = 0;
}
static void info_session(struct proxy_data *pd)
{
struct pw_session_info *info = pd->info;
info_global(pd);
print_properties(info->props, MARK_CHANGE(0), true);
print_params(info->params, info->n_params, MARK_CHANGE(1), true);
info->change_mask = 0;
}
static void info_endpoint(struct proxy_data *pd)
{
struct pw_endpoint_info *info = pd->info;
const char *direction;
info_global(pd);
printf("\tname: %s\n", info->name);
printf("\tmedia-class: %s\n", info->media_class);
switch(info->direction) {
case PW_DIRECTION_OUTPUT:
direction = "source";
break;
case PW_DIRECTION_INPUT:
direction = "sink";
break;
default:
direction = "invalid";
break;
}
printf("\tdirection: %s\n", direction);
printf("\tflags: 0x%x\n", info->flags);
printf("%c\tstreams: %u\n", MARK_CHANGE(0), info->n_streams);
printf("%c\tsession: %u\n", MARK_CHANGE(1), info->session_id);
print_properties(info->props, MARK_CHANGE(2), true);
print_params(info->params, info->n_params, MARK_CHANGE(3), true);
info->change_mask = 0;
}
static void info_endpoint_stream(struct proxy_data *pd)
{
struct pw_endpoint_stream_info *info = pd->info;
info_global(pd);
printf("\tid: %u\n", info->id);
printf("\tendpoint-id: %u\n", info->endpoint_id);
printf("\tname: %s\n", info->name);
print_properties(info->props, MARK_CHANGE(1), true);
print_params(info->params, info->n_params, MARK_CHANGE(2), true);
info->change_mask = 0;
}
static void core_event_info(void *data, const struct pw_core_info *info)
{
struct proxy_data *pd = data;
struct remote_data *rd = pd->rd;
if (pd->info)
printf("remote %d core %d changed\n", rd->id, info->id);
pd->info = pw_core_info_update(pd->info, info);
if (pd->global == NULL)
pd->global = pw_map_lookup(&rd->globals, info->id);
if (pd->global && pd->global->info_pending) {
info_core(pd);
pd->global->info_pending = false;
}
}
static const struct pw_core_events core_events = {
PW_VERSION_CORE_EVENTS,
.info = core_event_info
};
static void module_event_info(void *data, const struct pw_module_info *info)
{
struct proxy_data *pd = data;
struct remote_data *rd = pd->rd;
if (pd->info)
printf("remote %d module %d changed\n", rd->id, info->id);
pd->info = pw_module_info_update(pd->info, info);
if (pd->global == NULL)
pd->global = pw_map_lookup(&rd->globals, info->id);
if (pd->global && pd->global->info_pending) {
info_module(pd);
pd->global->info_pending = false;
}
}
static const struct pw_module_events module_events = {
PW_VERSION_MODULE_EVENTS,
.info = module_event_info
};
static void node_event_info(void *data, const struct pw_node_info *info)
{
struct proxy_data *pd = data;
struct remote_data *rd = pd->rd;
if (pd->info)
printf("remote %d node %d changed\n", rd->id, info->id);
pd->info = pw_node_info_update(pd->info, info);
if (pd->global == NULL)
pd->global = pw_map_lookup(&rd->globals, info->id);
if (pd->global && pd->global->info_pending) {
info_node(pd);
pd->global->info_pending = false;
}
}
static void event_param(void *_data, int seq, uint32_t id,
uint32_t index, uint32_t next, const struct spa_pod *param)
{
struct proxy_data *data = _data;
struct remote_data *rd = data->rd;
if (rd->data->interactive)
printf("remote %d object %d param %d index %d\n",
rd->id, data->global->id, id, index);
spa_debug_pod(2, NULL, param);
}
static const struct pw_node_events node_events = {
PW_VERSION_NODE_EVENTS,
.info = node_event_info,
.param = event_param
};
static void port_event_info(void *data, const struct pw_port_info *info)
{
struct proxy_data *pd = data;
struct remote_data *rd = pd->rd;
if (pd->info)
printf("remote %d port %d changed\n", rd->id, info->id);
pd->info = pw_port_info_update(pd->info, info);
if (pd->global == NULL)
pd->global = pw_map_lookup(&rd->globals, info->id);
if (pd->global && pd->global->info_pending) {
info_port(pd);
pd->global->info_pending = false;
}
}
static const struct pw_port_events port_events = {
PW_VERSION_PORT_EVENTS,
.info = port_event_info,
.param = event_param
};
static void factory_event_info(void *data, const struct pw_factory_info *info)
{
struct proxy_data *pd = data;
struct remote_data *rd = pd->rd;
if (pd->info)
printf("remote %d factory %d changed\n", rd->id, info->id);
pd->info = pw_factory_info_update(pd->info, info);
if (pd->global == NULL)
pd->global = pw_map_lookup(&rd->globals, info->id);
if (pd->global && pd->global->info_pending) {
info_factory(pd);
pd->global->info_pending = false;
}
}
static const struct pw_factory_events factory_events = {
PW_VERSION_FACTORY_EVENTS,
.info = factory_event_info
};
static void client_event_info(void *data, const struct pw_client_info *info)
{
struct proxy_data *pd = data;
struct remote_data *rd = pd->rd;
if (pd->info)
printf("remote %d client %d changed\n", rd->id, info->id);
pd->info = pw_client_info_update(pd->info, info);
if (pd->global == NULL)
pd->global = pw_map_lookup(&rd->globals, info->id);
if (pd->global && pd->global->info_pending) {
info_client(pd);
pd->global->info_pending = false;
}
}
static void client_event_permissions(void *_data, uint32_t index,
uint32_t n_permissions, const struct pw_permission *permissions)
{
struct proxy_data *data = _data;
struct remote_data *rd = data->rd;
uint32_t i;
printf("remote %d node %d index %d\n",
rd->id, data->global->id, index);
for (i = 0; i < n_permissions; i++) {
if (permissions[i].id == PW_ID_ANY)
printf(" default:");
else
printf(" %u:", permissions[i].id);
printf(" "PW_PERMISSION_FORMAT"\n",
PW_PERMISSION_ARGS(permissions[i].permissions));
}
}
static const struct pw_client_events client_events = {
PW_VERSION_CLIENT_EVENTS,
.info = client_event_info,
.permissions = client_event_permissions
};
static void link_event_info(void *data, const struct pw_link_info *info)
{
struct proxy_data *pd = data;
struct remote_data *rd = pd->rd;
if (pd->info)
printf("remote %d link %d changed\n", rd->id, info->id);
pd->info = pw_link_info_update(pd->info, info);
if (pd->global == NULL)
pd->global = pw_map_lookup(&rd->globals, info->id);
if (pd->global && pd->global->info_pending) {
info_link(pd);
pd->global->info_pending = false;