Reorganize serialization code a bit

Move the proxy plugin to the client-node
Move serialization code to pinos because its specific to pinos
Move some functions to the .h files
Make the mapper dynamic
This commit is contained in:
Wim Taymans 2016-10-17 12:20:49 +02:00
parent 8520246a1b
commit d8903b708d
25 changed files with 1950 additions and 3858 deletions

View file

@ -174,7 +174,7 @@ struct _SpaBuffer {
SpaData *datas;
};
inline void *
static inline void *
spa_buffer_find_meta (SpaBuffer *b, SpaMetaType type)
{
unsigned int i;
@ -185,11 +185,20 @@ spa_buffer_find_meta (SpaBuffer *b, SpaMetaType type)
return NULL;
}
size_t spa_buffer_get_size (const SpaBuffer *buffer);
size_t spa_buffer_serialize (void *dest, const SpaBuffer *buffer);
SpaBuffer * spa_buffer_deserialize (void *src, off_t offset);
size_t spa_meta_type_get_size (SpaMetaType type);
static inline size_t
spa_meta_type_get_size (SpaMetaType type)
{
static const size_t header_sizes[] = {
0,
sizeof (SpaMetaHeader),
sizeof (SpaMetaPointer),
sizeof (SpaMetaVideoCrop),
sizeof (SpaMetaRingbuffer),
};
if (type <= 0 || type >= SPA_N_ELEMENTS (header_sizes))
return 0;
return header_sizes[type];
}
#ifdef __cplusplus
} /* extern "C" */

View file

@ -1,270 +0,0 @@
/* 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_CONTROL_H__
#define __SPA_CONTROL_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaControl SpaControl;
typedef struct _SpaControlIter SpaControlIter;
typedef struct _SpaControlBuilder SpaControlBuilder;
#define SPA_CONTROL_VERSION 0
#include <spa/defs.h>
#include <spa/props.h>
#include <spa/format.h>
#include <spa/port.h>
#include <spa/node.h>
struct _SpaControl {
size_t x[16];
};
SpaResult spa_control_init_data (SpaControl *control,
void *data,
size_t size,
int *fds,
unsigned int n_fds);
SpaResult spa_control_clear (SpaControl *control);
uint32_t spa_control_get_version (SpaControl *control);
int spa_control_get_fd (SpaControl *control,
unsigned int index,
bool close);
typedef enum {
SPA_CONTROL_CMD_INVALID = 0,
/* client to server */
SPA_CONTROL_CMD_NODE_UPDATE = 1,
SPA_CONTROL_CMD_PORT_UPDATE = 2,
SPA_CONTROL_CMD_NODE_STATE_CHANGE = 3,
SPA_CONTROL_CMD_PORT_STATUS_CHANGE = 4,
/* server to client */
SPA_CONTROL_CMD_ADD_PORT = 32,
SPA_CONTROL_CMD_REMOVE_PORT = 33,
SPA_CONTROL_CMD_SET_FORMAT = 34,
SPA_CONTROL_CMD_SET_PROPERTY = 35,
SPA_CONTROL_CMD_NODE_COMMAND = 36,
/* both */
SPA_CONTROL_CMD_ADD_MEM = 64,
SPA_CONTROL_CMD_REMOVE_MEM = 65,
SPA_CONTROL_CMD_USE_BUFFERS = 66,
SPA_CONTROL_CMD_PROCESS_BUFFER = 67,
SPA_CONTROL_CMD_NODE_EVENT = 68,
} SpaControlCmd;
/* SPA_CONTROL_CMD_NODE_UPDATE */
typedef struct {
#define SPA_CONTROL_CMD_NODE_UPDATE_MAX_INPUTS (1 << 0)
#define SPA_CONTROL_CMD_NODE_UPDATE_MAX_OUTPUTS (1 << 1)
#define SPA_CONTROL_CMD_NODE_UPDATE_PROPS (1 << 2)
uint32_t change_mask;
unsigned int max_input_ports;
unsigned int max_output_ports;
const SpaProps *props;
} SpaControlCmdNodeUpdate;
/* SPA_CONTROL_CMD_PORT_UPDATE */
typedef struct {
SpaDirection direction;
uint32_t port_id;
#define SPA_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS (1 << 0)
#define SPA_CONTROL_CMD_PORT_UPDATE_FORMAT (1 << 1)
#define SPA_CONTROL_CMD_PORT_UPDATE_PROPS (1 << 2)
#define SPA_CONTROL_CMD_PORT_UPDATE_INFO (1 << 3)
uint32_t change_mask;
unsigned int n_possible_formats;
SpaFormat **possible_formats;
SpaFormat *format;
const SpaProps *props;
const SpaPortInfo *info;
} SpaControlCmdPortUpdate;
/* SPA_CONTROL_CMD_PORT_STATUS_CHANGE */
/* SPA_CONTROL_CMD_NODE_STATE_CHANGE */
typedef struct {
SpaNodeState state;
} SpaControlCmdNodeStateChange;
/* SPA_CONTROL_CMD_ADD_PORT */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
} SpaControlCmdAddPort;
/* SPA_CONTROL_CMD_REMOVE_PORT */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
} SpaControlCmdRemovePort;
/* SPA_CONTROL_CMD_SET_FORMAT */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
SpaPortFormatFlags flags;
SpaFormat *format;
} SpaControlCmdSetFormat;
/* SPA_CONTROL_CMD_SET_PROPERTY */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
uint32_t id;
size_t size;
void *value;
} SpaControlCmdSetProperty;
/* SPA_CONTROL_CMD_NODE_COMMAND */
typedef struct {
uint32_t seq;
SpaNodeCommand *command;
} SpaControlCmdNodeCommand;
/* SPA_CONTROL_CMD_ADD_MEM */
typedef struct {
SpaDirection direction;
uint32_t port_id;
uint32_t mem_id;
SpaDataType type;
unsigned int fd_index;
uint32_t flags;
off_t offset;
size_t size;
} SpaControlCmdAddMem;
/* SPA_CONTROL_CMD_REMOVE_MEM */
typedef struct {
SpaDirection direction;
uint32_t port_id;
uint32_t mem_id;
} SpaControlCmdRemoveMem;
typedef struct {
uint32_t mem_id;
off_t offset;
size_t size;
} SpaControlMemRef;
/* SPA_CONTROL_CMD_USE_BUFFERS */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
unsigned int n_buffers;
SpaControlMemRef *buffers;
} SpaControlCmdUseBuffers;
/* SPA_CONTROL_CMD_PROCESS_BUFFER */
typedef struct {
SpaDirection direction;
uint32_t port_id;
uint32_t buffer_id;
} SpaControlCmdProcessBuffer;
/* SPA_CONTROL_CMD_NODE_EVENT */
typedef struct {
SpaNodeEvent *event;
} SpaControlCmdNodeEvent;
struct _SpaControlIter {
/*< private >*/
size_t x[16];
};
SpaResult spa_control_iter_init_full (SpaControlIter *iter,
SpaControl *control,
uint32_t version);
#define spa_control_iter_init(i,b) spa_control_iter_init_full(i,b, SPA_CONTROL_VERSION);
SpaResult spa_control_iter_next (SpaControlIter *iter);
SpaResult spa_control_iter_end (SpaControlIter *iter);
SpaControlCmd spa_control_iter_get_cmd (SpaControlIter *iter);
void * spa_control_iter_get_data (SpaControlIter *iter,
size_t *size);
SpaResult spa_control_iter_set_data (SpaControlIter *iter,
void *data,
size_t size);
SpaResult spa_control_iter_parse_cmd (SpaControlIter *iter,
void *command);
/**
* SpaControlBuilder:
*/
struct _SpaControlBuilder {
/*< private >*/
size_t x[16];
};
SpaResult spa_control_builder_init_full (SpaControlBuilder *builder,
uint32_t version,
void *data,
size_t max_data,
int *fds,
unsigned int max_fds);
#define spa_control_builder_init_into(b,d,md,f,mf) spa_control_builder_init_full(b, SPA_CONTROL_VERSION,d,md,f,mf);
#define spa_control_builder_init(b) spa_control_builder_init_into(b, NULL, 0, NULL, 0);
SpaResult spa_control_builder_clear (SpaControlBuilder *builder);
SpaResult spa_control_builder_end (SpaControlBuilder *builder,
SpaControl *control);
int spa_control_builder_add_fd (SpaControlBuilder *builder,
int fd,
bool close);
SpaResult spa_control_builder_add_cmd (SpaControlBuilder *builder,
SpaControlCmd cmd,
void *command);
/* IO */
SpaResult spa_control_read (SpaControl *control,
int fd,
void *data,
size_t max_data,
int *fds,
unsigned int max_fds);
SpaResult spa_control_write (SpaControl *control,
int fd);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_CONTROL_H__ */

