Debian Codegraph @

lib/wp/private/pipewire-object-mixin.h

raw
1 /* WirePlumber
2 *
3 * Copyright © 2020 Collabora Ltd.
4 * @author George Kiagiadakis <[email protected]>
5 *
6 * SPDX-License-Identifier: MIT
7 */
8
9 #ifndef __WIREPLUMBER_PIPEWIRE_OBJECT_MIXIN_H__
10 #define __WIREPLUMBER_PIPEWIRE_OBJECT_MIXIN_H__
11
12 #include "proxy-interfaces.h"
13
14 #include <pipewire/pipewire.h>
15
16 G_BEGIN_DECLS
17
18 enum {
19 /* this is the same STEP_BIND as in WpGlobalProxy */
20 WP_PW_OBJECT_MIXIN_STEP_BIND = WP_TRANSITION_STEP_CUSTOM_START,
21 WP_PW_OBJECT_MIXIN_STEP_WAIT_INFO,
22 WP_PW_OBJECT_MIXIN_STEP_CACHE_PARAMS,
23
24 WP_PW_OBJECT_MIXIN_STEP_CUSTOM_START,
25 };
26
27 enum {
28 WP_PW_OBJECT_MIXIN_PROP_0,
29
30 // WpPipewireObject
31 WP_PW_OBJECT_MIXIN_PROP_NATIVE_INFO,
32 WP_PW_OBJECT_MIXIN_PROP_PROPERTIES,
33 WP_PW_OBJECT_MIXIN_PROP_PARAM_INFO,
34
35 WP_PW_OBJECT_MIXIN_PROP_CUSTOM_START,
36 };
37
38 #define WP_TYPE_PW_OBJECT_MIXIN_PRIV (wp_pw_object_mixin_priv_get_type ())
39 G_DECLARE_INTERFACE (WpPwObjectMixinPriv, wp_pw_object_mixin_priv,
40 WP, PW_OBJECT_MIXIN_PRIV, WpProxy)
41
42 struct _WpPwObjectMixinPrivInterface
43 {
44 GTypeInterface parent;
45
46 /* WpPwObjectMixinPriv-specific flags */
47 #define WP_PW_OBJECT_MIXIN_PRIV_NO_PARAM_CACHE (1 << 0)
48 guint32 flags;
49
50 /* pipewire info struct abstraction layer */
51 gsize info_size;
52 gsize change_mask_offset;
53 gsize props_offset;
54 gsize param_info_offset;
55 gsize n_params_offset;
56
57 guint64 CHANGE_MASK_ALL;
58 guint64 CHANGE_MASK_PROPS;
59 guint64 CHANGE_MASK_PARAMS;
60
61 gpointer (*update_info) (gpointer info, gconstpointer update);
62 void (*free_info) (gpointer info);
63
64 /* to further process info struct updates - for proxy objects only */
65 void (*process_info) (gpointer instance, gpointer old_info, gpointer info);
66
67 /* pipewire interface methods - proxy & impl */
68 gint (*enum_params) (gpointer instance, guint32 id,
69 guint32 start, guint32 num, WpSpaPod *filter);
70 GPtrArray * (*enum_params_sync) (gpointer instance, guint32 id,
71 guint32 start, guint32 num, WpSpaPod *filter);
72 gint (*set_param) (gpointer instance, guint32 id, guint32 flags,
73 WpSpaPod *param /* transfer full */);
74
75 /* pipewire interface events - for impl objects only */
76 void (*emit_info) (struct spa_hook_list * hooks, gconstpointer info);
77 void (*emit_param) (struct spa_hook_list * hooks, int seq,
78 guint32 id, guint32 index, guint32 next, const struct spa_pod *param);
79 };
80
81 /* fills in info struct abstraction layer in WpPwObjectMixinPrivInterface */
82 #define wp_pw_object_mixin_priv_interface_info_init(iface, type, TYPE) \
83 ({ \
84 iface->info_size = sizeof (struct pw_ ## type ## _info); \
85 iface->change_mask_offset = G_STRUCT_OFFSET (struct pw_ ## type ## _info, change_mask); \
86 iface->props_offset = G_STRUCT_OFFSET (struct pw_ ## type ## _info, props); \
87 iface->param_info_offset = G_STRUCT_OFFSET (struct pw_ ## type ## _info, params); \
88 iface->n_params_offset = G_STRUCT_OFFSET (struct pw_ ## type ## _info, n_params); \
89 iface->CHANGE_MASK_ALL = PW_ ## TYPE ## _CHANGE_MASK_ALL; \
90 iface->CHANGE_MASK_PROPS = PW_ ## TYPE ## _CHANGE_MASK_PROPS; \
91 iface->CHANGE_MASK_PARAMS = PW_ ## TYPE ## _CHANGE_MASK_PARAMS; \
92 iface->update_info = (gpointer (*)(gpointer, gconstpointer)) pw_ ## type ## _info_update; \
93 iface->free_info = (void (*)(gpointer)) pw_ ## type ## _info_free; \
94 })
95
96 /* same as above, for types that don't have params */
97 #define wp_pw_object_mixin_priv_interface_info_init_no_params(iface, type, TYPE) \
98 ({ \
99 iface->flags = WP_PW_OBJECT_MIXIN_PRIV_NO_PARAM_CACHE; \
100 iface->info_size = sizeof (struct pw_ ## type ## _info); \
101 iface->change_mask_offset = G_STRUCT_OFFSET (struct pw_ ## type ## _info, change_mask); \
102 iface->props_offset = G_STRUCT_OFFSET (struct pw_ ## type ## _info, props); \
103 iface->param_info_offset = 0; \
104 iface->n_params_offset = 0; \
105 iface->CHANGE_MASK_ALL = PW_ ## TYPE ## _CHANGE_MASK_ALL; \
106 iface->CHANGE_MASK_PROPS = PW_ ## TYPE ## _CHANGE_MASK_PROPS; \
107 iface->CHANGE_MASK_PARAMS = 0; \
108 iface->update_info = (gpointer (*)(gpointer, gconstpointer)) pw_ ## type ## _info_update; \
109 iface->free_info = (void (*)(gpointer)) pw_ ## type ## _info_free; \
110 })
111
112 /*************/
113 /* INTERFACE */
114
115 /* implements WpPipewireObject for an object that implements WpPwObjectMixinPriv */
116 void wp_pw_object_mixin_object_interface_init (WpPipewireObjectInterface * iface);
117
118 /********/
119 /* DATA */
120
121 typedef struct _WpPwObjectMixinData WpPwObjectMixinData;
122 struct _WpPwObjectMixinData
123 {
124 gpointer info; /* pointer to the info struct */
125 gpointer iface; /* pointer to the interface (ex. pw_node) */
126 struct spa_hook listener;
127 struct spa_hook_list hooks;
128 WpProperties *properties;
129 GList *enum_params_tasks; /* element-type: GTask* */
130 GList *params; /* element-type: WpPwObjectMixinParamStore* */
131 GArray *subscribed_ids; /* element-type: guint32 */
132 };
133
134 /* get mixin data (stored as qdata on the @em instance) */
135 WpPwObjectMixinData * wp_pw_object_mixin_get_data (gpointer instance);
136
137 /****************/
138 /* PARAMS STORE */
139
140 /* param store access; (transfer container) */
141 GPtrArray * wp_pw_object_mixin_get_stored_params (WpPwObjectMixinData * data,
142 guint32 id);
143
144 /* param store manipulation
145 * @em flags: see below
146 * @em param: (transfer full): WpSpaPod* or GPtrArray* */
147 void wp_pw_object_mixin_store_param (WpPwObjectMixinData * data, guint32 id,
148 guint32 flags, gpointer param);
149
150 /* set the index at which to store the new param */
151 #define WP_PW_OBJECT_MIXIN_STORE_PARAM_SET(x) ((x) & 0x7fff)
152 #define WP_PW_OBJECT_MIXIN_STORE_PARAM_APPEND (0xffff)
153 #define WP_PW_OBJECT_MIXIN_STORE_PARAM_PREPEND (0)
154 /* @em param is a GPtrArray* */
155 #define WP_PW_OBJECT_MIXIN_STORE_PARAM_ARRAY (1 << 16)
156 /* clear the existing array of params before storing */
157 #define WP_PW_OBJECT_MIXIN_STORE_PARAM_CLEAR (1 << 17)
158 /* completely remove stored params for @id */
159 #define WP_PW_OBJECT_MIXIN_STORE_PARAM_REMOVE (1 << 18)
160
161 /******************/
162 /* PROPERTIES API */
163
164 /* assign to get_property or chain it from there */
165 void wp_pw_object_mixin_get_property (GObject * object, guint property_id,
166 GValue * value, GParamSpec * pspec);
167
168 /* call from class_init */
169 void wp_pw_object_mixin_class_override_properties (GObjectClass * klass);
170
171 /****************/
172 /* FEATURES API */
173
174 /* call from get_supported_features */
175 WpObjectFeatures wp_pw_object_mixin_get_supported_features (WpObject * object);
176
177 /* assign directly to activate_get_next_step */
178 guint wp_pw_object_mixin_activate_get_next_step (WpObject * object,
179 WpFeatureActivationTransition * transition, guint step,
180 WpObjectFeatures missing);
181
182 /* call from activate_execute_step when
183 step == WP_PW_OBJECT_MIXIN_STEP_CACHE_PARAMS */
184 void wp_pw_object_mixin_cache_params (WpObject * object,
185 WpObjectFeatures missing);
186
187 /* handle deactivation of PARAM_* caching features */
188 void wp_pw_object_mixin_deactivate (WpObject * object,
189 WpObjectFeatures features);
190
191 /************************/
192 /* PROXY EVENT HANDLERS */
193 /* (for proxy objects) */
194
195 #define wp_pw_object_mixin_handle_pw_proxy_created(instance, pw_proxy, type, events) \
196 ({ \
197 WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (instance); \
198 d->iface = pw_proxy; \
199 pw_ ## type ## _add_listener ((struct pw_ ## type *) pw_proxy, \
200 &d->listener, events, instance); \
201 })
202
203 void wp_pw_object_mixin_handle_pw_proxy_destroyed (WpProxy * proxy);
204
205 /***************************/
206 /* PIPEWIRE EVENT HANDLERS */
207 /* (for proxy objects) */
208
209 #define HandleEventInfoFunc(type) \
210 void (*)(void *, const struct pw_ ## type ## _info *)
211
212 void wp_pw_object_mixin_handle_event_info (gpointer instance, gconstpointer info);
213
214 /* assign as the param event callback */
215 void wp_pw_object_mixin_handle_event_param (gpointer instance, int seq,
216 guint32 id, guint32 index, guint32 next, const struct spa_pod *param);
217
218 /***********************************/
219 /* PIPEWIRE METHOD IMPLEMENTATIONS */
220 /* (for impl objects) */
221
222 #define ImplAddListenerFunc(type) \
223 int (*)(void *, struct spa_hook *, const struct pw_ ## type ## _events *, void *)
224
225 int wp_pw_object_mixin_impl_add_listener (gpointer instance,
226 struct spa_hook *listener, gconstpointer events, gpointer data);
227
228 int wp_pw_object_mixin_impl_enum_params (gpointer instance, int seq,
229 guint32 id, guint32 start, guint32 num, const struct spa_pod *filter);
230
231 int wp_pw_object_mixin_impl_subscribe_params (gpointer instance,
232 guint32 *ids, guint32 n_ids);
233
234 int wp_pw_object_mixin_impl_set_param (gpointer instance, guint32 id,
235 guint32 flags, const struct spa_pod *param);
236
237 /**********************/
238 /* NOTIFIERS */
239 /* (for impl objects) */
240
241 void wp_pw_object_mixin_notify_info (gpointer instance, guint32 change_mask);
242
243 void wp_pw_object_mixin_notify_params_changed (gpointer instance, guint32 id);
244
245 G_END_DECLS
246
247 #endif