PipeWire: core.h Source File

PipeWire 0.3.26

core.h
Go to the documentation of this file.
1 /* PipeWire
2 *
3 * Copyright © 2018 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef PIPEWIRE_CORE_H
26 #define PIPEWIRE_CORE_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #include <stdarg.h>
33 #include <errno.h>
34
35 #include <spa/utils/hook.h>
36
37 #define PW_TYPE_INTERFACE_Core PW_TYPE_INFO_INTERFACE_BASE "Core"
38 #define PW_TYPE_INTERFACE_Registry PW_TYPE_INFO_INTERFACE_BASE "Registry"
39
40 #define PW_VERSION_CORE 3
41 struct pw_core;
42 #define PW_VERSION_REGISTRY 3
43 struct pw_registry;
44
45 /* the default remote name to connect to */
46 #define PW_DEFAULT_REMOTE "pipewire-0"
47
48 /* default ID for the core object after connect */
49 #define PW_ID_CORE 0
50
51 /* invalid ID that matches any object when used for permissions */
52 #define PW_ID_ANY (uint32_t)(0xffffffff)
53
55 struct pw_core_info {
56 uint32_t id;
57 uint32_t cookie;
58 const char *user_name;
59 const char *host_name;
60 const char *version;
61 const char *name;
62 #define PW_CORE_CHANGE_MASK_PROPS (1 << 0)
63 #define PW_CORE_CHANGE_MASK_ALL ((1 << 1)-1)
64 uint64_t change_mask;
65 struct spa_dict *props;
66 };
67
68 #include <pipewire/context.h>
69 #include <pipewire/properties.h>
70 #include <pipewire/proxy.h>
71
73 struct pw_core_info *
74 pw_core_info_update(struct pw_core_info *info,
75 const struct pw_core_info *update);
76
78 void pw_core_info_free(struct pw_core_info *info);
79
91 #define PW_CORE_EVENT_INFO 0
92 #define PW_CORE_EVENT_DONE 1
93 #define PW_CORE_EVENT_PING 2
94 #define PW_CORE_EVENT_ERROR 3
95 #define PW_CORE_EVENT_REMOVE_ID 4
96 #define PW_CORE_EVENT_BOUND_ID 5
97 #define PW_CORE_EVENT_ADD_MEM 6
98 #define PW_CORE_EVENT_REMOVE_MEM 7
99 #define PW_CORE_EVENT_NUM 8
100
105 struct pw_core_events {
106 #define PW_VERSION_CORE_EVENTS 0
107 uint32_t version;
108
117 void (*info) (void *object, const struct pw_core_info *info);
126 void (*done) (void *object, uint32_t id, int seq);
127
133 void (*ping) (void *object, uint32_t id, int seq);
134
152 void (*error) (void *object, uint32_t id, int seq, int res, const char *message);
164 void (*remove_id) (void *object, uint32_t id);
165
176 void (*bound_id) (void *object, uint32_t id, uint32_t global_id);
177
192 void (*add_mem) (void *object, uint32_t id, uint32_t type, int fd, uint32_t flags);
193
199 void (*remove_mem) (void *object, uint32_t id);
200 };
201
202 #define PW_CORE_METHOD_ADD_LISTENER 0
203 #define PW_CORE_METHOD_HELLO 1
204 #define PW_CORE_METHOD_SYNC 2
205 #define PW_CORE_METHOD_PONG 3
206 #define PW_CORE_METHOD_ERROR 4
207 #define PW_CORE_METHOD_GET_REGISTRY 5
208 #define PW_CORE_METHOD_CREATE_OBJECT 6
209 #define PW_CORE_METHOD_DESTROY 7
210 #define PW_CORE_METHOD_NUM 8
211
220 struct pw_core_methods {
221 #define PW_VERSION_CORE_METHODS 0
222 uint32_t version;
223
224 int (*add_listener) (void *object,
225 struct spa_hook *listener,
226 const struct pw_core_events *events,
227 void *data);
233 int (*hello) (void *object, uint32_t version);
245 int (*sync) (void *object, uint32_t id, int seq);
253 int (*pong) (void *object, uint32_t id, int seq);
270 int (*error) (void *object, uint32_t id, int seq, int res, const char *message);
279 struct pw_registry * (*get_registry) (void *object, uint32_t version,
280 size_t user_data_size);
281
291 void * (*create_object) (void *object,
292 const char *factory_name,
293 const char *type,
294 uint32_t version,
295 const struct spa_dict *props,
296 size_t user_data_size);
304 int (*destroy) (void *object, void *proxy);
305 };
306
307 #define pw_core_method(o,method,version,...) \
308 ({ \
309 int _res = -ENOTSUP; \
310 spa_interface_call_res((struct spa_interface*)o, \
311 struct pw_core_methods, _res, \
312 method, version, ##__VA_ARGS__); \
313 _res; \
314 })
315
316 #define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__)
317 #define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__)
318 #define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__)
319 #define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__)
320 #define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__)
321
322
323 static inline
324 SPA_PRINTF_FUNC(5, 0) int
325 pw_core_errorv(struct pw_core *core, uint32_t id, int seq,
326 int res, const char *message, va_list args)
327 {
328 char buffer[1024];
329 vsnprintf(buffer, sizeof(buffer), message, args);
330 buffer[1023] = '\0';
331 return pw_core_error(core, id, seq, res, buffer);
332 }
333
334 static inline
335 SPA_PRINTF_FUNC(5, 6) int
336 pw_core_errorf(struct pw_core *core, uint32_t id, int seq,
337 int res, const char *message, ...)
338 {
339 va_list args;
340 int r;
341 va_start(args, message);
342 r = pw_core_errorv(core, id, seq, res, message, args);
343 va_end(args);
344 return r;
345 }
346
347 static inline struct pw_registry *
348 pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
349 {
350 struct pw_registry *res = NULL;
351 spa_interface_call_res((struct spa_interface*)core,
352 struct pw_core_methods, res,
353 get_registry, 0, version, user_data_size);
354 return res;
355 }
356
357 static inline void *
358 pw_core_create_object(struct pw_core *core,
359 const char *factory_name,
360 const char *type,
361 uint32_t version,
362 const struct spa_dict *props,
363 size_t user_data_size)
364 {
365 void *res = NULL;
366 spa_interface_call_res((struct spa_interface*)core,
367 struct pw_core_methods, res,
368 create_object, 0, factory_name,
369 type, version, props, user_data_size);
370 return res;
371 }
372
373 #define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__)
374
407 #define PW_REGISTRY_EVENT_GLOBAL 0
408 #define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1
409 #define PW_REGISTRY_EVENT_NUM 2
410
412 struct pw_registry_events {
413 #define PW_VERSION_REGISTRY_EVENTS 0
414 uint32_t version;
427 void (*global) (void *object, uint32_t id,
428 uint32_t permissions, const char *type, uint32_t version,
429 const struct spa_dict *props);
439 void (*global_remove) (void *object, uint32_t id);
440 };
441
442 #define PW_REGISTRY_METHOD_ADD_LISTENER 0
443 #define PW_REGISTRY_METHOD_BIND 1
444 #define PW_REGISTRY_METHOD_DESTROY 2
445 #define PW_REGISTRY_METHOD_NUM 3
446
448 struct pw_registry_methods {
449 #define PW_VERSION_REGISTRY_METHODS 0
450 uint32_t version;
451
452 int (*add_listener) (void *object,
453 struct spa_hook *listener,
454 const struct pw_registry_events *events,
455 void *data);
468 void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
469 size_t use_data_size);
470
478 int (*destroy) (void *object, uint32_t id);
479 };
480
481 #define pw_registry_method(o,method,version,...) \
482 ({ \
483 int _res = -ENOTSUP; \
484 spa_interface_call_res((struct spa_interface*)o, \
485 struct pw_registry_methods, _res, \
486 method, version, ##__VA_ARGS__); \
487 _res; \
488 })
489
491 #define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__)
492
493 static inline void *
494 pw_registry_bind(struct pw_registry *registry,
495 uint32_t id, const char *type, uint32_t version,
496 size_t user_data_size)
497 {
498 void *res = NULL;
499 spa_interface_call_res((struct spa_interface*)registry,
500 struct pw_registry_methods, res,
501 bind, 0, id, type, version, user_data_size);
502 return res;
503 }
504
505 #define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__)
506
507
511 struct pw_core *
512 pw_context_connect(struct pw_context *context,
513 struct pw_properties *properties,
515 size_t user_data_size );
516
521 struct pw_core *
522 pw_context_connect_fd(struct pw_context *context,
523 int fd,
524 struct pw_properties *properties,
526 size_t user_data_size );
527
530 struct pw_core *
531 pw_context_connect_self(struct pw_context *context,
532 struct pw_properties *properties,
534 size_t user_data_size );
535
538 int pw_core_steal_fd(struct pw_core *core);
539
542 int pw_core_set_paused(struct pw_core *core, bool paused);
543
545 int pw_core_disconnect(struct pw_core *core);
546
549 void *pw_core_get_user_data(struct pw_core *core);
550
553 struct pw_client * pw_core_get_client(struct pw_core *core);
554
556 struct pw_context * pw_core_get_context(struct pw_core *core);
557
559 const struct pw_properties *pw_core_get_properties(struct pw_core *core);
560
564 int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict);
565
567 struct pw_mempool * pw_core_get_mempool(struct pw_core *core);
568
570 struct pw_proxy *pw_core_find_proxy(struct pw_core *core, uint32_t id);
571
573 struct pw_proxy *pw_core_export(struct pw_core *core,
574 const char *type,
575 const struct spa_dict *props,
576 void *object,
577 size_t user_data_size );
578
579
580 #ifdef __cplusplus
581 }
582 #endif
583
584 #endif /* PIPEWIRE_CORE_H */
pw_context
the PipeWire context
pw_introspect::pw_core_info_free
void pw_core_info_free(struct pw_core_info *info)
Free a pw_core_info.
Definition: introspect.c:156
pw_introspect::pw_core_info_update
struct pw_core_info * pw_core_info_update(struct pw_core_info *info, const struct pw_core_info *update)
Update and existing pw_core_info with update.
Definition: introspect.c:127
pw_proxy
Represents an object on the client side.
context.h
pw_context_connect_self
SPA_EXPORT struct pw_core * pw_context_connect_self(struct pw_context *context, struct pw_properties *properties, size_t user_data_size)
Definition: core.c:457
pw_context_connect_fd
SPA_EXPORT struct pw_core * pw_context_connect_fd(struct pw_context *context, int fd, struct pw_properties *properties, size_t user_data_size)
Definition: core.c:432
pw_context_connect
SPA_EXPORT struct pw_core * pw_context_connect(struct pw_context *context, struct pw_properties *properties, size_t user_data_size)
Definition: core.c:405
args
static uint32_t int int const char va_list args
Definition: core.h:327
pw_core_error
#define pw_core_error(c,...)
Definition: core.h:320
va_end
va_end(args)
message
static uint32_t int int const char * message
Definition: core.h:326
res
static uint32_t int int res
Definition: core.h:326
pw_core_get_client
struct pw_client * pw_core_get_client(struct pw_core *core)
Get the client proxy of the connected core.
Definition: core.c:265
pw_core_get_user_data
void * pw_core_get_user_data(struct pw_core *core)
Get the user_data.
Definition: core.c:164
pw_core_get_mempool
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
Get the core mempool object.
Definition: core.c:486
vsnprintf
vsnprintf(buffer, sizeof(buffer), message, args)
pw_core_update_properties
int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict)
Update the core properties.
Definition: core.c:146
pw_core_find_proxy
struct pw_proxy * pw_core_find_proxy(struct pw_core *core, uint32_t id)
Get the proxy with the given id.
Definition: core.c:271
pw_core_disconnect
int pw_core_disconnect(struct pw_core *core)
disconnect and destroy a core
Definition: core.c:492
pw_core_steal_fd
int pw_core_steal_fd(struct pw_core *core)
Steal the fd of the core connection or < 0 on error.
Definition: core.c:471
pw_core_get_context
struct pw_context * pw_core_get_context(struct pw_core *core)
Get the context object used to created this core.
Definition: core.c:134
r
static uint32_t int int const char int r
Definition: core.h:338
pw_core_get_properties
const struct pw_properties * pw_core_get_properties(struct pw_core *core)
Get properties from the core.
Definition: core.c:140
pw_core_set_paused
int pw_core_set_paused(struct pw_core *core, bool paused)
Pause or resume the core.
Definition: core.c:479
seq
static uint32_t int seq
Definition: core.h:325
id
static uint32_t id
Definition: core.h:325
va_start
va_start(args, message)
pw_core_export
struct pw_proxy * pw_core_export(struct pw_core *core, const char *type, const struct spa_dict *props, void *object, size_t user_data_size)
Export an object into the PipeWire instance associated with core.
Definition: core.c:277
properties.h
proxy.h
buffer
Definition: filter.c:58
data
Definition: filter.c:74
pw_core_events
Core events.
Definition: core.h:105
pw_core_events::error
void(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:152
pw_core_events::remove_mem
void(* remove_mem)(void *object, uint32_t id)
Remove memory for a client.
Definition: core.h:199
pw_core_events::done
void(* done)(void *object, uint32_t id, int seq)
Emit a done event.
Definition: core.h:126
pw_core_events::version
uint32_t version
Definition: core.h:107
pw_core_events::remove_id
void(* remove_id)(void *object, uint32_t id)
Remove an object ID.
Definition: core.h:164
pw_core_events::info
void(* info)(void *object, const struct pw_core_info *info)
Notify new core info.
Definition: core.h:117
pw_core_events::ping
void(* ping)(void *object, uint32_t id, int seq)
Emit a ping event.
Definition: core.h:133
pw_core_events::bound_id
void(* bound_id)(void *object, uint32_t id, uint32_t global_id)
Notify an object binding.
Definition: core.h:176
pw_core_events::add_mem
void(* add_mem)(void *object, uint32_t id, uint32_t type, int fd, uint32_t flags)
Add memory for a client.
Definition: core.h:192
pw_core_info
The core information.
Definition: core.h:55
pw_core_info::props
struct spa_dict * props
extra properties
Definition: core.h:65
pw_core_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition: core.h:64
pw_core_info::version
const char * version
version of the core
Definition: core.h:60
pw_core_info::cookie
uint32_t cookie
a random cookie for identifying this instance of PipeWire
Definition: core.h:57
pw_core_info::id
uint32_t id
id of the global
Definition: core.h:56
pw_core_info::user_name
const char * user_name
name of the user that started the core
Definition: core.h:58
pw_core_info::host_name
const char * host_name
name of the machine the core is running on
Definition: core.h:59
pw_core_info::name
const char * name
name of the core
Definition: core.h:61
pw_core_methods
Core methods.
Definition: core.h:220
pw_core_methods::add_listener
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_core_events *events, void *data)
Definition: core.h:224
pw_core_methods::pong
int(* pong)(void *object, uint32_t id, int seq)
Reply to a server ping event.
Definition: core.h:253
pw_core_methods::destroy
int(* destroy)(void *object, void *proxy)
Destroy an resource.
Definition: core.h:304
pw_core_methods::hello
int(* hello)(void *object, uint32_t version)
Start a conversation with the server.
Definition: core.h:233
pw_core_methods::error
int(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:270
pw_core_methods::sync
int(* sync)(void *object, uint32_t id, int seq)
Do server roundtrip.
Definition: core.h:245
pw_core_methods::version
uint32_t version
Definition: core.h:222
pw_mempool
Definition: mem.h:63
pw_properties
A collection of key/value pairs.
Definition: properties.h:45
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition: properties.h:46
pw_registry_events
Registry events.
Definition: core.h:412
pw_registry_events::global_remove
void(* global_remove)(void *object, uint32_t id)
Notify of a global object removal.
Definition: core.h:439
pw_registry_events::version
uint32_t version
Definition: core.h:414
pw_registry_events::global
void(* global)(void *object, uint32_t id, uint32_t permissions, const char *type, uint32_t version, const struct spa_dict *props)
Notify of a new global object.
Definition: core.h:427
pw_registry_methods
Registry methods.
Definition: core.h:448
pw_registry_methods::version
uint32_t version
Definition: core.h:450
pw_registry_methods::add_listener
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_registry_events *events, void *data)
Definition: core.h:452
pw_registry_methods::destroy
int(* destroy)(void *object, uint32_t id)
Attempt to destroy a global object.
Definition: core.h:478
registry
Definition: pipewire.c:72