PipeWire  0.3.76
core.h
Go to the documentation of this file.
1 /* PipeWire */
2 /* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4 
5 #ifndef PIPEWIRE_CORE_H
6 #define PIPEWIRE_CORE_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <stdarg.h>
13 #include <errno.h>
14 
15 #include <spa/utils/hook.h>
16 
34 #define PW_TYPE_INTERFACE_Core PW_TYPE_INFO_INTERFACE_BASE "Core"
35 #define PW_TYPE_INTERFACE_Registry PW_TYPE_INFO_INTERFACE_BASE "Registry"
36 
37 #define PW_VERSION_CORE 4
38 struct pw_core;
39 #define PW_VERSION_REGISTRY 3
40 struct pw_registry;
41 
43 #define PW_DEFAULT_REMOTE "pipewire-0"
44 
46 #define PW_ID_CORE 0
47 
48 /* invalid ID that matches any object when used for permissions */
49 #define PW_ID_ANY (uint32_t)(0xffffffff)
50 
53 struct pw_core_info {
54  uint32_t id;
55  uint32_t cookie;
56  const char *user_name;
57  const char *host_name;
58  const char *version;
59  const char *name;
60 #define PW_CORE_CHANGE_MASK_PROPS (1 << 0)
61 #define PW_CORE_CHANGE_MASK_ALL ((1 << 1)-1)
62  uint64_t change_mask;
63  struct spa_dict *props;
64 };
65 
66 #include <pipewire/context.h>
68 #include <pipewire/proxy.h>
69 
71 struct pw_core_info *
73  const struct pw_core_info *update);
75 struct pw_core_info *
76 pw_core_info_merge(struct pw_core_info *info,
77  const struct pw_core_info *update, bool reset);
79 void pw_core_info_free(struct pw_core_info *info);
80 
83 #define PW_CORE_EVENT_INFO 0
84 #define PW_CORE_EVENT_DONE 1
85 #define PW_CORE_EVENT_PING 2
86 #define PW_CORE_EVENT_ERROR 3
87 #define PW_CORE_EVENT_REMOVE_ID 4
88 #define PW_CORE_EVENT_BOUND_ID 5
89 #define PW_CORE_EVENT_ADD_MEM 6
90 #define PW_CORE_EVENT_REMOVE_MEM 7
91 #define PW_CORE_EVENT_BOUND_PROPS 8
92 #define PW_CORE_EVENT_NUM 9
93 
97 struct pw_core_events {
98 #define PW_VERSION_CORE_EVENTS 1
99  uint32_t version;
100 
109  void (*info) (void *data, const struct pw_core_info *info);
118  void (*done) (void *data, uint32_t id, int seq);
119 
125  void (*ping) (void *data, uint32_t id, int seq);
126 
144  void (*error) (void *data, uint32_t id, int seq, int res, const char *message);
156  void (*remove_id) (void *data, uint32_t id);
157 
168  void (*bound_id) (void *data, uint32_t id, uint32_t global_id);
169 
184  void (*add_mem) (void *data, uint32_t id, uint32_t type, int fd, uint32_t flags);
185 
191  void (*remove_mem) (void *data, uint32_t id);
192 
193  void (*bound_props) (void *data, uint32_t id, uint32_t global_id, const struct spa_dict *props);
194 };
195 
196 #define PW_CORE_METHOD_ADD_LISTENER 0
197 #define PW_CORE_METHOD_HELLO 1
198 #define PW_CORE_METHOD_SYNC 2
199 #define PW_CORE_METHOD_PONG 3
200 #define PW_CORE_METHOD_ERROR 4
201 #define PW_CORE_METHOD_GET_REGISTRY 5
202 #define PW_CORE_METHOD_CREATE_OBJECT 6
203 #define PW_CORE_METHOD_DESTROY 7
204 #define PW_CORE_METHOD_NUM 8
205 
214 struct pw_core_methods {
215 #define PW_VERSION_CORE_METHODS 0
216  uint32_t version;
217 
218  int (*add_listener) (void *object,
219  struct spa_hook *listener,
220  const struct pw_core_events *events,
221  void *data);
227  int (*hello) (void *object, uint32_t version);
239  int (*sync) (void *object, uint32_t id, int seq);
247  int (*pong) (void *object, uint32_t id, int seq);
264  int (*error) (void *object, uint32_t id, int seq, int res, const char *message);
273  struct pw_registry * (*get_registry) (void *object, uint32_t version,
274  size_t user_data_size);
275 
285  void * (*create_object) (void *object,
286  const char *factory_name,
287  const char *type,
288  uint32_t version,
289  const struct spa_dict *props,
290  size_t user_data_size);
298  int (*destroy) (void *object, void *proxy);
299 };
300 
301 #define pw_core_method(o,method,version,...) \
302 ({ \
303  int _res = -ENOTSUP; \
304  spa_interface_call_res((struct spa_interface*)o, \
305  struct pw_core_methods, _res, \
306  method, version, ##__VA_ARGS__); \
307  _res; \
308 })
309 
310 #define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__)
311 #define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__)
312 #define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__)
313 #define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__)
314 #define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__)
315 
316 
317 static inline
318 SPA_PRINTF_FUNC(5, 0) int
319 pw_core_errorv(struct pw_core *core, uint32_t id, int seq,
320  int res, const char *message, va_list args)
321 {
322  char buffer[1024];
323  vsnprintf(buffer, sizeof(buffer), message, args);
324  buffer[1023] = '\0';
325  return pw_core_error(core, id, seq, res, buffer);
326 }
327 
328 static inline
329 SPA_PRINTF_FUNC(5, 6) int
330 pw_core_errorf(struct pw_core *core, uint32_t id, int seq,
331  int res, const char *message, ...)
332 {
333  va_list args;
334  int r;
335  va_start(args, message);
336  r = pw_core_errorv(core, id, seq, res, message, args);
337  va_end(args);
338  return r;
339 }
340 
341 static inline struct pw_registry *
342 pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
343 {
344  struct pw_registry *res = NULL;
346  struct pw_core_methods, res,
347  get_registry, 0, version, user_data_size);
348  return res;
349 }
350 
351 static inline void *
353  const char *factory_name,
354  const char *type,
355  uint32_t version,
356  const struct spa_dict *props,
357  size_t user_data_size)
358 {
359  void *res = NULL;
361  struct pw_core_methods, res,
362  create_object, 0, factory_name,
363  type, version, props, user_data_size);
364  return res;
365 }
366 
367 #define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__)
368 
408 #define PW_REGISTRY_EVENT_GLOBAL 0
409 #define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1
410 #define PW_REGISTRY_EVENT_NUM 2
411 
413 struct pw_registry_events {
414 #define PW_VERSION_REGISTRY_EVENTS 0
415  uint32_t version;
428  void (*global) (void *data, uint32_t id,
429  uint32_t permissions, const char *type, uint32_t version,
430  const struct spa_dict *props);
440  void (*global_remove) (void *data, uint32_t id);
441 };
442 
443 #define PW_REGISTRY_METHOD_ADD_LISTENER 0
444 #define PW_REGISTRY_METHOD_BIND 1
445 #define PW_REGISTRY_METHOD_DESTROY 2
446 #define PW_REGISTRY_METHOD_NUM 3
447 
449 struct pw_registry_methods {
450 #define PW_VERSION_REGISTRY_METHODS 0
451  uint32_t version;
452 
453  int (*add_listener) (void *object,
454  struct spa_hook *listener,
455  const struct pw_registry_events *events,
456  void *data);
469  void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
470  size_t use_data_size);
471 
479  int (*destroy) (void *object, uint32_t id);
480 };
481 
482 #define pw_registry_method(o,method,version,...) \
483 ({ \
484  int _res = -ENOTSUP; \
485  spa_interface_call_res((struct spa_interface*)o, \
486  struct pw_registry_methods, _res, \
487  method, version, ##__VA_ARGS__); \
488  _res; \
489 })
490 
492 #define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__)
493 
494 static inline void *
495 pw_registry_bind(struct pw_registry *registry,
496  uint32_t id, const char *type, uint32_t version,
497  size_t user_data_size)
498 {
499  void *res = NULL;
500  spa_interface_call_res((struct spa_interface*)registry,
501  struct pw_registry_methods, res,
502  bind, 0, id, type, version, user_data_size);
503  return res;
504 }
505 
506 #define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__)
507 
527 struct pw_core *
528 pw_context_connect(struct pw_context *context,
529  struct pw_properties *properties,
530  size_t user_data_size);
531 
542 struct pw_core *
543 pw_context_connect_fd(struct pw_context *context,
544  int fd,
545  struct pw_properties *properties,
546  size_t user_data_size);
547 
556 struct pw_core *
557 pw_context_connect_self(struct pw_context *context,
558  struct pw_properties *properties,
559  size_t user_data_size);
560 
563 int pw_core_steal_fd(struct pw_core *core);
564 
567 int pw_core_set_paused(struct pw_core *core, bool paused);
568 
570 int pw_core_disconnect(struct pw_core *core);
571 
574 void *pw_core_get_user_data(struct pw_core *core);
575 
578 struct pw_client * pw_core_get_client(struct pw_core *core);
579 
581 struct pw_context * pw_core_get_context(struct pw_core *core);
582 
584 const struct pw_properties *pw_core_get_properties(struct pw_core *core);
585 
589 int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict);
590 
592 struct pw_mempool * pw_core_get_mempool(struct pw_core *core);
593 
595 struct pw_proxy *pw_core_find_proxy(struct pw_core *core, uint32_t id);
596 
598 struct pw_proxy *pw_core_export(struct pw_core *core,
599  const char *type,
600  const struct spa_dict *props,
601  void *object,
602  size_t user_data_size );
603 
608 #ifdef __cplusplus
609 }
610 #endif
611 
612 #endif /* PIPEWIRE_CORE_H */
static int pw_core_errorf(struct pw_core *core, uint32_t id, int seq, int res, const char *message,...)
Definition: core.h:377
static int pw_core_errorv(struct pw_core *core, uint32_t id, int seq, int res, const char *message, va_list args)
Definition: core.h:366
#define pw_core_error(c,...)
Fatal error event.
Definition: core.h:359
static void * pw_core_create_object(struct pw_core *core, const char *factory_name, const char *type, uint32_t version, const struct spa_dict *props, size_t user_data_size)
Definition: core.h:399
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:390
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:442
struct pw_core_info * pw_core_info_merge(struct pw_core_info *info, const struct pw_core_info *update, bool reset)
Update an existing pw_core_info with update.
Definition: introspect.c:107
struct pw_client * pw_core_get_client(struct pw_core *core)
Get the client proxy of the connected core.
Definition: core.c:253
void * pw_core_get_user_data(struct pw_core *core)
Get the user_data.
Definition: core.c:152
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
Get the core mempool object.
Definition: core.c:471
struct pw_core_info * pw_core_info_update(struct pw_core_info *info, const struct pw_core_info *update)
Update an existing pw_core_info with update with reset.
Definition: introspect.c:138
int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict)
Update the core properties.
Definition: core.c:134
struct pw_proxy * pw_core_find_proxy(struct pw_core *core, uint32_t id)
Get the proxy with the given id.
Definition: core.c:259
int pw_core_disconnect(struct pw_core *core)
disconnect and destroy a core
Definition: core.c:477
int pw_core_steal_fd(struct pw_core *core)
Steal the fd of the core connection or < 0 on error.
Definition: core.c:456
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:417
struct pw_context * pw_core_get_context(struct pw_core *core)
Get the context object used to created this core.
Definition: core.c:122
const struct pw_properties * pw_core_get_properties(struct pw_core *core)
Get properties from the core.
Definition: core.c:128
int pw_core_set_paused(struct pw_core *core, bool paused)
Pause or resume the core.
Definition: core.c:464
void pw_core_info_free(struct pw_core_info *info)
Free a pw_core_info
Definition: introspect.c:145
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:265
static struct pw_registry * pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
Definition: core.h:389
static void * pw_registry_bind(struct pw_registry *registry, uint32_t id, const char *type, uint32_t version, size_t user_data_size)
Definition: core.h:555
#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:251
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:273
spa/utils/hook.h
pipewire/properties.h
pipewire/proxy.h
pipewire/context.h
Core events.
Definition: core.h:123
void(* ping)(void *data, uint32_t id, int seq)
Emit a ping event.
Definition: core.h:152
void(* remove_mem)(void *data, uint32_t id)
Remove memory for a client.
Definition: core.h:218
void(* error)(void *data, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:171
void(* add_mem)(void *data, uint32_t id, uint32_t type, int fd, uint32_t flags)
Add memory for a client.
Definition: core.h:211
void(* bound_props)(void *data, uint32_t id, uint32_t global_id, const struct spa_dict *props)
Definition: core.h:220
void(* info)(void *data, const struct pw_core_info *info)
Notify new core info.
Definition: core.h:136
void(* remove_id)(void *data, uint32_t id)
Remove an object ID.
Definition: core.h:183
uint32_t version
Definition: core.h:126
void(* bound_id)(void *data, uint32_t id, uint32_t global_id)
Notify an object binding.
Definition: core.h:195
void(* done)(void *data, uint32_t id, int seq)
Emit a done event.
Definition: core.h:145
The core information.
Definition: core.h:67
uint64_t change_mask
bitfield of changed fields since last call
Definition: core.h:78
const char * version
version of the core
Definition: core.h:72
uint32_t cookie
a random cookie for identifying this instance of PipeWire
Definition: core.h:69
uint32_t id
id of the global
Definition: core.h:68
const char * user_name
name of the user that started the core
Definition: core.h:70
const char * host_name
name of the machine the core is running on
Definition: core.h:71
Core methods.
Definition: core.h:250
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_core_events *events, void *data)
Definition: core.h:255
int(* pong)(void *object, uint32_t id, int seq)
Reply to a server ping event.
Definition: core.h:284
int(* destroy)(void *object, void *proxy)
Destroy an resource.
Definition: core.h:335
int(* hello)(void *object, uint32_t version)
Start a conversation with the server.
Definition: core.h:264
int(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:301
int(* sync)(void *object, uint32_t id, int seq)
Do server roundtrip.
Definition: core.h:276
uint32_t version
Definition: core.h:253
A memory pool is a collection of pw_memblocks.
Definition: src/pipewire/mem.h:57
Definition: properties.h:33
struct spa_dict dict
dictionary of key/values
Definition: properties.h:34
Registry events.
Definition: core.h:465
void(* global_remove)(void *data, uint32_t id)
Notify of a global object removal.
Definition: core.h:493
void(* global)(void *data, 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:481
uint32_t version
Definition: core.h:468
Registry methods.
Definition: core.h:506
uint32_t version
Definition: core.h:509
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_registry_events *events, void *data)
Definition: core.h:511
int(* destroy)(void *object, uint32_t id)
Attempt to destroy a global object.
Definition: core.h:537
Definition: utils/dict.h:39
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:350
Definition: hook.h:138