mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-09 13:30:06 -05:00
More work on implementing remote protocol
Rework things so that we negotiate buffer pools beforehand and only pass buffer ids around We can then remove the refcount of buffers, events and commands. More work on buffer reuse Use the node state changes to trigger the next step in the configuration sequence. Move most of the client-node to a plugin Do buffer allocation in the port link.
This commit is contained in:
parent
05829f33e6
commit
3ace7e9648
36 changed files with 1780 additions and 1450 deletions
|
|
@ -138,9 +138,6 @@ typedef struct {
|
|||
|
||||
/**
|
||||
* SpaBuffer:
|
||||
* @refcount: reference counter
|
||||
* @notify: called when the refcount reaches 0
|
||||
* @user_data: extra user data
|
||||
* @id: buffer id
|
||||
* @size: total size of the buffer data
|
||||
* @n_metas: number of metadata
|
||||
|
|
@ -149,9 +146,6 @@ typedef struct {
|
|||
* @datas: array of @n_datas data pointers
|
||||
*/
|
||||
struct _SpaBuffer {
|
||||
volatile int refcount;
|
||||
SpaNotify notify;
|
||||
void *user_data;
|
||||
uint32_t id;
|
||||
size_t size;
|
||||
unsigned int n_metas;
|
||||
|
|
@ -160,44 +154,6 @@ struct _SpaBuffer {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ typedef enum {
|
|||
} SpaCommandType;
|
||||
|
||||
struct _SpaCommand {
|
||||
volatile int refcount;
|
||||
SpaNotify notify;
|
||||
SpaCommandType type;
|
||||
uint32_t port_id;
|
||||
void *data;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ typedef struct _SpaControlBuilder SpaControlBuilder;
|
|||
#include <spa/props.h>
|
||||
#include <spa/format.h>
|
||||
#include <spa/port.h>
|
||||
#include <spa/node.h>
|
||||
|
||||
struct _SpaControl {
|
||||
size_t x[16];
|
||||
|
|
@ -59,13 +60,12 @@ typedef enum {
|
|||
SPA_CONTROL_CMD_PORT_UPDATE = 2,
|
||||
SPA_CONTROL_CMD_PORT_REMOVED = 3,
|
||||
|
||||
SPA_CONTROL_CMD_START_CONFIGURE = 4,
|
||||
SPA_CONTROL_CMD_STATE_CHANGE = 4,
|
||||
|
||||
SPA_CONTROL_CMD_PORT_STATUS_CHANGE = 5,
|
||||
SPA_CONTROL_CMD_START_ALLOC = 6,
|
||||
|
||||
SPA_CONTROL_CMD_NEED_INPUT = 7,
|
||||
SPA_CONTROL_CMD_HAVE_OUTPUT = 8,
|
||||
SPA_CONTROL_CMD_NEED_INPUT = 6,
|
||||
SPA_CONTROL_CMD_HAVE_OUTPUT = 7,
|
||||
|
||||
/* server to client */
|
||||
SPA_CONTROL_CMD_ADD_PORT = 32,
|
||||
|
|
@ -73,11 +73,9 @@ typedef enum {
|
|||
|
||||
SPA_CONTROL_CMD_SET_FORMAT = 34,
|
||||
SPA_CONTROL_CMD_SET_PROPERTY = 35,
|
||||
SPA_CONTROL_CMD_END_CONFIGURE = 36,
|
||||
|
||||
SPA_CONTROL_CMD_PAUSE = 37,
|
||||
SPA_CONTROL_CMD_START = 38,
|
||||
SPA_CONTROL_CMD_STOP = 39,
|
||||
SPA_CONTROL_CMD_START = 36,
|
||||
SPA_CONTROL_CMD_STOP = 37,
|
||||
|
||||
/* both */
|
||||
SPA_CONTROL_CMD_ADD_MEM = 64,
|
||||
|
|
@ -100,7 +98,7 @@ typedef struct {
|
|||
|
||||
/* SPA_CONTROL_CMD_PORT_UPDATE */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
uint32_t change_mask;
|
||||
uint32_t direction;
|
||||
uint32_t n_possible_formats;
|
||||
|
|
@ -111,65 +109,61 @@ typedef struct {
|
|||
|
||||
/* SPA_CONTROL_CMD_PORT_REMOVED */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
} SpaControlCmdPortRemoved;
|
||||
|
||||
/* SPA_CONTROL_CMD_START_CONFIGURE */
|
||||
/* SPA_CONTROL_CMD_STATE_CHANGE */
|
||||
typedef struct {
|
||||
SpaNodeState state;
|
||||
} SpaControlCmdStateChange;
|
||||
|
||||
/* SPA_CONTROL_CMD_PORT_STATUS_CHANGE */
|
||||
|
||||
/* SPA_CONTROL_CMD_START_ALLOC */
|
||||
|
||||
/* SPA_CONTROL_CMD_NEED_INPUT */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
} SpaControlCmdNeedInput;
|
||||
|
||||
/* SPA_CONTROL_CMD_HAVE_OUTPUT */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
} SpaControlCmdHaveOutput;
|
||||
|
||||
|
||||
/* SPA_CONTROL_CMD_ADD_PORT */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
uint32_t direction;
|
||||
} SpaControlCmdAddPort;
|
||||
|
||||
/* SPA_CONTROL_CMD_REMOVE_PORT */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
} SpaControlCmdRemovePort;
|
||||
|
||||
|
||||
/* SPA_CONTROL_CMD_SET_FORMAT */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
const SpaFormat *format;
|
||||
const char *str;
|
||||
} SpaControlCmdSetFormat;
|
||||
|
||||
/* SPA_CONTROL_CMD_SET_PROPERTY */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
uint32_t id;
|
||||
uint32_t size;
|
||||
void *value;
|
||||
} SpaControlCmdSetProperty;
|
||||
|
||||
/* SPA_CONTROL_CMD_END_CONFIGURE */
|
||||
|
||||
/* SPA_CONTROL_CMD_PAUSE */
|
||||
/* SPA_CONTROL_CMD_START */
|
||||
/* SPA_CONTROL_CMD_STOP */
|
||||
|
||||
|
||||
/* SPA_CONTROL_CMD_ADD_MEM */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t id;
|
||||
uint32_t type;
|
||||
uint32_t port_id;
|
||||
uint32_t mem_id;
|
||||
uint32_t mem_type;
|
||||
uint32_t fd_index;
|
||||
uint64_t offset;
|
||||
uint64_t size;
|
||||
|
|
@ -177,32 +171,36 @@ typedef struct {
|
|||
|
||||
/* SPA_CONTROL_CMD_REMOVE_MEM */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t id;
|
||||
uint32_t port_id;
|
||||
uint32_t mem_id;
|
||||
} SpaControlCmdRemoveMem;
|
||||
|
||||
/* SPA_CONTROL_CMD_ADD_BUFFER */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t port_id;
|
||||
SpaBuffer *buffer;
|
||||
} SpaControlCmdAddBuffer;
|
||||
|
||||
/* SPA_CONTROL_CMD_REMOVE_BUFFER */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t id;
|
||||
uint32_t port_id;
|
||||
uint32_t buffer_id;
|
||||
} SpaControlCmdRemoveBuffer;
|
||||
|
||||
/* SPA_CONTROL_CMD_PROCESS_BUFFER */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t id;
|
||||
uint32_t port_id;
|
||||
uint32_t buffer_id;
|
||||
uint64_t offset;
|
||||
uint64_t size;
|
||||
} SpaControlCmdProcessBuffer;
|
||||
|
||||
/* SPA_CONTROL_CMD_REUSE_BUFFER */
|
||||
typedef struct {
|
||||
uint32_t port;
|
||||
uint32_t id;
|
||||
uint32_t port_id;
|
||||
uint32_t buffer_id;
|
||||
uint64_t offset;
|
||||
uint64_t size;
|
||||
} SpaControlCmdReuseBuffer;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ typedef enum {
|
|||
SPA_RESULT_TOO_MANY_PORTS = -24,
|
||||
SPA_RESULT_INVALID_PROPERTY_ACCESS = -25,
|
||||
SPA_RESULT_UNEXPECTED = -26,
|
||||
SPA_RESULT_NO_BUFFERS = -27,
|
||||
SPA_RESULT_INVALID_BUFFER_ID = -28,
|
||||
} SpaResult;
|
||||
|
||||
typedef enum {
|
||||
|
|
@ -69,6 +71,9 @@ typedef void (*SpaNotify) (void *data);
|
|||
#define SPA_MIN(a,b) ((a)<(b) ? (a) : (b))
|
||||
#define SPA_MAX(a,b) ((a)>(b) ? (a) : (b))
|
||||
|
||||
#define SPA_ID_INVALID ((uint32_t)0xffffffff)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,17 +28,17 @@ typedef struct _SpaEvent SpaEvent;
|
|||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/poll.h>
|
||||
#include <spa/node.h>
|
||||
|
||||
/**
|
||||
* SpaEventType:
|
||||
* @SPA_EVENT_TYPE_INVALID: invalid event, should be ignored
|
||||
* @SPA_EVENT_TYPE_STARTED: emited when the START command completes
|
||||
* @SPA_EVENT_TYPE_STOPPED: emited when the STOP command completes
|
||||
* @SPA_EVENT_TYPE_STATE_CHANGE: emited when the state changes
|
||||
* @SPA_EVENT_TYPE_CAN_PULL_OUTPUT: emited when an async node has output that can be pulled
|
||||
* @SPA_EVENT_TYPE_CAN_PUSH_INPUT: 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. data points to
|
||||
* buffer to fill.
|
||||
* @SPA_EVENT_TYPE_ALLOC_OUTPUT: emited when an output buffer needs to be allocated
|
||||
* SpaEventPullInput
|
||||
* @SPA_EVENT_TYPE_REUSE_BUFFER: emited when a buffer can be reused
|
||||
* @SPA_EVENT_TYPE_ADD_POLL: emited when a pollfd should be added. data points to #SpaPollItem
|
||||
* @SPA_EVENT_TYPE_REMOVE_POLL: emited when a pollfd should be removed. data points to #SpaPollItem
|
||||
* @SPA_EVENT_TYPE_DRAINED: emited when DRAIN command completed
|
||||
|
|
@ -49,12 +49,11 @@ typedef struct _SpaEvent SpaEvent;
|
|||
*/
|
||||
typedef enum {
|
||||
SPA_EVENT_TYPE_INVALID = 0,
|
||||
SPA_EVENT_TYPE_STARTED,
|
||||
SPA_EVENT_TYPE_STOPPED,
|
||||
SPA_EVENT_TYPE_STATE_CHANGE,
|
||||
SPA_EVENT_TYPE_CAN_PULL_OUTPUT,
|
||||
SPA_EVENT_TYPE_CAN_PUSH_INPUT,
|
||||
SPA_EVENT_TYPE_PULL_INPUT,
|
||||
SPA_EVENT_TYPE_ALLOC_OUTPUT,
|
||||
SPA_EVENT_TYPE_REUSE_BUFFER,
|
||||
SPA_EVENT_TYPE_ADD_POLL,
|
||||
SPA_EVENT_TYPE_REMOVE_POLL,
|
||||
SPA_EVENT_TYPE_DRAINED,
|
||||
|
|
@ -65,8 +64,6 @@ typedef enum {
|
|||
} SpaEventType;
|
||||
|
||||
struct _SpaEvent {
|
||||
volatile int refcount;
|
||||
SpaNotify notify;
|
||||
SpaEventType type;
|
||||
uint32_t port_id;
|
||||
void *data;
|
||||
|
|
@ -74,10 +71,21 @@ struct _SpaEvent {
|
|||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t buffer_id;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
} SpaEventPullInput;
|
||||
|
||||
typedef struct {
|
||||
SpaNodeState state;
|
||||
} SpaEventStateChange;
|
||||
|
||||
typedef struct {
|
||||
uint32_t buffer_id;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
} SpaEventReuseBuffer;
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -26,6 +26,24 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaNode SpaNode;
|
||||
|
||||
/**
|
||||
* SpaNodeState:
|
||||
* @SPA_NODE_STATE_INIT: the node is initializing
|
||||
* @SPA_NODE_STATE_CONFIGURE: the node needs at least one port format
|
||||
* @SPA_NODE_STATE_READY: the node is ready for memory allocation
|
||||
* @SPA_NODE_STATE_STREAMING: the node is streaming
|
||||
* @SPA_NODE_STATE_ERROR: the node is in error
|
||||
*/
|
||||
typedef enum {
|
||||
SPA_NODE_STATE_INIT,
|
||||
SPA_NODE_STATE_CONFIGURE,
|
||||
SPA_NODE_STATE_READY,
|
||||
SPA_NODE_STATE_PAUSED,
|
||||
SPA_NODE_STATE_STREAMING,
|
||||
SPA_NODE_STATE_ERROR
|
||||
} SpaNodeState;
|
||||
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/plugin.h>
|
||||
#include <spa/props.h>
|
||||
|
|
@ -62,18 +80,19 @@ typedef enum {
|
|||
* SpaInputInfo:
|
||||
* @port_id: the port id
|
||||
* @flags: extra flags
|
||||
* @buffer_id: a buffer id
|
||||
* @offset: offset of data in @id
|
||||
* @size: size of data in @id
|
||||
* @id: a buffer id
|
||||
* @status: status
|
||||
*
|
||||
* Input information for a node.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t port_id;
|
||||
SpaInputFlags flags;
|
||||
uint32_t buffer_id;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
uint32_t id;
|
||||
SpaResult status;
|
||||
} SpaInputInfo;
|
||||
|
||||
|
|
@ -96,36 +115,22 @@ typedef enum {
|
|||
* SpaOutputInfo:
|
||||
* @port_id: the port id
|
||||
* @flags: extra flags
|
||||
* @buffer_id: a buffer id will be set
|
||||
* @offset: offset to get
|
||||
* @size: size to get
|
||||
* @id: a buffer id will be set
|
||||
* @event: an event
|
||||
* @status: a status
|
||||
*
|
||||
* Output information for a node.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t port_id;
|
||||
SpaOutputFlags flags;
|
||||
uint32_t buffer_id;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
uint32_t id;
|
||||
SpaResult status;
|
||||
} SpaOutputInfo;
|
||||
|
||||
/**
|
||||
* SpaNodeState:
|
||||
* @SPA_NODE_STATE_INIT: the node is initializing
|
||||
* @SPA_NODE_STATE_CONFIGURE: the node needs at least one port format
|
||||
* @SPA_NODE_STATE_READY: the node is ready for memory allocation
|
||||
* @SPA_NODE_STREAMING: the node is streaming
|
||||
*/
|
||||
typedef enum {
|
||||
SPA_NODE_STATE_INIT,
|
||||
SPA_NODE_STATE_CONFIGURE,
|
||||
SPA_NODE_STATE_READY,
|
||||
SPA_NODE_STATE_STREAMING
|
||||
} SpaNodeState;
|
||||
|
||||
/**
|
||||
* SpaEventCallback:
|
||||
* @node: a #SpaNode emiting the event
|
||||
|
|
@ -371,6 +376,9 @@ struct _SpaNode {
|
|||
* will be set by @node so that buffers will be reused when the refcount
|
||||
* reaches 0.
|
||||
*
|
||||
* Passing %NULL as @buffers will remove the reference that the port has
|
||||
* on the buffers.
|
||||
*
|
||||
* Returns: #SPA_RESULT_OK on success
|
||||
*/
|
||||
SpaResult (*port_use_buffers) (SpaNode *node,
|
||||
|
|
@ -404,6 +412,12 @@ struct _SpaNode {
|
|||
SpaBuffer **buffers,
|
||||
unsigned int *n_buffers);
|
||||
|
||||
SpaResult (*port_reuse_buffer) (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
uint32_t buffer_id,
|
||||
off_t offset,
|
||||
size_t size);
|
||||
|
||||
SpaResult (*port_get_status) (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status);
|
||||
|
|
@ -473,6 +487,7 @@ 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__)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ extern "C" {
|
|||
/**
|
||||
* SpaAllocParamType:
|
||||
* @SPA_ALLOC_PARAM_TYPE_INVALID: invalid type, should be ignored
|
||||
* @SPA_ALLOC_PARAM_TYPE_BUFFER: buffer requirements
|
||||
* @SPA_ALLOC_PARAM_TYPE_META_ENABLE: enable a certain metadata on buffers
|
||||
* @SPA_ALLOC_PARAM_TYPE_VIDEO_PADDING: do specialized video padding
|
||||
*/
|
||||
|
|
@ -92,11 +93,6 @@ typedef enum {
|
|||
/**
|
||||
* SpaPortInfo
|
||||
* @flags: extra port flags
|
||||
* @minsize: minimum size of the buffers or 0 when not specified
|
||||
* @stride: suggested stride or 0 when not specified
|
||||
* @min_buffers: minimum number of buffers
|
||||
* @max_buffers: maximum number of buffers
|
||||
* @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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue