Add port direction again

simplify port numbering again by using 0->max_ports for bot input ports
and output ports. This means we need to tall what direction the port is.
Add port_info serialize functions
Copy metadata and data when we are not sharing buffers.
Make pinossink work again.
This commit is contained in:
Wim Taymans 2016-10-03 19:43:42 +02:00
parent b208e8b690
commit d828073bb8
26 changed files with 1104 additions and 648 deletions

View file

@ -94,6 +94,7 @@ typedef struct {
/* 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)
@ -116,20 +117,23 @@ typedef struct {
/* SPA_CONTROL_CMD_ADD_PORT */
typedef struct {
uint32_t seq;
uint32_t port_id;
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
} SpaControlCmdAddPort;
/* SPA_CONTROL_CMD_REMOVE_PORT */
typedef struct {
uint32_t seq;
uint32_t port_id;
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;
@ -137,11 +141,12 @@ typedef struct {
/* SPA_CONTROL_CMD_SET_PROPERTY */
typedef struct {
uint32_t seq;
uint32_t port_id;
uint32_t id;
size_t size;
void *value;
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
uint32_t id;
size_t size;
void *value;
} SpaControlCmdSetProperty;
/* SPA_CONTROL_CMD_NODE_COMMAND */
@ -152,6 +157,7 @@ typedef struct {
/* SPA_CONTROL_CMD_ADD_MEM */
typedef struct {
SpaDirection direction;
uint32_t port_id;
uint32_t mem_id;
unsigned int fd_index;
@ -162,6 +168,7 @@ typedef struct {
/* SPA_CONTROL_CMD_REMOVE_MEM */
typedef struct {
SpaDirection direction;
uint32_t port_id;
uint32_t mem_id;
} SpaControlCmdRemoveMem;
@ -175,6 +182,7 @@ typedef struct {
/* SPA_CONTROL_CMD_USE_BUFFERS */
typedef struct {
uint32_t seq;
SpaDirection direction;
uint32_t port_id;
unsigned int n_buffers;
SpaControlMemRef *buffers;
@ -182,8 +190,9 @@ typedef struct {
/* SPA_CONTROL_CMD_PROCESS_BUFFER */
typedef struct {
uint32_t port_id;
uint32_t buffer_id;
SpaDirection direction;
uint32_t port_id;
uint32_t buffer_id;
} SpaControlCmdProcessBuffer;
/* SPA_CONTROL_CMD_NODE_EVENT */

View file

@ -74,6 +74,12 @@ typedef enum {
#define SPA_RESULT_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK)
#define SPA_RESULT_RETURN_ASYNC(seq) (SPA_RESULT_ASYNC | ((seq) & SPA_ASYNC_SEQ_MASK))
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]))

View file

@ -75,14 +75,6 @@ typedef struct {
SpaResult res;
} SpaNodeEventAsyncComplete;
typedef struct {
uint32_t port_id;
} SpaNodeEventPortAdded;
typedef struct {
uint32_t port_id;
} SpaNodeEventPortRemoved;
typedef struct {
SpaNodeState state;
} SpaNodeEventStateChange;

View file

@ -270,8 +270,7 @@ struct _SpaNode {
* @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.
* Get the ids of the currently available ports.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
@ -285,26 +284,28 @@ struct _SpaNode {
/**
* SpaNode::add_port:
* @node: a #SpaNode
* @direction: a #SpaDirection
* @port_id: an unused port id
*
* Make a new port with @port_id. The called should use get_port_ids() to
* find an unused id.
* find an unused id for the given @direction.
*
* Input port ids should be between 0 and max_input_ports and output ports
* between max_input_ports and max_input_ports + max_output_ports as obtained
* from get_port_ids().
* Port ids should be between 0 and max_ports as obtained from get_n_ports().
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
*/
SpaResult (*add_port) (SpaNode *node,
SpaDirection direction,
uint32_t port_id);
SpaResult (*remove_port) (SpaNode *node,
SpaDirection direction,
uint32_t port_id);
/**
* SpaNode::port_enum_formats:
* @node: a #SpaNode
* @direction: a #SpaDirection
* @port_id: the port to query
* @format: pointer to a format
* @filter: a format filter
@ -325,6 +326,7 @@ struct _SpaNode {
* #SPA_RESULT_ENUM_END when no format exists
*/
SpaResult (*port_enum_formats) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaFormat **format,
const SpaFormat *filter,
@ -332,6 +334,7 @@ struct _SpaNode {
/**
* SpaNode::port_set_format:
* @node: a #SpaNode
* @direction: a #SpaDirection
* @port_id: the port to configure
* @flags: flags
* @format: a #SpaFormat with the format
@ -359,13 +362,15 @@ struct _SpaNode {
* is not correct.
* #SPA_RESULT_ASYNC the function is executed asynchronously
*/
SpaResult (*port_set_format) (SpaNode *node,
uint32_t port_id,
SpaPortFormatFlags flags,
const SpaFormat *format);
SpaResult (*port_set_format) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaPortFormatFlags flags,
const SpaFormat *format);
/**
* SpaNode::port_get_format:
* @node: a #SpaNode
* @direction: a #SpaDirection
* @port_id: the port to query
* @format: a pointer to a location to hold the #SpaFormat
*
@ -378,23 +383,28 @@ struct _SpaNode {
* #SPA_RESULT_INVALID_NO_FORMAT when no format was set
*/
SpaResult (*port_get_format) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
const SpaFormat **format);
SpaResult (*port_get_info) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
const SpaPortInfo **info);
SpaResult (*port_get_props) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaProps **props);
SpaResult (*port_set_props) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
const SpaProps *props);
/**
* SpaNode::port_use_buffers:
* @node: a #SpaNode
* @direction: a #SpaDirection
* @port_id: a port id
* @buffers: an array of buffer pointers
* @n_buffers: number of elements in @buffers
@ -420,12 +430,14 @@ struct _SpaNode {
* #SPA_RESULT_ASYNC the function is executed asynchronously
*/
SpaResult (*port_use_buffers) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaBuffer **buffers,
unsigned int n_buffers);
/**
* SpaNode::port_alloc_buffers:
* @node: a #SpaNode
* @direction: a #SpaDirection
* @port_id: a port id
* @params: allocation parameters
* @n_params: number of elements in @params
@ -456,28 +468,15 @@ struct _SpaNode {
* #SPA_RESULT_ASYNC the function is executed asynchronously
*/
SpaResult (*port_alloc_buffers) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaAllocParam **params,
unsigned int n_params,
SpaBuffer **buffers,
unsigned int *n_buffers);
/**
* SpaNode::port_reuse_buffer:
* @node: a #SpaNode
* @port_id: a port id
* @buffer_id: a buffer id to reuse
*
* Tell an output port to reuse a buffer.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
*/
SpaResult (*port_reuse_buffer) (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id);
SpaResult (*port_get_status) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
const SpaPortStatus **status);
@ -523,8 +522,23 @@ struct _SpaNode {
SpaResult (*port_pull_output) (SpaNode *node,
unsigned int n_info,
SpaPortOutputInfo *info);
/**
* SpaNode::port_reuse_buffer:
* @node: a #SpaNode
* @port_id: a port id
* @buffer_id: a buffer id to reuse
*
* Tell an output port to reuse a buffer.
*
* Returns: #SPA_RESULT_OK on success
* #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL
*/
SpaResult (*port_reuse_buffer) (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id);
SpaResult (*port_push_event) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaNodeEvent *event);
@ -546,10 +560,10 @@ struct _SpaNode {
#define spa_node_port_set_props(n,...) (n)->port_set_props((n),__VA_ARGS__)
#define spa_node_port_use_buffers(n,...) (n)->port_use_buffers((n),__VA_ARGS__)
#define spa_node_port_alloc_buffers(n,...) (n)->port_alloc_buffers((n),__VA_ARGS__)
#define spa_node_port_reuse_buffer(n,...) (n)->port_reuse_buffer((n),__VA_ARGS__)
#define spa_node_port_get_status(n,...) (n)->port_get_status((n),__VA_ARGS__)
#define spa_node_port_push_input(n,...) (n)->port_push_input((n),__VA_ARGS__)
#define spa_node_port_pull_output(n,...) (n)->port_pull_output((n),__VA_ARGS__)
#define spa_node_port_reuse_buffer(n,...) (n)->port_reuse_buffer((n),__VA_ARGS__)
#define spa_node_port_push_event(n,...) (n)->port_push_event((n),__VA_ARGS__)
#ifdef __cplusplus

View file

@ -115,6 +115,13 @@ typedef struct {
const char **features;
} 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