PipeWire  0.3.33
plugin.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2018 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_PLUGIN_H
26 #define SPA_PLUGIN_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <spa/utils/defs.h>
33 #include <spa/utils/dict.h>
34 
44 struct spa_handle {
46 #define SPA_VERSION_HANDLE 0
47  uint32_t version;
48 
62  int (*get_interface) (struct spa_handle *handle, const char *type, void **interface);
70  int (*clear) (struct spa_handle *handle);
71 };
72 
73 #define spa_handle_get_interface(h,...) (h)->get_interface((h),__VA_ARGS__)
74 #define spa_handle_clear(h) (h)->clear((h))
75 
81  const char *type; /*< the type of the interface, can be
82  * used to get the interface */
83 };
84 
89 struct spa_support {
90  const char *type; /*< the type of the support item */
91  void *data; /*< specific data for the item */
92 };
93 
95 /* static */ inline void *spa_support_find(const struct spa_support *support,
96  uint32_t n_support,
97  const char *type)
98 {
99  uint32_t i;
100  for (i = 0; i < n_support; i++) {
101  if (strcmp(support[i].type, type) == 0)
102  return support[i].data;
103  }
104  return NULL;
105 }
106 
107 #define SPA_SUPPORT_INIT(type,data) (struct spa_support) { (type), (data) }
108 
111 #define SPA_VERSION_HANDLE_FACTORY 1
112  uint32_t version;
126  const char *name;
130  const struct spa_dict *info;
138  size_t (*get_size) (const struct spa_handle_factory *factory,
139  const struct spa_dict *params);
140 
157  int (*init) (const struct spa_handle_factory *factory,
158  struct spa_handle *handle,
159  const struct spa_dict *info,
160  const struct spa_support *support,
161  uint32_t n_support);
162 
175  int (*enum_interface_info) (const struct spa_handle_factory *factory,
176  const struct spa_interface_info **info,
177  uint32_t *index);
178 };
179 
180 #define spa_handle_factory_get_size(h,...) (h)->get_size((h),__VA_ARGS__)
181 #define spa_handle_factory_init(h,...) (h)->init((h),__VA_ARGS__)
182 #define spa_handle_factory_enum_interface_info(h,...) (h)->enum_interface_info((h),__VA_ARGS__)
183 
193 typedef int (*spa_handle_factory_enum_func_t) (const struct spa_handle_factory **factory,
194  uint32_t *index);
195 
196 #define SPA_HANDLE_FACTORY_ENUM_FUNC_NAME "spa_handle_factory_enum"
197 
207 int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index);
208 
209 
210 
211 #define SPA_KEY_FACTORY_NAME "factory.name"
212 #define SPA_KEY_FACTORY_AUTHOR "factory.author"
213 #define SPA_KEY_FACTORY_DESCRIPTION "factory.description"
214 #define SPA_KEY_FACTORY_USAGE "factory.usage"
216 #define SPA_KEY_LIBRARY_NAME "library.name"
224 #ifdef __cplusplus
225 } /* extern "C" */
226 #endif
227 
228 #endif /* SPA_PLUGIN_H */
spa_handle_factory::get_size
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:138
spa_interface_info
This structure lists the information about available interfaces on handles.
Definition: plugin.h:80
spa_handle_factory_enum
int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index)
The entry point in a plugin.
spa_handle::version
uint32_t version
Definition: plugin.h:47
handle
Definition: pipewire.c:68
spa_support::type
const char * type
Definition: plugin.h:90
spa_handle_factory::info
const struct spa_dict * info
Extra information about the handles of this factory.
Definition: plugin.h:130
spa_support::data
void * data
Definition: plugin.h:91
spa_handle
Definition: plugin.h:44
spa_interface_info::type
const char * type
Definition: plugin.h:81
spa_dict
Definition: utils/dict.h:48
spa_support_find
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:95
spa_handle_factory_enum_func_t
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:193
spa_handle_factory::enum_interface_info
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:175
spa_handle::clear
int(* clear)(struct spa_handle *handle)
Clean up the memory of handle.
Definition: plugin.h:70
defs.h
spa_handle_factory::init
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:157
spa_handle_factory::name
const char * name
The name of the factory contains a logical name that describes the function of the handle.
Definition: plugin.h:126
spa_support
Extra supporting infrastructure passed to the init() function of a factory.
Definition: plugin.h:89
spa_handle::get_interface
int(* get_interface)(struct spa_handle *handle, const char *type, void **interface)
Get the interface provided by handle with type.
Definition: plugin.h:62
spa_handle_factory::version
uint32_t version
Definition: plugin.h:112
support
Definition: pipewire.c:80
spa_handle_factory
Definition: plugin.h:109
dict.h