View file

@ -98,14 +98,15 @@ typedef enum {
} SpaFormatProps;
SpaResult spa_format_fixate (SpaFormat *format);
size_t spa_format_get_size (const SpaFormat *format);
size_t spa_format_serialize (void *dest, const SpaFormat *format);
SpaFormat * spa_format_deserialize (void *src, off_t offset);
SpaFormat * spa_format_copy_into (void *dest, const SpaFormat *format);
static inline SpaResult
spa_format_fixate (SpaFormat *format)
{
if (format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
format->props.unset_mask = 0;
return SPA_RESULT_OK;
}
#ifdef __cplusplus
} /* extern "C" */

View file

@ -107,6 +107,8 @@ struct _SpaLog {
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,...) \
@ -124,7 +126,7 @@ struct _SpaLog {
#define SPA_LOG_FUNC(name,lev) \
static inline void spa_log_##name (SpaLog *l, const char *format, ...) \
{ \
if ((l) && (l)->level >= lev) { \
if (spa_log_level_enabled (l, lev)) { \
va_list varargs; \
va_start (varargs, format); \
(l)->logv((l),lev,__FILE__,__LINE__,__func__,format,varargs); \

View file

@ -124,12 +124,6 @@ typedef struct {
} SpaPortInfo;
size_t spa_port_info_get_size (const SpaPortInfo *info);
size_t spa_port_info_serialize (void *dest, const SpaPortInfo *info);
SpaPortInfo * spa_port_info_deserialize (void *src, off_t offset);
SpaPortInfo * spa_port_info_copy_into (void *dest, const SpaPortInfo *info);
/**
* SpaPortStatusFlags:
* @SPA_PORT_STATUS_FLAG_NONE: no status flags

View file

@ -235,13 +235,6 @@ SpaResult spa_props_copy_values (const SpaProps *src,
SpaProps *dest);
size_t spa_props_get_size (const SpaProps *props);
size_t spa_props_serialize (void *dest, const SpaProps *props);
SpaProps * spa_props_deserialize (void *src, off_t offset);
SpaProps * spa_props_copy_into (void *dest, const SpaProps *props);
#ifdef __cplusplus
} /* extern "C" */
#endif