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
This commit is contained in:
Wim Taymans 2016-11-03 19:41:53 +01:00
parent a1c0bef2ed
commit 7e46f9e3ad
81 changed files with 1831 additions and 1030 deletions

105
pinos/client/array.h Normal file
View file

@ -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__ */

View file

@ -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;
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;
PinosMessageType type;
off_t offset;
void *data;
size_t size;
bool update;
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;
}

View file

@ -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;
} PinosMessagePortUpdate;
/* PINOS_CONTROL_CMD_PORT_STATUS_CHANGE */
/* PINOS_CONTROL_CMD_NODE_STATE_CHANGE */
/* PINOS_MESSAGE_NODE_STATE_CHANGE */
typedef struct {
SpaNodeState state;
} PinosControlCmdNodeStateChange;
} PinosMessageNodeStateChange;
/* PINOS_CONTROL_CMD_ADD_PORT */
/* PINOS_MESSAGE_PORT_STATUS_CHANGE */
/* PINOS_MESSAGE_NODE_EVENT */
typedef struct {
SpaNodeEvent *event;
} PinosMessageNodeEvent;
/* 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__ */

View file

@ -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;

106
pinos/client/log.c Normal file
View file

@ -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);
}
}

74
pinos/client/log.h Normal file
View file

@ -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__ */

111
pinos/client/map.h Normal file
View file

@ -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__ */

74
pinos/client/mapper.c Normal file
View file

@ -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;
}

View file

@ -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',

View file

@ -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__ */

View file

@ -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__ */

View file

@ -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);
PinosMessageType type = pinos_connection_get_type (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);
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);
PinosMessageType type = pinos_connection_get_type (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);
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;
}

View file

@ -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);

View file

@ -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);