PipeWire 1.6.8

Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_DEVICE_UTILS_H
6#define SPA_DEVICE_UTILS_H
7
8#include <spa/pod/builder.h>
9#include <spa/monitor/device.h>
10
11#ifdef __cplusplus
12 extern "C" {
13#endif
14
15#ifndef SPA_API_DEVICE_UTILS
16 #ifdef SPA_API_IMPL
17 #define SPA_API_DEVICE_UTILS SPA_API_IMPL
18 #else
19 #define SPA_API_DEVICE_UTILS static inline
20 #endif
21#endif
22
27
28 struct spa_result_device_params_data {
29 struct spa_pod_builder *builder;
30 struct spa_result_device_params data;
31};
32
33 SPA_API_DEVICE_UTILS void spa_result_func_device_params(void *data, int seq SPA_UNUSED, int res SPA_UNUSED,
34 uint32_t type SPA_UNUSED, const void *result)
35{
36 struct spa_result_device_params_data *d =
37 (struct spa_result_device_params_data *)data;
38 const struct spa_result_device_params *r =
39 (const struct spa_result_device_params *)result;
40 uint32_t offset = d->builder->state.offset;
41 if (spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param)) < 0)
42 return;
43 d->data.next = r->next;
44 d->data.param = spa_pod_builder_deref(d->builder, offset);
45}
46
47 SPA_API_DEVICE_UTILS int spa_device_enum_params_sync(struct spa_device *device,
48 uint32_t id, uint32_t *index,
49 const struct spa_pod *filter,
50 struct spa_pod **param,
51 struct spa_pod_builder *builder)
52{
53 struct spa_result_device_params_data data = { builder, {0}};
54 struct spa_hook listener = {{0}, {0}, 0, 0};
55 static const struct spa_device_events device_events = {
56 .version = SPA_VERSION_DEVICE_EVENTS,
57 .info = NULL,
58 .result = spa_result_func_device_params,
59 };
60 int res;
61
62 spa_device_add_listener(device, &listener, &device_events, &data);
63 res = spa_device_enum_params(device, 0, id, *index, 1, filter);
64 spa_hook_remove(&listener);
65
66 if (data.data.param == NULL) {
67 if (res > 0)
68 res = 0;
69 } else {
70 *index = data.data.next;
71 *param = data.data.param;
72 res = 1;
73 }
74 return res;
75}
76
77#define spa_device_emit(hooks,method,version,...) \
78 spa_hook_list_call_simple(hooks, struct spa_device_events, \
79 method, version, ##__VA_ARGS__)
80
81#define spa_device_emit_info(hooks,i) spa_device_emit(hooks,info, 0, i)
82#define spa_device_emit_result(hooks,s,r,t,res) spa_device_emit(hooks,result, 0, s, r, t, res)
83#define spa_device_emit_event(hooks,e) spa_device_emit(hooks,event, 0, e)
84#define spa_device_emit_object_info(hooks,id,i) spa_device_emit(hooks,object_info, 0, id, i)
85
87
89
90#ifdef __cplusplus
91} /* extern "C" */
92#endif
93
94#endif /* SPA_DEVICE_UTILS_H */
builder.h
spa/pod/builder.h
seq
uint32_t int seq
Definition core.h:432
r
uint32_t int int const char int r
Definition core.h:447
res
uint32_t int int res
Definition core.h:433
spa_device_enum_params
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:276
SPA_VERSION_DEVICE_EVENTS
#define SPA_VERSION_DEVICE_EVENTS
version of the structure
Definition device.h:132
spa_device_add_listener
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:262
spa_result_func_device_params
SPA_API_DEVICE_UTILS void spa_result_func_device_params(void *data, int seq, int res 1, uint32_t type, const void *result)
Definition utils.h:40
spa_device_enum_params_sync
SPA_API_DEVICE_UTILS int spa_device_enum_params_sync(struct spa_device *device, uint32_t id, uint32_t *index, const struct spa_pod *filter, struct spa_pod **param, struct spa_pod_builder *builder)
Definition utils.h:54
spa_hook_remove
SPA_API_HOOK void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition hook.h:468
spa_pod_builder_deref
SPA_API_POD_BUILDER struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition builder.h:121
spa_pod_builder_raw_padded
SPA_API_POD_BUILDER int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition builder.h:205
SPA_POD_SIZE
#define SPA_POD_SIZE(pod)
Definition pod.h:35
SPA_UNUSED
#define SPA_UNUSED
Definition defs.h:309
device.h
spa/monitor/device.h
SPA_API_DEVICE_UTILS
#define SPA_API_DEVICE_UTILS
Definition utils.h:26
spa_device_events
spa_device_events:
Definition device.h:129
spa_device
Definition device.h:50
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition hook.h:427
spa_pod_builder_state::offset
uint32_t offset
Definition builder.h:43
spa_pod_builder
Definition builder.h:63
spa_pod_builder::state
struct spa_pod_builder_state state
Definition builder.h:67
spa_pod
Definition pod.h:57
spa_result_device_params_data
Definition utils.h:35
spa_result_device_params_data::data
struct spa_result_device_params data
Definition utils.h:37
spa_result_device_params_data::builder
struct spa_pod_builder * builder
Definition utils.h:36
spa_result_device_params
Definition device.h:106
spa_result_device_params::index
uint32_t index
Definition device.h:108
spa_result_device_params::next
uint32_t next
Definition device.h:109
spa_result_device_params::param
struct spa_pod * param
Definition device.h:110