+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
c · 247 lines · 6.9 KB · SPDX: MIT
main
1 /* Simple Plugin API */
2 /* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4  
5 #ifndef SPA_PLUGIN_H
6 #define SPA_PLUGIN_H
7  
8 #include <errno.h>
9  
10 #include <spa/utils/defs.h>
11 #include <spa/utils/hook.h>
12 #include <spa/utils/dict.h>
13  
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17  
18 #ifndef SPA_API_PLUGIN
19 #ifdef SPA_API_IMPL
20 #define SPA_API_PLUGIN SPA_API_IMPL
21 #else
22 #define SPA_API_PLUGIN static inline
23 #endif
24 #endif
25  
26 /**
27 * \defgroup spa_handle Plugin Handle
28 * SPA plugin handle and factory interfaces
29 */
30  
31 /**
32 * \addtogroup spa_handle
33 * \{
34 */
35  
36 struct spa_handle {
37 /** Version of this struct */
38 #define SPA_VERSION_HANDLE 0
39 uint32_t version;
40  
41 /**
42 * Get the interface provided by \a handle with \a type.
43 *
44 * \a interface is always a struct spa_interface but depending on
45 * \a type, the struct might contain other information.
46 *
47 * \param handle a spa_handle
48 * \param type the interface type
49 * \param iface result to hold the interface.
50 * \return 0 on success
51 * -ENOTSUP when there are no interfaces
52 * -EINVAL when handle or info is NULL
53 */
54 int (*get_interface) (struct spa_handle *handle, const char *type, void **iface);
55 /**
56 * Clean up the memory of \a handle. After this, \a handle should not be used
57 * anymore.
58 *
59 * \param handle a pointer to memory
60 * \return 0 on success
61 */
62 int (*clear) (struct spa_handle *handle);
63 };
64  
65 SPA_API_PLUGIN int
66 spa_handle_get_interface(struct spa_handle *object,
67 const char *type, void **iface)
68 {
69 return spa_api_func_r(int, -ENOTSUP, object, get_interface, 0, type, iface);
70 }
71 SPA_API_PLUGIN int
72 spa_handle_clear(struct spa_handle *object)
73 {
74 return spa_api_func_r(int, -ENOTSUP, object, clear, 0);
75 }
76  
77 /**
78 * This structure lists the information about available interfaces on
79 * handles.
80 */
81 struct spa_interface_info {
82 const char *type; /*< the type of the interface, can be
83 * used to get the interface */
84 };
85  
86 /**
87 * Extra supporting infrastructure passed to the init() function of
88 * a factory. It can be extra information or interfaces such as logging.
89 */
90 struct spa_support {
91 const char *type; /*< the type of the support item */
92 void *data; /*< specific data for the item */
93 };
94  
95 /** Find a support item of the given type */
96 SPA_API_PLUGIN void *spa_support_find(const struct spa_support *support,
97 uint32_t n_support,
98 const char *type)
99 {
100 uint32_t i;
101 for (i = 0; i < n_support; i++) {
102 if (strcmp(support[i].type, type) == 0)
103 return support[i].data;
104 }
105 return NULL;
106 }
107  
108 #define SPA_SUPPORT_INIT(type,data) ((struct spa_support) { (type), (data) })
109  
110 struct spa_handle_factory {
111 /** The version of this structure */
112 #define SPA_VERSION_HANDLE_FACTORY 1
113 uint32_t version;
114 /**
115 * The name of the factory contains a logical name that describes
116 * the function of the handle. Other plugins might contain an alternative
117 * implementation with the same name.
118 *
119 * See utils/names.h for the list of standard names.
120 *
121 * Examples include:
122 *
123 * api.alsa.pcm.sink: an object to write PCM samples to an alsa PLAYBACK
124 * device
125 * api.v4l2.source: an object to read from a v4l2 source.
126 */
127 const char *name;
128 /**
129 * Extra information about the handles of this factory.
130 */
131 const struct spa_dict *info;
132 /**
133 * Get the size of handles from this factory.
134 *
135 * \param factory a spa_handle_factory
136 * \param params extra parameters that determine the size of the
137 * handle.
138 */
139 size_t (*get_size) (const struct spa_handle_factory *factory,
140 const struct spa_dict *params);
141  
142 /**
143 * Initialize an instance of this factory. The caller should allocate
144 * memory at least size bytes and pass this as \a handle.
145 *
146 * \a support can optionally contain extra interfaces or data items that the
147 * plugin can use such as a logger.
148 *
149 * \param factory a spa_handle_factory
150 * \param handle a pointer to memory
151 * \param info extra handle specific information, usually obtained
152 * from a spa_device. This can be used to configure the handle.
153 * \param support support items
154 * \param n_support number of elements in \a support
155 * \return 0 on success
156 * < 0 errno type error
157 */
158 int (*init) (const struct spa_handle_factory *factory,
159 struct spa_handle *handle,
160 const struct spa_dict *info,
161 const struct spa_support *support,
162 uint32_t n_support);
163  
164 /**
165 * spa_handle_factory::enum_interface_info:
166 * \param factory: a #spa_handle_factory
167 * \param info: result to hold spa_interface_info.
168 * \param index: index to keep track of the enumeration, 0 for first item
169 *
170 * Enumerate the interface information for \a factory.
171 *
172 * \return 1 when an item is available
173 * 0 when no more items are available
174 * < 0 errno type error
175 */
176 int (*enum_interface_info) (const struct spa_handle_factory *factory,
177 const struct spa_interface_info **info,
178 uint32_t *index);
179 };
180  
181 SPA_API_PLUGIN size_t
182 spa_handle_factory_get_size(const struct spa_handle_factory *object,
183 const struct spa_dict *params)
184 {
185 return spa_api_func_r(size_t, 0, object, get_size, 1, params);
186 }
187 SPA_API_PLUGIN int
188 spa_handle_factory_init(const struct spa_handle_factory *object,
189 struct spa_handle *handle, const struct spa_dict *info,
190 const struct spa_support *support, uint32_t n_support)
191 {
192 return spa_api_func_r(int, -ENOTSUP, object, init, 1, handle, info,
193 support, n_support);
194 }
195 SPA_API_PLUGIN int
196 spa_handle_factory_enum_interface_info(const struct spa_handle_factory *object,
197 const struct spa_interface_info **info, uint32_t *index)
198 {
199 return spa_api_func_r(int, -ENOTSUP, object, enum_interface_info, 1,
200 info, index);
201 }
202  
203 /**
204 * The function signature of the entry point in a plugin.
205 *
206 * \param factory a location to hold the factory result
207 * \param index index to keep track of the enumeration
208 * \return 1 on success
209 * 0 when there are no more factories
210 * -EINVAL when factory is NULL
211 */
212 typedef int (*spa_handle_factory_enum_func_t) (const struct spa_handle_factory **factory,
213 uint32_t *index);
214  
215 #define SPA_HANDLE_FACTORY_ENUM_FUNC_NAME "spa_handle_factory_enum"
216  
217 /**
218 * The entry point in a plugin.
219 *
220 * \param factory a location to hold the factory result
221 * \param index index to keep track of the enumeration
222 * \return 1 on success
223 * 0 when no more items are available
224 * < 0 errno type error
225 */
226 int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index);
227  
228  
229  
230 #define SPA_KEY_FACTORY_NAME "factory.name" /**< the name of a factory */
231 #define SPA_KEY_FACTORY_AUTHOR "factory.author" /**< a comma separated list of factory authors */
232 #define SPA_KEY_FACTORY_DESCRIPTION "factory.description" /**< description of a factory */
233 #define SPA_KEY_FACTORY_USAGE "factory.usage" /**< usage of a factory */
234  
235 #define SPA_KEY_LIBRARY_NAME "library.name" /**< the name of a library. This is usually
236 * the filename of the plugin without the
237 * path or the plugin extension. */
238  
239 /**
240 * \}
241 */
242  
243 #ifdef __cplusplus
244 } /* extern "C" */
245 #endif
246  
247 #endif /* SPA_PLUGIN_H */