mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-19 08:57:14 -05:00
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:
parent
a03352353f
commit
ca7d08c406
45 changed files with 1614 additions and 570 deletions
135
spa/lib/buffer.c
Normal file
135
spa/lib/buffer.c
Normal 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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
spalib_sources = ['audio-raw.c',
|
||||
'buffer.c',
|
||||
'control.c',
|
||||
'debug.c',
|
||||
'memory.c',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue