PipeWire 1.1.0
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_CORE_PERM_MASK PW_PERM_R|PW_PERM_X|PW_PERM_M
38
39#define PW_VERSION_CORE 4
40struct pw_core;
41#define PW_VERSION_REGISTRY 3
43
45#define PW_DEFAULT_REMOTE "pipewire-0"
46
48#define PW_ID_CORE 0
50/* invalid ID that matches any object when used for permissions */
51#define PW_ID_ANY (uint32_t)(0xffffffff)
55struct 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>
76 const struct pw_core_info *update);
79struct pw_core_info *
81 const struct pw_core_info *update, bool reset);
83void 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
101struct 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);
129 void (*ping) (void *data, uint32_t id, int seq);
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);
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
213 void (*bound_props) (void *data, uint32_t id, uint32_t global_id, const struct spa_dict *props);
214};
215
216#define PW_CORE_METHOD_ADD_LISTENER 0
217#define PW_CORE_METHOD_HELLO 1
218#define PW_CORE_METHOD_SYNC 2
219#define PW_CORE_METHOD_PONG 3
220#define PW_CORE_METHOD_ERROR 4
221#define PW_CORE_METHOD_GET_REGISTRY 5
222#define PW_CORE_METHOD_CREATE_OBJECT 6
223#define PW_CORE_METHOD_DESTROY 7
224#define PW_CORE_METHOD_NUM 8
225
234struct pw_core_methods {
235#define PW_VERSION_CORE_METHODS 0
236 uint32_t version;
237
238 int (*add_listener) (void *object,
239 struct spa_hook *listener,
240 const struct pw_core_events *events,
241 void *data);
249 int (*hello) (void *object, uint32_t version);
263 int (*sync) (void *object, uint32_t id, int seq);
273 int (*pong) (void *object, uint32_t id, int seq);
292 int (*error) (void *object, uint32_t id, int seq, int res, const char *message);
303 struct pw_registry * (*get_registry) (void *object, uint32_t version,
304 size_t user_data_size);
305
317 void * (*create_object) (void *object,
318 const char *factory_name,
319 const char *type,
320 uint32_t version,
321 const struct spa_dict *props,
322 size_t user_data_size);
332 int (*destroy) (void *object, void *proxy);
333};
334
335#define pw_core_method(o,method,version,...) \
336({ \
337 int _res = -ENOTSUP; \
338 spa_interface_call_res((struct spa_interface*)o, \
339 struct pw_core_methods, _res, \
340 method, version, ##__VA_ARGS__); \
341 _res; \
342})
343
344#define pw_core_add_listener(c,...) pw_core_method(c,add_listener,0,__VA_ARGS__)
345#define pw_core_hello(c,...) pw_core_method(c,hello,0,__VA_ARGS__)
346#define pw_core_sync(c,...) pw_core_method(c,sync,0,__VA_ARGS__)
347#define pw_core_pong(c,...) pw_core_method(c,pong,0,__VA_ARGS__)
348#define pw_core_error(c,...) pw_core_method(c,error,0,__VA_ARGS__)
349
350
351static inline
352SPA_PRINTF_FUNC(5, 0) int
353pw_core_errorv(struct pw_core *core, uint32_t id, int seq,
354 int res, const char *message, va_list args)
356 char buffer[1024];
357 vsnprintf(buffer, sizeof(buffer), message, args);
358 buffer[1023] = '\0';
359 return pw_core_error(core, id, seq, res, buffer);
360}
361
362static inline
363SPA_PRINTF_FUNC(5, 6) int
364pw_core_errorf(struct pw_core *core, uint32_t id, int seq,
365 int res, const char *message, ...)
366{
367 va_list args;
368 int r;
369 va_start(args, message);
370 r = pw_core_errorv(core, id, seq, res, message, args);
371 va_end(args);
372 return r;
374
375static inline struct pw_registry *
376pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
377{
378 struct pw_registry *res = NULL;
380 struct pw_core_methods, res,
381 get_registry, 0, version, user_data_size);
382 return res;
383}
385static inline void *
386pw_core_create_object(struct pw_core *core,
387 const char *factory_name,
388 const char *type,
389 uint32_t version,
390 const struct spa_dict *props,
391 size_t user_data_size)
392{
393 void *res = NULL;
395 struct pw_core_methods, res,
396 create_object, 0, factory_name,
397 type, version, props, user_data_size);
398 return res;
399}
400
401#define pw_core_destroy(c,...) pw_core_method(c,destroy,0,__VA_ARGS__)
402
442#define PW_REGISTRY_EVENT_GLOBAL 0
443#define PW_REGISTRY_EVENT_GLOBAL_REMOVE 1
444#define PW_REGISTRY_EVENT_NUM 2
445
447struct pw_registry_events {
448#define PW_VERSION_REGISTRY_EVENTS 0
449 uint32_t version;
462 void (*global) (void *data, uint32_t id,
463 uint32_t permissions, const char *type, uint32_t version,
464 const struct spa_dict *props);
474 void (*global_remove) (void *data, uint32_t id);
475};
476
477#define PW_REGISTRY_METHOD_ADD_LISTENER 0
478#define PW_REGISTRY_METHOD_BIND 1
479#define PW_REGISTRY_METHOD_DESTROY 2
480#define PW_REGISTRY_METHOD_NUM 3
481
483struct pw_registry_methods {
484#define PW_VERSION_REGISTRY_METHODS 0
485 uint32_t version;
486
487 int (*add_listener) (void *object,
488 struct spa_hook *listener,
489 const struct pw_registry_events *events,
490 void *data);
503 void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
504 size_t use_data_size);
505
514 int (*destroy) (void *object, uint32_t id);
515};
517#define pw_registry_method(o,method,version,...) \
518({ \
519 int _res = -ENOTSUP; \
520 spa_interface_call_res((struct spa_interface*)o, \
521 struct pw_registry_methods, _res, \
522 method, version, ##__VA_ARGS__); \
523 _res; \
524})
525
527#define pw_registry_add_listener(p,...) pw_registry_method(p,add_listener,0,__VA_ARGS__)
529static inline void *
530pw_registry_bind(struct pw_registry *registry,
531 uint32_t id, const char *type, uint32_t version,
532 size_t user_data_size)
533{
534 void *res = NULL;
535 spa_interface_call_res((struct spa_interface*)registry,
537 bind, 0, id, type, version, user_data_size);
538 return res;
539}
540
541#define pw_registry_destroy(p,...) pw_registry_method(p,destroy,0,__VA_ARGS__)
542
562struct pw_core *
563pw_context_connect(struct pw_context *context,
564 struct pw_properties *properties,
565 size_t user_data_size);
566
577struct pw_core *
578pw_context_connect_fd(struct pw_context *context,
579 int fd,
580 struct pw_properties *properties,
581 size_t user_data_size);
582
591struct pw_core *
592pw_context_connect_self(struct pw_context *context,
593 struct pw_properties *properties,
594 size_t user_data_size);
595
598int pw_core_steal_fd(struct pw_core *core);
599
602int pw_core_set_paused(struct pw_core *core, bool paused);
603
605int pw_core_disconnect(struct pw_core *core);
606
609void *pw_core_get_user_data(struct pw_core *core);
610
613struct pw_client * pw_core_get_client(struct pw_core *core);
614
616struct pw_context * pw_core_get_context(struct pw_core *core);
617
619const struct pw_properties *pw_core_get_properties(struct pw_core *core);
620
624int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict);
625
627struct pw_mempool * pw_core_get_mempool(struct pw_core *core);
628
630struct pw_proxy *pw_core_find_proxy(struct pw_core *core, uint32_t id);
631
633struct pw_proxy *pw_core_export(struct pw_core *core,
634 const char *type,
635 const struct spa_dict *props,
636 void *object,
637 size_t user_data_size );
638
643#ifdef __cplusplus
644}
645#endif
646
647#endif /* PIPEWIRE_CORE_H */
struct pw_context * pw_core_get_context(struct pw_core *core)
Get the context object used to created this core.
Definition core.c:123
static int pw_core_errorf(struct pw_core *core, uint32_t id, int seq, int res, const char *message,...)
Definition core.h:412
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:401
struct pw_proxy * pw_core_find_proxy(struct pw_core *core, uint32_t id)
Get the proxy with the given id.
Definition core.c:260
#define pw_core_error(c,...)
Fatal error event.
Definition core.h:394
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:391
struct pw_mempool * pw_core_get_mempool(struct pw_core *core)
Get the core mempool object.
Definition core.c:472
const struct pw_properties * pw_core_get_properties(struct pw_core *core)
Get properties from the core.
Definition core.c:129
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:443
struct pw_client * pw_core_get_client(struct pw_core *core)
Get the client proxy of the connected core.
Definition core.c:254
void * pw_core_get_user_data(struct pw_core *core)
Get the user_data.
Definition core.c:153
int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict)
Update the core properties.
Definition core.c:135
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:266
int pw_core_disconnect(struct pw_core *core)
disconnect and destroy a core
Definition core.c:478
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:434
int pw_core_steal_fd(struct pw_core *core)
Steal the fd of the core connection or < 0 on error.
Definition core.c:457
static struct pw_registry * pw_core_get_registry(struct pw_core *core, uint32_t version, size_t user_data_size)
Definition core.h:424
int pw_core_set_paused(struct pw_core *core, bool paused)
Pause or resume the core.
Definition core.c:465
void pw_core_info_free(struct pw_core_info *info)
Free a pw_core_info
Definition introspect.c:146
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:418
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
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
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:591
#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:285
spa/utils/hook.h
pipewire/properties.h
pipewire/proxy.h
pipewire/context.h
Core events.
Definition core.h:128
void(* ping)(void *data, uint32_t id, int seq)
Emit a ping event.
Definition core.h:157
void(* remove_mem)(void *data, uint32_t id)
Remove memory for a client.
Definition core.h:226
void(* error)(void *data, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition core.h:176
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
void(* bound_props)(void *data, uint32_t id, uint32_t global_id, const struct spa_dict *props)
Notify an object binding.
Definition core.h:241
void(* info)(void *data, const struct pw_core_info *info)
Notify new core info.
Definition core.h:141
void(* remove_id)(void *data, uint32_t id)
Remove an object ID.
Definition core.h:188
uint32_t version
Definition core.h:131
void(* bound_id)(void *data, uint32_t id, uint32_t global_id)
Notify an object binding.
Definition core.h:203
void(* done)(void *data, uint32_t id, int seq)
Emit a done event.
Definition core.h:150
The core information.
Definition core.h:70
uint64_t change_mask
bitfield of changed fields since last call
Definition core.h:81
const char * version
version of the core
Definition core.h:75
uint32_t cookie
a random cookie for identifying this instance of PipeWire
Definition core.h:72
uint32_t id
id of the global
Definition core.h:71
const char * user_name
name of the user that started the core
Definition core.h:73
const char * host_name
name of the machine the core is running on
Definition core.h:74
Core methods.
Definition core.h:271
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_core_events *events, void *data)
Definition core.h:276
int(* pong)(void *object, uint32_t id, int seq)
Reply to a server ping event.
Definition core.h:311
int(* destroy)(void *object, void *proxy)
Destroy an resource.
Definition core.h:370
int(* hello)(void *object, uint32_t version)
Start a conversation with the server.
Definition core.h:287
int(* error)(void *object, uint32_t id, int seq, int res, const char *message)
Fatal error event.
Definition core.h:330
int(* sync)(void *object, uint32_t id, int seq)
Do server roundtrip.
Definition core.h:301
uint32_t version
Definition core.h:274
A memory pool is a collection of pw_memblocks.
Definition mem.h:57
Definition properties.h:33
struct spa_dict dict
dictionary of key/values
Definition properties.h:34
Registry events.
Definition core.h:500
void(* global_remove)(void *data, uint32_t id)
Notify of a global object removal.
Definition core.h:528
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:516
uint32_t version
Definition core.h:503
Registry methods.
Definition core.h:541
uint32_t version
Definition core.h:544
int(* add_listener)(void *object, struct spa_hook *listener, const struct pw_registry_events *events, void *data)
Definition core.h:546
int(* destroy)(void *object, uint32_t id)
Attempt to destroy a global object.
Definition core.h:573
Definition 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