PipeWire: core.h Source File

PipeWire 0.3.67

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
9extern "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 3
38struct 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
53struct 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>
67#include <pipewire/properties.h>
68#include <pipewire/proxy.h>
69
71 struct pw_core_info *
72 pw_core_info_update(struct pw_core_info *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);
79void 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_NUM 8
92
96struct pw_core_events {
97#define PW_VERSION_CORE_EVENTS 0
98 uint32_t version;
99
108 void (*info) (void *data, const struct pw_core_info *info);
117 void (*done) (void *data, uint32_t id, int seq);
118
124 void (*ping) (void *data, uint32_t id, int seq);
125
143 void (*error) (void *data, uint32_t id, int seq, int res, const char *message);
155 void (*remove_id) (void *data, uint32_t id);
156
167 void (*bound_id) (void *data, uint32_t id, uint32_t global_id);
168
183 void (*add_mem) (void *data, uint32_t id, uint32_t type, int fd, uint32_t flags);
184
190 void (*remove_mem) (void *data, uint32_t id);
191};
192
193#define PW_CORE_METHOD_ADD_LISTENER 0
194#define PW_CORE_METHOD_HELLO 1
195#define PW_CORE_METHOD_SYNC 2
196#define PW_CORE_METHOD_PONG 3
197#define PW_CORE_METHOD_ERROR 4
198#define PW_CORE_METHOD_GET_REGISTRY 5
199#define PW_CORE_METHOD_CREATE_OBJECT 6
200#define PW_CORE_METHOD_DESTROY 7
201#define PW_CORE_METHOD_NUM 8
202
211struct pw_core_methods {
212#define PW_VERSION_CORE_METHODS 0
213 uint32_t version;
214
215 int (*add_listener) (void *object,
216 struct spa_hook *listener,
217 const struct pw_core_events *events,
218 void *data);
224 int (*hello) (void *object, uint32_t version);
236 int (*sync) (void *object, uint32_t id, int seq);
244 int (*pong) (void *object, uint32_t id, int seq);
261 int (*error) (void *object, uint32_t id, int seq, int res, const char *message);
270 struct pw_registry * (*get_registry) (void *object, uint32_t version,
271 size_t user_data_size);
272
282 void * (*create_object) (void *object,
283 const char *factory_name,
284 const char *type,
285 uint32_t version,
286 const struct spa_dict *props,
287 size_t user_data_size);
295 int (*destroy) (void *object, void *proxy);
296};
297
298#define pw_core_method(o,method,version,...) \
299({ \
300 int _res = -ENOTSUP; \
301 spa_interface_call_res((struct spa_interface*)o, \
302 struct pw_core_methods, _res, \
303 method, version, ##__VA_ARGS__); \
304 _res; \
305})
306
307#define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__)
308#define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__)
309#define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__)
310#define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__)
311#define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__)
312
313
314static inline
315 SPA_PRINTF_FUNC(5, 0) int
316 pw_core_errorv(struct pw_core *core, uint32_t id, int seq,
317 int res, const char *message, va_list args)
318{
319 char buffer[1024];
320 vsnprintf(buffer, sizeof(buffer), message, args);
321 buffer[1023] = '\0';
322 return pw_core_error(core, id, seq, res, buffer);
323}
324
325static inline
326 SPA_PRINTF_FUNC(5, 6) int
327 pw_core_errorf(struct pw_core *core, uint32_t id, int seq,
328 int res, const char *message, ...)
329{
330 va_list args;
331 int r;
332 va_start(args, message);
333 r = pw_core_errorv(core, id, seq, res, message, args);
334 va_end(args);
335 return r;
336}
337
338static inline struct pw_registry *
339 pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
340{
341 struct pw_registry *res = NULL;
342 spa_interface_call_res((struct spa_interface*)core,
343 struct pw_core_methods, res,
344 get_registry, 0, version, user_data_size);
345 return res;
346}
347
348 static inline void *
349 pw_core_create_object(struct pw_core *core,
350 const char *factory_name,
351 const char *type,
352 uint32_t version,
353 const struct spa_dict *props,
354 size_t user_data_size)
355{
356 void *res = NULL;
357 spa_interface_call_res((struct spa_interface*)core,
358 struct pw_core_methods, res,
359 create_object, 0, factory_name,
360 type, version, props, user_data_size);
361 return res;
362}
363
364#define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__)
365
405#define PW_REGISTRY_EVENT_GLOBAL 0
406#define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1
407#define PW_REGISTRY_EVENT_NUM 2
408
410struct pw_registry_events {
411#define PW_VERSION_REGISTRY_EVENTS 0
412 uint32_t version;
425 void (*global) (void *data, uint32_t id,
426 uint32_t permissions, const char *type, uint32_t version,
427 const struct spa_dict *props);
437 void (*global_remove) (void *data, uint32_t id);
438};
439
440#define PW_REGISTRY_METHOD_ADD_LISTENER 0
441#define PW_REGISTRY_METHOD_BIND 1
442#define PW_REGISTRY_METHOD_DESTROY 2
443#define PW_REGISTRY_METHOD_NUM 3
444
446struct pw_registry_methods {
447#define PW_VERSION_REGISTRY_METHODS 0
448 uint32_t version;
449
450 int (*add_listener) (void *object,
451 struct spa_hook *listener,
452 const struct pw_registry_events *events,
453 void *data);
466 void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
467 size_t use_data_size);
468
476 int (*destroy) (void *object, uint32_t id);
477};
478
479#define pw_registry_method(o,method,version,...) \
480({ \
481 int _res = -ENOTSUP; \
482 spa_interface_call_res((struct spa_interface*)o, \
483 struct pw_registry_methods, _res, \
484 method, version, ##__VA_ARGS__); \
485 _res; \
486})
487
489#define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__)
490
491static inline void *
492 pw_registry_bind(struct pw_registry *registry,
493 uint32_t id, const char *type, uint32_t version,
494 size_t user_data_size)
495{
496 void *res = NULL;
497 spa_interface_call_res((struct spa_interface*)registry,
498 struct pw_registry_methods, res,
499 bind, 0, id, type, version, user_data_size);
500 return res;
501}
502
503#define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__)
504
524struct pw_core *
525 pw_context_connect(struct pw_context *context,
526 struct pw_properties *properties,
527 size_t user_data_size);
528
539struct pw_core *
540 pw_context_connect_fd(struct pw_context *context,
541 int fd,
542 struct pw_properties *properties,
543 size_t user_data_size);
544
553struct pw_core *
554 pw_context_connect_self(struct pw_context *context,
555 struct pw_properties *properties,
556 size_t user_data_size);
557
560int pw_core_steal_fd(struct pw_core *core);
561
564 int pw_core_set_paused(struct pw_core *core, bool paused);
565
567int pw_core_disconnect(struct pw_core *core);
568
571void *pw_core_get_user_data(struct pw_core *core);
572
575struct pw_client * pw_core_get_client(struct pw_core *core);
576
578struct pw_context * pw_core_get_context(struct pw_core *core);
579
581const struct pw_properties *pw_core_get_properties(struct pw_core *core);
582
586int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict);
587
589struct pw_mempool * pw_core_get_mempool(struct pw_core *core);
590
592struct pw_proxy *pw_core_find_proxy(struct pw_core *core, uint32_t id);
593
595struct pw_proxy *pw_core_export(struct pw_core *core,
596 const char *type,
597 const struct spa_dict *props,
598 void *object,
599 size_t user_data_size );
600
605#ifdef __cplusplus
606}
607#endif
608
609#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:112
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:373
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:362
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:249
pw_core_error
#define pw_core_error(c,...)
Fatal error event.
Definition: core.h:355
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:382
pw_core_get_mempool
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
Get the core mempool object.
Definition: core.c:463
pw_core_get_properties
const struct pw_properties * pw_core_get_properties(struct pw_core *core)
Get properties from the core.
Definition: core.c:118
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:434
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:243
pw_core_get_user_data
void * pw_core_get_user_data(struct pw_core *core)
Get the user_data.
Definition: core.c:142
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:124
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:255
pw_core_disconnect
int pw_core_disconnect(struct pw_core *core)
disconnect and destroy a core
Definition: core.c:469
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:395
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:448
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:385
pw_core_set_paused
int pw_core_set_paused(struct pw_core *core, bool paused)
Pause or resume the core.
Definition: core.c:456
pw_core_info_free
void pw_core_info_free(struct pw_core_info *info)
Free a pw_core_info
Definition: introspect.c:145
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:409
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:107
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:138
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:551
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:235
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition: defs.h:273
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:121
pw_core_events::ping
void(* ping)(void *data, uint32_t id, int seq)
Emit a ping event.
Definition: core.h:150
pw_core_events::remove_mem
void(* remove_mem)(void *data, uint32_t id)
Remove memory for a client.
Definition: core.h:216
pw_core_events::error
void(* error)(void *data, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:169
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:209
pw_core_events::info
void(* info)(void *data, const struct pw_core_info *info)
Notify new core info.
Definition: core.h:134
pw_core_events::remove_id
void(* remove_id)(void *data, uint32_t id)
Remove an object ID.
Definition: core.h:181
pw_core_events::version
uint32_t version
Definition: core.h:124
pw_core_events::bound_id
void(* bound_id)(void *data, uint32_t id, uint32_t global_id)
Notify an object binding.
Definition: core.h:193
pw_core_events::done
void(* done)(void *data, uint32_t id, int seq)
Emit a done event.
Definition: core.h:143
pw_core_info
The core information.
Definition: core.h:67
pw_core_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition: core.h:78
pw_core_info::version
const char * version
version of the core
Definition: core.h:72
pw_core_info::cookie
uint32_t cookie
a random cookie for identifying this instance of PipeWire
Definition: core.h:69
pw_core_info::id
uint32_t id
id of the global
Definition: core.h:68
pw_core_info::user_name
const char * user_name
name of the user that started the core
Definition: core.h:70
pw_core_info::host_name
const char * host_name
name of the machine the core is running on
Definition: core.h:71
pw_core_methods
Core methods.
Definition: core.h:246
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:251
pw_core_methods::pong
int(* pong)(void *object, uint32_t id, int seq)
Reply to a server ping event.
Definition: core.h:280
pw_core_methods::destroy
int(* destroy)(void *object, void *proxy)
Destroy an resource.
Definition: core.h:331
pw_core_methods::hello
int(* hello)(void *object, uint32_t version)
Start a conversation with the server.
Definition: core.h:260
pw_core_methods::error
int(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition: core.h:297
pw_core_methods::sync
int(* sync)(void *object, uint32_t id, int seq)
Do server roundtrip.
Definition: core.h:272
pw_core_methods::version
uint32_t version
Definition: core.h:249
pw_core
pw_mempool
A memory pool is a collection of pw_memblocks.
Definition: src/pipewire/mem.h:57
pw_properties
Definition: properties.h:33
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition: properties.h:34
pw_proxy
pw_registry_events
Registry events.
Definition: core.h:461
pw_registry_events::global_remove
void(* global_remove)(void *data, uint32_t id)
Notify of a global object removal.
Definition: core.h:489
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:477
pw_registry_events::version
uint32_t version
Definition: core.h:464
pw_registry_methods
Registry methods.
Definition: core.h:502
pw_registry_methods::version
uint32_t version
Definition: core.h:505
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:507
pw_registry_methods::destroy
int(* destroy)(void *object, uint32_t id)
Attempt to destroy a global object.
Definition: core.h:533
pw_registry
spa_dict
Definition: utils/dict.h:39
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:331
spa_interface
Definition: hook.h:138