PipeWire 1.4.1
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
plugin.h
Go to the documentation of this file.
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#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <errno.h>
13
14#include <spa/utils/defs.h>
15#include <spa/utils/hook.h>
16#include <spa/utils/dict.h>
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
36struct spa_handle {
38#define SPA_VERSION_HANDLE 0
39 uint32_t version;
40
54 int (*get_interface) (struct spa_handle *handle, const char *type, void **iface);
62 int (*clear) (struct spa_handle *handle);
63};
64
67 const char *type, void **iface)
68{
69 return spa_api_func_r(int, -ENOTSUP, object, get_interface, 0, type, iface);
72spa_handle_clear(struct spa_handle *object)
73{
74 return spa_api_func_r(int, -ENOTSUP, object, clear, 0);
75}
76
81struct spa_interface_info {
82 const char *type; /*< the type of the interface, can be
83 * used to get the interface */
84};
85
91 const char *type; /*< the type of the support item */
92 void *data; /*< specific data for the item */
93};
94
96SPA_API_PLUGIN void *spa_support_find(const struct spa_support *support,
97 uint32_t n_support,
98 const char *type)
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;
105 return NULL;
106}
107
108#define SPA_SUPPORT_INIT(type,data) ((struct spa_support) { (type), (data) })
109
110struct spa_handle_factory {
112#define SPA_VERSION_HANDLE_FACTORY 1
113 uint32_t version;
127 const char *name;
131 const struct spa_dict *info;
139 size_t (*get_size) (const struct spa_handle_factory *factory,
140 const struct spa_dict *params);
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
176 int (*enum_interface_info) (const struct spa_handle_factory *factory,
177 const struct spa_interface_info **info,
178 uint32_t *index);
179};
180
181SPA_API_PLUGIN size_t
183 const struct spa_dict *params)
184{
185 return spa_api_func_r(size_t, 0, object, get_size, 1, params);
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}
197 const struct spa_interface_info **info, uint32_t *index)
199 return spa_api_func_r(int, -ENOTSUP, object, enum_interface_info, 1,
200 info, index);
201}
202
212typedef 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
226int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index);
227
228
229
230#define SPA_KEY_FACTORY_NAME "factory.name"
231#define SPA_KEY_FACTORY_AUTHOR "factory.author"
232#define SPA_KEY_FACTORY_DESCRIPTION "factory.description"
233#define SPA_KEY_FACTORY_USAGE "factory.usage"
235#define SPA_KEY_LIBRARY_NAME "library.name"
243#ifdef __cplusplus
244} /* extern "C" */
245#endif
247#endif /* SPA_PLUGIN_H */
spa/utils/defs.h
int(* spa_handle_factory_enum_func_t)(const struct spa_handle_factory **factory, uint32_t *index)
The function signature of the entry point in a plugin.
Definition plugin.h:222
SPA_API_PLUGIN size_t spa_handle_factory_get_size(const struct spa_handle_factory *object, const struct spa_dict *params)
Definition plugin.h:192
SPA_API_PLUGIN int spa_handle_get_interface(struct spa_handle *object, const char *type, void **iface)
Definition plugin.h:74
SPA_API_PLUGIN void * spa_support_find(const struct spa_support *support, uint32_t n_support, const char *type)
Find a support item of the given type.
Definition plugin.h:104
SPA_API_PLUGIN int spa_handle_factory_enum_interface_info(const struct spa_handle_factory *object, const struct spa_interface_info **info, uint32_t *index)
Definition plugin.h:206
SPA_API_PLUGIN int spa_handle_clear(struct spa_handle *object)
Definition plugin.h:80
SPA_API_PLUGIN int spa_handle_factory_init(const struct spa_handle_factory *object, struct spa_handle *handle, const struct spa_dict *info, const struct spa_support *support, uint32_t n_support)
Definition plugin.h:198
int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index)
The entry point in a plugin.
#define spa_api_func_r(rtype, def, o, method, version,...)
Definition hook.h:273
spa/utils/hook.h
#define SPA_API_PLUGIN
Definition plugin.h:29
Definition dict.h:51
Definition plugin.h:119
int(* enum_interface_info)(const struct spa_handle_factory *factory, const struct spa_interface_info **info, uint32_t *index)
spa_handle_factory::enum_interface_info:
Definition plugin.h:186
uint32_t version
Definition plugin.h:123
const struct spa_dict * info
Extra information about the handles of this factory.
Definition plugin.h:141
size_t(* get_size)(const struct spa_handle_factory *factory, const struct spa_dict *params)
Get the size of handles from this factory.
Definition plugin.h:149
int(* init)(const struct spa_handle_factory *factory, struct spa_handle *handle, const struct spa_dict *info, const struct spa_support *support, uint32_t n_support)
Initialize an instance of this factory.
Definition plugin.h:168
Definition plugin.h:43
int(* get_interface)(struct spa_handle *handle, const char *type, void **iface)
Get the interface provided by handle with type.
Definition plugin.h:62
int(* clear)(struct spa_handle *handle)
Clean up the memory of handle.
Definition plugin.h:70
uint32_t version
Definition plugin.h:47
This structure lists the information about available interfaces on handles.
Definition plugin.h:89
const char * type
Definition plugin.h:90
Extra supporting infrastructure passed to the init() function of a factory.
Definition plugin.h:98
void * data
Definition plugin.h:100
const char * type
Definition plugin.h:99
spa/utils/dict.h