PipeWire 1.2.6

Loading...
Searching...
No Matches
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_CORE_PERM_MASK PW_PERM_R|PW_PERM_X|PW_PERM_M
38
39#define PW_VERSION_CORE 4
40 struct pw_core;
41#define PW_VERSION_REGISTRY 3
42 struct pw_registry;
43
45#define PW_DEFAULT_REMOTE "pipewire-0"
46
48#define PW_ID_CORE 0
49
50/* invalid ID that matches any object when used for permissions */
51#define PW_ID_ANY (uint32_t)(0xffffffff)
52
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
74 struct pw_core_info *
75 pw_core_info_update(struct pw_core_info *info,
76 const struct pw_core_info *update);
79 struct pw_core_info *
80 pw_core_info_merge(struct pw_core_info *info,
81 const struct pw_core_info *update, bool reset);
83 void pw_core_info_free(struct pw_core_info *info);
84
87#define PW_CORE_EVENT_INFO 0
88#define PW_CORE_EVENT_DONE 1
89#define PW_CORE_EVENT_PING 2
90#define PW_CORE_EVENT_ERROR 3
91#define PW_CORE_EVENT_REMOVE_ID 4
92#define PW_CORE_EVENT_BOUND_ID 5
93#define PW_CORE_EVENT_ADD_MEM 6
94#define PW_CORE_EVENT_REMOVE_MEM 7
95#define PW_CORE_EVENT_BOUND_PROPS 8
96#define PW_CORE_EVENT_NUM 9
97
101 struct pw_core_events {
102#define PW_VERSION_CORE_EVENTS 1
103 uint32_t version;
104
113 void (*info) (void *data, const struct pw_core_info *info);
122 void (*done) (void *data, uint32_t id, int seq);
123
129 void (*ping) (void *data, uint32_t id, int seq);
130
148 void (*error) (void *data, uint32_t id, int seq, int res, const char *message);
160 void (*remove_id) (void *data, uint32_t id);
161
175 void (*bound_id) (void *data, uint32_t id, uint32_t global_id);
176
191 void (*add_mem) (void *data, uint32_t id, uint32_t type, int fd, uint32_t flags);
192
198 void (*remove_mem) (void *data, uint32_t id);
199
215 void (*bound_props) (void *data, uint32_t id, uint32_t global_id, const struct spa_dict *props);
216};
217
218#define PW_CORE_METHOD_ADD_LISTENER 0
219#define PW_CORE_METHOD_HELLO 1
220#define PW_CORE_METHOD_SYNC 2
221#define PW_CORE_METHOD_PONG 3
222#define PW_CORE_METHOD_ERROR 4
223#define PW_CORE_METHOD_GET_REGISTRY 5
224#define PW_CORE_METHOD_CREATE_OBJECT 6
225#define PW_CORE_METHOD_DESTROY 7
226#define PW_CORE_METHOD_NUM 8
227
236 struct pw_core_methods {
237#define PW_VERSION_CORE_METHODS 0
238 uint32_t version;
239
240 int (*add_listener) (void *object,
241 struct spa_hook *listener,
242 const struct pw_core_events *events,
243 void *data);
251 int (*hello) (void *object, uint32_t version);
265 int (*sync) (void *object, uint32_t id, int seq);
275 int (*pong) (void *object, uint32_t id, int seq);
294 int (*error) (void *object, uint32_t id, int seq, int res, const char *message);
305 struct pw_registry * (*get_registry) (void *object, uint32_t version,
306 size_t user_data_size);
307
319 void * (*create_object) (void *object,
320 const char *factory_name,
321 const char *type,
322 uint32_t version,
323 const struct spa_dict *props,
324 size_t user_data_size);
334 int (*destroy) (void *object, void *proxy);
335};
336
337#define pw_core_method(o,method,version,...) \
338({ \
339 int _res = -ENOTSUP; \
340 spa_interface_call_res((struct spa_interface*)o, \
341 struct pw_core_methods, _res, \
342 method, version, ##__VA_ARGS__); \
343 _res; \
344})
345
346#define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__)
347#define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__)
348#define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__)
349#define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__)
350#define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__)
351
352
353 static inline
354 SPA_PRINTF_FUNC(5, 0) int
355 pw_core_errorv(struct pw_core *core, uint32_t id, int seq,
356 int res, const char *message, va_list args)
357{
358 char buffer[1024];
359 vsnprintf(buffer, sizeof(buffer), message, args);
360 buffer[1023] = '\0';
361 return pw_core_error(core, id, seq, res, buffer);
362}
363
364 static inline
365 SPA_PRINTF_FUNC(5, 6) int
366 pw_core_errorf(struct pw_core *core, uint32_t id, int seq,
367 int res, const char *message, ...)
368{
369 va_list args;
370 int r;
371 va_start(args, message);
372 r = pw_core_errorv(core, id, seq, res, message, args);
373 va_end(args);
374 return r;
375}
376
377 static inline struct pw_registry *
378 pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
379{
380 struct pw_registry *res = NULL;
381 spa_interface_call_res((struct spa_interface*)core,
382 struct pw_core_methods, res,
383 get_registry, 0, version, user_data_size);
384 return res;
385}
386
387 static inline void *
388 pw_core_create_object(struct pw_core *core,
389 const char *factory_name,
390 const char *type,
391 uint32_t version,
392 const struct spa_dict *props,
393 size_t user_data_size)
394{
395 void *res = NULL;
396 spa_interface_call_res((struct spa_interface*)core,
397 struct pw_core_methods, res,
398 create_object, 0, factory_name,
399 type, version, props, user_data_size);
400 return res;
401}
402
403#define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__)
404
444#define PW_REGISTRY_EVENT_GLOBAL 0
445#define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1
446#define PW_REGISTRY_EVENT_NUM 2
447
449 struct pw_registry_events {
450#define PW_VERSION_REGISTRY_EVENTS 0
451 uint32_t version;
464 void (*global) (void *data, uint32_t id,
465 uint32_t permissions, const char *type, uint32_t version,
466 const struct spa_dict *props);
476 void (*global_remove) (void *data, uint32_t id);
477};
478
479#define PW_REGISTRY_METHOD_ADD_LISTENER 0
480#define PW_REGISTRY_METHOD_BIND 1
481#define PW_REGISTRY_METHOD_DESTROY 2
482#define PW_REGISTRY_METHOD_NUM 3
483
485 struct pw_registry_methods {
486#define PW_VERSION_REGISTRY_METHODS 0
487 uint32_t version;
488
489 int (*add_listener) (void *object,
490 struct spa_hook *listener,
491 const struct pw_registry_events *events,
492 void *data);
505 void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
506 size_t use_data_size);
507
516 int (*destroy) (void *object, uint32_t id);
517};
518
519#define pw_registry_method(o,method,version,...) \
520({ \
521 int _res = -ENOTSUP; \
522 spa_interface_call_res((struct spa_interface*)o, \
523 struct pw_registry_methods, _res, \
524 method, version, ##__VA_ARGS__); \
525 _res; \
526})
527
529#define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__)
530
531 static inline void *
532 pw_registry_bind(struct pw_registry *registry,
533 uint32_t id, const char *type, uint32_t version,
534 size_t user_data_size)
535{
536 void *res = NULL;
537 spa_interface_call_res((struct spa_interface*)registry,
538 struct pw_registry_methods, res,
539 bind, 0, id, type, version, user_data_size);
540 return res;
541}
542
543#define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__)
544
564 struct pw_core *
565 pw_context_connect(struct pw_context *context,
566 struct pw_properties *properties,
567 size_t user_data_size);
568
579 struct pw_core *
580 pw_context_connect_fd(struct pw_context *context,
581 int fd,
582 struct pw_properties *properties,
583 size_t user_data_size);
584
593 struct pw_core *
594 pw_context_connect_self(struct pw_context *context,
595 struct pw_properties *properties,
596 size_t user_data_size);
597
600 int pw_core_steal_fd(struct pw_core *core);
601
604 int pw_core_set_paused(struct pw_core *core, bool paused);
605
607 int pw_core_disconnect(struct pw_core *core);
608
611 void *pw_core_get_user_data(struct pw_core *core);
612
615 struct pw_client * pw_core_get_client(struct pw_core *core);
616
618 struct pw_context * pw_core_get_context(struct pw_core *core);
619
621 const struct pw_properties *pw_core_get_properties(struct pw_core *core);
622
626 int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict);
627
629 struct pw_mempool * pw_core_get_mempool(struct pw_core *core);
630
632 struct pw_proxy *pw_core_find_proxy(struct pw_core *core, uint32_t id);
633
635 struct pw_proxy *pw_core_export(struct pw_core *core,
636 const char *type,
637 const struct spa_dict *props,
638 void *object,
639 size_t user_data_size );
640
645#ifdef __cplusplus
646}
647#endif
648
649#endif /* PIPEWIRE_CORE_H */
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:126
pw_core_errorf
static int pw_core_errorf(struct pw_core *core, uint32_t id, int seq, int res, const char *message,...)
Definition core.h:414
pw_core_errorv
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:403
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:263
pw_core_error
#define pw_core_error(c,...)
Fatal error event.
Definition core.h:396
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:394
pw_core_get_mempool
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
Get the core mempool object.
Definition core.c:475
pw_core_get_properties
const struct pw_properties * pw_core_get_properties(struct pw_core *core)
Get properties from the core.
Definition core.c:132
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:446
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:257
pw_core_get_user_data
void * pw_core_get_user_data(struct pw_core *core)
Get the user_data.
Definition core.c:156
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:138
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:269
pw_core_disconnect
int pw_core_disconnect(struct pw_core *core)
disconnect and destroy a core
Definition core.c:481
pw_core_create_object
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:436
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:460
pw_core_get_registry
static struct pw_registry * pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
Definition core.h:426
pw_core_set_paused
int pw_core_set_paused(struct pw_core *core, bool paused)
Pause or resume the core.
Definition core.c:468
pw_core_info_free
void pw_core_info_free(struct pw_core_info *info)
Free a pw_core_info
Definition introspect.c:146
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:421
pw_core_info_merge
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:108
pw_core_info_update
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:139
pw_registry_bind
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:593
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:251
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition defs.h:295
hook.h
spa/utils/hook.h
properties.h
pipewire/properties.h
proxy.h
pipewire/proxy.h
context.h
pipewire/context.h
pw_client
pw_context
pw_core_events
Core events.
Definition core.h:128
pw_core_events::ping
void(* ping)(void *data, uint32_t id, int seq)
Emit a ping event.
Definition core.h:157
pw_core_events::remove_mem
void(* remove_mem)(void *data, uint32_t id)
Remove memory for a client.
Definition core.h:226
pw_core_events::error
void(* error)(void *data, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition core.h:176
pw_core_events::add_mem
void(* add_mem)(void *data, uint32_t id, uint32_t type, int fd, uint32_t flags)
Add memory for a client.
Definition core.h:219
pw_core_events::bound_props
void(* bound_props)(void *data, uint32_t id, uint32_t global_id, const struct spa_dict *props)
Notify an object binding.
Definition core.h:243
pw_core_events::info
void(* info)(void *data, const struct pw_core_info *info)
Notify new core info.
Definition core.h:141
pw_core_events::remove_id
void(* remove_id)(void *data, uint32_t id)
Remove an object ID.
Definition core.h:188
pw_core_events::version
uint32_t version
Definition core.h:131
pw_core_events::bound_id
void(* bound_id)(void *data, uint32_t id, uint32_t global_id)
Notify an object binding.
Definition core.h:203
pw_core_events::done
void(* done)(void *data, uint32_t id, int seq)
Emit a done event.
Definition core.h:150
pw_core_info
The core information.
Definition core.h:70
pw_core_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition core.h:81
pw_core_info::version
const char * version
version of the core
Definition core.h:75
pw_core_info::cookie
uint32_t cookie
a random cookie for identifying this instance of PipeWire
Definition core.h:72
pw_core_info::id
uint32_t id
id of the global
Definition core.h:71
pw_core_info::user_name
const char * user_name
name of the user that started the core
Definition core.h:73
pw_core_info::host_name
const char * host_name
name of the machine the core is running on
Definition core.h:74
pw_core_methods
Core methods.
Definition core.h:273
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:278
pw_core_methods::pong
int(* pong)(void *object, uint32_t id, int seq)
Reply to a server ping event.
Definition core.h:313
pw_core_methods::destroy
int(* destroy)(void *object, void *proxy)
Destroy an resource.
Definition core.h:372
pw_core_methods::hello
int(* hello)(void *object, uint32_t version)
Start a conversation with the server.
Definition core.h:289
pw_core_methods::error
int(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition core.h:332
pw_core_methods::sync
int(* sync)(void *object, uint32_t id, int seq)
Do server roundtrip.
Definition core.h:303
pw_core_methods::version
uint32_t version
Definition core.h:276
pw_core
pw_mempool
A memory pool is a collection of pw_memblocks.
Definition mem.h:58
pw_properties
Definition properties.h:34
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition properties.h:35
pw_proxy
pw_registry_events
Registry events.
Definition core.h:502
pw_registry_events::global_remove
void(* global_remove)(void *data, uint32_t id)
Notify of a global object removal.
Definition core.h:530
pw_registry_events::global
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:518
pw_registry_events::version
uint32_t version
Definition core.h:505
pw_registry_methods
Registry methods.
Definition core.h:543
pw_registry_methods::version
uint32_t version
Definition core.h:546
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:548
pw_registry_methods::destroy
int(* destroy)(void *object, uint32_t id)
Attempt to destroy a global object.
Definition core.h:575
pw_registry
spa_dict
Definition dict.h:39
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition hook.h:350
spa_interface
Definition hook.h:138