wireplumber: update to latest master
[AGL/meta-agl-devel.git] / meta-pipewire / recipes-multimedia / pipewire / pipewire / 0010-pipewire-cli-add-support-for-printing-endpoint-info-.patch
1 From 76865803c2db13b753e1261e01de22760c7b398b Mon Sep 17 00:00:00 2001
2 From: George Kiagiadakis <george.kiagiadakis@collabora.com>
3 Date: Tue, 28 May 2019 11:46:36 +0300
4 Subject: [PATCH] pipewire-cli: add support for printing endpoint info & params
5
6 Upstream-Status: Pending
7 ---
8  src/tools/pipewire-cli.c | 107 ++++++++++++++++++++++++++++++++++++++-
9  1 file changed, 106 insertions(+), 1 deletion(-)
10
11 diff --git a/src/tools/pipewire-cli.c b/src/tools/pipewire-cli.c
12 index 6110d170..0dbc8368 100644
13 --- a/src/tools/pipewire-cli.c
14 +++ b/src/tools/pipewire-cli.c
15 @@ -37,6 +37,8 @@
16  #include <pipewire/type.h>
17  #include <pipewire/permission.h>
18  
19 +#include <extensions/session-manager.h>
20 +
21  static const char WHITESPACE[] = " \t";
22  
23  struct remote_data;
24 @@ -174,8 +176,10 @@ static void print_params(struct spa_param_info *params, uint32_t n_params, char
25                 return;
26         }
27         for (i = 0; i < n_params; i++) {
28 +               const struct spa_type_info *type_info = spa_type_param;
29 +
30                 fprintf(stdout, "%c\t  %d (%s) %c%c\n", mark, params[i].id,
31 -                       spa_debug_type_find_name(spa_type_param, params[i].id),
32 +                       spa_debug_type_find_name(type_info, params[i].id),
33                         params[i].flags & SPA_PARAM_INFO_READ ? 'r' : '-',
34                         params[i].flags & SPA_PARAM_INFO_WRITE ? 'w' : '-');
35         }
36 @@ -652,6 +656,40 @@ static void info_device(struct proxy_data *pd)
37         info->change_mask = 0;
38  }
39  
40 +static void info_endpoint(struct proxy_data *pd)
41 +{
42 +       struct pw_endpoint_info *info = pd->info;
43 +       const char *direction;
44 +
45 +       info_global(pd);
46 +       fprintf(stdout, "\tname: %s\n", info->name);
47 +       fprintf(stdout, "\tmedia-class: %s\n",  info->media_class);
48 +       switch(info->direction) {
49 +       case PW_ENDPOINT_DIRECTION_SINK_INPUT:
50 +               direction = "sink-input";
51 +               break;
52 +       case PW_ENDPOINT_DIRECTION_SOURCE_OUTPUT:
53 +               direction = "source-output";
54 +               break;
55 +       case PW_ENDPOINT_DIRECTION_SOURCE:
56 +               direction = "source";
57 +               break;
58 +       case PW_ENDPOINT_DIRECTION_SINK:
59 +               direction = "sink";
60 +               break;
61 +       default:
62 +               direction = "invalid";
63 +               break;
64 +       }
65 +       fprintf(stdout, "\tdirection: %s\n", direction);
66 +       fprintf(stdout, "\tflags: 0x%x\n", info->flags);
67 +       fprintf(stdout, "%c\tstreams: %u\n", MARK_CHANGE(0), info->n_streams);
68 +       fprintf(stdout, "%c\tsession: %u\n", MARK_CHANGE(0), info->session_id);
69 +       print_properties(info->props, MARK_CHANGE(2), true);
70 +       print_params(info->params, info->n_params, MARK_CHANGE(3), true);
71 +       info->change_mask = 0;
72 +}
73 +
74  static void core_event_info(void *object, const struct pw_core_info *info)
75  {
76         struct proxy_data *pd = object;
77 @@ -853,6 +891,63 @@ static const struct pw_device_proxy_events device_events = {
78         .param = event_param
79  };
80  
81 +static void endpoint_info_free(struct pw_endpoint_info *info)
82 +{
83 +       free(info->name);
84 +       free(info->media_class);
85 +       free(info->params);
86 +       if (info->props)
87 +               pw_properties_free ((struct pw_properties *)info->props);
88 +       free(info);
89 +}
90 +
91 +static void endpoint_event_info(void *object,
92 +                               const struct pw_endpoint_info *update)
93 +{
94 +       struct proxy_data *pd = object;
95 +       struct remote_data *rd = pd->rd;
96 +       struct pw_endpoint_info *info = pd->info;
97 +
98 +       if (!info) {
99 +               info = pd->info = calloc(1, sizeof(*info));
100 +               info->id = update->id;
101 +               info->name = strdup(update->name);
102 +               info->media_class = strdup(update->media_class);
103 +               info->direction = update->direction;
104 +               info->flags = update->flags;
105 +       }
106 +       if (update->change_mask & PW_ENDPOINT_CHANGE_MASK_STREAMS)
107 +               info->n_streams = update->n_streams;
108 +       if (update->change_mask & PW_ENDPOINT_CHANGE_MASK_SESSION)
109 +               info->session_id = update->session_id;
110 +       if (update->change_mask & PW_ENDPOINT_CHANGE_MASK_PARAMS) {
111 +               info->n_params = update->n_params;
112 +               free(info->params);
113 +               info->params = malloc(info->n_params * sizeof(struct spa_param_info));
114 +               memcpy(info->params, update->params,
115 +                       info->n_params * sizeof(struct spa_param_info));
116 +       }
117 +       if (update->change_mask & PW_ENDPOINT_CHANGE_MASK_PROPS) {
118 +               if (info->props)
119 +                       pw_properties_free ((struct pw_properties *)info->props);
120 +               info->props =
121 +                       (struct spa_dict *) pw_properties_new_dict (update->props);
122 +       }
123 +
124 +       if (pd->global == NULL)
125 +               pd->global = pw_map_lookup(&rd->globals, info->id);
126 +       if (pd->global && pd->global->info_pending) {
127 +               info_endpoint(pd);
128 +               pd->global->info_pending = false;
129 +       }
130 +}
131 +
132 +static const struct pw_endpoint_proxy_events endpoint_events = {
133 +       PW_VERSION_ENDPOINT_PROXY_EVENTS,
134 +       .info = endpoint_event_info,
135 +       .param = event_param
136 +};
137 +
138  static void
139  destroy_proxy (void *data)
140  {
141 @@ -939,6 +1034,12 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er
142                 destroy = (pw_destroy_t) pw_link_info_free;
143                 info_func = info_link;
144                 break;
145 +       case PW_TYPE_INTERFACE_Endpoint:
146 +               events = &endpoint_events;
147 +               client_version = PW_VERSION_ENDPOINT_PROXY;
148 +               destroy = (pw_destroy_t) endpoint_info_free;
149 +               info_func = info_endpoint;
150 +               break;
151         default:
152                 asprintf(error, "unsupported type %s", spa_debug_type_find_name(pw_type_info(), global->type));
153                 return false;
154 @@ -1213,6 +1314,10 @@ static bool do_enum_params(struct data *data, const char *cmd, char *args, char
155                 pw_device_proxy_enum_params((struct pw_device_proxy*)global->proxy, 0,
156                         param_id, 0, 0, NULL);
157                 break;
158 +       case PW_TYPE_INTERFACE_Endpoint:
159 +               pw_endpoint_proxy_enum_params((struct pw_endpoint_proxy*)global->proxy, 0,
160 +                       param_id, 0, 0, NULL);
161 +               break;
162         default:
163                 asprintf(error, "enum-params not implemented on object %d", atoi(a[0]));
164                 return false;
165 -- 
166 2.23.0
167