Loading...
Searching...
No Matches
plugin.h
Go to the documentation of this file.
/* Simple Plugin API */
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef SPA_PLUGIN_H
#define SPA_PLUGIN_H
#include <errno.h>
#include <spa/utils/defs.h>
#include <spa/utils/hook.h>
#include <spa/utils/dict.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_PLUGIN
#ifdef SPA_API_IMPL
#define SPA_API_PLUGIN SPA_API_IMPL
#else
#define SPA_API_PLUGIN static inline
#endif
#endif
struct spa_handle {
#define SPA_VERSION_HANDLE 0
uint32_t version;
*
* \a interface is always a struct spa_interface but depending on
* \a type, the struct might contain other information.
*
* \param handle a spa_handle
* \param type the interface type
* \param iface result to hold the interface.
* \return 0 on success
* -ENOTSUP when there are no interfaces
* -EINVAL when handle or info is NULL
*/
int (*get_interface) (struct spa_handle *handle, const char *type, void **iface);
int (*clear) (struct spa_handle *handle);
};
SPA_API_PLUGIN int
spa_handle_get_interface(struct spa_handle *object,
const char *type, void **iface)
{
return spa_api_func_r(int, -ENOTSUP, object, get_interface, 0, type, iface);
}
SPA_API_PLUGIN int
spa_handle_clear(struct spa_handle *object)
{
return spa_api_func_r(int, -ENOTSUP, object, clear, 0);
}
*/
struct spa_interface_info {
const char *type; /*< the type of the interface, can be
* used to get the interface */
};
*/
struct spa_support {
const char *type; /*< the type of the support item */
void *data; /*< specific data for the item */
};
SPA_API_PLUGIN void *spa_support_find(const struct spa_support *support,
uint32_t n_support,
const char *type)
{
uint32_t i;
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, type) == 0)
return support[i].data;
}
return NULL;
}
#define SPA_SUPPORT_INIT(type,data) ((struct spa_support) { (type), (data) })
struct spa_handle_factory {
#define SPA_VERSION_HANDLE_FACTORY 1
uint32_t version;
* See utils/names.h for the list of standard names.
*
* Examples include:
*
* api.alsa.pcm.sink: an object to write PCM samples to an alsa PLAYBACK
* device
* api.v4l2.source: an object to read from a v4l2 source.
*/
const char *name;
const struct spa_dict *info;
size_t (*get_size) (const struct spa_handle_factory *factory,
const struct spa_dict *params);
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);
int (*enum_interface_info) (const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t *index);
};
SPA_API_PLUGIN size_t
spa_handle_factory_get_size(const struct spa_handle_factory *object,
const struct spa_dict *params)
{
return spa_api_func_r(size_t, 0, object, get_size, 1, params);
}
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)
{
return spa_api_func_r(int, -ENOTSUP, object, init, 1, handle, info,
support, n_support);
}
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)
{
return spa_api_func_r(int, -ENOTSUP, object, enum_interface_info, 1,
info, index);
}
* \param factory a location to hold the factory result
* \param index index to keep track of the enumeration
* \return 1 on success
* 0 when there are no more factories
* -EINVAL when factory is NULL
*/
typedef int (*spa_handle_factory_enum_func_t) (const struct spa_handle_factory **factory,
uint32_t *index);
#define SPA_HANDLE_FACTORY_ENUM_FUNC_NAME "spa_handle_factory_enum"
int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index);
#define SPA_KEY_FACTORY_NAME "factory.name"
#define SPA_KEY_FACTORY_AUTHOR "factory.author"
#define SPA_KEY_FACTORY_DESCRIPTION "factory.description"
#define SPA_KEY_FACTORY_USAGE "factory.usage"
#define SPA_KEY_LIBRARY_NAME "library.name"
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_PLUGIN_H */
defs.h
spa/utils/defs.h
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:222
spa_handle_factory_get_size
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_handle_get_interface
SPA_API_PLUGIN int spa_handle_get_interface(struct spa_handle *object, const char *type, void **iface)
Definition plugin.h:74
spa_support_find
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_handle_factory_enum_interface_info
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_handle_clear
SPA_API_PLUGIN int spa_handle_clear(struct spa_handle *object)
Definition plugin.h:80
spa_handle_factory_init
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
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_api_func_r
#define spa_api_func_r(rtype, def, o, method, version,...)
Definition hook.h:273
hook.h
spa/utils/hook.h
SPA_API_PLUGIN
#define SPA_API_PLUGIN
Definition plugin.h:29
spa_dict
Definition dict.h:51
spa_handle_factory
Definition plugin.h:119
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:186
spa_handle_factory::version
uint32_t version
Definition plugin.h:123
spa_handle_factory::info
const struct spa_dict * info
Extra information about the handles of this factory.
Definition plugin.h:141
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:149
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:168
spa_handle
Definition plugin.h:43
spa_handle::get_interface
int(* get_interface)(struct spa_handle *handle, const char *type, void **iface)
Get the interface provided by handle with type.
Definition plugin.h:62
spa_handle::clear
int(* clear)(struct spa_handle *handle)
Clean up the memory of handle.
Definition plugin.h:70
spa_handle::version
uint32_t version
Definition plugin.h:47
spa_interface_info
This structure lists the information about available interfaces on handles.
Definition plugin.h:89
spa_interface_info::type
const char * type
Definition plugin.h:90
spa_support
Extra supporting infrastructure passed to the init() function of a factory.
Definition plugin.h:98
spa_support::type
const char * type
Definition plugin.h:99
dict.h
spa/utils/dict.h