PipeWire  0.3.33
system.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2019 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 SPA_SYSTEM_H
26 #define SPA_SYSTEM_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 struct itimerspec;
33 
34 #include <time.h>
35 #include <sys/types.h>
36 
37 #include <spa/utils/defs.h>
38 #include <spa/utils/hook.h>
39 
48 #define SPA_TYPE_INTERFACE_System SPA_TYPE_INFO_INTERFACE_BASE "System"
49 #define SPA_TYPE_INTERFACE_DataSystem SPA_TYPE_INFO_INTERFACE_BASE "DataSystem"
50 
51 #define SPA_VERSION_SYSTEM 0
52 struct spa_system { struct spa_interface iface; };
53 
54 /* IO events */
55 #define SPA_IO_IN (1 << 0)
56 #define SPA_IO_OUT (1 << 2)
57 #define SPA_IO_ERR (1 << 3)
58 #define SPA_IO_HUP (1 << 4)
59 
60 /* flags */
61 #define SPA_FD_CLOEXEC (1<<0)
62 #define SPA_FD_NONBLOCK (1<<1)
63 #define SPA_FD_EVENT_SEMAPHORE (1<<2)
64 #define SPA_FD_TIMER_ABSTIME (1<<3)
65 #define SPA_FD_TIMER_CANCEL_ON_SET (1<<4)
66 
68  uint32_t events;
69  void *data;
70 };
71 
73 #define SPA_VERSION_SYSTEM_METHODS 0
74  uint32_t version;
75 
76  /* read/write/ioctl */
77  ssize_t (*read) (void *object, int fd, void *buf, size_t count);
78  ssize_t (*write) (void *object, int fd, const void *buf, size_t count);
79  int (*ioctl) (void *object, int fd, unsigned long request, ...);
80  int (*close) (void *object, int fd);
81 
82  /* clock */
83  int (*clock_gettime) (void *object,
84  int clockid, struct timespec *value);
85  int (*clock_getres) (void *object,
86  int clockid, struct timespec *res);
87 
88  /* poll */
89  int (*pollfd_create) (void *object, int flags);
90  int (*pollfd_add) (void *object, int pfd, int fd, uint32_t events, void *data);
91  int (*pollfd_mod) (void *object, int pfd, int fd, uint32_t events, void *data);
92  int (*pollfd_del) (void *object, int pfd, int fd);
93  int (*pollfd_wait) (void *object, int pfd,
94  struct spa_poll_event *ev, int n_ev, int timeout);
95 
96  /* timers */
97  int (*timerfd_create) (void *object, int clockid, int flags);
98  int (*timerfd_settime) (void *object,
99  int fd, int flags,
100  const struct itimerspec *new_value,
101  struct itimerspec *old_value);
102  int (*timerfd_gettime) (void *object,
103  int fd, struct itimerspec *curr_value);
104  int (*timerfd_read) (void *object, int fd, uint64_t *expirations);
105 
106  /* events */
107  int (*eventfd_create) (void *object, int flags);
108  int (*eventfd_write) (void *object, int fd, uint64_t count);
109  int (*eventfd_read) (void *object, int fd, uint64_t *count);
110 
111  /* signals */
112  int (*signalfd_create) (void *object, int signal, int flags);
113  int (*signalfd_read) (void *object, int fd, int *signal);
114 };
115 
116 #define spa_system_method_r(o,method,version,...) \
117 ({ \
118  int _res = -ENOTSUP; \
119  struct spa_system *_o = o; \
120  spa_interface_call_res(&_o->iface, \
121  struct spa_system_methods, _res, \
122  method, version, ##__VA_ARGS__); \
123  _res; \
124 })
125 
126 
127 #define spa_system_read(s,...) spa_system_method_r(s,read,0,__VA_ARGS__)
128 #define spa_system_write(s,...) spa_system_method_r(s,write,0,__VA_ARGS__)
129 #define spa_system_ioctl(s,...) spa_system_method_r(s,ioctl,0,__VA_ARGS__)
130 #define spa_system_close(s,...) spa_system_method_r(s,close,0,__VA_ARGS__)
131 
132 #define spa_system_clock_gettime(s,...) spa_system_method_r(s,clock_gettime,0,__VA_ARGS__)
133 #define spa_system_clock_getres(s,...) spa_system_method_r(s,clock_getres,0,__VA_ARGS__)
134 
135 #define spa_system_pollfd_create(s,...) spa_system_method_r(s,pollfd_create,0,__VA_ARGS__)
136 #define spa_system_pollfd_add(s,...) spa_system_method_r(s,pollfd_add,0,__VA_ARGS__)
137 #define spa_system_pollfd_mod(s,...) spa_system_method_r(s,pollfd_mod,0,__VA_ARGS__)
138 #define spa_system_pollfd_del(s,...) spa_system_method_r(s,pollfd_del,0,__VA_ARGS__)
139 #define spa_system_pollfd_wait(s,...) spa_system_method_r(s,pollfd_wait,0,__VA_ARGS__)
140 
141 #define spa_system_timerfd_create(s,...) spa_system_method_r(s,timerfd_create,0,__VA_ARGS__)
142 #define spa_system_timerfd_settime(s,...) spa_system_method_r(s,timerfd_settime,0,__VA_ARGS__)
143 #define spa_system_timerfd_gettime(s,...) spa_system_method_r(s,timerfd_gettime,0,__VA_ARGS__)
144 #define spa_system_timerfd_read(s,...) spa_system_method_r(s,timerfd_read,0,__VA_ARGS__)
145 
146 #define spa_system_eventfd_create(s,...) spa_system_method_r(s,eventfd_create,0,__VA_ARGS__)
147 #define spa_system_eventfd_write(s,...) spa_system_method_r(s,eventfd_write,0,__VA_ARGS__)
148 #define spa_system_eventfd_read(s,...) spa_system_method_r(s,eventfd_read,0,__VA_ARGS__)
149 
150 #define spa_system_signalfd_create(s,...) spa_system_method_r(s,signalfd_create,0,__VA_ARGS__)
151 #define spa_system_signalfd_read(s,...) spa_system_method_r(s,signalfd_read,0,__VA_ARGS__)
152 
157 #ifdef __cplusplus
158 } /* extern "C" */
159 #endif
160 
161 #endif /* SPA_SYSTEM_H */
pw_context_get_main_loop
struct pw_loop * pw_context_get_main_loop(struct pw_context *context)
get the context main loop
Definition: context.c:567
impl::node_list
struct spa_list node_list
Definition: policy-node.c:86
pw_properties_get
int int const char * pw_properties_get(const struct pw_properties *properties, const char *key)
Get a property.
Definition: properties.c:487
spa_interface
Definition: hook.h:146
spa_system_methods::version
uint32_t version
Definition: system.h:74
sm_media_session_add_listener
int sm_media_session_add_listener(struct sm_media_session *sess, struct spa_hook *listener, const struct sm_media_session_events *events, void *data)
Definition: media-session.c:1519
spa_system_methods::eventfd_create
int(* eventfd_create)(void *object, int flags)
Definition: system.h:107
spa_system_methods::read
ssize_t(* read)(void *object, int fd, void *buf, size_t count)
Definition: system.h:77
pw_loop_update_timer
#define pw_loop_update_timer(l,...)
Definition: src/pipewire/loop.h:78
node::direction
enum pw_direction direction
Definition: alsa-monitor.c:69
node.h
PW_NODE_STATE_RUNNING
@ PW_NODE_STATE_RUNNING
the node is running
Definition: src/pipewire/node.h:63
string.h
node::link
struct spa_list link
link in impl node_list
Definition: module-filter-chain.c:151
data
user data to add to an object
Definition: filter.c:75
impl::data
uint8_t data[MAX_BUFFER]
Definition: module-profiler.c:87
spa_streq
bool spa_streq(const char *s1, const char *s2)
Definition: string.h:50
node::obj
struct sm_node * obj
Definition: bluez-autoswitch.c:79
pw_loop
Definition: src/pipewire/loop.h:47
PW_NODE_STATE_IDLE
@ PW_NODE_STATE_IDLE
the node is running but there is no active port
Definition: src/pipewire/node.h:61
impl::seq
int seq
Definition: policy-ep.c:65
node::idle_timeout
struct spa_source * idle_timeout
Definition: suspend-node.c:73
impl::listener
struct spa_hook listener
Definition: access-flatpak.c:46
node
Definition: module-filter-chain.c:150
node::listener
struct spa_hook listener
Definition: bluez-autoswitch.c:81
impl
Definition: control.c:33
PW_NODE_STATE_ERROR
@ PW_NODE_STATE_ERROR
error state
Definition: src/pipewire/node.h:57
PW_NODE_CHANGE_MASK_STATE
#define PW_NODE_CHANGE_MASK_STATE
Definition: src/pipewire/node.h:76
spa_list
Definition: list.h:37
spa_system_methods::clock_gettime
int(* clock_gettime)(void *object, int clockid, struct timespec *value)
Definition: system.h:83
spa_strstartswith
bool spa_strstartswith(const char *s, const char *prefix)
Definition: string.h:71
impl::id
uint32_t id
Definition: module-echo-cancel.c:139
SESSION_KEY
#define SESSION_KEY
Definition: suspend-node.c:47
pod.h
spa_source
Definition: build-12683127/doc/spa/support/loop.h:58
pw_loop_destroy_source
#define pw_loop_destroy_source(l,...)
Definition: src/pipewire/loop.h:80
spa_system_methods::write
ssize_t(* write)(void *object, int fd, const void *buf, size_t count)
Definition: system.h:78
spa_system_methods::timerfd_read
int(* timerfd_read)(void *object, int fd, uint64_t *expirations)
Definition: system.h:104
NAME
#define NAME
Definition: suspend-node.c:46
node::impl
struct impl * impl
Definition: alsa-monitor.c:68
spa_system
Definition: system.h:52
sm_suspend_node_start
int sm_suspend_node_start(struct sm_media_session *session)
Definition: suspend-node.c:248
spa_system_methods::ioctl
int(* ioctl)(void *object, int fd, unsigned long request,...)
Definition: system.h:79
spa_list_remove
void spa_list_remove(struct spa_list *elem)
Definition: list.h:69
impl::now
struct timespec now
Definition: default-profile.c:87
DEFAULT_IDLE_SECONDS
#define DEFAULT_IDLE_SECONDS
Definition: suspend-node.c:49
PW_TYPE_INTERFACE_Node
#define PW_TYPE_INTERFACE_Node
Definition: src/pipewire/node.h:50
spa_poll_event::events
uint32_t events
Definition: system.h:68
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:295
spa_system_methods::pollfd_wait
int(* pollfd_wait)(void *object, int pfd, struct spa_poll_event *ev, int n_ev, int timeout)
Definition: system.h:93
SPA_NODE_COMMAND_Suspend
@ SPA_NODE_COMMAND_Suspend
suspend a node, this removes all configured formats and closes any devices
Definition: node/command.h:41
SPA_NODE_COMMAND_INIT
#define SPA_NODE_COMMAND_INIT(id)
Definition: node/command.h:60
pw_node_send_command
#define pw_node_send_command(c,...)
Definition: src/pipewire/node.h:202
sm_object_remove_data
int sm_object_remove_data(struct sm_object *obj, const char *id)
Definition: media-session.c:290
spa_system_methods::signalfd_create
int(* signalfd_create)(void *object, int signal, int flags)
Definition: system.h:112
spa_system_methods
Definition: system.h:72
sm_object_get_data
void * sm_object_get_data(struct sm_object *obj, const char *id)
Definition: media-session.c:281
spa_system_methods::timerfd_gettime
int(* timerfd_gettime)(void *object, int fd, struct itimerspec *curr_value)
Definition: system.h:102
spa_system_methods::pollfd_mod
int(* pollfd_mod)(void *object, int pfd, int fd, uint32_t events, void *data)
Definition: system.h:91
spa_list_init
void spa_list_init(struct spa_list *list)
Definition: list.h:44
node::node
struct spa_node * node
Definition: alsa-monitor.c:76
sm_object_add_listener
int sm_object_add_listener(struct sm_object *obj, struct spa_hook *listener, const struct sm_object_events *events, void *data)
Definition: media-session.c:1512
PW_NODE_STATE_SUSPENDED
@ PW_NODE_STATE_SUSPENDED
the node is suspended, the device might be closed
Definition: src/pipewire/node.h:59
spa_system_methods::pollfd_create
int(* pollfd_create)(void *object, int flags)
Definition: system.h:89
spa_dict_lookup
const char * spa_dict_lookup(const struct spa_dict *dict, const char *key)
Definition: utils/dict.h:99
spa_system_methods::pollfd_add
int(* pollfd_add)(void *object, int pfd, int fd, uint32_t events, void *data)
Definition: system.h:90
pw_loop_add_timer
#define pw_loop_add_timer(l,...)
Definition: src/pipewire/loop.h:77
pw_log_debug
#define pw_log_debug(...)
Definition: src/pipewire/log.h:89
impl::context
struct pw_context * context
Definition: settings.c:43
PW_KEY_MEDIA_CLASS
#define PW_KEY_MEDIA_CLASS
class Ex: "Video/Source"
Definition: src/pipewire/keys.h:285
impl::session
struct sm_media_session * session
Definition: access-flatpak.c:45
sm_object_add_data
void * sm_object_add_data(struct sm_object *obj, const char *id, size_t size)
Definition: media-session.c:261
spa_system_methods::timerfd_settime
int(* timerfd_settime)(void *object, int fd, int flags, const struct itimerspec *new_value, struct itimerspec *old_value)
Definition: system.h:98
pw_log_warn
#define pw_log_warn(...)
Definition: src/pipewire/log.h:87
spa_system::iface
struct spa_interface iface
Definition: system.h:52
spa_command
Definition: pod/command.h:44
pw_node_info::state
enum pw_node_state state
the current state of the node
Definition: src/pipewire/node.h:83
spa_poll_event::data
void * data
Definition: system.h:69
spa_system_methods::pollfd_del
int(* pollfd_del)(void *object, int pfd, int fd)
Definition: system.h:92
defs.h
spa_hook_remove
void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition: hook.h:336
pw_log_info
#define pw_log_info(...)
Definition: src/pipewire/log.h:88
spa_system_methods::clock_getres
int(* clock_getres)(void *object, int clockid, struct timespec *res)
Definition: system.h:85
spa_system_methods::timerfd_create
int(* timerfd_create)(void *object, int clockid, int flags)
Definition: system.h:97
pipewire.h
pw_node_info::change_mask
uint64_t change_mask
bitfield of changed fields since last call
Definition: src/pipewire/node.h:80
hook.h
pw_node_info
The node information.
Definition: src/pipewire/node.h:70
props.h
spa_poll_event
Definition: system.h:67
pw_direction
#define pw_direction
The direction of a port.
Definition: port.h:56
spa_system_methods::eventfd_read
int(* eventfd_read)(void *object, int fd, uint64_t *count)
Definition: system.h:109
spa_system_methods::close
int(* close)(void *object, int fd)
Definition: system.h:80
spa_system_methods::eventfd_write
int(* eventfd_write)(void *object, int fd, uint64_t count)
Definition: system.h:108
spa_system_methods::signalfd_read
int(* signalfd_read)(void *object, int fd, int *signal)
Definition: system.h:113
node::id
uint32_t id
Definition: alsa-monitor.c:72
spa_list_append
#define spa_list_append(list, item)
Definition: list.h:81