PipeWire: core.h Source File

PipeWire 0.3.34

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
54 #define PW_TYPE_INTERFACE_Core PW_TYPE_INFO_INTERFACE_BASE "Core"
55 #define PW_TYPE_INTERFACE_Registry PW_TYPE_INFO_INTERFACE_BASE "Registry"
56
57 #define PW_VERSION_CORE 3
58 struct pw_core;
59 #define PW_VERSION_REGISTRY 3
60 struct pw_registry;
61
63 #define PW_DEFAULT_REMOTE "pipewire-0"
64
66 #define PW_ID_CORE 0
67
68 /* invalid ID that matches any object when used for permissions */
69 #define PW_ID_ANY (uint32_t)(0xffffffff)
70
73 struct pw_core_info {
74 uint32_t id;
75 uint32_t cookie;
76 const char *user_name;
77 const char *host_name;
78 const char *version;
79 const char *name;
80 #define PW_CORE_CHANGE_MASK_PROPS (1 << 0)
81 #define PW_CORE_CHANGE_MASK_ALL ((1 << 1)-1)
82 uint64_t change_mask;
83 struct spa_dict *props;
84 };
85
86 #include <pipewire/context.h>
87 #include <pipewire/properties.h>
88 #include <pipewire/proxy.h>
89
91 struct pw_core_info *
92 pw_core_info_update(struct pw_core_info *info,
93 const struct pw_core_info *update);
94
96 void pw_core_info_free(struct pw_core_info *info);
97
100 #define PW_CORE_EVENT_INFO 0
101 #define PW_CORE_EVENT_DONE 1
102 #define PW_CORE_EVENT_PING 2
103 #define PW_CORE_EVENT_ERROR 3
104 #define PW_CORE_EVENT_REMOVE_ID 4
105 #define PW_CORE_EVENT_BOUND_ID 5
106 #define PW_CORE_EVENT_ADD_MEM 6
107 #define PW_CORE_EVENT_REMOVE_MEM 7
108 #define PW_CORE_EVENT_NUM 8
109
114 struct pw_core_events {
115 #define PW_VERSION_CORE_EVENTS 0
116 uint32_t version;
117
126 void (*info) (void *object, const struct pw_core_info *info);
135 void (*done) (void *object, uint32_t id, int seq);
136
142 void (*ping) (void *object, uint32_t id, int seq);
143
161 void (*error) (void *object, uint32_t id, int seq, int res, const char *message);
173 void (*remove_id) (void *object, uint32_t id);
174
185 void (*bound_id) (void *object, uint32_t id, uint32_t global_id);
186
201 void (*add_mem) (void *object, uint32_t id, uint32_t type, int fd, uint32_t flags);
202
208 void (*remove_mem) (void *object, uint32_t id);
209 };
210
211 #define PW_CORE_METHOD_ADD_LISTENER 0
212 #define PW_CORE_METHOD_HELLO 1
213 #define PW_CORE_METHOD_SYNC 2
214 #define PW_CORE_METHOD_PONG 3
215 #define PW_CORE_METHOD_ERROR 4
216 #define PW_CORE_METHOD_GET_REGISTRY 5
217 #define PW_CORE_METHOD_CREATE_OBJECT 6
218 #define PW_CORE_METHOD_DESTROY 7
219 #define PW_CORE_METHOD_NUM 8
220
229 struct pw_core_methods {
230 #define PW_VERSION_CORE_METHODS 0
231 uint32_t version;
232
233 int (*add_listener) (void *object,
234 struct spa_hook *listener,
235 const struct pw_core_events *events,
236 void *data);
242 int (*hello) (void *object, uint32_t version);
254 int (*sync) (void *object, uint32_t id, int seq);
262 int (*pong) (void *object, uint32_t id, int seq);
279 int (*error) (void *object, uint32_t id, int seq, int res, const char *message);
288 struct pw_registry * (*get_registry) (void *object, uint32_t version,
289 size_t user_data_size);
290
300 void * (*create_object) (void *object,
301 const char *factory_name,
302 const char *type,
303 uint32_t version,
304 const struct spa_dict *props,
305 size_t user_data_size);
313 int (*destroy) (void *object, void *proxy);
314 };
315
316 #define pw_core_method(o,method,version,...) \
317 ({ \
318 int _res = -ENOTSUP; \
319 spa_interface_call_res((struct spa_interface*)o, \
320 struct pw_core_methods, _res, \
321 method, version, ##__VA_ARGS__); \
322 _res; \
323 })
324
325 #define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__)
326 #define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__)
327 #define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__)
328 #define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__)
329 #define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__)
330
331
332 static inline
333 SPA_PRINTF_FUNC(5, 0) int
334 pw_core_errorv(struct pw_core *core, uint32_t id, int seq,
335 int res, const char *message, va_list args)
336 {
337 char buffer[1024];
338 vsnprintf(buffer, sizeof(buffer), message, args);
339 buffer[1023] = '\0';
340 return pw_core_error(core, id, seq, res, buffer);
341 }
342
343 static inline
344 SPA_PRINTF_FUNC(5, 6) int
345 pw_core_errorf(struct pw_core *core, uint32_t id, int seq,
346 int res, const char *message, ...)
347 {
348 va_list args;
349 int r;
350 va_start(args, message);
351 r = pw_core_errorv(core, id, seq, res, message, args);
352 va_end(args);
353 return r;
354 }
355
356 static inline struct pw_registry *
357 pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
358 {
359 struct pw_registry *res = NULL;
360 spa_interface_call_res((struct spa_interface*)core,
361 struct pw_core_methods, res,
362 get_registry, 0, version, user_data_size);
363 return res;
364 }
365
366 static inline void *
367 pw_core_create_object(struct pw_core *core,
368 const char *factory_name,
369 const char *type,
370 uint32_t version,
371 const struct spa_dict *props,
372 size_t user_data_size)
373 {
374 void *res = NULL;
375 spa_interface_call_res((struct spa_interface*)core,
376 struct pw_core_methods, res,
377 create_object, 0, factory_name,
378 type, version, props, user_data_size);
379 return res;
380 }
381
382 #define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__)
383
423 #define PW_REGISTRY_EVENT_GLOBAL 0
424 #define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1
425 #define PW_REGISTRY_EVENT_NUM 2
426
428 struct pw_registry_events {
429 #define PW_VERSION_REGISTRY_EVENTS 0
430 uint32_t version;
443 void (*global) (void *object, uint32_t id,
444 uint32_t permissions, const char *type, uint32_t version,
445 const struct spa_dict *props);
455 void (*global_remove) (void *object, uint32_t id);
456 };
457
458 #define PW_REGISTRY_METHOD_ADD_LISTENER 0
459 #define PW_REGISTRY_METHOD_BIND 1
460 #define PW_REGISTRY_METHOD_DESTROY 2
461 #define PW_REGISTRY_METHOD_NUM 3
462
464 struct pw_registry_methods {
465 #define PW_VERSION_REGISTRY_METHODS 0
466 uint32_t version;
467
468 int (*add_listener) (void *object,
469 struct spa_hook *listener,
470 const struct pw_registry_events *events,
471 void *data);
484 void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
485 size_t use_data_size);
486
494 int (*destroy) (void *object, uint32_t id);
495 };
496
497 #define pw_registry_method(o,method,version,...) \
498 ({ \
499 int _res = -ENOTSUP; \
500 spa_interface_call_res((struct spa_interface*)o, \
501 struct pw_registry_methods, _res, \
502 method, version, ##__VA_ARGS__); \
503 _res; \
504 })
505
507 #define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__)
508
509 static inline void *
510 pw_registry_bind(struct pw_registry *registry,
511 uint32_t id, const char *type, uint32_t version,
512 size_t user_data_size)
513 {
514 void *res = NULL;
515 spa_interface_call_res((struct spa_interface*)registry,
516 struct pw_registry_methods, res,
517 bind, 0, id, type, version, user_data_size);
518 return res;
519 }
520
521 #define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__)
522
542 struct pw_core *
543 pw_context_connect(struct pw_context *context,
544 struct pw_properties *properties,
545 size_t user_data_size);
546
557 struct pw_core *
558 pw_context_connect_fd(struct pw_context *context,
559 int fd,
560 struct pw_properties *properties,
561 size_t user_data_size);
562
571 struct pw_core *
572 pw_context_connect_self(struct pw_context *context,
573 struct pw_properties *properties,
574 size_t user_data_size);
575
578 int pw_core_steal_fd(struct pw_core *core);
579
582 int pw_core_set_paused(struct pw_core *core, bool paused);
583
585 int pw_core_disconnect(struct pw_core *core);
586
589 void *pw_core_get_user_data(struct pw_core *core);
590
593 struct pw_client * pw_core_get_client(struct pw_core *core);
594
596 struct pw_context * pw_core_get_context(struct pw_core *core);
597
599 const struct pw_properties *pw_core_get_properties(struct pw_core *core);
600
604 int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict);
605
607 struct pw_mempool * pw_core_get_mempool(struct pw_core *core);
608
610 struct pw_proxy *pw_core_find_proxy(struct pw_core *core, uint32_t id);
611
613 struct pw_proxy *pw_core_export(struct pw_core *core,
614 const char *type,
615 const struct spa_dict *props,
616 void *object,
617 size_t user_data_size );
618
623 #ifdef __cplusplus
624 }
625 #endif
626
627 #endif /* PIPEWIRE_CORE_H */
context.h
pw_core_error
#define pw_core_error(c,...)
Definition: core.h:329
pw_context_connect
struct pw_core * pw_context_connect(struct pw_context *context, struct pw_properties *properties, size_t user_data_size)
Connect to a PipeWire instance.
Definition: core.c:401
pw_context_connect_self
struct pw_core * pw_context_connect_self(struct pw_context *context, struct pw_properties *properties, size_t user_data_size)
Connect to a given PipeWire instance.
Definition: core.c:453
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:262
pw_core_get_user_data
void * pw_core_get_user_data(struct pw_core *core)
Get the user_data.
Definition: core.c:161
pw_core_get_mempool
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
Get the core mempool object.
Definition: core.c:482
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_core_update_properties
int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict)
Update the core properties.
Definition: core.c:143
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:268
pw_core_disconnect
int pw_core_disconnect(struct pw_core *core)
disconnect and destroy a core
Definition: core.c:488
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:467
pw_context_connect_fd
struct pw_core * pw_context_connect_fd(struct pw_context *context, int fd, struct pw_properties *properties, size_t user_data_size)
Connect to a PipeWire instance on the given socket.
Definition: core.c:428
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:131
pw_core_get_properties
const struct pw_properties * pw_core_get_properties(struct pw_core *core)
Get properties from the core.
Definition: core.c:137
pw_core_set_paused
int pw_core_set_paused(struct pw_core *core, bool paused)
Pause or resume the core.
Definition: core.c:475
pw_core_info_free
void pw_core_info_free(struct pw_core_info *info)
Free a pw_core_info
Definition: introspect.c:156
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:274
spa_interface_call_res
#define spa_interface_call_res(iface, method_type, res, method, vers,...)
Invoke method named method in the callbacks on the given interface object.
Definition: hook.h:208
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:205
hook.h
props
const char * props
Definition: media-session.c:2382
properties.h
proxy.h
buffer
Definition: filter.c:59
data
user data to add to an object
Definition: filter.c:75
pw_core_events
Core events.
Definition: core.h:114
pw_core_events::error
void(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:161
pw_core_events::remove_mem
void(* remove_mem)(void *object, uint32_t id)
Remove memory for a client.
Definition: core.h:208
pw_core_events::done
void(* done)(void *object, uint32_t id, int seq)
Emit a done event.
Definition: core.h:135
pw_core_events::version
uint32_t version
Definition: core.h:116
pw_core_events::remove_id
void(* remove_id)(void *object, uint32_t id)
Remove an object ID.
Definition: core.h:173
pw_core_events::info
void(* info)(void *object, const struct pw_core_info *info)
Notify new core info.
Definition: core.h:126
pw_core_events::ping
void(* ping)(void *object, uint32_t id, int seq)
Emit a ping event.
Definition: core.h:142
pw_core_events::bound_id
void(* bound_id)(void *object, uint32_t id, uint32_t global_id)
Notify an object binding.
Definition: core.h:185
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:201
pw_core_info
The core information.
Definition: core.h:73
pw_core_info::props
struct spa_dict * props
extra properties
Definition: core.h:83
pw_core_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition: core.h:82
pw_core_info::version
const char * version
version of the core
Definition: core.h:78
pw_core_info::cookie
uint32_t cookie
a random cookie for identifying this instance of PipeWire
Definition: core.h:75
pw_core_info::id
uint32_t id
id of the global
Definition: core.h:74
pw_core_info::user_name
const char * user_name
name of the user that started the core
Definition: core.h:76
pw_core_info::host_name
const char * host_name
name of the machine the core is running on
Definition: core.h:77
pw_core_info::name
const char * name
name of the core
Definition: core.h:79
pw_core_methods
Core methods.
Definition: core.h:229
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:233
pw_core_methods::pong
int(* pong)(void *object, uint32_t id, int seq)
Reply to a server ping event.
Definition: core.h:262
pw_core_methods::destroy
int(* destroy)(void *object, void *proxy)
Destroy an resource.
Definition: core.h:313
pw_core_methods::hello
int(* hello)(void *object, uint32_t version)
Start a conversation with the server.
Definition: core.h:242
pw_core_methods::error
int(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:279
pw_core_methods::version
uint32_t version
Definition: core.h:231
pw_mempool
A memory pool is a collection of pw_memblocks.
Definition: pipewire/src/pipewire/mem.h:72
pw_properties
Definition: properties.h:49
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition: properties.h:50
pw_registry_events
Registry events.
Definition: core.h:428
pw_registry_events::global_remove
void(* global_remove)(void *object, uint32_t id)
Notify of a global object removal.
Definition: core.h:455
pw_registry_events::version
uint32_t version
Definition: core.h:430
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:443
pw_registry_methods
Registry methods.
Definition: core.h:464
pw_registry_methods::version
uint32_t version
Definition: core.h:466
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:468
pw_registry_methods::destroy
int(* destroy)(void *object, uint32_t id)
Attempt to destroy a global object.
Definition: core.h:494
registry
Definition: pipewire.c:76
spa_dict
Definition: utils/dict.h:48
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:295
spa_interface
Definition: hook.h:146
sync
Definition: media-session.c:119