PipeWire: spa/monitor/utils.h Source File

PipeWire 1.2.3

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#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <spa/pod/builder.h>
13#include <spa/monitor/device.h>
14
20struct spa_result_device_params_data {
21 struct spa_pod_builder *builder;
22 struct spa_result_device_params data;
23};
24
25 static inline void spa_result_func_device_params(void *data, int seq SPA_UNUSED, int res SPA_UNUSED,
26 uint32_t type SPA_UNUSED, const void *result)
27{
28 struct spa_result_device_params_data *d =
29 (struct spa_result_device_params_data *)data;
30 const struct spa_result_device_params *r =
31 (const struct spa_result_device_params *)result;
32 uint32_t offset = d->builder->state.offset;
33 if (spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param)) < 0)
34 return;
35 d->data.next = r->next;
36 d->data.param = spa_pod_builder_deref(d->builder, offset);
37}
38
39static inline int spa_device_enum_params_sync(struct spa_device *device,
40 uint32_t id, uint32_t *index,
41 const struct spa_pod *filter,
42 struct spa_pod **param,
43 struct spa_pod_builder *builder)
44{
45 struct spa_result_device_params_data data = { builder, {0}};
46 struct spa_hook listener = {{0}, {0}, 0, 0};
47 static const struct spa_device_events device_events = {
48 .version = SPA_VERSION_DEVICE_EVENTS,
49 .info = NULL,
50 .result = spa_result_func_device_params,
51 };
52 int res;
53
54 spa_device_add_listener(device, &listener, &device_events, &data);
55 res = spa_device_enum_params(device, 0, id, *index, 1, filter);
56 spa_hook_remove(&listener);
57
58 if (data.data.param == NULL) {
59 if (res > 0)
60 res = 0;
61 } else {
62 *index = data.data.next;
63 *param = data.data.param;
64 res = 1;
65 }
66 return res;
67}
68
69#define spa_device_emit(hooks,method,version,...) \
70 spa_hook_list_call_simple(hooks, struct spa_device_events, \
71 method, version, ##__VA_ARGS__)
72
73#define spa_device_emit_info(hooks,i) spa_device_emit(hooks,info, 0, i)
74#define spa_device_emit_result(hooks,s,r,t,res) spa_device_emit(hooks,result, 0, s, r, t, res)
75#define spa_device_emit_event(hooks,e) spa_device_emit(hooks,event, 0, e)
76#define spa_device_emit_object_info(hooks,id,i) spa_device_emit(hooks,object_info, 0, id, i)
77
82#ifdef __cplusplus
83} /* extern "C" */
84#endif
85
86#endif /* SPA_DEVICE_UTILS_H */
builder.h
spa/pod/builder.h
spa_device_enum_params
#define spa_device_enum_params(d,...)
Enumerate the parameters of a device.
Definition device.h:268
spa_result_func_device_params
static void spa_result_func_device_params(void *data, int seq, int res 1, uint32_t type, const void *result)
Definition utils.h:30
spa_device_enum_params_sync
static 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:44
SPA_VERSION_DEVICE_EVENTS
#define SPA_VERSION_DEVICE_EVENTS
version of the structure
Definition device.h:122
spa_device_add_listener
#define spa_device_add_listener(d,...)
Set events to receive asynchronous notifications from the device.
Definition device.h:262
spa_hook_remove
static void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition hook.h:391
spa_pod_builder_raw_padded
static int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition builder.h:160
SPA_POD_SIZE
#define SPA_POD_SIZE(pod)
Definition pod.h:30
spa_pod_builder_deref
static struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition builder.h:93
SPA_UNUSED
#define SPA_UNUSED
Definition defs.h:307
device.h
spa/monitor/device.h
spa_device_events
spa_device_events:
Definition device.h:119
spa_device
Definition device.h:40
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition hook.h:350
spa_pod_builder_state::offset
uint32_t offset
Definition builder.h:33
spa_pod_builder
Definition builder.h:53
spa_pod_builder::state
struct spa_pod_builder_state state
Definition builder.h:57
spa_pod
Definition pod.h:43
spa_result_device_params_data
Definition utils.h:25
spa_result_device_params_data::data
struct spa_result_device_params data
Definition utils.h:27
spa_result_device_params_data::builder
struct spa_pod_builder * builder
Definition utils.h:26
spa_result_device_params
Definition device.h:96
spa_result_device_params::index
uint32_t index
Definition device.h:98
spa_result_device_params::next
uint32_t next
Definition device.h:99
spa_result_device_params::param
struct spa_pod * param
Definition device.h:100