Work on sink

Remove _remove from properties, we can do the same with set of a NULL
value.
Add signals to the stream API to manage the buffers. Wrap those buffers
in a GstBuffer in the pinossrc and pinossink elements and pool them in a
bufferpool.
Remove SPA_EVENT_TYPE_PULL_INPUT, we can do the same with NEED_INPUT and
by using a ringbuffer.
Do more complete allocation of buffers in the link. Use the buffer
allocator if none of the nodes can allocate.
Follow the node state to trigger negotiation and allocation.
Remove offset and size when refering to buffers, we want to always deal
with the complete buffer and use a ringbuffer for ranges or change the
offset/size in the buffer data when needed.
Serialize port_info structures as part of the port_update
Print both the enum number and the name when debuging properties or
formats.
This commit is contained in:
Wim Taymans 2016-08-24 16:26:58 +02:00
parent a03352353f
commit ca7d08c406
45 changed files with 1614 additions and 570 deletions

View file

@ -67,9 +67,10 @@ typedef struct _ALSABuffer ALSABuffer;
struct _ALSABuffer {
SpaBuffer buffer;
SpaMeta meta[1];
SpaMeta metas[2];
SpaMetaHeader header;
SpaData data[1];
SpaMetaRingbuffer ringbuffer;
SpaData datas[1];
};
struct _SpaALSASink {
@ -88,12 +89,15 @@ struct _SpaALSASink {
SpaALSAState state;
SpaPortInfo info;
SpaAllocParam *params[1];
SpaAllocParamBuffers param_buffers;
SpaPortStatus status;
SpaBuffer *buffers;
unsigned int n_buffers;
uint32_t input_buffer;
SpaMemory *mem;
ALSABuffer buffer;
};
@ -395,6 +399,20 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
if (alsa_set_format (this, &this->current_format, false) < 0)
return SPA_RESULT_ERROR;
this->info.flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
this->info.maxbuffering = -1;
this->info.latency = -1;
this->info.n_params = 1;
this->params[0] = &this->param_buffers.param;
this->param_buffers.param.type = SPA_ALLOC_PARAM_TYPE_BUFFERS;
this->param_buffers.param.size = sizeof (this->param_buffers);
this->param_buffers.minsize = 1;
this->param_buffers.stride = 0;
this->param_buffers.min_buffers = 1;
this->param_buffers.max_buffers = 8;
this->param_buffers.align = 16;
this->info.features = NULL;
this->have_format = true;
return SPA_RESULT_OK;
@ -476,15 +494,71 @@ spa_alsa_sink_node_port_alloc_buffers (SpaNode *node,
SpaBuffer **buffers,
uint32_t *n_buffers)
{
return SPA_RESULT_NOT_IMPLEMENTED;
SpaALSASink *this;
ALSABuffer *b;
SpaALSAState *state;
if (node == NULL || node->handle == NULL || buffers == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
this = (SpaALSASink *) node->handle;
if (!this->have_format)
return SPA_RESULT_NO_FORMAT;
state = &this->state;
if (!this->mem)
this->mem = spa_memory_alloc_with_fd (SPA_MEMORY_POOL_SHARED, NULL, state->buffer_size);
b = &this->buffer;
b->buffer.id = 0;
b->buffer.mem.mem.pool_id = -1;
b->buffer.mem.mem.id = -1;
b->buffer.mem.offset = 0;
b->buffer.mem.size = sizeof (ALSABuffer);
b->buffer.n_metas = 2;
b->buffer.metas = offsetof (ALSABuffer, metas);
b->buffer.n_datas = 1;
b->buffer.datas = offsetof (ALSABuffer, datas);
b->header.flags = 0;
b->header.seq = 0;
b->header.pts = 0;
b->header.dts_offset = 0;
b->metas[0].type = SPA_META_TYPE_HEADER;
b->metas[0].offset = offsetof (ALSABuffer, header);
b->metas[0].size = sizeof (b->header);
b->ringbuffer.readindex = 0;
b->ringbuffer.writeindex = 0;
b->ringbuffer.size = 0;
b->ringbuffer.size_mask = 0;
b->metas[1].type = SPA_META_TYPE_RINGBUFFER;
b->metas[1].offset = offsetof (ALSABuffer, ringbuffer);
b->metas[1].size = sizeof (b->ringbuffer);
b->datas[0].mem.mem = this->mem->mem;
b->datas[0].mem.offset = 0;
b->datas[0].mem.size = state->buffer_size;
b->datas[0].stride = 0;
buffers[0] = &b->buffer;
*n_buffers = 1;
return SPA_RESULT_OK;
}
static SpaResult
spa_alsa_sink_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size)
uint32_t buffer_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
@ -627,7 +701,6 @@ alsa_sink_init (const SpaHandleFactory *factory,
this->props[1].props.prop_info = prop_info;
reset_alsa_sink_props (&this->props[1]);
this->info.flags = SPA_PORT_INFO_FLAG_NONE;
this->status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
return SPA_RESULT_OK;

View file

@ -225,17 +225,11 @@ static void
pull_input (SpaALSASink *this, void *data, snd_pcm_uframes_t frames)
{
SpaEvent event;
SpaEventPullInput pi;
event.type = SPA_EVENT_TYPE_PULL_INPUT;
event.type = SPA_EVENT_TYPE_NEED_INPUT;
event.port_id = 0;
event.size = frames * sizeof (uint16_t) * 2;
event.data = &pi;
pi.buffer_id = this->buffer.buffer.id;
pi.offset = 0;
pi.size = frames * sizeof (uint16_t) * 2;
event.size = 0;
event.data = NULL;
this->event_cb (&this->node, &event, this->user_data);
}
@ -373,6 +367,9 @@ spa_alsa_stop (SpaALSASink *this)
SpaALSAState *state = &this->state;
SpaEvent event;
if (!state->opened)
return 0;
snd_pcm_drop (state->handle);
event.type = SPA_EVENT_TYPE_REMOVE_POLL;

View file

@ -469,9 +469,7 @@ spa_audiomixer_node_port_alloc_buffers (SpaNode *node,
static SpaResult
spa_audiomixer_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size)
uint32_t buffer_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
@ -571,15 +569,11 @@ static void
pull_port (SpaAudioMixer *this, uint32_t port_id, SpaOutputInfo *info, size_t pull_size)
{
SpaEvent event;
MixerBuffer *buffer = &this->ports[port_id].mix;
SpaEventPullInput pi;
event.type = SPA_EVENT_TYPE_PULL_INPUT;
event.type = SPA_EVENT_TYPE_NEED_INPUT;
event.port_id = port_id;
event.data = &pi;
pi.buffer_id = buffer->buffer.id;
pi.offset = 0;
pi.size = pull_size;
event.size = 0;
event.data = NULL;
this->event_cb (&this->node, &event, this->user_data);
}
@ -645,7 +639,7 @@ mix_data (SpaAudioMixer *this, SpaOutputInfo *info)
if (info->port_id != 0)
return SPA_RESULT_INVALID_PORT;
pull_size = info->size;
pull_size = 0;
min_size = 0;
min_port = 0;

View file

@ -424,9 +424,7 @@ spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
static SpaResult
spa_audiotestsrc_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size)
uint32_t buffer_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
@ -492,7 +490,7 @@ spa_audiotestsrc_node_port_pull_output (SpaNode *node,
continue;
}
size = info[i].size;
size = 0;
for (j = 0; j < size; j++)
ptr[j] = rand();

View file

@ -428,9 +428,7 @@ spa_ffmpeg_dec_node_port_alloc_buffers (SpaNode *node,
static SpaResult
spa_ffmpeg_dec_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offse,
size_t size)
uint32_t buffer_id)
{
if (node == NULL || node->handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;

View file

@ -428,9 +428,7 @@ spa_ffmpeg_enc_node_port_alloc_buffers (SpaNode *node,
static SpaResult
spa_ffmpeg_enc_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size)
uint32_t buffer_id)
{
if (node == NULL || node->handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;

View file

@ -58,6 +58,7 @@ typedef struct {
SpaPortStatus status;
unsigned int n_buffers;
SpaBuffer **buffers;
uint32_t buffer_id;
} SpaProxyPort;
struct _SpaProxy {
@ -335,35 +336,46 @@ spa_proxy_node_get_port_ids (SpaNode *node,
}
static void
do_init_port (SpaProxy *this,
uint32_t port_id,
SpaDirection direction,
unsigned int n_formats,
SpaFormat **formats)
do_update_port (SpaProxy *this,
SpaControlCmdPortUpdate *pu)
{
SpaEvent event;
SpaProxyPort *port;
SpaEventPortAdded pa;
fprintf (stderr, "%p: adding port %d, %d\n", this, port_id, direction);
port = &this->ports[port_id];
port->direction = direction;
port->valid = true;
port->format = NULL;
port->n_formats = n_formats;
port->formats = formats;
port = &this->ports[pu->port_id];
if (direction == SPA_DIRECTION_INPUT)
this->n_inputs++;
else
this->n_outputs++;
event.type = SPA_EVENT_TYPE_PORT_ADDED;
event.port_id = port_id;
event.data = &pa;
event.size = sizeof (pa);
pa.direction = direction;
this->event_cb (&this->node, &event, this->user_data);
if (pu->change_mask & SPA_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS) {
port->n_formats = pu->n_possible_formats;
port->formats = pu->possible_formats;
}
if (pu->change_mask & SPA_CONTROL_CMD_PORT_UPDATE_PROPS) {
}
if (pu->change_mask & SPA_CONTROL_CMD_PORT_UPDATE_INFO) {
port->info = *pu->info;
}
if (!port->valid) {
fprintf (stderr, "%p: adding port %d, %d\n", this, pu->port_id, pu->direction);
port->direction = pu->direction;
port->format = NULL;
port->valid = true;
if (pu->direction == SPA_DIRECTION_INPUT)
this->n_inputs++;
else
this->n_outputs++;
event.type = SPA_EVENT_TYPE_PORT_ADDED;
event.port_id = pu->port_id;
event.data = &pa;
event.size = sizeof (pa);
pa.direction = pu->direction;
this->event_cb (&this->node, &event, this->user_data);
}
}
static void
@ -400,6 +412,7 @@ spa_proxy_node_add_port (SpaNode *node,
uint32_t port_id)
{
SpaProxy *this;
SpaControlCmdPortUpdate pu;
if (node == NULL || node->handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
@ -409,7 +422,17 @@ spa_proxy_node_add_port (SpaNode *node,
if (!CHECK_FREE_PORT_ID (this, port_id))
return SPA_RESULT_INVALID_PORT;
do_init_port (this, port_id, direction, 0, NULL);
pu.change_mask = SPA_CONTROL_CMD_PORT_UPDATE_DIRECTION |
SPA_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS |
SPA_CONTROL_CMD_PORT_UPDATE_PROPS |
SPA_CONTROL_CMD_PORT_UPDATE_INFO;
pu.port_id = port_id;
pu.direction = direction;
pu.n_possible_formats = 0;
pu.possible_formats = NULL;
pu.props = NULL;
pu.info = NULL;
do_update_port (this, &pu);
return SPA_RESULT_OK;
}
@ -617,7 +640,7 @@ add_buffer (SpaProxy *this, uint32_t port_id, SpaBuffer *buffer)
spa_control_builder_init_into (&builder, buf, sizeof (buf), fds, sizeof (fds));
if (buffer->mem.mem.id == SPA_ID_INVALID) {
fprintf (stderr, "proxy %p: alloc buffer space\n", this);
fprintf (stderr, "proxy %p: alloc buffer space %zd\n", this, buffer->mem.size);
bmem = spa_memory_alloc_with_fd (SPA_MEMORY_POOL_SHARED, buffer, buffer->mem.size);
b = spa_memory_ensure_ptr (bmem);
b->mem.mem = bmem->mem;
@ -776,9 +799,7 @@ spa_proxy_node_port_alloc_buffers (SpaNode *node,
static SpaResult
spa_proxy_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size)
uint32_t buffer_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
@ -879,6 +900,9 @@ spa_proxy_node_port_pull_output (SpaNode *node,
have_error = true;
continue;
}
info[i].buffer_id = port->buffer_id;
info[i].status = SPA_RESULT_OK;
}
if (have_error)
return SPA_RESULT_ERROR;
@ -893,6 +917,39 @@ spa_proxy_node_port_push_event (SpaNode *node,
uint32_t port_id,
SpaEvent *event)
{
SpaProxy *this;
SpaResult res;
if (node == NULL || node->handle == NULL || event == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaProxy *) node->handle;
switch (event->type) {
case SPA_EVENT_TYPE_REUSE_BUFFER:
{
SpaEventReuseBuffer *rb = event->data;
SpaControlCmdReuseBuffer crb;
SpaControlBuilder builder;
SpaControl control;
uint8_t buf[128];
/* send start */
spa_control_builder_init_into (&builder, buf, sizeof (buf), NULL, 0);
crb.port_id = event->port_id;
crb.buffer_id = rb->buffer_id;
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_REUSE_BUFFER, &crb);
spa_control_builder_end (&builder, &control);
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
fprintf (stderr, "proxy %p: error writing control %d\n", this, res);
spa_control_clear (&control);
return SPA_RESULT_OK;
}
default:
break;
}
return SPA_RESULT_NOT_IMPLEMENTED;
}
@ -936,7 +993,7 @@ parse_control (SpaProxy *this,
case SPA_CONTROL_CMD_PORT_UPDATE:
{
SpaControlCmdPortUpdate pu;
SpaProxyPort *port;
bool remove;
fprintf (stderr, "proxy %p: got port update %d\n", this, cmd);
if (spa_control_iter_parse_cmd (&it, &pu) < 0)
@ -945,16 +1002,13 @@ parse_control (SpaProxy *this,
if (pu.port_id >= MAX_PORTS)
break;
port = &this->ports[pu.port_id];
remove = (pu.change_mask & SPA_CONTROL_CMD_PORT_UPDATE_DIRECTION) &&
(pu.direction == SPA_DIRECTION_INVALID);
if (!port->valid && pu.direction != SPA_DIRECTION_INVALID) {
do_init_port (this,
pu.port_id,
pu.direction,
pu.n_possible_formats,
pu.possible_formats);
} else {
if (remove) {
do_uninit_port (this, pu.port_id);
} else {
do_update_port (this, &pu);
}
break;
}
@ -981,6 +1035,17 @@ parse_control (SpaProxy *this,
}
case SPA_CONTROL_CMD_HAVE_OUTPUT:
{
SpaEvent event;
SpaControlCmdHaveOutput cmd;
if (spa_control_iter_parse_cmd (&it, &cmd) < 0)
break;
event.type = SPA_EVENT_TYPE_HAVE_OUTPUT;
event.port_id = cmd.port_id;
event.data = NULL;
event.size = 0;
this->event_cb (&this->node, &event, this->user_data);
break;
}
@ -995,6 +1060,14 @@ parse_control (SpaProxy *this,
case SPA_CONTROL_CMD_PROCESS_BUFFER:
{
SpaControlCmdProcessBuffer cmd;
SpaProxyPort *port;
if (spa_control_iter_parse_cmd (&it, &cmd) < 0)
break;
port = &this->ports[cmd.port_id];
port->buffer_id = cmd.buffer_id;
break;
}
case SPA_CONTROL_CMD_REUSE_BUFFER:
@ -1011,8 +1084,6 @@ parse_control (SpaProxy *this,
event.data = &rb;
event.size = sizeof (rb);
rb.buffer_id = crb.buffer_id;
rb.offset = crb.offset;
rb.size = crb.size;
this->event_cb (&this->node, &event, this->user_data);
break;

View file

@ -203,6 +203,20 @@ spa_v4l2_source_node_set_props (SpaNode *node,
return res;
}
static void
send_state_change (SpaV4l2Source *this, SpaNodeState state)
{
SpaEvent event;
SpaEventStateChange sc;
event.type = SPA_EVENT_TYPE_STATE_CHANGE;
event.port_id = -1;
event.data = &sc;
event.size = sizeof (sc);
sc.state = state;
this->event_cb (&this->node, &event, this->user_data);
}
static SpaResult
spa_v4l2_source_node_send_command (SpaNode *node,
SpaCommand *command)
@ -221,34 +235,12 @@ spa_v4l2_source_node_send_command (SpaNode *node,
case SPA_COMMAND_START:
spa_v4l2_start (this);
if (this->event_cb) {
SpaEvent event;
SpaEventStateChange sc;
event.type = SPA_EVENT_TYPE_STATE_CHANGE;
event.port_id = -1;
event.data = &sc;
event.size = sizeof (sc);
sc.state = SPA_NODE_STATE_STREAMING;
this->event_cb (node, &event, this->user_data);
}
send_state_change (this, SPA_NODE_STATE_STREAMING);
break;
case SPA_COMMAND_STOP:
spa_v4l2_stop (this);
if (this->event_cb) {
SpaEvent event;
SpaEventStateChange sc;
event.type = SPA_EVENT_TYPE_STATE_CHANGE;
event.port_id = -1;
event.data = &sc;
event.size = sizeof (sc);
sc.state = SPA_NODE_STATE_PAUSED;
this->event_cb (node, &event, this->user_data);
}
send_state_change (this, SPA_NODE_STATE_PAUSED);
break;
case SPA_COMMAND_FLUSH:
@ -274,6 +266,8 @@ spa_v4l2_source_node_set_event_callback (SpaNode *node,
this->event_cb = event;
this->user_data = user_data;
send_state_change (this, SPA_NODE_STATE_CONFIGURE);
return SPA_RESULT_OK;
}
@ -427,6 +421,8 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
memcpy (tf, f, fs);
state->current_format = tf;
send_state_change (this, SPA_NODE_STATE_READY);
}
return SPA_RESULT_OK;
@ -525,7 +521,7 @@ spa_v4l2_source_node_port_alloc_buffers (SpaNode *node,
{
SpaV4l2Source *this;
if (node == NULL || node->handle == NULL)
if (node == NULL || node->handle == NULL || buffers == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaV4l2Source *) node->handle;
@ -541,9 +537,7 @@ spa_v4l2_source_node_port_alloc_buffers (SpaNode *node,
static SpaResult
spa_v4l2_source_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size)
uint32_t buffer_id)
{
SpaV4l2Source *this;

View file

@ -477,7 +477,7 @@ v4l2_on_fd_events (SpaPollNotifyData *data)
if (mmap_read (this) < 0)
return 0;
event.type = SPA_EVENT_TYPE_CAN_PULL_OUTPUT;
event.type = SPA_EVENT_TYPE_HAVE_OUTPUT;
event.port_id = 0;
event.size = 0;
event.data = NULL;

View file

@ -418,9 +418,7 @@ spa_volume_node_port_alloc_buffers (SpaNode *node,
static SpaResult
spa_volume_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size)
uint32_t buffer_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
@ -530,8 +528,6 @@ release_buffer (SpaVolume *this, SpaBuffer *buffer)
event.data = &rb;
event.size = sizeof (rb);
rb.buffer_id = buffer->id;
rb.offset = 0;
rb.size = -1;
this->event_cb (&this->node, &event, this->user_data);
}

View file

@ -452,9 +452,7 @@ spa_xv_sink_node_port_alloc_buffers (SpaNode *node,
static SpaResult
spa_xv_sink_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size)
uint32_t buffer_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}