PipeWire  0.3.59
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>
88 #include <pipewire/proxy.h>
89 
91 struct pw_core_info *
93  const struct pw_core_info *update);
95 struct pw_core_info *
96 pw_core_info_merge(struct pw_core_info *info,
97  const struct pw_core_info *update, bool reset);
99 void pw_core_info_free(struct pw_core_info *info);
100 
103 #define PW_CORE_EVENT_INFO 0
104 #define PW_CORE_EVENT_DONE 1
105 #define PW_CORE_EVENT_PING 2
106 #define PW_CORE_EVENT_ERROR 3
107 #define PW_CORE_EVENT_REMOVE_ID 4
108 #define PW_CORE_EVENT_BOUND_ID 5
109 #define PW_CORE_EVENT_ADD_MEM 6
110 #define PW_CORE_EVENT_REMOVE_MEM 7
111 #define PW_CORE_EVENT_NUM 8
112 
116 struct pw_core_events {
117 #define PW_VERSION_CORE_EVENTS 0
118  uint32_t version;
119 
128  void (*info) (void *data, const struct pw_core_info *info);
137  void (*done) (void *data, uint32_t id, int seq);
138 
144  void (*ping) (void *data, uint32_t id, int seq);
145 
163  void (*error) (void *data, uint32_t id, int seq, int res, const char *message);
175  void (*remove_id) (void *data, uint32_t id);
176 
187  void (*bound_id) (void *data, uint32_t id, uint32_t global_id);
188 
203  void (*add_mem) (void *data, uint32_t id, uint32_t type, int fd, uint32_t flags);
204 
210  void (*remove_mem) (void *data, uint32_t id);
211 };
212 
213 #define PW_CORE_METHOD_ADD_LISTENER 0
214 #define PW_CORE_METHOD_HELLO 1
215 #define PW_CORE_METHOD_SYNC 2
216 #define PW_CORE_METHOD_PONG 3
217 #define PW_CORE_METHOD_ERROR 4
218 #define PW_CORE_METHOD_GET_REGISTRY 5
219 #define PW_CORE_METHOD_CREATE_OBJECT 6
220 #define PW_CORE_METHOD_DESTROY 7
221 #define PW_CORE_METHOD_NUM 8
222 
231 struct pw_core_methods {
232 #define PW_VERSION_CORE_METHODS 0
233  uint32_t version;
234 
235  int (*add_listener) (void *object,
236  struct spa_hook *listener,
237  const struct pw_core_events *events,
238  void *data);
244  int (*hello) (void *object, uint32_t version);
256  int (*sync) (void *object, uint32_t id, int seq);
264  int (*pong) (void *object, uint32_t id, int seq);
281  int (*error) (void *object, uint32_t id, int seq, int res, const char *message);
290  struct pw_registry * (*get_registry) (void *object, uint32_t version,
291  size_t user_data_size);
292 
302  void * (*create_object) (void *object,
303  const char *factory_name,
304  const char *type,
305  uint32_t version,
306  const struct spa_dict *props,
307  size_t user_data_size);
315  int (*destroy) (void *object, void *proxy);
316 };
317 
318 #define pw_core_method(o,method,version,...) \
319 ({ \
320  int _res = -ENOTSUP; \
321  spa_interface_call_res((struct spa_interface*)o, \
322  struct pw_core_methods, _res, \
323  method, version, ##__VA_ARGS__); \
324  _res; \
325 })
326 
327 #define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__)
328 #define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__)
329 #define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__)
330 #define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__)
331 #define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__)
332 
333 
334 static inline
335 SPA_PRINTF_FUNC(5, 0) int
336 pw_core_errorv(struct pw_core *core, uint32_t id, int seq,
337  int res, const char *message, va_list args)
338 {
339  char buffer[1024];
340  vsnprintf(buffer, sizeof(buffer), message, args);
341  buffer[1023] = '\0';
342  return pw_core_error(core, id, seq, res, buffer);
343 }
344 
345 static inline
346 SPA_PRINTF_FUNC(5, 6) int
347 pw_core_errorf(struct pw_core *core, uint32_t id, int seq,
348  int res, const char *message, ...)
349 {
350  va_list args;
351  int r;
352  va_start(args, message);
353  r = pw_core_errorv(core, id, seq, res, message, args);
354  va_end(args);
355  return r;
356 }
357 
358 static inline struct pw_registry *
359 pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
360 {
361  struct pw_registry *res = NULL;
363  struct pw_core_methods, res,
364  get_registry, 0, version, user_data_size);
365  return res;
366 }
367 
368 static inline void *
369 pw_core_create_object(struct pw_core *core,
370  const char *factory_name,
371  const char *type,
372  uint32_t version,
373  const struct spa_dict *props,
374  size_t user_data_size)
375 {
376  void *res = NULL;
378  struct pw_core_methods, res,
379  create_object, 0, factory_name,
380  type, version, props, user_data_size);
381  return res;
382 }
383 
384 #define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__)
385 
425 #define PW_REGISTRY_EVENT_GLOBAL 0
426 #define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1
427 #define PW_REGISTRY_EVENT_NUM 2
428 
430 struct pw_registry_events {
431 #define PW_VERSION_REGISTRY_EVENTS 0
432  uint32_t version;
445  void (*global) (void *data, uint32_t id,
446  uint32_t permissions, const char *type, uint32_t version,
447  const struct spa_dict *props);
457  void (*global_remove) (void *data, uint32_t id);
458 };
459 
460 #define PW_REGISTRY_METHOD_ADD_LISTENER 0
461 #define PW_REGISTRY_METHOD_BIND 1
462 #define PW_REGISTRY_METHOD_DESTROY 2
463 #define PW_REGISTRY_METHOD_NUM 3
464 
466 struct pw_registry_methods {
467 #define PW_VERSION_REGISTRY_METHODS 0
468  uint32_t version;
469 
470  int (*add_listener) (void *object,
471  struct spa_hook *listener,
472  const struct pw_registry_events *events,
473  void *data);
486  void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
487  size_t use_data_size);
488 
496  int (*destroy) (void *object, uint32_t id);
497 };
498 
499 #define pw_registry_method(o,method,version,...) \
500 ({ \
501  int _res = -ENOTSUP; \
502  spa_interface_call_res((struct spa_interface*)o, \
503  struct pw_registry_methods, _res, \
504  method, version, ##__VA_ARGS__); \
505  _res; \
506 })
507 
509 #define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__)
510 
511 static inline void *
512 pw_registry_bind(struct pw_registry *registry,
513  uint32_t id, const char *type, uint32_t version,
514  size_t user_data_size)
515 {
516  void *res = NULL;
518  struct pw_registry_methods, res,
519  bind, 0, id, type, version, user_data_size);
520  return res;
521 }
522 
523 #define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__)
524 
544 struct pw_core *
545 pw_context_connect(struct pw_context *context,
546  struct pw_properties *properties,
547  size_t user_data_size);
548 
559 struct pw_core *
560 pw_context_connect_fd(struct pw_context *context,
561  int fd,
562  struct pw_properties *properties,
563  size_t user_data_size);
564 
573 struct pw_core *
574 pw_context_connect_self(struct pw_context *context,
575  struct pw_properties *properties,
576  size_t user_data_size);
577 
580 int pw_core_steal_fd(struct pw_core *core);
581 
584 int pw_core_set_paused(struct pw_core *core, bool paused);
585 
587 int pw_core_disconnect(struct pw_core *core);
588 
591 void *pw_core_get_user_data(struct pw_core *core);
592 
595 struct pw_client * pw_core_get_client(struct pw_core *core);
596 
598 struct pw_context * pw_core_get_context(struct pw_core *core);
599 
601 const struct pw_properties *pw_core_get_properties(struct pw_core *core);
602 
606 int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict);
607 
609 struct pw_mempool * pw_core_get_mempool(struct pw_core *core);
610 
612 struct pw_proxy *pw_core_find_proxy(struct pw_core *core, uint32_t id);
613 
615 struct pw_proxy *pw_core_export(struct pw_core *core,
616  const char *type,
617  const struct spa_dict *props,
618  void *object,
619  size_t user_data_size );
620 
625 #ifdef __cplusplus
626 }
627 #endif
628 
629 #endif /* PIPEWIRE_CORE_H */
pipewire/context.h
static int pw_core_errorf(struct pw_core *core, uint32_t id, int seq, int res, const char *message,...)
Definition: core.h:393
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:382
#define pw_core_error(c,...)
Fatal error event.
Definition: core.h:375
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:415
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:402
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:454
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:127
struct pw_client * pw_core_get_client(struct pw_core *core)
Get the client proxy of the connected core.
Definition: core.c:263
void * pw_core_get_user_data(struct pw_core *core)
Get the user_data.
Definition: core.c:162
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
Get the core mempool object.
Definition: core.c:483
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:158
int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict)
Update the core properties.
Definition: core.c:144
struct pw_proxy * pw_core_find_proxy(struct pw_core *core, uint32_t id)
Get the proxy with the given id.
Definition: core.c:269
int pw_core_disconnect(struct pw_core *core)
disconnect and destroy a core
Definition: core.c:489
int pw_core_steal_fd(struct pw_core *core)
Steal the fd of the core connection or < 0 on error.
Definition: core.c:468
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:429
struct pw_context * pw_core_get_context(struct pw_core *core)
Get the context object used to created this core.
Definition: core.c:132
const struct pw_properties * pw_core_get_properties(struct pw_core *core)
Get properties from the core.
Definition: core.c:138
int pw_core_set_paused(struct pw_core *core, bool paused)
Pause or resume the core.
Definition: core.c:476
void pw_core_info_free(struct pw_core_info *info)
Free a pw_core_info
Definition: introspect.c:165
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:275
static struct pw_registry * pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
Definition: core.h:405
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:571
#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:255
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:289
spa/utils/hook.h
pipewire/properties.h
pipewire/proxy.h
Core events.
Definition: core.h:141
void(* ping)(void *data, uint32_t id, int seq)
Emit a ping event.
Definition: core.h:170
void(* remove_mem)(void *data, uint32_t id)
Remove memory for a client.
Definition: core.h:236
void(* error)(void *data, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:189
void(* add_mem)(void *data, uint32_t id, uint32_t type, int fd, uint32_t flags)
Add memory for a client.
Definition: core.h:229
void(* info)(void *data, const struct pw_core_info *info)
Notify new core info.
Definition: core.h:154
void(* remove_id)(void *data, uint32_t id)
Remove an object ID.
Definition: core.h:201
uint32_t version
Definition: core.h:144
void(* bound_id)(void *data, uint32_t id, uint32_t global_id)
Notify an object binding.
Definition: core.h:213
void(* done)(void *data, uint32_t id, int seq)
Emit a done event.
Definition: core.h:163
The core information.
Definition: core.h:87
uint64_t change_mask
bitfield of changed fields since last call
Definition: core.h:98
const char * version
version of the core
Definition: core.h:92
uint32_t cookie
a random cookie for identifying this instance of PipeWire
Definition: core.h:89
uint32_t id
id of the global
Definition: core.h:88
const char * user_name
name of the user that started the core
Definition: core.h:90
const char * host_name
name of the machine the core is running on
Definition: core.h:91
Core methods.
Definition: core.h:266
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_core_events *events, void *data)
Definition: core.h:271
int(* pong)(void *object, uint32_t id, int seq)
Reply to a server ping event.
Definition: core.h:300
int(* destroy)(void *object, void *proxy)
Destroy an resource.
Definition: core.h:351
int(* hello)(void *object, uint32_t version)
Start a conversation with the server.
Definition: core.h:280
int(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:317
int(* sync)(void *object, uint32_t id, int seq)
Do server roundtrip.
Definition: core.h:292
uint32_t version
Definition: core.h:269
A memory pool is a collection of pw_memblocks.
Definition: mem.h:77
Definition: properties.h:53
struct spa_dict dict
dictionary of key/values
Definition: properties.h:54
Registry events.
Definition: core.h:481
void(* global_remove)(void *data, uint32_t id)
Notify of a global object removal.
Definition: core.h:509
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:497
uint32_t version
Definition: core.h:484
Registry methods.
Definition: core.h:522
uint32_t version
Definition: core.h:525
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_registry_events *events, void *data)
Definition: core.h:527
int(* destroy)(void *object, uint32_t id)
Attempt to destroy a global object.
Definition: core.h:553
Definition: dict.h:59
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:351
Definition: hook.h:158