1 /* PipeWire
2  *
3  * Copyright © 2019 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_INTERFACES_H
27 #define PIPEWIRE_EXT_SESSION_MANAGER_INTERFACES_H
28 
29 #include <spa/utils/defs.h>
30 #include <spa/utils/hook.h>
31 
32 #include "introspect.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /**
39  * \addtogroup pw_session_manager
40  * \{
41  */
42 
43 #define PW_TYPE_INTERFACE_Session		PW_TYPE_INFO_INTERFACE_BASE "Session"
44 #define PW_VERSION_SESSION			0
45 struct pw_session;
46 
47 #define PW_TYPE_INTERFACE_Endpoint		PW_TYPE_INFO_INTERFACE_BASE "Endpoint"
48 #define PW_VERSION_ENDPOINT			0
49 struct pw_endpoint;
50 
51 #define PW_TYPE_INTERFACE_EndpointStream	PW_TYPE_INFO_INTERFACE_BASE "EndpointStream"
52 #define PW_VERSION_ENDPOINT_STREAM		0
53 struct pw_endpoint_stream;
54 
55 #define PW_TYPE_INTERFACE_EndpointLink		PW_TYPE_INFO_INTERFACE_BASE "EndpointLink"
56 #define PW_VERSION_ENDPOINT_LINK		0
57 struct pw_endpoint_link;
58 
59 /* Session */
60 
61 #define PW_SESSION_EVENT_INFO		0
62 #define PW_SESSION_EVENT_PARAM		1
63 #define PW_SESSION_EVENT_NUM		2
64 
65 struct pw_session_events {
66 #define PW_VERSION_SESSION_EVENTS		0
67 	uint32_t version;			/**< version of this structure */
68 
69 	/**
70 	 * Notify session info
71 	 *
72 	 * \param info info about the session
73 	 */
74 	void (*info) (void *object, const struct pw_session_info *info);
75 
76 	/**
77 	 * Notify a session param
78 	 *
79 	 * Event emitted as a result of the enum_params method.
80 	 *
81 	 * \param seq the sequence number of the request
82 	 * \param id the param id
83 	 * \param index the param index
84 	 * \param next the param index of the next param
85 	 * \param param the parameter
86 	 */
87 	void (*param) (void *object, int seq,
88 		       uint32_t id, uint32_t index, uint32_t next,
89 		       const struct spa_pod *param);
90 };
91 
92 #define PW_SESSION_METHOD_ADD_LISTENER		0
93 #define PW_SESSION_METHOD_SUBSCRIBE_PARAMS	1
94 #define PW_SESSION_METHOD_ENUM_PARAMS		2
95 #define PW_SESSION_METHOD_SET_PARAM		3
96 #define PW_SESSION_METHOD_CREATE_LINK		4
97 #define PW_SESSION_METHOD_NUM			5
98 
99 struct pw_session_methods {
100 #define PW_VERSION_SESSION_METHODS	0
101 	uint32_t version;			/**< version of this structure */
102 
103 	int (*add_listener) (void *object,
104 			struct spa_hook *listener,
105 			const struct pw_session_events *events,
106 			void *data);
107 
108 	/**
109 	 * Subscribe to parameter changes
110 	 *
111 	 * Automatically emit param events for the given ids when
112 	 * they are changed.
113 	 *
114 	 * \param ids an array of param ids
115 	 * \param n_ids the number of ids in \a ids
116 	 */
117 	int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids);
118 
119 	/**
120 	 * Enumerate session parameters
121 	 *
122 	 * Start enumeration of session parameters. For each param, a
123 	 * param event will be emitted.
124 	 *
125 	 * \param seq a sequence number returned in the reply
126 	 * \param id the parameter id to enumerate
127 	 * \param start the start index or 0 for the first param
128 	 * \param num the maximum number of params to retrieve
129 	 * \param filter a param filter or NULL
130 	 */
131 	int (*enum_params) (void *object, int seq,
132 			uint32_t id, uint32_t start, uint32_t num,
133 			const struct spa_pod *filter);
134 
135 	/**
136 	 * Set a parameter on the session
137 	 *
138 	 * \param id the parameter id to set
139 	 * \param flags extra parameter flags
140 	 * \param param the parameter to set
141 	 */
142 	int (*set_param) (void *object, uint32_t id, uint32_t flags,
143 			  const struct spa_pod *param);
144 };
145 
146 #define pw_session_method(o,method,version,...)				\
147 ({									\
148 	int _res = -ENOTSUP;						\
149 	spa_interface_call_res((struct spa_interface*)o,		\
150 			struct pw_session_methods, _res,		\
151 			method, version, ##__VA_ARGS__);		\
152 	_res;								\
153 })
154 
155 #define pw_session_add_listener(c,...)		pw_session_method(c,add_listener,0,__VA_ARGS__)
156 #define pw_session_subscribe_params(c,...)	pw_session_method(c,subscribe_params,0,__VA_ARGS__)
157 #define pw_session_enum_params(c,...)		pw_session_method(c,enum_params,0,__VA_ARGS__)
158 #define pw_session_set_param(c,...)		pw_session_method(c,set_param,0,__VA_ARGS__)
159 
160 
161 /* Endpoint */
162 
163 #define PW_ENDPOINT_EVENT_INFO		0
164 #define PW_ENDPOINT_EVENT_PARAM		1
165 #define PW_ENDPOINT_EVENT_NUM		2
166 
167 struct pw_endpoint_events {
168 #define PW_VERSION_ENDPOINT_EVENTS	0
169 	uint32_t version;			/**< version of this structure */
170 
171 	/**
172 	 * Notify endpoint info
173 	 *
174 	 * \param info info about the endpoint
175 	 */
176 	void (*info) (void *object, const struct pw_endpoint_info *info);
177 
178 	/**
179 	 * Notify a endpoint param
180 	 *
181 	 * Event emitted as a result of the enum_params method.
182 	 *
183 	 * \param seq the sequence number of the request
184 	 * \param id the param id
185 	 * \param index the param index
186 	 * \param next the param index of the next param
187 	 * \param param the parameter
188 	 */
189 	void (*param) (void *object, int seq,
190 		       uint32_t id, uint32_t index, uint32_t next,
191 		       const struct spa_pod *param);
192 };
193 
194 #define PW_ENDPOINT_METHOD_ADD_LISTENER		0
195 #define PW_ENDPOINT_METHOD_SUBSCRIBE_PARAMS	1
196 #define PW_ENDPOINT_METHOD_ENUM_PARAMS		2
197 #define PW_ENDPOINT_METHOD_SET_PARAM		3
198 #define PW_ENDPOINT_METHOD_CREATE_LINK		4
199 #define PW_ENDPOINT_METHOD_NUM			5
200 
201 struct pw_endpoint_methods {
202 #define PW_VERSION_ENDPOINT_METHODS	0
203 	uint32_t version;			/**< version of this structure */
204 
205 	int (*add_listener) (void *object,
206 			struct spa_hook *listener,
207 			const struct pw_endpoint_events *events,
208 			void *data);
209 
210 	/**
211 	 * Subscribe to parameter changes
212 	 *
213 	 * Automatically emit param events for the given ids when
214 	 * they are changed.
215 	 *
216 	 * \param ids an array of param ids
217 	 * \param n_ids the number of ids in \a ids
218 	 */
219 	int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids);
220 
221 	/**
222 	 * Enumerate endpoint parameters
223 	 *
224 	 * Start enumeration of endpoint parameters. For each param, a
225 	 * param event will be emitted.
226 	 *
227 	 * \param seq a sequence number returned in the reply
228 	 * \param id the parameter id to enumerate
229 	 * \param start the start index or 0 for the first param
230 	 * \param num the maximum number of params to retrieve
231 	 * \param filter a param filter or NULL
232 	 */
233 	int (*enum_params) (void *object, int seq,
234 			uint32_t id, uint32_t start, uint32_t num,
235 			const struct spa_pod *filter);
236 
237 	/**
238 	 * Set a parameter on the endpoint
239 	 *
240 	 * \param id the parameter id to set
241 	 * \param flags extra parameter flags
242 	 * \param param the parameter to set
243 	 */
244 	int (*set_param) (void *object, uint32_t id, uint32_t flags,
245 			  const struct spa_pod *param);
246 
247 	int (*create_link) (void *object, const struct spa_dict *props);
248 };
249 
250 #define pw_endpoint_method(o,method,version,...)			\
251 ({									\
252 	int _res = -ENOTSUP;						\
253 	spa_interface_call_res((struct spa_interface*)o,		\
254 			struct pw_endpoint_methods, _res,		\
255 			method, version, ##__VA_ARGS__);		\
256 	_res;								\
257 })
258 
259 #define pw_endpoint_add_listener(c,...)		pw_endpoint_method(c,add_listener,0,__VA_ARGS__)
260 #define pw_endpoint_subscribe_params(c,...)	pw_endpoint_method(c,subscribe_params,0,__VA_ARGS__)
261 #define pw_endpoint_enum_params(c,...)		pw_endpoint_method(c,enum_params,0,__VA_ARGS__)
262 #define pw_endpoint_set_param(c,...)		pw_endpoint_method(c,set_param,0,__VA_ARGS__)
263 #define pw_endpoint_create_link(c,...)		pw_endpoint_method(c,create_link,0,__VA_ARGS__)
264 
265 /* Endpoint Stream */
266 
267 #define PW_ENDPOINT_STREAM_EVENT_INFO		0
268 #define PW_ENDPOINT_STREAM_EVENT_PARAM		1
269 #define PW_ENDPOINT_STREAM_EVENT_NUM		2
270 
271 struct pw_endpoint_stream_events {
272 #define PW_VERSION_ENDPOINT_STREAM_EVENTS	0
273 	uint32_t version;			/**< version of this structure */
274 
275 	/**
276 	 * Notify endpoint stream info
277 	 *
278 	 * \param info info about the endpoint stream
279 	 */
280 	void (*info) (void *object, const struct pw_endpoint_stream_info *info);
281 
282 	/**
283 	 * Notify a endpoint stream param
284 	 *
285 	 * Event emitted as a result of the enum_params method.
286 	 *
287 	 * \param seq the sequence number of the request
288 	 * \param id the param id
289 	 * \param index the param index
290 	 * \param next the param index of the next param
291 	 * \param param the parameter
292 	 */
293 	void (*param) (void *object, int seq,
294 		       uint32_t id, uint32_t index, uint32_t next,
295 		       const struct spa_pod *param);
296 };
297 
298 #define PW_ENDPOINT_STREAM_METHOD_ADD_LISTENER		0
299 #define PW_ENDPOINT_STREAM_METHOD_SUBSCRIBE_PARAMS	1
300 #define PW_ENDPOINT_STREAM_METHOD_ENUM_PARAMS		2
301 #define PW_ENDPOINT_STREAM_METHOD_SET_PARAM		3
302 #define PW_ENDPOINT_STREAM_METHOD_NUM			4
303 
304 struct pw_endpoint_stream_methods {
305 #define PW_VERSION_ENDPOINT_STREAM_METHODS	0
306 	uint32_t version;			/**< version of this structure */
307 
308 	int (*add_listener) (void *object,
309 			struct spa_hook *listener,
310 			const struct pw_endpoint_stream_events *events,
311 			void *data);
312 
313 	/**
314 	 * Subscribe to parameter changes
315 	 *
316 	 * Automatically emit param events for the given ids when
317 	 * they are changed.
318 	 *
319 	 * \param ids an array of param ids
320 	 * \param n_ids the number of ids in \a ids
321 	 */
322 	int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids);
323 
324 	/**
325 	 * Enumerate stream parameters
326 	 *
327 	 * Start enumeration of stream parameters. For each param, a
328 	 * param event will be emitted.
329 	 *
330 	 * \param seq a sequence number returned in the reply
331 	 * \param id the parameter id to enumerate
332 	 * \param start the start index or 0 for the first param
333 	 * \param num the maximum number of params to retrieve
334 	 * \param filter a param filter or NULL
335 	 */
336 	int (*enum_params) (void *object, int seq,
337 			uint32_t id, uint32_t start, uint32_t num,
338 			const struct spa_pod *filter);
339 
340 	/**
341 	 * Set a parameter on the stream
342 	 *
343 	 * \param id the parameter id to set
344 	 * \param flags extra parameter flags
345 	 * \param param the parameter to set
346 	 */
347 	int (*set_param) (void *object, uint32_t id, uint32_t flags,
348 			  const struct spa_pod *param);
349 };
350 
351 #define pw_endpoint_stream_method(o,method,version,...)		\
352 ({									\
353 	int _res = -ENOTSUP;						\
354 	spa_interface_call_res((struct spa_interface*)o,		\
355 			struct pw_endpoint_stream_methods, _res,	\
356 			method, version, ##__VA_ARGS__);		\
357 	_res;								\
358 })
359 
360 #define pw_endpoint_stream_add_listener(c,...)		pw_endpoint_stream_method(c,add_listener,0,__VA_ARGS__)
361 #define pw_endpoint_stream_subscribe_params(c,...)	pw_endpoint_stream_method(c,subscribe_params,0,__VA_ARGS__)
362 #define pw_endpoint_stream_enum_params(c,...)		pw_endpoint_stream_method(c,enum_params,0,__VA_ARGS__)
363 #define pw_endpoint_stream_set_param(c,...)		pw_endpoint_stream_method(c,set_param,0,__VA_ARGS__)
364 
365 /* Endpoint Link */
366 
367 #define PW_ENDPOINT_LINK_EVENT_INFO		0
368 #define PW_ENDPOINT_LINK_EVENT_PARAM		1
369 #define PW_ENDPOINT_LINK_EVENT_NUM		2
370 
371 struct pw_endpoint_link_events {
372 #define PW_VERSION_ENDPOINT_LINK_EVENTS	0
373 	uint32_t version;			/**< version of this structure */
374 
375 	/**
376 	 * Notify endpoint link info
377 	 *
378 	 * \param info info about the endpoint link
379 	 */
380 	void (*info) (void *object, const struct pw_endpoint_link_info *info);
381 
382 	/**
383 	 * Notify a endpoint link param
384 	 *
385 	 * Event emitted as a result of the enum_params method.
386 	 *
387 	 * \param seq the sequence number of the request
388 	 * \param id the param id
389 	 * \param index the param index
390 	 * \param next the param index of the next param
391 	 * \param param the parameter
392 	 */
393 	void (*param) (void *object, int seq,
394 		       uint32_t id, uint32_t index, uint32_t next,
395 		       const struct spa_pod *param);
396 };
397 
398 #define PW_ENDPOINT_LINK_METHOD_ADD_LISTENER		0
399 #define PW_ENDPOINT_LINK_METHOD_SUBSCRIBE_PARAMS	1
400 #define PW_ENDPOINT_LINK_METHOD_ENUM_PARAMS		2
401 #define PW_ENDPOINT_LINK_METHOD_SET_PARAM		3
402 #define PW_ENDPOINT_LINK_METHOD_REQUEST_STATE		4
403 #define PW_ENDPOINT_LINK_METHOD_DESTROY			5
404 #define PW_ENDPOINT_LINK_METHOD_NUM			6
405 
406 struct pw_endpoint_link_methods {
407 #define PW_VERSION_ENDPOINT_LINK_METHODS	0
408 	uint32_t version;			/**< version of this structure */
409 
410 	int (*add_listener) (void *object,
411 			struct spa_hook *listener,
412 			const struct pw_endpoint_link_events *events,
413 			void *data);
414 
415 	/**
416 	 * Subscribe to parameter changes
417 	 *
418 	 * Automatically emit param events for the given ids when
419 	 * they are changed.
420 	 *
421 	 * \param ids an array of param ids
422 	 * \param n_ids the number of ids in \a ids
423 	 */
424 	int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids);
425 
426 	/**
427 	 * Enumerate link parameters
428 	 *
429 	 * Start enumeration of link parameters. For each param, a
430 	 * param event will be emitted.
431 	 *
432 	 * \param seq a sequence number returned in the reply
433 	 * \param id the parameter id to enumerate
434 	 * \param start the start index or 0 for the first param
435 	 * \param num the maximum number of params to retrieve
436 	 * \param filter a param filter or NULL
437 	 */
438 	int (*enum_params) (void *object, int seq,
439 			uint32_t id, uint32_t start, uint32_t num,
440 			const struct spa_pod *filter);
441 
442 	/**
443 	 * Set a parameter on the link
444 	 *
445 	 * \param id the parameter id to set
446 	 * \param flags extra parameter flags
447 	 * \param param the parameter to set
448 	 */
449 	int (*set_param) (void *object, uint32_t id, uint32_t flags,
450 			  const struct spa_pod *param);
451 
452 	int (*request_state) (void *object, enum pw_endpoint_link_state state);
453 };
454 
455 #define pw_endpoint_link_method(o,method,version,...)			\
456 ({									\
457 	int _res = -ENOTSUP;						\
458 	spa_interface_call_res((struct spa_interface*)o,		\
459 			struct pw_endpoint_link_methods, _res,		\
460 			method, version, ##__VA_ARGS__);		\
461 	_res;								\
462 })
463 
464 #define pw_endpoint_link_add_listener(c,...)		pw_endpoint_link_method(c,add_listener,0,__VA_ARGS__)
465 #define pw_endpoint_link_subscribe_params(c,...)	pw_endpoint_link_method(c,subscribe_params,0,__VA_ARGS__)
466 #define pw_endpoint_link_enum_params(c,...)		pw_endpoint_link_method(c,enum_params,0,__VA_ARGS__)
467 #define pw_endpoint_link_set_param(c,...)		pw_endpoint_link_method(c,set_param,0,__VA_ARGS__)
468 #define pw_endpoint_link_request_state(c,...)		pw_endpoint_link_method(c,request_state,0,__VA_ARGS__)
469 
470 
471 /**
472  * \}
473  */
474 
475 #ifdef __cplusplus
476 }  /* extern "C" */
477 #endif
478 
479 #endif /* PIPEWIRE_EXT_SESSION_MANAGER_INTERFACES_H */
480