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

@ -27,9 +27,6 @@ extern "C" {
typedef struct _SpaBuffer SpaBuffer;
typedef struct _SpaBufferGroup SpaBufferGroup;
#include <spa/defs.h>
#include <spa/memory.h>
/**
* SpaMetaType:
* @SPA_META_TYPE_INVALID: invalid metadata, should be ignored
@ -40,8 +37,13 @@ typedef enum {
SPA_META_TYPE_HEADER,
SPA_META_TYPE_POINTER,
SPA_META_TYPE_VIDEO_CROP,
SPA_META_TYPE_RINGBUFFER,
} SpaMetaType;
#include <spa/defs.h>
#include <spa/memory.h>
#include <spa/port.h>
/**
* SpaBufferFlags:
* @SPA_BUFFER_FLAG_NONE: no flag
@ -87,6 +89,20 @@ typedef struct {
int width, height;
} SpaMetaVideoCrop;
/**
* SpaMetaRingbuffer:
* @readindex:
* @writeindex:
* @size:
* @size_mask:
*/
typedef struct {
volatile int readindex;
volatile int writeindex;
int size;
int size_mask;
} SpaMetaRingbuffer;
/**
* SpaMeta:
* @type: metadata type
@ -133,6 +149,11 @@ struct _SpaBuffer {
#define spa_buffer_ref(b) spa_memory_ref (&(b)->mem)
#define spa_buffer_unref(b) spa_memory_unref (&(b)->mem)
SpaResult spa_buffer_alloc (SpaAllocParam **params,
unsigned int n_params,
SpaBuffer **buffers,
unsigned int *n_buffers);
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -201,16 +201,12 @@ typedef struct {
typedef struct {
uint32_t port_id;
uint32_t buffer_id;
off_t offset;
size_t size;
} SpaControlCmdProcessBuffer;
/* SPA_CONTROL_CMD_REUSE_BUFFER */
typedef struct {
uint32_t port_id;
uint32_t buffer_id;
off_t offset;
size_t size;
} SpaControlCmdReuseBuffer;

View file

@ -33,11 +33,11 @@ typedef struct _SpaEvent SpaEvent;
/**
* SpaEventType:
* @SPA_EVENT_TYPE_INVALID: invalid event, should be ignored
* @SPA_EVENT_TYPE_PORT_ADDED: a new port is added
* @SPA_EVENT_TYPE_PORT_REMOVED: a port is removed
* @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
* SpaEventPullInput
* @SPA_EVENT_TYPE_HAVE_OUTPUT: emited when an async node has output that can be pulled
* @SPA_EVENT_TYPE_NEED_INPUT: emited when more data can be pushed to an async node
* @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
@ -52,9 +52,8 @@ typedef enum {
SPA_EVENT_TYPE_PORT_ADDED,
SPA_EVENT_TYPE_PORT_REMOVED,
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_HAVE_OUTPUT,
SPA_EVENT_TYPE_NEED_INPUT,
SPA_EVENT_TYPE_REUSE_BUFFER,
SPA_EVENT_TYPE_ADD_POLL,
SPA_EVENT_TYPE_REMOVE_POLL,
@ -76,20 +75,12 @@ typedef struct {
SpaDirection direction;
} SpaEventPortAdded;
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;
uint32_t buffer_id;
} SpaEventReuseBuffer;
#ifdef __cplusplus

View file

@ -31,6 +31,7 @@ typedef struct _SpaNode SpaNode;
* @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_PAUSED: the node is paused
* @SPA_NODE_STATE_STREAMING: the node is streaming
* @SPA_NODE_STATE_ERROR: the node is in error
*/
@ -81,8 +82,6 @@ typedef enum {
* @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
* @status: status
*
* Input information for a node.
@ -91,8 +90,6 @@ typedef struct {
uint32_t port_id;
SpaInputFlags flags;
uint32_t buffer_id;
off_t offset;
size_t size;
SpaResult status;
} SpaInputInfo;
@ -116,8 +113,6 @@ typedef enum {
* @port_id: the port id
* @flags: extra flags
* @buffer_id: a buffer id will be set
* @offset: offset to get
* @size: size to get
* @event: output event
* @status: a status
*
@ -127,8 +122,6 @@ typedef struct {
uint32_t port_id;
SpaOutputFlags flags;
uint32_t buffer_id;
off_t offset;
size_t size;
SpaEvent *event;
SpaResult status;
} SpaOutputInfo;
@ -416,9 +409,7 @@ struct _SpaNode {
SpaResult (*port_reuse_buffer) (SpaNode *node,
uint32_t port_id,
uint32_t buffer_id,
off_t offset,
size_t size);
uint32_t buffer_id);
SpaResult (*port_get_status) (SpaNode *node,
uint32_t port_id,

View file

@ -24,6 +24,8 @@
extern "C" {
#endif
typedef struct _SpaAllocParam SpaAllocParam;
#include <spa/defs.h>
#include <spa/buffer.h>
@ -41,10 +43,10 @@ typedef enum {
SPA_ALLOC_PARAM_TYPE_VIDEO_PADDING,
} SpaAllocParamType;
typedef struct {
struct _SpaAllocParam {
uint32_t type;
size_t size;
} SpaAllocParam;
};
typedef struct {
SpaAllocParam param;

135
spa/lib/buffer.c Normal file
View file

@ -0,0 +1,135 @@
/* 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.
*/
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <spa/buffer.h>
#include <spa/port.h>
typedef struct {
SpaBuffer buffer;
SpaMeta metas[3];
SpaMetaHeader header;
SpaMetaRingbuffer ringbuffer;
SpaMetaVideoCrop crop;
SpaData datas[4];
} Buffer;
SpaResult
spa_buffer_alloc (SpaAllocParam **params,
unsigned int n_params,
SpaBuffer **buffers,
unsigned int *n_buffers)
{
unsigned int i, nbufs;
size_t size = 0, stride = 0;
SpaMemory *bmem, *dmem;
Buffer *bufs;
Buffer *b;
bool add_header = false;
int n_metas = 0;
nbufs = *n_buffers;
if (nbufs == 0)
return SPA_RESULT_ERROR;
for (i = 0; i < n_params; i++) {
SpaAllocParam *p = params[i];
switch (p->type) {
case SPA_ALLOC_PARAM_TYPE_BUFFERS:
{
SpaAllocParamBuffers *b = (SpaAllocParamBuffers *) p;
size = SPA_MAX (size, b->minsize);
break;
}
case SPA_ALLOC_PARAM_TYPE_META_ENABLE:
{
SpaAllocParamMetaEnable *b = (SpaAllocParamMetaEnable *) p;
switch (b->type) {
case SPA_META_TYPE_HEADER:
if (!add_header)
n_metas++;
add_header = true;
break;
case SPA_META_TYPE_POINTER:
break;
case SPA_META_TYPE_VIDEO_CROP:
break;
case SPA_META_TYPE_RINGBUFFER:
break;
default:
break;
}
break;
}
default:
break;
}
}
*n_buffers = nbufs;
bmem = spa_memory_alloc_with_fd (SPA_MEMORY_POOL_SHARED,
NULL, sizeof (Buffer) * nbufs);
dmem = spa_memory_alloc_with_fd (SPA_MEMORY_POOL_SHARED,
NULL, size * nbufs);
bufs = spa_memory_ensure_ptr (bmem);
for (i = 0; i < nbufs; i++) {
int mi = 0;
b = &bufs[i];
b->buffer.id = i;
b->buffer.mem.mem = bmem->mem;
b->buffer.mem.offset = sizeof (Buffer) * i;
b->buffer.mem.size = sizeof (Buffer);
buffers[i] = &b->buffer;
b->buffer.n_metas = n_metas;
b->buffer.metas = offsetof (Buffer, metas);
b->buffer.n_datas = 1;
b->buffer.datas = offsetof (Buffer, datas);
if (add_header) {
b->header.flags = 0;
b->header.seq = 0;
b->header.pts = 0;
b->header.dts_offset = 0;
b->metas[mi].type = SPA_META_TYPE_HEADER;
b->metas[mi].offset = offsetof (Buffer, header);
b->metas[mi].size = sizeof (b->header);
mi++;
}
b->datas[0].mem.mem = dmem->mem;
b->datas[0].mem.offset = size * i;
b->datas[0].mem.size = size;
b->datas[0].stride = stride;
}
return SPA_RESULT_OK;
}

View file

@ -431,8 +431,17 @@ iter_parse_port_update (struct stack_iter *si, SpaControlCmdPortUpdate *pu)
if (pu->props)
pu->props = parse_props (mem, p, SPA_PTR_TO_INT (pu->props));
if (pu->info)
pu->info = SPA_MEMBER (p, SPA_PTR_TO_INT (pu->info), SpaPortInfo);
if (pu->info) {
SpaPortInfo *pi;
pu->info = p = SPA_MEMBER (p, SPA_PTR_TO_INT (pu->info), SpaPortInfo);
pi = (SpaPortInfo *) pu->info;
pi->params = SPA_MEMBER (p, SPA_PTR_TO_INT (pi->params), SpaAllocParam *);
for (i = 0; i < pi->n_params; i++) {
pi->params[i] = SPA_MEMBER (p, SPA_PTR_TO_INT (pi->params[i]), SpaAllocParam);
}
}
}
static void
@ -945,25 +954,55 @@ write_format (void *p, const SpaFormat *format)
return write_props (p, &format->props, sizeof (SpaFormat));
}
static size_t
write_port_info (void *p, const SpaPortInfo *info)
{
SpaPortInfo *tp;
SpaAllocParam **ap;
int i;
size_t len;
tp = p;
memcpy (tp, info, sizeof (SpaPortInfo));
p = SPA_MEMBER (tp, sizeof (SpaPortInfo), SpaAllocParam *);
ap = p;
if (info->n_params)
tp->params = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
else
tp->params = 0;
tp->features = 0;
p = SPA_MEMBER (p, sizeof (SpaAllocParam*) * info->n_params, void);
for (i = 0; i < info->n_params; i++) {
len = info->params[i]->size;
memcpy (p, info->params[i], len);
ap[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
p = SPA_MEMBER (p, len, void);
}
return SPA_PTRDIFF (p, tp);
}
static void
builder_add_node_update (struct stack_builder *sb, SpaControlCmdNodeUpdate *nu)
{
size_t len;
void *p, *base;
void *p;
SpaControlCmdNodeUpdate *d;
/* calc len */
len = sizeof (SpaControlCmdNodeUpdate);
len += calc_props_len (nu->props);
base = builder_add_cmd (sb, SPA_CONTROL_CMD_NODE_UPDATE, len);
memcpy (base, nu, sizeof (SpaControlCmdNodeUpdate));
d = base;
p = builder_add_cmd (sb, SPA_CONTROL_CMD_NODE_UPDATE, len);
memcpy (p, nu, sizeof (SpaControlCmdNodeUpdate));
d = p;
p = SPA_MEMBER (d, sizeof (SpaControlCmdNodeUpdate), void);
if (nu->props) {
len = write_props (p, nu->props, sizeof (SpaProps));
d->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, base));
d->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
} else {
d->props = 0;
}
@ -973,7 +1012,7 @@ static void
builder_add_port_update (struct stack_builder *sb, SpaControlCmdPortUpdate *pu)
{
size_t len;
void *p, *base;
void *p;
int i;
SpaFormat **bfa;
SpaControlCmdPortUpdate *d;
@ -984,15 +1023,21 @@ builder_add_port_update (struct stack_builder *sb, SpaControlCmdPortUpdate *pu)
for (i = 0; i < pu->n_possible_formats; i++)
len += calc_format_len (pu->possible_formats[i]);
len += calc_props_len (pu->props);
if (pu->info) {
len += sizeof (SpaPortInfo);
len += pu->info->n_params * sizeof (SpaAllocParam *);
for (i = 0; i < pu->info->n_params; i++)
len += pu->info->params[i]->size;
}
base = builder_add_cmd (sb, SPA_CONTROL_CMD_PORT_UPDATE, len);
memcpy (base, pu, sizeof (SpaControlCmdPortUpdate));
d = base;
p = builder_add_cmd (sb, SPA_CONTROL_CMD_PORT_UPDATE, len);
memcpy (p, pu, sizeof (SpaControlCmdPortUpdate));
d = p;
p = SPA_MEMBER (d, sizeof (SpaControlCmdPortUpdate), void);
bfa = p;
if (pu->n_possible_formats)
d->possible_formats = SPA_INT_TO_PTR (SPA_PTRDIFF (p, base));
d->possible_formats = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
else
d->possible_formats = 0;
@ -1000,31 +1045,36 @@ builder_add_port_update (struct stack_builder *sb, SpaControlCmdPortUpdate *pu)
for (i = 0; i < pu->n_possible_formats; i++) {
len = write_format (p, pu->possible_formats[i]);
bfa[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, base));
bfa[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
p = SPA_MEMBER (p, len, void);
}
if (pu->props) {
len = write_props (p, pu->props, sizeof (SpaProps));
d->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, base));
d->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
p = SPA_MEMBER (p, len, void);
} else {
d->props = 0;
}
/* FIXME add more things */
if (pu->info) {
len = write_port_info (p, pu->info);
d->info = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
p = SPA_MEMBER (p, len, void);
} else {
d->info = 0;
}
}
static void
builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
{
size_t len;
void *p, *base;
void *p;
/* calculate length */
/* port_id + format + mask */
len = sizeof (SpaControlCmdSetFormat) + calc_format_len (sf->format);
base = builder_add_cmd (sb, SPA_CONTROL_CMD_SET_FORMAT, len);
memcpy (base, sf, sizeof (SpaControlCmdSetFormat));
sf = base;
p = builder_add_cmd (sb, SPA_CONTROL_CMD_SET_FORMAT, len);
memcpy (p, sf, sizeof (SpaControlCmdSetFormat));
sf = p;
p = SPA_MEMBER (sf, sizeof (SpaControlCmdSetFormat), void);
len = write_format (p, sf->format);

View file

@ -213,6 +213,7 @@ print_value (const SpaPropInfo *info, int size, const void *value)
{
SpaPropType type = info->type;
bool enum_string = false;
const void *enum_value;
if (info->range_type == SPA_PROP_RANGE_TYPE_ENUM) {
int i;
@ -220,8 +221,7 @@ print_value (const SpaPropInfo *info, int size, const void *value)
for (i = 0; i < info->n_range_values; i++) {
if (memcmp (info->range_values[i].value, value, size) == 0) {
if (info->range_values[i].name) {
type = SPA_PROP_TYPE_STRING;
value = info->range_values[i].name;
enum_value = info->range_values[i].name;
enum_string = true;
}
}
@ -272,10 +272,7 @@ print_value (const SpaPropInfo *info, int size, const void *value)
fprintf (stderr, "%g", *(double *)value);
break;
case SPA_PROP_TYPE_STRING:
if (enum_string)
fprintf (stderr, "%s", (char *)value);
else
fprintf (stderr, "\"%s\"", (char *)value);
fprintf (stderr, "\"%s\"", (char *)value);
break;
case SPA_PROP_TYPE_RECTANGLE:
{
@ -297,6 +294,8 @@ print_value (const SpaPropInfo *info, int size, const void *value)
default:
break;
}
if (enum_string)
fprintf (stderr, " (%s)", (char *)enum_value);
}
SpaResult

View file

@ -182,7 +182,7 @@ spa_memory_alloc_with_fd (uint32_t pool_id, void *data, size_t size)
seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
if (fcntl (mem->fd, F_ADD_SEALS, seals) == -1) {
fprintf (stderr, "Failed to write data: %s\n", strerror (errno));
fprintf (stderr, "Failed to add seals: %s\n", strerror (errno));
close (mem->fd);
return NULL;
}
@ -320,7 +320,7 @@ spa_memory_ensure_ptr (SpaMemory *mem)
mem->ptr = mmap (NULL, mem->size, prot, MAP_SHARED, mem->fd, 0);
if (mem->ptr == MAP_FAILED) {
mem->ptr = NULL;
fprintf (stderr, "Failed to mmap memory %p: %s\n", mem, strerror (errno));
fprintf (stderr, "Failed to mmap memory %zd %p: %s\n", mem->size, mem, strerror (errno));
}
return mem->ptr;
}

View file

@ -1,4 +1,5 @@
spalib_sources = ['audio-raw.c',
'buffer.c',
'control.c',
'debug.c',
'memory.c',

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;
}

View file

@ -94,19 +94,14 @@ on_mix_event (SpaNode *node, SpaEvent *event, void *user_data)
AppData *data = user_data;
switch (event->type) {
case SPA_EVENT_TYPE_PULL_INPUT:
case SPA_EVENT_TYPE_NEED_INPUT:
{
SpaInputInfo iinfo;
SpaOutputInfo oinfo;
SpaResult res;
SpaEventPullInput *pi;
pi = event->data;
oinfo.port_id = 0;
oinfo.flags = SPA_OUTPUT_FLAG_NONE;
oinfo.size = pi->size;
oinfo.offset = pi->offset;
if (event->port_id == data->mix_ports[0]) {
if ((res = spa_node_port_pull_output (data->source1, 1, &oinfo)) < 0)
@ -136,19 +131,14 @@ on_sink_event (SpaNode *node, SpaEvent *event, void *user_data)
AppData *data = user_data;
switch (event->type) {
case SPA_EVENT_TYPE_PULL_INPUT:
case SPA_EVENT_TYPE_NEED_INPUT:
{
SpaInputInfo iinfo;
SpaOutputInfo oinfo;
SpaResult res;
SpaEventPullInput *pi;
pi = event->data;
oinfo.port_id = 0;
oinfo.flags = SPA_OUTPUT_FLAG_PULL;
oinfo.offset = pi->offset;
oinfo.size = pi->size;
if ((res = spa_node_port_pull_output (data->mix, 1, &oinfo)) < 0)
printf ("got error %d\n", res);

View file

@ -115,7 +115,7 @@ on_source_event (SpaNode *node, SpaEvent *event, void *user_data)
AppData *data = user_data;
switch (event->type) {
case SPA_EVENT_TYPE_CAN_PULL_OUTPUT:
case SPA_EVENT_TYPE_HAVE_OUTPUT:
{
SpaOutputInfo info[1] = { 0, };
SpaResult res;
@ -178,7 +178,7 @@ on_source_event (SpaNode *node, SpaEvent *event, void *user_data)
SDL_RenderCopy (data->renderer, data->texture, NULL, NULL);
SDL_RenderPresent (data->renderer);
}
spa_node_port_reuse_buffer (data->source, 0, info->buffer_id, info->offset, info->size);
spa_node_port_reuse_buffer (data->source, 0, info->buffer_id);
break;
}
case SPA_EVENT_TYPE_ADD_POLL: