mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-18 07:00:06 -05:00
Reorganise SPA tree
Reorganise the SPA includes to make it more extensible later Simplify the naming of the buffer and meta params
This commit is contained in:
parent
58451d626c
commit
caaeaff223
151 changed files with 1353 additions and 964 deletions
76
spa/include/spa/support/log-impl.h
Normal file
76
spa/include/spa/support/log-impl.h
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_LOG_IMPL_H__
|
||||
#define __SPA_LOG_IMPL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <spa/support/log.h>
|
||||
|
||||
static inline void spa_log_impl_logv(struct spa_log *log,
|
||||
enum spa_log_level level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt,
|
||||
va_list args)
|
||||
{
|
||||
char text[512], location[1024];
|
||||
static const char *levels[] = { "-", "E", "W", "I", "D", "T" };
|
||||
|
||||
vsnprintf(text, sizeof(text), fmt, args);
|
||||
snprintf(location, sizeof(location), "[%s][%s:%i %s()] %s\n",
|
||||
levels[level], strrchr(file, '/') + 1, line, func, text);
|
||||
fputs(location, stderr);
|
||||
}
|
||||
static inline void spa_log_impl_log(struct spa_log *log,
|
||||
enum spa_log_level level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
spa_log_impl_logv(log, level, file, line, func, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#define SPA_LOG_IMPL_DEFINE(name) \
|
||||
struct { \
|
||||
struct spa_log log; \
|
||||
} name
|
||||
|
||||
#define SPA_LOG_IMPL_INIT \
|
||||
{ { SPA_VERSION_LOG, \
|
||||
NULL, \
|
||||
SPA_LOG_LEVEL_INFO, \
|
||||
spa_log_impl_log, \
|
||||
spa_log_impl_logv,} }
|
||||
|
||||
#define SPA_LOG_IMPL(name) \
|
||||
SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* __SPA_LOG_IMPL_H__ */
|
||||
144
spa/include/spa/support/log.h
Normal file
144
spa/include/spa/support/log.h
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_LOG_H__
|
||||
#define __SPA_LOG_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SPA_TYPE__Log SPA_TYPE_INTERFACE_BASE "Log"
|
||||
#define SPA_TYPE_LOG_BASE SPA_TYPE__Log ":"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <spa/utils/defs.h>
|
||||
|
||||
enum spa_log_level {
|
||||
SPA_LOG_LEVEL_NONE = 0,
|
||||
SPA_LOG_LEVEL_ERROR,
|
||||
SPA_LOG_LEVEL_WARN,
|
||||
SPA_LOG_LEVEL_INFO,
|
||||
SPA_LOG_LEVEL_DEBUG,
|
||||
SPA_LOG_LEVEL_TRACE,
|
||||
};
|
||||
|
||||
/**
|
||||
* struct spa_log:
|
||||
*
|
||||
* The Log interface
|
||||
*/
|
||||
struct spa_log {
|
||||
/* the version of this log. This can be used to expand this
|
||||
* structure in the future */
|
||||
#define SPA_VERSION_LOG 0
|
||||
uint32_t version;
|
||||
/**
|
||||
* struct spa_log::info
|
||||
*
|
||||
* Extra information about the log
|
||||
*/
|
||||
const struct spa_dict *info;
|
||||
|
||||
/**
|
||||
* struct spa_log::level
|
||||
*
|
||||
* Logging level, everything above this level is not logged
|
||||
*/
|
||||
enum spa_log_level level;
|
||||
|
||||
/**
|
||||
* struct spa_log::log
|
||||
* @log: a #struct spa_log
|
||||
* @level: a #enum spa_log_level
|
||||
* @file: the file name
|
||||
* @line: the line number
|
||||
* @func: the function name
|
||||
* @fmt: printf style format
|
||||
* @...: format arguments
|
||||
*
|
||||
* Log a message with the given log level.
|
||||
*/
|
||||
void (*log) (struct spa_log *log,
|
||||
enum spa_log_level level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt, ...) SPA_PRINTF_FUNC(6, 7);
|
||||
|
||||
/**
|
||||
* struct spa_log::logv
|
||||
* @log: a #struct spa_log
|
||||
* @level: a #enum spa_log_level
|
||||
* @file: the file name
|
||||
* @line: the line number
|
||||
* @func: the function name
|
||||
* @fmt: printf style format
|
||||
* @args: format arguments
|
||||
*
|
||||
* Log a message with the given log level.
|
||||
*/
|
||||
void (*logv) (struct spa_log *log,
|
||||
enum spa_log_level level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt,
|
||||
va_list args) SPA_PRINTF_FUNC(6, 0);
|
||||
};
|
||||
|
||||
#define spa_log_level_enabled(l,lev) ((l) && (l)->level >= (lev))
|
||||
|
||||
#if __STDC_VERSION__ >= 199901L
|
||||
|
||||
#define spa_log_log(l,lev,...) \
|
||||
if (SPA_UNLIKELY (spa_log_level_enabled (l, lev))) \
|
||||
(l)->log((l),lev,__VA_ARGS__)
|
||||
|
||||
#define spa_log_error(l,...) spa_log_log(l,SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||
#define spa_log_warn(l,...) spa_log_log(l,SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||
#define spa_log_info(l,...) spa_log_log(l,SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||
#define spa_log_debug(l,...) spa_log_log(l,SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||
#define spa_log_trace(l,...) spa_log_log(l,SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#define SPA_LOG_FUNC(name,lev) \
|
||||
static inline void spa_log_##name (struct spa_log *l, const char *format, ...) \
|
||||
{ \
|
||||
if (SPA_UNLIKELY (spa_log_level_enabled (l, lev))) { \
|
||||
va_list varargs; \
|
||||
va_start (varargs, format); \
|
||||
(l)->logv((l),lev,__FILE__,__LINE__,__func__,format,varargs); \
|
||||
va_end (varargs); \
|
||||
} \
|
||||
}
|
||||
|
||||
SPA_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR)
|
||||
SPA_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN)
|
||||
SPA_LOG_FUNC(info, SPA_LOG_LEVEL_INFO)
|
||||
SPA_LOG_FUNC(debug, SPA_LOG_LEVEL_DEBUG)
|
||||
SPA_LOG_FUNC(trace, SPA_LOG_LEVEL_TRACE)
|
||||
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* __SPA_LOG_H__ */
|
||||
215
spa/include/spa/support/loop.h
Normal file
215
spa/include/spa/support/loop.h
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_LOOP_H__
|
||||
#define __SPA_LOOP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct spa_loop;
|
||||
#define SPA_TYPE__Loop SPA_TYPE_INTERFACE_BASE "Loop"
|
||||
#define SPA_TYPE_LOOP_BASE SPA_TYPE__Loop ":"
|
||||
|
||||
struct spa_loop_control;
|
||||
#define SPA_TYPE__LoopControl SPA_TYPE_INTERFACE_BASE "LoopControl"
|
||||
struct spa_loop_utils;
|
||||
#define SPA_TYPE__LoopUtils SPA_TYPE_INTERFACE_BASE "LoopUtils"
|
||||
|
||||
#define SPA_TYPE_LOOP__MainLoop SPA_TYPE_LOOP_BASE "MainLoop"
|
||||
#define SPA_TYPE_LOOP__DataLoop SPA_TYPE_LOOP_BASE "DataLoop"
|
||||
|
||||
#include <spa/utils/defs.h>
|
||||
#include <spa/utils/hook.h>
|
||||
|
||||
enum spa_io {
|
||||
SPA_IO_IN = (1 << 0),
|
||||
SPA_IO_OUT = (1 << 1),
|
||||
SPA_IO_HUP = (1 << 2),
|
||||
SPA_IO_ERR = (1 << 3),
|
||||
};
|
||||
|
||||
struct spa_source;
|
||||
|
||||
typedef void (*spa_source_func_t) (struct spa_source *source);
|
||||
|
||||
struct spa_source {
|
||||
struct spa_loop *loop;
|
||||
spa_source_func_t func;
|
||||
void *data;
|
||||
int fd;
|
||||
enum spa_io mask;
|
||||
enum spa_io rmask;
|
||||
};
|
||||
|
||||
typedef int (*spa_invoke_func_t) (struct spa_loop *loop,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
const void *data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* spa_loop:
|
||||
*
|
||||
* Register sources and work items to an event loop
|
||||
*/
|
||||
struct spa_loop {
|
||||
/* the version of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
#define SPA_VERSION_LOOP 0
|
||||
uint32_t version;
|
||||
|
||||
/** add a source to the loop */
|
||||
int (*add_source) (struct spa_loop *loop,
|
||||
struct spa_source *source);
|
||||
|
||||
/** update the source io mask */
|
||||
int (*update_source) (struct spa_source *source);
|
||||
|
||||
/** remove a source from the loop */
|
||||
void (*remove_source) (struct spa_source *source);
|
||||
|
||||
/** invoke a function in the context of this loop */
|
||||
int (*invoke) (struct spa_loop *loop,
|
||||
spa_invoke_func_t func,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
const void *data,
|
||||
bool block,
|
||||
void *user_data);
|
||||
};
|
||||
|
||||
#define spa_loop_add_source(l,...) (l)->add_source((l),__VA_ARGS__)
|
||||
#define spa_loop_update_source(l,...) (l)->update_source(__VA_ARGS__)
|
||||
#define spa_loop_remove_source(l,...) (l)->remove_source(__VA_ARGS__)
|
||||
#define spa_loop_invoke(l,...) (l)->invoke((l),__VA_ARGS__)
|
||||
|
||||
|
||||
/** Control hooks */
|
||||
struct spa_loop_control_hooks {
|
||||
#define SPA_VERSION_LOOP_CONTROL_HOOKS 0
|
||||
uint32_t version;
|
||||
/** Executed right before waiting for events */
|
||||
void (*before) (void *data);
|
||||
/** Executed right after waiting for events */
|
||||
void (*after) (void *data);
|
||||
};
|
||||
|
||||
/**
|
||||
* spa_loop_control:
|
||||
*
|
||||
* Control an event loop
|
||||
*/
|
||||
struct spa_loop_control {
|
||||
/* the version of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
#define SPA_VERSION_LOOP_CONTROL 0
|
||||
uint32_t version;
|
||||
|
||||
int (*get_fd) (struct spa_loop_control *ctrl);
|
||||
|
||||
/** Add a hook
|
||||
* \param ctrl the control to change
|
||||
* \param hooks the hooks to add */
|
||||
void (*add_hook) (struct spa_loop_control *ctrl,
|
||||
struct spa_hook *hook,
|
||||
const struct spa_loop_control_hooks *hooks,
|
||||
void *data);
|
||||
|
||||
void (*enter) (struct spa_loop_control *ctrl);
|
||||
void (*leave) (struct spa_loop_control *ctrl);
|
||||
|
||||
int (*iterate) (struct spa_loop_control *ctrl, int timeout);
|
||||
};
|
||||
|
||||
#define spa_loop_control_get_fd(l) (l)->get_fd(l)
|
||||
#define spa_loop_control_add_hook(l,...) (l)->add_hook((l),__VA_ARGS__)
|
||||
#define spa_loop_control_enter(l) (l)->enter(l)
|
||||
#define spa_loop_control_iterate(l,...) (l)->iterate((l),__VA_ARGS__)
|
||||
#define spa_loop_control_leave(l) (l)->leave(l)
|
||||
|
||||
|
||||
typedef void (*spa_source_io_func_t) (void *data, int fd, enum spa_io mask);
|
||||
typedef void (*spa_source_idle_func_t) (void *data);
|
||||
typedef void (*spa_source_event_func_t) (void *data, uint64_t count);
|
||||
typedef void (*spa_source_timer_func_t) (void *data, uint64_t expirations);
|
||||
typedef void (*spa_source_signal_func_t) (void *data, int signal_number);
|
||||
|
||||
/**
|
||||
* struct spa_loop_utils:
|
||||
*
|
||||
* Create sources for an event loop
|
||||
*/
|
||||
struct spa_loop_utils {
|
||||
/* the version of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
#define SPA_VERSION_LOOP_UTILS 0
|
||||
uint32_t version;
|
||||
|
||||
struct spa_source *(*add_io) (struct spa_loop_utils *utils,
|
||||
int fd,
|
||||
enum spa_io mask,
|
||||
bool close,
|
||||
spa_source_io_func_t func, void *data);
|
||||
|
||||
int (*update_io) (struct spa_source *source, enum spa_io mask);
|
||||
|
||||
struct spa_source *(*add_idle) (struct spa_loop_utils *utils,
|
||||
bool enabled,
|
||||
spa_source_idle_func_t func, void *data);
|
||||
void (*enable_idle) (struct spa_source *source, bool enabled);
|
||||
|
||||
struct spa_source *(*add_event) (struct spa_loop_utils *utils,
|
||||
spa_source_event_func_t func, void *data);
|
||||
void (*signal_event) (struct spa_source *source);
|
||||
|
||||
struct spa_source *(*add_timer) (struct spa_loop_utils *utils,
|
||||
spa_source_timer_func_t func, void *data);
|
||||
int (*update_timer) (struct spa_source *source,
|
||||
struct timespec *value,
|
||||
struct timespec *interval,
|
||||
bool absolute);
|
||||
struct spa_source *(*add_signal) (struct spa_loop_utils *utils,
|
||||
int signal_number,
|
||||
spa_source_signal_func_t func, void *data);
|
||||
|
||||
/** destroy a source allocated with this interface. This function
|
||||
* should only be called when the loop is not running or from the
|
||||
* context of the running loop */
|
||||
void (*destroy_source) (struct spa_source *source);
|
||||
};
|
||||
|
||||
#define spa_loop_utils_add_io(l,...) (l)->add_io(l,__VA_ARGS__)
|
||||
#define spa_loop_utils_update_io(l,...) (l)->update_io(__VA_ARGS__)
|
||||
#define spa_loop_utils_add_idle(l,...) (l)->add_idle(l,__VA_ARGS__)
|
||||
#define spa_loop_utils_enable_idle(l,...) (l)->enable_idle(__VA_ARGS__)
|
||||
#define spa_loop_utils_add_event(l,...) (l)->add_event(l,__VA_ARGS__)
|
||||
#define spa_loop_utils_signal_event(l,...) (l)->signal_event(__VA_ARGS__)
|
||||
#define spa_loop_utils_add_timer(l,...) (l)->add_timer(l,__VA_ARGS__)
|
||||
#define spa_loop_utils_update_timer(l,...) (l)->update_timer(__VA_ARGS__)
|
||||
#define spa_loop_utils_add_signal(l,...) (l)->add_signal(l,__VA_ARGS__)
|
||||
#define spa_loop_utils_destroy_source(l,...) (l)->destroy_source(__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_LOOP_H__ */
|
||||
209
spa/include/spa/support/plugin.h
Normal file
209
spa/include/spa/support/plugin.h
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_PLUGIN_H__
|
||||
#define __SPA_PLUGIN_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <spa/utils/defs.h>
|
||||
#include <spa/utils/dict.h>
|
||||
|
||||
#define SPA_TYPE__Handle SPA_TYPE_INTERFACE_BASE "Handle"
|
||||
#define SPA_TYPE__HandleFactory SPA_TYPE_INTERFACE_BASE "HandleFactory"
|
||||
|
||||
struct spa_handle {
|
||||
/** Version of this struct */
|
||||
#define SPA_VERSION_HANDLE 0
|
||||
uint32_t version;
|
||||
|
||||
/* user_data that can be set by the application */
|
||||
void *user_data;
|
||||
/**
|
||||
* spa_handle::get_interface:
|
||||
* @handle: a #spa_handle
|
||||
* @interface_id: the interface id
|
||||
* @interface: result to hold the interface.
|
||||
*
|
||||
* Get the interface provided by @handle with @interface_id.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
* #SPA_RESULT_NOT_IMPLEMENTED when there are no extensions
|
||||
* #SPA_RESULT_INVALID_ARGUMENTS when handle or info is %NULL
|
||||
*/
|
||||
int (*get_interface) (struct spa_handle *handle, uint32_t interface_id, void **interface);
|
||||
/**
|
||||
* spa_handle::clear
|
||||
* @handle: a pointer to memory
|
||||
*
|
||||
* Clean up the memory of @handle. After this, @handle should not be used
|
||||
* anymore.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
*/
|
||||
int (*clear) (struct spa_handle *handle);
|
||||
};
|
||||
|
||||
#define spa_handle_get_interface(h,...) (h)->get_interface((h),__VA_ARGS__)
|
||||
#define spa_handle_clear(h) (h)->clear((h))
|
||||
|
||||
/**
|
||||
* struct spa_interface_info:
|
||||
* @type: the type of the interface, can be used to get the interface
|
||||
*
|
||||
* This structure lists the information about available interfaces on
|
||||
* handles.
|
||||
*/
|
||||
struct spa_interface_info {
|
||||
const char *type;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct spa_support:
|
||||
* @type: the type of the support item
|
||||
* @data: specific data for the item
|
||||
*
|
||||
* Extra supporting infrastructure passed to the init() function of
|
||||
* a factory. It can be extra information or interfaces such as logging.
|
||||
*/
|
||||
struct spa_support {
|
||||
const char *type;
|
||||
void *data;
|
||||
};
|
||||
|
||||
static inline 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->type, type) == 0)
|
||||
return support->data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define SPA_SUPPORT_INIT(type,data) (struct spa_support) { (type), (data) }
|
||||
|
||||
struct spa_handle_factory {
|
||||
/** The version of this structure */
|
||||
#define SPA_VERSION_HANDLE_FACTORY 0
|
||||
uint32_t version;
|
||||
/**
|
||||
* spa_handle_factory::name
|
||||
*
|
||||
* The name
|
||||
*/
|
||||
const char *name;
|
||||
/**
|
||||
* spa_handle_factory::info
|
||||
*
|
||||
* Extra information about the handles of this factory.
|
||||
*/
|
||||
const struct spa_dict *info;
|
||||
/**
|
||||
* spa_handle_factory::size
|
||||
*
|
||||
* The size of handles from this factory
|
||||
*/
|
||||
const size_t size;
|
||||
|
||||
/**
|
||||
* spa_handle_factory::init
|
||||
* @factory: a #spa_handle_factory
|
||||
* @handle: a pointer to memory
|
||||
* @info: extra handle specific information, usually obtained
|
||||
* from a #spa_monitor. This can be used to configure the handle.
|
||||
* @support: support items
|
||||
* @n_support: number of elements in @support
|
||||
*
|
||||
* Initialize an instance of this factory. The caller should allocate
|
||||
* memory at least spa_handle_factory::size bytes and pass this as @handle.
|
||||
*
|
||||
* @support can optionally contain extra interfaces or data ites that the
|
||||
* plugin can use such as a logger.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
* #SPA_RESULT_NOT_IMPLEMENTED when an instance can't be made
|
||||
* #SPA_RESULT_INVALID_ARGUMENTS when factory or handle are %NULL
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* spa_handle_factory::enum_interface_info:
|
||||
* @factory: a #spa_handle_factory
|
||||
* @info: result to hold spa_interface_info.
|
||||
* @index: index to keep track of the enumeration, 0 for first item
|
||||
*
|
||||
* Enumerate the interface information for @factory.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
* #SPA_RESULT_NOT_IMPLEMENTED when there are no interfaces
|
||||
* #SPA_RESULT_INVALID_ARGUMENTS when handle or info is %NULL
|
||||
* #SPA_RESULT_ENUM_END when there are no more infos
|
||||
*/
|
||||
int (*enum_interface_info) (const struct spa_handle_factory *factory,
|
||||
const struct spa_interface_info **info,
|
||||
uint32_t index);
|
||||
};
|
||||
|
||||
#define spa_handle_factory_init(h,...) (h)->init((h),__VA_ARGS__)
|
||||
#define spa_handle_factory_enum_interface_info(h,...) (h)->enum_interface_info((h),__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* spa_handle_factory_enum_func_t:
|
||||
* @factory: a location to hold the factory result
|
||||
* @index: index to keep track of the enumeration
|
||||
*
|
||||
* The function signature of the entry point in a plugin.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
* #SPA_RESULT_INVALID_ARGUMENTS when factory is %NULL
|
||||
* #SPA_RESULT_ENUM_END when there are no more factories
|
||||
*/
|
||||
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"
|
||||
|
||||
/**
|
||||
* spa_handle_factory_enum:
|
||||
* @factory: a location to hold the factory result
|
||||
* @index: index to keep track of the enumeration
|
||||
*
|
||||
* The entry point in a plugin.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
* #SPA_RESULT_INVALID_ARGUMENTS when factory is %NULL
|
||||
* #SPA_RESULT_ENUM_END when there are no more factories
|
||||
*/
|
||||
int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t index);
|
||||
|
||||
void spa_handle_factory_register(const struct spa_handle_factory *factory);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_PLUGIN_H__ */
|
||||
81
spa/include/spa/support/type-map-impl.h
Normal file
81
spa/include/spa/support/type-map-impl.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_TYPE_MAP_IMPL_H__
|
||||
#define __SPA_TYPE_MAP_IMPL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <spa/support/type-map.h>
|
||||
|
||||
static inline uint32_t
|
||||
spa_type_map_impl_get_id (struct spa_type_map *map, const char *type)
|
||||
{
|
||||
struct { struct spa_type_map map; uint32_t n_types; char *types[1]; } *impl = (void*) map;
|
||||
uint32_t i = 0;
|
||||
|
||||
for (i = 1; i <= impl->n_types; i++) {
|
||||
if (strcmp(impl->types[i], type) == 0)
|
||||
return i;
|
||||
}
|
||||
impl->types[i] = (char *) type;
|
||||
impl->n_types++;
|
||||
return i;
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
spa_type_map_impl_get_type (const struct spa_type_map *map, uint32_t id)
|
||||
{
|
||||
struct { struct spa_type_map map; uint32_t n_types; char *types[1]; } *impl = (void*) map;
|
||||
if (id <= impl->n_types)
|
||||
return impl->types[id];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline size_t spa_type_map_impl_get_size (const struct spa_type_map *map)
|
||||
{
|
||||
struct { struct spa_type_map map; uint32_t n_types; char *types[1]; } *impl = (void*) map;
|
||||
return impl->n_types;
|
||||
}
|
||||
|
||||
#define SPA_TYPE_MAP_IMPL_DEFINE(name,maxtypes) \
|
||||
struct { \
|
||||
struct spa_type_map map; \
|
||||
unsigned int n_types; \
|
||||
char *types[maxtypes]; \
|
||||
} name
|
||||
|
||||
#define SPA_TYPE_MAP_IMPL_INIT \
|
||||
{ { SPA_VERSION_TYPE_MAP, \
|
||||
NULL, \
|
||||
spa_type_map_impl_get_id, \
|
||||
spa_type_map_impl_get_type, \
|
||||
spa_type_map_impl_get_size,}, \
|
||||
0, { NULL, } }
|
||||
|
||||
#define SPA_TYPE_MAP_IMPL(name,maxtypes) \
|
||||
SPA_TYPE_MAP_IMPL_DEFINE(name,maxtypes) = SPA_TYPE_MAP_IMPL_INIT
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_TYPE_MAP_IMPL_H__ */
|
||||
64
spa/include/spa/support/type-map.h
Normal file
64
spa/include/spa/support/type-map.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_TYPE_MAP_H__
|
||||
#define __SPA_TYPE_MAP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <spa/utils/defs.h>
|
||||
#include <spa/utils/type.h>
|
||||
|
||||
#define SPA_TYPE__TypeMap SPA_TYPE_INTERFACE_BASE "TypeMap"
|
||||
|
||||
/**
|
||||
* spa_type_map:
|
||||
*
|
||||
* Maps between string types and their type id
|
||||
*/
|
||||
struct spa_type_map {
|
||||
/* the version of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
#define SPA_VERSION_TYPE_MAP 0
|
||||
uint32_t version;
|
||||
/**
|
||||
* spa_type_map::info
|
||||
*
|
||||
* Extra information about the type map
|
||||
*/
|
||||
const struct spa_dict *info;
|
||||
|
||||
uint32_t (*get_id) (struct spa_type_map *map, const char *type);
|
||||
|
||||
const char *(*get_type) (const struct spa_type_map *map, uint32_t id);
|
||||
|
||||
size_t (*get_size) (const struct spa_type_map *map);
|
||||
};
|
||||
|
||||
#define spa_type_map_get_id(n,...) (n)->get_id((n),__VA_ARGS__)
|
||||
#define spa_type_map_get_type(n,...) (n)->get_type((n),__VA_ARGS__)
|
||||
#define spa_type_map_get_size(n) (n)->get_size(n)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_TYPE_MAP_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue