+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
c · 310 lines · 10.4 KB · SPDX: MIT
main
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/event.h>
12  
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16  
17 #ifndef SPA_API_DEVICE
18 #ifdef SPA_API_IMPL
19 #define SPA_API_DEVICE SPA_API_IMPL
20 #else
21 #define SPA_API_DEVICE static inline
22 #endif
23 #endif
24  
25 /**
26 * \defgroup spa_device Device
27 *
28 * The device interface can be used to monitor all kinds of devices
29 * and create objects as a result. Objects a typically other
30 * Devices or Nodes.
31 *
32 */
33  
34 /**
35 * \addtogroup spa_device
36 * \{
37 */
38 #define SPA_TYPE_INTERFACE_Device SPA_TYPE_INFO_INTERFACE_BASE "Device"
39  
40 #define SPA_VERSION_DEVICE 0
41 struct spa_device { struct spa_interface iface; };
42  
43 /**
44 * Information about the device and parameters it supports
45 *
46 * This information is part of the info event on a device.
47 */
48 struct spa_device_info {
49 #define SPA_VERSION_DEVICE_INFO 0
50 uint32_t version;
51  
52 #define SPA_DEVICE_CHANGE_MASK_FLAGS (1u<<0)
53 #define SPA_DEVICE_CHANGE_MASK_PROPS (1u<<1)
54 #define SPA_DEVICE_CHANGE_MASK_PARAMS (1u<<2)
55 uint64_t change_mask;
56 uint64_t flags;
57 const struct spa_dict *props; /**< device properties */
58 struct spa_param_info *params; /**< supported parameters */
59 uint32_t n_params; /**< number of elements in params */
60 };
61  
62 #define SPA_DEVICE_INFO_INIT() ((struct spa_device_info){ SPA_VERSION_DEVICE_INFO, })
63  
64 /**
65 * Information about a device object
66 *
67 * This information is part of the object_info event on the device.
68 */
69 struct spa_device_object_info {
70 #define SPA_VERSION_DEVICE_OBJECT_INFO 0
71 uint32_t version;
72  
73 const char *type; /**< the object type managed by this device */
74 const char *factory_name; /**< a factory name that implements the object */
75  
76 #define SPA_DEVICE_OBJECT_CHANGE_MASK_FLAGS (1u<<0)
77 #define SPA_DEVICE_OBJECT_CHANGE_MASK_PROPS (1u<<1)
78 uint64_t change_mask;
79 uint64_t flags;
80 const struct spa_dict *props; /**< extra object properties */
81 };
82  
83 #define SPA_DEVICE_OBJECT_INFO_INIT() ((struct spa_device_object_info){ SPA_VERSION_DEVICE_OBJECT_INFO, })
84  
85 /** the result of spa_device_enum_params() */
86 #define SPA_RESULT_TYPE_DEVICE_PARAMS 1
87 struct spa_result_device_params {
88 uint32_t id;
89 uint32_t index;
90 uint32_t next;
91 struct spa_pod *param;
92 };
93  
94 #define SPA_DEVICE_EVENT_INFO 0
95 #define SPA_DEVICE_EVENT_RESULT 1
96 #define SPA_DEVICE_EVENT_EVENT 2
97 #define SPA_DEVICE_EVENT_OBJECT_INFO 3
98 #define SPA_DEVICE_EVENT_NUM 4
99  
100 /**
101 * spa_device_events:
102 *
103 * Events are always emitted from the main thread
104 */
105 struct spa_device_events {
106 /** version of the structure */
107 #define SPA_VERSION_DEVICE_EVENTS 0
108 uint32_t version;
109  
110 /** notify extra information about the device */
111 void (*info) (void *data, const struct spa_device_info *info);
112  
113 /** notify a result */
114 void (*result) (void *data, int seq, int res, uint32_t type, const void *result);
115  
116 /** a device event */
117 void (*event) (void *data, const struct spa_event *event);
118  
119 /** info changed for an object managed by the device, info is NULL when
120 * the object is removed */
121 void (*object_info) (void *data, uint32_t id,
122 const struct spa_device_object_info *info);
123 };
124  
125 #define SPA_DEVICE_METHOD_ADD_LISTENER 0
126 #define SPA_DEVICE_METHOD_SYNC 1
127 #define SPA_DEVICE_METHOD_ENUM_PARAMS 2
128 #define SPA_DEVICE_METHOD_SET_PARAM 3
129 #define SPA_DEVICE_METHOD_NUM 4
130  
131 /**
132 * spa_device_methods:
133 */
134 struct spa_device_methods {
135 /* the version of the methods. This can be used to expand this
136 * structure in the future */
137 #define SPA_VERSION_DEVICE_METHODS 0
138 uint32_t version;
139  
140 /**
141 * Set events to receive asynchronous notifications from
142 * the device.
143 *
144 * Setting the events will trigger the info event and an
145 * object_info event for each managed object on the new
146 * listener.
147 *
148 * \param object a \ref spa_device
149 * \param listener a listener
150 * \param events a struct \ref spa_device_events
151 * \param data data passed as first argument in functions of \a events
152 * \return 0 on success
153 * < 0 errno on error
154 */
155 int (*add_listener) (void *object,
156 struct spa_hook *listener,
157 const struct spa_device_events *events,
158 void *data);
159 /**
160 * Perform a sync operation.
161 *
162 * This method will emit the result event with the given sequence
163 * number synchronously or with the returned async return value
164 * asynchronously.
165 *
166 * Because all methods are serialized in the device, this can be used
167 * to wait for completion of all previous method calls.
168 *
169 * \param seq a sequence number
170 * \return 0 on success
171 * -EINVAL when node is NULL
172 * an async result
173 */
174 int (*sync) (void *object, int seq);
175  
176 /**
177 * Enumerate the parameters of a device.
178 *
179 * Parameters are identified with an \a id. Some parameters can have
180 * multiple values, see the documentation of the parameter id.
181 *
182 * Parameters can be filtered by passing a non-NULL \a filter.
183 *
184 * The result callback will be called at most \a max times with a
185 * struct spa_result_device_params as the result.
186 *
187 * This function must be called from the main thread.
188 *
189 * \param device a \ref spa_device
190 * \param seq a sequence number to pass to the result function
191 * \param id the param id to enumerate
192 * \param index the index of enumeration, pass 0 for the first item.
193 * \param max the maximum number of items to iterate
194 * \param filter and optional filter to use
195 * \return 0 when there are no more parameters to enumerate
196 * -EINVAL when invalid arguments are given
197 * -ENOENT the parameter \a id is unknown
198 * -ENOTSUP when there are no parameters
199 * implemented on \a device
200 */
201 int (*enum_params) (void *object, int seq,
202 uint32_t id, uint32_t index, uint32_t max,
203 const struct spa_pod *filter);
204  
205 /**
206 * Set the configurable parameter in \a device.
207 *
208 * Usually, \a param will be obtained from enum_params and then
209 * modified but it is also possible to set another spa_pod
210 * as long as its keys and types match a supported object.
211 *
212 * Objects with property keys that are not known are ignored.
213 *
214 * This function must be called from the main thread.
215 *
216 * \param object \ref spa_device
217 * \param id the parameter id to configure
218 * \param flags additional flags
219 * \param param the parameter to configure
220 *
221 * \return 0 on success
222 * -EINVAL when invalid arguments are given
223 * -ENOTSUP when there are no parameters implemented on \a device
224 * -ENOENT the parameter is unknown
225 */
226 int (*set_param) (void *object,
227 uint32_t id, uint32_t flags,
228 const struct spa_pod *param);
229 };
230  
231 SPA_API_DEVICE int spa_device_add_listener(struct spa_device *object,
232 struct spa_hook *listener,
233 const struct spa_device_events *events,
234 void *data)
235 {
236 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, add_listener, 0,
237 listener, events, data);
238  
239 }
240 SPA_API_DEVICE int spa_device_sync(struct spa_device *object, int seq)
241 {
242 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, sync, 0,
243 seq);
244 }
245 SPA_API_DEVICE int spa_device_enum_params(struct spa_device *object, int seq,
246 uint32_t id, uint32_t index, uint32_t max,
247 const struct spa_pod *filter)
248 {
249 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, enum_params, 0,
250 seq, id, index, max, filter);
251 }
252 SPA_API_DEVICE int spa_device_set_param(struct spa_device *object,
253 uint32_t id, uint32_t flags,
254 const struct spa_pod *param)
255 {
256 return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, set_param, 0,
257 id, flags, param);
258 }
259  
260 #define SPA_KEY_DEVICE_ENUM_API "device.enum.api" /**< the api used to discover this
261 * device */
262 #define SPA_KEY_DEVICE_API "device.api" /**< the api used by the device
263 * Ex. "udev", "alsa", "v4l2". */
264 #define SPA_KEY_DEVICE_NAME "device.name" /**< the name of the device */
265 #define SPA_KEY_DEVICE_ALIAS "device.alias" /**< alternative name of the device */
266 #define SPA_KEY_DEVICE_NICK "device.nick" /**< the device short name */
267 #define SPA_KEY_DEVICE_DESCRIPTION "device.description" /**< a device description */
268 #define SPA_KEY_DEVICE_ICON "device.icon" /**< icon for the device. A base64 blob
269 * containing PNG image data */
270 #define SPA_KEY_DEVICE_ICON_NAME "device.icon-name" /**< an XDG icon name for the device.
271 * Ex. "sound-card-speakers-usb" */
272 #define SPA_KEY_DEVICE_PLUGGED_USEC "device.plugged.usec" /**< when the device was plugged */
273  
274 #define SPA_KEY_DEVICE_BUS_ID "device.bus-id" /**< the device bus-id */
275 #define SPA_KEY_DEVICE_BUS_PATH "device.bus-path" /**< bus path to the device in the OS'
276 * format.
277 * Ex. "pci-0000:00:14.0-usb-0:3.2:1.0" */
278 #define SPA_KEY_DEVICE_BUS "device.bus" /**< bus of the device if applicable. One of
279 * "isa", "pci", "usb", "firewire",
280 * "bluetooth" */
281 #define SPA_KEY_DEVICE_SUBSYSTEM "device.subsystem" /**< device subsystem */
282 #define SPA_KEY_DEVICE_SYSFS_PATH "device.sysfs.path" /**< device sysfs path */
283  
284 #define SPA_KEY_DEVICE_VENDOR_ID "device.vendor.id" /**< vendor ID if applicable */
285 #define SPA_KEY_DEVICE_VENDOR_NAME "device.vendor.name" /**< vendor name if applicable */
286 #define SPA_KEY_DEVICE_PRODUCT_ID "device.product.id" /**< product ID if applicable */
287 #define SPA_KEY_DEVICE_PRODUCT_NAME "device.product.name" /**< product name if applicable */
288 #define SPA_KEY_DEVICE_SERIAL "device.serial" /**< Serial number if applicable */
289 #define SPA_KEY_DEVICE_CLASS "device.class" /**< device class */
290 #define SPA_KEY_DEVICE_CAPABILITIES "device.capabilities" /**< api specific device capabilities */
291 #define SPA_KEY_DEVICE_FORM_FACTOR "device.form-factor" /**< form factor if applicable. One of
292 * "internal", "speaker", "handset", "tv",
293 * "webcam", "microphone", "headset",
294 * "headphone", "hands-free", "car", "hifi",
295 * "computer", "portable" */
296 #define SPA_KEY_DEVICE_PROFILE "device.profile" /**< profile for the device */
297 #define SPA_KEY_DEVICE_PROFILE_SET "device.profile-set" /**< profile set for the device */
298 #define SPA_KEY_DEVICE_STRING "device.string" /**< device string in the underlying
299 * layer's format. E.g. "surround51:0" */
300 #define SPA_KEY_DEVICE_DEVIDS "device.devids" /**< space separated list of device ids (dev_t) of the
301 * underlying device(s) if applicable */
302 /**
303 * \}
304 */
305  
306 #ifdef __cplusplus
307 } /* extern "C" */
308 #endif
309  
310 #endif /* SPA_DEVICE_H */