PipeWire  0.3.67
spa/include/spa/monitor/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
9 extern "C" {
10 #endif
11 
12 #include <spa/pod/builder.h>
13 #include <spa/monitor/device.h>
14 
21  struct spa_pod_builder *builder;
23 };
24 
25 static inline void spa_result_func_device_params(void *data, int seq, int res,
26  uint32_t type, const void *result)
27 {
30  const struct spa_result_device_params *r =
31  (const struct spa_result_device_params *)result;
32  uint32_t offset = d->builder->state.offset;
34  return;
35  d->data.next = r->next;
36  d->data.param = spa_pod_builder_deref(d->builder, offset);
37 }
38 
39 static 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 {
46  struct spa_hook listener = {{0}};
47  static const struct spa_device_events device_events = {
49  .info = NULL,
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 */
spa/pod/builder.h
#define spa_device_enum_params(d,...)
Enumerate the parameters of a device.
Definition: spa/include/spa/monitor/device.h:268
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: spa/include/spa/monitor/utils.h:44
#define SPA_VERSION_DEVICE_EVENTS
version of the structure
Definition: spa/include/spa/monitor/device.h:122
#define spa_device_add_listener(d,...)
Set events to receive asynchronous notifications from the device.
Definition: spa/include/spa/monitor/device.h:262
static void spa_result_func_device_params(void *data, int seq, int res, uint32_t type, const void *result)
Definition: spa/include/spa/monitor/utils.h:30
static void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition: hook.h:372
static int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition: builder.h:160
#define SPA_POD_SIZE(pod)
Definition: pod/pod.h:30
static struct spa_pod * spa_pod_builder_deref(struct spa_pod_builder *builder, uint32_t offset)
Definition: builder.h:93
spa/monitor/device.h
spa_device_events:
Definition: spa/include/spa/monitor/device.h:119
uint32_t version
Definition: spa/include/spa/monitor/device.h:123
Definition: spa/include/spa/monitor/device.h:40
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:331
uint32_t offset
Definition: builder.h:33
Definition: builder.h:53
struct spa_pod_builder_state state
Definition: builder.h:57
Definition: pod/pod.h:43
Definition: spa/include/spa/monitor/utils.h:25
struct spa_result_device_params data
Definition: spa/include/spa/monitor/utils.h:27
struct spa_pod_builder * builder
Definition: spa/include/spa/monitor/utils.h:26
Definition: spa/include/spa/monitor/device.h:96
uint32_t index
Definition: spa/include/spa/monitor/device.h:98
uint32_t next
Definition: spa/include/spa/monitor/device.h:99
struct spa_pod * param
Definition: spa/include/spa/monitor/device.h:100