diff options
author | Wim Taymans <wtaymans@redhat.com> | 2016-11-03 19:41:53 +0100 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2016-11-03 19:41:53 +0100 |
commit | 7e46f9e3ad6fdccae965799666aca036850182c0 (patch) | |
tree | e9a3663d26bda7dc2eab3af6407b01e91bc89353 | |
parent | a1c0bef2ed7ef80502efbc742d88013024345f56 (diff) |
More hacking
Move array and map to pinos
Move more things to spa lib
ControlCmd -> Message
Make pinos log, use for plugins as well
work on ringbuffer in alsa and nodes
work on making registry with all objects
81 files changed, 1838 insertions, 1037 deletions
diff --git a/pinos/client/array.h b/pinos/client/array.h new file mode 100644 index 00000000..b76a55ce --- /dev/null +++ b/pinos/client/array.h @@ -0,0 +1,105 @@ +/* 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. + */ + +#ifndef __PINOS_ARRAY_H__ +#define __PINOS_ARRAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _PinosArray PinosArray; + +#include <string.h> + +#include <spa/defs.h> + +struct _PinosArray { + void *data; + size_t size; + size_t alloc; +}; + +#define pinos_array_get_len_s(a,s) ((a)->size / (s)) +#define pinos_array_get_unchecked_s(a,idx,s,t) SPA_MEMBER ((a)->data,(idx)*(s),t) +#define pinos_array_check_index_s(a,idx,s) ((idx) < pinos_array_get_len(a,s)) + +#define pinos_array_get_len(a,t) pinos_array_get_len_s(a,sizeof(t)) +#define pinos_array_get_unchecked(a,idx,t) pinos_array_get_unchecked_s(a,idx,sizeof(t),t) +#define pinos_array_check_index(a,idx,t) pinos_array_check_index_s(a,idx,sizeof(t)) + +#define pinos_array_for_each(pos, array) \ + for (pos = (array)->data; \ + (const char *) pos < ((const char *) (array)->data + (array)->size); \ + (pos)++) + +static inline void +pinos_array_init (PinosArray *arr) +{ + memset (arr, 0, sizeof (PinosArray)); +} + +static inline void +pinos_array_clear (PinosArray *arr) +{ + free (arr->data); +} + +static inline bool +pinos_array_ensure_size (PinosArray *arr, + size_t size) +{ + size_t alloc, need; + + alloc = arr->alloc; + need = alloc + size; + + if (SPA_UNLIKELY (alloc < need)) { + void *data; + alloc = SPA_MAX (alloc, 16); + while (alloc < need) + alloc *= 2; + if (SPA_UNLIKELY ((data = realloc (arr->data, alloc)) == NULL)) + return false; + arr->data = data; + arr->alloc = alloc; + } + return true; +} + +static inline void * +pinos_array_add (PinosArray *arr, + size_t size) +{ + void *p; + + if (!pinos_array_ensure_size (arr, size)) + return NULL; + + p = arr->data + arr->size; + arr->size += size; + + return p; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __PINOS_ARRAY_H__ */ diff --git a/pinos/client/connection.c b/pinos/client/connection.c index 27aed319..91274001 100644 --- a/pinos/client/connection.c +++ b/pinos/client/connection.c @@ -27,23 +27,24 @@ #include "connection.h" #include "serialize.h" +#include "log.h" #define MAX_BUFFER_SIZE 1024 #define MAX_FDS 28 typedef struct { - uint8_t *buffer_data; - size_t buffer_size; - size_t buffer_maxsize; - int fds[MAX_FDS]; - unsigned int n_fds; - - PinosControlCmd cmd; - off_t offset; - void *data; - size_t size; - - bool update; + uint8_t *buffer_data; + size_t buffer_size; + size_t buffer_maxsize; + int fds[MAX_FDS]; + unsigned int n_fds; + + PinosMessageType type; + off_t offset; + void *data; + size_t size; + + bool update; } ConnectionBuffer; struct _PinosConnection { @@ -52,9 +53,9 @@ struct _PinosConnection { }; #if 0 -#define PINOS_DEBUG_CONTROL(format,args...) g_debug(format,##args) +#define PINOS_DEBUG_MESSAGE(format,args...) pinos_log_debug(stderr, format,##args) #else -#define PINOS_DEBUG_CONTROL(format,args...) +#define PINOS_DEBUG_MESSAGE(format,args...) #endif static bool @@ -80,20 +81,20 @@ read_length (uint8_t * data, unsigned int size, size_t * length, size_t * skip) } static void -connection_parse_node_update (PinosConnection *conn, PinosControlCmdNodeUpdate *nu) +connection_parse_node_update (PinosConnection *conn, PinosMessageNodeUpdate *nu) { - memcpy (nu, conn->in.data, sizeof (PinosControlCmdNodeUpdate)); + memcpy (nu, conn->in.data, sizeof (PinosMessageNodeUpdate)); if (nu->props) nu->props = pinos_serialize_props_deserialize (conn->in.data, SPA_PTR_TO_INT (nu->props)); } static void -connection_parse_port_update (PinosConnection *conn, PinosControlCmdPortUpdate *pu) +connection_parse_port_update (PinosConnection *conn, PinosMessagePortUpdate *pu) { void *p; unsigned int i; - memcpy (pu, conn->in.data, sizeof (PinosControlCmdPortUpdate)); + memcpy (pu, conn->in.data, sizeof (PinosMessagePortUpdate)); p = conn->in.data; @@ -115,47 +116,47 @@ connection_parse_port_update (PinosConnection *conn, PinosControlCmdPortUpdate * } static void -connection_parse_set_format (PinosConnection *conn, PinosControlCmdSetFormat *cmd) +connection_parse_set_format (PinosConnection *conn, PinosMessageSetFormat *cmd) { - memcpy (cmd, conn->in.data, sizeof (PinosControlCmdSetFormat)); + memcpy (cmd, conn->in.data, sizeof (PinosMessageSetFormat)); if (cmd->format) cmd->format = pinos_serialize_format_deserialize (conn->in.data, SPA_PTR_TO_INT (cmd->format)); } static void -connection_parse_use_buffers (PinosConnection *conn, PinosControlCmdUseBuffers *cmd) +connection_parse_use_buffers (PinosConnection *conn, PinosMessageUseBuffers *cmd) { void *p; p = conn->in.data; - memcpy (cmd, p, sizeof (PinosControlCmdUseBuffers)); + memcpy (cmd, p, sizeof (PinosMessageUseBuffers)); if (cmd->buffers) - cmd->buffers = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->buffers), PinosControlMemRef); + cmd->buffers = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->buffers), PinosMessageMemRef); } static void -connection_parse_node_event (PinosConnection *conn, PinosControlCmdNodeEvent *cmd) +connection_parse_node_event (PinosConnection *conn, PinosMessageNodeEvent *cmd) { void *p = conn->in.data; - memcpy (cmd, p, sizeof (PinosControlCmdNodeEvent)); + memcpy (cmd, p, sizeof (PinosMessageNodeEvent)); if (cmd->event) cmd->event = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->event), SpaNodeEvent); } static void -connection_parse_node_command (PinosConnection *conn, PinosControlCmdNodeCommand *cmd) +connection_parse_node_command (PinosConnection *conn, PinosMessageNodeCommand *cmd) { void *p = conn->in.data; - memcpy (cmd, p, sizeof (PinosControlCmdNodeCommand)); + memcpy (cmd, p, sizeof (PinosMessageNodeCommand)); if (cmd->command) cmd->command = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->command), SpaNodeCommand); } static void -connection_parse_port_command (PinosConnection *conn, PinosControlCmdPortCommand *cmd) +connection_parse_port_command (PinosConnection *conn, PinosMessagePortCommand *cmd) { void *p = conn->in.data; - memcpy (cmd, p, sizeof (PinosControlCmdPortCommand)); + memcpy (cmd, p, sizeof (PinosMessagePortCommand)); if (cmd->command) cmd->command = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->command), SpaNodeCommand); } @@ -165,14 +166,14 @@ connection_ensure_size (PinosConnection *conn, ConnectionBuffer *buf, size_t siz { if (buf->buffer_size + size > buf->buffer_maxsize) { buf->buffer_maxsize = buf->buffer_size + MAX_BUFFER_SIZE * ((size + MAX_BUFFER_SIZE-1) / MAX_BUFFER_SIZE); - g_debug ("connection %p: resize buffer to %zd", conn, buf->buffer_maxsize); + pinos_log_warn ("connection %p: resize buffer to %zd", conn, buf->buffer_maxsize); buf->buffer_data = realloc (buf->buffer_data, buf->buffer_maxsize); } return (uint8_t *) buf->buffer_data + buf->buffer_size; } static void * -connection_add_cmd (PinosConnection *conn, PinosControlCmd cmd, size_t size) +connection_add_message (PinosConnection *conn, PinosMessageType type, size_t size) { uint8_t *p; unsigned int plen; @@ -185,11 +186,11 @@ connection_add_cmd (PinosConnection *conn, PinosControlCmd cmd, size_t size) /* 1 for cmd, plen for size and size for payload */ p = connection_ensure_size (conn, buf, 1 + plen + size); - buf->cmd = cmd; + buf->type = type; buf->offset = buf->buffer_size; buf->buffer_size += 1 + plen + size; - *p++ = cmd; + *p++ = type; /* write length */ while (plen) { plen--; @@ -199,21 +200,21 @@ connection_add_cmd (PinosConnection *conn, PinosControlCmd cmd, size_t size) } static void -connection_add_node_update (PinosConnection *conn, PinosControlCmdNodeUpdate *nu) +connection_add_node_update (PinosConnection *conn, PinosMessageNodeUpdate *nu) { size_t len; void *p; - PinosControlCmdNodeUpdate *d; + PinosMessageNodeUpdate *d; /* calc len */ - len = sizeof (PinosControlCmdNodeUpdate); + len = sizeof (PinosMessageNodeUpdate); len += pinos_serialize_props_get_size (nu->props); - p = connection_add_cmd (conn, PINOS_CONTROL_CMD_NODE_UPDATE, len); - memcpy (p, nu, sizeof (PinosControlCmdNodeUpdate)); + p = connection_add_message (conn, PINOS_MESSAGE_NODE_UPDATE, len); + memcpy (p, nu, sizeof (PinosMessageNodeUpdate)); d = p; - p = SPA_MEMBER (d, sizeof (PinosControlCmdNodeUpdate), void); + p = SPA_MEMBER (d, sizeof (PinosMessageNodeUpdate), void); if (nu->props) { len = pinos_serialize_props_serialize (p, nu->props); d->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); @@ -223,16 +224,16 @@ connection_add_node_update (PinosConnection *conn, PinosControlCmdNodeUpdate *nu } static void -connection_add_port_update (PinosConnection *conn, PinosControlCmdPortUpdate *pu) +connection_add_port_update (PinosConnection *conn, PinosMessagePortUpdate *pu) { size_t len; void *p; int i; SpaFormat **bfa; - PinosControlCmdPortUpdate *d; + PinosMessagePortUpdate *d; /* calc len */ - len = sizeof (PinosControlCmdPortUpdate); + len = sizeof (PinosMessagePortUpdate); len += pu->n_possible_formats * sizeof (SpaFormat *); for (i = 0; i < pu->n_possible_formats; i++) { len += pinos_serialize_format_get_size (pu->possible_formats[i]); @@ -242,11 +243,11 @@ connection_add_port_update (PinosConnection *conn, PinosControlCmdPortUpdate *pu if (pu->info) len += pinos_serialize_port_info_get_size (pu->info); - p = connection_add_cmd (conn, PINOS_CONTROL_CMD_PORT_UPDATE, len); - memcpy (p, pu, sizeof (PinosControlCmdPortUpdate)); + p = connection_add_message (conn, PINOS_MESSAGE_PORT_UPDATE, len); + memcpy (p, pu, sizeof (PinosMessagePortUpdate)); d = p; - p = SPA_MEMBER (d, sizeof (PinosControlCmdPortUpdate), void); + p = SPA_MEMBER (d, sizeof (PinosMessagePortUpdate), void); bfa = p; if (pu->n_possible_formats) d->possible_formats = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); @@ -284,19 +285,19 @@ connection_add_port_update (PinosConnection *conn, PinosControlCmdPortUpdate *pu } static void -connection_add_set_format (PinosConnection *conn, PinosControlCmdSetFormat *sf) +connection_add_set_format (PinosConnection *conn, PinosMessageSetFormat *sf) { size_t len; void *p; /* calculate length */ /* port_id + format + mask */ - len = sizeof (PinosControlCmdSetFormat) + pinos_serialize_format_get_size (sf->format); - p = connection_add_cmd (conn, PINOS_CONTROL_CMD_SET_FORMAT, len); - memcpy (p, sf, sizeof (PinosControlCmdSetFormat)); + len = sizeof (PinosMessageSetFormat) + pinos_serialize_format_get_size (sf->format); + p = connection_add_message (conn, PINOS_MESSAGE_SET_FORMAT, len); + memcpy (p, sf, sizeof (PinosMessageSetFormat)); sf = p; - p = SPA_MEMBER (sf, sizeof (PinosControlCmdSetFormat), void); + p = SPA_MEMBER (sf, sizeof (PinosMessageSetFormat), void); if (sf->format) { len = pinos_serialize_format_serialize (p, sf->format); sf->format = SPA_INT_TO_PTR (SPA_PTRDIFF (p, sf)); @@ -305,21 +306,21 @@ connection_add_set_format (PinosConnection *conn, PinosControlCmdSetFormat *sf) } static void -connection_add_use_buffers (PinosConnection *conn, PinosControlCmdUseBuffers *ub) +connection_add_use_buffers (PinosConnection *conn, PinosMessageUseBuffers *ub) { size_t len; int i; - PinosControlCmdUseBuffers *d; - PinosControlMemRef *mr; + PinosMessageUseBuffers *d; + PinosMessageMemRef *mr; /* calculate length */ - len = sizeof (PinosControlCmdUseBuffers); - len += ub->n_buffers * sizeof (PinosControlMemRef); + len = sizeof (PinosMessageUseBuffers); + len += ub->n_buffers * sizeof (PinosMessageMemRef); - d = connection_add_cmd (conn, PINOS_CONTROL_CMD_USE_BUFFERS, len); - memcpy (d, ub, sizeof (PinosControlCmdUseBuffers)); + d = connection_add_message (conn, PINOS_MESSAGE_USE_BUFFERS, len); + memcpy (d, ub, sizeof (PinosMessageUseBuffers)); - mr = SPA_MEMBER (d, sizeof (PinosControlCmdUseBuffers), void); + mr = SPA_MEMBER (d, sizeof (PinosMessageUseBuffers), void); if (d->n_buffers) d->buffers = SPA_INT_TO_PTR (SPA_PTRDIFF (mr, d)); @@ -327,73 +328,73 @@ connection_add_use_buffers (PinosConnection *conn, PinosControlCmdUseBuffers *ub d->buffers = 0; for (i = 0; i < ub->n_buffers; i++) - memcpy (&mr[i], &ub->buffers[i], sizeof (PinosControlMemRef)); + memcpy (&mr[i], &ub->buffers[i], sizeof (PinosMessageMemRef)); } static void -connection_add_node_event (PinosConnection *conn, PinosControlCmdNodeEvent *ev) +connection_add_node_event (PinosConnection *conn, PinosMessageNodeEvent *ev) { size_t len; void *p; - PinosControlCmdNodeEvent *d; + PinosMessageNodeEvent *d; /* calculate length */ - len = sizeof (PinosControlCmdNodeEvent); + len = sizeof (PinosMessageNodeEvent); len += ev->event->size; - p = connection_add_cmd (conn, PINOS_CONTROL_CMD_NODE_EVENT, len); - memcpy (p, ev, sizeof (PinosControlCmdNodeEvent)); + p = connection_add_message (conn, PINOS_MESSAGE_NODE_EVENT, len); + memcpy (p, ev, sizeof (PinosMessageNodeEvent)); d = p; - p = SPA_MEMBER (d, sizeof (PinosControlCmdNodeEvent), void); + p = SPA_MEMBER (d, sizeof (PinosMessageNodeEvent), void); d->event = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); memcpy (p, ev->event, ev->event->size); } static void -connection_add_node_command (PinosConnection *conn, PinosControlCmdNodeCommand *cm) +connection_add_node_command (PinosConnection *conn, PinosMessageNodeCommand *cm) { size_t len; void *p; - PinosControlCmdNodeCommand *d; + PinosMessageNodeCommand *d; /* calculate length */ - len = sizeof (PinosControlCmdNodeCommand); + len = sizeof (PinosMessageNodeCommand); len += cm->command->size; - p = connection_add_cmd (conn, PINOS_CONTROL_CMD_NODE_COMMAND, len); - memcpy (p, cm, sizeof (PinosControlCmdNodeCommand)); + p = connection_add_message (conn, PINOS_MESSAGE_NODE_COMMAND, len); + memcpy (p, cm, sizeof (PinosMessageNodeCommand)); d = p; - p = SPA_MEMBER (d, sizeof (PinosControlCmdNodeCommand), void); + p = SPA_MEMBER (d, sizeof (PinosMessageNodeCommand), void); d->command = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); memcpy (p, cm->command, cm->command->size); } static void -connection_add_port_command (PinosConnection *conn, PinosControlCmdPortCommand *cm) +connection_add_port_command (PinosConnection *conn, PinosMessagePortCommand *cm) { size_t len; void *p; - PinosControlCmdPortCommand *d; + PinosMessagePortCommand *d; /* calculate length */ - len = sizeof (PinosControlCmdPortCommand); + len = sizeof (PinosMessagePortCommand); len += cm->command->size; - p = connection_add_cmd (conn, PINOS_CONTROL_CMD_PORT_COMMAND, len); - memcpy (p, cm, sizeof (PinosControlCmdPortCommand)); + p = connection_add_message (conn, PINOS_MESSAGE_PORT_COMMAND, len); + memcpy (p, cm, sizeof (PinosMessagePortCommand)); d = p; - p = SPA_MEMBER (d, sizeof (PinosControlCmdPortCommand), void); + p = SPA_MEMBER (d, sizeof (PinosMessagePortCommand), void); d->command = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); memcpy (p, cm->command, cm->command->size); } -static gboolean +static bool refill_buffer (PinosConnection *conn, ConnectionBuffer *buf) { ssize_t len; @@ -422,7 +423,7 @@ refill_buffer (PinosConnection *conn, ConnectionBuffer *buf) } if (len < 4) - return FALSE; + return false; buf->buffer_size += len; @@ -434,15 +435,15 @@ refill_buffer (PinosConnection *conn, ConnectionBuffer *buf) buf->n_fds = (cmsg->cmsg_len - ((char *)CMSG_DATA (cmsg) - (char *)cmsg)) / sizeof (int); memcpy (buf->fds, CMSG_DATA (cmsg), buf->n_fds * sizeof (int)); } - PINOS_DEBUG_CONTROL ("connection %p: %d read %zd bytes and %d fds", conn, conn->fd, len, buf->n_fds); + PINOS_DEBUG_MESSAGE ("connection %p: %d read %zd bytes and %d fds", conn, conn->fd, len, buf->n_fds); - return TRUE; + return true; /* ERRORS */ recv_error: { - g_warning ("could not recvmsg on fd %d: %s", conn->fd, strerror (errno)); - return FALSE; + pinos_log_error ("could not recvmsg on fd %d: %s", conn->fd, strerror (errno)); + return false; } } @@ -458,7 +459,7 @@ clear_buffer (ConnectionBuffer *buf) } } buf->n_fds = 0; - buf->cmd = PINOS_CONTROL_CMD_INVALID; + buf->type = PINOS_MESSAGE_INVALID; buf->offset = 0; buf->size = 0; buf->buffer_size = 0; @@ -494,16 +495,16 @@ pinos_connection_free (PinosConnection *conn) * * Move to the next packet in @conn. * - * Returns: %TRUE if more packets are available. + * Returns: %true if more packets are available. */ -gboolean +bool pinos_connection_has_next (PinosConnection *conn) { size_t len, size, skip; uint8_t *data; ConnectionBuffer *buf; - g_return_val_if_fail (conn != NULL, FALSE); + spa_return_val_if_fail (conn != NULL, false); buf = &conn->in; @@ -523,13 +524,13 @@ again: if (buf->offset >= size) { clear_buffer (buf); buf->update = true; - return FALSE; + return false; } data += buf->offset; size -= buf->offset; - buf->cmd = *data; + buf->type = *data; data++; size--; @@ -542,97 +543,97 @@ again: buf->data = data + skip; buf->offset += 1 + skip; - return TRUE; + return true; } -PinosControlCmd -pinos_connection_get_cmd (PinosConnection *conn) +PinosMessageType +pinos_connection_get_type (PinosConnection *conn) { - g_return_val_if_fail (conn != NULL, PINOS_CONTROL_CMD_INVALID); + spa_return_val_if_fail (conn != NULL, PINOS_MESSAGE_INVALID); - return conn->in.cmd; + return conn->in.type; } -gboolean -pinos_connection_parse_cmd (PinosConnection *conn, - gpointer command) +bool +pinos_connection_parse_message (PinosConnection *conn, + void *message) { - g_return_val_if_fail (conn != NULL, FALSE); + spa_return_val_if_fail (conn != NULL, false); - switch (conn->in.cmd) { + switch (conn->in.type) { /* C -> S */ - case PINOS_CONTROL_CMD_NODE_UPDATE: - connection_parse_node_update (conn, command); + case PINOS_MESSAGE_NODE_UPDATE: + connection_parse_node_update (conn, message); break; - case PINOS_CONTROL_CMD_PORT_UPDATE: - connection_parse_port_update (conn, command); + case PINOS_MESSAGE_PORT_UPDATE: + connection_parse_port_update (conn, message); break; - case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: - g_warning ("implement iter of %d", conn->in.cmd); + case PINOS_MESSAGE_PORT_STATUS_CHANGE: + pinos_log_warn ("implement iter of %d", conn->in.type); break; - case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: - if (conn->in.size < sizeof (PinosControlCmdNodeStateChange)) - return FALSE; - memcpy (command, conn->in.data, sizeof (PinosControlCmdNodeStateChange)); + case PINOS_MESSAGE_NODE_STATE_CHANGE: + if (conn->in.size < sizeof (PinosMessageNodeStateChange)) + return false; + memcpy (message, conn->in.data, sizeof (PinosMessageNodeStateChange)); break; /* S -> C */ - case PINOS_CONTROL_CMD_ADD_PORT: - if (conn->in.size < sizeof (PinosControlCmdAddPort)) - return FALSE; - memcpy (command, conn->in.data, sizeof (PinosControlCmdAddPort)); + case PINOS_MESSAGE_ADD_PORT: + if (conn->in.size < sizeof (PinosMessageAddPort)) + return false; + memcpy (message, conn->in.data, sizeof (PinosMessageAddPort)); break; - case PINOS_CONTROL_CMD_REMOVE_PORT: - if (conn->in.size < sizeof (PinosControlCmdRemovePort)) - return FALSE; - memcpy (command, conn->in.data, sizeof (PinosControlCmdRemovePort)); + case PINOS_MESSAGE_REMOVE_PORT: + if (conn->in.size < sizeof (PinosMessageRemovePort)) + return false; + memcpy (message, conn->in.data, sizeof (PinosMessageRemovePort)); break; - case PINOS_CONTROL_CMD_SET_FORMAT: - connection_parse_set_format (conn, command); + case PINOS_MESSAGE_SET_FORMAT: + connection_parse_set_format (conn, message); break; - case PINOS_CONTROL_CMD_SET_PROPERTY: - g_warning ("implement iter of %d", conn->in.cmd); + case PINOS_MESSAGE_SET_PROPERTY: + pinos_log_warn ("implement iter of %d", conn->in.type); break; /* bidirectional */ - case PINOS_CONTROL_CMD_ADD_MEM: - if (conn->in.size < sizeof (PinosControlCmdAddMem)) - return FALSE; - memcpy (command, conn->in.data, sizeof (PinosControlCmdAddMem)); + case PINOS_MESSAGE_ADD_MEM: + if (conn->in.size < sizeof (PinosMessageAddMem)) + return false; + memcpy (message, conn->in.data, sizeof (PinosMessageAddMem)); break; - case PINOS_CONTROL_CMD_USE_BUFFERS: - connection_parse_use_buffers (conn, command); + case PINOS_MESSAGE_USE_BUFFERS: + connection_parse_use_buffers (conn, message); break; - case PINOS_CONTROL_CMD_PROCESS_BUFFER: - if (conn->in.size < sizeof (PinosControlCmdProcessBuffer)) - return FALSE; - memcpy (command, conn->in.data, sizeof (PinosControlCmdProcessBuffer)); + case PINOS_MESSAGE_PROCESS_BUFFER: + if (conn->in.size < sizeof (PinosMessageProcessBuffer)) + return false; + memcpy (message, conn->in.data, sizeof (PinosMessageProcessBuffer)); break; - case PINOS_CONTROL_CMD_NODE_EVENT: - connection_parse_node_event (conn, command); + case PINOS_MESSAGE_NODE_EVENT: + connection_parse_node_event (conn, message); break; - case PINOS_CONTROL_CMD_NODE_COMMAND: - connection_parse_node_command (conn, command); + case PINOS_MESSAGE_NODE_COMMAND: + connection_parse_node_command (conn, message); break; - case PINOS_CONTROL_CMD_PORT_COMMAND: - connection_parse_port_command (conn, command); + case PINOS_MESSAGE_PORT_COMMAND: + connection_parse_port_command (conn, message); break; - case PINOS_CONTROL_CMD_INVALID: - return FALSE; + case PINOS_MESSAGE_INVALID: + return false; } - return TRUE; + return true; } /** @@ -648,13 +649,13 @@ pinos_connection_parse_cmd (PinosConnection *conn, */ int pinos_connection_get_fd (PinosConnection *conn, - guint index, - gboolean close) + unsigned int index, + bool close) { int fd; - g_return_val_if_fail (conn != NULL, -1); - g_return_val_if_fail (index < conn->in.n_fds, -1); + spa_return_val_if_fail (conn != NULL, -1); + spa_return_val_if_fail (index < conn->in.n_fds, -1); fd = conn->in.fds[index]; if (fd < 0) @@ -677,11 +678,11 @@ pinos_connection_get_fd (PinosConnection *conn, int pinos_connection_add_fd (PinosConnection *conn, int fd, - gboolean close) + bool close) { int index, i; - g_return_val_if_fail (conn != NULL, -1); + spa_return_val_if_fail (conn != NULL, -1); for (i = 0; i < conn->out.n_fds; i++) { if (conn->out.fds[i] == fd || conn->out.fds[i] == -fd) @@ -696,97 +697,97 @@ pinos_connection_add_fd (PinosConnection *conn, } /** - * pinos_connection_add_cmd: + * pinos_connection_add_message: * @conn: a #PinosConnection - * @cmd: a #PinosControlCmd - * @command: a command + * @type: a #PinosMessageType + * @message: a message * - * Add a @cmd to @conn with data from @command. + * Add a @cmd to @conn with data from @message. * - * Returns: %TRUE on success. + * Returns: %true on success. */ -gboolean -pinos_connection_add_cmd (PinosConnection *conn, - PinosControlCmd cmd, - gpointer command) +bool +pinos_connection_add_message (PinosConnection *conn, + PinosMessageType type, + void *message) { void *p; - g_return_val_if_fail (conn != NULL, FALSE); - g_return_val_if_fail (command != NULL, FALSE); + spa_return_val_if_fail (conn != NULL, false); + spa_return_val_if_fail (message != NULL, false); - switch (cmd) { + switch (type) { /* C -> S */ - case PINOS_CONTROL_CMD_NODE_UPDATE: - connection_add_node_update (conn, command); + case PINOS_MESSAGE_NODE_UPDATE: + connection_add_node_update (conn, message); break; - case PINOS_CONTROL_CMD_PORT_UPDATE: - connection_add_port_update (conn, command); + case PINOS_MESSAGE_PORT_UPDATE: + connection_add_port_update (conn, message); break; - case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: - p = connection_add_cmd (conn, cmd, 0); + case PINOS_MESSAGE_PORT_STATUS_CHANGE: + p = connection_add_message (conn, type, 0); break; - case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: - p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdNodeStateChange)); - memcpy (p, command, sizeof (PinosControlCmdNodeStateChange)); + case PINOS_MESSAGE_NODE_STATE_CHANGE: + p = connection_add_message (conn, type, sizeof (PinosMessageNodeStateChange)); + memcpy (p, message, sizeof (PinosMessageNodeStateChange)); break; /* S -> C */ - case PINOS_CONTROL_CMD_ADD_PORT: - p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdAddPort)); - memcpy (p, command, sizeof (PinosControlCmdAddPort)); + case PINOS_MESSAGE_ADD_PORT: + p = connection_add_message (conn, type, sizeof (PinosMessageAddPort)); + memcpy (p, message, sizeof (PinosMessageAddPort)); break; - case PINOS_CONTROL_CMD_REMOVE_PORT: - p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdRemovePort)); - memcpy (p, command, sizeof (PinosControlCmdRemovePort)); + case PINOS_MESSAGE_REMOVE_PORT: + p = connection_add_message (conn, type, sizeof (PinosMessageRemovePort)); + memcpy (p, message, sizeof (PinosMessageRemovePort)); break; - case PINOS_CONTROL_CMD_SET_FORMAT: - connection_add_set_format (conn, command); + case PINOS_MESSAGE_SET_FORMAT: + connection_add_set_format (conn, message); break; - case PINOS_CONTROL_CMD_SET_PROPERTY: - g_warning ("implement builder of %d", cmd); + case PINOS_MESSAGE_SET_PROPERTY: + pinos_log_warn ("implement builder of %d", type); break; /* bidirectional */ - case PINOS_CONTROL_CMD_ADD_MEM: - p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdAddMem)); - memcpy (p, command, sizeof (PinosControlCmdAddMem)); + case PINOS_MESSAGE_ADD_MEM: + p = connection_add_message (conn, type, sizeof (PinosMessageAddMem)); + memcpy (p, message, sizeof (PinosMessageAddMem)); break; - case PINOS_CONTROL_CMD_USE_BUFFERS: - connection_add_use_buffers (conn, command); + case PINOS_MESSAGE_USE_BUFFERS: + connection_add_use_buffers (conn, message); break; - case PINOS_CONTROL_CMD_PROCESS_BUFFER: - p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdProcessBuffer)); - memcpy (p, command, sizeof (PinosControlCmdProcessBuffer)); + case PINOS_MESSAGE_PROCESS_BUFFER: + p = connection_add_message (conn, type, sizeof (PinosMessageProcessBuffer)); + memcpy (p, message, sizeof (PinosMessageProcessBuffer)); break; - case PINOS_CONTROL_CMD_NODE_EVENT: - connection_add_node_event (conn, command); + case PINOS_MESSAGE_NODE_EVENT: + connection_add_node_event (conn, message); break; - case PINOS_CONTROL_CMD_NODE_COMMAND: - connection_add_node_command (conn, command); + case PINOS_MESSAGE_NODE_COMMAND: + connection_add_node_command (conn, message); break; - case PINOS_CONTROL_CMD_PORT_COMMAND: - connection_add_port_command (conn, command); + case PINOS_MESSAGE_PORT_COMMAND: + connection_add_port_command (conn, message); break; - case PINOS_CONTROL_CMD_INVALID: - return FALSE; + case PINOS_MESSAGE_INVALID: + return false; } - return TRUE; + return true; } -gboolean +bool pinos_connection_flush (PinosConnection *conn) { ssize_t len; @@ -797,12 +798,12 @@ pinos_connection_flush (PinosConnection *conn) int *cm, i, fds_len; ConnectionBuffer *buf; - g_return_val_if_fail (conn != NULL, FALSE); + spa_return_val_if_fail (conn != NULL, false); buf = &conn->out; if (buf->buffer_size == 0) - return TRUE; + return true; fds_len = buf->n_fds * sizeof (int); @@ -840,26 +841,26 @@ pinos_connection_flush (PinosConnection *conn) buf->buffer_size -= len; buf->n_fds = 0; - PINOS_DEBUG_CONTROL ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds); + PINOS_DEBUG_MESSAGE ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds); - return TRUE; + return true; /* ERRORS */ send_error: { - g_warning ("could not sendmsg: %s", strerror (errno)); - return FALSE; + pinos_log_error ("could not sendmsg: %s", strerror (errno)); + return false; } } -gboolean +bool pinos_connection_clear (PinosConnection *conn) { - g_return_val_if_fail (conn != NULL, FALSE); + spa_return_val_if_fail (conn != NULL, false); clear_buffer (&conn->out); clear_buffer (&conn->in); conn->in.update = true; - return TRUE; + return true; } diff --git a/pinos/client/connection.h b/pinos/client/connection.h index 6517ace8..e46eb283 100644 --- a/pinos/client/connection.h +++ b/pinos/client/connection.h @@ -17,12 +17,12 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_CONTROL_H__ -#define __PINOS_CONTROL_H__ +#ifndef __PINOS_CONNECTION_H__ +#define __PINOS_CONNECTION_H__ -#include <glib-object.h> - -G_BEGIN_DECLS +#ifdef __cplusplus +extern "C" { +#endif #include <spa/defs.h> #include <spa/props.h> @@ -33,113 +33,116 @@ G_BEGIN_DECLS typedef struct _PinosConnection PinosConnection; typedef enum { - PINOS_CONTROL_CMD_INVALID = 0, + PINOS_MESSAGE_INVALID = 0, /* client to server */ - PINOS_CONTROL_CMD_NODE_UPDATE = 1, - PINOS_CONTROL_CMD_PORT_UPDATE = 2, - PINOS_CONTROL_CMD_NODE_STATE_CHANGE = 3, + PINOS_MESSAGE_NODE_UPDATE = 1, + PINOS_MESSAGE_PORT_UPDATE = 2, + PINOS_MESSAGE_NODE_STATE_CHANGE = 3, - PINOS_CONTROL_CMD_PORT_STATUS_CHANGE = 4, + PINOS_MESSAGE_PORT_STATUS_CHANGE = 4, + PINOS_MESSAGE_NODE_EVENT = 5, /* server to client */ - PINOS_CONTROL_CMD_ADD_PORT = 32, - PINOS_CONTROL_CMD_REMOVE_PORT = 33, + PINOS_MESSAGE_ADD_PORT = 32, + PINOS_MESSAGE_REMOVE_PORT = 33, - PINOS_CONTROL_CMD_SET_FORMAT = 34, - PINOS_CONTROL_CMD_SET_PROPERTY = 35, + PINOS_MESSAGE_SET_FORMAT = 34, + PINOS_MESSAGE_SET_PROPERTY = 35, - PINOS_CONTROL_CMD_NODE_COMMAND = 36, - PINOS_CONTROL_CMD_PORT_COMMAND = 37, + PINOS_MESSAGE_NODE_COMMAND = 36, + PINOS_MESSAGE_PORT_COMMAND = 37, /* both */ - PINOS_CONTROL_CMD_ADD_MEM = 64, - PINOS_CONTROL_CMD_USE_BUFFERS = 66, - PINOS_CONTROL_CMD_PROCESS_BUFFER = 67, + PINOS_MESSAGE_ADD_MEM = 64, + PINOS_MESSAGE_USE_BUFFERS = 66, + PINOS_MESSAGE_PROCESS_BUFFER = 67, - PINOS_CONTROL_CMD_NODE_EVENT = 68, -} PinosControlCmd; +} PinosMessageType; -/* PINOS_CONTROL_CMD_NODE_UPDATE */ +/* PINOS_MESSAGE_NODE_UPDATE */ typedef struct { -#define PINOS_CONTROL_CMD_NODE_UPDATE_MAX_INPUTS (1 << 0) -#define PINOS_CONTROL_CMD_NODE_UPDATE_MAX_OUTPUTS (1 << 1) -#define PINOS_CONTROL_CMD_NODE_UPDATE_PROPS (1 << 2) +#define PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS (1 << 0) +#define PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS (1 << 1) +#define PINOS_MESSAGE_NODE_UPDATE_PROPS (1 << 2) uint32_t change_mask; unsigned int max_input_ports; unsigned int max_output_ports; const SpaProps *props; -} PinosControlCmdNodeUpdate; +} PinosMessageNodeUpdate; -/* PINOS_CONTROL_CMD_PORT_UPDATE */ +/* PINOS_MESSAGE_PORT_UPDATE */ typedef struct { SpaDirection direction; uint32_t port_id; -#define PINOS_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS (1 << 0) -#define PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT (1 << 1) -#define PINOS_CONTROL_CMD_PORT_UPDATE_PROPS (1 << 2) -#define PINOS_CONTROL_CMD_PORT_UPDATE_INFO (1 << 3) +#define PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS (1 << 0) +#define PINOS_MESSAGE_PORT_UPDATE_FORMAT (1 << 1) +#define PINOS_MESSAGE_PORT_UPDATE_PROPS (1 << 2) +#define PINOS_MESSAGE_PORT_UPDATE_INFO (1 << 3) uint32_t change_mask; unsigned int n_possible_formats; SpaFormat **possible_formats; SpaFormat *format; const SpaProps *props; const SpaPortInfo *info; -} PinosControlCmdPortUpdate; - -/* PINOS_CONTROL_CMD_PORT_STATUS_CHANGE */ +} PinosMessagePortUpdate; -/* PINOS_CONTROL_CMD_NODE_STATE_CHANGE */ +/* PINOS_MESSAGE_NODE_STATE_CHANGE */ typedef struct { SpaNodeState state; -} PinosControlCmdNodeStateChange; +} PinosMessageNodeStateChange; + +/* PINOS_MESSAGE_PORT_STATUS_CHANGE */ + +/* PINOS_MESSAGE_NODE_EVENT */ +typedef struct { + SpaNodeEvent *event; +} PinosMessageNodeEvent; -/* PINOS_CONTROL_CMD_ADD_PORT */ +/* PINOS_MESSAGE_ADD_PORT */ typedef struct { uint32_t seq; SpaDirection direction; uint32_t port_id; -} PinosControlCmdAddPort; +} PinosMessageAddPort; -/* PINOS_CONTROL_CMD_REMOVE_PORT */ +/* PINOS_MESSAGE_REMOVE_PORT */ typedef struct { uint32_t seq; SpaDirection direction; uint32_t port_id; -} PinosControlCmdRemovePort; +} PinosMessageRemovePort; -/* PINOS_CONTROL_CMD_SET_FORMAT */ +/* PINOS_MESSAGE_SET_FORMAT */ typedef struct { uint32_t seq; SpaDirection direction; uint32_t port_id; SpaPortFormatFlags flags; SpaFormat *format; -} PinosControlCmdSetFormat; +} PinosMessageSetFormat; -/* PINOS_CONTROL_CMD_SET_PROPERTY */ +/* PINOS_MESSAGE_SET_PROPERTY */ typedef struct { uint32_t seq; - SpaDirection direction; - uint32_t port_id; uint32_t id; size_t size; void *value; -} PinosControlCmdSetProperty; +} PinosMessageSetProperty; -/* PINOS_CONTROL_CMD_NODE_COMMAND */ +/* PINOS_MESSAGE_NODE_COMMAND */ typedef struct { uint32_t seq; SpaNodeCommand *command; -} PinosControlCmdNodeCommand; +} PinosMessageNodeCommand; -/* PINOS_CONTROL_CMD_PORT_COMMAND */ +/* PINOS_MESSAGE_PORT_COMMAND */ typedef struct { uint32_t port_id; SpaNodeCommand *command; -} PinosControlCmdPortCommand; +} PinosMessagePortCommand; -/* PINOS_CONTROL_CMD_ADD_MEM */ +/* PINOS_MESSAGE_ADD_MEM */ typedef struct { SpaDirection direction; uint32_t port_id; @@ -149,57 +152,53 @@ typedef struct { uint32_t flags; off_t offset; size_t size; -} PinosControlCmdAddMem; +} PinosMessageAddMem; typedef struct { uint32_t mem_id; off_t offset; size_t size; -} PinosControlMemRef; +} PinosMessageMemRef; -/* PINOS_CONTROL_CMD_USE_BUFFERS */ +/* PINOS_MESSAGE_USE_BUFFERS */ typedef struct { uint32_t seq; SpaDirection direction; uint32_t port_id; unsigned int n_buffers; - PinosControlMemRef *buffers; -} PinosControlCmdUseBuffers; + PinosMessageMemRef *buffers; +} PinosMessageUseBuffers; -/* PINOS_CONTROL_CMD_PROCESS_BUFFER */ +/* PINOS_MESSAGE_PROCESS_BUFFER */ typedef struct { SpaDirection direction; uint32_t port_id; uint32_t buffer_id; -} PinosControlCmdProcessBuffer; - -/* PINOS_CONTROL_CMD_NODE_EVENT */ -typedef struct { - SpaNodeEvent *event; -} PinosControlCmdNodeEvent; - +} PinosMessageProcessBuffer; PinosConnection * pinos_connection_new (int fd); void pinos_connection_free (PinosConnection *conn); -gboolean pinos_connection_has_next (PinosConnection *conn); -PinosControlCmd pinos_connection_get_cmd (PinosConnection *conn); -gboolean pinos_connection_parse_cmd (PinosConnection *conn, - gpointer command); +bool pinos_connection_has_next (PinosConnection *conn); +PinosMessageType pinos_connection_get_type (PinosConnection *conn); +bool pinos_connection_parse_message (PinosConnection *conn, + void *msg); int pinos_connection_get_fd (PinosConnection *conn, - guint index, - gboolean close); + unsigned int index, + bool close); int pinos_connection_add_fd (PinosConnection *conn, int fd, - gboolean close); -gboolean pinos_connection_add_cmd (PinosConnection *conn, - PinosControlCmd cmd, - gpointer command); + bool close); +bool pinos_connection_add_message (PinosConnection *conn, + PinosMessageType type, + void *msg); -gboolean pinos_connection_flush (PinosConnection *conn); -gboolean pinos_connection_clear (PinosConnection *conn); +bool pinos_connection_flush (PinosConnection *conn); +bool pinos_connection_clear (PinosConnection *conn); -G_END_DECLS +#ifdef __cplusplus +} /* extern "C" */ +#endif -#endif /* __PINOS_CONTROL_H__ */ +#endif /* __PINOS_CONNECTION_H__ */ diff --git a/pinos/client/context.c b/pinos/client/context.c index c8e95e91..1845b08b 100644 --- a/pinos/client/context.c +++ b/pinos/client/context.c @@ -137,7 +137,7 @@ pinos_context_finalize (GObject * object) PinosContext *context = PINOS_CONTEXT (object); PinosContextPrivate *priv = context->priv; - g_debug ("free context %p", context); + pinos_log_debug ("free context %p", context); if (priv->id) g_bus_unwatch_name(priv->id); @@ -277,7 +277,7 @@ pinos_context_init (PinosContext * context) { PinosContextPrivate *priv = context->priv = PINOS_CONTEXT_GET_PRIVATE (context); - g_debug ("new context %p", context); + pinos_log_debug ("new context %p", context); priv->state = PINOS_CONTEXT_STATE_UNCONNECTED; diff --git a/pinos/client/log.c b/pinos/client/log.c new file mode 100644 index 00000000..0982f8eb --- /dev/null +++ b/pinos/client/log.c @@ -0,0 +1,106 @@ +/* Pinos + * Copyright (C) 2015 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 <stdio.h> + +#include <pinos/client/log.h> + +static void +do_logv (SpaLog *log, + SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, + va_list args) +{ + char text[16*1024], location[128]; + static const char *levels[] = { + "-", + "E", + "W", + "I", + "D", + "T", + }; + vsnprintf (text, sizeof(text), fmt, args); + if (1) { + snprintf (location, sizeof(location), "%s:%i %s()", strrchr (file, '/')+1, line, func); + fprintf(stderr, "[%s][%s] %s\n", levels[level], location, text); + } else { + fprintf(stderr, "[%s] %s\n", levels[level], text); + } +} + +static void +do_log (SpaLog *log, + SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + do_logv (log, level, file, line, func, fmt, args); + va_end (args); +} + +static SpaLog log = { + sizeof (SpaLog), + NULL, + SPA_LOG_LEVEL_DEBUG, + do_log, + do_logv, +}; + +SpaLog * +pinos_log_get (void) +{ + return &log; +} + + +void +pinos_log_log (SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, ...) +{ + if (log.level >= level) { + va_list args; + va_start (args, fmt); + do_logv (&log, level, file, line, func, fmt, args); + va_end (args); + } +} + +void +pinos_log_logv (SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, + va_list args) +{ + if (log.level >= level) { + do_logv (&log, level, file, line, func, fmt, args); + } +} diff --git a/pinos/client/log.h b/pinos/client/log.h new file mode 100644 index 00000000..05c44aba --- /dev/null +++ b/pinos/client/log.h @@ -0,0 +1,74 @@ +/* Pinos + * Copyright (C) 2015 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. + */ + +#ifndef __PINOS_LOG_H__ +#define __PINOS_LOG_H__ + +#include <spa/log.h> + +#ifdef __cplusplus +extern "C" { +#endif + +SpaLog * pinos_log_get (void); + + +void pinos_log_log (SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, ...) SPA_PRINTF_FUNC(5, 6); +void pinos_log_logv (SpaLogLevel level, + const char *file, + int line, + const char *func, + const char *fmt, + va_list args) SPA_PRINTF_FUNC(5, 0); + +#if __STDC_VERSION__ >= 199901L + +#define pinos_log_error(...) pinos_log_log(SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__) +#define pinos_log_warn(...) pinos_log_log(SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__) +#define pinos_log_info(...) pinos_log_log(SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__) +#define pinos_log_debug(...) pinos_log_log(SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__) +#define pinos_log_trace(...) pinos_log_log(SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__) + +#else + +#define PINOS_LOG_FUNC(name,lev) \ +static inline void pinos_log_##name (const char *format, ...) \ +{ \ + va_list varargs; \ + va_start (varargs, format); \ + pinos_log_logv (lev,__FILE__,__LINE__,__func__,format,varargs); \ + va_end (varargs); \ +} +PINOS_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR) +PINOS_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN) +PINOS_LOG_FUNC(info, SPA_LOG_LEVEL_INFO) +PINOS_LOG_FUNC(debug, SPA_LOG_LEVEL_DEBUG) +PINOS_LOG_FUNC(trace, SPA_LOG_LEVEL_TRACE) + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __PINOS_LOG_H__ */ diff --git a/pinos/client/map.h b/pinos/client/map.h new file mode 100644 index 00000000..ffedd53f --- /dev/null +++ b/pinos/client/map.h @@ -0,0 +1,111 @@ +/* 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. + */ + +#ifndef __PINOS_MAP_H__ +#define __PINOS_MAP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _PinosMap PinosMap; + +#include <string.h> +#include <stdio.h> + +#include <spa/defs.h> +#include <pinos/client/array.h> +#include <pinos/client/log.h> + +typedef union { + uint32_t next; + void *data; +} PinosMapItem; + +struct _PinosMap { + PinosArray items; + uint32_t free_list; +}; + +#define pinos_map_get_size(m) pinos_array_get_len (&(m)->items, PinosMapItem) +#define pinos_map_get_item(m,id) pinos_array_get_unchecked(&(m)->items,id,PinosMapItem) +#define pinos_map_item_is_free(m,id) (pinos_map_get_item(m,id)->next & 0x1) +#define pinos_map_check_id(m,id) ((id) < pinos_map_get_size (m)) +#define pinos_map_has_item(m,id) (pinos_map_check_id(m,id) && !pinos_map_item_is_free(m, id)) +#define pinos_map_lookup_unchecked(m,id) pinos_map_get_item(m,id)->data + +static inline void +pinos_map_init (PinosMap *map, + size_t size) +{ + pinos_array_init (&map->items); + pinos_array_ensure_size (&map->items, size * sizeof (PinosMapItem)); + map->free_list = 0; +} + +static inline void +pinos_map_clear (PinosMap *map) +{ + pinos_array_clear (&map->items); +} + +static inline uint32_t +pinos_map_insert_new (PinosMap *map, + void *data) +{ + PinosMapItem *start, *item; + uint32_t id; + + if (map->free_list) { + start = map->items.data; + item = &start[map->free_list >> 1]; + map->free_list = item->next; + } else { + item = pinos_array_add (&map->items, sizeof (PinosMapItem)); + if (!item) + return SPA_ID_INVALID; + start = map->items.data; + } + item->data = data; + id = (item - start); + return id; +} + +static inline void +pinos_map_remove (PinosMap *map, + uint32_t id) +{ + pinos_map_get_item (map, id)->next = map->free_list; + map->free_list = (id << 1) | 1; +} + +static inline void * +pinos_map_lookup (PinosMap *map, + uint32_t id) +{ + if (SPA_LIKELY (pinos_map_check_id (map, id))) + return pinos_map_lookup_unchecked (map, id); + return NULL; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __PINOS_MAP_H__ */ diff --git a/pinos/client/mapper.c b/pinos/client/mapper.c new file mode 100644 index 00000000..f0cca32f --- /dev/null +++ b/pinos/client/mapper.c @@ -0,0 +1,74 @@ +/* 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/id-map.h> + +#include <pinos/client/map.h> + +#define MAX_URIS 4096 + +typedef struct { + SpaIDMap map; + PinosMap uris; +} IDMap; + +static uint32_t +id_map_get_id (SpaIDMap *map, const char *uri) +{ + IDMap *this = SPA_CONTAINER_OF (map, IDMap, map); + uint32_t i = 0; + + if (uri != NULL) { + for (i = 0; i < pinos_map_get_size (&this->uris); i++) { + if (strcmp (pinos_map_lookup_unchecked (&this->uris, i), uri) == 0) + return i; + } + i = pinos_map_insert_new (&this->uris, (char *)uri); + } + return i; +} + +static const char * +id_map_get_uri (SpaIDMap *map, uint32_t id) +{ + IDMap *this = SPA_CONTAINER_OF (map, IDMap, map); + if (id == SPA_ID_INVALID) + return NULL; + return pinos_map_lookup (&this->uris, id); +} + +static IDMap default_id_map = { + { sizeof (SpaIDMap), + NULL, + id_map_get_id, + id_map_get_uri, + }, + { { NULL, } }, +}; + +SpaIDMap * +pinos_id_map_get_default (void) +{ + return &default_id_map.map; +} diff --git a/pinos/client/meson.build b/pinos/client/meson.build index d6ed7a23..c78728b1 100644 --- a/pinos/client/meson.build +++ b/pinos/client/meson.build @@ -1,7 +1,10 @@ pinos_headers = [ + 'array.h', 'context.h', 'format.h', 'introspect.h', + 'log.h', + 'map.h', 'pinos.h', 'properties.h', 'ringbuffer.h', @@ -16,6 +19,8 @@ pinos_sources = [ 'context.c', 'format.c', 'introspect.c', + 'log.c', + 'mapper.c', 'properties.c', 'serialize.c', 'stream.c', diff --git a/pinos/client/pinos.h b/pinos/client/pinos.h index 47d4a8ad..a185d0d4 100644 --- a/pinos/client/pinos.h +++ b/pinos/client/pinos.h @@ -25,11 +25,13 @@ extern const char g_log_domain_pinos[]; #include <pinos/client/context.h> #include <pinos/client/enumtypes.h> #include <pinos/client/introspect.h> +#include <pinos/client/log.h> #include <pinos/client/thread-mainloop.h> #include <pinos/client/properties.h> #include <pinos/client/ringbuffer.h> #include <pinos/client/stream.h> #include <pinos/client/subscribe.h> +#include <spa/include/spa/id-map.h> #define PINOS_DBUS_SERVICE "org.pinos" #define PINOS_DBUS_OBJECT_PREFIX "/org/pinos" @@ -59,4 +61,6 @@ void pinos_fill_stream_properties (PinosProperties *properties); PinosDirection pinos_direction_reverse (PinosDirection direction); +SpaIDMap * pinos_id_map_get_default (void); + #endif /* __PINOS_H__ */ diff --git a/pinos/client/serialize.h b/pinos/client/serialize.h index 33057b6b..f1eaa4a7 100644 --- a/pinos/client/serialize.h +++ b/pinos/client/serialize.h @@ -20,9 +20,9 @@ #ifndef __PINOS_SERIALIZE_H__ #define __PINOS_SERIALIZE_H__ -#include <glib-object.h> - -G_BEGIN_DECLS +#ifdef __cplusplus +extern "C" { +#endif #include <spa/include/spa/buffer.h> #include <spa/include/spa/format.h> @@ -48,6 +48,8 @@ size_t pinos_serialize_props_serialize (void *dest, const SpaProp SpaProps * pinos_serialize_props_deserialize (void *src, off_t offset); SpaProps * pinos_serialize_props_copy_into (void *dest, const SpaProps *props); -G_END_DECLS +#ifdef __cplusplus +} +#endif #endif /* __PINOS_SERIALIZE_H__ */ diff --git a/pinos/client/stream.c b/pinos/client/stream.c index 57cc7429..af0863ae 100644 --- a/pinos/client/stream.c +++ b/pinos/client/stream.c @@ -22,7 +22,7 @@ #include <sys/mman.h> #include <errno.h> -#include "spa/include/spa/debug.h" +#include "spa/lib/debug.h" #include <gio/gio.h> #include <gio/gunixfdlist.h> @@ -50,7 +50,6 @@ typedef struct { uint32_t flags; void *ptr; size_t size; - bool cleanup; } MemId; typedef struct { @@ -100,8 +99,8 @@ struct _PinosStreamPrivate GSource *timeout_source; - GArray *mem_ids; - GArray *buffer_ids; + PinosArray mem_ids; + PinosArray buffer_ids; gboolean in_order; gint64 last_ticks; @@ -139,15 +138,13 @@ static void clear_buffers (PinosStream *stream) { PinosStreamPrivate *priv = stream->priv; - guint i; - - for (i = 0; i < priv->buffer_ids->len; i++) { - BufferId *bid = &g_array_index (priv->buffer_ids, BufferId, i); + BufferId *bid; + pinos_array_for_each (bid, &priv->buffer_ids) { g_signal_emit (stream, signals[SIGNAL_REMOVE_BUFFER], 0, bid->id); bid->buf = NULL; } - g_array_set_size (priv->buffer_ids, 0); + priv->buffer_ids.size = 0; priv->in_order = TRUE; } @@ -263,7 +260,7 @@ on_node_info (PinosContext *c, PinosStream *stream = PINOS_STREAM (user_data); if (info->state == PINOS_NODE_STATE_ERROR) { - g_debug ("stream %p: node %s in error", stream, info->node_path); + pinos_log_debug ("stream %p: node %s in error", stream, info->node_path); stream_set_state (stream, PINOS_STREAM_STATE_ERROR, g_error_new (PINOS_ERROR, @@ -278,7 +275,7 @@ info_ready (GObject *o, GAsyncResult *res, gpointer user_data) GError *error = NULL; if (!pinos_context_info_finish (o, res, &error)) { - g_printerr ("introspection failure: %s\n", error->message); + pinos_log_error ("introspection failure: %s\n", error->message); g_clear_error (&error); } } @@ -341,7 +338,7 @@ pinos_stream_finalize (GObject * object) PinosStream *stream = PINOS_STREAM (object); PinosStreamPrivate *priv = stream->priv; - g_debug ("free stream %p", stream); + pinos_log_debug ("free stream %p", stream); g_clear_object (&priv->node); @@ -353,6 +350,9 @@ pinos_stream_finalize (GObject * object) g_free (priv->path); g_clear_error (&priv->error); + pinos_array_clear (&priv->buffer_ids); + pinos_array_clear (&priv->mem_ids); + if (priv->properties) pinos_properties_free (priv->properties); g_signal_handler_disconnect (priv->context->priv->subscribe, priv->id); @@ -513,12 +513,14 @@ pinos_stream_init (PinosStream * stream) { PinosStreamPrivate *priv = stream->priv = PINOS_STREAM_GET_PRIVATE (stream); - g_debug ("new stream %p", stream); + pinos_log_debug ("new stream %p", 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); + pinos_array_init (&priv->mem_ids); + pinos_array_ensure_size (&priv->mem_ids, sizeof (MemId) * 64); + pinos_array_init (&priv->buffer_ids); + pinos_array_ensure_size (&priv->buffer_ids, sizeof (BufferId) * 64); priv->pending_seq = SPA_ID_INVALID; } @@ -614,26 +616,26 @@ static void add_node_update (PinosStream *stream, uint32_t change_mask) { PinosStreamPrivate *priv = stream->priv; - PinosControlCmdNodeUpdate nu = { 0, }; + PinosMessageNodeUpdate nu = { 0, }; nu.change_mask = change_mask; - if (change_mask & PINOS_CONTROL_CMD_NODE_UPDATE_MAX_INPUTS) + if (change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS) nu.max_input_ports = priv->direction == SPA_DIRECTION_INPUT ? 1 : 0; - if (change_mask & PINOS_CONTROL_CMD_NODE_UPDATE_MAX_OUTPUTS) + if (change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS) nu.max_output_ports = priv->direction == SPA_DIRECTION_OUTPUT ? 1 : 0; nu.props = NULL; - pinos_connection_add_cmd (priv->conn, PINOS_CONTROL_CMD_NODE_UPDATE, &nu); + pinos_connection_add_message (priv->conn, PINOS_MESSAGE_NODE_UPDATE, &nu); } static void add_state_change (PinosStream *stream, SpaNodeState state) { PinosStreamPrivate *priv = stream->priv; - PinosControlCmdNodeStateChange sc; + PinosMessageNodeStateChange sc; if (priv->node_state != state) { sc.state = priv->node_state = state; - pinos_connection_add_cmd (priv->conn, PINOS_CONTROL_CMD_NODE_STATE_CHANGE, &sc); + pinos_connection_add_message (priv->conn, PINOS_MESSAGE_NODE_STATE_CHANGE, &sc); } } @@ -641,47 +643,47 @@ static void add_port_update (PinosStream *stream, uint32_t change_mask) { PinosStreamPrivate *priv = stream->priv; - PinosControlCmdPortUpdate pu = { 0, };; + PinosMessagePortUpdate pu = { 0, };; pu.direction = priv->direction; pu.port_id = priv->port_id; pu.change_mask = change_mask; - if (change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS) { + if (change_mask & PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS) { pu.n_possible_formats = priv->possible_formats->len; pu.possible_formats = (SpaFormat **)priv->possible_formats->pdata; } - if (change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT) { + if (change_mask & PINOS_MESSAGE_PORT_UPDATE_FORMAT) { pu.format = priv->format; } pu.props = NULL; - if (change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_INFO) { + if (change_mask & PINOS_MESSAGE_PORT_UPDATE_INFO) { pu.info = &priv->port_info; } - pinos_connection_add_cmd (priv->conn, PINOS_CONTROL_CMD_PORT_UPDATE, &pu); + pinos_connection_add_message (priv->conn, PINOS_MESSAGE_PORT_UPDATE, &pu); } static void send_need_input (PinosStream *stream, uint32_t port_id) { PinosStreamPrivate *priv = stream->priv; - PinosControlCmdNodeEvent cne; + PinosMessageNodeEvent cne; SpaNodeEventNeedInput ni; cne.event = &ni.event; ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT; ni.event.size = sizeof (ni); ni.port_id = port_id; - pinos_connection_add_cmd (priv->rtconn, PINOS_CONTROL_CMD_NODE_EVENT, &cne); + pinos_connection_add_message (priv->rtconn, PINOS_MESSAGE_NODE_EVENT, &cne); if (!pinos_connection_flush (priv->rtconn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); } static void add_request_clock_update (PinosStream *stream) { PinosStreamPrivate *priv = stream->priv; - PinosControlCmdNodeEvent cne; + PinosMessageNodeEvent cne; SpaNodeEventRequestClockUpdate rcu; cne.event = &rcu.event; @@ -690,7 +692,7 @@ add_request_clock_update (PinosStream *stream) rcu.update_mask = SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_TIME; rcu.timestamp = 0; rcu.offset = 0; - pinos_connection_add_cmd (priv->conn, PINOS_CONTROL_CMD_NODE_EVENT, &cne); + pinos_connection_add_message (priv->conn, PINOS_MESSAGE_NODE_EVENT, &cne); } static void @@ -699,7 +701,7 @@ add_async_complete (PinosStream *stream, SpaResult res) { PinosStreamPrivate *priv = stream->priv; - PinosControlCmdNodeEvent cne; + PinosMessageNodeEvent cne; SpaNodeEventAsyncComplete ac; cne.event = &ac.event; @@ -707,14 +709,14 @@ add_async_complete (PinosStream *stream, ac.event.size = sizeof (ac); ac.seq = seq; ac.res = res; - pinos_connection_add_cmd (priv->conn, PINOS_CONTROL_CMD_NODE_EVENT, &cne); + pinos_connection_add_message (priv->conn, PINOS_MESSAGE_NODE_EVENT, &cne); } static void send_reuse_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id) { PinosStreamPrivate *priv = stream->priv; - PinosControlCmdNodeEvent cne; + PinosMessageNodeEvent cne; SpaNodeEventReuseBuffer rb; cne.event = &rb.event; @@ -722,33 +724,33 @@ send_reuse_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id) rb.event.size = sizeof (rb); rb.port_id = port_id; rb.buffer_id = buffer_id; - pinos_connection_add_cmd (priv->rtconn, PINOS_CONTROL_CMD_NODE_EVENT, &cne); + pinos_connection_add_message (priv->rtconn, PINOS_MESSAGE_NODE_EVENT, &cne); if (!pinos_connection_flush (priv->rtconn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); } static void send_process_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id) { PinosStreamPrivate *priv = stream->priv; - PinosControlCmdProcessBuffer pb; - PinosControlCmdNodeEvent cne; + PinosMessageProcessBuffer pb; + PinosMessageNodeEvent cne; SpaNodeEventHaveOutput ho; pb.direction = priv->direction; pb.port_id = port_id; pb.buffer_id = buffer_id; - pinos_connection_add_cmd (priv->rtconn, PINOS_CONTROL_CMD_PROCESS_BUFFER, &pb); + pinos_connection_add_message (priv->rtconn, PINOS_MESSAGE_PROCESS_BUFFER, &pb); cne.event = &ho.event; ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT; ho.event.size = sizeof (ho); ho.port_id = port_id; - pinos_connection_add_cmd (priv->rtconn, PINOS_CONTROL_CMD_NODE_EVENT, &cne); + pinos_connection_add_message (priv->rtconn, PINOS_MESSAGE_NODE_EVENT, &cne); if (!pinos_connection_flush (priv->rtconn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); } static void @@ -756,27 +758,26 @@ do_node_init (PinosStream *stream) { PinosStreamPrivate *priv = stream->priv; - add_node_update (stream, PINOS_CONTROL_CMD_NODE_UPDATE_MAX_INPUTS | - PINOS_CONTROL_CMD_NODE_UPDATE_MAX_OUTPUTS); + add_node_update (stream, PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS | + PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS); priv->port_info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS; - add_port_update (stream, PINOS_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS | - PINOS_CONTROL_CMD_PORT_UPDATE_INFO); + add_port_update (stream, PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS | + PINOS_MESSAGE_PORT_UPDATE_INFO); add_state_change (stream, SPA_NODE_STATE_CONFIGURE); if (!pinos_connection_flush (priv->conn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); } static MemId * find_mem (PinosStream *stream, uint32_t id) { PinosStreamPrivate *priv = stream->priv; - guint i; + MemId *mid; - for (i = 0; i < priv->mem_ids->len; i++) { - MemId *mid = &g_array_index (priv->mem_ids, MemId, i); + pinos_array_for_each (mid, &priv->mem_ids) { if (mid->id == id) return mid; } @@ -787,13 +788,13 @@ static BufferId * find_buffer (PinosStream *stream, uint32_t id) { PinosStreamPrivate *priv = stream->priv; - guint i; - if (priv->in_order && id < priv->buffer_ids->len) { - return &g_array_index (priv->buffer_ids, BufferId, id); + if (priv->in_order && pinos_array_check_index (&priv->buffer_ids, id, BufferId)) { + return pinos_array_get_unchecked (&priv->buffer_ids, id, BufferId); } else { - for (i = 0; i < priv->buffer_ids->len; i++) { - BufferId *bid = &g_array_index (priv->buffer_ids, BufferId, i); + BufferId *bid; + + pinos_array_for_each (bid, &priv->buffer_ids) { if (bid->id == id) return bid; } @@ -815,7 +816,7 @@ handle_node_event (PinosStream *stream, case SPA_NODE_EVENT_TYPE_BUFFERING: case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH: case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE: - g_warning ("unhandled node event %d", event->type); + pinos_log_warn ("unhandled node event %d", event->type); break; } return TRUE; @@ -834,12 +835,12 @@ handle_rtnode_event (PinosStream *stream, case SPA_NODE_EVENT_TYPE_BUFFERING: case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH: case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE: - g_warning ("unexpected node event %d", event->type); + pinos_log_warn ("unexpected node event %d", event->type); break; case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT: case SPA_NODE_EVENT_TYPE_NEED_INPUT: - g_warning ("unhandled node event %d", event->type); + pinos_log_warn ("unhandled node event %d", event->type); break; case SPA_NODE_EVENT_TYPE_REUSE_BUFFER: @@ -874,25 +875,25 @@ handle_node_command (PinosStream *stream, break; case SPA_NODE_COMMAND_PAUSE: { - g_debug ("stream %p: pause %d", stream, seq); + pinos_log_debug ("stream %p: pause %d", stream, seq); add_state_change (stream, SPA_NODE_STATE_PAUSED); add_async_complete (stream, seq, SPA_RESULT_OK); if (!pinos_connection_flush (priv->conn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL); break; } case SPA_NODE_COMMAND_START: { - g_debug ("stream %p: start %d", stream, seq); + pinos_log_debug ("stream %p: start %d", stream, seq); add_state_change (stream, SPA_NODE_STATE_STREAMING); add_async_complete (stream, seq, SPA_RESULT_OK); if (!pinos_connection_flush (priv->conn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); if (priv->direction == SPA_DIRECTION_INPUT) send_need_input (stream, priv->port_id); @@ -904,11 +905,11 @@ handle_node_command (PinosStream *stream, case SPA_NODE_COMMAND_DRAIN: case SPA_NODE_COMMAND_MARKER: { - g_warning ("unhandled node command %d", command->type); + pinos_log_warn ("unhandled node command %d", command->type); add_async_complete (stream, seq, SPA_RESULT_NOT_IMPLEMENTED); if (!pinos_connection_flush (priv->conn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); break; } case SPA_NODE_COMMAND_CLOCK_UPDATE: @@ -936,28 +937,28 @@ parse_connection (PinosStream *stream) PinosConnection *conn = priv->conn; while (pinos_connection_has_next (conn)) { - PinosControlCmd cmd = pinos_connection_get_cmd (conn); - - switch (cmd) { - case PINOS_CONTROL_CMD_NODE_UPDATE: - case PINOS_CONTROL_CMD_PORT_UPDATE: - case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: - case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: - case PINOS_CONTROL_CMD_PROCESS_BUFFER: - g_warning ("got unexpected command %d", cmd); + PinosMessageType type = pinos_connection_get_type (conn); + + switch (type) { + case PINOS_MESSAGE_NODE_UPDATE: + case PINOS_MESSAGE_PORT_UPDATE: + case PINOS_MESSAGE_PORT_STATUS_CHANGE: + case PINOS_MESSAGE_NODE_STATE_CHANGE: + case PINOS_MESSAGE_PROCESS_BUFFER: + pinos_log_warn ("got unexpected message %d", type); break; - case PINOS_CONTROL_CMD_ADD_PORT: - case PINOS_CONTROL_CMD_REMOVE_PORT: - g_warning ("add/remove port not supported"); + case PINOS_MESSAGE_ADD_PORT: + case PINOS_MESSAGE_REMOVE_PORT: + pinos_log_warn ("add/remove port not supported"); break; - case PINOS_CONTROL_CMD_SET_FORMAT: + case PINOS_MESSAGE_SET_FORMAT: { - PinosControlCmdSetFormat p; + PinosMessageSetFormat p; gpointer mem; - if (!pinos_connection_parse_cmd (conn, &p)) + if (!pinos_connection_parse_message (conn, &p)) break; if (priv->format) @@ -970,17 +971,17 @@ parse_connection (PinosStream *stream) stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL); break; } - case PINOS_CONTROL_CMD_SET_PROPERTY: - g_warning ("set property not implemented"); + case PINOS_MESSAGE_SET_PROPERTY: + pinos_log_warn ("set property not implemented"); break; - case PINOS_CONTROL_CMD_ADD_MEM: + case PINOS_MESSAGE_ADD_MEM: { - PinosControlCmdAddMem p; + PinosMessageAddMem p; int fd; - MemId mid, *m; + MemId *m; - if (!pinos_connection_parse_cmd (conn, &p)) + if (!pinos_connection_parse_message (conn, &p)) break; fd = pinos_connection_get_fd (conn, p.fd_index, false); @@ -989,33 +990,26 @@ parse_connection (PinosStream *stream) m = find_mem (stream, p.mem_id); if (m) { - g_debug ("update mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size); - - m->id = p.mem_id; - m->fd = fd; - m->flags = p.flags; - m->ptr = NULL; - m->size = p.size; + pinos_log_debug ("update mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size); } else { - 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, size %zd", p.mem_id, fd, p.flags, p.size); - g_array_append_val (priv->mem_ids, mid); + m = pinos_array_add (&priv->mem_ids, sizeof (MemId)); + pinos_log_debug ("add mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size); } + m->id = p.mem_id; + m->fd = fd; + m->flags = p.flags; + m->ptr = NULL; + m->size = p.size; break; } - case PINOS_CONTROL_CMD_USE_BUFFERS: + case PINOS_MESSAGE_USE_BUFFERS: { - PinosControlCmdUseBuffers p; - BufferId bid; - unsigned int i, j; + PinosMessageUseBuffers p; + BufferId *bid; + unsigned int i, j, len; SpaBuffer *b; - if (!pinos_connection_parse_cmd (conn, &p)) + if (!pinos_connection_parse_message (conn, &p)) break; /* clear previous buffers */ @@ -1024,7 +1018,7 @@ parse_connection (PinosStream *stream) for (i = 0; i < p.n_buffers; i++) { MemId *mid = find_mem (stream, p.buffers[i].mem_id); if (mid == NULL) { - g_warning ("unknown memory id %u", mid->id); + pinos_log_warn ("unknown memory id %u", mid->id); continue; } @@ -1032,18 +1026,20 @@ parse_connection (PinosStream *stream) 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)); + pinos_log_warn ("Failed to mmap memory %zd %p: %s", mid->size, mid, strerror (errno)); continue; } } + len = pinos_array_get_len (&priv->buffer_ids, BufferId); + bid = pinos_array_add (&priv->buffer_ids, sizeof (BufferId)); - bid.buf_ptr = SPA_MEMBER (mid->ptr, p.buffers[i].offset, void); + bid->buf_ptr = SPA_MEMBER (mid->ptr, p.buffers[i].offset, void); { size_t size; unsigned int i; SpaMeta *m; - b = bid.buf_ptr; + b = bid->buf_ptr; size = sizeof (SpaBuffer); m = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta); for (i = 0; i < b->n_metas; i++) @@ -1051,24 +1047,28 @@ parse_connection (PinosStream *stream) for (i = 0; i < b->n_datas; i++) size += sizeof (SpaData); - b = bid.buf = g_memdup (bid.buf_ptr, size); + b = bid->buf = g_memdup (bid->buf_ptr, size); if (b->metas) b->metas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta); if (b->datas) { - bid.datas = SPA_MEMBER (bid.buf_ptr, SPA_PTR_TO_INT (b->datas), SpaData); + bid->datas = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (b->datas), SpaData); b->datas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->datas), SpaData); } } - bid.id = b->id; + bid->id = b->id; - g_debug ("add buffer %d %d %zd", mid->id, bid.id, p.buffers[i].offset); + if (bid->id != len) { + pinos_log_warn ("unexpected id %u found, expected %u", bid->id, len); + priv->in_order = FALSE; + } + pinos_log_debug ("add buffer %d %d %zd", mid->id, bid->id, p.buffers[i].offset); for (j = 0; j < b->n_metas; j++) { SpaMeta *m = &b->metas[j]; if (m->data) - m->data = SPA_MEMBER (bid.buf_ptr, SPA_PTR_TO_INT (m->data), void); + m->data = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (m->data), void); } for (j = 0; j < b->n_datas; j++) { @@ -1081,28 +1081,23 @@ parse_connection (PinosStream *stream) d->type = SPA_DATA_TYPE_MEMFD; d->data = NULL; d->fd = bmid->fd; - g_debug (" data %d %u -> fd %d", j, bmid->id, bmid->fd); + pinos_log_debug (" data %d %u -> fd %d", j, bmid->id, bmid->fd); break; } case SPA_DATA_TYPE_MEMPTR: { - d->data = SPA_MEMBER (bid.buf_ptr, SPA_PTR_TO_INT (d->data), void); + d->data = SPA_MEMBER (bid->buf_ptr, SPA_PTR_TO_INT (d->data), void); d->fd = -1; - g_debug (" data %d %u -> mem %p", j, bid.id, d->data); + pinos_log_debug (" data %d %u -> mem %p", j, bid->id, d->data); break; } default: - g_warning ("unknown buffer data type %d", d->type); + pinos_log_warn ("unknown buffer data type %d", d->type); break; } } - if (bid.id != priv->buffer_ids->len) { - g_warning ("unexpected id %u found, expected %u", bid.id, priv->buffer_ids->len); - priv->in_order = FALSE; - } - g_array_append_val (priv->buffer_ids, bid); - g_signal_emit (stream, signals[SIGNAL_ADD_BUFFER], 0, bid.id); + g_signal_emit (stream, signals[SIGNAL_ADD_BUFFER], 0, bid->id); } if (p.n_buffers) { @@ -1113,7 +1108,7 @@ parse_connection (PinosStream *stream) add_async_complete (stream, p.seq, SPA_RESULT_OK); if (!pinos_connection_flush (conn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); if (p.n_buffers) stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL); @@ -1121,37 +1116,37 @@ parse_connection (PinosStream *stream) stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL); break; } - case PINOS_CONTROL_CMD_NODE_EVENT: + case PINOS_MESSAGE_NODE_EVENT: { - PinosControlCmdNodeEvent p; + PinosMessageNodeEvent p; - if (!pinos_connection_parse_cmd (conn, &p)) + if (!pinos_connection_parse_message (conn, &p)) break; handle_node_event (stream, p.event); break; } - case PINOS_CONTROL_CMD_NODE_COMMAND: + case PINOS_MESSAGE_NODE_COMMAND: { - PinosControlCmdNodeCommand p; + PinosMessageNodeCommand p; - if (!pinos_connection_parse_cmd (conn, &p)) + if (!pinos_connection_parse_message (conn, &p)) break; handle_node_command (stream, p.seq, p.command); break; } - case PINOS_CONTROL_CMD_PORT_COMMAND: + case PINOS_MESSAGE_PORT_COMMAND: { - PinosControlCmdPortCommand p; + PinosMessagePortCommand p; - if (!pinos_connection_parse_cmd (conn, &p)) + if (!pinos_connection_parse_message (conn, &p)) break; break; } - case PINOS_CONTROL_CMD_INVALID: - g_warning ("unhandled command %d", cmd); + case PINOS_MESSAGE_INVALID: + pinos_log_warn ("unhandled message %d", type); break; } } @@ -1165,34 +1160,34 @@ parse_rtconnection (PinosStream *stream) PinosConnection *conn = priv->rtconn; while (pinos_connection_has_next (conn)) { - PinosControlCmd cmd = pinos_connection_get_cmd (conn); - - switch (cmd) { - case PINOS_CONTROL_CMD_INVALID: - case PINOS_CONTROL_CMD_NODE_UPDATE: - case PINOS_CONTROL_CMD_PORT_UPDATE: - case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: - case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: - case PINOS_CONTROL_CMD_ADD_PORT: - case PINOS_CONTROL_CMD_REMOVE_PORT: - case PINOS_CONTROL_CMD_SET_FORMAT: - case PINOS_CONTROL_CMD_SET_PROPERTY: - case PINOS_CONTROL_CMD_ADD_MEM: - case PINOS_CONTROL_CMD_USE_BUFFERS: - case PINOS_CONTROL_CMD_NODE_COMMAND: - g_warning ("got unexpected command %d", cmd); + PinosMessageType type = pinos_connection_get_type (conn); + + switch (type) { + case PINOS_MESSAGE_INVALID: + case PINOS_MESSAGE_NODE_UPDATE: + case PINOS_MESSAGE_PORT_UPDATE: + case PINOS_MESSAGE_PORT_STATUS_CHANGE: + case PINOS_MESSAGE_NODE_STATE_CHANGE: + case PINOS_MESSAGE_ADD_PORT: + case PINOS_MESSAGE_REMOVE_PORT: + case PINOS_MESSAGE_SET_FORMAT: + case PINOS_MESSAGE_SET_PROPERTY: + case PINOS_MESSAGE_ADD_MEM: + case PINOS_MESSAGE_USE_BUFFERS: + case PINOS_MESSAGE_NODE_COMMAND: + pinos_log_warn ("got unexpected command %d", type); break; - case PINOS_CONTROL_CMD_PROCESS_BUFFER: + case PINOS_MESSAGE_PROCESS_BUFFER: { - PinosControlCmdProcessBuffer p; + PinosMessageProcessBuffer p; guint i; BufferId *bid; if (priv->direction != SPA_DIRECTION_INPUT) break; - if (!pinos_connection_parse_cmd (conn, &p)) + if (!pinos_connection_parse_message (conn, &p)) break; if ((bid = find_buffer (stream, p.buffer_id))) { @@ -1205,17 +1200,17 @@ parse_rtconnection (PinosStream *stream) } break; } - case PINOS_CONTROL_CMD_NODE_EVENT: + case PINOS_MESSAGE_NODE_EVENT: { - PinosControlCmdNodeEvent p; + PinosMessageNodeEvent p; - if (!pinos_connection_parse_cmd (conn, &p)) + if (!pinos_connection_parse_message (conn, &p)) break; handle_rtnode_event (stream, p.event); break; } - case PINOS_CONTROL_CMD_PORT_COMMAND: + case PINOS_MESSAGE_PORT_COMMAND: { break; } @@ -1240,7 +1235,7 @@ on_socket_condition (GSocket *socket, } case G_IO_OUT: - g_warning ("can do IO\n"); + pinos_log_warn ("can do IO\n"); break; default: @@ -1264,7 +1259,7 @@ on_rtsocket_condition (GSocket *socket, } case G_IO_OUT: - g_warning ("can do IO\n"); + pinos_log_warn ("can do IO\n"); break; default: @@ -1282,7 +1277,7 @@ on_timeout (gpointer user_data) add_request_clock_update (stream); if (!pinos_connection_flush (priv->conn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); return G_SOURCE_CONTINUE; } @@ -1321,7 +1316,7 @@ handle_socket (PinosStream *stream, gint fd, gint rtfd) /* ERRORS */ socket_failed: { - g_warning ("failed to create socket: %s", error->message); + pinos_log_warn ("failed to create socket: %s", error->message); stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error); return; } @@ -1368,7 +1363,7 @@ on_node_proxy (GObject *source_object, node_failed: { - g_warning ("failed to get node proxy: %s", error->message); + pinos_log_warn ("failed to get node proxy: %s", error->message); stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error); g_object_unref (stream); return; @@ -1425,12 +1420,12 @@ on_node_created (GObject *source_object, /* ERRORS */ create_failed: { - g_warning ("failed to connect: %s", error->message); + pinos_log_warn ("failed to connect: %s", error->message); goto exit_error; } fd_failed: { - g_warning ("failed to get FD: %s", error->message); + pinos_log_warn ("failed to get FD: %s", error->message); g_object_unref (fd_list); goto exit_error; } @@ -1479,12 +1474,12 @@ on_node_registered (GObject *source_object, /* ERRORS */ create_failed: { - g_warning ("failed to connect: %s", error->message); + pinos_log_warn ("failed to connect: %s", error->message); goto exit_error; } fd_failed: { - g_warning ("failed to get FD: %s", error->message); + pinos_log_warn ("failed to get FD: %s", error->message); g_object_unref (fd_list); goto exit_error; } @@ -1635,8 +1630,8 @@ pinos_stream_finish_format (PinosStream *stream, priv->port_info.n_params = n_params; if (SPA_RESULT_IS_OK (res)) { - add_port_update (stream, PINOS_CONTROL_CMD_PORT_UPDATE_INFO | - PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT); + add_port_update (stream, PINOS_MESSAGE_PORT_UPDATE_INFO | + PINOS_MESSAGE_PORT_UPDATE_FORMAT); if (priv->format) { add_state_change (stream, SPA_NODE_STATE_READY); } else { @@ -1652,7 +1647,7 @@ pinos_stream_finish_format (PinosStream *stream, priv->pending_seq = SPA_ID_INVALID; if (!pinos_connection_flush (priv->conn)) - g_warning ("stream %p: error writing connection", stream); + pinos_log_warn ("stream %p: error writing connection", stream); return TRUE; } @@ -1752,7 +1747,7 @@ on_node_removed (GObject *source_object, /* ERRORS */ proxy_failed: { - g_warning ("failed to disconnect: %s", error->message); + pinos_log_warn ("failed to disconnect: %s", error->message); stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error); g_object_unref (stream); return; @@ -1841,14 +1836,13 @@ guint pinos_stream_get_empty_buffer (PinosStream *stream) { PinosStreamPrivate *priv; - guint i; + BufferId *bid; g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE); priv = stream->priv; g_return_val_if_fail (priv->direction == SPA_DIRECTION_OUTPUT, FALSE); - for (i = 0; i < priv->buffer_ids->len; i++) { - BufferId *bid = &g_array_index (priv->buffer_ids, BufferId, i); + pinos_array_for_each (bid, &priv->buffer_ids) { if (!bid->used) return bid->id; } diff --git a/pinos/client/subscribe.c b/pinos/client/subscribe.c index ca2eb0a3..660cc0b1 100644 --- a/pinos/client/subscribe.c +++ b/pinos/client/subscribe.c @@ -196,7 +196,7 @@ on_proxy_created (GObject *source_object, data->proxy = g_dbus_proxy_new_finish (res, &error); if (data->proxy == NULL) { priv->objects = g_list_remove (priv->objects, data); - g_warning ("could not create proxy: %s", error->message); + pinos_log_warn ("could not create proxy: %s", error->message); subscription_set_state (subscribe, PINOS_SUBSCRIPTION_STATE_ERROR); priv->error = error; return; @@ -365,7 +365,7 @@ on_managed_objects_ready (GObject *source_object, objects = g_dbus_proxy_call_finish (priv->manager_proxy, res, &error); if (objects == NULL) { - g_warning ("could not get objects: %s", error->message); + pinos_log_warn ("could not get objects: %s", error->message); subscription_set_state (subscribe, PINOS_SUBSCRIPTION_STATE_ERROR); priv->error = error; return; @@ -464,7 +464,7 @@ on_manager_proxy_ready (GObject *source_object, /* ERRORS */ manager_error: { - g_warning ("could not create client manager: %s", error->message); + pinos_log_warn ("could not create client manager: %s", error->message); subscription_set_state (subscribe, PINOS_SUBSCRIPTION_STATE_ERROR); priv->error = error; g_object_unref (subscribe); diff --git a/pinos/client/thread-mainloop.c b/pinos/client/thread-mainloop.c index c754d396..943136a0 100644 --- a/pinos/client/thread-mainloop.c +++ b/pinos/client/thread-mainloop.c @@ -110,7 +110,7 @@ pinos_thread_main_loop_constructed (GObject * object) PinosThreadMainLoopPrivate *priv = loop->priv; priv->mainloop = g_main_loop_new (priv->maincontext, FALSE); - g_debug ("thread-mainloop %p: contructed %p %p", loop, priv->maincontext, priv->mainloop); + pinos_log_debug ("thread-mainloop %p: contructed %p %p", loop, priv->maincontext, priv->mainloop); G_OBJECT_CLASS (pinos_thread_main_loop_parent_class)->constructed (object); } @@ -269,9 +269,9 @@ handle_mainloop (PinosThreadMainLoop *loop) g_main_context_set_poll_func (priv->maincontext, do_poll); g_main_context_push_thread_default (priv->maincontext); - g_debug ("thread-mainloop %p: run mainloop %p context %p", loop, priv->mainloop, priv->maincontext); + pinos_log_debug ("thread-mainloop %p: run mainloop %p context %p", loop, priv->mainloop, priv->maincontext); g_main_loop_run (priv->mainloop); - g_debug ("thread-mainloop %p: done", loop); + pinos_log_debug ("thread-mainloop %p: done", loop); g_main_context_pop_thread_default (priv->maincontext); g_main_context_set_poll_func (priv->maincontext, priv->poll_func); diff --git a/pinos/daemon/daemon-config.c b/pinos/daemon/daemon-config.c index a879f983..8e5040cb 100644 --- a/pinos/daemon/daemon-config.c +++ b/pinos/daemon/daemon-config.c @@ -135,7 +135,7 @@ pinos_daemon_config_load_file (PinosDaemonConfig * config, g_return_val_if_fail (config != NULL, FALSE); g_return_val_if_fail (filename != NULL && *filename != '\0', FALSE); - g_debug ("deamon-config %p loading file %s", config, filename); + pinos_log_debug ("deamon-config %p loading file %s", config, filename); if (!g_file_get_contents (filename, &data, NULL, err)) { return FALSE; @@ -175,7 +175,7 @@ pinos_daemon_config_load (PinosDaemonConfig * config, filename = g_getenv ("PINOS_CONFIG_FILE"); if (filename != NULL && *filename != '\0') { - g_debug ("PINOS_CONFIG_FILE set to: %s", filename); + pinos_log_debug ("PINOS_CONFIG_FILE set to: %s", filename); } else { filename = DEFAULT_CONFIG_FILE; } @@ -206,7 +206,7 @@ pinos_daemon_config_run_commands (PinosDaemonConfig * config, for (walk = config->commands; walk != NULL; walk = walk->next) { PinosCommand *command = (PinosCommand *)walk->data; if (!pinos_command_run (command, daemon, &err)) { - g_warning ("could not run command %s: %s", + pinos_log_warn ("could not run command %s: %s", pinos_command_get_name (command), err->message); g_clear_error (&err); ret = FALSE; diff --git a/pinos/gst/gstpinospool.c b/pinos/gst/gstpinospool.c index b941e6ec..889efa2c 100644 --- a/pinos/gst/gstpinospool.c +++ b/pinos/gst/gstpinospool.c @@ -105,9 +105,10 @@ do_start (GstBufferPool * pool) guint size; guint min_buffers; guint max_buffers; - SpaAllocParam *port_params[2]; - SpaAllocParamMetaEnable param_meta_enable; + SpaAllocParam *port_params[3]; SpaAllocParamBuffers param_buffers; + SpaAllocParamMetaEnable param_meta_enable; + SpaAllocParamMetaEnableRingbuffer param_meta_enable_rb; config = gst_buffer_pool_get_config (pool); gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers, &max_buffers); @@ -124,6 +125,14 @@ do_start (GstBufferPool * pool) param_meta_enable.param.type = SPA_ALLOC_PARAM_TYPE_META_ENABLE; param_meta_enable.param.size = sizeof (SpaAllocParamMetaEnable); param_meta_enable.type = SPA_META_TYPE_HEADER; + port_params[2] = ¶m_meta_enable_rb.param; + param_meta_enable_rb.param.type = SPA_ALLOC_PARAM_TYPE_META_ENABLE; + param_meta_enable_rb.param.size = sizeof (SpaAllocParamMetaEnableRingbuffer); + param_meta_enable_rb.type = SPA_META_TYPE_RINGBUFFER; + param_meta_enable_rb.minsize = size * SPA_MAX (4, SPA_MAX (min_buffers, max_buffers)); + param_meta_enable_rb.stride = 0; + param_meta_enable_rb.blocks = 1; + param_meta_enable_rb.align = 16; pinos_stream_finish_format (p->stream, SPA_RESULT_OK, port_params, 2); diff --git a/pinos/modules/spa/spa-alsa-monitor.c b/pinos/modules/spa/spa-alsa-monitor.c index a947985b..c9fa090a 100644 --- a/pinos/modules/spa/spa-alsa-monitor.c +++ b/pinos/modules/spa/spa-alsa-monitor.c @@ -31,6 +31,8 @@ #include <spa/include/spa/node.h> #include <spa/include/spa/monitor.h> +#include <pinos/client/log.h> + #include "spa-alsa-monitor.h" #define PINOS_SPA_ALSA_MONITOR_GET_PRIVATE(obj) \ @@ -109,7 +111,7 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item) void *node_iface, *clock_iface; PinosProperties *props = NULL; - g_debug ("alsa-monitor %p: add: \"%s\" (%s)", this, item->name, item->id); + pinos_log_debug ("alsa-monitor %p: add: \"%s\" (%s)", this, item->name, item->id); handle = calloc (1, item->factory->size); if ((res = spa_handle_factory_init (item->factory, @@ -125,7 +127,7 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item) return; } if ((res = spa_handle_get_interface (handle, priv->uri.clock, &clock_iface)) < 0) { - g_debug ("can't get CLOCK interface: %d", res); + pinos_log_debug ("can't get CLOCK interface: %d", res); clock_iface = NULL; } @@ -157,7 +159,7 @@ remove_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item) PinosSpaALSAMonitorPrivate *priv = this->priv; PinosNode *node; - g_debug ("alsa-monitor %p: remove: \"%s\" (%s)", this, item->name, item->id); + pinos_log_debug ("alsa-monitor %p: remove: \"%s\" (%s)", this, item->name, item->id); node = g_hash_table_lookup (priv->nodes, item->id); if (node) { @@ -188,7 +190,7 @@ on_monitor_event (SpaMonitor *monitor, case SPA_MONITOR_EVENT_TYPE_CHANGED: { SpaMonitorItem *item = (SpaMonitorItem *) event; - g_debug ("alsa-monitor %p: changed: \"%s\"", this, item->name); + pinos_log_debug ("alsa-monitor %p: changed: \"%s\"", this, item->name); break; } default: @@ -204,7 +206,7 @@ monitor_constructed (GObject * object) SpaResult res; void *state = NULL; - g_debug ("spa-monitor %p: constructed", this); + pinos_log_debug ("spa-monitor %p: constructed", this); G_OBJECT_CLASS (pinos_spa_alsa_monitor_parent_class)->constructed (object); @@ -216,7 +218,7 @@ monitor_constructed (GObject * object) if ((res = spa_monitor_enum_items (priv->monitor, &item, &state)) < 0) { if (res != SPA_RESULT_ENUM_END) - g_debug ("spa_monitor_enum_items: got error %d\n", res); + pinos_log_debug ("spa_monitor_enum_items: got error %d\n", res); break; } add_item (this, item); @@ -278,7 +280,7 @@ monitor_finalize (GObject * object) PinosSpaALSAMonitor *this = PINOS_SPA_ALSA_MONITOR (object); PinosSpaALSAMonitorPrivate *priv = this->priv; - g_debug ("spa-monitor %p: dispose", this); + pinos_log_debug ("spa-monitor %p: dispose", this); spa_handle_clear (priv->handle); g_free (priv->handle); g_hash_table_unref (priv->nodes); diff --git a/pinos/modules/spa/spa-audiotestsrc.c b/pinos/modules/spa/spa-audiotestsrc.c index 827fa030..75e5209b 100644 --- a/pinos/modules/spa/spa-audiotestsrc.c +++ b/pinos/modules/spa/spa-audiotestsrc.c @@ -100,10 +100,10 @@ setup_node (PinosSpaAudioTestSrc *this) SpaPropValue value; if ((res = spa_node_get_props (node->node, &props)) < 0) - g_debug ("got get_props error %d", res); + pinos_log_debug ("got get_props error %d", res); if ((res = spa_node_set_props (node->node, props)) < 0) - g_debug ("got set_props error %d", res); + pinos_log_debug ("got set_props error %d", res); #endif } @@ -149,7 +149,7 @@ src_finalize (GObject * object) PinosSpaAudioTestSrc *src = PINOS_SPA_AUDIOTESTSRC (object); PinosSpaAudioTestSrcPrivate *priv = src->priv; - g_debug ("audiotestsrc %p: dispose", src); + pinos_log_debug ("audiotestsrc %p: dispose", src); spa_handle_clear (priv->handle); g_free (priv->handle); diff --git a/pinos/modules/spa/spa-v4l2-monitor.c b/pinos/modules/spa/spa-v4l2-monitor.c index 06500c6c..0642e4c5 100644 --- a/pinos/modules/spa/spa-v4l2-monitor.c +++ b/pinos/modules/spa/spa-v4l2-monitor.c @@ -26,10 +26,9 @@ #include <unistd.h> #include <sys/mman.h> -#include <gio/gio.h> - #include <spa/include/spa/node.h> #include <spa/include/spa/monitor.h> +#include <pinos/client/log.h> #include "spa-v4l2-monitor.h" @@ -110,7 +109,7 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item) void *clock_iface; PinosProperties *props = NULL; - g_debug ("v4l2-monitor %p: add: \"%s\" (%s)", this, item->name, item->id); + pinos_log_debug ("v4l2-monitor %p: add: \"%s\" (%s)", this, item->name, item->id); handle = calloc (1, item->factory->size); if ((res = spa_handle_factory_init (item->factory, @@ -158,7 +157,7 @@ remove_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item) PinosSpaV4l2MonitorPrivate *priv = this->priv; PinosNode *node; - g_debug ("v4l2-monitor %p: remove: \"%s\" (%s)", this, item->name, item->id); + pinos_log_debug ("v4l2-monitor %p: remove: \"%s\" (%s)", this, item->name, item->id); node = g_hash_table_lookup (priv->nodes, item->id); if (node) { @@ -189,7 +188,7 @@ on_monitor_event (SpaMonitor *monitor, case SPA_MONITOR_EVENT_TYPE_CHANGED: { SpaMonitorItem *item = (SpaMonitorItem *) event; - g_debug ("v4l2-monitor %p: changed: \"%s\"", this, item->name); + pinos_log_debug ("v4l2-monitor %p: changed: \"%s\"", this, item->name); break; } default: @@ -205,7 +204,7 @@ monitor_constructed (GObject * object) SpaResult res; void *state = NULL; - g_debug ("spa-monitor %p: constructed", this); + pinos_log_debug ("spa-monitor %p: constructed", this); G_OBJECT_CLASS (pinos_spa_v4l2_monitor_parent_class)->constructed (object); @@ -217,7 +216,7 @@ monitor_constructed (GObject * object) if ((res = spa_monitor_enum_items (priv->monitor, &item, &state)) < 0) { if (res != SPA_RESULT_ENUM_END) - g_debug ("spa_monitor_enum_items: got error %d\n", res); + pinos_log_debug ("spa_monitor_enum_items: got error %d\n", res); break; } add_item (this, item); @@ -279,7 +278,7 @@ monitor_finalize (GObject * object) PinosSpaV4l2Monitor *this = PINOS_SPA_V4L2_MONITOR (object); PinosSpaV4l2MonitorPrivate *priv = this->priv; - g_debug ("spa-monitor %p: dispose", this); + pinos_log_debug ("spa-monitor %p: dispose", this); spa_handle_clear (priv->handle); g_free (priv->handle); g_hash_table_unref (priv->nodes); diff --git a/pinos/server/client-node.c b/pinos/server/client-node.c index fce02e11..1496333d 100644 --- a/pinos/server/client-node.c +++ b/pinos/server/client-node.c @@ -164,7 +164,7 @@ static SpaResult clear_buffers (SpaProxy *this, SpaProxyPort *port) { if (port->n_buffers) { - spa_log_info (this->log, "proxy %p: clear buffers\n", this); + spa_log_info (this->log, "proxy %p: clear buffers", this); munmap (port->buffer_mem_ptr, port->buffer_mem_size); close (port->buffer_mem_fd); @@ -211,15 +211,15 @@ spa_proxy_node_send_command (SpaNode *node, case SPA_NODE_COMMAND_DRAIN: case SPA_NODE_COMMAND_MARKER: { - PinosControlCmdNodeCommand cnc; + PinosMessageNodeCommand cnc; /* send start */ cnc.seq = this->seq++; cnc.command = command; - pinos_connection_add_cmd (this->conn, PINOS_CONTROL_CMD_NODE_COMMAND, &cnc); + pinos_connection_add_message (this->conn, PINOS_MESSAGE_NODE_COMMAND, &cnc); if (!pinos_connection_flush (this->conn)) { - spa_log_error (this->log, "proxy %p: error writing connection\n", this); + spa_log_error (this->log, "proxy %p: error writing connection", this); res = SPA_RESULT_ERROR; } else res = SPA_RESULT_RETURN_ASYNC (cnc.seq); @@ -228,14 +228,14 @@ spa_proxy_node_send_command (SpaNode *node, case SPA_NODE_COMMAND_CLOCK_UPDATE: { - PinosControlCmdNodeCommand cnc; + PinosMessageNodeCommand cnc; /* send start */ cnc.command = command; - pinos_connection_add_cmd (this->conn, PINOS_CONTROL_CMD_NODE_COMMAND, &cnc); + pinos_connection_add_message (this->conn, PINOS_MESSAGE_NODE_COMMAND, &cnc); if (!pinos_connection_flush (this->conn)) { - spa_log_error (this->log, "proxy %p: error writing connection\n", this); + spa_log_error (this->log, "proxy %p: error writing connection", this); res = SPA_RESULT_ERROR; } break; @@ -319,7 +319,7 @@ spa_proxy_node_get_port_ids (SpaNode *node, static void do_update_port (SpaProxy *this, - PinosControlCmdPortUpdate *pu) + PinosMessagePortUpdate *pu) { SpaProxyPort *port; unsigned int i; @@ -331,7 +331,7 @@ do_update_port (SpaProxy *this, port = &this->out_ports[pu->port_id]; } - if (pu->change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS) { + if (pu->change_mask & PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS) { for (i = 0; i < port->n_formats; i++) free (port->formats[i]); port->n_formats = pu->n_possible_formats; @@ -341,17 +341,17 @@ do_update_port (SpaProxy *this, port->formats[i] = pinos_serialize_format_copy_into (malloc (size), pu->possible_formats[i]); } } - if (pu->change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT) { + if (pu->change_mask & PINOS_MESSAGE_PORT_UPDATE_FORMAT) { if (port->format) free (port->format); size = pinos_serialize_format_get_size (pu->format); port->format = pinos_serialize_format_copy_into (malloc (size), pu->format); } - if (pu->change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_PROPS) { + if (pu->change_mask & PINOS_MESSAGE_PORT_UPDATE_PROPS) { } - if (pu->change_mask & PINOS_CONTROL_CMD_PORT_UPDATE_INFO && pu->info) { + if (pu->change_mask & PINOS_MESSAGE_PORT_UPDATE_INFO && pu->info) { if (port->info) free (port->info); size = pinos_serialize_port_info_get_size (pu->info); @@ -359,7 +359,7 @@ do_update_port (SpaProxy *this, } if (!port->valid) { - spa_log_info (this->log, "proxy %p: adding port %d\n", this, pu->port_id); + spa_log_info (this->log, "proxy %p: adding port %d", this, pu->port_id); port->format = NULL; port->valid = true; @@ -376,12 +376,12 @@ clear_port (SpaProxy *this, SpaDirection direction, uint32_t port_id) { - PinosControlCmdPortUpdate pu; + PinosMessagePortUpdate pu; - pu.change_mask = PINOS_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS | - PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT | - PINOS_CONTROL_CMD_PORT_UPDATE_PROPS | - PINOS_CONTROL_CMD_PORT_UPDATE_INFO; + pu.change_mask = PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS | + PINOS_MESSAGE_PORT_UPDATE_FORMAT | + PINOS_MESSAGE_PORT_UPDATE_PROPS | + PINOS_MESSAGE_PORT_UPDATE_INFO; pu.direction = direction; pu.port_id = port_id; pu.n_possible_formats = 0; @@ -400,7 +400,7 @@ do_uninit_port (SpaProxy *this, { SpaProxyPort *port; - spa_log_info (this->log, "proxy %p: removing port %d\n", this, port_id); + spa_log_info (this->log, "proxy %p: removing port %d", this, port_id); if (direction == SPA_DIRECTION_INPUT) { port = &this->in_ports[port_id]; this->n_inputs--; @@ -495,7 +495,7 @@ spa_proxy_node_port_set_format (SpaNode *node, const SpaFormat *format) { SpaProxy *this; - PinosControlCmdSetFormat sf; + PinosMessageSetFormat sf; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; @@ -510,10 +510,10 @@ spa_proxy_node_port_set_format (SpaNode *node, sf.port_id = port_id; sf.flags = flags; sf.format = (SpaFormat *) format; - pinos_connection_add_cmd (this->conn, PINOS_CONTROL_CMD_SET_FORMAT, &sf); + pinos_connection_add_message (this->conn, PINOS_MESSAGE_SET_FORMAT, &sf); if (!pinos_connection_flush (this->conn)) - spa_log_error (this->log, "proxy %p: error writing connection\n", this); + spa_log_error (this->log, "proxy %p: error writing connection", this); return SPA_RESULT_RETURN_ASYNC (sf.seq); } @@ -624,17 +624,17 @@ spa_proxy_node_port_use_buffers (SpaNode *node, SpaProxy *this; SpaProxyPort *port; unsigned int i, j; - PinosControlCmdAddMem am; - PinosControlCmdUseBuffers ub; + PinosMessageAddMem am; + PinosMessageUseBuffers ub; size_t size, n_mem; - PinosControlMemRef *memref; + PinosMessageMemRef *memref; void *p; if (node == NULL) return SPA_RESULT_INVALID_ARGUMENTS; this = SPA_CONTAINER_OF (node, SpaProxy, node); - spa_log_info (this->log, "proxy %p: use buffers %p %u\n", this, buffers, n_buffers); + spa_log_info (this->log, "proxy %p: use buffers %p %u", this, buffers, n_buffers); if (!CHECK_PORT (this, direction, port_id)) return SPA_RESULT_INVALID_PORT; @@ -680,7 +680,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, am.flags = d->flags; am.offset = d->offset; am.size = d->maxsize; - pinos_connection_add_cmd (this->conn, PINOS_CONTROL_CMD_ADD_MEM, &am); + pinos_connection_add_message (this->conn, PINOS_MESSAGE_ADD_MEM, &am); b->buffer.datas[j].type = SPA_DATA_TYPE_ID; b->buffer.datas[j].data = SPA_UINT32_TO_PTR (n_mem); @@ -693,7 +693,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, default: b->buffer.datas[j].type = SPA_DATA_TYPE_INVALID; b->buffer.datas[j].data = 0; - spa_log_error (this->log, "invalid memory type %d\n", d->type); + spa_log_error (this->log, "invalid memory type %d", d->type); break; } } @@ -707,7 +707,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, port->buffer_mem_fd = memfd_create ("spa-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING); if (ftruncate (port->buffer_mem_fd, size) < 0) { - spa_log_error (this->log, "Failed to truncate temporary file: %s\n", strerror (errno)); + spa_log_error (this->log, "Failed to truncate temporary file: %s", strerror (errno)); close (port->buffer_mem_fd); return SPA_RESULT_ERROR; } @@ -715,7 +715,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node, { unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL; if (fcntl (port->buffer_mem_fd, F_ADD_SEALS, seals) == -1) { - spa_log_error (this->log, "Failed to add seals: %s\n", strerror (errno)); + spa_log_error (this->log, "Failed to add seals: %s", strerror (errno)); } } #endif @@ -752,9 +752,9 @@ spa_proxy_node_port_use_buffers (SpaNode *node, am.flags = 0; am.offset = 0; am.size = size; - pinos_connection_add_cmd (this->conn, PINOS_CONTROL_CMD_ADD_MEM, &am); + pinos_connection_add_message (this->conn, PINOS_MESSAGE_ADD_MEM, &am); - memref = alloca (n_buffers * sizeof (PinosControlMemRef)); + memref = alloca (n_buffers * sizeof (PinosMessageMemRef)); for (i = 0; i < n_buffers; i++) { memref[i].mem_id = port->buffer_mem_id; memref[i].offset = port->buffers[i].offset; @@ -770,10 +770,10 @@ spa_proxy_node_port_use_buffers (SpaNode *node, ub.port_id = port_id; ub.n_buffers = n_buffers; ub.buffers = memref; - pinos_connection_add_cmd (this->conn, PINOS_CONTROL_CMD_USE_BUFFERS, &ub); + pinos_connection_add_message (this->conn, PINOS_MESSAGE_USE_BUFFERS, &ub); if (!pinos_connection_flush (this->conn)) - spa_log_error (this->log, "proxy %p: error writing connection\n", this); + spa_log_error (this->log, "proxy %p: error writing connection", this); return SPA_RESULT_RETURN_ASYNC (ub.seq); } @@ -820,7 +820,7 @@ copy_meta_in (SpaProxy *this, SpaProxyPort *port, uint32_t buffer_id) for (i = 0; i < b->outbuf->n_datas; i++) { b->outbuf->datas[i].size = b->buffer.datas[i].size; if (b->outbuf->datas[i].type == SPA_DATA_TYPE_MEMPTR) { - spa_log_info (this->log, "memcpy in %zd\n", b->buffer.datas[i].size); + spa_log_info (this->log, "memcpy in %zd", b->buffer.datas[i].size); memcpy (b->outbuf->datas[i].data, b->datas[i].data, b->buffer.datas[i].size); } } @@ -840,7 +840,7 @@ copy_meta_out (SpaProxy *this, SpaProxyPort *port, uint32_t buffer_id) for (i = 0; i < b->outbuf->n_datas; i++) { b->buffer.datas[i].size = b->outbuf->datas[i].size; if (b->datas[i].type == SPA_DATA_TYPE_MEMPTR) { - spa_log_info (this->log, "memcpy out %zd\n", b->outbuf->datas[i].size); + spa_log_info (this->log, "memcpy out %zd", b->outbuf->datas[i].size); memcpy (b->datas[i].data, b->outbuf->datas[i].data, b->outbuf->datas[i].size); } } @@ -855,7 +855,7 @@ spa_proxy_node_port_push_input (SpaNode *node, SpaProxyPort *port; unsigned int i; bool have_error = false; - PinosControlCmdProcessBuffer pb; + PinosMessageProcessBuffer pb; if (node == NULL || n_info == 0 || info == NULL) return SPA_RESULT_INVALID_ARGUMENTS; @@ -864,7 +864,7 @@ spa_proxy_node_port_push_input (SpaNode *node, for (i = 0; i < n_info; i++) { if (!CHECK_IN_PORT (this, SPA_DIRECTION_INPUT, info[i].port_id)) { - spa_log_warn (this->log, "invalid port %d\n", info[i].port_id); + spa_log_warn (this->log, "invalid port %d", info[i].port_id); info[i].status = SPA_RESULT_INVALID_PORT; have_error = true; continue; @@ -890,7 +890,7 @@ spa_proxy_node_port_push_input (SpaNode *node, pb.direction = SPA_DIRECTION_INPUT; pb.port_id = info[i].port_id; pb.buffer_id = info[i].buffer_id; - pinos_connection_add_cmd (this->rtconn, PINOS_CONTROL_CMD_PROCESS_BUFFER, &pb); + pinos_connection_add_message (this->rtconn, PINOS_MESSAGE_PROCESS_BUFFER, &pb); info[i].status = SPA_RESULT_OK; } @@ -899,7 +899,7 @@ spa_proxy_node_port_push_input (SpaNode *node, return SPA_RESULT_ERROR; if (!pinos_connection_flush (this->rtconn)) - spa_log_error (this->log, "proxy %p: error writing connection\n", this); + spa_log_error (this->log, "proxy %p: error writing connection", this); return SPA_RESULT_OK; } @@ -923,7 +923,7 @@ spa_proxy_node_port_pull_output (SpaNode *node, ProxyBuffer *b; if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, info[i].port_id)) { - spa_log_warn (this->log, "invalid port %u\n", info[i].port_id); + spa_log_warn (this->log, "invalid port %u", info[i].port_id); info[i].status = SPA_RESULT_INVALID_PORT; have_error = true; continue; @@ -960,7 +960,7 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node, uint32_t buffer_id) { SpaProxy *this; - PinosControlCmdNodeEvent cne; + PinosMessageNodeEvent cne; SpaNodeEventReuseBuffer rb; if (node == NULL) @@ -977,10 +977,10 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node, rb.event.size = sizeof (rb); rb.port_id = port_id; rb.buffer_id = buffer_id; - pinos_connection_add_cmd (this->rtconn, PINOS_CONTROL_CMD_NODE_EVENT, &cne); + pinos_connection_add_message (this->rtconn, PINOS_MESSAGE_NODE_EVENT, &cne); if (!pinos_connection_flush (this->rtconn)) - spa_log_error (this->log, "proxy %p: error writing connection\n", this); + spa_log_error (this->log, "proxy %p: error writing connection", this); return SPA_RESULT_OK; } @@ -1009,21 +1009,21 @@ spa_proxy_node_port_send_command (SpaNode *node, case SPA_NODE_COMMAND_DRAIN: case SPA_NODE_COMMAND_MARKER: { - PinosControlCmdPortCommand cpc; + PinosMessagePortCommand cpc; cpc.port_id = port_id; cpc.command = command; - pinos_connection_add_cmd (this->rtconn, PINOS_CONTROL_CMD_PORT_COMMAND, &cpc); + pinos_connection_add_message (this->rtconn, PINOS_MESSAGE_PORT_COMMAND, &cpc); if (!pinos_connection_flush (this->rtconn)) { - spa_log_error (this->log, "proxy %p: error writing connection\n", this); + spa_log_error (this->log, "proxy %p: error writing connection", this); res = SPA_RESULT_ERROR; } break; } default: - spa_log_warn (this->log, "unhandled command %d\n", command->type); + spa_log_warn (this->log, "unhandled command %d", command->type); res = SPA_RESULT_NOT_IMPLEMENTED; break; } @@ -1059,45 +1059,45 @@ parse_connection (SpaProxy *this) PinosConnection *conn = this->conn; while (pinos_connection_has_next (conn)) { - PinosControlCmd cmd = pinos_connection_get_cmd (conn); - - switch (cmd) { - case PINOS_CONTROL_CMD_INVALID: - case PINOS_CONTROL_CMD_ADD_PORT: - case PINOS_CONTROL_CMD_REMOVE_PORT: - case PINOS_CONTROL_CMD_SET_FORMAT: - case PINOS_CONTROL_CMD_SET_PROPERTY: - case PINOS_CONTROL_CMD_NODE_COMMAND: - case PINOS_CONTROL_CMD_PORT_COMMAND: - case PINOS_CONTROL_CMD_PROCESS_BUFFER: - spa_log_error (this->log, "proxy %p: got unexpected command %d\n", this, cmd); + PinosMessageType type = pinos_connection_get_type (conn); + + switch (type) { + case PINOS_MESSAGE_INVALID: + case PINOS_MESSAGE_ADD_PORT: + case PINOS_MESSAGE_REMOVE_PORT: + case PINOS_MESSAGE_SET_FORMAT: + case PINOS_MESSAGE_SET_PROPERTY: + case PINOS_MESSAGE_NODE_COMMAND: + case PINOS_MESSAGE_PORT_COMMAND: + case PINOS_MESSAGE_PROCESS_BUFFER: + spa_log_error (this->log, "proxy %p: got unexpected command %d", this, type); break; - case PINOS_CONTROL_CMD_NODE_UPDATE: + case PINOS_MESSAGE_NODE_UPDATE: { - PinosControlCmdNodeUpdate nu; + PinosMessageNodeUpdate nu; - if (!pinos_connection_parse_cmd (conn, &nu)) + if (!pinos_connection_parse_message (conn, &nu)) break; - if (nu.change_mask & PINOS_CONTROL_CMD_NODE_UPDATE_MAX_INPUTS) + if (nu.change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS) this->max_inputs = nu.max_input_ports; - if (nu.change_mask & PINOS_CONTROL_CMD_NODE_UPDATE_MAX_OUTPUTS) + if (nu.change_mask & PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS) this->max_outputs = nu.max_output_ports; - spa_log_info (this->log, "proxy %p: got node update %d, max_in %u, max_out %u\n", this, cmd, + spa_log_info (this->log, "proxy %p: got node update %d, max_in %u, max_out %u", this, type, this->max_inputs, this->max_outputs); break; } - case PINOS_CONTROL_CMD_PORT_UPDATE: + case PINOS_MESSAGE_PORT_UPDATE: { - PinosControlCmdPortUpdate pu; + PinosMessagePortUpdate pu; bool remove; - spa_log_info (this->log, "proxy %p: got port update %d\n", this, cmd); - if (!pinos_connection_parse_cmd (conn, &pu)) + spa_log_info (this->log, "proxy %p: got port update %d", this, type); + if (!pinos_connection_parse_message (conn, &pu)) break; if (!CHECK_PORT_ID (this, pu.direction, pu.port_id)) @@ -1113,21 +1113,21 @@ parse_connection (SpaProxy *this) break; } - case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: + case PINOS_MESSAGE_PORT_STATUS_CHANGE: { - spa_log_warn (this->log, "proxy %p: command not implemented %d\n", this, cmd); + spa_log_warn (this->log, "proxy %p: command not implemented %d", this, type); break; } - case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: + case PINOS_MESSAGE_NODE_STATE_CHANGE: { - PinosControlCmdNodeStateChange sc; + PinosMessageNodeStateChange sc; SpaNodeState old = this->node.state; - if (!pinos_connection_parse_cmd (conn, &sc)) + if (!pinos_connection_parse_message (conn, &sc)) break; - spa_log_info (this->log, "proxy %p: got node state change %d -> %d\n", this, old, sc.state); + spa_log_info (this->log, "proxy %p: got node state change %d -> %d", this, old, sc.state); this->node.state = sc.state; if (old == SPA_NODE_STATE_INIT) send_async_complete (this, 0, SPA_RESULT_OK); @@ -1135,16 +1135,16 @@ parse_connection (SpaProxy *this) break; } - case PINOS_CONTROL_CMD_ADD_MEM: + case PINOS_MESSAGE_ADD_MEM: break; - case PINOS_CONTROL_CMD_USE_BUFFERS: + case PINOS_MESSAGE_USE_BUFFERS: break; - case PINOS_CONTROL_CMD_NODE_EVENT: + case PINOS_MESSAGE_NODE_EVENT: { - PinosControlCmdNodeEvent cne; + PinosMessageNodeEvent cne; - if (!pinos_connection_parse_cmd (conn, &cne)) + if (!pinos_connection_parse_message (conn, &cne)) break; handle_node_event (this, cne.event); @@ -1162,63 +1162,63 @@ parse_rtconnection (SpaProxy *this) PinosConnection *conn = this->rtconn; while (pinos_connection_has_next (conn)) { - PinosControlCmd cmd = pinos_connection_get_cmd (conn); - - switch (cmd) { - case PINOS_CONTROL_CMD_INVALID: - case PINOS_CONTROL_CMD_NODE_UPDATE: - case PINOS_CONTROL_CMD_PORT_UPDATE: - case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: - case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: - case PINOS_CONTROL_CMD_ADD_PORT: - case PINOS_CONTROL_CMD_REMOVE_PORT: - case PINOS_CONTROL_CMD_SET_FORMAT: - case PINOS_CONTROL_CMD_SET_PROPERTY: - case PINOS_CONTROL_CMD_NODE_COMMAND: - case PINOS_CONTROL_CMD_ADD_MEM: - case PINOS_CONTROL_CMD_USE_BUFFERS: - spa_log_error (this->log, "proxy %p: got unexpected connection %d\n", this, cmd); + PinosMessageType type = pinos_connection_get_type (conn); + + switch (type) { + case PINOS_MESSAGE_INVALID: + case PINOS_MESSAGE_NODE_UPDATE: + case PINOS_MESSAGE_PORT_UPDATE: + case PINOS_MESSAGE_NODE_STATE_CHANGE: + case PINOS_MESSAGE_PORT_STATUS_CHANGE: + case PINOS_MESSAGE_ADD_PORT: + case PINOS_MESSAGE_REMOVE_PORT: + case PINOS_MESSAGE_SET_FORMAT: + case PINOS_MESSAGE_SET_PROPERTY: + case PINOS_MESSAGE_NODE_COMMAND: + case PINOS_MESSAGE_ADD_MEM: + case PINOS_MESSAGE_USE_BUFFERS: + spa_log_error (this->log, "proxy %p: got unexpected message %d", this, type); break; - case PINOS_CONTROL_CMD_PROCESS_BUFFER: + case PINOS_MESSAGE_PROCESS_BUFFER: { - PinosControlCmdProcessBuffer cmd; + PinosMessageProcessBuffer msg; SpaProxyPort *port; ProxyBuffer *b; - if (!pinos_connection_parse_cmd (conn, &cmd)) + if (!pinos_connection_parse_message (conn, &msg)) break; - if (!CHECK_PORT (this, cmd.direction, cmd.port_id)) + if (!CHECK_PORT (this, msg.direction, msg.port_id)) break; - port = cmd.direction == SPA_DIRECTION_INPUT ? &this->in_ports[cmd.port_id] : &this->out_ports[cmd.port_id]; + port = msg.direction == SPA_DIRECTION_INPUT ? &this->in_ports[msg.port_id] : &this->out_ports[msg.port_id]; - if (!CHECK_PORT_BUFFER (this, cmd.buffer_id, port)) + if (!CHECK_PORT_BUFFER (this, msg.buffer_id, port)) break; - copy_meta_in (this, port, cmd.buffer_id); + copy_meta_in (this, port, msg.buffer_id); - b = &port->buffers[cmd.buffer_id]; + b = &port->buffers[msg.buffer_id]; b->next = NULL; SPA_QUEUE_PUSH_TAIL (&port->ready, ProxyBuffer, next, b); break; } - case PINOS_CONTROL_CMD_NODE_EVENT: + case PINOS_MESSAGE_NODE_EVENT: { - PinosControlCmdNodeEvent cne; + PinosMessageNodeEvent cne; - if (!pinos_connection_parse_cmd (conn, &cne)) + if (!pinos_connection_parse_message (conn, &cne)) break; handle_node_event (this, cne.event); break; } - case PINOS_CONTROL_CMD_PORT_COMMAND: + case PINOS_MESSAGE_PORT_COMMAND: { - PinosControlCmdPortCommand cm; + PinosMessagePortCommand cm; - if (!pinos_connection_parse_cmd (conn, &cm)) + if (!pinos_connection_parse_message (conn, &cm)) break; break; @@ -1387,7 +1387,7 @@ pinos_client_node_dispose (GObject * object) PinosClientNode *this = PINOS_CLIENT_NODE (object); PinosClientNodePrivate *priv = this->priv; - g_debug ("client-node %p: dispose", this); + pinos_log_debug ("client-node %p: dispose", this); proxy_clear (priv->proxy); @@ -1400,7 +1400,7 @@ pinos_client_node_finalize (GObject * object) PinosClientNode *this = PINOS_CLIENT_NODE (object); PinosClientNodePrivate *priv = this->priv; - g_debug ("client-node %p: finalize", this); + pinos_log_debug ("client-node %p: finalize", this); g_clear_object (&priv->sockets[0]); g_clear_object (&priv->sockets[1]); @@ -1416,7 +1416,7 @@ pinos_client_node_constructed (GObject * object) PinosClientNode *this = PINOS_CLIENT_NODE (object); PinosClientNodePrivate *priv = this->priv; - g_debug ("client-node %p: constructed", this); + pinos_log_debug ("client-node %p: constructed", this); G_OBJECT_CLASS (pinos_client_node_parent_class)->constructed (object); @@ -1443,7 +1443,7 @@ pinos_client_node_init (PinosClientNode * node) { node->priv = PINOS_CLIENT_NODE_GET_PRIVATE (node); - g_debug ("client-node %p: new", node); + pinos_log_debug ("client-node %p: new", node); } /** diff --git a/pinos/server/client.c b/pinos/server/client.c index 62073722..6e8ecdbc 100644 --- a/pinos/server/client.c +++ b/pinos/server/client.c @@ -70,7 +70,7 @@ client_name_appeared_handler (GDBusConnection *connection, { PinosClient *client = user_data; - g_debug ("client %p: appeared %s %s", client, name, name_owner); + pinos_log_debug ("client %p: appeared %s %s", client, name, name_owner); g_signal_emit (client, signals[SIGNAL_APPEARED], 0, NULL); } @@ -83,7 +83,7 @@ client_name_vanished_handler (GDBusConnection *connection, PinosClient *client = user_data; PinosClientPrivate *priv = client->priv; - g_debug ("client %p: vanished %s", client, name); + pinos_log_debug ("client %p: vanished %s", client, name); g_signal_emit (client, signals[SIGNAL_VANISHED], 0, NULL); g_bus_unwatch_name (priv->id); @@ -186,7 +186,9 @@ client_register_object (PinosClient *client) priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel)); g_object_unref (skel); - g_debug ("client %p: register %s", client, priv->object_path); + client->id = pinos_map_insert_new (&daemon->registry.clients, client); + + pinos_log_debug ("client %p: register %s", client, priv->object_path); } static void @@ -195,8 +197,9 @@ client_unregister_object (PinosClient *client) PinosClientPrivate *priv = client->priv; PinosDaemon *daemon = priv->daemon; - g_debug ("client %p: unregister", client); + pinos_log_debug ("client %p: unregister", client); pinos_daemon_unexport (daemon, priv->object_path); + pinos_map_remove (&daemon->registry.clients, client->id); } static void @@ -206,7 +209,7 @@ pinos_client_dispose (GObject * object) PinosClientPrivate *priv = client->priv; GList *copy; - g_debug ("client %p: dispose", client); + pinos_log_debug ("client %p: dispose", client); copy = g_list_copy (priv->objects); g_list_free_full (copy, g_object_unref); g_list_free (priv->objects); @@ -222,7 +225,7 @@ pinos_client_finalize (GObject * object) PinosClient *client = PINOS_CLIENT (object); PinosClientPrivate *priv = client->priv; - g_debug ("client %p: finalize", client); + pinos_log_debug ("client %p: finalize", client); g_clear_object (&priv->daemon); g_clear_object (&priv->iface); g_free (priv->sender); @@ -238,7 +241,7 @@ pinos_client_constructed (GObject * object) { PinosClient *client = PINOS_CLIENT (object); - g_debug ("client %p: constructed", client); + pinos_log_debug ("client %p: constructed", client); client_watch_name (client); client_register_object (client); @@ -335,7 +338,7 @@ pinos_client_init (PinosClient * client) PinosClientPrivate *priv = client->priv = PINOS_CLIENT_GET_PRIVATE (client); priv->iface = pinos_client1_skeleton_new (); - g_debug ("client %p: new", client); + pinos_log_debug ("client %p: new", client); } /** @@ -373,7 +376,7 @@ pinos_client_remove (PinosClient *client) { g_return_if_fail (PINOS_IS_CLIENT (client)); - g_debug ("client %p: remove", client); + pinos_log_debug ("client %p: remove", client); g_signal_emit (client, signals[SIGNAL_REMOVE], 0, NULL); } diff --git a/pinos/server/client.h b/pinos/server/client.h index f071ae94..7ae26e44 100644 --- a/pinos/server/client.h +++ b/pinos/server/client.h @@ -47,6 +47,8 @@ typedef struct _PinosClientPrivate PinosClientPrivate; struct _PinosClient { GObject object; + uint32_t id; + PinosClientPrivate *priv; }; diff --git a/pinos/server/daemon.c b/pinos/server/daemon.c index eeb5b2ac..b21210da 100644 --- a/pinos/server/daemon.c +++ b/pinos/server/daemon.c @@ -26,6 +26,7 @@ #include "config.h" #include "pinos/client/pinos.h" +#include "pinos/client/log.h" #include "pinos/server/daemon.h" #include "pinos/server/node.h" @@ -50,8 +51,6 @@ struct _PinosDaemonPrivate gchar *object_path; - GList *nodes; - GHashTable *clients; PinosDataLoop *data_loop; PinosMainLoop *main_loop; @@ -61,7 +60,6 @@ struct _PinosDaemonPrivate GHashTable *node_factories; SpaSupport support[4]; - SpaLog log; }; enum @@ -80,7 +78,7 @@ handle_client_appeared (PinosClient *client, gpointer user_data) PinosDaemon *daemon = user_data; PinosDaemonPrivate *priv = daemon->priv; - g_debug ("daemon %p: appeared %p", daemon, client); + pinos_log_debug ("daemon %p: appeared %p", daemon, client); g_hash_table_insert (priv->clients, (gpointer) pinos_client_get_sender (client), client); } @@ -91,7 +89,7 @@ handle_client_vanished (PinosClient *client, gpointer user_data) PinosDaemon *daemon = user_data; PinosDaemonPrivate *priv = daemon->priv; - g_debug ("daemon %p: vanished %p", daemon, client); + pinos_log_debug ("daemon %p: vanished %p", daemon, client); g_hash_table_remove (priv->clients, (gpointer) pinos_client_get_sender (client)); } @@ -107,7 +105,7 @@ sender_get_client (PinosDaemon *daemon, if (client == NULL && create) { client = pinos_client_new (daemon, sender, NULL); - g_debug ("daemon %p: new client %p for %s", daemon, client, sender); + pinos_log_debug ("daemon %p: new client %p for %s", daemon, client, sender); g_signal_connect (client, "appeared", (GCallback) handle_client_appeared, @@ -126,7 +124,7 @@ handle_remove_node (PinosNode *node, { PinosClient *client = user_data; - g_debug ("client %p: node %p remove", daemon, node); + pinos_log_debug ("client %p: node %p remove", daemon, node); pinos_client_remove_object (client, G_OBJECT (node)); } @@ -149,7 +147,7 @@ handle_create_node (PinosDaemon1 *interface, sender = g_dbus_method_invocation_get_sender (invocation); client = sender_get_client (daemon, sender, TRUE); - g_debug ("daemon %p: create node: %s", daemon, sender); + pinos_log_debug ("daemon %p: create node: %s", daemon, sender); props = pinos_properties_from_variant (arg_properties); @@ -158,7 +156,6 @@ handle_create_node (PinosDaemon1 *interface, goto no_factory; node = pinos_node_factory_create_node (factory, - daemon, client, arg_name, props); @@ -175,7 +172,7 @@ handle_create_node (PinosDaemon1 *interface, client); object_path = pinos_node_get_object_path (node); - g_debug ("daemon %p: added node %p with path %s", daemon, node, object_path); + pinos_log_debug ("daemon %p: added node %p with path %s", daemon, node, object_path); g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", object_path)); g_object_unref (node); @@ -185,14 +182,14 @@ handle_create_node (PinosDaemon1 *interface, /* ERRORS */ no_factory: { - g_debug ("daemon %p: could find factory named %s", daemon, arg_factory_name); + pinos_log_debug ("daemon %p: could find factory named %s", daemon, arg_factory_name); g_dbus_method_invocation_return_dbus_error (invocation, "org.pinos.Error", "can't find factory"); return TRUE; } no_node: { - g_debug ("daemon %p: could create node named %s from factory %s", daemon, arg_name, arg_factory_name); + pinos_log_debug ("daemon %p: could create node named %s from factory %s", daemon, arg_name, arg_factory_name); g_dbus_method_invocation_return_dbus_error (invocation, "org.pinos.Error", "can't create node"); return TRUE; @@ -205,7 +202,7 @@ on_link_port_unlinked (PinosLink *link, PinosPort *port, PinosDaemon *this) { - g_debug ("daemon %p: link %p: port %p unlinked", this, link, port); + pinos_log_debug ("daemon %p: link %p: port %p unlinked", this, link, port); if (port->direction == PINOS_DIRECTION_OUTPUT && link->input) try_link_port (link->input->node, link->input, this); @@ -224,7 +221,7 @@ on_link_state_notify (GObject *obj, switch (state) { case PINOS_LINK_STATE_ERROR: { - g_debug ("daemon %p: link %p: state error: %s", daemon, link, error->message); + pinos_log_debug ("daemon %p: link %p: state error: %s", daemon, link, error->message); if (link->input && link->input->node) pinos_node_report_error (link->input->node, g_error_copy (error)); @@ -234,7 +231,7 @@ on_link_state_notify (GObject *obj, } case PINOS_LINK_STATE_UNLINKED: - g_debug ("daemon %p: link %p: unlinked", daemon, link); + pinos_log_debug ("daemon %p: link %p: unlinked", daemon, link); #if 0 g_set_error (&error, @@ -348,7 +345,7 @@ on_node_state_change (PinosNode *node, PinosNodeState state, PinosDaemon *this) { - g_debug ("daemon %p: node %p state change %s -> %s", this, node, + pinos_log_debug ("daemon %p: node %p state change %s -> %s", this, node, pinos_node_state_as_string (old), pinos_node_state_as_string (state)); @@ -362,7 +359,7 @@ on_node_added (PinosDaemon *daemon, PinosNode *node) PinosNodeState state; PinosDaemonPrivate *priv = daemon->priv; - g_debug ("daemon %p: node %p added", daemon, node); + pinos_log_debug ("daemon %p: node %p added", daemon, node); g_object_set (node, "data-loop", priv->data_loop, NULL); @@ -377,7 +374,7 @@ on_node_added (PinosDaemon *daemon, PinosNode *node) static void on_node_removed (PinosDaemon *daemon, PinosNode *node) { - g_debug ("daemon %p: node %p removed", daemon, node); + pinos_log_debug ("daemon %p: node %p removed", daemon, node); g_signal_handlers_disconnect_by_data (node, daemon); } @@ -401,7 +398,7 @@ handle_create_client_node (PinosDaemon1 *interface, sender = g_dbus_method_invocation_get_sender (invocation); client = sender_get_client (daemon, sender, TRUE); - g_debug ("daemon %p: create client-node: %s", daemon, sender); + pinos_log_debug ("daemon %p: create client-node: %s", daemon, sender); props = pinos_properties_from_variant (arg_properties); node = pinos_client_node_new (daemon, @@ -421,7 +418,7 @@ handle_create_client_node (PinosDaemon1 *interface, pinos_client_add_object (client, G_OBJECT (node)); object_path = pinos_node_get_object_path (PINOS_NODE (node)); - g_debug ("daemon %p: add client-node %p, %s", daemon, node, object_path); + pinos_log_debug ("daemon %p: add client-node %p, %s", daemon, node, object_path); g_object_unref (node); fdlist = g_unix_fd_list_new (); @@ -438,7 +435,7 @@ handle_create_client_node (PinosDaemon1 *interface, no_socket: { - g_debug ("daemon %p: could not create socket %s", daemon, error->message); + pinos_log_debug ("daemon %p: could not create socket %s", daemon, error->message); g_object_unref (node); goto exit_error; } @@ -470,7 +467,7 @@ handle_register_client_node (PinosDaemon1 *interface, sender = g_dbus_method_invocation_get_sender (invocation); client = sender_get_client (daemon, sender, TRUE); - g_debug ("daemon %p: register client-node: %s", daemon, sender); + pinos_log_debug ("daemon %p: register client-node: %s", daemon, sender); props = pinos_properties_from_variant (arg_properties); node = pinos_dbus_client_node_new (daemon, @@ -498,7 +495,7 @@ handle_register_client_node (PinosDaemon1 *interface, no_socket: { - g_debug ("daemon %p: could not create socket %s", daemon, error->message); + pinos_log_debug ("daemon %p: could not create socket %s", daemon, error->message); g_object_unref (node); goto exit_error; } @@ -606,7 +603,7 @@ pinos_daemon_start (PinosDaemon *daemon) priv = daemon->priv; g_return_if_fail (priv->id == 0); - g_debug ("daemon %p: start", daemon); + pinos_log_debug ("daemon %p: start", daemon); priv->id = g_bus_own_name (G_BUS_TYPE_SESSION, PINOS_DBUS_SERVICE, @@ -631,7 +628,7 @@ pinos_daemon_stop (PinosDaemon *daemon) g_return_if_fail (PINOS_IS_DAEMON (daemon)); - g_debug ("daemon %p: stop", daemon); + pinos_log_debug ("daemon %p: stop", daemon); if (priv->id != 0) { g_bus_unown_name (priv->id); @@ -688,13 +685,9 @@ void pinos_daemon_add_node (PinosDaemon *daemon, PinosNode *node) { - PinosDaemonPrivate *priv; - g_return_if_fail (PINOS_IS_DAEMON (daemon)); g_return_if_fail (PINOS_IS_NODE (node)); - priv = daemon->priv; - priv->nodes = g_list_prepend (priv->nodes, node); on_node_added (daemon, node); } @@ -709,14 +702,10 @@ void pinos_daemon_remove_node (PinosDaemon *daemon, PinosNode *node) { - PinosDaemonPrivate *priv; - g_return_if_fail (PINOS_IS_DAEMON (daemon)); g_return_if_fail (PINOS_IS_NODE (node)); - priv = daemon->priv; on_node_removed (daemon, node); - priv->nodes = g_list_remove (priv->nodes, node); } /** @@ -740,29 +729,27 @@ pinos_daemon_find_port (PinosDaemon *daemon, GPtrArray *format_filters, GError **error) { - PinosDaemonPrivate *priv; PinosPort *best = NULL; - GList *nodes; gboolean have_name; + guint i; g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL); - priv = daemon->priv; have_name = name ? strlen (name) > 0 : FALSE; - g_debug ("name \"%s\", %d", name, have_name); + pinos_log_debug ("name \"%s\", %d", name, have_name); - for (nodes = priv->nodes; nodes; nodes = g_list_next (nodes)) { - PinosNode *n = nodes->data; + for (i = 0; i < pinos_map_get_size (&daemon->registry.nodes); i++) { + PinosNode *n = pinos_map_lookup (&daemon->registry.nodes, i); - if (n->flags & PINOS_NODE_FLAG_REMOVING) + if (n == NULL || n->flags & PINOS_NODE_FLAG_REMOVING) continue; - g_debug ("node path \"%s\"", pinos_node_get_object_path (n)); + pinos_log_debug ("node path \"%s\"", pinos_node_get_object_path (n)); if (have_name) { if (g_str_has_suffix (pinos_node_get_object_path (n), name)) { - g_debug ("name \"%s\" matches node %p", name, n); + pinos_log_debug ("name \"%s\" matches node %p", name, n); best = pinos_node_get_free_port (n, pinos_direction_reverse (other_port->direction)); if (best) @@ -839,7 +826,7 @@ pinos_daemon_constructed (GObject * object) PinosDaemon *daemon = PINOS_DAEMON_CAST (object); PinosDaemonPrivate *priv = daemon->priv; - g_debug ("daemon %p: constructed", object); + pinos_log_debug ("daemon %p: constructed", object); pinos_daemon1_set_user_name (priv->iface, g_get_user_name ()); pinos_daemon1_set_host_name (priv->iface, g_get_host_name ()); pinos_daemon1_set_version (priv->iface, PACKAGE_VERSION); @@ -855,7 +842,7 @@ pinos_daemon_dispose (GObject * object) { PinosDaemon *daemon = PINOS_DAEMON_CAST (object); - g_debug ("daemon %p: dispose", object); + pinos_log_debug ("daemon %p: dispose", object); pinos_daemon_stop (daemon); @@ -868,7 +855,7 @@ pinos_daemon_finalize (GObject * object) PinosDaemon *daemon = PINOS_DAEMON_CAST (object); PinosDaemonPrivate *priv = daemon->priv; - g_debug ("daemon %p: finalize", object); + pinos_log_debug ("daemon %p: finalize", object); g_clear_object (&priv->server_manager); g_clear_object (&priv->iface); g_clear_object (&priv->data_loop); @@ -923,54 +910,18 @@ pinos_daemon_class_init (PinosDaemonClass * klass) } static void -do_logv (SpaLog *log, - SpaLogLevel level, - const char *file, - int line, - const char *func, - const char *fmt, - va_list args) - -{ - char text[16*1024], location[128]; - static const char *levels[] = { - "-", - "E", - "W", - "I", - "D", - "T", - }; - vsnprintf (text, sizeof(text), fmt, args); - snprintf (location, sizeof(location), "%s:%i %s()", file, line, func); - fprintf(stderr, "[%s][%s] %s", levels[level], location, text); -} - -static void -do_log (SpaLog *log, - SpaLogLevel level, - const char *file, - int line, - const char *func, - const char *fmt, ...) -{ - va_list args; - va_start (args, fmt); - do_logv (log, level, file, line, func, fmt, args); - va_end (args); -} - -static void pinos_daemon_init (PinosDaemon * daemon) { PinosDaemonPrivate *priv = daemon->priv = PINOS_DAEMON_GET_PRIVATE (daemon); - g_debug ("daemon %p: new", daemon); + pinos_log_debug ("daemon %p: new", daemon); priv->iface = pinos_daemon1_skeleton_new (); g_signal_connect (priv->iface, "handle-create-node", (GCallback) handle_create_node, daemon); g_signal_connect (priv->iface, "handle-create-client-node", (GCallback) handle_create_client_node, daemon); g_signal_connect (priv->iface, "handle-register-client-node", (GCallback) handle_register_client_node, daemon); + pinos_registry_init (&daemon->registry); + priv->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX); priv->clients = g_hash_table_new (g_str_hash, g_str_equal); priv->node_factories = g_hash_table_new_full (g_str_hash, @@ -979,17 +930,10 @@ pinos_daemon_init (PinosDaemon * daemon) g_object_unref); daemon->main_loop = pinos_main_loop_new (g_main_context_get_thread_default ()); - priv->data_loop = pinos_data_loop_new(); - priv->log.size = sizeof (SpaLog); - priv->log.info = NULL; - priv->log.level = SPA_LOG_LEVEL_INFO; - priv->log.log = do_log; - priv->log.logv = do_logv; - - daemon->map = spa_id_map_get_default(); - daemon->log = &priv->log; + daemon->map = pinos_id_map_get_default(); + daemon->log = pinos_log_get(); priv->support[0].uri = SPA_ID_MAP_URI; priv->support[0].data = daemon->map; diff --git a/pinos/server/daemon.h b/pinos/server/daemon.h index 6aa18421..6e7ab731 100644 --- a/pinos/server/daemon.h +++ b/pinos/server/daemon.h @@ -44,6 +44,7 @@ typedef struct _PinosDaemonPrivate PinosDaemonPrivate; #include <pinos/server/node-factory.h> #include <pinos/server/main-loop.h> #include <pinos/client/properties.h> +#include <pinos/server/registry.h> /** * PinosDaemon: @@ -61,6 +62,8 @@ struct _PinosDaemon { SpaSupport *support; unsigned int n_support; + PinosRegistry registry; + PinosDaemonPrivate *priv; }; diff --git a/pinos/server/data-loop.c b/pinos/server/data-loop.c index 8db6cc28..f0737782 100644 --- a/pinos/server/data-loop.c +++ b/pinos/server/data-loop.c @@ -27,9 +27,8 @@ #include <sys/time.h> #include <sys/resource.h> -#include <gio/gio.h> - #include "spa/include/spa/ringbuffer.h" +#include "pinos/client/log.h" #include "pinos/client/rtkit.h" #include "pinos/server/data-loop.h" @@ -63,7 +62,7 @@ struct _PinosDataLoopPrivate uint32_t counter; uint32_t seq; - gboolean running; + bool running; pthread_t thread; }; @@ -97,31 +96,31 @@ make_realtime (PinosDataLoop *this) sp.sched_priority = rtprio; if (pthread_setschedparam (pthread_self(), SCHED_RR|SCHED_RESET_ON_FORK, &sp) == 0) { - g_debug ("SCHED_OTHER|SCHED_RESET_ON_FORK worked."); + pinos_log_debug ("SCHED_OTHER|SCHED_RESET_ON_FORK worked."); return; } system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); rl.rlim_cur = rl.rlim_max = rttime; if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0) - g_debug ("setrlimit() failed: %s", strerror (errno)); + pinos_log_debug ("setrlimit() failed: %s", strerror (errno)); if (rttime >= 0) { r = getrlimit (RLIMIT_RTTIME, &rl); if (r >= 0 && (long long) rl.rlim_max > rttime) { - g_debug ("Clamping rlimit-rttime to %lld for RealtimeKit", rttime); + pinos_log_debug ("Clamping rlimit-rttime to %lld for RealtimeKit", rttime); rl.rlim_cur = rl.rlim_max = rttime; if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0) - g_debug ("setrlimit() failed: %s", strerror (errno)); + pinos_log_debug ("setrlimit() failed: %s", strerror (errno)); } } if (!pinos_rtkit_make_realtime (system_bus, 0, rtprio, &error)) { - g_debug ("could not make thread realtime: %s", error->message); + pinos_log_debug ("could not make thread realtime: %s", error->message); g_clear_error (&error); } else { - g_debug ("thread made realtime"); + pinos_log_debug ("thread made realtime"); } g_object_unref (system_bus); } @@ -136,7 +135,7 @@ loop (void *user_data) make_realtime (this); - g_debug ("data-loop %p: enter thread", this); + pinos_log_debug ("data-loop %p: enter thread", this); while (priv->running) { SpaPollNotifyData ndata; unsigned int n_idle = 0; @@ -196,7 +195,7 @@ loop (void *user_data) break; } if (r == 0) { - g_warning ("data-loop %p: select timeout should not happen", this); + pinos_log_warn ("data-loop %p: select timeout should not happen", this); continue; } @@ -206,7 +205,7 @@ loop (void *user_data) size_t offset; if (read (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t)) - g_warning ("data-loop %p: failed to read fd: %s", this, strerror (errno)); + pinos_log_warn ("data-loop %p: failed to read fd: %s", this, strerror (errno)); while (spa_ringbuffer_get_read_offset (&priv->buffer, &offset) > 0) { InvokeItem *item = SPA_MEMBER (priv->buffer_data, offset, InvokeItem); @@ -232,7 +231,7 @@ loop (void *user_data) } } } - g_debug ("data-loop %p: leave thread", this); + pinos_log_debug ("data-loop %p: leave thread", this); return NULL; } @@ -244,7 +243,7 @@ wakeup_thread (PinosDataLoop *this) uint64_t u = 1; if (write (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t)) - g_warning ("data-loop %p: failed to write fd: %s", this, strerror (errno)); + pinos_log_warn ("data-loop %p: failed to write fd: %s", this, strerror (errno)); } static void @@ -256,14 +255,14 @@ start_thread (PinosDataLoop *this) if (!priv->running) { priv->running = true; if ((err = pthread_create (&priv->thread, NULL, loop, this)) != 0) { - g_warning ("data-loop %p: can't create thread: %s", this, strerror (err)); + pinos_log_warn ("data-loop %p: can't create thread: %s", this, strerror (err)); priv->running = false; } } } static void -stop_thread (PinosDataLoop *this, gboolean in_thread) +stop_thread (PinosDataLoop *this, bool in_thread) { PinosDataLoopPrivate *priv = this->priv; @@ -282,7 +281,7 @@ do_add_item (SpaPoll *poll, { PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll); PinosDataLoopPrivate *priv = this->priv; - gboolean in_thread = pthread_equal (priv->thread, pthread_self()); + bool in_thread = pthread_equal (priv->thread, pthread_self()); item->id = ++priv->counter; priv->poll[priv->n_poll] = *item; @@ -304,7 +303,7 @@ do_update_item (SpaPoll *poll, { PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll); PinosDataLoopPrivate *priv = this->priv; - gboolean in_thread = pthread_equal (priv->thread, pthread_self()); + bool in_thread = pthread_equal (priv->thread, pthread_self()); unsigned int i; for (i = 0; i < priv->n_poll; i++) { @@ -326,7 +325,7 @@ do_remove_item (SpaPoll *poll, { PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll); PinosDataLoopPrivate *priv = this->priv; - gboolean in_thread = pthread_equal (priv->thread, pthread_self()); + bool in_thread = pthread_equal (priv->thread, pthread_self()); unsigned int i; for (i = 0; i < priv->n_poll; i++) { @@ -355,7 +354,7 @@ do_invoke (SpaPoll *poll, { PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll); PinosDataLoopPrivate *priv = this->priv; - gboolean in_thread = pthread_equal (priv->thread, pthread_self()); + bool in_thread = pthread_equal (priv->thread, pthread_self()); SpaRingbufferArea areas[2]; InvokeItem *item; SpaResult res; @@ -365,7 +364,7 @@ do_invoke (SpaPoll *poll, } else { spa_ringbuffer_get_write_areas (&priv->buffer, areas); if (areas[0].len < sizeof (InvokeItem)) { - g_warning ("queue full"); + pinos_log_warn ("queue full"); return SPA_RESULT_ERROR; } item = SPA_MEMBER (priv->buffer_data, areas[0].offset, InvokeItem); @@ -403,7 +402,7 @@ pinos_data_loop_constructed (GObject * obj) PinosDataLoop *this = PINOS_DATA_LOOP (obj); PinosDataLoopPrivate *priv = this->priv; - g_debug ("data-loop %p: constructed", this); + pinos_log_debug ("data-loop %p: constructed", this); G_OBJECT_CLASS (pinos_data_loop_parent_class)->constructed (obj); @@ -418,7 +417,7 @@ pinos_data_loop_dispose (GObject * obj) { PinosDataLoop *this = PINOS_DATA_LOOP (obj); - g_debug ("data-loop %p: dispose", this); + pinos_log_debug ("data-loop %p: dispose", this); stop_thread (this, FALSE); G_OBJECT_CLASS (pinos_data_loop_parent_class)->dispose (obj); @@ -429,7 +428,7 @@ pinos_data_loop_finalize (GObject * obj) { PinosDataLoop *this = PINOS_DATA_LOOP (obj); - g_debug ("data-loop %p: finalize", this); + pinos_log_debug ("data-loop %p: finalize", this); G_OBJECT_CLASS (pinos_data_loop_parent_class)->finalize (obj); } @@ -451,7 +450,7 @@ pinos_data_loop_init (PinosDataLoop * this) { PinosDataLoopPrivate *priv = this->priv = PINOS_DATA_LOOP_GET_PRIVATE (this); - g_debug ("data-loop %p: new", this); + pinos_log_debug ("data-loop %p: new", this); this->poll.size = sizeof (SpaPoll); this->poll.info = NULL; @@ -476,7 +475,7 @@ pinos_data_loop_new (void) return g_object_new (PINOS_TYPE_DATA_LOOP, NULL); } -gboolean +bool pinos_data_loop_in_thread (PinosDataLoop *loop) { return pthread_equal (loop->priv->thread, pthread_self()); diff --git a/pinos/server/data-loop.h b/pinos/server/data-loop.h index 3f3a26f0..2a1fb151 100644 --- a/pinos/server/data-loop.h +++ b/pinos/server/data-loop.h @@ -67,7 +67,7 @@ GType pinos_data_loop_get_type (void); PinosDataLoop * pinos_data_loop_new (void); -gboolean pinos_data_loop_in_thread (PinosDataLoop *loop); +bool pinos_data_loop_in_thread (PinosDataLoop *loop); G_END_DECLS diff --git a/pinos/server/dbus-client-node.c b/pinos/server/dbus-client-node.c index de8a6bff..dd9b2af9 100644 --- a/pinos/server/dbus-client-node.c +++ b/pinos/server/dbus-client-node.c @@ -27,6 +27,8 @@ #include <poll.h> #include <sys/eventfd.h> +#include "spa/lib/props.h" + #include "pinos/client/pinos.h" #include "pinos/client/enumtypes.h" #include "pinos/client/private.h" diff --git a/pinos/server/link.c b/pinos/server/link.c index 808f2a30..821269a4 100644 --- a/pinos/server/link.c +++ b/pinos/server/link.c @@ -22,7 +22,7 @@ #include <gio/gio.h> #include <spa/include/spa/video/format.h> -#include <spa/include/spa/debug.h> +#include <spa/lib/debug.h> #include "pinos/client/pinos.h" #include "pinos/client/enumtypes.h" @@ -181,7 +181,9 @@ link_register_object (PinosLink *this) priv->object_path = pinos_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel)); g_object_unref (skel); - g_debug ("link %p: register object %s", this, priv->object_path); + this->id = pinos_map_insert_new (&priv->daemon->registry.links, this); + + pinos_log_debug ("link %p: register object %s, id %u", this, priv->object_path, this->id); } static void @@ -189,8 +191,9 @@ link_unregister_object (PinosLink *this) { PinosLinkPrivate *priv = this->priv; - g_debug ("link %p: unregister object", this); + pinos_log_debug ("link %p: unregister object", this); pinos_daemon_unexport (priv->daemon, priv->object_path); + pinos_map_remove (&priv->daemon->registry.links, this->id); } static void @@ -200,7 +203,7 @@ pinos_link_update_state (PinosLink *link, PinosLinkState state) if (state != priv->state) { g_clear_error (&priv->error); - g_debug ("link %p: update state %s -> %s", link, + pinos_log_debug ("link %p: update state %s -> %s", link, pinos_link_state_as_string (priv->state), pinos_link_state_as_string (state)); priv->state = state; @@ -216,7 +219,7 @@ pinos_link_report_error (PinosLink *link, GError *error) g_clear_error (&priv->error); priv->error = error; priv->state = PINOS_LINK_STATE_ERROR; - g_debug ("link %p: got error state %s", link, error->message); + pinos_log_debug ("link %p: got error state %s", link, error->message); g_object_notify (G_OBJECT (link), "state"); } @@ -235,7 +238,7 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) /* both ports need a format */ if (in_state == SPA_NODE_STATE_CONFIGURE && out_state == SPA_NODE_STATE_CONFIGURE) { - g_debug ("link %p: doing negotiate format", this); + pinos_log_debug ("link %p: doing negotiate format", this); again: if ((res = spa_node_port_enum_formats (this->input->node->node, SPA_DIRECTION_INPUT, @@ -251,7 +254,7 @@ again: goto error; } } - g_debug ("Try filter:"); + pinos_log_debug ("Try filter:"); spa_debug_format (filter); if ((res = spa_node_port_enum_formats (this->output->node->node, @@ -270,7 +273,7 @@ again: "error output enum formats: %d", res); goto error; } - g_debug ("Got filtered:"); + pinos_log_debug ("Got filtered:"); spa_debug_format (format); spa_format_fixate (format); } else if (in_state == SPA_NODE_STATE_CONFIGURE && out_state > SPA_NODE_STATE_CONFIGURE) { @@ -300,11 +303,11 @@ again: } else return SPA_RESULT_OK; - g_debug ("link %p: doing set format", this); + pinos_log_debug ("link %p: doing set format", this); spa_debug_format (format); if (out_state == SPA_NODE_STATE_CONFIGURE) { - g_debug ("link %p: doing set format on output", this); + pinos_log_debug ("link %p: doing set format on output", this); if ((res = spa_node_port_set_format (this->output->node->node, SPA_DIRECTION_OUTPUT, this->output->port, @@ -317,7 +320,7 @@ again: goto error; } } else if (in_state == SPA_NODE_STATE_CONFIGURE) { - g_debug ("link %p: doing set format on input", this); + pinos_log_debug ("link %p: doing set format on input", this); if ((res = spa_node_port_set_format (this->input->node->node, SPA_DIRECTION_INPUT, this->input->port, @@ -351,6 +354,20 @@ find_param (const SpaPortInfo *info, SpaAllocParamType type) return NULL; } +static void * +find_meta_enable (const SpaPortInfo *info, SpaMetaType type) +{ + unsigned int i; + + for (i = 0; i < info->n_params; i++) { + if (info->params[i]->type == SPA_ALLOC_PARAM_TYPE_META_ENABLE && + ((SpaAllocParamMetaEnable*)info->params[i])->type == type) { + return info->params[i]; + } + } + return NULL; +} + static SpaResult do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) { @@ -365,7 +382,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) pinos_link_update_state (this, PINOS_LINK_STATE_ALLOCATING); - g_debug ("link %p: doing alloc buffers %p %p", this, this->output->node, this->input->node); + pinos_log_debug ("link %p: doing alloc buffers %p %p", this, this->output->node, this->input->node); /* find out what's possible */ if ((res = spa_node_port_get_info (this->output->node->node, SPA_DIRECTION_OUTPUT, @@ -394,7 +411,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) out_flags = oinfo->flags; if (out_flags & SPA_PORT_INFO_FLAG_LIVE) { - g_debug ("setting link as live"); + pinos_log_debug ("setting link as live"); this->output->node->live = true; this->input->node->live = true; } @@ -435,21 +452,33 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) if (priv->buffers == NULL) { SpaAllocParamBuffers *in_alloc, *out_alloc; - guint max_buffers = MAX_BUFFERS; - size_t minsize = 0, stride = 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); - minsize = SPA_MAX (minsize, in_alloc->minsize); - stride = SPA_MAX (stride, in_alloc->stride); - } - 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); - minsize = SPA_MAX (minsize, out_alloc->minsize); - stride = SPA_MAX (stride, out_alloc->stride); + SpaAllocParamMetaEnableRingbuffer *in_me, *out_me; + guint max_buffers; + size_t minsize, stride, blocks; + + in_me = find_meta_enable (iinfo, SPA_META_TYPE_RINGBUFFER); + out_me = find_meta_enable (oinfo, SPA_META_TYPE_RINGBUFFER); + if (in_me && out_me) { + max_buffers = 1; + minsize = SPA_MAX (out_me->minsize, in_me->minsize); + stride = SPA_MAX (out_me->stride, in_me->stride); + blocks = SPA_MAX (1, SPA_MAX (out_me->blocks, in_me->blocks)); + } else { + max_buffers = MAX_BUFFERS; + minsize = stride = 0; + blocks = 1; + 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); + minsize = SPA_MAX (minsize, in_alloc->minsize); + stride = SPA_MAX (stride, in_alloc->stride); + } + 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); + minsize = SPA_MAX (minsize, out_alloc->minsize); + stride = SPA_MAX (stride, out_alloc->stride); + } } if ((in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) || @@ -462,7 +491,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) priv->n_buffers = this->output->n_buffers; priv->buffers = this->output->buffers; priv->allocated = FALSE; - g_debug ("reusing %d output buffers %p", priv->n_buffers, priv->buffers); + pinos_log_debug ("reusing %d output buffers %p", priv->n_buffers, priv->buffers); } else { guint i, j; size_t hdr_size, buf_size, arr_size; @@ -486,7 +515,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) } hdr_size += n_metas * sizeof (SpaMeta); - buf_size = SPA_ROUND_UP_N (hdr_size + minsize, 64); + buf_size = SPA_ROUND_UP_N (hdr_size + (minsize * blocks), 64); priv->n_buffers = max_buffers; pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD | @@ -523,6 +552,17 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) b->metas[mi].type = pme->type; b->metas[mi].data = pd; b->metas[mi].size = spa_meta_type_get_size (pme->type); + + switch (pme->type) { + case SPA_META_TYPE_RINGBUFFER: + { + SpaMetaRingbuffer *rb = pd; + spa_ringbuffer_init (&rb->ringbuffer, minsize); + break; + } + default: + break; + } pd = SPA_MEMBER (pd, b->metas[mi].size, void); mi++; } @@ -543,7 +583,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) d->data = NULL; } } - g_debug ("allocated %d buffers %p %zd", priv->n_buffers, priv->buffers, minsize); + pinos_log_debug ("allocated %d buffers %p %zd", priv->n_buffers, priv->buffers, minsize); priv->allocated = TRUE; } @@ -564,7 +604,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) this->output->allocated = TRUE; this->output->buffer_mem = priv->buffer_mem; priv->allocated = FALSE; - g_debug ("allocated %d buffers %p from output port", priv->n_buffers, priv->buffers); + pinos_log_debug ("allocated %d buffers %p from output port", priv->n_buffers, priv->buffers); } else if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) { if ((res = spa_node_port_alloc_buffers (this->input->node->node, SPA_DIRECTION_INPUT, @@ -582,12 +622,12 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) this->input->allocated = TRUE; this->input->buffer_mem = priv->buffer_mem; priv->allocated = FALSE; - g_debug ("allocated %d buffers %p from input port", priv->n_buffers, priv->buffers); + pinos_log_debug ("allocated %d buffers %p from input port", priv->n_buffers, priv->buffers); } } if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) { - g_debug ("using %d buffers %p on input port", priv->n_buffers, priv->buffers); + pinos_log_debug ("using %d buffers %p on input port", priv->n_buffers, priv->buffers); if ((res = spa_node_port_use_buffers (this->input->node->node, SPA_DIRECTION_INPUT, this->input->port, @@ -604,7 +644,7 @@ 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 buffers %p on output port", priv->n_buffers, priv->buffers); + pinos_log_debug ("using %d buffers %p on output port", priv->n_buffers, priv->buffers); if ((res = spa_node_port_use_buffers (this->output->node->node, SPA_DIRECTION_OUTPUT, this->output->port, @@ -673,7 +713,7 @@ check_states (PinosLink *this, PinosLinkPrivate *priv = this->priv; if (res != SPA_RESULT_OK) { - g_warning ("link %p: error: %d", this, res); + pinos_log_warn ("link %p: error: %d", this, res); return res; } @@ -684,7 +724,7 @@ again: in_state = this->input->node->node->state; out_state = this->output->node->node->state; - g_debug ("link %p: input state %d, output state %d", this, in_state, out_state); + pinos_log_debug ("link %p: input state %d, output state %d", this, in_state, out_state); if ((res = do_negotiate (this, in_state, out_state)) != SPA_RESULT_OK) goto exit; @@ -714,7 +754,7 @@ on_async_complete_notify (PinosNode *node, PinosLink *this) { PinosLinkPrivate *priv = this->priv; - g_debug ("link %p: node %p async complete %d %d", this, node, seq, res); + pinos_log_debug ("link %p: node %p async complete %d %d", this, node, seq, res); pinos_main_loop_defer_complete (priv->main_loop, this, seq, res); } @@ -782,7 +822,7 @@ on_node_remove (PinosNode *node, PinosLink *this) priv->buffers = NULL; priv->n_buffers = 0; - g_debug ("link %p: clear input allocated buffers on port %p", link, other); + pinos_log_debug ("link %p: clear input allocated buffers on port %p", link, other); pinos_port_clear_buffers (other); } @@ -814,7 +854,7 @@ pinos_link_constructed (GObject * object) G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object); on_property_notify (G_OBJECT (this), NULL, this); - g_debug ("link %p: constructed %p:%d -> %p:%d", this, + pinos_log_debug ("link %p: constructed %p:%d -> %p:%d", this, this->output->node, this->output->port, this->input->node, this->input->port); link_register_object (this); @@ -826,7 +866,7 @@ pinos_link_dispose (GObject * object) PinosLink *this = PINOS_LINK (object); PinosLinkPrivate *priv = this->priv; - g_debug ("link %p: dispose", this); + pinos_log_debug ("link %p: dispose", this); if (this->input && this->input->node) g_signal_handlers_disconnect_by_data (this->input->node, this); @@ -853,7 +893,7 @@ pinos_link_finalize (GObject * object) PinosLink *this = PINOS_LINK (object); PinosLinkPrivate *priv = this->priv; - g_debug ("link %p: finalize", this); + pinos_log_debug ("link %p: finalize", this); g_clear_object (&priv->daemon); g_clear_object (&priv->iface); g_free (priv->object_path); @@ -963,7 +1003,7 @@ pinos_link_init (PinosLink * this) PinosLinkPrivate *priv = this->priv = PINOS_LINK_GET_PRIVATE (this); priv->iface = pinos_link1_skeleton_new (); - g_debug ("link %p: new", this); + pinos_log_debug ("link %p: new", this); priv->state = PINOS_LINK_STATE_INIT; } @@ -976,7 +1016,7 @@ pinos_link_init (PinosLink * this) void pinos_link_remove (PinosLink *this) { - g_debug ("link %p: remove", this); + pinos_log_debug ("link %p: remove", this); g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL); } diff --git a/pinos/server/link.h b/pinos/server/link.h index 49df3981..46c02625 100644 --- a/pinos/server/link.h +++ b/pinos/server/link.h @@ -50,6 +50,8 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate; struct _PinosLink { GObject object; + uint32_t id; + PinosPort *output; PinosPort *input; diff --git a/pinos/server/main-loop.c b/pinos/server/main-loop.c index 375abc0b..df2a24df 100644 --- a/pinos/server/main-loop.c +++ b/pinos/server/main-loop.c @@ -27,6 +27,7 @@ #include "spa/include/spa/queue.h" #include "spa/include/spa/ringbuffer.h" +#include "pinos/client/log.h" #include "pinos/server/main-loop.h" #define PINOS_MAIN_LOOP_GET_PRIVATE(loop) \ @@ -130,7 +131,7 @@ do_add_item (SpaPoll *poll, item->id = g_source_attach (source, g_main_context_get_thread_default ()); g_source_unref (source); - g_debug ("added main poll %d", item->id); + pinos_log_debug ("added main poll %d", item->id); return SPA_RESULT_OK; } @@ -139,7 +140,7 @@ static SpaResult do_update_item (SpaPoll *poll, SpaPollItem *item) { - g_debug ("update main poll %d", item->id); + pinos_log_debug ("update main poll %d", item->id); return SPA_RESULT_OK; } @@ -149,7 +150,7 @@ do_remove_item (SpaPoll *poll, { GSource *source; - g_debug ("remove main poll %d", item->id); + pinos_log_debug ("remove main poll %d", item->id); source = g_main_context_find_source_by_id (g_main_context_get_thread_default (), item->id); g_source_destroy (source); @@ -167,7 +168,7 @@ main_loop_dispatch (SpaPollNotifyData *data) InvokeItem *item; if (read (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t)) - g_warning ("main-loop %p: failed to read fd", strerror (errno)); + pinos_log_warn ("main-loop %p: failed to read fd", strerror (errno)); while (spa_ringbuffer_get_read_offset (&priv->buffer, &offset) > 0) { item = SPA_MEMBER (priv->buffer_data, offset, InvokeItem); @@ -199,7 +200,7 @@ do_invoke (SpaPoll *poll, } else { spa_ringbuffer_get_write_areas (&priv->buffer, areas); if (areas[0].len < sizeof (InvokeItem)) { - g_warning ("queue full"); + pinos_log_warn ("queue full"); return SPA_RESULT_ERROR; } item = SPA_MEMBER (priv->buffer_data, areas[0].offset, InvokeItem); @@ -222,7 +223,7 @@ do_invoke (SpaPoll *poll, spa_ringbuffer_write_advance (&priv->buffer, item->item_size); if (write (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t)) - g_warning ("data-loop %p: failed to write fd", strerror (errno)); + pinos_log_warn ("data-loop %p: failed to write fd", strerror (errno)); res = SPA_RESULT_RETURN_ASYNC (seq); } @@ -276,7 +277,7 @@ pinos_main_loop_constructed (GObject * obj) PinosMainLoop *this = PINOS_MAIN_LOOP (obj); PinosMainLoopPrivate *priv = this->priv; - g_debug ("main-loop %p: constructed", this); + pinos_log_debug ("main-loop %p: constructed", this); priv->loop = g_main_loop_new (priv->context, FALSE); priv->fds[0].fd = eventfd (0, 0); @@ -301,7 +302,7 @@ pinos_main_loop_dispose (GObject * obj) { PinosMainLoop *this = PINOS_MAIN_LOOP (obj); - g_debug ("main-loop %p: dispose", this); + pinos_log_debug ("main-loop %p: dispose", this); G_OBJECT_CLASS (pinos_main_loop_parent_class)->dispose (obj); } @@ -312,7 +313,7 @@ pinos_main_loop_finalize (GObject * obj) PinosMainLoop *this = PINOS_MAIN_LOOP (obj); PinosMainLoopPrivate *priv = this->priv; - g_debug ("main-loop %p: finalize", this); + pinos_log_debug ("main-loop %p: finalize", this); g_slice_free_chain (WorkItem, priv->free_list, next); @@ -349,7 +350,7 @@ pinos_main_loop_init (PinosMainLoop * this) { PinosMainLoopPrivate *priv = this->priv = PINOS_MAIN_LOOP_GET_PRIVATE (this); - g_debug ("main-loop %p: new", this); + pinos_log_debug ("main-loop %p: new", this); this->poll.size = sizeof (SpaPoll); this->poll.info = NULL; @@ -400,7 +401,7 @@ process_work_queue (PinosMainLoop *this) prev->next = next; if (item->func) { - g_debug ("main-loop %p: process work item %p", this, item->obj); + pinos_log_debug ("main-loop %p: process work item %p", this, item->obj); item->func (item->obj, item->data, item->res, item->id); } if (item->notify) @@ -445,12 +446,12 @@ pinos_main_loop_defer (PinosMainLoop *loop, if (SPA_RESULT_IS_ASYNC (res)) { item->seq = SPA_RESULT_ASYNC_SEQ (res); item->res = res; - g_debug ("main-loop %p: defer async %d for object %p", loop, item->seq, obj); + pinos_log_debug ("main-loop %p: defer async %d for object %p", loop, item->seq, obj); } else { item->seq = SPA_ID_INVALID; item->res = res; have_work = TRUE; - g_debug ("main-loop %p: defer object %p", loop, obj); + pinos_log_debug ("main-loop %p: defer object %p", loop, obj); } SPA_QUEUE_PUSH_TAIL (&priv->work, WorkItem, next, item); @@ -474,7 +475,7 @@ pinos_main_loop_defer_cancel (PinosMainLoop *loop, for (item = priv->work.head; item; item = item->next) { if ((id == 0 || item->id == id) && (obj == NULL || item->obj == obj)) { - g_debug ("main-loop %p: cancel defer %d for object %p", loop, item->seq, item->obj); + pinos_log_debug ("main-loop %p: cancel defer %d for object %p", loop, item->seq, item->obj); item->seq = SPA_ID_INVALID; item->func = NULL; have_work = TRUE; @@ -499,14 +500,14 @@ pinos_main_loop_defer_complete (PinosMainLoop *loop, for (item = priv->work.head; item; item = item->next) { if (item->obj == obj && item->seq == seq) { - g_debug ("main-loop %p: found defered %d for object %p", loop, seq, obj); + pinos_log_debug ("main-loop %p: found defered %d for object %p", loop, seq, obj); item->seq = SPA_ID_INVALID; item->res = res; have_work = TRUE; } } if (!have_work) - g_debug ("main-loop %p: no defered %d found for object %p", loop, seq, obj); + pinos_log_debug ("main-loop %p: no defered %d found for object %p", loop, seq, obj); if (priv->work_id == 0 && have_work) priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop); diff --git a/pinos/server/meson.build b/pinos/server/meson.build index 51798bba..a142a571 100644 --- a/pinos/server/meson.build +++ b/pinos/server/meson.build @@ -10,6 +10,7 @@ pinoscore_headers = [ 'module.h', 'node.h', 'node-factory.h', + 'registry.h', 'utils.h', ] @@ -25,6 +26,7 @@ pinoscore_sources = [ 'module.c', 'node.c', 'node-factory.c', + 'registry.c', 'utils.c', ] diff --git a/pinos/server/module.c b/pinos/server/module.c index 32cc2b2f..1b36862f 100644 --- a/pinos/server/module.c +++ b/pinos/server/module.c @@ -180,7 +180,7 @@ find_module (const gchar * path, const gchar *name) dir = g_dir_open (path, 0, &err); if (dir == NULL) { - g_warning ("could not open %s: %s", path, err->message); + pinos_log_warn ("could not open %s: %s", path, err->message); g_error_free (err); return NULL; } @@ -241,7 +241,7 @@ pinos_module_load (PinosDaemon * daemon, gchar **l; gint i; - g_debug ("PINOS_MODULE_DIR set to: %s", module_dir); + pinos_log_debug ("PINOS_MODULE_DIR set to: %s", module_dir); l = g_strsplit (module_dir, G_SEARCHPATH_SEPARATOR_S, 0); for (i = 0; l[i] != NULL; i++) { @@ -251,7 +251,7 @@ pinos_module_load (PinosDaemon * daemon, } g_strfreev (l); } else { - g_debug ("moduledir set to: %s", MODULEDIR); + pinos_log_debug ("moduledir set to: %s", MODULEDIR); filename = find_module (MODULEDIR, name); } @@ -262,7 +262,7 @@ pinos_module_load (PinosDaemon * daemon, return NULL; } - g_debug ("trying to load module: %s (%s)", name, filename); + pinos_log_debug ("trying to load module: %s (%s)", name, filename); gmodule = g_module_open (filename, G_MODULE_BIND_LOCAL); g_free (filename); @@ -295,7 +295,7 @@ pinos_module_load (PinosDaemon * daemon, return NULL; } - g_debug ("loaded module: %s", module->name); + pinos_log_debug ("loaded module: %s", module->name); return module; } diff --git a/pinos/server/node-factory.c b/pinos/server/node-factory.c index 6acf66be..c727a522 100644 --- a/pinos/server/node-factory.c +++ b/pinos/server/node-factory.c @@ -25,6 +25,8 @@ struct _PinosNodeFactoryPrivate { + PinosDaemon *daemon; + gchar *name; }; @@ -33,6 +35,7 @@ G_DEFINE_ABSTRACT_TYPE (PinosNodeFactory, pinos_node_factory, G_TYPE_OBJECT); enum { PROP_0, + PROP_DAEMON, PROP_NAME, }; @@ -46,6 +49,10 @@ pinos_node_factory_get_property (GObject *_object, PinosNodeFactoryPrivate *priv = factory->priv; switch (prop_id) { + case PROP_DAEMON: + g_value_set_object (value, priv->daemon); + break; + case PROP_NAME: g_value_set_string (value, priv->name); break; @@ -66,6 +73,10 @@ pinos_node_factory_set_property (GObject *_object, PinosNodeFactoryPrivate *priv = factory->priv; switch (prop_id) { + case PROP_DAEMON: + priv->daemon = g_value_dup_object (value); + break; + case PROP_NAME: priv->name = g_value_dup_string (value); break; @@ -80,9 +91,12 @@ static void pinos_node_factory_constructed (GObject * obj) { PinosNodeFactory *factory = PINOS_NODE_FACTORY (obj); + PinosNodeFactoryPrivate *priv = factory->priv; g_debug ("node factory %p: constructed", factory); + factory->id = pinos_map_insert_new (&priv->daemon->registry.node_factories, factory); + G_OBJECT_CLASS (pinos_node_factory_parent_class)->constructed (obj); } @@ -93,6 +107,7 @@ pinos_node_factory_finalize (GObject * obj) PinosNodeFactoryPrivate *priv = factory->priv; g_debug ("node factory %p: finalize", factory); + pinos_map_remove (&priv->daemon->registry.node_factories, factory->id); g_free (priv->name); @@ -112,6 +127,16 @@ pinos_node_factory_class_init (PinosNodeFactoryClass * klass) gobject_class->get_property = pinos_node_factory_get_property; g_object_class_install_property (gobject_class, + PROP_DAEMON, + g_param_spec_object ("daemon", + "Daemon", + "The Daemon", + PINOS_TYPE_DAEMON, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, PROP_NAME, g_param_spec_string ("name", "Name", @@ -152,7 +177,6 @@ pinos_node_factory_get_name (PinosNodeFactory *factory) /** * pinos_node_factory_create_node: * @factory: A #PinosNodeFactory - * @daemon: a #PinosDaemon * @client: the owner client * @name: node name * @props: #PinosProperties for the node @@ -163,7 +187,6 @@ pinos_node_factory_get_name (PinosNodeFactory *factory) */ PinosNode * pinos_node_factory_create_node (PinosNodeFactory *factory, - PinosDaemon *daemon, PinosClient *client, const gchar *name, PinosProperties *props) @@ -177,5 +200,5 @@ pinos_node_factory_create_node (PinosNodeFactory *factory, return NULL; g_debug ("node factory %p: create node", factory); - return klass->create_node (factory, daemon, client, name, props); + return klass->create_node (factory, factory->priv->daemon, client, name, props); } diff --git a/pinos/server/node-factory.h b/pinos/server/node-factory.h index fec1d4c0..9849451d 100644 --- a/pinos/server/node-factory.h +++ b/pinos/server/node-factory.h @@ -48,6 +48,8 @@ typedef struct _PinosNodeFactoryPrivate PinosNodeFactoryPrivate; struct _PinosNodeFactory { GObject object; + uint32_t id; + PinosNodeFactoryPrivate *priv; }; @@ -71,7 +73,6 @@ struct _PinosNodeFactoryClass { GType pinos_node_factory_get_type (void); PinosNode * pinos_node_factory_create_node (PinosNodeFactory *factory, - PinosDaemon *daemon, PinosClient *client, const gchar *name, PinosProperties *props); diff --git a/pinos/server/node.c b/pinos/server/node.c index dc8bfd6e..ac0c31dd 100644 --- a/pinos/server/node.c +++ b/pinos/server/node.c @@ -144,7 +144,7 @@ update_port_ids (PinosNode *node, gboolean create) max_output_ports, output_port_ids); - g_debug ("node %p: update_port ids %u/%u, %u/%u", node, + pinos_log_debug ("node %p: update_port ids %u/%u, %u/%u", node, n_input_ports, max_input_ports, n_output_ports, max_output_ports); i = 0; @@ -157,7 +157,7 @@ update_port_ids (PinosNode *node, gboolean create) ports = g_list_next (ports); } else if ((p && i < n_input_ports && input_port_ids[i] < p->port) || i < n_input_ports) { PinosPort *np; - g_debug ("node %p: input port added %d", node, input_port_ids[i]); + pinos_log_debug ("node %p: input port added %d", node, input_port_ids[i]); np = new_pinos_port (node, PINOS_DIRECTION_INPUT, input_port_ids[i]); priv->input_ports = g_list_insert_before (priv->input_ports, ports, np); @@ -167,7 +167,7 @@ update_port_ids (PinosNode *node, gboolean create) i++; } else if (p) { GList *next; - g_debug ("node %p: input port removed %d", node, p->port); + pinos_log_debug ("node %p: input port removed %d", node, p->port); next = g_list_next (ports); priv->input_ports = g_list_delete_link (priv->input_ports, ports); @@ -191,7 +191,7 @@ update_port_ids (PinosNode *node, gboolean create) ports = g_list_next (ports); } else if ((p && i < n_output_ports && output_port_ids[i] < p->port) || i < n_output_ports) { PinosPort *np; - g_debug ("node %p: output port added %d", node, output_port_ids[i]); + pinos_log_debug ("node %p: output port added %d", node, output_port_ids[i]); np = new_pinos_port (node, PINOS_DIRECTION_OUTPUT, output_port_ids[i]); priv->output_ports = g_list_insert_before (priv->output_ports, ports, np); @@ -201,7 +201,7 @@ update_port_ids (PinosNode *node, gboolean create) i++; } else if (p) { GList *next; - g_debug ("node %p: output port removed %d", node, p->port); + pinos_log_debug ("node %p: output port removed %d", node, p->port); next = g_list_next (ports); priv->output_ports = g_list_delete_link (priv->output_ports, ports); @@ -231,12 +231,12 @@ pause_node (PinosNode *this) SpaResult res; SpaNodeCommand cmd; - g_debug ("node %p: pause node", this); + pinos_log_debug ("node %p: pause node", this); cmd.type = SPA_NODE_COMMAND_PAUSE; cmd.size = sizeof (cmd); if ((res = spa_node_send_command (this->node, &cmd)) < 0) - g_debug ("got error %d", res); + pinos_log_debug ("got error %d", res); return res; } @@ -247,12 +247,12 @@ start_node (PinosNode *this) SpaResult res; SpaNodeCommand cmd; - g_debug ("node %p: start node", this); + pinos_log_debug ("node %p: start node", this); cmd.type = SPA_NODE_COMMAND_START; cmd.size = sizeof (cmd); if ((res = spa_node_send_command (this->node, &cmd)) < 0) - g_debug ("got error %d", res); + pinos_log_debug ("got error %d", res); return res; } @@ -264,12 +264,12 @@ suspend_node (PinosNode *this) SpaResult res = SPA_RESULT_OK; GList *walk; - g_debug ("node %p: suspend node", this); + pinos_log_debug ("node %p: suspend node", this); for (walk = priv->input_ports; walk; walk = g_list_next (walk)) { PinosPort *p = walk->data; if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_INPUT, p->port, 0, NULL)) < 0) - g_warning ("error unset format output: %d", res); + pinos_log_warn ("error unset format output: %d", res); p->buffers = NULL; p->n_buffers = 0; if (p->allocated) @@ -279,7 +279,7 @@ suspend_node (PinosNode *this) for (walk = priv->output_ports; walk; walk = g_list_next (walk)) { PinosPort *p = walk->data; if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_OUTPUT, p->port, 0, NULL)) < 0) - g_warning ("error unset format output: %d", res); + pinos_log_warn ("error unset format output: %d", res); p->buffers = NULL; p->n_buffers = 0; if (p->allocated) @@ -314,7 +314,7 @@ send_clock_update (PinosNode *this) cu.state = SPA_CLOCK_STATE_RUNNING; if ((res = spa_node_send_command (this->node, &cu.command)) < 0) - g_debug ("got error %d", res); + pinos_log_debug ("got error %d", res); } static SpaResult @@ -341,7 +341,7 @@ do_read_link (SpaPoll *poll, iinfo[0].flags = SPA_PORT_INPUT_FLAG_NONE; if ((res = spa_node_port_push_input (link->input->node->node, 1, iinfo)) < 0) - g_warning ("node %p: error pushing buffer: %d, %d", this, res, iinfo[0].status); + pinos_log_warn ("node %p: error pushing buffer: %d, %d", this, res, iinfo[0].status); spa_ringbuffer_read_advance (&link->ringbuffer, 1); link->in_ready--; @@ -367,7 +367,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data) { SpaNodeEventAsyncComplete *ac = (SpaNodeEventAsyncComplete *) event; - g_debug ("node %p: async complete event %d %d", this, ac->seq, ac->res); + pinos_log_debug ("node %p: async complete event %d %d", this, ac->seq, ac->res); if (!pinos_main_loop_defer_complete (priv->main_loop, this, ac->seq, ac->res)) g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res); break; @@ -405,7 +405,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data) oinfo[0].port_id = ho->port_id; if ((res = spa_node_port_pull_output (node, 1, oinfo)) < 0) { - g_warning ("node %p: got pull error %d, %d", this, res, oinfo[0].status); + pinos_log_warn ("node %p: got pull error %d, %d", this, res, oinfo[0].status); break; } @@ -434,7 +434,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data) } if (!pushed) { if ((res = spa_node_port_reuse_buffer (node, oinfo[0].port_id, oinfo[0].buffer_id)) < 0) - g_warning ("node %p: error reuse buffer: %d", node, res); + pinos_log_warn ("node %p: error reuse buffer: %d", node, res); } break; } @@ -453,7 +453,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data) if ((res = spa_node_port_reuse_buffer (link->output->node->node, link->output->port, rb->buffer_id)) < 0) - g_warning ("node %p: error reuse buffer: %d", node, res); + pinos_log_warn ("node %p: error reuse buffer: %d", node, res); } break; } @@ -470,7 +470,7 @@ handle_remove (PinosNode1 *interface, { PinosNode *this = user_data; - g_debug ("node %p: remove", this); + pinos_log_debug ("node %p: remove", this); pinos_node_remove (this); g_dbus_method_invocation_return_value (invocation, @@ -554,7 +554,7 @@ pinos_node_set_property (GObject *_object, if (priv->data_loop) { if ((res = spa_node_set_event_callback (this->node, on_node_event, this)) < 0) - g_warning ("node %p: error setting callback", this); + pinos_log_warn ("node %p: error setting callback", this); } break; } @@ -599,7 +599,9 @@ node_register_object (PinosNode *this) priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel)); g_object_unref (skel); - g_debug ("node %p: register object %s", this, priv->object_path); + this->id = pinos_map_insert_new (&daemon->registry.nodes, this); + pinos_log_debug ("node %p: register object %s, id %u", this, priv->object_path, this->id); + pinos_daemon_add_node (daemon, this); return; @@ -610,10 +612,11 @@ node_unregister_object (PinosNode *this) { PinosNodePrivate *priv = this->priv; - g_debug ("node %p: unregister object %s", this, priv->object_path); + pinos_log_debug ("node %p: unregister object %s", this, priv->object_path); pinos_daemon_unexport (priv->daemon, priv->object_path); g_clear_pointer (&priv->object_path, g_free); pinos_daemon_remove_node (priv->daemon, this); + pinos_map_remove (&priv->daemon->registry.nodes, this->id); } static void @@ -645,7 +648,7 @@ init_complete (PinosNode *this) PinosNodePrivate *priv = this->priv; update_port_ids (this, FALSE); - g_debug ("node %p: init completed", this); + pinos_log_debug ("node %p: init completed", this); priv->async_init = FALSE; on_property_notify (G_OBJECT (this), NULL, this); pinos_node_update_state (this, PINOS_NODE_STATE_SUSPENDED); @@ -657,7 +660,7 @@ pinos_node_constructed (GObject * obj) PinosNode *this = PINOS_NODE (obj); PinosNodePrivate *priv = this->priv; - g_debug ("node %p: constructed", this); + pinos_log_debug ("node %p: constructed", this); priv->main_loop = priv->daemon->main_loop; @@ -696,7 +699,7 @@ pinos_node_dispose (GObject * obj) PinosNode *node = PINOS_NODE (obj); PinosNodePrivate *priv = node->priv; - g_debug ("node %p: dispose", node); + pinos_log_debug ("node %p: dispose", node); pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED); node_unregister_object (node); @@ -712,7 +715,7 @@ pinos_node_finalize (GObject * obj) PinosNode *node = PINOS_NODE (obj); PinosNodePrivate *priv = node->priv; - g_debug ("node %p: finalize", node); + pinos_log_debug ("node %p: finalize", node); g_clear_object (&priv->daemon); g_clear_object (&priv->iface); g_clear_object (&priv->data_loop); @@ -871,7 +874,7 @@ pinos_node_init (PinosNode * node) { PinosNodePrivate *priv = node->priv = PINOS_NODE_GET_PRIVATE (node); - g_debug ("node %p: new", node); + pinos_log_debug ("node %p: new", node); priv->iface = pinos_node1_skeleton_new (); g_signal_connect (priv->iface, "handle-remove", (GCallback) handle_remove, @@ -1009,7 +1012,7 @@ pinos_node_remove (PinosNode *node) if (node->flags & PINOS_NODE_FLAG_REMOVING) return; - g_debug ("node %p: remove", node); + pinos_log_debug ("node %p: remove", node); node->flags |= PINOS_NODE_FLAG_REMOVING; g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL); } @@ -1046,7 +1049,7 @@ pinos_node_get_free_port (PinosNode *node, } free_port = 0; - g_debug ("node %p: direction %d max %u, n %u, free_port %u", node, direction, max_ports, n_ports, free_port); + pinos_log_debug ("node %p: direction %d max %u, n %u, free_port %u", node, direction, max_ports, n_ports, free_port); for (walk = ports; walk; walk = g_list_next (walk)) { PinosPort *p = walk->data; @@ -1140,7 +1143,7 @@ pinos_port_link (PinosPort *output_port, priv = output_node->priv; input_node = input_port->node; - g_debug ("port link %p:%u -> %p:%u", output_node, output_port->port, input_node, input_port->port); + pinos_log_debug ("port link %p:%u -> %p:%u", output_node, output_port->port, input_node, input_port->port); if (output_node == input_node) goto same_node; @@ -1156,7 +1159,7 @@ pinos_port_link (PinosPort *output_port, input_node->live = output_node->live; if (output_node->clock) input_node->clock = output_node->clock; - g_debug ("node %p: clock %p, live %d", output_node, output_node->clock, output_node->live); + pinos_log_debug ("node %p: clock %p, live %d", output_node, output_node->clock, output_node->live); link = g_object_new (PINOS_TYPE_LINK, "daemon", priv->daemon, @@ -1231,7 +1234,7 @@ do_remove_link_done (SpaPoll *poll, PinosNodePrivate *priv = this->priv; PinosLink *link = ((PinosLink**)data)[0]; - g_debug ("port %p: finish unlink", port); + pinos_log_debug ("port %p: finish unlink", port); if (port->direction == PINOS_DIRECTION_OUTPUT) { if (g_ptr_array_remove_fast (port->links, link)) priv->n_used_output_links--; @@ -1248,7 +1251,7 @@ do_remove_link_done (SpaPoll *poll, } if (!port->allocated) { - g_debug ("port %p: clear buffers on port", port); + pinos_log_debug ("port %p: clear buffers on port", port); spa_node_port_use_buffers (port->node->node, port->direction, port->port, @@ -1302,7 +1305,7 @@ pinos_port_unlink (PinosPort *port, PinosLink *link) { SpaResult res; - g_debug ("port %p: start unlink %p", port, link); + pinos_log_debug ("port %p: start unlink %p", port, link); g_object_ref (link); g_object_ref (port->node); @@ -1328,7 +1331,7 @@ do_clear_buffers_done (SpaPoll *poll, PinosNodePrivate *priv = this->priv; SpaResult res; - g_debug ("port %p: clear buffers finish", port); + pinos_log_debug ("port %p: clear buffers finish", port); res = spa_node_port_use_buffers (port->node->node, port->direction, @@ -1372,7 +1375,7 @@ pinos_port_clear_buffers (PinosPort *port) { SpaResult res; - g_debug ("port %p: clear buffers", port); + pinos_log_debug ("port %p: clear buffers", port); res = spa_poll_invoke (&port->node->priv->data_loop->poll, do_clear_buffers, port->node->priv->seq++, @@ -1457,7 +1460,7 @@ pinos_node_set_state (PinosNode *node, remove_idle_timeout (node); - g_debug ("node %p: set state %s", node, pinos_node_state_as_string (state)); + pinos_log_debug ("node %p: set state %s", node, pinos_node_state_as_string (state)); switch (state) { case PINOS_NODE_STATE_CREATING: @@ -1515,7 +1518,7 @@ pinos_node_update_state (PinosNode *node, old = priv->state; if (old != state) { - g_debug ("node %p: update state from %s -> %s", node, + pinos_log_debug ("node %p: update state from %s -> %s", node, pinos_node_state_as_string (old), pinos_node_state_as_string (state)); priv->state = state; @@ -1546,7 +1549,7 @@ pinos_node_report_error (PinosNode *node, remove_idle_timeout (node); priv->error = error; priv->state = PINOS_NODE_STATE_ERROR; - g_debug ("node %p: got error state %s", node, error->message); + pinos_log_debug ("node %p: got error state %s", node, error->message); pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_ERROR); g_signal_emit (node, signals[SIGNAL_STATE_CHANGE], 0, old, priv->state); } @@ -1557,7 +1560,7 @@ idle_timeout (PinosNode *node) PinosNodePrivate *priv = node->priv; priv->idle_timeout = 0; - g_debug ("node %p: idle timeout", node); + pinos_log_debug ("node %p: idle timeout", node); pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED); return G_SOURCE_REMOVE; @@ -1578,7 +1581,7 @@ pinos_node_report_idle (PinosNode *node) g_return_if_fail (PINOS_IS_NODE (node)); priv = node->priv; - g_debug ("node %p: report idle", node); + pinos_log_debug ("node %p: report idle", node); pinos_node_set_state (node, PINOS_NODE_STATE_IDLE); priv->idle_timeout = g_timeout_add_seconds (3, @@ -1598,6 +1601,6 @@ pinos_node_report_busy (PinosNode *node) { g_return_if_fail (PINOS_IS_NODE (node)); - g_debug ("node %p: report busy", node); + pinos_log_debug ("node %p: report busy", node); pinos_node_set_state (node, PINOS_NODE_STATE_RUNNING); } diff --git a/pinos/server/node.h b/pinos/server/node.h index f4f95a6a..a6b6b9d9 100644 --- a/pinos/server/node.h +++ b/pinos/server/node.h @@ -44,6 +44,7 @@ typedef enum { #include <pinos/server/utils.h> struct _PinosPort { + uint32_t id; PinosNode *node; PinosDirection direction; uint32_t port; @@ -71,6 +72,8 @@ struct _PinosPort { struct _PinosNode { GObject object; + uint32_t id; + PinosNodeFlags flags; SpaNode *node; diff --git a/pinos/server/registry.c b/pinos/server/registry.c new file mode 100644 index 00000000..b711f24f --- /dev/null +++ b/pinos/server/registry.c @@ -0,0 +1,36 @@ +/* Pinos + * Copyright (C) 2015 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 <string.h> + +#include "pinos/client/pinos.h" +#include "pinos/server/registry.h" + +void +pinos_registry_init (PinosRegistry *reg) +{ + reg->map = pinos_id_map_get_default(); + + pinos_map_init (®->clients, 64); + pinos_map_init (®->nodes, 128); + pinos_map_init (®->ports, 512); + pinos_map_init (®->links, 256); + pinos_map_init (®->modules, 128); + pinos_map_init (®->monitors, 64); +} diff --git a/pinos/server/registry.h b/pinos/server/registry.h new file mode 100644 index 00000000..aa4fe274 --- /dev/null +++ b/pinos/server/registry.h @@ -0,0 +1,57 @@ +/* Pinos + * Copyright (C) 2015 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. + */ + +#ifndef __PINOS_REGISTRY_H__ +#define __PINOS_REGISTRY_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#include <pinos/client/map.h> +#include <spa/include/spa/id-map.h> + +typedef struct _PinosRegistry PinosRegistry; + +/** + * PinosRegistry: + * + * Pinos registry struct. + */ +struct _PinosRegistry { + SpaIDMap *map; + + PinosMap objects; + + PinosMap clients; + PinosMap node_factories; + PinosMap nodes; + PinosMap ports; + PinosMap links; + PinosMap modules; + PinosMap monitors; + PinosMap devices; +}; + + +void pinos_registry_init (PinosRegistry *reg); + +G_END_DECLS + +#endif /* __PINOS_REGISTRY_H__ */ diff --git a/pinos/server/utils.c b/pinos/server/utils.c index c6b6d34b..1df2cfe5 100644 --- a/pinos/server/utils.c +++ b/pinos/server/utils.c @@ -28,6 +28,7 @@ #include "memfd-wrappers.h" +#include <pinos/client/log.h> #include <pinos/server/utils.h> #undef USE_MEMFD @@ -47,21 +48,21 @@ pinos_memblock_alloc (PinosMemblockFlags flags, #ifdef USE_MEMFD mem->fd = memfd_create ("pinos-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING); if (mem->fd == -1) { - fprintf (stderr, "Failed to create memfd: %s\n", strerror (errno)); + pinos_log_error ("Failed to create memfd: %s\n", strerror (errno)); return FALSE; } #else char filename[] = "/dev/shm/spa-tmpfile.XXXXXX"; mem->fd = mkostemp (filename, O_CLOEXEC); if (mem->fd == -1) { - fprintf (stderr, "Failed to create temporary file: %s\n", strerror (errno)); + pinos_log_error ("Failed to create temporary file: %s\n", strerror (errno)); return FALSE; } unlink (filename); #endif if (ftruncate (mem->fd, size) < 0) { - g_warning ("Failed to truncate temporary file: %s", strerror (errno)); + pinos_log_warn ("Failed to truncate temporary file: %s", strerror (errno)); close (mem->fd); return FALSE; } @@ -69,7 +70,7 @@ pinos_memblock_alloc (PinosMemblockFlags flags, if (flags & PINOS_MEMBLOCK_FLAG_SEAL) { unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL; if (fcntl (mem->fd, F_ADD_SEALS, seals) == -1) { - g_warning ("Failed to add seals: %s", strerror (errno)); + pinos_log_warn ("Failed to add seals: %s", strerror (errno)); } } #endif diff --git a/spa/include/spa/buffer.h b/spa/include/spa/buffer.h index 7bc05600..1b58c56a 100644 --- a/spa/include/spa/buffer.h +++ b/spa/include/spa/buffer.h @@ -64,6 +64,7 @@ typedef enum { #include <spa/defs.h> #include <spa/port.h> +#include <spa/ringbuffer.h> /** * SpaBufferFlags: @@ -112,16 +113,10 @@ typedef struct { /** * SpaMetaRingbuffer: - * @readindex: - * @writeindex: - * @size: - * @size_mask: + * @ringbuffer: */ typedef struct { - volatile int readindex; - volatile int writeindex; - int size; - int size_mask; + SpaRingbuffer ringbuffer; } SpaMetaRingbuffer; /** diff --git a/spa/include/spa/id-map.h b/spa/include/spa/id-map.h index f2bb0d3f..1549f145 100644 --- a/spa/include/spa/id-map.h +++ b/spa/include/spa/id-map.h @@ -57,8 +57,6 @@ struct _SpaIDMap { #define spa_id_map_get_id(n,...) (n)->get_id((n),__VA_ARGS__) #define spa_id_map_get_uri(n,...) (n)->get_uri((n),__VA_ARGS__) -SpaIDMap * spa_id_map_get_default (void); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/port.h b/spa/include/spa/port.h index 5d5f2ee6..b0d4cb1d 100644 --- a/spa/include/spa/port.h +++ b/spa/include/spa/port.h @@ -71,6 +71,15 @@ typedef struct { } SpaAllocParamMetaEnable; typedef struct { + SpaAllocParam param; + SpaMetaType type; + size_t minsize; + size_t stride; + size_t blocks; + uint32_t align; +} SpaAllocParamMetaEnableRingbuffer; + +typedef struct { SpaAllocParam param; unsigned int padding_top; unsigned int padding_bottom; diff --git a/spa/include/spa/props.h b/spa/include/spa/props.h index f83a9771..57e2aa98 100644 --- a/spa/include/spa/props.h +++ b/spa/include/spa/props.h @@ -197,44 +197,6 @@ spa_props_index_for_name (const SpaProps *props, const char *name) return SPA_IDX_INVALID; } - -/** - * spa_props_set_value: - * @props: a #SpaProps - * @index: the index of the property in the prop_info array - * @value: the value to set - * - * Sets @value in @prop. type should match the type specified - * in the #SpaPropInfo at @index or else #SPA_RESULT_WRONG_PROPERTY_TYPE - * is returned. - * - * Returns: #SPA_RESULT_OK on success. - * #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid - * #SPA_RESULT_WRONG_PROPERTY_TYPE when type is not correct - */ -SpaResult spa_props_set_value (SpaProps *props, - unsigned int index, - const SpaPropValue *value); -/** - * spa_props_get_value: - * @props: a #SpaProps - * @index: the property index in the prop_info array - * @value: a location for the type, size and value - * - * Get the size and value of the property at @index. - * - * Returns: #SPA_RESULT_OK on success. - * #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid - * #SPA_RESULT_PROPERTY_UNSET when no value has been set yet - */ -SpaResult spa_props_get_value (const SpaProps *props, - unsigned int index, - SpaPropValue *value); - -SpaResult spa_props_copy_values (const SpaProps *src, - SpaProps *dest); - - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/lib/audio-raw.c b/spa/lib/audio-raw.c index fd23f205..2dc46fa8 100644 --- a/spa/lib/audio-raw.c +++ b/spa/lib/audio-raw.c @@ -24,6 +24,7 @@ #include <spa/audio/raw.h> #include <spa/audio/format.h> +#include <lib/props.h> static const uint32_t format_values[] = { SPA_AUDIO_FORMAT_S8, diff --git a/spa/lib/debug.c b/spa/lib/debug.c index dc5b10d9..02e8bb32 100644 --- a/spa/lib/debug.c +++ b/spa/lib/debug.c @@ -19,9 +19,8 @@ #include <stdio.h> -#include "spa/debug.h" -#include "spa/props.h" -#include "spa/format.h" +#include "debug.h" +#include "props.h" struct meta_type_name { const char *name; @@ -83,6 +82,19 @@ spa_debug_port_info (const SpaPortInfo *info) SpaAllocParamMetaEnable *p = (SpaAllocParamMetaEnable *)param; fprintf (stderr, " SpaAllocParamMetaEnable:\n"); fprintf (stderr, " type: \t%d (%s)\n", p->type, META_TYPE_NAME(p->type)); + switch (p->type) { + case SPA_META_TYPE_RINGBUFFER: + { + SpaAllocParamMetaEnableRingbuffer *rb = (SpaAllocParamMetaEnableRingbuffer *)p; + fprintf (stderr, " minsize: \t\t%zd\n", rb->minsize); + fprintf (stderr, " stride: \t\t%zd\n", rb->stride); + fprintf (stderr, " blocks: \t\t%zd\n", rb->blocks); + fprintf (stderr, " align: \t\t%d\n", rb->align); + break; + } + default: + break; + } break; } case SPA_ALLOC_PARAM_TYPE_VIDEO_PADDING: @@ -153,10 +165,11 @@ spa_debug_buffer (const SpaBuffer *buffer) { SpaMetaRingbuffer *h = m->data; fprintf (stderr, " SpaMetaRingbuffer:\n"); - fprintf (stderr, " readindex: %d\n", h->readindex); - fprintf (stderr, " writeindex: %d\n", h->writeindex); - fprintf (stderr, " size: %d\n", h->size); - fprintf (stderr, " size_mask: %d\n", h->size_mask); + fprintf (stderr, " readindex: %zd\n", h->ringbuffer.readindex); + fprintf (stderr, " writeindex: %zd\n", h->ringbuffer.writeindex); + fprintf (stderr, " size: %zd\n", h->ringbuffer.size); + fprintf (stderr, " mask: %zd\n", h->ringbuffer.mask); + fprintf (stderr, " mask2: %zd\n", h->ringbuffer.mask2); break; } default: diff --git a/spa/include/spa/debug.h b/spa/lib/debug.h index 3c3ca344..552248a6 100644 --- a/spa/include/spa/debug.h +++ b/spa/lib/debug.h @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __SPA_DEBUG_H__ -#define __SPA_DEBUG_H__ +#ifndef __SPA_LIBDEBUG_H__ +#define __SPA_LIBDEBUG_H__ #ifdef __cplusplus extern "C" { @@ -43,4 +43,4 @@ SpaResult spa_debug_dict (const SpaDict *dict); #endif -#endif /* __SPA_DEBUG_H__ */ +#endif /* __SPA_LIBDEBUG_H__ */ diff --git a/spa/lib/mapper.c b/spa/lib/mapper.c index bdc31efe..f7d28692 100644 --- a/spa/lib/mapper.c +++ b/spa/lib/mapper.c @@ -36,7 +36,8 @@ #include <spa/props.h> #include <spa/queue.h> #include <spa/ringbuffer.h> -#include <spa/debug.h> + +#include <lib/debug.h> #define MAX_URIS 4096 diff --git a/spa/lib/mapper.h b/spa/lib/mapper.h new file mode 100644 index 00000000..f04d514a --- /dev/null +++ b/spa/lib/mapper.h @@ -0,0 +1,35 @@ +/* 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. + */ + +#ifndef __SPA_LIBMAPPER_H__ +#define __SPA_LIBMAPPER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <spa/id-map.h> + +SpaIDMap * spa_id_map_get_default (void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_LIBMAPPER_H__ */ diff --git a/spa/lib/meson.build b/spa/lib/meson.build index d1f5b66f..582bd4bd 100644 --- a/spa/lib/meson.build +++ b/spa/lib/meson.build @@ -6,7 +6,7 @@ spalib_sources = ['audio-raw.c', spalib = shared_library('spa-lib', spalib_sources, - include_directories : spa_inc, + include_directories : [ spa_inc, spa_libinc ], install : true) spalib_dep = declare_dependency(link_with : spalib, diff --git a/spa/lib/props.h b/spa/lib/props.h new file mode 100644 index 00000000..2407c3b6 --- /dev/null +++ b/spa/lib/props.h @@ -0,0 +1,71 @@ +/* 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. + */ + +#ifndef __SPA_LIBPROPS_H__ +#define __SPA_LIBPROPS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <spa/props.h> + +/** + * spa_props_set_value: + * @props: a #SpaProps + * @index: the index of the property in the prop_info array + * @value: the value to set + * + * Sets @value in @prop. type should match the type specified + * in the #SpaPropInfo at @index or else #SPA_RESULT_WRONG_PROPERTY_TYPE + * is returned. + * + * Returns: #SPA_RESULT_OK on success. + * #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid + * #SPA_RESULT_WRONG_PROPERTY_TYPE when type is not correct + */ +SpaResult spa_props_set_value (SpaProps *props, + unsigned int index, + const SpaPropValue *value); +/** + * spa_props_get_value: + * @props: a #SpaProps + * @index: the property index in the prop_info array + * @value: a location for the type, size and value + * + * Get the size and value of the property at @index. + * + * Returns: #SPA_RESULT_OK on success. + * #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid + * #SPA_RESULT_PROPERTY_UNSET when no value has been set yet + */ +SpaResult spa_props_get_value (const SpaProps *props, + unsigned int index, + SpaPropValue *value); + +SpaResult spa_props_copy_values (const SpaProps *src, + SpaProps *dest); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* __SPA_LIBPROPS_H__ */ diff --git a/spa/lib/video-raw.c b/spa/lib/video-raw.c index c7b63b1f..3b122389 100644 --- a/spa/lib/video-raw.c +++ b/spa/lib/video-raw.c @@ -25,6 +25,8 @@ #include <spa/video/raw.h> #include <spa/video/format.h> +#include "props.h" + static const uint32_t format_values[] = { SPA_VIDEO_FORMAT_UNKNOWN, SPA_VIDEO_FORMAT_ENCODED, diff --git a/spa/meson.build b/spa/meson.build index 409d820d..50ac8204 100644 --- a/spa/meson.build +++ b/spa/meson.build @@ -17,6 +17,7 @@ dl_lib = cc.find_library('dl', required : true) pthread_lib = cc.find_library('pthread', required : true) spa_inc = include_directories('include') +spa_libinc = include_directories('.') subdir('include') subdir('lib') diff --git a/spa/plugins/alsa/alsa-monitor.c b/spa/plugins/alsa/alsa-monitor.c index 37ecf2f3..88631861 100644 --- a/spa/plugins/alsa/alsa-monitor.c +++ b/spa/plugins/alsa/alsa-monitor.c @@ -31,7 +31,7 @@ #include <spa/id-map.h> #include <spa/poll.h> #include <spa/monitor.h> -#include <spa/debug.h> +#include <lib/debug.h> extern const SpaHandleFactory spa_alsa_sink_factory; extern const SpaHandleFactory spa_alsa_source_factory; @@ -100,7 +100,7 @@ path_get_card_id (const char *path) return e + 5; } -#define CHECK(s,msg) if ((err = (s)) < 0) { spa_log_error (state->log, msg ": %s\n", snd_strerror(err)); return err; } +#define CHECK(s,msg) if ((err = (s)) < 0) { spa_log_error (state->log, msg ": %s", snd_strerror(err)); return err; } static int fill_item (SpaALSAMonitor *this, ALSAItem *item, struct udev_device *udevice) @@ -136,7 +136,7 @@ fill_item (SpaALSAMonitor *this, ALSAItem *item, struct udev_device *udevice) SND_PCM_NO_AUTO_RESAMPLE | SND_PCM_NO_AUTO_CHANNELS | SND_PCM_NO_AUTO_FORMAT)) < 0) { - spa_log_error (this->log, "PLAYBACK open failed: %s\n", snd_strerror(err)); + spa_log_error (this->log, "PLAYBACK open failed: %s", snd_strerror(err)); if ((err = snd_pcm_open (&hndl, device, SND_PCM_STREAM_CAPTURE, @@ -144,7 +144,7 @@ fill_item (SpaALSAMonitor *this, ALSAItem *item, struct udev_device *udevice) SND_PCM_NO_AUTO_RESAMPLE | SND_PCM_NO_AUTO_CHANNELS | SND_PCM_NO_AUTO_FORMAT)) < 0) { - spa_log_error (this->log, "CAPTURE open failed: %s\n", snd_strerror(err)); + spa_log_error (this->log, "CAPTURE open failed: %s", snd_strerror(err)); return -1; } else { item->item.factory = &spa_alsa_source_factory; diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index acc4a12d..88c8baef 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -23,6 +23,7 @@ #include <spa/node.h> #include <spa/audio/format.h> +#include <lib/props.h> #include "alsa-utils.h" @@ -47,7 +48,7 @@ reset_alsa_sink_props (SpaALSAProps *props) static void update_state (SpaALSASink *this, SpaNodeState state) { - spa_log_info (this->log, "update state %d\n", state); + spa_log_info (this->log, "update state %d", state); this->node.state = state; } @@ -367,6 +368,7 @@ spa_alsa_clear_buffers (SpaALSASink *this) if (this->n_buffers > 0) { SPA_QUEUE_INIT (&this->ready); this->n_buffers = 0; + this->ringbuffer = NULL; } return SPA_RESULT_OK; } @@ -390,7 +392,7 @@ spa_alsa_sink_node_port_set_format (SpaNode *node, return SPA_RESULT_INVALID_PORT; if (format == NULL) { - spa_log_info (this->log, "clear format\n"); + spa_log_info (this->log, "clear format"); spa_alsa_pause (this, false); spa_alsa_clear_buffers (this); spa_alsa_close (this); @@ -409,7 +411,7 @@ spa_alsa_sink_node_port_set_format (SpaNode *node, SPA_PORT_INFO_FLAG_LIVE; this->info.maxbuffering = this->buffer_frames * this->frame_size; this->info.latency = (this->period_frames * SPA_NSEC_PER_SEC) / this->rate; - this->info.n_params = 2; + this->info.n_params = 3; this->info.params = this->params; this->params[0] = &this->param_buffers.param; this->param_buffers.param.type = SPA_ALLOC_PARAM_TYPE_BUFFERS; @@ -423,6 +425,14 @@ spa_alsa_sink_node_port_set_format (SpaNode *node, this->param_meta.param.type = SPA_ALLOC_PARAM_TYPE_META_ENABLE; this->param_meta.param.size = sizeof (this->param_meta); this->param_meta.type = SPA_META_TYPE_HEADER; + this->params[2] = &this->param_meta_rb.param; + this->param_meta_rb.param.type = SPA_ALLOC_PARAM_TYPE_META_ENABLE; + this->param_meta_rb.param.size = sizeof (this->param_meta_rb); + this->param_meta_rb.type = SPA_META_TYPE_RINGBUFFER; + this->param_meta_rb.minsize = this->period_frames * this->frame_size * 32; + this->param_meta_rb.stride = 0; + this->param_meta_rb.blocks = 1; + this->param_meta_rb.align = 16; this->info.extra = NULL; this->have_format = true; @@ -512,7 +522,7 @@ spa_alsa_sink_node_port_use_buffers (SpaNode *node, this = SPA_CONTAINER_OF (node, SpaALSASink, node); - spa_log_info (this->log, "use buffers %d\n", n_buffers); + spa_log_info (this->log, "use buffers %d", n_buffers); if (!this->have_format) return SPA_RESULT_NO_FORMAT; @@ -530,13 +540,16 @@ spa_alsa_sink_node_port_use_buffers (SpaNode *node, b->outstanding = true; b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER); + b->rb = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_RINGBUFFER); + if (b->rb) + this->ringbuffer = b; switch (buffers[i]->datas[0].type) { case SPA_DATA_TYPE_MEMFD: case SPA_DATA_TYPE_DMABUF: case SPA_DATA_TYPE_MEMPTR: if (buffers[i]->datas[0].data == NULL) { - spa_log_error (this->log, "alsa-source: need mapped memory\n"); + spa_log_error (this->log, "alsa-source: need mapped memory"); continue; } break; @@ -637,9 +650,14 @@ spa_alsa_sink_node_port_push_input (SpaNode *node, have_error = true; continue; } + if (this->ringbuffer) { + this->ringbuffer->outstanding = true; + this->ringbuffer = b; + } else { + b->next = NULL; + SPA_QUEUE_PUSH_TAIL (&this->ready, SpaALSABuffer, next, b); + } b->outstanding = false; - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->ready, SpaALSABuffer, next, b); info[i].status = SPA_RESULT_OK; } if (have_error) diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c index c37213f6..131a7356 100644 --- a/spa/plugins/alsa/alsa-source.c +++ b/spa/plugins/alsa/alsa-source.c @@ -24,6 +24,7 @@ #include <spa/node.h> #include <spa/queue.h> #include <spa/audio/format.h> +#include <lib/props.h> #include "alsa-utils.h" @@ -583,7 +584,7 @@ spa_alsa_source_node_port_use_buffers (SpaNode *node, case SPA_DATA_TYPE_DMABUF: case SPA_DATA_TYPE_MEMPTR: if (buffers[i]->datas[0].data == NULL) { - spa_log_error (this->log, "alsa-source: need mapped memory\n"); + spa_log_error (this->log, "alsa-source: need mapped memory"); continue; } break; @@ -697,7 +698,7 @@ spa_alsa_source_node_port_pull_output (SpaNode *node, info[i].buffer_id = b->outbuf->id; info[i].status = SPA_RESULT_OK; - spa_log_debug (this->log, "pull buffer %u\n", b->outbuf->id); + spa_log_debug (this->log, "pull buffer %u", b->outbuf->id); } if (have_error) return SPA_RESULT_ERROR; @@ -727,7 +728,7 @@ spa_alsa_source_node_port_reuse_buffer (SpaNode *node, if (buffer_id >= this->n_buffers) return SPA_RESULT_INVALID_BUFFER_ID; - spa_log_debug (this->log, "recycle buffer %u\n", buffer_id); + spa_log_debug (this->log, "recycle buffer %u", buffer_id); recycle_buffer (this, buffer_id); return SPA_RESULT_OK; diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index d89c2584..13f4a81f 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -7,9 +7,10 @@ #include <sys/time.h> #include <math.h> +#include <lib/debug.h> #include "alsa-utils.h" -#define CHECK(s,msg) if ((err = (s)) < 0) { spa_log_error (state->log, msg ": %s\n", snd_strerror(err)); return err; } +#define CHECK(s,msg) if ((err = (s)) < 0) { spa_log_error (state->log, msg ": %s", snd_strerror(err)); return err; } static int alsa_on_fd_events (SpaPollNotifyData *data); @@ -24,7 +25,7 @@ spa_alsa_open (SpaALSAState *state) CHECK (snd_output_stdio_attach (&state->output, stderr, 0), "attach failed"); - spa_log_info (state->log, "ALSA device open '%s'\n", props->device); + spa_log_info (state->log, "ALSA device open '%s'", props->device); CHECK (snd_pcm_open (&state->hndl, props->device, state->stream, @@ -59,7 +60,7 @@ spa_alsa_close (SpaALSAState *state) spa_poll_remove_item (state->data_loop, &state->poll); - spa_log_info (state->log, "Device closing\n"); + spa_log_info (state->log, "Device closing"); CHECK (snd_pcm_close (state->hndl), "close failed"); state->opened = false; @@ -147,14 +148,14 @@ spa_alsa_set_format (SpaALSAState *state, SpaFormatAudio *fmt, SpaPortFormatFlag /* set the sample format */ format = spa_alsa_format_to_alsa (info->format); - spa_log_info (state->log, "Stream parameters are %iHz, %s, %i channels\n", info->rate, snd_pcm_format_name(format), info->channels); + spa_log_info (state->log, "Stream parameters are %iHz, %s, %i channels", info->rate, snd_pcm_format_name(format), info->channels); CHECK (snd_pcm_hw_params_set_format (hndl, params, format), "set_format"); /* set the count of channels */ rchannels = info->channels; CHECK (snd_pcm_hw_params_set_channels_near (hndl, params, &rchannels), "set_channels"); if (rchannels != info->channels) { - spa_log_info (state->log, "Channels doesn't match (requested %u, get %u\n", info->channels, rchannels); + spa_log_info (state->log, "Channels doesn't match (requested %u, get %u", info->channels, rchannels); if (flags & SPA_PORT_FORMAT_FLAG_NEAREST) info->channels = rchannels; else @@ -165,7 +166,7 @@ spa_alsa_set_format (SpaALSAState *state, SpaFormatAudio *fmt, SpaPortFormatFlag rrate = info->rate; CHECK (snd_pcm_hw_params_set_rate_near (hndl, params, &rrate, 0), "set_rate_near"); if (rrate != info->rate) { - spa_log_info (state->log, "Rate doesn't match (requested %iHz, get %iHz)\n", info->rate, rrate); + spa_log_info (state->log, "Rate doesn't match (requested %iHz, get %iHz)", info->rate, rrate); if (flags & SPA_PORT_FORMAT_FLAG_NEAREST) info->rate = rrate; else @@ -189,6 +190,8 @@ spa_alsa_set_format (SpaALSAState *state, SpaFormatAudio *fmt, SpaPortFormatFlag CHECK (snd_pcm_hw_params_get_period_size (params, &size, &dir), "get_period_size"); state->period_frames = size; + spa_log_info (state->log, "buffer frames %zd, period frames %zd", state->buffer_frames, state->period_frames); + /* write the parameters to device */ CHECK (snd_pcm_hw_params (hndl, params), "set_hw_params"); @@ -210,10 +213,13 @@ set_swparams (SpaALSAState *state) CHECK (snd_pcm_sw_params_set_tstamp_mode (hndl, params, SND_PCM_TSTAMP_ENABLE), "sw_params_set_tstamp_mode"); - /* start the transfer when the buffer is almost full: */ - /* (buffer_frames / avail_min) * avail_min */ - CHECK (snd_pcm_sw_params_set_start_threshold (hndl, params, - (state->buffer_frames / state->period_frames) * state->period_frames), "set_start_threshold"); + /* start the transfer */ + CHECK (snd_pcm_sw_params_set_start_threshold (hndl, params, 0U), "set_start_threshold"); + CHECK (snd_pcm_sw_params_set_stop_threshold (hndl, params, + (state->buffer_frames / state->period_frames) * state->period_frames), "set_stop_threshold"); +// CHECK (snd_pcm_sw_params_set_stop_threshold (hndl, params, -1), "set_stop_threshold"); + + CHECK (snd_pcm_sw_params_set_silence_threshold (hndl, params, 0U), "set_silence_threshold"); /* allow the transfer when at least period_size samples can be processed */ /* or disable this mechanism when period event is enabled (aka interrupt like style processing) */ @@ -240,18 +246,18 @@ xrun_recovery (SpaALSAState *state, snd_pcm_t *hndl, int err) snd_pcm_status_alloca (&status); if ((err = snd_pcm_status (hndl, status)) < 0) { - spa_log_error (state->log, "snd_pcm_status error: %s\n", snd_strerror (err)); + spa_log_error (state->log, "snd_pcm_status error: %s", snd_strerror (err)); } if (snd_pcm_status_get_state (status) == SND_PCM_STATE_SUSPENDED) { - spa_log_info (state->log, "SUSPENDED, trying to resume\n"); + spa_log_warn (state->log, "SUSPENDED, trying to resume"); if ((err = snd_pcm_prepare (hndl)) < 0) { - spa_log_error (state->log, "snd_pcm_prepare error: %s\n", snd_strerror (err)); + spa_log_error (state->log, "snd_pcm_prepare error: %s", snd_strerror (err)); } } if (snd_pcm_status_get_state (status) == SND_PCM_STATE_XRUN) { - spa_log_info (state->log, "XRUN\n"); + spa_log_warn (state->log, "XRUN"); } if (spa_alsa_pause (state, true) != SPA_RESULT_OK) @@ -262,6 +268,98 @@ xrun_recovery (SpaALSAState *state, snd_pcm_t *hndl, int err) return err; } +static snd_pcm_uframes_t +pull_frames_queue (SpaALSAState *state, + const snd_pcm_channel_area_t *my_areas, + snd_pcm_uframes_t offset, + snd_pcm_uframes_t frames) +{ + SpaALSABuffer *b; + + SPA_QUEUE_PEEK_HEAD (&state->ready, SpaALSABuffer, b); + + if (b) { + uint8_t *src, *dst; + size_t n_bytes; + + src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset + state->ready_offset, uint8_t); + dst = SPA_MEMBER (my_areas[0].addr, offset * state->frame_size, uint8_t); + n_bytes = SPA_MIN (b->outbuf->datas[0].size - state->ready_offset, frames * state->frame_size); + frames = SPA_MIN (frames, n_bytes / state->frame_size); + + memcpy (dst, src, n_bytes); + + state->ready_offset += n_bytes; + if (state->ready_offset >= b->outbuf->datas[0].size) { + SpaNodeEventReuseBuffer rb; + + SPA_QUEUE_POP_HEAD (&state->ready, SpaALSABuffer, next, b); + b->outstanding = true; + + rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER; + rb.event.size = sizeof (rb); + rb.port_id = 0; + rb.buffer_id = b->outbuf->id; + state->event_cb (&state->node, &rb.event, state->user_data); + + state->ready_offset = 0; + } + } else { + spa_log_warn (state->log, "underrun"); + snd_pcm_areas_silence (my_areas, offset, state->channels, frames, state->format); + } + return frames; +} + +static snd_pcm_uframes_t +pull_frames_ringbuffer (SpaALSAState *state, + const snd_pcm_channel_area_t *my_areas, + snd_pcm_uframes_t offset, + snd_pcm_uframes_t frames) +{ + SpaRingbufferArea areas[2]; + size_t size, avail; + SpaALSABuffer *b; + uint8_t *src, *dst; + SpaNodeEventReuseBuffer rb; + + b = state->ringbuffer; + + src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void); + dst = SPA_MEMBER (my_areas[0].addr, offset * state->frame_size, uint8_t); + + spa_ringbuffer_get_read_areas (&b->rb->ringbuffer, areas); + avail = areas[0].len + areas[1].len; + size = SPA_MIN (avail, frames * state->frame_size); + + spa_log_debug (state->log, "%zd %zd %zd %zd %zd %zd", + areas[0].offset, areas[0].len, + areas[1].offset, areas[1].len, offset, size); + + if (size > 0) { + areas[0].len = SPA_MIN (areas[0].len, size); + areas[1].len = SPA_MIN (areas[1].len, size - areas[0].len); + + memcpy (dst, src + areas[0].offset, areas[0].len); + if (areas[1].len) + memcpy (dst + areas[0].len, src + areas[1].offset, areas[1].len); + + spa_ringbuffer_read_advance (&b->rb->ringbuffer, size); + frames = size / state->frame_size; + } else { + spa_log_warn (state->log, "underrun"); + snd_pcm_areas_silence (my_areas, offset, state->channels, frames, state->format); + } + + b->outstanding = true; + rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER; + rb.event.size = sizeof (rb); + rb.port_id = 0; + rb.buffer_id = b->outbuf->id; + state->event_cb (&state->node, &rb.event, state->user_data); + + return frames; +} static int mmap_write (SpaALSAState *state) { @@ -270,71 +368,42 @@ mmap_write (SpaALSAState *state) snd_pcm_sframes_t avail; snd_pcm_uframes_t offset, frames, size; const snd_pcm_channel_area_t *my_areas; - SpaNodeEventNeedInput ni; - SpaALSABuffer *b; snd_pcm_status_t *status; + SpaNodeEventNeedInput ni; snd_pcm_status_alloca (&status); if ((err = snd_pcm_status (hndl, status)) < 0) { - spa_log_error (state->log, "snd_pcm_status error: %s\n", snd_strerror (err)); + spa_log_error (state->log, "snd_pcm_status error: %s", snd_strerror (err)); return -1; } avail = snd_pcm_status_get_avail (status); + ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT; + ni.event.size = sizeof (ni); + ni.port_id = 0; + state->event_cb (&state->node, &ni.event, state->user_data); + size = avail; while (size > 0) { frames = size; if ((err = snd_pcm_mmap_begin (hndl, &my_areas, &offset, &frames)) < 0) { - spa_log_error (state->log, "snd_pcm_mmap_begin error: %s\n", snd_strerror(err)); + spa_log_error (state->log, "snd_pcm_mmap_begin error: %s", snd_strerror(err)); return -1; } - ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT; - ni.event.size = sizeof (ni); - ni.port_id = 0; - state->event_cb (&state->node, &ni.event, state->user_data); - - SPA_QUEUE_PEEK_HEAD (&state->ready, SpaALSABuffer, b); - - if (b) { - uint8_t *src; - size_t n_bytes; - - src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset + state->ready_offset, void); - n_bytes = SPA_MIN (b->outbuf->datas[0].size - state->ready_offset, frames * state->frame_size); - frames = SPA_MIN (frames, n_bytes / state->frame_size); - - memcpy ((uint8_t *)my_areas[0].addr + (offset * state->frame_size), - src, - n_bytes); - - state->ready_offset += n_bytes; - if (state->ready_offset >= b->outbuf->datas[0].size) { - SpaNodeEventReuseBuffer rb; - - SPA_QUEUE_POP_HEAD (&state->ready, SpaALSABuffer, next, b); - b->outstanding = true; - - rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER; - rb.event.size = sizeof (rb); - rb.port_id = 0; - rb.buffer_id = b->outbuf->id; - state->event_cb (&state->node, &rb.event, state->user_data); - - state->ready_offset = 0; - } - } else { - spa_log_warn (state->log, "underrun\n"); - snd_pcm_areas_silence (my_areas, offset, state->channels, frames, state->format); - } + if (state->ringbuffer) + frames = pull_frames_ringbuffer (state, my_areas, offset, frames); + else + frames = pull_frames_queue (state, my_areas, offset, frames); if ((err = snd_pcm_mmap_commit (hndl, offset, frames)) < 0) { - spa_log_error (state->log, "snd_pcm_mmap_commit error: %s\n", snd_strerror(err)); + spa_log_error (state->log, "snd_pcm_mmap_commit error: %s", snd_strerror(err)); if (err != -EPIPE && err != -ESTRPIPE) return -1; } + spa_log_debug (state->log, "write %zd/%zd/%zd %u", frames, size, avail, state->ready.length); size -= frames; } return 0; @@ -358,7 +427,7 @@ mmap_read (SpaALSAState *state) snd_pcm_status_alloca(&status); if ((err = snd_pcm_status (hndl, status)) < 0) { - spa_log_error (state->log, "snd_pcm_status error: %s\n", snd_strerror(err)); + spa_log_error (state->log, "snd_pcm_status error: %s", snd_strerror(err)); return err; } @@ -371,7 +440,7 @@ mmap_read (SpaALSAState *state) SPA_QUEUE_POP_HEAD (&state->free, SpaALSABuffer, next, b); if (b == NULL) { - spa_log_warn (state->log, "no more buffers\n"); + spa_log_warn (state->log, "no more buffers"); } else { dest = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void); destsize = b->outbuf->datas[0].size; @@ -390,7 +459,7 @@ mmap_read (SpaALSAState *state) while (size > 0) { frames = size; if ((err = snd_pcm_mmap_begin (hndl, &my_areas, &offset, &frames)) < 0) { - spa_log_error (state->log, "snd_pcm_mmap_begin error: %s\n", snd_strerror (err)); + spa_log_error (state->log, "snd_pcm_mmap_begin error: %s", snd_strerror (err)); return -1; } @@ -404,13 +473,12 @@ mmap_read (SpaALSAState *state) } if ((err = snd_pcm_mmap_commit (hndl, offset, frames)) < 0) { - spa_log_error (state->log, "snd_pcm_mmap_commit error: %s\n", snd_strerror(err)); + spa_log_error (state->log, "snd_pcm_mmap_commit error: %s", snd_strerror(err)); return -1; } size -= frames; } - if (b) { SpaNodeEventHaveOutput ho; SpaData *d; @@ -443,7 +511,7 @@ alsa_on_fd_events (SpaPollNotifyData *data) &revents); if (revents & POLLERR) { if ((err = xrun_recovery (state, hndl, err)) < 0) { - spa_log_error (state->log, "error: %s\n", snd_strerror (err)); + spa_log_error (state->log, "error: %s", snd_strerror (err)); return -1; } } @@ -476,16 +544,16 @@ spa_alsa_start (SpaALSAState *state, bool xrun_recover) snd_pcm_dump (state->hndl, state->output); if ((err = snd_pcm_prepare (state->hndl)) < 0) { - spa_log_error (state->log, "snd_pcm_prepare error: %s\n", snd_strerror (err)); + spa_log_error (state->log, "snd_pcm_prepare error: %s", snd_strerror (err)); return SPA_RESULT_ERROR; } if ((state->poll.n_fds = snd_pcm_poll_descriptors_count (state->hndl)) <= 0) { - spa_log_error (state->log, "Invalid poll descriptors count %d\n", state->poll.n_fds); + spa_log_error (state->log, "Invalid poll descriptors count %d", state->poll.n_fds); return SPA_RESULT_ERROR; } if ((err = snd_pcm_poll_descriptors (state->hndl, (struct pollfd *)state->fds, state->poll.n_fds)) < 0) { - spa_log_error (state->log, "snd_pcm_poll_descriptors: %s\n", snd_strerror(err)); + spa_log_error (state->log, "snd_pcm_poll_descriptors: %s", snd_strerror(err)); return SPA_RESULT_ERROR; } @@ -499,7 +567,7 @@ spa_alsa_start (SpaALSAState *state, bool xrun_recover) } if ((err = snd_pcm_start (state->hndl)) < 0) { - spa_log_error (state->log, "snd_pcm_start: %s\n", snd_strerror (err)); + spa_log_error (state->log, "snd_pcm_start: %s", snd_strerror (err)); return SPA_RESULT_ERROR; } @@ -522,7 +590,7 @@ spa_alsa_pause (SpaALSAState *state, bool xrun_recover) } if ((err = snd_pcm_drop (state->hndl)) < 0) - spa_log_error (state->log, "snd_pcm_drop %s\n", snd_strerror (err)); + spa_log_error (state->log, "snd_pcm_drop %s", snd_strerror (err)); state->started = false; diff --git a/spa/plugins/alsa/alsa-utils.h b/spa/plugins/alsa/alsa-utils.h index da920e72..720bcbb6 100644 --- a/spa/plugins/alsa/alsa-utils.h +++ b/spa/plugins/alsa/alsa-utils.h @@ -32,6 +32,7 @@ extern "C" { #include <spa/log.h> #include <spa/queue.h> #include <spa/node.h> +#include <spa/ringbuffer.h> #include <spa/audio/format.h> typedef struct _SpaALSAState SpaALSAState; @@ -52,6 +53,7 @@ typedef struct { struct _SpaALSABuffer { SpaBuffer *outbuf; SpaMetaHeader *h; + SpaMetaRingbuffer *rb; bool outstanding; SpaALSABuffer *next; }; @@ -96,13 +98,16 @@ struct _SpaALSAState { size_t frame_size; SpaPortInfo info; - SpaAllocParam *params[2]; + SpaAllocParam *params[3]; SpaAllocParamBuffers param_buffers; SpaAllocParamMetaEnable param_meta; + SpaAllocParamMetaEnableRingbuffer param_meta_rb; SpaPortStatus status; SpaALSABuffer buffers[MAX_BUFFERS]; unsigned int n_buffers; + bool use_ringbuffer; + SpaALSABuffer *ringbuffer; SpaQueue free; SpaQueue ready; diff --git a/spa/plugins/alsa/meson.build b/spa/plugins/alsa/meson.build index a287f0b6..9544839c 100644 --- a/spa/plugins/alsa/meson.build +++ b/spa/plugins/alsa/meson.build @@ -6,7 +6,7 @@ spa_alsa_sources = ['alsa.c', spa_alsa = shared_library('spa-alsa', spa_alsa_sources, - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc], dependencies : [ alsa_dep, libudev_dep ], link_with : spalib, install : true, diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index 2d285a61..5f1eaac3 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -24,6 +24,7 @@ #include <spa/id-map.h> #include <spa/node.h> #include <spa/audio/format.h> +#include <lib/props.h> #define MAX_PORTS 128 @@ -700,7 +701,7 @@ spa_audiomixer_node_port_pull_output (SpaNode *node, for (i = 0; i < n_info; i++) { if ((info[i].status = mix_data (this, &info[i])) < 0) { - spa_log_error (this->log, "error mixing: %d\n", info[i].status); + spa_log_error (this->log, "error mixing: %d", info[i].status); have_error = true; continue; } diff --git a/spa/plugins/audiomixer/meson.build b/spa/plugins/audiomixer/meson.build index 06faee09..2f081dcb 100644 --- a/spa/plugins/audiomixer/meson.build +++ b/spa/plugins/audiomixer/meson.build @@ -2,7 +2,7 @@ audiomixer_sources = ['audiomixer.c', 'plugin.c'] audiomixerlib = shared_library('spa-audiomixer', audiomixer_sources, - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc], link_with : spalib, install : true, install_dir : '@0@/spa'.format(get_option('libdir'))) diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 17705523..524b0fa9 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -29,6 +29,7 @@ #include <spa/node.h> #include <spa/queue.h> #include <spa/audio/format.h> +#include <lib/props.h> #define SAMPLES_TO_TIME(this,s) ((s) * SPA_NSEC_PER_SEC / (this)->current_format.info.raw.rate) #define BYTES_TO_SAMPLES(this,b) ((b)/(this)->bpf) @@ -526,7 +527,7 @@ static SpaResult clear_buffers (SpaAudioTestSrc *this) { if (this->n_buffers > 0) { - spa_log_info (this->log, "audiotestsrc %p: clear buffers\n", this); + spa_log_info (this->log, "audiotestsrc %p: clear buffers", this); this->n_buffers = 0; SPA_QUEUE_INIT (&this->empty); SPA_QUEUE_INIT (&this->ready); @@ -690,7 +691,7 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node, case SPA_DATA_TYPE_MEMFD: case SPA_DATA_TYPE_DMABUF: if (d[0].data == NULL) { - spa_log_error (this->log, "audiotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]); + spa_log_error (this->log, "audiotestsrc %p: invalid memory on buffer %p", this, buffers[i]); continue; } b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void); diff --git a/spa/plugins/audiotestsrc/meson.build b/spa/plugins/audiotestsrc/meson.build index 40e1cb68..a7531611 100644 --- a/spa/plugins/audiotestsrc/meson.build +++ b/spa/plugins/audiotestsrc/meson.build @@ -2,7 +2,7 @@ audiotestsrc_sources = ['audiotestsrc.c', 'plugin.c'] audiotestsrclib = shared_library('spa-audiotestsrc', audiotestsrc_sources, - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc], link_with : spalib, install : true, install_dir : '@0@/spa'.format(get_option('libdir'))) diff --git a/spa/plugins/ffmpeg/ffmpeg-dec.c b/spa/plugins/ffmpeg/ffmpeg-dec.c index 53455a74..3f784199 100644 --- a/spa/plugins/ffmpeg/ffmpeg-dec.c +++ b/spa/plugins/ffmpeg/ffmpeg-dec.c @@ -26,6 +26,7 @@ #include <spa/log.h> #include <spa/node.h> #include <spa/video/format.h> +#include <lib/props.h> typedef struct _SpaFFMpegDec SpaFFMpegDec; diff --git a/spa/plugins/ffmpeg/ffmpeg-enc.c b/spa/plugins/ffmpeg/ffmpeg-enc.c index 0010a619..675a3242 100644 --- a/spa/plugins/ffmpeg/ffmpeg-enc.c +++ b/spa/plugins/ffmpeg/ffmpeg-enc.c @@ -26,6 +26,7 @@ #include <spa/id-map.h> #include <spa/node.h> #include <spa/video/format.h> +#include <lib/props.h> typedef struct _SpaFFMpegEnc SpaFFMpegEnc; diff --git a/spa/plugins/ffmpeg/meson.build b/spa/plugins/ffmpeg/meson.build index 8aa26bda..7dee7b0c 100644 --- a/spa/plugins/ffmpeg/meson.build +++ b/spa/plugins/ffmpeg/meson.build @@ -4,7 +4,7 @@ ffmpeg_sources = ['ffmpeg.c', ffmpeglib = shared_library('spa-ffmpeg', ffmpeg_sources, - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc], dependencies : [ avcodec_dep, avformat_dep ], link_with : spalib, install : true, diff --git a/spa/plugins/v4l2/meson.build b/spa/plugins/v4l2/meson.build index 451ce9f7..d4d236f9 100644 --- a/spa/plugins/v4l2/meson.build +++ b/spa/plugins/v4l2/meson.build @@ -4,7 +4,7 @@ v4l2_sources = ['v4l2.c', v4l2lib = shared_library('spa-v4l2', v4l2_sources, - include_directories : spa_inc, + include_directories : [ spa_inc, spa_libinc ], dependencies : [ v4l2_dep, libudev_dep ], link_with : spalib, install : true, diff --git a/spa/plugins/v4l2/v4l2-monitor.c b/spa/plugins/v4l2/v4l2-monitor.c index eda1043e..e8357a35 100644 --- a/spa/plugins/v4l2/v4l2-monitor.c +++ b/spa/plugins/v4l2/v4l2-monitor.c @@ -30,7 +30,7 @@ #include <spa/id-map.h> #include <spa/poll.h> #include <spa/monitor.h> -#include <spa/debug.h> +#include <lib/debug.h> extern const SpaHandleFactory spa_v4l2_source_factory; diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index 2ecd11b1..e6f6ce2f 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -26,10 +26,11 @@ #include <spa/node.h> #include <spa/video/format.h> -#include <spa/debug.h> #include <spa/queue.h> #include <spa/log.h> #include <spa/id-map.h> +#include <lib/debug.h> +#include <lib/props.h> typedef struct _SpaV4l2Source SpaV4l2Source; @@ -150,7 +151,7 @@ struct _SpaV4l2Source { static void update_state (SpaV4l2Source *this, SpaNodeState state) { - spa_log_info (this->log, "state: %d\n", state); + spa_log_info (this->log, "state: %d", state); this->node.state = state; } #include "v4l2-utils.c" diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index 55f4edf6..a5a4d41e 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -34,27 +34,27 @@ spa_v4l2_open (SpaV4l2Source *this) return 0; if (props->props.unset_mask & 1) { - spa_log_error (state->log, "v4l2: Device property not set\n"); + spa_log_error (state->log, "v4l2: Device property not set"); return -1; } - spa_log_info (state->log, "v4l2: Playback device is '%s'\n", props->device); + spa_log_info (state->log, "v4l2: Playback device is '%s'", props->device); if (stat (props->device, &st) < 0) { - spa_log_error (state->log, "v4l2: Cannot identify '%s': %d, %s\n", + spa_log_error (state->log, "v4l2: Cannot identify '%s': %d, %s", props->device, errno, strerror (errno)); return -1; } if (!S_ISCHR (st.st_mode)) { - spa_log_error (state->log, "v4l2: %s is no device\n", props->device); + spa_log_error (state->log, "v4l2: %s is no device", props->device); return -1; } state->fd = open (props->device, O_RDWR | O_NONBLOCK, 0); if (state->fd == -1) { - spa_log_error (state->log, "v4l2: Cannot open '%s': %d, %s\n", + spa_log_error (state->log, "v4l2: Cannot open '%s': %d, %s", props->device, errno, strerror (errno)); return -1; } @@ -65,7 +65,7 @@ spa_v4l2_open (SpaV4l2Source *this) } if ((state->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) { - spa_log_error (state->log, "v4l2: %s is no video capture device\n", props->device); + spa_log_error (state->log, "v4l2: %s is no video capture device", props->device); return -1; } @@ -120,7 +120,7 @@ spa_v4l2_clear_buffers (SpaV4l2Source *this) b = &state->buffers[i]; if (b->outstanding) { - spa_log_info (state->log, "v4l2: queueing outstanding buffer %p\n", b); + spa_log_info (state->log, "v4l2: queueing outstanding buffer %p", b); spa_v4l2_buffer_recycle (this, i); } if (b->allocated) { @@ -156,7 +156,7 @@ spa_v4l2_close (SpaV4l2Source *this) if (state->n_buffers > 0) return 0; - spa_log_info (state->log, "v4l2: close\n"); + spa_log_info (state->log, "v4l2: close"); spa_poll_remove_item (state->data_loop, &state->poll); @@ -768,7 +768,7 @@ spa_v4l2_set_format (SpaV4l2Source *this, V4l2Format *f, bool try_only) f->format, 0); if (info == NULL) { - spa_log_error (state->log, "v4l2: unknown media type %d %d %d\n", f->fmt.media_type, + spa_log_error (state->log, "v4l2: unknown media type %d %d %d", f->fmt.media_type, f->fmt.media_subtype, f->format); return -1; } @@ -780,7 +780,7 @@ spa_v4l2_set_format (SpaV4l2Source *this, V4l2Format *f, bool try_only) streamparm.parm.capture.timeperframe.numerator = f->framerate.denom; streamparm.parm.capture.timeperframe.denominator = f->framerate.num; - spa_log_info (state->log, "v4l2: set %08x %dx%d %d/%d\n", fmt.fmt.pix.pixelformat, + spa_log_info (state->log, "v4l2: set %08x %dx%d %d/%d", fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height, streamparm.parm.capture.timeperframe.numerator, streamparm.parm.capture.timeperframe.denominator); @@ -800,7 +800,7 @@ spa_v4l2_set_format (SpaV4l2Source *this, V4l2Format *f, bool try_only) if (xioctl (state->fd, VIDIOC_S_PARM, &streamparm) < 0) perror ("VIDIOC_S_PARM"); - spa_log_info (state->log, "v4l2: got %08x %dx%d %d/%d\n", fmt.fmt.pix.pixelformat, + spa_log_info (state->log, "v4l2: got %08x %dx%d %d/%d", fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height, streamparm.parm.capture.timeperframe.numerator, streamparm.parm.capture.timeperframe.denominator); @@ -932,7 +932,7 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe state->memtype = V4L2_MEMORY_DMABUF; break; default: - spa_log_error (state->log, "v4l2: can't use buffers\n"); + spa_log_error (state->log, "v4l2: can't use buffers"); return SPA_RESULT_ERROR; } } @@ -946,9 +946,9 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe perror ("VIDIOC_REQBUFS"); return SPA_RESULT_ERROR; } - spa_log_info (state->log, "v4l2: got %d buffers\n", reqbuf.count); + spa_log_info (state->log, "v4l2: got %d buffers", reqbuf.count); if (reqbuf.count < 2) { - spa_log_error (state->log, "v4l2: can't allocate enough buffers\n"); + spa_log_error (state->log, "v4l2: can't allocate enough buffers"); return SPA_RESULT_ERROR; } @@ -961,10 +961,10 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe b->allocated = false; b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER); - spa_log_info (state->log, "v4l2: import buffer %p\n", buffers[i]); + spa_log_info (state->log, "v4l2: import buffer %p", buffers[i]); if (buffers[i]->n_datas < 1) { - spa_log_error (state->log, "v4l2: invalid memory on buffer %p\n", buffers[i]); + spa_log_error (state->log, "v4l2: invalid memory on buffer %p", buffers[i]); continue; } d = buffers[i]->datas; @@ -977,7 +977,7 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe case SPA_DATA_TYPE_MEMPTR: case SPA_DATA_TYPE_MEMFD: if (d[0].data == NULL) { - spa_log_error (state->log, "v4l2: need mmaped memory\n"); + spa_log_error (state->log, "v4l2: need mmaped memory"); continue; } b->v4l2_buffer.m.userptr = (unsigned long) SPA_MEMBER (d[0].data, d[0].offset, void *); @@ -1019,22 +1019,22 @@ mmap_init (SpaV4l2Source *this, return SPA_RESULT_ERROR; } - spa_log_info (state->log, "v4l2: got %d buffers\n", reqbuf.count); + spa_log_info (state->log, "v4l2: got %d buffers", reqbuf.count); *n_buffers = reqbuf.count; if (reqbuf.count < 2) { - spa_log_error (state->log, "v4l2: can't allocate enough buffers\n"); + spa_log_error (state->log, "v4l2: can't allocate enough buffers"); return SPA_RESULT_ERROR; } if (state->export_buf) - spa_log_info (state->log, "v4l2: using EXPBUF\n"); + spa_log_info (state->log, "v4l2: using EXPBUF"); for (i = 0; i < reqbuf.count; i++) { V4l2Buffer *b; SpaData *d; if (buffers[i]->n_datas < 1) { - spa_log_error (state->log, "v4l2: invalid buffer data\n"); + spa_log_error (state->log, "v4l2: invalid buffer data"); return SPA_RESULT_ERROR; } diff --git a/spa/plugins/videotestsrc/meson.build b/spa/plugins/videotestsrc/meson.build index f112ac38..53d9febc 100644 --- a/spa/plugins/videotestsrc/meson.build +++ b/spa/plugins/videotestsrc/meson.build @@ -2,7 +2,7 @@ videotestsrc_sources = ['videotestsrc.c', 'plugin.c'] videotestsrclib = shared_library('spa-videotestsrc', videotestsrc_sources, - include_directories : spa_inc, + include_directories : [ spa_inc, spa_libinc], dependencies : threads_dep, link_with : spalib, install : true, diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index 601a0177..024db177 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -30,6 +30,7 @@ #include <spa/node.h> #include <spa/queue.h> #include <spa/video/format.h> +#include <lib/props.h> #define FRAMES_TO_TIME(this,f) ((this->current_format.info.raw.framerate.num * (f) * SPA_NSEC_PER_SEC) / \ (this->current_format.info.raw.framerate.denom)) @@ -474,7 +475,7 @@ static SpaResult clear_buffers (SpaVideoTestSrc *this) { if (this->n_buffers > 0) { - spa_log_info (this->log, "videotestsrc %p: clear buffers\n", this); + spa_log_info (this->log, "videotestsrc %p: clear buffers", this); this->n_buffers = 0; SPA_QUEUE_INIT (&this->empty); SPA_QUEUE_INIT (&this->ready); @@ -639,7 +640,7 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node, case SPA_DATA_TYPE_MEMFD: case SPA_DATA_TYPE_DMABUF: if (d[0].data == NULL) { - spa_log_error (this->log, "videotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]); + spa_log_error (this->log, "videotestsrc %p: invalid memory on buffer %p", this, buffers[i]); continue; } b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void); diff --git a/spa/plugins/volume/meson.build b/spa/plugins/volume/meson.build index 06d3bf43..860e2e66 100644 --- a/spa/plugins/volume/meson.build +++ b/spa/plugins/volume/meson.build @@ -2,7 +2,7 @@ volume_sources = ['volume.c', 'plugin.c'] volumelib = shared_library('spa-volume', volume_sources, - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc], link_with : spalib, install : true, install_dir : '@0@/spa'.format(get_option('libdir'))) diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index 0a193b95..9fbbd7b3 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -24,6 +24,7 @@ #include <spa/id-map.h> #include <spa/node.h> #include <spa/audio/format.h> +#include <lib/props.h> typedef struct _SpaVolume SpaVolume; diff --git a/spa/plugins/xv/meson.build b/spa/plugins/xv/meson.build index 073528a9..c1a508e7 100644 --- a/spa/plugins/xv/meson.build +++ b/spa/plugins/xv/meson.build @@ -3,7 +3,7 @@ xv_sources = ['xv.c', xvlib = shared_library('spa-xv', xv_sources, - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc], dependencies : xv_dep, link_with : spalib, install : true, diff --git a/spa/plugins/xv/xv-sink.c b/spa/plugins/xv/xv-sink.c index 7b13c711..65e362f3 100644 --- a/spa/plugins/xv/xv-sink.c +++ b/spa/plugins/xv/xv-sink.c @@ -28,6 +28,7 @@ #include <spa/log.h> #include <spa/node.h> #include <spa/video/format.h> +#include <lib/props.h> typedef struct _SpaXvSink SpaXvSink; diff --git a/spa/tests/meson.build b/spa/tests/meson.build index ab644738..db474b14 100644 --- a/spa/tests/meson.build +++ b/spa/tests/meson.build @@ -1,11 +1,11 @@ executable('test-mixer', 'test-mixer.c', - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc ], dependencies : [dl_lib, pthread_lib], link_with : spalib, install : false) executable('test-v4l2', 'test-v4l2.c', - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc ], dependencies : [dl_lib, sdl_dep, pthread_lib], link_with : spalib, install : false) diff --git a/spa/tests/test-mixer.c b/spa/tests/test-mixer.c index 6b161cd8..50bf35d6 100644 --- a/spa/tests/test-mixer.c +++ b/spa/tests/test-mixer.c @@ -30,6 +30,8 @@ #include <spa/log.h> #include <spa/id-map.h> #include <spa/audio/format.h> +#include <lib/mapper.h> +#include <lib/props.h> typedef struct { uint32_t node; diff --git a/spa/tests/test-v4l2.c b/spa/tests/test-v4l2.c index a2460ad1..5f9cae22 100644 --- a/spa/tests/test-v4l2.c +++ b/spa/tests/test-v4l2.c @@ -31,8 +31,10 @@ #include <spa/id-map.h> #include <spa/log.h> #include <spa/node.h> -#include <spa/debug.h> #include <spa/video/format.h> +#include <lib/debug.h> +#include <lib/props.h> +#include <lib/mapper.h> #define MAX_BUFFERS 8 diff --git a/spa/tools/meson.build b/spa/tools/meson.build index 476b5169..c0360354 100644 --- a/spa/tools/meson.build +++ b/spa/tools/meson.build @@ -1,11 +1,11 @@ executable('spa-inspect', 'spa-inspect.c', - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc], dependencies : [dl_lib], link_with : spalib, install : true) executable('spa-monitor', 'spa-monitor.c', - include_directories : spa_inc, + include_directories : [spa_inc, spa_libinc], dependencies : [dl_lib], link_with : spalib, install : true) diff --git a/spa/tools/spa-inspect.c b/spa/tools/spa-inspect.c index 86268a78..f727b2ce 100644 --- a/spa/tools/spa-inspect.c +++ b/spa/tools/spa-inspect.c @@ -26,7 +26,8 @@ #include <spa/id-map.h> #include <spa/log.h> #include <spa/node.h> -#include <spa/debug.h> +#include <lib/debug.h> +#include <lib/mapper.h> typedef struct { uint32_t node; diff --git a/spa/tools/spa-monitor.c b/spa/tools/spa-monitor.c index 4c04fbcb..55c54e3d 100644 --- a/spa/tools/spa-monitor.c +++ b/spa/tools/spa-monitor.c @@ -29,7 +29,8 @@ #include <spa/id-map.h> #include <spa/monitor.h> #include <spa/poll.h> -#include <spa/debug.h> +#include <lib/debug.h> +#include <lib/mapper.h> typedef struct { uint32_t monitor; |