PipeWire 1.7.0
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_DEVICE_H
6#define SPA_DEVICE_H
7
8#include <spa/utils/defs.h>
9#include <spa/utils/hook.h>
10#include <spa/utils/dict.h>
11#include <spa/pod/command.h>
12#include <spa/pod/event.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#ifndef SPA_API_DEVICE
19 #ifdef SPA_API_IMPL
20 #define SPA_API_DEVICE SPA_API_IMPL
21 #else
22 #define SPA_API_DEVICE static inline
23 #endif
24#endif
25
34
39#define SPA_TYPE_INTERFACE_Device SPA_TYPE_INFO_INTERFACE_BASE "Device"
40
41#define SPA_VERSION_DEVICE 0
42struct spa_device { struct spa_interface iface; };
43
49struct spa_device_info {
50#define SPA_VERSION_DEVICE_INFO 0
51 uint32_t version;
52
53#define SPA_DEVICE_CHANGE_MASK_FLAGS (1u<<0)
54#define SPA_DEVICE_CHANGE_MASK_PROPS (1u<<1)
55#define SPA_DEVICE_CHANGE_MASK_PARAMS (1u<<2)
56 uint64_t change_mask;
57 uint64_t flags;
58 const struct spa_dict *props;
59 struct spa_param_info *params;
60 uint32_t n_params;
61};
62
63#define SPA_DEVICE_INFO_INIT() ((struct spa_device_info){ SPA_VERSION_DEVICE_INFO, })
71#define SPA_VERSION_DEVICE_OBJECT_INFO 0
72 uint32_t version;
74 const char *type;
75 const char *factory_name;
76
77#define SPA_DEVICE_OBJECT_CHANGE_MASK_FLAGS (1u<<0)
78#define SPA_DEVICE_OBJECT_CHANGE_MASK_PROPS (1u<<1)
79 uint64_t change_mask;
80 uint64_t flags;
81 const struct spa_dict *props;
82};
83
84#define SPA_DEVICE_OBJECT_INFO_INIT() ((struct spa_device_object_info){ SPA_VERSION_DEVICE_OBJECT_INFO, })
85
87#define SPA_RESULT_TYPE_DEVICE_PARAMS 1
89 uint32_t id;
90 uint32_t index;
91 uint32_t next;
92 struct spa_pod *param;
93};
94
95#define SPA_DEVICE_EVENT_INFO 0
96#define SPA_DEVICE_EVENT_RESULT 1
97#define SPA_DEVICE_EVENT_EVENT 2
98#define SPA_DEVICE_EVENT_OBJECT_INFO 3
99#define SPA_DEVICE_EVENT_NUM 4
100
107 /** version of the structure */
108#define SPA_VERSION_DEVICE_EVENTS 0
109 uint32_t version;
112 void (*info) (void *data, const struct spa_device_info *info);
113
115 void (*result) (void *data, int seq, int res, uint32_t type, const void *result);
116
118 void (*event) (void *data, const struct spa_event *event);
122 void (*object_info) (void *data, uint32_t id,
123 const struct spa_device_object_info *info);
124};
125
126#define SPA_DEVICE_METHOD_ADD_LISTENER 0
127#define SPA_DEVICE_METHOD_SYNC 1
128#define SPA_DEVICE_METHOD_ENUM_PARAMS 2
129#define SPA_DEVICE_METHOD_SET_PARAM 3
130#define SPA_DEVICE_METHOD_SEND_COMMAND 4
131#define SPA_DEVICE_METHOD_NUM 5
132
133/* object id of SPA_TYPE_COMMAND_Device */
136};
138#define SPA_DEVICE_COMMAND_ID(cmd) SPA_COMMAND_ID(cmd, SPA_TYPE_COMMAND_Device)
139#define SPA_DEVICE_COMMAND_INIT(id) SPA_COMMAND_INIT(SPA_TYPE_COMMAND_Device, id)
141
142/* properties for SPA_TYPE_COMMAND_Device */
145
148
150};
151
155struct spa_device_methods {
156 /* the version of the methods. This can be used to expand this
157 * structure in the future */
158#define SPA_VERSION_DEVICE_METHODS 1
159 uint32_t version;
165 * Setting the events will trigger the info event and an
166 * object_info event for each managed object on the new
167 * listener.
168 *
169 * \param object a \ref spa_device
170 * \param listener a listener
171 * \param events a struct \ref spa_device_events
172 * \param data data passed as first argument in functions of \a events
173 * \return 0 on success
174 * < 0 errno on error
175 */
176 int (*add_listener) (void *object,
177 struct spa_hook *listener,
178 const struct spa_device_events *events,
179 void *data);
184
188 * to wait for completion of all previous method calls.
189 *
190 * \param seq a sequence number
191 * \return 0 on success
192 * -EINVAL when node is NULL
193 * an async result
194 */
195 int (*sync) (void *object, int seq);
196
222 int (*enum_params) (void *object, int seq,
223 uint32_t id, uint32_t index, uint32_t max,
224 const struct spa_pod *filter);
225
247 int (*set_param) (void *object,
248 uint32_t id, uint32_t flags,
249 const struct spa_pod *param);
250
265 int (*send_command) (void *object, const struct spa_command *command);
266
267};
268
270 struct spa_hook *listener,
271 const struct spa_device_events *events,
272 void *data)
273{
274 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, add_listener, 0,
275 listener, events, data);
276
277}
278SPA_API_DEVICE int spa_device_sync(struct spa_device *object, int seq)
279{
280 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, sync, 0,
282}
284 uint32_t id, uint32_t index, uint32_t max,
285 const struct spa_pod *filter)
286{
287 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, enum_params, 0,
288 seq, id, index, max, filter);
289}
291 uint32_t id, uint32_t flags,
292 const struct spa_pod *param)
293{
294 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, set_param, 0,
295 id, flags, param);
296}
298 const struct spa_command *command)
300 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, send_command, 1,
301 command);
302}
304#define SPA_KEY_DEVICE_ENUM_API "device.enum.api"
306#define SPA_KEY_DEVICE_API "device.api"
308#define SPA_KEY_DEVICE_NAME "device.name"
309#define SPA_KEY_DEVICE_ALIAS "device.alias"
310#define SPA_KEY_DEVICE_NICK "device.nick"
311#define SPA_KEY_DEVICE_DESCRIPTION "device.description"
312#define SPA_KEY_DEVICE_ICON "device.icon"
314#define SPA_KEY_DEVICE_ICON_NAME "device.icon-name"
316#define SPA_KEY_DEVICE_PLUGGED_USEC "device.plugged.usec"
318#define SPA_KEY_DEVICE_BUS_ID "device.bus-id"
319#define SPA_KEY_DEVICE_BUS_PATH "device.bus-path"
322#define SPA_KEY_DEVICE_BUS "device.bus"
324
324 * "bluetooth" */
325#define SPA_KEY_DEVICE_SUBSYSTEM "device.subsystem"
326#define SPA_KEY_DEVICE_SYSFS_PATH "device.sysfs.path"
327
328#define SPA_KEY_DEVICE_VENDOR_ID "device.vendor.id"
329#define SPA_KEY_DEVICE_VENDOR_NAME "device.vendor.name"
330#define SPA_KEY_DEVICE_PRODUCT_ID "device.product.id"
331#define SPA_KEY_DEVICE_PRODUCT_NAME "device.product.name"
332#define SPA_KEY_DEVICE_SERIAL "device.serial"
333#define SPA_KEY_DEVICE_CLASS "device.class"
334#define SPA_KEY_DEVICE_CAPABILITIES "device.capabilities"
335#define SPA_KEY_DEVICE_FORM_FACTOR "device.form-factor"
337
340#define SPA_KEY_DEVICE_PROFILE "device.profile"
341#define SPA_KEY_DEVICE_PROFILE_SET "device.profile-set"
342#define SPA_KEY_DEVICE_STRING "device.string"
344#define SPA_KEY_DEVICE_DEVIDS "device.devids"
350#ifdef __cplusplus
351} /* extern "C" */
352#endif
354#endif /* SPA_DEVICE_H */
spa/utils/defs.h
uint32_t int seq
Definition core.h:432
uint32_t id
Definition core.h:432
uint32_t int int res
Definition core.h:433
SPA_API_DEVICE int spa_device_sync(struct spa_device *object, int seq)
Definition device.h:312
SPA_API_DEVICE int spa_device_send_command(struct spa_device *object, const struct spa_command *command)
Definition device.h:331
SPA_API_DEVICE int spa_device_set_param(struct spa_device *object, uint32_t id, uint32_t flags, const struct spa_pod *param)
Definition device.h:324
SPA_API_DEVICE int spa_device_enum_params(struct spa_device *object, int seq, uint32_t id, uint32_t index, uint32_t max, const struct spa_pod *filter)
Definition device.h:317
spa_device_commands
Definition device.h:165
spa_command_device
Definition device.h:176
SPA_API_DEVICE int spa_device_add_listener(struct spa_device *object, struct spa_hook *listener, const struct spa_device_events *events, void *data)
Definition device.h:303
@ SPA_DEVICE_COMMAND_User
Definition device.h:166
@ SPA_COMMAND_DEVICE_extra
Definition device.h:180
@ SPA_COMMAND_DEVICE_START_User
Definition device.h:179
@ SPA_COMMAND_DEVICE_START
Definition device.h:177
@ SPA_COMMAND_DEVICE_START_CUSTOM
extra info (String)
Definition device.h:182
#define spa_api_method_r(rtype, def, type, o, method, version,...)
Definition hook.h:291
spa/utils/hook.h
spa/pod/command.h
spa/pod/event.h
#define SPA_API_DEVICE
Definition device.h:29
Definition command.h:29
spa_device_events:
Definition device.h:130
void(* result)(void *data, int seq, int res, uint32_t type, const void *result)
notify a result
Definition device.h:140
void(* event)(void *data, const struct spa_event *event)
a device event
Definition device.h:143
uint32_t version
Definition device.h:134
Information about the device and parameters it supports.
Definition device.h:58
uint64_t flags
Definition device.h:70
struct spa_param_info * params
supported parameters
Definition device.h:72
uint32_t version
Definition device.h:61
uint32_t n_params
number of elements in params
Definition device.h:73
uint64_t change_mask
Definition device.h:69
spa_device_methods:
Definition device.h:188
uint32_t version
Definition device.h:193
int(* sync)(void *object, int seq)
Perform a sync operation.
Definition device.h:229
int(* enum_params)(void *object, int seq, uint32_t id, uint32_t index, uint32_t max, const struct spa_pod *filter)
Enumerate the parameters of a device.
Definition device.h:256
int(* send_command)(void *object, const struct spa_command *command)
Send a command to a device.
Definition device.h:299
int(* set_param)(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param)
Set the configurable parameter in device.
Definition device.h:281
int(* add_listener)(void *object, struct spa_hook *listener, const struct spa_device_events *events, void *data)
Set events to receive asynchronous notifications from the device.
Definition device.h:210
Information about a device object.
Definition device.h:84
uint64_t change_mask
Definition device.h:96
const char * factory_name
a factory name that implements the object
Definition device.h:90
uint64_t flags
Definition device.h:97
Definition device.h:51
struct spa_interface iface
Definition device.h:51
Definition dict.h:51
Definition event.h:28
A hook, contains the structure with functions and the data passed to the functions.
Definition hook.h:427
Definition hook.h:148
information about a parameter
Definition param.h:56
Definition pod.h:57
Definition device.h:107
uint32_t index
Definition device.h:109
uint32_t next
Definition device.h:110
spa/utils/dict.h