PipeWire  0.3.29
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 
49 #define PW_TYPE_INTERFACE_Core PW_TYPE_INFO_INTERFACE_BASE "Core"
50 #define PW_TYPE_INTERFACE_Registry PW_TYPE_INFO_INTERFACE_BASE "Registry"
51 
52 #define PW_VERSION_CORE 3
53 struct pw_core;
54 #define PW_VERSION_REGISTRY 3
55 struct pw_registry;
56 
57 /* the default remote name to connect to */
58 #define PW_DEFAULT_REMOTE "pipewire-0"
59 
60 /* default ID for the core object after connect */
61 #define PW_ID_CORE 0
62 
63 /* invalid ID that matches any object when used for permissions */
64 #define PW_ID_ANY (uint32_t)(0xffffffff)
65 
67 struct pw_core_info {
68  uint32_t id;
69  uint32_t cookie;
70  const char *user_name;
71  const char *host_name;
72  const char *version;
73  const char *name;
74 #define PW_CORE_CHANGE_MASK_PROPS (1 << 0)
75 #define PW_CORE_CHANGE_MASK_ALL ((1 << 1)-1)
76  uint64_t change_mask;
77  struct spa_dict *props;
78 };
79 
80 #include <pipewire/context.h>
81 #include <pipewire/properties.h>
82 #include <pipewire/proxy.h>
83 
85 struct pw_core_info *
87  const struct pw_core_info *update);
88 
90 void pw_core_info_free(struct pw_core_info *info);
91 
94 #define PW_CORE_EVENT_INFO 0
95 #define PW_CORE_EVENT_DONE 1
96 #define PW_CORE_EVENT_PING 2
97 #define PW_CORE_EVENT_ERROR 3
98 #define PW_CORE_EVENT_REMOVE_ID 4
99 #define PW_CORE_EVENT_BOUND_ID 5
100 #define PW_CORE_EVENT_ADD_MEM 6
101 #define PW_CORE_EVENT_REMOVE_MEM 7
102 #define PW_CORE_EVENT_NUM 8
103 
109 #define PW_VERSION_CORE_EVENTS 0
110  uint32_t version;
111 
120  void (*info) (void *object, const struct pw_core_info *info);
129  void (*done) (void *object, uint32_t id, int seq);
130 
136  void (*ping) (void *object, uint32_t id, int seq);
137 
155  void (*error) (void *object, uint32_t id, int seq, int res, const char *message);
167  void (*remove_id) (void *object, uint32_t id);
168 
179  void (*bound_id) (void *object, uint32_t id, uint32_t global_id);
180 
195  void (*add_mem) (void *object, uint32_t id, uint32_t type, int fd, uint32_t flags);
196 
202  void (*remove_mem) (void *object, uint32_t id);
203 };
204 
205 #define PW_CORE_METHOD_ADD_LISTENER 0
206 #define PW_CORE_METHOD_HELLO 1
207 #define PW_CORE_METHOD_SYNC 2
208 #define PW_CORE_METHOD_PONG 3
209 #define PW_CORE_METHOD_ERROR 4
210 #define PW_CORE_METHOD_GET_REGISTRY 5
211 #define PW_CORE_METHOD_CREATE_OBJECT 6
212 #define PW_CORE_METHOD_DESTROY 7
213 #define PW_CORE_METHOD_NUM 8
214 
224 #define PW_VERSION_CORE_METHODS 0
225  uint32_t version;
226 
227  int (*add_listener) (void *object,
228  struct spa_hook *listener,
229  const struct pw_core_events *events,
230  void *data);
236  int (*hello) (void *object, uint32_t version);
248  int (*sync) (void *object, uint32_t id, int seq);
256  int (*pong) (void *object, uint32_t id, int seq);
273  int (*error) (void *object, uint32_t id, int seq, int res, const char *message);
282  struct pw_registry * (*get_registry) (void *object, uint32_t version,
283  size_t user_data_size);
284 
294  void * (*create_object) (void *object,
295  const char *factory_name,
296  const char *type,
297  uint32_t version,
298  const struct spa_dict *props,
299  size_t user_data_size);
307  int (*destroy) (void *object, void *proxy);
308 };
309 
310 #define pw_core_method(o,method,version,...) \
311 ({ \
312  int _res = -ENOTSUP; \
313  spa_interface_call_res((struct spa_interface*)o, \
314  struct pw_core_methods, _res, \
315  method, version, ##__VA_ARGS__); \
316  _res; \
317 })
318 
319 #define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__)
320 #define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__)
321 #define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__)
322 #define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__)
323 #define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__)
324 
325 
326 static inline
327 SPA_PRINTF_FUNC(5, 0) int
328 pw_core_errorv(struct pw_core *core, uint32_t id, int seq,
329  int res, const char *message, va_list args)
330 {
331  char buffer[1024];
333  buffer[1023] = '\0';
334  return pw_core_error(core, id, seq, res, buffer);
335 }
336 
337 static inline
338 SPA_PRINTF_FUNC(5, 6) int
339 pw_core_errorf(struct pw_core *core, uint32_t id, int seq,
340  int res, const char *message, ...)
341 {
342  va_list args;
343  int r;
345  r = pw_core_errorv(core, id, seq, res, message, args);
347  return r;
348 }
349 
350 static inline struct pw_registry *
351 pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
352 {
353  struct pw_registry *res = NULL;
355  struct pw_core_methods, res,
356  get_registry, 0, version, user_data_size);
357  return res;
358 }
359 
360 static inline void *
361 pw_core_create_object(struct pw_core *core,
362  const char *factory_name,
363  const char *type,
364  uint32_t version,
365  const struct spa_dict *props,
366  size_t user_data_size)
367 {
368  void *res = NULL;
370  struct pw_core_methods, res,
371  create_object, 0, factory_name,
372  type, version, props, user_data_size);
373  return res;
374 }
375 
376 #define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__)
377 
417 #define PW_REGISTRY_EVENT_GLOBAL 0
418 #define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1
419 #define PW_REGISTRY_EVENT_NUM 2
420 
423 #define PW_VERSION_REGISTRY_EVENTS 0
424  uint32_t version;
437  void (*global) (void *object, uint32_t id,
438  uint32_t permissions, const char *type, uint32_t version,
439  const struct spa_dict *props);
449  void (*global_remove) (void *object, uint32_t id);
450 };
451 
452 #define PW_REGISTRY_METHOD_ADD_LISTENER 0
453 #define PW_REGISTRY_METHOD_BIND 1
454 #define PW_REGISTRY_METHOD_DESTROY 2
455 #define PW_REGISTRY_METHOD_NUM 3
456 
459 #define PW_VERSION_REGISTRY_METHODS 0
460  uint32_t version;
461 
462  int (*add_listener) (void *object,
463  struct spa_hook *listener,
464  const struct pw_registry_events *events,
465  void *data);
478  void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
479  size_t use_data_size);
480 
488  int (*destroy) (void *object, uint32_t id);
489 };
490 
491 #define pw_registry_method(o,method,version,...) \
492 ({ \
493  int _res = -ENOTSUP; \
494  spa_interface_call_res((struct spa_interface*)o, \
495  struct pw_registry_methods, _res, \
496  method, version, ##__VA_ARGS__); \
497  _res; \
498 })
499 
501 #define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__)
502 
503 static inline void *
504 pw_registry_bind(struct pw_registry *registry,
505  uint32_t id, const char *type, uint32_t version,
506  size_t user_data_size)
507 {
508  void *res = NULL;
510  struct pw_registry_methods, res,
511  bind, 0, id, type, version, user_data_size);
512  return res;
513 }
514 
515 #define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__)
516 
529 struct pw_core *
530 pw_context_connect(struct pw_context *context,
531  struct pw_properties *properties,
533  size_t user_data_size );
534 
543 struct pw_core *
544 pw_context_connect_fd(struct pw_context *context,
545  int fd,
546  struct pw_properties *properties,
547  size_t user_data_size);
548 
551 struct pw_core *
552 pw_context_connect_self(struct pw_context *context,
553  struct pw_properties *properties,
555  size_t user_data_size );
556 
559 int pw_core_steal_fd(struct pw_core *core);
560 
563 int pw_core_set_paused(struct pw_core *core, bool paused);
564 
566 int pw_core_disconnect(struct pw_core *core);
567 
570 void *pw_core_get_user_data(struct pw_core *core);
571 
574 struct pw_client * pw_core_get_client(struct pw_core *core);
575 
577 struct pw_context * pw_core_get_context(struct pw_core *core);
578 
580 const struct pw_properties *pw_core_get_properties(struct pw_core *core);
581 
585 int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict);
586 
588 struct pw_mempool * pw_core_get_mempool(struct pw_core *core);
589 
591 struct pw_proxy *pw_core_find_proxy(struct pw_core *core, uint32_t id);
592 
594 struct pw_proxy *pw_core_export(struct pw_core *core,
595  const char *type,
596  const struct spa_dict *props,
597  void *object,
598  size_t user_data_size );
599 
604 #ifdef __cplusplus
605 }
606 #endif
607 
608 #endif /* PIPEWIRE_CORE_H */
static uint32_t int int const char va_list args
Definition: core.h:330
#define pw_core_error(c,...)
Definition: core.h:323
va_end(args)
static uint32_t int int const char * message
Definition: core.h:329
static uint32_t int int res
Definition: core.h:329
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
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
struct pw_client * pw_core_get_client(struct pw_core *core)
Get the client proxy of the connected core.
Definition: core.c:262
void * pw_core_get_user_data(struct pw_core *core)
Get the user_data.
Definition: core.c:161
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
Get the core mempool object.
Definition: core.c:482
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
vsnprintf(buffer, sizeof(buffer), message, args)
int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict)
Update the core properties.
Definition: core.c:143
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
int pw_core_disconnect(struct pw_core *core)
disconnect and destroy a core
Definition: core.c:488
int pw_core_steal_fd(struct pw_core *core)
Steal the fd of the core connection or < 0 on error.
Definition: core.c:467
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
struct pw_context * pw_core_get_context(struct pw_core *core)
Get the context object used to created this core.
Definition: core.c:131
static uint32_t int int const char int r
Definition: core.h:341
const struct pw_properties * pw_core_get_properties(struct pw_core *core)
Get properties from the core.
Definition: core.c:137
int pw_core_set_paused(struct pw_core *core, bool paused)
Pause or resume the core.
Definition: core.c:475
void pw_core_info_free(struct pw_core_info *info)
Free a pw_core_info
Definition: introspect.c:156
static uint32_t int seq
Definition: core.h:328
static uint32_t id
Definition: core.h:328
va_start(args, message)
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
#define spa_interface_call_res(iface, type, res, method, vers,...)
Definition: hook.h:170
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:203
Definition: filter.c:59
Definition: filter.c:75
Core events.
Definition: core.h:108
void(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:155
void(* remove_mem)(void *object, uint32_t id)
Remove memory for a client.
Definition: core.h:202
void(* done)(void *object, uint32_t id, int seq)
Emit a done event.
Definition: core.h:129
uint32_t version
Definition: core.h:110
void(* remove_id)(void *object, uint32_t id)
Remove an object ID.
Definition: core.h:167
void(* info)(void *object, const struct pw_core_info *info)
Notify new core info.
Definition: core.h:120
void(* ping)(void *object, uint32_t id, int seq)
Emit a ping event.
Definition: core.h:136
void(* bound_id)(void *object, uint32_t id, uint32_t global_id)
Notify an object binding.
Definition: core.h:179
void(* add_mem)(void *object, uint32_t id, uint32_t type, int fd, uint32_t flags)
Add memory for a client.
Definition: core.h:195
The core information.
Definition: core.h:67
struct spa_dict * props
extra properties
Definition: core.h:77
uint64_t change_mask
bitfield of changed fields since last call
Definition: core.h:76
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
const char * name
name of the core
Definition: core.h:73
Core methods.
Definition: core.h:223
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_core_events *events, void *data)
Definition: core.h:227
int(* pong)(void *object, uint32_t id, int seq)
Reply to a server ping event.
Definition: core.h:256
int(* destroy)(void *object, void *proxy)
Destroy an resource.
Definition: core.h:307
int(* hello)(void *object, uint32_t version)
Start a conversation with the server.
Definition: core.h:236
int(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:273
int(* sync)(void *object, uint32_t id, int seq)
Do server roundtrip.
Definition: core.h:248
uint32_t version
Definition: core.h:225
A memory pool is a collection of pw_memblocks.
Definition: src/pipewire/mem.h:72
Definition: properties.h:49
struct spa_dict dict
dictionary of key/values
Definition: properties.h:50
Registry events.
Definition: core.h:422
void(* global_remove)(void *object, uint32_t id)
Notify of a global object removal.
Definition: core.h:449
uint32_t version
Definition: core.h:424
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:437
Registry methods.
Definition: core.h:458
uint32_t version
Definition: core.h:460
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_registry_events *events, void *data)
Definition: core.h:462
int(* destroy)(void *object, uint32_t id)
Attempt to destroy a global object.
Definition: core.h:488
Definition: pipewire.c:73
Definition: utils/dict.h:48
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:76
Definition: hook.h:65