mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-14 06:59:57 -05:00
Use int counters for iterating items
Use counters instead of void* to iterate items. This simplifies some things and makes it easier to do over the wire. Add format description to NodeInfo and use this to add format descriptions to pinos devices. Small fixes to fix leaks and crashes.
This commit is contained in:
parent
8b84d8fde6
commit
b38ecafe81
38 changed files with 363 additions and 330 deletions
|
|
@ -81,8 +81,8 @@ connection_add_fd (PinosConnection *conn,
|
|||
return index;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#define PINOS_DEBUG_MESSAGE(format,args...) pinos_log_debug(stderr, format,##args)
|
||||
#if 1
|
||||
#define PINOS_DEBUG_MESSAGE(format,args...) pinos_log_debug(format,##args)
|
||||
#else
|
||||
#define PINOS_DEBUG_MESSAGE(format,args...)
|
||||
#endif
|
||||
|
|
@ -200,6 +200,7 @@ connection_parse_node_info (PinosConnection *conn, PinosMessageNodeInfo *m)
|
|||
{
|
||||
void *p;
|
||||
PinosNodeInfo *di;
|
||||
int i;
|
||||
|
||||
p = conn->in.data;
|
||||
memcpy (m, p, sizeof (PinosMessageNodeInfo));
|
||||
|
|
@ -207,12 +208,32 @@ connection_parse_node_info (PinosConnection *conn, PinosMessageNodeInfo *m)
|
|||
m->info = SPA_MEMBER (p, SPA_PTR_TO_INT (m->info), PinosNodeInfo);
|
||||
di = m->info;
|
||||
|
||||
if (m->info->name)
|
||||
m->info->name = SPA_MEMBER (di, SPA_PTR_TO_INT (m->info->name), const char);
|
||||
if (m->info->error)
|
||||
m->info->error = SPA_MEMBER (di, SPA_PTR_TO_INT (m->info->error), const char);
|
||||
if (m->info->props)
|
||||
m->info->props = pinos_serialize_dict_deserialize (di, SPA_PTR_TO_INT (m->info->props));
|
||||
if (di->name)
|
||||
di->name = SPA_MEMBER (di, SPA_PTR_TO_INT (di->name), const char);
|
||||
|
||||
if (di->input_formats)
|
||||
di->input_formats = SPA_MEMBER (di,
|
||||
SPA_PTR_TO_INT (di->input_formats), SpaFormat *);
|
||||
for (i = 0; i < di->n_input_formats; i++) {
|
||||
if (di->input_formats[i]) {
|
||||
di->input_formats[i] = pinos_serialize_format_deserialize (di,
|
||||
SPA_PTR_TO_INT (di->input_formats[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (di->output_formats)
|
||||
di->output_formats = SPA_MEMBER (di,
|
||||
SPA_PTR_TO_INT (di->output_formats), SpaFormat *);
|
||||
for (i = 0; i < di->n_output_formats; i++) {
|
||||
if (di->output_formats[i]) {
|
||||
di->output_formats[i] = pinos_serialize_format_deserialize (di,
|
||||
SPA_PTR_TO_INT (di->output_formats[i]));
|
||||
}
|
||||
}
|
||||
if (di->error)
|
||||
di->error = SPA_MEMBER (di, SPA_PTR_TO_INT (di->error), const char);
|
||||
if (di->props)
|
||||
di->props = pinos_serialize_dict_deserialize (di, SPA_PTR_TO_INT (di->props));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +380,7 @@ connection_add_message (PinosConnection *conn,
|
|||
buf->buffer_size += 8 + size;
|
||||
|
||||
*p++ = dest_id;
|
||||
*p++ = (type << 16) | (size & 0xffff);
|
||||
*p++ = (type << 24) | (size & 0xffffff);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
@ -624,12 +645,19 @@ connection_add_node_info (PinosConnection *conn, uint32_t dest_id, PinosMessageN
|
|||
size_t len, slen;
|
||||
void *p;
|
||||
PinosMessageNodeInfo *d;
|
||||
int i;
|
||||
|
||||
/* calc len */
|
||||
len = sizeof (PinosMessageNodeInfo);
|
||||
if (m->info) {
|
||||
len += sizeof (PinosNodeInfo);
|
||||
len += m->info->name ? strlen (m->info->name) + 1 : 0;
|
||||
len += m->info->n_input_formats * sizeof (SpaFormat *);
|
||||
for (i = 0; i < m->info->n_input_formats; i++)
|
||||
len += pinos_serialize_format_get_size (m->info->input_formats[i]);
|
||||
len += m->info->n_output_formats * sizeof (SpaFormat *);
|
||||
for (i = 0; i < m->info->n_output_formats; i++)
|
||||
len += pinos_serialize_format_get_size (m->info->output_formats[i]);
|
||||
len += m->info->error ? strlen (m->info->error) + 1 : 0;
|
||||
len += pinos_serialize_dict_get_size (m->info->props);
|
||||
}
|
||||
|
|
@ -641,18 +669,43 @@ connection_add_node_info (PinosConnection *conn, uint32_t dest_id, PinosMessageN
|
|||
p = SPA_MEMBER (d, sizeof (PinosMessageNodeInfo), void);
|
||||
if (m->info) {
|
||||
PinosNodeInfo *di;
|
||||
SpaFormat **ifa, **ofa;
|
||||
|
||||
memcpy (p, m->info, sizeof (PinosNodeInfo));
|
||||
d->info = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
|
||||
di = p;
|
||||
|
||||
p = SPA_MEMBER (p, sizeof (PinosNodeInfo), void);
|
||||
ifa = p;
|
||||
if (m->info->n_input_formats)
|
||||
di->input_formats = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
|
||||
else
|
||||
di->input_formats = 0;
|
||||
p = SPA_MEMBER (p, sizeof (SpaFormat*) * m->info->n_input_formats, void);
|
||||
|
||||
ofa = p;
|
||||
if (m->info->n_output_formats)
|
||||
di->output_formats = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
|
||||
else
|
||||
di->output_formats = 0;
|
||||
p = SPA_MEMBER (p, sizeof (SpaFormat*) * m->info->n_output_formats, void);
|
||||
|
||||
if (m->info->name) {
|
||||
slen = strlen (m->info->name) + 1;
|
||||
memcpy (p, m->info->name, slen);
|
||||
di->name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
|
||||
p += slen;
|
||||
}
|
||||
for (i = 0; i < m->info->n_input_formats; i++) {
|
||||
len = pinos_serialize_format_serialize (p, m->info->input_formats[i]);
|
||||
ifa[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
|
||||
p = SPA_MEMBER (p, len, void);
|
||||
}
|
||||
for (i = 0; i < m->info->n_output_formats; i++) {
|
||||
len = pinos_serialize_format_serialize (p, m->info->output_formats[i]);
|
||||
ofa[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
|
||||
p = SPA_MEMBER (p, len, void);
|
||||
}
|
||||
if (m->info->error) {
|
||||
slen = strlen (m->info->error) + 1;
|
||||
memcpy (p, m->info->error, slen);
|
||||
|
|
@ -662,6 +715,7 @@ connection_add_node_info (PinosConnection *conn, uint32_t dest_id, PinosMessageN
|
|||
if (m->info->props) {
|
||||
len = pinos_serialize_dict_serialize (p, m->info->props);
|
||||
di->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
|
||||
p += len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1084,8 +1138,8 @@ again:
|
|||
size -= 8;
|
||||
|
||||
buf->dest_id = p[0];
|
||||
buf->type = p[1] >> 16;
|
||||
len = p[1] & 0xffff;
|
||||
buf->type = p[1] >> 24;
|
||||
len = p[1] & 0xffffff;
|
||||
|
||||
if (len > size) {
|
||||
connection_ensure_size (conn, buf, len);
|
||||
|
|
@ -1522,11 +1576,11 @@ pinos_connection_flush (PinosConnection *conn)
|
|||
}
|
||||
break;
|
||||
}
|
||||
PINOS_DEBUG_MESSAGE ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds);
|
||||
|
||||
buf->buffer_size -= len;
|
||||
buf->n_fds = 0;
|
||||
|
||||
PINOS_DEBUG_MESSAGE ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds);
|
||||
|
||||
return true;
|
||||
|
||||
/* ERRORS */
|
||||
|
|
|
|||
|
|
@ -492,6 +492,8 @@ pinos_context_new (PinosLoop *loop,
|
|||
if (impl == NULL)
|
||||
return NULL;
|
||||
|
||||
impl->fd = -1;
|
||||
|
||||
this = &impl->this;
|
||||
pinos_log_debug ("context %p: new", impl);
|
||||
|
||||
|
|
@ -686,10 +688,21 @@ pinos_context_disconnect (PinosContext *context)
|
|||
|
||||
impl->disconnecting = true;
|
||||
|
||||
pinos_proxy_destroy (context->registry_proxy);
|
||||
pinos_proxy_destroy (context->core_proxy);
|
||||
pinos_connection_destroy (impl->connection);
|
||||
close (impl->fd);
|
||||
if (context->registry_proxy)
|
||||
pinos_proxy_destroy (context->registry_proxy);
|
||||
context->registry_proxy = NULL;
|
||||
|
||||
if (context->core_proxy)
|
||||
pinos_proxy_destroy (context->core_proxy);
|
||||
context->core_proxy = NULL;
|
||||
|
||||
if (impl->connection)
|
||||
pinos_connection_destroy (impl->connection);
|
||||
impl->connection = NULL;
|
||||
|
||||
if (impl->fd != -1)
|
||||
close (impl->fd);
|
||||
impl->fd = -1;
|
||||
|
||||
context_set_state (context, PINOS_CONTEXT_STATE_UNCONNECTED, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/client/serialize.h"
|
||||
|
||||
#include "pinos/client/context.h"
|
||||
#include "pinos/client/subscribe.h"
|
||||
|
|
@ -218,6 +219,8 @@ pinos_node_info_update (PinosNodeInfo *info,
|
|||
const PinosNodeInfo *update)
|
||||
{
|
||||
uint64_t change_mask;
|
||||
int i;
|
||||
size_t size;
|
||||
|
||||
if (update == NULL)
|
||||
return info;
|
||||
|
|
@ -240,13 +243,38 @@ pinos_node_info_update (PinosNodeInfo *info,
|
|||
}
|
||||
if (update->change_mask & (1 << 1))
|
||||
info->max_inputs = update->max_inputs;
|
||||
if (update->change_mask & (1 << 2))
|
||||
if (update->change_mask & (1 << 2)) {
|
||||
for (i = 0; i < info->n_input_formats; i++)
|
||||
free (info->input_formats[i]);
|
||||
info->n_input_formats = update->n_input_formats;
|
||||
|
||||
if (info->n_input_formats)
|
||||
info->input_formats = realloc (info->input_formats, info->n_input_formats * sizeof (SpaFormat *));
|
||||
else {
|
||||
free (info->input_formats);
|
||||
info->input_formats = NULL;
|
||||
}
|
||||
for (i = 0; i < info->n_input_formats; i++) {
|
||||
size = pinos_serialize_format_get_size (update->input_formats[i]);
|
||||
info->input_formats[i] = size ? pinos_serialize_format_copy_into (malloc (size), update->input_formats[i]) : NULL;
|
||||
}
|
||||
}
|
||||
if (update->change_mask & (1 << 3))
|
||||
info->max_outputs = update->max_outputs;
|
||||
if (update->change_mask & (1 << 4))
|
||||
if (update->change_mask & (1 << 4)) {
|
||||
for (i = 0; i < info->n_output_formats; i++)
|
||||
free (info->output_formats[i]);
|
||||
info->n_output_formats = update->n_output_formats;
|
||||
if (info->n_output_formats)
|
||||
info->output_formats = realloc (info->output_formats, info->n_output_formats * sizeof (SpaFormat *));
|
||||
else {
|
||||
free (info->output_formats);
|
||||
info->output_formats = NULL;
|
||||
}
|
||||
for (i = 0; i < info->n_output_formats; i++) {
|
||||
size = pinos_serialize_format_get_size (update->output_formats[i]);
|
||||
info->output_formats[i] = size ? pinos_serialize_format_copy_into (malloc (size), update->output_formats[i]) : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (update->change_mask & (1 << 5)) {
|
||||
info->state = update->state;
|
||||
|
|
@ -265,10 +293,22 @@ pinos_node_info_update (PinosNodeInfo *info,
|
|||
void
|
||||
pinos_node_info_free (PinosNodeInfo *info)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (info == NULL)
|
||||
return;
|
||||
if (info->name)
|
||||
free ((void*)info->name);
|
||||
if (info->input_formats) {
|
||||
for (i = 0; i < info->n_input_formats; i++)
|
||||
free (info->input_formats[i]);
|
||||
free (info->input_formats);
|
||||
}
|
||||
if (info->output_formats) {
|
||||
for (i = 0; i < info->n_output_formats; i++)
|
||||
free (info->output_formats[i]);
|
||||
free (info->output_formats);
|
||||
}
|
||||
if (info->error)
|
||||
free ((void*)info->error);
|
||||
if (info->props)
|
||||
|
|
|
|||
|
|
@ -119,6 +119,8 @@ pinos_thread_main_loop_destroy (PinosThreadMainLoop *loop)
|
|||
|
||||
pinos_signal_emit (&loop->destroy_signal, loop);
|
||||
|
||||
pinos_thread_main_loop_stop (loop);
|
||||
|
||||
if (loop->name)
|
||||
free (loop->name);
|
||||
pthread_mutex_destroy (&impl->lock);
|
||||
|
|
@ -187,9 +189,11 @@ pinos_thread_main_loop_stop (PinosThreadMainLoop *loop)
|
|||
{
|
||||
PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this);
|
||||
|
||||
pinos_loop_signal_event (loop->loop, impl->event);
|
||||
|
||||
pthread_join (impl->thread, NULL);
|
||||
if (impl->running) {
|
||||
pinos_loop_signal_event (loop->loop, impl->event);
|
||||
pthread_join (impl->thread, NULL);
|
||||
impl->running = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue