fix some leaks

Fix some leaks
Remove some unused fields
Install a loop so that plugins can use it
Start on adding format introspection
This commit is contained in:
Wim Taymans 2017-01-31 09:57:58 +01:00
parent 4b55d7c4da
commit 8b84d8fde6
13 changed files with 124 additions and 103 deletions

View file

@ -1216,10 +1216,6 @@ pinos_connection_parse_message (PinosConnection *conn,
connection_parse_port_update (conn, message);
break;
case PINOS_MESSAGE_PORT_STATUS_CHANGE:
pinos_log_warn ("implement iter of %d", conn->in.type);
break;
case PINOS_MESSAGE_NODE_STATE_CHANGE:
if (conn->in.size < sizeof (PinosMessageNodeStateChange))
return false;
@ -1410,10 +1406,6 @@ pinos_connection_add_message (PinosConnection *conn,
connection_add_port_update (conn, dest_id, message);
break;
case PINOS_MESSAGE_PORT_STATUS_CHANGE:
p = connection_add_message (conn, dest_id, type, 0);
break;
case PINOS_MESSAGE_NODE_STATE_CHANGE:
p = connection_add_message (conn, dest_id, type, sizeof (PinosMessageNodeStateChange));
memcpy (p, message, sizeof (PinosMessageNodeStateChange));

View file

@ -65,8 +65,6 @@ typedef enum {
PINOS_MESSAGE_NODE_UPDATE,
PINOS_MESSAGE_PORT_UPDATE,
PINOS_MESSAGE_NODE_STATE_CHANGE,
PINOS_MESSAGE_PORT_STATUS_CHANGE,
PINOS_MESSAGE_NODE_EVENT,
/* server to client */
@ -229,8 +227,6 @@ typedef struct {
SpaNodeState state;
} PinosMessageNodeStateChange;
/* PINOS_MESSAGE_PORT_STATUS_CHANGE */
/* PINOS_MESSAGE_NODE_EVENT */
typedef struct {
SpaNodeEvent *event;

View file

@ -543,6 +543,9 @@ pinos_context_destroy (PinosContext *context)
pinos_log_debug ("context %p: destroy", context);
pinos_signal_emit (&context->destroy_signal, context);
if (context->state != PINOS_CONTEXT_STATE_UNCONNECTED)
pinos_context_disconnect (context);
spa_list_for_each_safe (stream, t1, &context->stream_list, link)
pinos_stream_destroy (stream);
spa_list_for_each_safe (proxy, t2, &context->proxy_list, link)

View file

@ -238,13 +238,23 @@ pinos_node_info_update (PinosNodeInfo *info,
free ((void*)info->name);
info->name = update->name ? strdup (update->name) : NULL;
}
if (update->change_mask & (1 << 1)) {
if (update->change_mask & (1 << 1))
info->max_inputs = update->max_inputs;
if (update->change_mask & (1 << 2))
info->n_input_formats = update->n_input_formats;
if (update->change_mask & (1 << 3))
info->max_outputs = update->max_outputs;
if (update->change_mask & (1 << 4))
info->n_output_formats = update->n_output_formats;
if (update->change_mask & (1 << 5)) {
info->state = update->state;
if (info->error)
free ((void*)info->error);
info->error = update->error ? strdup (update->error) : NULL;
}
if (update->change_mask & (1 << 2)) {
if (update->change_mask & (1 << 6)) {
if (info->props)
pinos_spa_dict_destroy (info->props);
info->props = pinos_spa_dict_copy (update->props);

View file

@ -255,6 +255,14 @@ struct _PinosNodeInfo {
uint32_t id;
uint64_t change_mask;
const char *name;
unsigned int max_inputs;
unsigned int n_inputs;
unsigned int n_input_formats;
SpaFormat **input_formats;
unsigned int max_outputs;
unsigned int n_outputs;
unsigned int n_output_formats;
SpaFormat **output_formats;
PinosNodeState state;
const char *error;
SpaDict *props;

View file

@ -96,6 +96,26 @@ typedef struct
int64_t last_monotonic;
} PinosStreamImpl;
static void
clear_memid (MemId *mid)
{
if (mid->ptr != NULL)
munmap (mid->ptr, mid->size + mid->offset);
mid->ptr = NULL;
close (mid->fd);
}
static void
clear_mems (PinosStream *stream)
{
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
MemId *mid;
pinos_array_for_each (mid, &impl->mem_ids)
clear_memid (mid);
impl->mem_ids.size = 0;
}
static void
clear_buffers (PinosStream *stream)
{
@ -104,7 +124,9 @@ clear_buffers (PinosStream *stream)
pinos_array_for_each (bid, &impl->buffer_ids) {
pinos_signal_emit (&stream->remove_buffer, stream, bid->id);
free (bid->buf);
bid->buf = NULL;
bid->used = false;
}
impl->buffer_ids.size = 0;
impl->in_order = true;
@ -229,13 +251,19 @@ pinos_stream_destroy (PinosStream *stream)
spa_list_remove (&stream->link);
if (impl->node_proxy)
pinos_signal_remove (&impl->node_proxy_destroy);
if (impl->format)
free (impl->format);
if (stream->error)
free (stream->error);
clear_buffers (stream);
pinos_array_clear (&impl->buffer_ids);
clear_mems (stream);
pinos_array_clear (&impl->mem_ids);
if (stream->properties)
@ -499,6 +527,10 @@ unhandle_socket (PinosStream *stream)
pinos_loop_destroy_source (stream->context->loop, impl->rtsocket_source);
impl->rtsocket_source = NULL;
}
if (impl->timeout_source) {
pinos_loop_destroy_source (stream->context->loop, impl->timeout_source);
impl->timeout_source = NULL;
}
}
static void
@ -540,7 +572,7 @@ handle_socket (PinosStream *stream, int rtfd)
impl->rtsocket_source = pinos_loop_add_io (stream->context->loop,
impl->rtfd,
SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP,
false,
true,
on_rtsocket_condition,
stream);
@ -691,6 +723,7 @@ stream_dispatch_func (void *object,
if (m) {
pinos_log_debug ("update mem %u, fd %d, flags %d, off %zd, size %zd",
p->mem_id, p->memfd, p->flags, p->offset, p->size);
clear_memid (m);
} else {
m = pinos_array_add (&impl->mem_ids, sizeof (MemId));
pinos_log_debug ("add mem %u, fd %d, flags %d, off %zd, size %zd",
@ -719,12 +752,11 @@ stream_dispatch_func (void *object,
MemId *mid = find_mem (stream, p->buffers[i].mem_id);
if (mid == NULL) {
pinos_log_warn ("unknown memory id %u", mid->id);
pinos_log_warn ("unknown memory id %u", p->buffers[i].mem_id);
continue;
}
if (mid->ptr == NULL) {
//mid->ptr = mmap (NULL, mid->size, PROT_READ | PROT_WRITE, MAP_SHARED, mid->fd, mid->offset);
mid->ptr = mmap (NULL, mid->size + mid->offset, PROT_READ | PROT_WRITE, MAP_SHARED, mid->fd, 0);
if (mid->ptr == MAP_FAILED) {
mid->ptr = NULL;
@ -794,6 +826,7 @@ stream_dispatch_func (void *object,
if (p->n_buffers) {
add_state_change (stream, SPA_NODE_STATE_PAUSED, false);
} else {
clear_mems (stream);
add_state_change (stream, SPA_NODE_STATE_READY, false);
}
add_async_complete (stream, p->seq, SPA_RESULT_OK, true);
@ -855,6 +888,7 @@ on_node_proxy_destroy (PinosListener *listener,
impl->disconnecting = false;
impl->node_proxy = NULL;
pinos_signal_remove (&impl->node_proxy_destroy);
stream_set_state (this, PINOS_STREAM_STATE_UNCONNECTED, NULL);
}