mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-12 13:30:15 -05:00
mem: remove memory stuff
Remove the memory stuff from the spa API, we can do thing more simple and efficiently if we always allocate buffers outside of the plugins and only implement an alloc function on the node when it can do something clever. Move serialize code to the props/format/buffer code Make it possible to copy a format and properties.
This commit is contained in:
parent
fe37e2bc1b
commit
24108e01c1
46 changed files with 901 additions and 1546 deletions
|
|
@ -23,27 +23,21 @@
|
|||
static SpaFormat *
|
||||
format_copy (SpaFormat *format)
|
||||
{
|
||||
SpaMemory *mem;
|
||||
SpaFormat *f;
|
||||
void *p;
|
||||
size_t size;
|
||||
|
||||
if (format == NULL)
|
||||
return NULL;
|
||||
|
||||
mem = spa_memory_alloc_size (format->mem.mem.pool_id, format, format->mem.size);
|
||||
f = spa_memory_ensure_ptr (mem);
|
||||
f->mem.mem = mem->mem;
|
||||
f->mem.offset = 0;
|
||||
f->mem.size = format->mem.size;
|
||||
|
||||
return spa_memory_ensure_ptr (mem);
|
||||
size = spa_format_get_size (format);
|
||||
p = malloc (size);
|
||||
return spa_format_copy_into (p, format);
|
||||
}
|
||||
|
||||
static void
|
||||
format_free (SpaFormat *format)
|
||||
{
|
||||
g_return_if_fail (format != NULL);
|
||||
|
||||
spa_memory_unref (&format->mem.mem);
|
||||
g_free (format);
|
||||
}
|
||||
|
||||
G_DEFINE_BOXED_TYPE (SpaFormat, spa_format,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
#include <glib.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "spa/include/spa/memory.h"
|
||||
|
||||
const gchar g_log_domain_pinos[] = "Pinos";
|
||||
|
||||
|
|
@ -45,7 +44,6 @@ pinos_error_quark (void)
|
|||
void
|
||||
pinos_init (int *argc, char **argv[])
|
||||
{
|
||||
spa_memory_init ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@
|
|||
#include <sys/socket.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "spa/include/spa/control.h"
|
||||
#include "spa/include/spa/debug.h"
|
||||
#include "spa/include/spa/memory.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixfdlist.h>
|
||||
|
|
@ -43,7 +43,15 @@
|
|||
#define MAX_OUTPUTS 64
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
int fd;
|
||||
uint32_t flags;
|
||||
void *ptr;
|
||||
size_t size;
|
||||
bool cleanup;
|
||||
} MemId;
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
bool used;
|
||||
SpaBuffer *buf;
|
||||
|
|
@ -90,6 +98,7 @@ struct _PinosStreamPrivate
|
|||
guint8 send_data[MAX_BUFFER_SIZE];
|
||||
int send_fds[MAX_FDS];
|
||||
|
||||
GArray *mem_ids;
|
||||
GArray *buffer_ids;
|
||||
gboolean in_order;
|
||||
|
||||
|
|
@ -134,7 +143,6 @@ clear_buffers (PinosStream *stream)
|
|||
BufferId *bid = &g_array_index (priv->buffer_ids, BufferId, i);
|
||||
|
||||
g_signal_emit (stream, signals[SIGNAL_REMOVE_BUFFER], 0, bid->id);
|
||||
spa_memory_unref (&bid->buf->mem.mem);
|
||||
bid->buf = NULL;
|
||||
}
|
||||
g_array_set_size (priv->buffer_ids, 0);
|
||||
|
|
@ -207,7 +215,7 @@ pinos_stream_set_property (GObject *_object,
|
|||
|
||||
case PROP_FORMAT:
|
||||
if (priv->format)
|
||||
spa_format_unref (priv->format);
|
||||
g_boxed_free (SPA_TYPE_FORMAT, priv->format);
|
||||
priv->format = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
|
|
@ -338,7 +346,7 @@ pinos_stream_finalize (GObject * object)
|
|||
if (priv->possible_formats)
|
||||
g_ptr_array_unref (priv->possible_formats);
|
||||
if (priv->format)
|
||||
spa_format_unref (priv->format);
|
||||
g_boxed_free (SPA_TYPE_FORMAT, priv->format);
|
||||
|
||||
g_free (priv->path);
|
||||
g_clear_error (&priv->error);
|
||||
|
|
@ -507,6 +515,7 @@ pinos_stream_init (PinosStream * stream)
|
|||
|
||||
priv->state = PINOS_STREAM_STATE_UNCONNECTED;
|
||||
priv->node_state = SPA_NODE_STATE_INIT;
|
||||
priv->mem_ids = g_array_sized_new (FALSE, FALSE, sizeof (MemId), 64);
|
||||
priv->buffer_ids = g_array_sized_new (FALSE, FALSE, sizeof (BufferId), 64);
|
||||
priv->pending_seq = SPA_ID_INVALID;
|
||||
}
|
||||
|
|
@ -809,6 +818,20 @@ do_node_init (PinosStream *stream)
|
|||
spa_control_clear (&control);
|
||||
}
|
||||
|
||||
static MemId *
|
||||
find_mem (PinosStream *stream, uint32_t id)
|
||||
{
|
||||
PinosStreamPrivate *priv = stream->priv;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < priv->mem_ids->len; i++) {
|
||||
MemId *mid = &g_array_index (priv->mem_ids, MemId, i);
|
||||
if (mid->id == id)
|
||||
return mid;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BufferId *
|
||||
find_buffer (PinosStream *stream, uint32_t id)
|
||||
{
|
||||
|
|
@ -987,24 +1010,15 @@ parse_control (PinosStream *stream,
|
|||
case SPA_CONTROL_CMD_SET_FORMAT:
|
||||
{
|
||||
SpaControlCmdSetFormat p;
|
||||
SpaMemory *mem;
|
||||
void *data;
|
||||
size_t size;
|
||||
gpointer mem;
|
||||
|
||||
data = spa_control_iter_get_data (&it, &size);
|
||||
mem = spa_memory_alloc_size (SPA_MEMORY_POOL_LOCAL, data, size);
|
||||
spa_control_iter_set_data (&it, spa_memory_ensure_ptr (mem), size);
|
||||
|
||||
if (spa_control_iter_parse_cmd (&it, &p) < 0) {
|
||||
spa_memory_unref (&mem->mem);
|
||||
if (spa_control_iter_parse_cmd (&it, &p) < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (priv->format)
|
||||
spa_format_unref (priv->format);
|
||||
if (p.format)
|
||||
p.format->mem.mem = mem->mem;
|
||||
priv->format = p.format;
|
||||
g_free (priv->format);
|
||||
mem = malloc (spa_format_get_size (p.format));
|
||||
priv->format = spa_format_copy_into (mem, p.format);
|
||||
|
||||
spa_debug_format (p.format);
|
||||
priv->pending_seq = p.seq;
|
||||
|
|
@ -1018,8 +1032,8 @@ parse_control (PinosStream *stream,
|
|||
case SPA_CONTROL_CMD_ADD_MEM:
|
||||
{
|
||||
SpaControlCmdAddMem p;
|
||||
SpaMemory *mem;
|
||||
int fd;
|
||||
MemId mid;
|
||||
|
||||
if (spa_control_iter_parse_cmd (&it, &p) < 0)
|
||||
break;
|
||||
|
|
@ -1028,32 +1042,34 @@ parse_control (PinosStream *stream,
|
|||
if (fd == -1)
|
||||
break;
|
||||
|
||||
mem = spa_memory_import (&p.mem);
|
||||
if (mem->fd == -1) {
|
||||
g_debug ("add mem %u:%u, fd %d, flags %d", p.mem.pool_id, p.mem.id, fd, p.flags);
|
||||
mem->flags = p.flags;
|
||||
mem->fd = fd;
|
||||
mem->ptr = NULL;
|
||||
mem->size = p.size;
|
||||
}
|
||||
mid.id = p.mem_id;
|
||||
mid.fd = fd;
|
||||
mid.flags = p.flags;
|
||||
mid.ptr = NULL;
|
||||
mid.size = p.size;
|
||||
|
||||
g_debug ("add mem %u, fd %d, flags %d", p.mem_id, fd, p.flags);
|
||||
g_array_append_val (priv->mem_ids, mid);
|
||||
break;
|
||||
}
|
||||
case SPA_CONTROL_CMD_REMOVE_MEM:
|
||||
{
|
||||
SpaControlCmdRemoveMem p;
|
||||
MemId *mid;
|
||||
|
||||
if (spa_control_iter_parse_cmd (&it, &p) < 0)
|
||||
break;
|
||||
|
||||
g_debug ("stream %p: remove mem", stream);
|
||||
spa_memory_unref (&p.mem);
|
||||
g_debug ("stream %p: remove mem %d", stream, p.mem_id);
|
||||
if ((mid = find_mem (stream, p.mem_id)))
|
||||
mid->cleanup = true;
|
||||
break;
|
||||
}
|
||||
case SPA_CONTROL_CMD_USE_BUFFERS:
|
||||
{
|
||||
SpaControlCmdUseBuffers p;
|
||||
BufferId bid;
|
||||
unsigned int i;
|
||||
unsigned int i, j;
|
||||
SpaControlBuilder builder;
|
||||
SpaControl control;
|
||||
|
||||
|
|
@ -1064,12 +1080,34 @@ parse_control (PinosStream *stream,
|
|||
clear_buffers (stream);
|
||||
|
||||
for (i = 0; i < p.n_buffers; i++) {
|
||||
bid.buf = p.buffers[i];
|
||||
bid.cleanup = false;
|
||||
MemId *mid = find_mem (stream, p.buffers[i].mem_id);
|
||||
if (mid == NULL) {
|
||||
g_warning ("unknown memory id %u", mid->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mid->ptr == NULL) {
|
||||
mid->ptr = mmap (NULL, mid->size, PROT_READ | PROT_WRITE, MAP_SHARED, mid->fd, 0);
|
||||
if (mid->ptr == MAP_FAILED) {
|
||||
mid->ptr = NULL;
|
||||
g_warning ("Failed to mmap memory %zd %p: %s", mid->size, mid, strerror (errno));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
bid.buf = spa_buffer_deserialize (mid->ptr, p.buffers[i].offset);
|
||||
bid.id = bid.buf->id;
|
||||
g_debug ("add buffer %d: %u:%u, %zd-%zd", bid.id,
|
||||
bid.buf->mem.mem.pool_id, bid.buf->mem.mem.id,
|
||||
bid.buf->mem.offset, bid.buf->mem.size);
|
||||
|
||||
spa_debug_dump_mem (mid->ptr, 256);
|
||||
|
||||
g_debug ("add buffer %d %zd", bid.id, p.buffers[i].offset);
|
||||
|
||||
for (j = 0; j < bid.buf->n_datas; j++) {
|
||||
SpaData *d = &bid.buf->datas[j];
|
||||
MemId *bmid = find_mem (stream, SPA_PTR_TO_UINT32 (d->data));
|
||||
d->data = SPA_INT_TO_PTR (bmid->fd);
|
||||
g_debug (" data %d %u -> %d", j, bmid->id, bmid->fd);
|
||||
}
|
||||
|
||||
if (bid.id != priv->buffer_ids->len) {
|
||||
g_warning ("unexpected id %u found, expected %u", bid.id, priv->buffer_ids->len);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include <pinos/client/pinos.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
#include <pinos/server/module.h>
|
||||
#include <spa/include/spa/memory.h>
|
||||
|
||||
#include "daemon-config.h"
|
||||
|
||||
|
|
@ -37,7 +36,6 @@ main (gint argc, gchar *argv[])
|
|||
GError *err = NULL;
|
||||
|
||||
pinos_init (&argc, &argv);
|
||||
spa_memory_init ();
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
|
|
|
|||
|
|
@ -288,7 +288,6 @@ convert_1 (GstCapsFeatures *cf, GstStructure *cs)
|
|||
{
|
||||
const GValue *val;
|
||||
guint size, n_infos = 0, n_ranges = 0, n_datas = 0;
|
||||
SpaMemory *mem;
|
||||
ConvertData d;
|
||||
|
||||
d.cf = cf;
|
||||
|
|
@ -301,12 +300,7 @@ convert_1 (GstCapsFeatures *cf, GstStructure *cs)
|
|||
size += n_ranges * sizeof (SpaPropRangeInfo);
|
||||
size += n_datas;
|
||||
|
||||
mem = spa_memory_alloc_size (SPA_MEMORY_POOL_LOCAL, NULL, size);
|
||||
d.f = spa_memory_ensure_ptr (mem);
|
||||
d.f->mem.mem = mem->mem;
|
||||
d.f->mem.offset = 0;
|
||||
d.f->mem.size = mem->size;
|
||||
|
||||
d.f = malloc (size);
|
||||
d.bpi = SPA_MEMBER (d.f, sizeof (SpaFormat), SpaPropInfo);
|
||||
d.bri = SPA_MEMBER (d.bpi, n_infos * sizeof (SpaPropInfo), SpaPropRangeInfo);
|
||||
d.p = SPA_MEMBER (d.bri, n_ranges * sizeof (SpaPropRangeInfo), void);
|
||||
|
|
@ -474,9 +468,7 @@ gst_caps_to_format_all (GstCaps *caps)
|
|||
{
|
||||
GPtrArray *res;
|
||||
|
||||
res = g_ptr_array_new_full (gst_caps_get_size (caps),
|
||||
(GDestroyNotify)spa_format_unref);
|
||||
|
||||
res = g_ptr_array_new_full (gst_caps_get_size (caps), (GDestroyNotify)g_free);
|
||||
gst_caps_foreach (caps, (GstCapsForeachFunc) foreach_func, res);
|
||||
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -371,33 +371,31 @@ on_add_buffer (GObject *gobject,
|
|||
data.header = NULL;
|
||||
|
||||
for (i = 0; i < b->n_metas; i++) {
|
||||
SpaMeta *m = &SPA_BUFFER_METAS(b)[i];
|
||||
SpaMeta *m = &b->metas[i];
|
||||
|
||||
switch (m->type) {
|
||||
case SPA_META_TYPE_HEADER:
|
||||
data.header = SPA_MEMBER (b, m->offset, SpaMetaHeader);
|
||||
data.header = m->data;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < b->n_datas; i++) {
|
||||
SpaData *d = &SPA_BUFFER_DATAS (b)[i];
|
||||
SpaMemory *mem;
|
||||
SpaData *d = &b->datas[i];
|
||||
|
||||
mem = spa_memory_find (&d->mem.mem);
|
||||
|
||||
if (mem->fd) {
|
||||
if (d->type == SPA_DATA_TYPE_FD) {
|
||||
GstMemory *fdmem = NULL;
|
||||
gint fd = *(int*)d->data;
|
||||
|
||||
fdmem = gst_fd_allocator_alloc (pinossink->allocator, dup (mem->fd),
|
||||
d->mem.offset + d->mem.size, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (fdmem, d->mem.offset, d->mem.size);
|
||||
fdmem = gst_fd_allocator_alloc (pinossink->allocator, dup (fd),
|
||||
d->offset + d->size, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (fdmem, d->offset, d->size);
|
||||
gst_buffer_append_memory (buf, fdmem);
|
||||
} else {
|
||||
gst_buffer_append_memory (buf,
|
||||
gst_memory_new_wrapped (0, mem->ptr, mem->size, d->mem.offset,
|
||||
d->mem.size, NULL, NULL));
|
||||
gst_memory_new_wrapped (0, d->data, d->offset + d->size, d->offset,
|
||||
d->size, NULL, NULL));
|
||||
}
|
||||
}
|
||||
data.flags = GST_BUFFER_FLAGS (buf);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@
|
|||
#include <gst/allocators/gstfdmemory.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#include <spa/include/spa/memory.h>
|
||||
#include <spa/include/spa/buffer.h>
|
||||
|
||||
#include "gstpinosclock.h"
|
||||
|
|
@ -387,34 +386,29 @@ on_add_buffer (GObject *gobject,
|
|||
data.header = NULL;
|
||||
|
||||
for (i = 0; i < b->n_metas; i++) {
|
||||
SpaMeta *m = &SPA_BUFFER_METAS(b)[i];
|
||||
SpaMeta *m = &b->metas[i];
|
||||
|
||||
switch (m->type) {
|
||||
case SPA_META_TYPE_HEADER:
|
||||
data.header = SPA_MEMBER (b, m->offset, SpaMetaHeader);
|
||||
data.header = m->data;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < b->n_datas; i++) {
|
||||
SpaData *d = &SPA_BUFFER_DATAS(b)[i];
|
||||
SpaMemory *mem;
|
||||
SpaData *d = &b->datas[i];
|
||||
GstMemory *gmem;
|
||||
|
||||
mem = spa_memory_find (&d->mem.mem);
|
||||
if (mem == NULL) {
|
||||
g_warning ("failed to get buffer memory");
|
||||
continue;
|
||||
}
|
||||
if (d->type == SPA_DATA_TYPE_FD) {
|
||||
gint fd = SPA_PTR_TO_INT (d->data);
|
||||
|
||||
if (mem->fd) {
|
||||
gmem = gst_fd_allocator_alloc (pinossrc->fd_allocator, dup (mem->fd),
|
||||
mem->size, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (gmem, d->mem.offset, d->mem.size);
|
||||
gmem = gst_fd_allocator_alloc (pinossrc->fd_allocator, dup (fd),
|
||||
d->offset + d->size, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (gmem, d->offset, d->size);
|
||||
} else {
|
||||
gmem = gst_memory_new_wrapped (0, mem->ptr, mem->size, d->mem.offset,
|
||||
d->mem.size, NULL, NULL);
|
||||
gmem = gst_memory_new_wrapped (0, d->data, d->offset + d->size, d->offset,
|
||||
d->size, NULL, NULL);
|
||||
}
|
||||
gst_buffer_append_memory (buf, gmem);
|
||||
}
|
||||
|
|
@ -472,9 +466,9 @@ on_new_buffer (GObject *gobject,
|
|||
GST_BUFFER_OFFSET (buf) = h->seq;
|
||||
}
|
||||
for (i = 0; i < data->buf->n_datas; i++) {
|
||||
SpaData *d = &SPA_BUFFER_DATAS(data->buf)[i];
|
||||
SpaData *d = &data->buf->datas[i];
|
||||
GstMemory *mem = gst_buffer_get_memory (buf, i);
|
||||
gst_memory_resize (mem, 0, d->mem.size);
|
||||
gst_memory_resize (mem, 0, d->size);
|
||||
}
|
||||
g_queue_push_tail (&pinossrc->queue, buf);
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ pinos_client_node_get_socket_pair (PinosClientNode *this,
|
|||
spa_node_get_props (node->node, &props);
|
||||
value.value = &priv->fd;
|
||||
value.size = sizeof (int);
|
||||
spa_props_set_prop (props, spa_props_index_for_name (props, "socket"), &value);
|
||||
spa_props_set_value (props, spa_props_index_for_name (props, "socket"), &value);
|
||||
spa_node_set_props (node->node, props);
|
||||
}
|
||||
return g_object_ref (priv->sockets[1]);
|
||||
|
|
@ -172,7 +172,7 @@ pinos_client_node_dispose (GObject * object)
|
|||
spa_node_get_props (node->node, &props);
|
||||
value.value = &fd;
|
||||
value.size = sizeof (int);
|
||||
spa_props_set_prop (props, spa_props_index_for_name (props, "socket"), &value);
|
||||
spa_props_set_value (props, spa_props_index_for_name (props, "socket"), &value);
|
||||
spa_node_set_props (node->node, props);
|
||||
|
||||
G_OBJECT_CLASS (pinos_client_node_parent_class)->dispose (object);
|
||||
|
|
|
|||
|
|
@ -350,8 +350,6 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
const SpaPortInfo *iinfo, *oinfo;
|
||||
SpaPortInfoFlags in_flags, out_flags;
|
||||
GError *error = NULL;
|
||||
unsigned int max_buffers = MAX_BUFFERS;
|
||||
SpaAllocParamBuffers *in_alloc, *out_alloc;
|
||||
|
||||
if (in_state != SPA_NODE_STATE_READY && out_state != SPA_NODE_STATE_READY)
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -377,14 +375,6 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
in_flags = iinfo->flags;
|
||||
out_flags = oinfo->flags;
|
||||
|
||||
max_buffers = MAX_BUFFERS;
|
||||
in_alloc = find_param (iinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
|
||||
if (in_alloc)
|
||||
max_buffers = in_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (in_alloc->max_buffers, max_buffers);
|
||||
out_alloc = find_param (oinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
|
||||
if (out_alloc)
|
||||
max_buffers = out_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (out_alloc->max_buffers, max_buffers);
|
||||
|
||||
if (out_flags & SPA_PORT_INFO_FLAG_LIVE) {
|
||||
this->output->node->live = true;
|
||||
this->input->node->live = true;
|
||||
|
|
@ -401,27 +391,8 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
in_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
} else if ((out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) &&
|
||||
(in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS)) {
|
||||
priv->n_buffers = max_buffers;
|
||||
out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
in_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
|
||||
if ((res = spa_buffer_alloc (oinfo->params, oinfo->n_params,
|
||||
priv->buffers,
|
||||
&priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error buffer alloc: %d", res);
|
||||
goto error;
|
||||
}
|
||||
priv->allocated = TRUE;
|
||||
memcpy (this->output->buffers, priv->buffers, priv->n_buffers * sizeof (SpaBuffer*));
|
||||
memcpy (this->input->buffers, priv->buffers, priv->n_buffers * sizeof (SpaBuffer*));
|
||||
this->output->n_buffers = priv->n_buffers;
|
||||
this->input->n_buffers = priv->n_buffers;
|
||||
this->output->allocated = FALSE;
|
||||
this->input->allocated = FALSE;
|
||||
g_debug ("allocated %d buffers %p", priv->n_buffers, priv->buffers);
|
||||
} else if ((out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) &&
|
||||
(in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS)) {
|
||||
out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
|
|
@ -446,38 +417,68 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
spa_debug_port_info (oinfo);
|
||||
spa_debug_port_info (iinfo);
|
||||
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS && this->input->n_buffers == 0) {
|
||||
this->input->n_buffers = max_buffers;
|
||||
if ((res = spa_node_port_alloc_buffers (this->input->node->node, this->input->port,
|
||||
oinfo->params, oinfo->n_params,
|
||||
this->input->buffers, &this->input->n_buffers)) < 0) {
|
||||
if (!priv->allocated) {
|
||||
SpaAllocParamBuffers *in_alloc, *out_alloc;
|
||||
guint max_buffers = MAX_BUFFERS;
|
||||
SpaBufferAllocFlags flags = 0;
|
||||
|
||||
max_buffers = MAX_BUFFERS;
|
||||
in_alloc = find_param (iinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
|
||||
if (in_alloc)
|
||||
max_buffers = in_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (in_alloc->max_buffers, max_buffers);
|
||||
out_alloc = find_param (oinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
|
||||
if (out_alloc)
|
||||
max_buffers = out_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (out_alloc->max_buffers, max_buffers);
|
||||
|
||||
if ((in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) ||
|
||||
(out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS))
|
||||
flags |= SPA_BUFFER_ALLOC_FLAG_NO_MEM;
|
||||
|
||||
priv->n_buffers = max_buffers;
|
||||
if ((res = spa_buffer_alloc (flags,
|
||||
oinfo->params, oinfo->n_params,
|
||||
priv->buffers,
|
||||
&priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc input buffers: %d", res);
|
||||
"error buffer alloc: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->input->allocated = TRUE;
|
||||
g_debug ("allocated %d buffers %p from input port", this->input->n_buffers, this->input->buffers);
|
||||
}
|
||||
else if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS && this->output->n_buffers == 0) {
|
||||
this->output->n_buffers = max_buffers;
|
||||
if ((res = spa_node_port_alloc_buffers (this->output->node->node, this->output->port,
|
||||
iinfo->params, iinfo->n_params,
|
||||
this->output->buffers, &this->output->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc output buffers: %d", res);
|
||||
goto error;
|
||||
g_debug ("allocated %d buffers %p", priv->n_buffers, priv->buffers);
|
||||
priv->allocated = TRUE;
|
||||
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
||||
if ((res = spa_node_port_alloc_buffers (this->input->node->node, this->input->port,
|
||||
oinfo->params, oinfo->n_params,
|
||||
priv->buffers, &priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc input buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->input->allocated = TRUE;
|
||||
g_debug ("allocated %d buffers %p from input port", priv->n_buffers, priv->buffers);
|
||||
}
|
||||
else if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
||||
if ((res = spa_node_port_alloc_buffers (this->output->node->node, this->output->port,
|
||||
iinfo->params, iinfo->n_params,
|
||||
priv->buffers, &priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc output buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->output->allocated = TRUE;
|
||||
g_debug ("allocated %d buffers %p from output port", priv->n_buffers, priv->buffers);
|
||||
}
|
||||
this->output->allocated = TRUE;
|
||||
g_debug ("allocated %d buffers %p from output port", this->output->n_buffers, this->output->buffers);
|
||||
}
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
||||
g_debug ("using output buffers %p on input port", this->output->buffers);
|
||||
g_debug ("using %d buffers %p on input port", priv->n_buffers, priv->buffers);
|
||||
if ((res = spa_node_port_use_buffers (this->input->node->node, this->input->port,
|
||||
this->output->buffers, this->output->n_buffers)) < 0) {
|
||||
priv->buffers, priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
|
|
@ -487,9 +488,9 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
this->input->allocated = FALSE;
|
||||
}
|
||||
else if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
||||
g_debug ("using %d in_buffers %p on output port", this->input->n_buffers, this->input->buffers);
|
||||
g_debug ("using %d buffers %p on output port", priv->n_buffers, priv->buffers);
|
||||
if ((res = spa_node_port_use_buffers (this->output->node->node, this->output->port,
|
||||
this->input->buffers, this->input->n_buffers)) < 0) {
|
||||
priv->buffers, priv->n_buffers)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
|
|
|
|||
|
|
@ -44,8 +44,6 @@ typedef struct {
|
|||
PinosNode *node;
|
||||
uint32_t port;
|
||||
gboolean allocated;
|
||||
SpaBuffer *buffers[16];
|
||||
guint n_buffers;
|
||||
} PinosPort;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ find_node_port (GList *ports, PinosNode *node, uint32_t port)
|
|||
GList *walk;
|
||||
for (walk = ports; walk; walk = g_list_next (walk)) {
|
||||
NodePort *np = walk->data;
|
||||
g_debug ("%p %d <-> %p %d", np->port.node, np->port.port, node, port);
|
||||
if (np->port.node == node && np->port.port == port)
|
||||
return np;
|
||||
}
|
||||
|
|
@ -285,14 +284,12 @@ suspend_node (PinosNode *this)
|
|||
if ((res = spa_node_port_set_format (this->node, p->port.port, 0, NULL)) < 0)
|
||||
g_warning ("error unset format output: %d", res);
|
||||
p->port.allocated = FALSE;
|
||||
p->port.n_buffers = 0;
|
||||
}
|
||||
for (walk = priv->output_ports; walk; walk = g_list_next (walk)) {
|
||||
NodePort *p = walk->data;
|
||||
if ((res = spa_node_port_set_format (this->node, p->port.port, 0, NULL)) < 0)
|
||||
g_warning ("error unset format output: %d", res);
|
||||
p->port.allocated = FALSE;
|
||||
p->port.n_buffers = 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue