more hacking

Move plugin API to separate directory for now
Add ringbuffer and way to get ringbuffer from a port
This commit is contained in:
Wim Taymans 2016-06-28 12:21:56 +02:00
parent b8f6e99537
commit 3c029cba53
56 changed files with 7055 additions and 1530 deletions

1
spa/include/meson.build Normal file
View file

@ -0,0 +1 @@
subdir('spa')

View file

@ -0,0 +1,44 @@
/* 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_AUDIO_FORMAT_H__
#define __SPA_AUDIO_FORMAT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/format.h>
typedef enum {
SPA_PROP_ID_AUDIO_FORMAT = SPA_PROP_ID_MEDIA_CUSTOM_START,
SPA_PROP_ID_AUDIO_FLAGS,
SPA_PROP_ID_AUDIO_LAYOUT,
SPA_PROP_ID_AUDIO_RATE,
SPA_PROP_ID_AUDIO_CHANNELS,
SPA_PROP_ID_AUDIO_CHANNEL_MASK,
SPA_PROP_ID_AUDIO_RAW_INFO,
} SpaPropIdAudio;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_AUDIO_FORMAT */

158
spa/include/spa/audio/raw.h Normal file
View file

@ -0,0 +1,158 @@
/* 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_AUDIO_RAW_H__
#define __SPA_AUDIO_RAW_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaAudioRawInfo SpaAudioRawInfo;
typedef struct _SpaAudioRawFormat SpaAudioRawFormat;
#include <endian.h>
#include <spa/audio/format.h>
#if __BYTE_ORDER == __BIG_ENDIAN
#define _SPA_AUDIO_FORMAT_NE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## BE
#define _SPA_AUDIO_FORMAT_OE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## LE
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#define _SPA_AUDIO_FORMAT_NE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## LE
#define _SPA_AUDIO_FORMAT_OE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## BE
#endif
typedef enum {
SPA_AUDIO_FORMAT_UNKNOWN,
SPA_AUDIO_FORMAT_ENCODED,
/* 8 bit */
SPA_AUDIO_FORMAT_S8,
SPA_AUDIO_FORMAT_U8,
/* 16 bit */
SPA_AUDIO_FORMAT_S16LE,
SPA_AUDIO_FORMAT_S16BE,
SPA_AUDIO_FORMAT_U16LE,
SPA_AUDIO_FORMAT_U16BE,
/* 24 bit in low 3 bytes of 32 bits*/
SPA_AUDIO_FORMAT_S24_32LE,
SPA_AUDIO_FORMAT_S24_32BE,
SPA_AUDIO_FORMAT_U24_32LE,
SPA_AUDIO_FORMAT_U24_32BE,
/* 32 bit */
SPA_AUDIO_FORMAT_S32LE,
SPA_AUDIO_FORMAT_S32BE,
SPA_AUDIO_FORMAT_U32LE,
SPA_AUDIO_FORMAT_U32BE,
/* 24 bit in 3 bytes*/
SPA_AUDIO_FORMAT_S24LE,
SPA_AUDIO_FORMAT_S24BE,
SPA_AUDIO_FORMAT_U24LE,
SPA_AUDIO_FORMAT_U24BE,
/* 20 bit in 3 bytes*/
SPA_AUDIO_FORMAT_S20LE,
SPA_AUDIO_FORMAT_S20BE,
SPA_AUDIO_FORMAT_U20LE,
SPA_AUDIO_FORMAT_U20BE,
/* 18 bit in 3 bytes*/
SPA_AUDIO_FORMAT_S18LE,
SPA_AUDIO_FORMAT_S18BE,
SPA_AUDIO_FORMAT_U18LE,
SPA_AUDIO_FORMAT_U18BE,
/* float */
SPA_AUDIO_FORMAT_F32LE,
SPA_AUDIO_FORMAT_F32BE,
SPA_AUDIO_FORMAT_F64LE,
SPA_AUDIO_FORMAT_F64BE,
/* native endianness equivalents */
SPA_AUDIO_FORMAT_S16 = _SPA_AUDIO_FORMAT_NE(S16),
SPA_AUDIO_FORMAT_U16 = _SPA_AUDIO_FORMAT_NE(U16),
SPA_AUDIO_FORMAT_S24_32 = _SPA_AUDIO_FORMAT_NE(S24_32),
SPA_AUDIO_FORMAT_U24_32 = _SPA_AUDIO_FORMAT_NE(U24_32),
SPA_AUDIO_FORMAT_S32 = _SPA_AUDIO_FORMAT_NE(S32),
SPA_AUDIO_FORMAT_U32 = _SPA_AUDIO_FORMAT_NE(U32),
SPA_AUDIO_FORMAT_S24 = _SPA_AUDIO_FORMAT_NE(S24),
SPA_AUDIO_FORMAT_U24 = _SPA_AUDIO_FORMAT_NE(U24),
SPA_AUDIO_FORMAT_S20 = _SPA_AUDIO_FORMAT_NE(S20),
SPA_AUDIO_FORMAT_U20 = _SPA_AUDIO_FORMAT_NE(U20),
SPA_AUDIO_FORMAT_S18 = _SPA_AUDIO_FORMAT_NE(S18),
SPA_AUDIO_FORMAT_U18 = _SPA_AUDIO_FORMAT_NE(U18),
SPA_AUDIO_FORMAT_F32 = _SPA_AUDIO_FORMAT_NE(F32),
SPA_AUDIO_FORMAT_F64 = _SPA_AUDIO_FORMAT_NE(F64)
} SpaAudioFormat;
/**
* SpaAudioFlags:
* @SPA_AUDIO_FLAG_NONE: no valid flag
* @SPA_AUDIO_FLAG_UNPOSITIONED: the position array explicitly
* contains unpositioned channels.
*
* Extra audio flags
*/
typedef enum {
SPA_AUDIO_FLAG_NONE = 0,
SPA_AUDIO_FLAG_UNPOSITIONED = (1 << 0)
} SpaAudioFlags;
/**
* SpaAudioLayout:
* @SPA_AUDIO_LAYOUT_INTERLEAVED: interleaved audio
* @SPA_AUDIO_LAYOUT_NON_INTERLEAVED: non-interleaved audio
*
* Layout of the audio samples for the different channels.
*/
typedef enum {
SPA_AUDIO_LAYOUT_INTERLEAVED = 0,
SPA_AUDIO_LAYOUT_NON_INTERLEAVED
} SpaAudioLayout;
/**
* SpaAudioRawInfo:
* @format: the format
* @flags: extra flags
* @layout: the sample layout
* @rate: the sample rate
* @channels: the number of channels
* @channel_mask: the channel mask
*/
struct _SpaAudioRawInfo {
SpaAudioFormat format;
SpaAudioFlags flags;
SpaAudioLayout layout;
uint32_t rate;
uint32_t channels;
uint32_t channel_mask;
};
struct _SpaAudioRawFormat {
SpaFormat format;
uint32_t unset_mask;
SpaAudioRawInfo info;
};
SpaResult spa_audio_raw_format_init (SpaAudioRawFormat *format);
SpaResult spa_audio_raw_format_parse (const SpaFormat *format,
SpaAudioRawFormat *rawformat);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_AUDIO_RAW_H__ */

180
spa/include/spa/buffer.h Normal file
View file

@ -0,0 +1,180 @@
/* 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_BUFFER_H__
#define __SPA_BUFFER_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaBuffer SpaBuffer;
#include <spa/defs.h>
/**
* SpaMetaType:
* @SPA_META_TYPE_INVALID: invalid metadata, should be ignored
* @SPA_META_TYPE_HEADER: header metadata
*/
typedef enum {
SPA_META_TYPE_INVALID = 0,
SPA_META_TYPE_HEADER,
} SpaMetaType;
/**
* SpaBufferFlags:
* @SPA_BUFFER_FLAG_NONE: no flag
* @SPA_BUFFER_FLAG_DISCONT: the buffer marks a data discontinuity
* @SPA_BUFFER_FLAG_CORRUPTED: the buffer data might be corrupted
* @SPA_BUFFER_FLAG_MARKER: the buffer contains a media specific marker
* @SPA_BUFFER_FLAG_HEADER: the buffer contains a header
* @SPA_BUFFER_FLAG_GAP: the buffer has been constructed to fill a gap
* and contains media neutral data
* @SPA_BUFFER_FLAG_DELTA_UNIT: the media cannot be decoded independently
*/
typedef enum {
SPA_BUFFER_FLAG_NONE = 0,
SPA_BUFFER_FLAG_DISCONT = (1 << 0),
SPA_BUFFER_FLAG_CORRUPTED = (1 << 1),
SPA_BUFFER_FLAG_MARKER = (1 << 2),
SPA_BUFFER_FLAG_HEADER = (1 << 3),
SPA_BUFFER_FLAG_GAP = (1 << 4),
SPA_BUFFER_FLAG_DELTA_UNIT = (1 << 5),
} SpaBufferFlags;
typedef struct {
SpaBufferFlags flags;
uint32_t seq;
int64_t pts;
int64_t dts_offset;
} SpaMetaHeader;
/**
* SpaMeta:
* @type: metadata type
* @data: pointer to metadata
* @size: size of metadata
*/
typedef struct {
SpaMetaType type;
void *data;
size_t size;
} SpaMeta;
/**
* SpaDataType:
* @SPA_DATA_TYPE_INVALID: invalid data type, is ignored
* @SPA_DATA_TYPE_MEMPTR: data and size point to memory
* @SPA_DATA_TYPE_FD: data points to SpaDataFd
*/
typedef enum {
SPA_DATA_TYPE_INVALID = 0,
SPA_DATA_TYPE_MEMPTR,
SPA_DATA_TYPE_FD,
} SpaDataType;
/**
* SpaDataFd
* fd: a file descriptor
* offset: offset in the data referenced by @fd
* @size: size of data referenced by fd
*/
typedef struct {
int fd;
unsigned int offset;
size_t size;
} SpaDataFD;
/**
* SpaData:
* @id: user id
* @type: the type of data
* @data: pointer to data
* @size: size of data
*/
typedef struct {
SpaDataType type;
void *data;
size_t size;
} SpaData;
/**
* SpaBuffer:
* @refcount: reference counter
* @notify: called when the refcount reaches 0
* @size: total size of the buffer data
* @n_metas: number of metadata
* @metas: array of @n_metas metadata
* @n_datas: number of data pointers
* @datas: array of @n_datas data pointers
*/
struct _SpaBuffer {
volatile int refcount;
SpaNotify notify;
size_t size;
unsigned int n_metas;
SpaMeta *metas;
unsigned int n_datas;
SpaData *datas;
};
/**
* spa_buffer_ref:
* @buffer: a #SpaBuffer
*
* Increase the refcount on @buffer
*
* Returns: @buffer
*/
static inline SpaBuffer *
spa_buffer_ref (SpaBuffer *buffer)
{
if (buffer != NULL)
buffer->refcount++;
return buffer;
}
/**
* spa_buffer_unref:
* @buffer: a #SpaBuffer
*
* Decrease the refcount on buffer. when the refcount is 0, the notify,
* if any, of the buffer will be called.
*
* Returns: @buffer or %NULL when the refcount is 0
*/
static inline SpaBuffer *
spa_buffer_unref (SpaBuffer *buffer)
{
if (buffer != NULL) {
if (--buffer->refcount == 0) {
if (buffer->notify)
buffer->notify (buffer);
return NULL;
}
}
return buffer;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_BUFFER_H__ */

55
spa/include/spa/command.h Normal file
View file

@ -0,0 +1,55 @@
/* 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_COMMAND_H__
#define __SPA_COMMAND_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaCommand SpaCommand;
#include <spa/defs.h>
typedef enum {
SPA_COMMAND_INVALID = 0,
SPA_COMMAND_ACTIVATE,
SPA_COMMAND_DEACTIVATE,
SPA_COMMAND_START,
SPA_COMMAND_STOP,
SPA_COMMAND_FLUSH,
SPA_COMMAND_DRAIN,
SPA_COMMAND_MARKER,
} SpaCommandType;
struct _SpaCommand {
volatile int refcount;
SpaNotify notify;
SpaCommandType type;
uint32_t port_id;
void *data;
size_t size;
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_COMMAND_H__ */

74
spa/include/spa/defs.h Normal file
View file

@ -0,0 +1,74 @@
/* 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_DEFS_H__
#define __SPA_DEFS_H__
#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif
#include <inttypes.h>
#include <stdlib.h>
typedef enum {
SPA_RESULT_OK = 0,
SPA_RESULT_ERROR = -1,
SPA_RESULT_INACTIVE = -2,
SPA_RESULT_NO_FORMAT = -3,
SPA_RESULT_INVALID_COMMAND = -4,
SPA_RESULT_INVALID_PORT = -5,
SPA_RESULT_HAVE_ENOUGH_INPUT = -6,
SPA_RESULT_NEED_MORE_INPUT = -7,
SPA_RESULT_PORTS_CHANGED = -9,
SPA_RESULT_FORMAT_CHANGED = -10,
SPA_RESULT_PROPERTIES_CHANGED = -11,
SPA_RESULT_NOT_IMPLEMENTED = -12,
SPA_RESULT_INVALID_PROPERTY_INDEX = -13,
SPA_RESULT_PROPERTY_UNSET = -14,
SPA_RESULT_ENUM_END = -15,
SPA_RESULT_WRONG_PROPERTY_TYPE = -16,
SPA_RESULT_WRONG_PROPERTY_SIZE = -17,
SPA_RESULT_INVALID_MEDIA_TYPE = -18,
SPA_RESULT_INVALID_FORMAT_PROPERTIES = -19,
SPA_RESULT_FORMAT_INCOMPLETE = -20,
SPA_RESULT_INVALID_ARGUMENTS = -21,
SPA_RESULT_UNKNOWN_INTERFACE = -22,
SPA_RESULT_INVALID_DIRECTION = -23,
SPA_RESULT_TOO_MANY_PORTS = -24,
SPA_RESULT_INVALID_PROPERTY_ACCESS = -25,
} SpaResult;
typedef enum {
SPA_DIRECTION_INVALID = 0,
SPA_DIRECTION_INPUT,
SPA_DIRECTION_OUTPUT
} SpaDirection;
typedef void (*SpaNotify) (void *data);
#define SPA_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_DEFS_H__ */

76
spa/include/spa/event.h Normal file
View 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_EVENT_H__
#define __SPA_EVENT_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaEvent SpaEvent;
#include <spa/defs.h>
/**
* SpaEventType:
* @SPA_EVENT_TYPE_INVALID: invalid event, should be ignored
* @SPA_EVENT_TYPE_ACTIVATED: emited when the ACTIVATE command completes
* @SPA_EVENT_TYPE_DEACTIVATED: emited when the DEACTIVATE command completes
* @SPA_EVENT_TYPE_CAN_PULL_OUTPUT: emited when an async node has output that can be pulled
* @SPA_EVENT_TYPE_CAN_PUSH_INTPUT: emited when more data can be pushed to an async node
* @SPA_EVENT_TYPE_PULL_INPUT: emited when data needs to be provided on an input
* @SPA_EVENT_TYPE_ALLOC_OUTPUT: emited when an output buffer needs to be allocated
* @SPA_EVENT_TYPE_ADD_POLL: emited when a pollfd should be added
* @SPA_EVENT_TYPE_REMOVE_POLL: emited when a pollfd should be removed
* @SPA_EVENT_TYPE_DRAINED: emited when DRAIN command completed
* @SPA_EVENT_TYPE_MARKER: emited when MARK command completed
* @SPA_EVENT_TYPE_ERROR: emited when error occured
* @SPA_EVENT_TYPE_BUFFERING: emited when buffering is in progress
*/
typedef enum {
SPA_EVENT_TYPE_INVALID = 0,
SPA_EVENT_TYPE_ACTIVATED,
SPA_EVENT_TYPE_DEACTIVATED,
SPA_EVENT_TYPE_CAN_PULL_OUTPUT,
SPA_EVENT_TYPE_CAN_PUSH_INTPUT,
SPA_EVENT_TYPE_PULL_INPUT,
SPA_EVENT_TYPE_ALLOC_OUTPUT,
SPA_EVENT_TYPE_ADD_POLL,
SPA_EVENT_TYPE_REMOVE_POLL,
SPA_EVENT_TYPE_DRAINED,
SPA_EVENT_TYPE_MARKER,
SPA_EVENT_TYPE_ERROR,
SPA_EVENT_TYPE_BUFFERING,
} SpaEventType;
struct _SpaEvent {
volatile int refcount;
SpaNotify notify;
SpaEventType type;
uint32_t port_id;
void *data;
size_t size;
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_EVENT_H__ */

57
spa/include/spa/format.h Normal file
View file

@ -0,0 +1,57 @@
/* 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_FORMAT_H__
#define __SPA_FORMAT_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaFormat SpaFormat;
#include <spa/defs.h>
#include <spa/props.h>
typedef enum {
SPA_MEDIA_TYPE_INVALID = 0,
SPA_MEDIA_TYPE_AUDIO = 1,
} SpaMediaType;
typedef enum {
SPA_MEDIA_SUBTYPE_INVALID = 0,
SPA_MEDIA_SUBTYPE_RAW = 1,
} SpaMediaSubType;
struct _SpaFormat {
SpaProps props;
SpaMediaType media_type;
SpaMediaSubType media_subtype;
};
typedef enum {
SPA_PROP_ID_INVALID = 0,
SPA_PROP_ID_MEDIA_CUSTOM_START = 200,
} SpaFormatProps;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_FORMAT_H__ */

View file

@ -0,0 +1,8 @@
install_headers('buffer.h',
'command.h',
'defs.h',
'event.h',
'node.h',
'plugin.h',
'port.h',
'props.h')

370
spa/include/spa/node.h Normal file
View file

@ -0,0 +1,370 @@
/* 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_NODE_H__
#define __SPA_NODE_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaNode SpaNode;
#include <spa/defs.h>
#include <spa/plugin.h>
#include <spa/props.h>
#include <spa/port.h>
#include <spa/event.h>
#include <spa/buffer.h>
#include <spa/command.h>
#include <spa/format.h>
/**
* SpaInputFlags:
* @SPA_INPUT_FLAG_NONE: no flag
*/
typedef enum {
SPA_INPUT_FLAG_NONE = 0,
} SpaInputFlags;
/**
* SpaInputInfo:
* @port_id: the port id
* @flags: extra flags
* @buffer: a buffer
*
* Input information for a node.
*/
typedef struct {
uint32_t port_id;
SpaInputFlags flags;
SpaBuffer *buffer;
SpaEvent *event;
SpaResult status;
} SpaInputInfo;
/**
* SpaOutputFlags:
* @SPA_OUTPUT_FLAG_NONE: no flag
* @SPA_OUTPUT_FLAG_PULL: force a #SPA_EVENT_NEED_INPUT event on the
* peer input ports when no data is available.
* @SPA_OUTPUT_FLAG_DISCARD: discard the buffer data
* @SPA_OUTPUT_FLAG_NO_BUFFER: no buffer was produced on the port
*/
typedef enum {
SPA_OUTPUT_FLAG_NONE = 0,
SPA_OUTPUT_FLAG_PULL = (1 << 0),
SPA_OUTPUT_FLAG_DISCARD = (1 << 1),
SPA_OUTPUT_FLAG_NO_BUFFER = (1 << 2),
} SpaOutputFlags;
/**
* SpaOutputInfo:
* @port_id: the port id
* @flags: extra flags
* @buffer: a buffer
* @event: an event
*
* Output information for a node.
*/
typedef struct {
uint32_t port_id;
SpaOutputFlags flags;
SpaBuffer *buffer;
SpaEvent *event;
SpaResult status;
} SpaOutputInfo;
/**
* SpaEventCallback:
* @node: a #SpaHandle emiting the event
* @event: the event that was emited
* @user_data: user data provided when registering the callback
*
* This will be called when an out-of-bound event is notified
* on @node.
*/
typedef void (*SpaEventCallback) (SpaHandle *handle,
SpaEvent *event,
void *user_data);
#define SPA_INTERFACE_ID_NODE 0
#define SPA_INTERFACE_ID_NODE_NAME "Node interface"
#define SPA_INTERFACE_ID_NODE_DESCRIPTION "Main processing node interface"
/**
* SpaNode:
*
* The main processing nodes.
*/
struct _SpaNode {
/* the total size of this node. This can be used to expand this
* structure in the future */
size_t size;
/**
* SpaNode::get_props:
* @handle: a #SpaHandle
* @props: a location for a #SpaProps pointer
*
* Get the configurable properties of @node.
*
* The returned @props is a snapshot of the current configuration and
* can be modified. The modifications will take effect after a call
* to SpaNode::set_props.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node or props are %NULL
* #SPA_RESULT_NOT_IMPLEMENTED when there are no properties
* implemented on @node
*/
SpaResult (*get_props) (SpaHandle *handle,
SpaProps **props);
/**
* SpaNode::set_props:
* @handle: a #SpaHandle
* @props: a #SpaProps
*
* Set the configurable properties in @node.
*
* Usually, @props will be obtained from SpaNode::get_props and then
* modified but it is also possible to set another #SpaProps object
* as long as its keys and types match those of SpaProps::get_props.
*
* Properties with keys that are not known are ignored.
*
* If @props is NULL, all the properties are reset to their defaults.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
* #SPA_RESULT_NOT_IMPLEMENTED when no properties can be
* modified on @node.
* #SPA_RESULT_WRONG_PROPERTY_TYPE when a property has the wrong
* type.
*/
SpaResult (*set_props) (SpaHandle *handle,
const SpaProps *props);
/**
* SpaNode::send_command:
* @handle: a #SpaHandle
* @command: a #SpaCommand
*
* Send a command to @node.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node or command is %NULL
* #SPA_RESULT_NOT_IMPLEMENTED when this node can't process commands
* #SPA_RESULT_INVALID_COMMAND @command is an invalid command
*/
SpaResult (*send_command) (SpaHandle *handle,
SpaCommand *command);
/**
* SpaNode::set_event_callback:
* @handle: a #SpaHandle
* @callback: a callback
* @user_data: user data passed in the callback
*
* Set a callback to receive events from @node. if @callback is %NULL, the
* current callback is removed.
*
* The callback can be emited from any thread. The caller should take
* appropriate actions to handle the event in other threads when needed.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
*/
SpaResult (*set_event_callback) (SpaHandle *handle,
SpaEventCallback callback,
void *user_data);
/**
* SpaNode::get_n_ports:
* @handle: a #SpaHandle
* @n_input_ports: location to hold the number of input ports or %NULL
* @max_input_ports: location to hold the maximum number of input ports or %NULL
* @n_output_ports: location to hold the number of output ports or %NULL
* @max_output_ports: location to hold the maximum number of output ports or %NULL
*
* Get the current number of input and output ports and also the maximum
* number of ports.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
*/
SpaResult (*get_n_ports) (SpaHandle *handle,
unsigned int *n_input_ports,
unsigned int *max_input_ports,
unsigned int *n_output_ports,
unsigned int *max_output_ports);
/**
* SpaNode::get_port_ids:
* @handle: a #SpaHandle
* @n_input_ports: size of the @input_ids array
* @input_ids: array to store the input stream ids
* @n_output_ports: size of the @output_ids array
* @output_ids: array to store the output stream ids
*
* Get the current number of input and output ports and also the maximum
* number of ports.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
*/
SpaResult (*get_port_ids) (SpaHandle *handle,
unsigned int n_input_ports,
uint32_t *input_ids,
unsigned int n_output_ports,
uint32_t *output_ids);
SpaResult (*add_port) (SpaHandle *handle,
SpaDirection direction,
uint32_t *port_id);
SpaResult (*remove_port) (SpaHandle *handle,
uint32_t port_id);
/**
* SpaNode::enum_port_formats:
* @handle: a #SpaHandle
* @port_id: the port to query
* @index: the format index to retrieve
* @format: pointer to a format
*
* Enumerate all possible formats on @port_id of @node.
*
* Use the index to retrieve the formats one by one until the function
* returns #SPA_RESULT_ENUM_END.
*
* The result format can be queried and modified and ultimately be used
* to call SpaNode::set_port_format.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node or format is %NULL
* #SPA_RESULT_INVALID_PORT when port_id is not valid
* #SPA_RESULT_ENUM_END when no format exists for @index
*
*/
SpaResult (*enum_port_formats) (SpaHandle *handle,
uint32_t port_id,
unsigned int index,
SpaFormat **format);
/**
* SpaNode::set_port_format:
* @handle: a #SpaHandle
* @port_id: the port to configure
* @format: a #SpaFormat with the format
*
* Set a format on @port_id of @node.
*
* When @format is %NULL, the current format will be removed.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
* #SPA_RESULT_INVALID_PORT when port_id is not valid
* #SPA_RESULT_INVALID_MEDIA_TYPE when the media type is not valid
* #SPA_RESULT_INVALID_FORMAT_PROPERTIES when one of the mandatory format
* properties is not specified.
* #SPA_RESULT_WRONG_PROPERTY_TYPE when the type or size of a property
* is not correct.
*/
SpaResult (*set_port_format) (SpaHandle *handle,
uint32_t port_id,
int test_only,
const SpaFormat *format);
/**
* SpaNode::get_port_format:
* @handle: a #SpaHandle
* @port_id: the port to query
* @format: a pointer to a location to hold the #SpaFormat
*
* Get the format on @port_id of @node. The result #SpaFormat can
* not be modified.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when @node or @format is %NULL
* #SPA_RESULT_INVALID_PORT when @port_id is not valid
* #SPA_RESULT_INVALID_NO_FORMAT when no format was set
*/
SpaResult (*get_port_format) (SpaHandle *handle,
uint32_t port_id,
const SpaFormat **format);
SpaResult (*get_port_info) (SpaHandle *handle,
uint32_t port_id,
const SpaPortInfo **info);
SpaResult (*get_port_props) (SpaHandle *handle,
uint32_t port_id,
SpaProps **props);
SpaResult (*set_port_props) (SpaHandle *handle,
uint32_t port_id,
const SpaProps *props);
SpaResult (*get_port_status) (SpaHandle *handle,
uint32_t port_id,
const SpaPortStatus **status);
/**
* SpaNode::push_port_input:
* @handle: a #SpaHandle
* @n_info: number of #SpaInputInfo in @info
* @info: array of #SpaInputInfo
*
* Push a buffer and/or an event into one or more input ports of
* @node.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node or info is %NULL
* #SPA_RESULT_ERROR when one or more of the @info has an
* error result. Check the status of all the
* @info.
* #SPA_RESULT_HAVE_ENOUGH_INPUT when output can be produced.
*/
SpaResult (*push_port_input) (SpaHandle *handle,
unsigned int n_info,
SpaInputInfo *info);
/**
* SpaNode::pull_port_output:
* @handle: a #SpaHandle
* @n_info: number of #SpaOutputInfo in @info
* @info: array of #SpaOutputInfo
*
* Pull a buffer and/or an event from one or more output ports of
* @node.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node or info is %NULL
* #SPA_RESULT_PORTS_CHANGED the number of ports has changed. None
* of the @info fields are modified
* #SPA_RESULT_FORMAT_CHANGED a format changed on some port.
* the ports that changed are marked in the status.
* #SPA_RESULT_PROPERTIES_CHANGED port properties changed. The
* changed ports are marked in the status.
* #SPA_RESULT_ERROR when one or more of the @info has an
* error result. Check the status of all the @info.
* #SPA_RESULT_NEED_MORE_INPUT when no output can be produced
* because more input is needed.
*/
SpaResult (*pull_port_output) (SpaHandle *handle,
unsigned int n_info,
SpaOutputInfo *info);
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_NODE_H__ */

145
spa/include/spa/plugin.h Normal file
View file

@ -0,0 +1,145 @@
/* 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/defs.h>
#include <spa/props.h>
typedef struct _SpaHandle SpaHandle;
typedef struct _SpaHandleFactory SpaHandleFactory;
struct _SpaHandle {
/* user_data that can be set by the application */
void * user_data;
/**
* SpaHandle::get_interface:
* @handle: a #SpaHandle
* @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
*/
SpaResult (*get_interface) (SpaHandle *handle,
uint32_t interface_id,
const void **interface);
};
/**
* SpaInterfaceInfo:
* @interface_id: the id of the interface, can be used to get the interface
* @name: name of the interface
* @description: Human readable description of the interface.
*
* This structure lists the information about available interfaces on
* handles.
*/
typedef struct {
uint32_t interface_id;
const char *name;
const char *description;
} SpaInterfaceInfo;
struct _SpaHandleFactory {
/**
* SpaHandleFactory::name
*
* The name
*/
const char * name;
/**
* SpaHandleFactory::info
*
* Extra information about the handles of this factory.
*/
const SpaProps * info;
/**
* SpaHandleFactory::instantiate
* @factory: a #SpaHandleFactory
* @handle: a pointer to hold the result
*
* Make an instance of this factory.
*
* 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
*/
SpaResult (*instantiate) (const SpaHandleFactory *factory,
SpaHandle **handle);
/**
* SpaHandle::enum_interface_info:
* @factory: a #SpaHandleFactory
* @index: the interface index
* @info: result to hold SpaInterfaceInfo.
*
* Get the interface information at @index.
*
* 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
*/
SpaResult (*enum_interface_info) (const SpaHandleFactory *factory,
unsigned int index,
const SpaInterfaceInfo **info);
};
/**
* SpaEnumHandleFactoryFunc:
* @index: the index to enumerate
* @factory: a location to hold the factory result
*
* 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 SpaResult (*SpaEnumHandleFactoryFunc) (unsigned int index,
const SpaHandleFactory **factory);
/**
* spa_enum_handle_factory:
* @index: the index to enumerate
* @factory: a location to hold the factory result
*
* 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
*/
SpaResult spa_enum_handle_factory (unsigned int index,
const SpaHandleFactory **factory);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_PLUGIN_H__ */

95
spa/include/spa/port.h Normal file
View file

@ -0,0 +1,95 @@
/* 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_PORT_H__
#define __SPA_PORT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/defs.h>
/**
* SpaPortInfoFlags:
* @SPA_PORT_INFO_FLAG_NONE: no flags
* @SPA_PORT_INFO_FLAG_REMOVABLE: port can be removed
* @SPA_PORT_INFO_FLAG_OPTIONAL: processing on port is optional
* @SPA_PORT_INFO_FLAG_CAN_GIVE_BUFFER: the port can give a buffer
* @SPA_PORT_INFO_FLAG_CAN_USE_BUFFER: the port can use a provided buffer
* @SPA_PORT_INFO_FLAG_IN_PLACE: the port can process data in-place and will need
* a writable input buffer when no output buffer is specified.
* @SPA_PORT_INFO_FLAG_NO_REF: the port does not keep a ref on the buffer
*/
typedef enum {
SPA_PORT_INFO_FLAG_NONE = 0,
SPA_PORT_INFO_FLAG_REMOVABLE = 1 << 0,
SPA_PORT_INFO_FLAG_OPTIONAL = 1 << 1,
SPA_PORT_INFO_FLAG_CAN_GIVE_BUFFER = 1 << 2,
SPA_PORT_INFO_FLAG_CAN_USE_BUFFER = 1 << 3,
SPA_PORT_INFO_FLAG_IN_PLACE = 1 << 4,
SPA_PORT_INFO_FLAG_NO_REF = 1 << 5,
} SpaPortInfoFlags;
/**
* SpaPortInfo
* @flags: extra port flags
* @size: minimum size of the buffers or 0 when not specified
* @align: required alignment of the data
* @maxbuffering: the maximum amount of bytes that the element will keep
* around internally
* @latency: latency on this port in nanoseconds
* @features: NULL terminated array of extra port features
*
*/
typedef struct {
SpaPortInfoFlags flags;
size_t minsize;
uint32_t align;
unsigned int maxbuffering;
uint64_t latency;
const char **features;
} SpaPortInfo;
/**
* SpaPortStatusFlags:
* @SPA_PORT_STATUS_FLAG_NONE: no status flags
* @SPA_PORT_STATUS_FLAG_HAVE_OUTPUT: port has output
* @SPA_PORT_STATUS_FLAG_NEED_INPUT: port needs input
*/
typedef enum {
SPA_PORT_STATUS_FLAG_NONE = 0,
SPA_PORT_STATUS_FLAG_HAVE_OUTPUT = 1 << 0,
SPA_PORT_STATUS_FLAG_NEED_INPUT = 1 << 1,
} SpaPortStatusFlags;
/**
* SpaPortStatus:
* @flags: port status flags
*/
typedef struct {
SpaPortStatusFlags flags;
} SpaPortStatus;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_PORT_H__ */

242
spa/include/spa/props.h Normal file
View file

@ -0,0 +1,242 @@
/* 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_PROPS_H__
#define __SPA_PROPS_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaProps SpaProps;
#include <string.h>
#include <spa/defs.h>
/**
* SpaPropType:
*/
typedef enum {
SPA_PROP_TYPE_INVALID = 0,
SPA_PROP_TYPE_BOOL,
SPA_PROP_TYPE_INT8,
SPA_PROP_TYPE_UINT8,
SPA_PROP_TYPE_INT16,
SPA_PROP_TYPE_UINT16,
SPA_PROP_TYPE_INT32,
SPA_PROP_TYPE_UINT32,
SPA_PROP_TYPE_INT64,
SPA_PROP_TYPE_UINT64,
SPA_PROP_TYPE_FLOAT,
SPA_PROP_TYPE_DOUBLE,
SPA_PROP_TYPE_STRING,
SPA_PROP_TYPE_POINTER,
SPA_PROP_TYPE_FRACTION,
SPA_PROP_TYPE_BITMASK,
SPA_PROP_TYPE_BYTES,
SPA_PROP_TYPE_STRUCT,
} SpaPropType;
/**
* SpaPropFlags:
* @SPA_PROP_FLAG_NONE: no flags
* @SPA_PROP_FLAG_OPTIONAL: the value can be left unset
* @SPA_PROP_FLAG_READABLE: property is readable
* @SPA_PROP_FLAG_WRITABLE: property is writable
* @SPA_PROP_FLAG_READWRITE: property is readable and writable
* @SPA_PROP_FLAG_DEPRECATED: property is deprecated and should not be used
*/
typedef enum {
SPA_PROP_FLAG_NONE = 0,
SPA_PROP_FLAG_OPTIONAL = (1 << 0),
SPA_PROP_FLAG_READABLE = (1 << 1),
SPA_PROP_FLAG_WRITABLE = (1 << 2),
SPA_PROP_FLAG_READWRITE = SPA_PROP_FLAG_READABLE | SPA_PROP_FLAG_WRITABLE,
SPA_PROP_FLAG_DEPRECATED = (1 << 3),
} SpaPropFlags;
/* SpaPropRangeType:
* @SPA_PROP_RANGE_TYPE_NONE: no range specified, full range of type applies
* @SPA_PROP_RANGE_TYPE_MIN_MAX: range contains 2 values, min and max
* @SPA_PROP_RANGE_TYPE_ENUM: range contains enum of possible values with
* NULL-terminated name
* @SPA_PROP_RANGE_TYPE_FLAGS: range contains flags of possible values with
* NULL-terminated name
*/
typedef enum {
SPA_PROP_RANGE_TYPE_NONE = 0,
SPA_PROP_RANGE_TYPE_MIN_MAX,
SPA_PROP_RANGE_TYPE_ENUM,
SPA_PROP_RANGE_TYPE_FLAGS,
} SpaPropRangeType;
/**
* SpaPropRangeInfo:
* @name: name of this value
* @description: user visible description of this value
* @size: the size of value
* @value: a possible value
*/
typedef struct {
const char *name;
const char *description;
size_t size;
const void *value;
} SpaPropRangeInfo;
/**
* SpaPropInfo:
* @id: unique id
* @name: human readable name
* @description: description of the property
* @flags: property flags
* @type: property type
* @max_size: maximum size of property value
* @default_size: size of default value
* @default_value: default value of property
* @range_type: type of the range values
* @n_range_values: number of elements in @range_values
* @range_values: array of possible values
* @tags: extra tags, NULL terminated
* @offset: offset in structure with data
* @unset_mask: mask to clear when value is set
* @priv: extra private data
*/
typedef struct {
uint32_t id;
const char *name;
const char *description;
SpaPropFlags flags;
SpaPropType type;
size_t maxsize;
size_t default_size;
const void *default_value;
SpaPropRangeType range_type;
unsigned int n_range_values;
const SpaPropRangeInfo *range_values;
const char **tags;
size_t offset;
size_t mask_offset;
uint32_t unset_mask;
const void *priv;
} SpaPropInfo;
typedef struct {
SpaPropType type;
size_t size;
const void *value;
} SpaPropValue;
/**
* SpaProps:
*
* Generic propertiers.
*/
struct _SpaProps {
/**
* SpaProps::n_prop_info:
*
* The number of items in @prop_info.
*/
unsigned int n_prop_info;
/**
* SpaProps::prop_info:
*
* Info about the properties. Can be %NULL when unspecified.
*/
const SpaPropInfo *prop_info;
/**
* SpaProps::set_prop
* @props: a #SpaProps
* @index: the index of the property in the prop_info array
* @value: the value to set
*
* Sets @value in @prop. type should match the type specified
* in the #SpaPropInfo at @index or else #SPA_RESULT_WRONG_PROPERTY_TYPE
* is returned.
*
* Returns: #SPA_RESULT_OK on success.
* #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid
* #SPA_RESULT_WRONG_PROPERTY_TYPE when type is not correct
*/
SpaResult (*set_prop) (SpaProps *props,
unsigned int index,
const SpaPropValue *value);
/**
* SpaProps::get_prop
* @props: a #SpaProps
* @index: the property index in the prop_info array
* @value: a location for the type, size and value
*
* Get the type, size and value of the property at @index.
*
* Returns: #SPA_RESULT_OK on success.
* #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid
* #SPA_RESULT_PROPERTY_UNSET when no value has been set yet
*/
SpaResult (*get_prop) (const SpaProps *props,
unsigned int index,
SpaPropValue *value);
void *priv;
};
static inline unsigned int
spa_props_index_for_id (const SpaProps *props, uint32_t id)
{
unsigned int i;
for (i = 0; i < props->n_prop_info; i++) {
if (props->prop_info[i].id == id)
return i;
}
return -1;
}
static inline unsigned int
spa_props_index_for_name (const SpaProps *props, const char *name)
{
unsigned int i;
for (i = 0; i < props->n_prop_info; i++) {
if (strcmp (props->prop_info[i].name, name) == 0)
return i;
}
return -1;
}
SpaResult spa_props_generic_set_prop (SpaProps *props,
unsigned int index,
const SpaPropValue *value);
SpaResult spa_props_generic_get_prop (const SpaProps *props,
unsigned int index,
SpaPropValue *value);
SpaResult spa_props_copy (const SpaProps *src,
SpaProps *dest);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_PROPS_H__ */

View file

@ -0,0 +1,71 @@
/* 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_RINGBUFFER_H__
#define __SPA_RINGBUFFER_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaRingbuffer SpaRingbuffer;
#include <spa/defs.h>
typedef struct {
uint8_t *data;
size_t len;
} SpaRingbufferArea;
/**
* SpaRingbuffer:
* @data: pointer to data
* @readindex: the current read index
* @writeindex: the current write index
* @size: the size of the ringbuffer
* @size_mask: mask if @size is power of 2
*/
struct _SpaRingbuffer {
uint8_t *data;
volatile size_t readindex;
volatile size_t writeindex;
size_t size;
size_t size_mask;
};
SpaResult spa_ringbuffer_init (SpaRingbuffer *rbuf,
uint8_t *data, size_t size);
SpaResult spa_ringbuffer_clear (SpaRingbuffer *rbuf);
SpaResult spa_ringbuffer_get_read_areas (SpaRingbuffer *rbuf,
SpaRingbufferArea areas[2]);
SpaResult spa_ringbuffer_read_advance (SpaRingbuffer *rbuf,
ssize_t len);
SpaResult spa_ringbuffer_get_write_areas (SpaRingbuffer *rbuf,
SpaRingbufferArea areas[2]);
SpaResult spa_ringbuffer_write_advance (SpaRingbuffer *rbuf,
ssize_t len);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_RINGBUFFER_H__ */