PipeWire  0.3.33
build-12683127/doc/spa/monitor/utils.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2019 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef SPA_DEVICE_UTILS_H
26 #define SPA_DEVICE_UTILS_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <spa/pod/builder.h>
33 #include <spa/monitor/device.h>
34 
38 };
39 
40 /* static */ inline void spa_result_func_device_params(void *data, int seq, int res,
41  uint32_t type, const void *result)
42 {
45  const struct spa_result_device_params *r =
46  (const struct spa_result_device_params *)result;
47  uint32_t offset = d->builder->state.offset;
49  d->data.next = r->next;
50  d->data.param = SPA_PTROFF(d->builder->data, offset, struct spa_pod);
51 }
52 
53 /* static */ inline int spa_device_enum_params_sync(struct spa_device *device,
54  uint32_t id, uint32_t *index,
55  const struct spa_pod *filter,
56  struct spa_pod **param,
57  struct spa_pod_builder *builder)
58 {
60  struct spa_hook listener = {{0}};
61  static const struct spa_device_events device_events = {
63  .info = NULL,
65  };
66  int res;
67 
68  spa_device_add_listener(device, &listener, &device_events, &data);
69  res = spa_device_enum_params(device, 0, id, *index, 1, filter);
70  spa_hook_remove(&listener);
71 
72  if (data.data.param == NULL) {
73  if (res > 0)
74  res = 0;
75  } else {
76  *index = data.data.next;
77  *param = data.data.param;
78  res = 1;
79  }
80  return res;
81 }
82 
83 #define spa_device_emit(hooks,method,version,...) \
84  spa_hook_list_call_simple(hooks, struct spa_device_events, \
85  method, version, ##__VA_ARGS__)
86 
87 #define spa_device_emit_info(hooks,i) spa_device_emit(hooks,info, 0, i)
88 #define spa_device_emit_result(hooks,s,r,t,res) spa_device_emit(hooks,result, 0, s, r, t, res)
89 #define spa_device_emit_event(hooks,e) spa_device_emit(hooks,event, 0, e)
90 #define spa_device_emit_object_info(hooks,id,i) spa_device_emit(hooks,object_info, 0, id, i)
91 
92 #ifdef __cplusplus
93 } /* extern "C" */
94 #endif
95 
96 #endif /* SPA_DEVICE_UTILS_H */
spa_result_func_device_params
void spa_result_func_device_params(void *data, int seq, int res, uint32_t type, const void *result)
Definition: build-12683127/doc/spa/monitor/utils.h:40
spa_pod_builder_raw_padded
int spa_pod_builder_raw_padded(struct spa_pod_builder *builder, const void *data, uint32_t size)
Definition: builder.h:167
spa_device
Definition: build-12683127/doc/spa/monitor/device.h:53
spa_pod_builder::state
struct spa_pod_builder_state state
Definition: builder.h:67
data
user data to add to an object
Definition: filter.c:75
spa_result_device_params::param
struct spa_pod * param
Definition: build-12683127/doc/spa/monitor/device.h:103
device
Definition: alsa-monitor.c:82
spa_device_enum_params_sync
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: build-12683127/doc/spa/monitor/utils.h:53
spa_result_device_params
Definition: build-12683127/doc/spa/monitor/device.h:99
SPA_PTROFF
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition: defs.h:159
spa_device_events::version
uint32_t version
Definition: build-12683127/doc/spa/monitor/device.h:120
spa_result_device_params_data
Definition: build-12683127/doc/spa/monitor/utils.h:35
spa_pod_builder::data
void * data
Definition: builder.h:64
spa_pod
Definition: pod/pod.h:50
spa_device_enum_params
#define spa_device_enum_params(d,...)
Definition: build-12683127/doc/spa/monitor/device.h:255
filter
Definition: filter.c:126
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:295
param
Definition: filter.c:80
spa_result_device_params::next
uint32_t next
Definition: build-12683127/doc/spa/monitor/device.h:102
spa_hook_remove
void spa_hook_remove(struct spa_hook *hook)
Remove a hook.
Definition: hook.h:336
SPA_POD_SIZE
#define SPA_POD_SIZE(pod)
Definition: pod/pod.h:42
SPA_VERSION_DEVICE_EVENTS
#define SPA_VERSION_DEVICE_EVENTS
version of the structure
Definition: build-12683127/doc/spa/monitor/device.h:119
spa_device_add_listener
#define spa_device_add_listener(d,...)
Definition: build-12683127/doc/spa/monitor/device.h:253
spa_result_device_params_data::data
struct spa_result_device_params data
Definition: build-12683127/doc/spa/monitor/utils.h:37
spa_result_device_params_data::builder
struct spa_pod_builder * builder
Definition: build-12683127/doc/spa/monitor/utils.h:36
spa_device_events
spa_device_events:
Definition: build-12683127/doc/spa/monitor/device.h:117
spa_pod_builder
Definition: builder.h:63
spa_result_device_params::index
uint32_t index
Definition: build-12683127/doc/spa/monitor/device.h:101
spa_pod_builder_state::offset
uint32_t offset
Definition: builder.h:47
builder.h
device.h