PipeWire: pipewire/extensions/session-manager/introspect-funcs.h Source File

PipeWire 0.3.51

introspect-funcs.h
Go to the documentation of this file.
1/* PipeWire
2 *
3 * Copyright © 2020 Collabora Ltd.
4 * @author George Kiagiadakis <george.kiagiadakis@collabora.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#ifndef PIPEWIRE_EXT_SESSION_MANAGER_INTROSPECT_FUNCS_H
27#define PIPEWIRE_EXT_SESSION_MANAGER_INTROSPECT_FUNCS_H
28
29#include "introspect.h"
30#include <spa/pod/builder.h>
31#include <pipewire/pipewire.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
42static inline struct pw_session_info *
43 pw_session_info_update (struct pw_session_info *info,
44 const struct pw_session_info *update)
45{
46 struct extended_info {
47 struct pw_properties *props_storage;
48 struct pw_session_info info;
49 } *ext;
50
51 if (update == NULL)
52 return info;
53
54 if (info == NULL) {
55 ext = (struct extended_info *) calloc(1, sizeof(*ext));
56 if (ext == NULL)
57 return NULL;
58
59 info = &ext->info;
60 info->id = update->id;
61 } else {
62 ext = SPA_CONTAINER_OF(info, struct extended_info, info);
63 }
64
65 info->change_mask = update->change_mask;
66
67 if (update->change_mask & PW_SESSION_CHANGE_MASK_PROPS) {
68 if (!ext->props_storage) {
69 ext->props_storage = pw_properties_new(NULL, NULL);
70 info->props = &ext->props_storage->dict;
71 }
72 pw_properties_clear(ext->props_storage);
73 pw_properties_update(ext->props_storage, update->props);
74 }
75 if (update->change_mask & PW_SESSION_CHANGE_MASK_PARAMS) {
76 info->n_params = update->n_params;
77 free((void *) info->params);
78 if (update->params) {
79 size_t size = info->n_params * sizeof(struct spa_param_info);
80 info->params = (struct spa_param_info *) malloc(size);
81 memcpy(info->params, update->params, size);
82 }
83 else
84 info->params = NULL;
85 }
86 return info;
87}
88
89static inline void
90 pw_session_info_free (struct pw_session_info *info)
91{
92 struct extended_info {
93 struct pw_properties *props_storage;
94 struct pw_session_info info;
95 } *ext = SPA_CONTAINER_OF(info, struct extended_info, info);
96
97 pw_properties_free(ext->props_storage);
98 free((void *) info->params);
99 free(ext);
100}
101
102static inline struct pw_endpoint_info *
103 pw_endpoint_info_update (struct pw_endpoint_info *info,
104 const struct pw_endpoint_info *update)
105{
106 struct extended_info {
107 struct pw_properties *props_storage;
108 struct pw_endpoint_info info;
109 } *ext;
110
111 if (update == NULL)
112 return info;
113
114 if (info == NULL) {
115 ext = (struct extended_info *) calloc(1, sizeof(*ext));
116 if (ext == NULL)
117 return NULL;
118
119 info = &ext->info;
120 info->id = update->id;
121 info->name = strdup(update->name);
122 info->media_class = strdup(update->media_class);
123 info->direction = update->direction;
124 info->flags = update->flags;
125 } else {
126 ext = SPA_CONTAINER_OF(info, struct extended_info, info);
127 }
128
129 info->change_mask = update->change_mask;
130
131 if (update->change_mask & PW_ENDPOINT_CHANGE_MASK_STREAMS)
132 info->n_streams = update->n_streams;
133
134 if (update->change_mask & PW_ENDPOINT_CHANGE_MASK_SESSION)
135 info->session_id = update->session_id;
136
137 if (update->change_mask & PW_ENDPOINT_CHANGE_MASK_PROPS) {
138 if (!ext->props_storage) {
139 ext->props_storage = pw_properties_new(NULL, NULL);
140 info->props = &ext->props_storage->dict;
141 }
142 pw_properties_clear(ext->props_storage);
143 pw_properties_update(ext->props_storage, update->props);
144 }
145 if (update->change_mask & PW_ENDPOINT_CHANGE_MASK_PARAMS) {
146 info->n_params = update->n_params;
147 free((void *) info->params);
148 if (update->params) {
149 size_t size = info->n_params * sizeof(struct spa_param_info);
150 info->params = (struct spa_param_info *) malloc(size);
151 memcpy(info->params, update->params, size);
152 }
153 else
154 info->params = NULL;
155 }
156 return info;
157}
158
159static inline void
160 pw_endpoint_info_free (struct pw_endpoint_info *info)
161{
162 struct extended_info {
163 struct pw_properties *props_storage;
164 struct pw_endpoint_info info;
165 } *ext = SPA_CONTAINER_OF(info, struct extended_info, info);
166
167 pw_properties_free(ext->props_storage);
168 free(info->name);
169 free(info->media_class);
170 free((void *) info->params);
171 free(ext);
172}
173
174static inline struct pw_endpoint_stream_info *
175 pw_endpoint_stream_info_update (struct pw_endpoint_stream_info *info,
176 const struct pw_endpoint_stream_info *update)
177{
178 struct extended_info {
179 struct pw_properties *props_storage;
180 struct pw_endpoint_stream_info info;
181 } *ext;
182
183 if (update == NULL)
184 return info;
185
186 if (info == NULL) {
187 ext = (struct extended_info *) calloc(1, sizeof(*ext));
188 if (ext == NULL)
189 return NULL;
190
191 info = &ext->info;
192 info->id = update->id;
193 info->endpoint_id = update->endpoint_id;
194 info->name = strdup(update->name);
195 } else {
196 ext = SPA_CONTAINER_OF(info, struct extended_info, info);
197 }
198
199 info->change_mask = update->change_mask;
200
201 if (update->change_mask & PW_ENDPOINT_STREAM_CHANGE_MASK_LINK_PARAMS) {
202 free(info->link_params);
203 info->link_params = update->link_params ?
204 spa_pod_copy(update->link_params) : NULL;
205 }
206 if (update->change_mask & PW_ENDPOINT_STREAM_CHANGE_MASK_PROPS) {
207 if (!ext->props_storage) {
208 ext->props_storage = pw_properties_new(NULL, NULL);
209 info->props = &ext->props_storage->dict;
210 }
211 pw_properties_clear(ext->props_storage);
212 pw_properties_update(ext->props_storage, update->props);
213 }
214 if (update->change_mask & PW_ENDPOINT_STREAM_CHANGE_MASK_PARAMS) {
215 info->n_params = update->n_params;
216 free((void *) info->params);
217 if (update->params) {
218 size_t size = info->n_params * sizeof(struct spa_param_info);
219 info->params = (struct spa_param_info *) malloc(size);
220 memcpy(info->params, update->params, size);
221 }
222 else
223 info->params = NULL;
224 }
225 return info;
226}
227
228static inline void
229 pw_endpoint_stream_info_free (struct pw_endpoint_stream_info *info)
230{
231 struct extended_info {
232 struct pw_properties *props_storage;
233 struct pw_endpoint_stream_info info;
234 } *ext = SPA_CONTAINER_OF(info, struct extended_info, info);
235
236 pw_properties_free(ext->props_storage);
237 free(info->name);
238 free(info->link_params);
239 free((void *) info->params);
240 free(ext);
241}
242
243
244static inline struct pw_endpoint_link_info *
245 pw_endpoint_link_info_update (struct pw_endpoint_link_info *info,
246 const struct pw_endpoint_link_info *update)
247{
248 struct extended_info {
249 struct pw_properties *props_storage;
250 struct pw_endpoint_link_info info;
251 } *ext;
252
253 if (update == NULL)
254 return info;
255
256 if (info == NULL) {
257 ext = (struct extended_info *) calloc(1, sizeof(*ext));
258 if (ext == NULL)
259 return NULL;
260
261 info = &ext->info;
262 info->id = update->id;
263 info->session_id = update->session_id;
264 info->output_endpoint_id = update->output_endpoint_id;
265 info->output_stream_id = update->output_stream_id;
266 info->input_endpoint_id = update->input_endpoint_id;
267 info->input_stream_id = update->input_stream_id;
268 } else {
269 ext = SPA_CONTAINER_OF(info, struct extended_info, info);
270 }
271
272 info->change_mask = update->change_mask;
273
274 if (update->change_mask & PW_ENDPOINT_LINK_CHANGE_MASK_STATE) {
275 info->state = update->state;
276 free(info->error);
277 info->error = update->error ? strdup(update->error) : NULL;
278 }
279 if (update->change_mask & PW_ENDPOINT_LINK_CHANGE_MASK_PROPS) {
280 if (!ext->props_storage) {
281 ext->props_storage = pw_properties_new(NULL, NULL);
282 info->props = &ext->props_storage->dict;
283 }
284 pw_properties_clear(ext->props_storage);
285 pw_properties_update(ext->props_storage, update->props);
286 }
287 if (update->change_mask & PW_ENDPOINT_LINK_CHANGE_MASK_PARAMS) {
288 info->n_params = update->n_params;
289 free((void *) info->params);
290 if (update->params) {
291 size_t size = info->n_params * sizeof(struct spa_param_info);
292 info->params = (struct spa_param_info *) malloc(size);
293 memcpy(info->params, update->params, size);
294 }
295 else
296 info->params = NULL;
297 }
298 return info;
299}
300
301static inline void
302 pw_endpoint_link_info_free (struct pw_endpoint_link_info *info)
303{
304 struct extended_info {
305 struct pw_properties *props_storage;
306 struct pw_endpoint_link_info info;
307 } *ext = SPA_CONTAINER_OF(info, struct extended_info, info);
308
309 pw_properties_free(ext->props_storage);
310 free(info->error);
311 free((void *) info->params);
312 free(ext);
313}
314
319#ifdef __cplusplus
320} /* extern "C" */
321#endif
322
323#endif /* PIPEWIRE_EXT_SESSION_MANAGER_INTROSPECT_FUNCS_H */
builder.h
spa/pod/builder.h
pw_properties_free
void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition: properties.c:368
pw_properties_new
struct pw_properties * pw_properties_new(const char *key,...) 1
Make a new properties object.
Definition: properties.c:102
pw_properties_update
int pw_properties_update(struct pw_properties *props, const struct spa_dict *dict)
Update properties.
Definition: properties.c:302
pw_properties_clear
void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition: properties.c:281
PW_ENDPOINT_STREAM_CHANGE_MASK_PARAMS
#define PW_ENDPOINT_STREAM_CHANGE_MASK_PARAMS
Definition: introspect.h:111
pw_endpoint_info_free
static void pw_endpoint_info_free(struct pw_endpoint_info *info)
Definition: introspect-funcs.h:164
PW_SESSION_CHANGE_MASK_PROPS
#define PW_SESSION_CHANGE_MASK_PROPS
Definition: introspect.h:59
PW_ENDPOINT_CHANGE_MASK_SESSION
#define PW_ENDPOINT_CHANGE_MASK_SESSION
Definition: introspect.h:84
PW_ENDPOINT_STREAM_CHANGE_MASK_PROPS
#define PW_ENDPOINT_STREAM_CHANGE_MASK_PROPS
Definition: introspect.h:109
PW_ENDPOINT_CHANGE_MASK_STREAMS
#define PW_ENDPOINT_CHANGE_MASK_STREAMS
Definition: introspect.h:82
pw_session_info_free
static void pw_session_info_free(struct pw_session_info *info)
Definition: introspect-funcs.h:94
pw_session_info_update
static struct pw_session_info * pw_session_info_update(struct pw_session_info *info, const struct pw_session_info *update)
Definition: introspect-funcs.h:47
PW_ENDPOINT_CHANGE_MASK_PROPS
#define PW_ENDPOINT_CHANGE_MASK_PROPS
Definition: introspect.h:86
PW_ENDPOINT_LINK_CHANGE_MASK_PARAMS
#define PW_ENDPOINT_LINK_CHANGE_MASK_PARAMS
Definition: introspect.h:136
pw_endpoint_stream_info_update
static struct pw_endpoint_stream_info * pw_endpoint_stream_info_update(struct pw_endpoint_stream_info *info, const struct pw_endpoint_stream_info *update)
Definition: introspect-funcs.h:179
pw_endpoint_link_info_update
static struct pw_endpoint_link_info * pw_endpoint_link_info_update(struct pw_endpoint_link_info *info, const struct pw_endpoint_link_info *update)
Definition: introspect-funcs.h:249
PW_ENDPOINT_CHANGE_MASK_PARAMS
#define PW_ENDPOINT_CHANGE_MASK_PARAMS
Definition: introspect.h:88
PW_ENDPOINT_LINK_CHANGE_MASK_PROPS
#define PW_ENDPOINT_LINK_CHANGE_MASK_PROPS
Definition: introspect.h:134
PW_SESSION_CHANGE_MASK_PARAMS
#define PW_SESSION_CHANGE_MASK_PARAMS
Definition: introspect.h:61
pw_endpoint_stream_info_free
static void pw_endpoint_stream_info_free(struct pw_endpoint_stream_info *info)
Definition: introspect-funcs.h:233
pw_endpoint_link_info_free
static void pw_endpoint_link_info_free(struct pw_endpoint_link_info *info)
Definition: introspect-funcs.h:306
PW_ENDPOINT_STREAM_CHANGE_MASK_LINK_PARAMS
#define PW_ENDPOINT_STREAM_CHANGE_MASK_LINK_PARAMS
Definition: introspect.h:107
pw_endpoint_info_update
static struct pw_endpoint_info * pw_endpoint_info_update(struct pw_endpoint_info *info, const struct pw_endpoint_info *update)
Definition: introspect-funcs.h:107
PW_ENDPOINT_LINK_CHANGE_MASK_STATE
#define PW_ENDPOINT_LINK_CHANGE_MASK_STATE
Definition: introspect.h:132
spa_pod_copy
static struct spa_pod * spa_pod_copy(const struct spa_pod *pod)
Copy a pod structure.
Definition: builder.h:703
SPA_CONTAINER_OF
#define SPA_CONTAINER_OF(p, t, m)
Definition: defs.h:197
introspect.h
pipewire/extensions/session-manager/introspect.h
pipewire.h
pipewire/pipewire.h
pw_endpoint_info
Definition: introspect.h:70
pw_endpoint_info::params
struct spa_param_info * params
parameters
Definition: introspect.h:95
pw_endpoint_info::id
uint32_t id
the endpoint id (global)
Definition: introspect.h:74
pw_endpoint_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition: introspect.h:91
pw_endpoint_info::direction
enum pw_direction direction
direction of the endpoint
Definition: introspect.h:77
pw_endpoint_info::n_params
uint32_t n_params
number of items in params
Definition: introspect.h:96
pw_endpoint_info::flags
uint32_t flags
additional flags
Definition: introspect.h:80
pw_endpoint_info::media_class
char * media_class
media class of the endpoint
Definition: introspect.h:76
pw_endpoint_info::session_id
uint32_t session_id
the id of the controlling session
Definition: introspect.h:93
pw_endpoint_info::n_streams
uint32_t n_streams
number of streams available
Definition: introspect.h:92
pw_endpoint_link_info
Definition: introspect.h:121
pw_endpoint_link_info::id
uint32_t id
the link id (global)
Definition: introspect.h:125
pw_endpoint_link_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition: introspect.h:139
pw_endpoint_link_info::output_endpoint_id
uint32_t output_endpoint_id
the output endpoint id (global)
Definition: introspect.h:127
pw_endpoint_link_info::input_endpoint_id
uint32_t input_endpoint_id
the input endpoint id (global)
Definition: introspect.h:129
pw_endpoint_link_info::error
char * error
error string if state == ERROR
Definition: introspect.h:141
pw_endpoint_link_info::params
struct spa_param_info * params
parameters
Definition: introspect.h:143
pw_endpoint_link_info::state
enum pw_endpoint_link_state state
the state of the link
Definition: introspect.h:140
pw_endpoint_link_info::n_params
uint32_t n_params
number of items in params
Definition: introspect.h:144
pw_endpoint_link_info::output_stream_id
uint32_t output_stream_id
the output stream id (local or global)
Definition: introspect.h:128
pw_endpoint_link_info::input_stream_id
uint32_t input_stream_id
the input stream id (local or global)
Definition: introspect.h:130
pw_endpoint_link_info::session_id
uint32_t session_id
the session id (global)
Definition: introspect.h:126
pw_endpoint_stream_info
Definition: introspect.h:99
pw_endpoint_stream_info::n_params
uint32_t n_params
number of items in params
Definition: introspect.h:118
pw_endpoint_stream_info::params
struct spa_param_info * params
parameters
Definition: introspect.h:117
pw_endpoint_stream_info::endpoint_id
uint32_t endpoint_id
the endpoint id (global)
Definition: introspect.h:104
pw_endpoint_stream_info::link_params
struct spa_pod * link_params
information for linking this stream
Definition: introspect.h:115
pw_endpoint_stream_info::id
uint32_t id
the stream id (local or global)
Definition: introspect.h:103
pw_endpoint_stream_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition: introspect.h:114
pw_properties
Definition: properties.h:53
pw_session_info
Definition: introspect.h:53
pw_session_info::params
struct spa_param_info * params
parameters
Definition: introspect.h:66
pw_session_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition: introspect.h:64
pw_session_info::id
uint32_t id
the session id (global)
Definition: introspect.h:57
pw_session_info::n_params
uint32_t n_params
number of items in params
Definition: introspect.h:67
spa_param_info
information about a parameter
Definition: param.h:70