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 "connection.h"
#include "serialize.h" #include "serialize.h"
#include "log.h"
#define MAX_BUFFER_SIZE 1024 #define MAX_BUFFER_SIZE 1024
#define MAX_FDS 28 #define MAX_FDS 28
typedef struct { typedef struct {
uint8_t *buffer_data; uint8_t *buffer_data;
size_t buffer_size; size_t buffer_size;
size_t buffer_maxsize; size_t buffer_maxsize;
int fds[MAX_FDS]; int fds[MAX_FDS];
unsigned int n_fds; unsigned int n_fds;
PinosControlCmd cmd; PinosMessageType type;
off_t offset; off_t offset;
void *data; void *data;
size_t size; size_t size;
bool update; bool update;
} ConnectionBuffer; } ConnectionBuffer;
struct _PinosConnection { struct _PinosConnection {
@ -52,9 +53,9 @@ struct _PinosConnection {
}; };
#if 0 #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 #else
#define PINOS_DEBUG_CONTROL(format,args...) #define PINOS_DEBUG_MESSAGE(format,args...)
#endif #endif
static bool static bool
@ -80,20 +81,20 @@ read_length (uint8_t * data, unsigned int size, size_t * length, size_t * skip)
} }
static void 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) if (nu->props)
nu->props = pinos_serialize_props_deserialize (conn->in.data, SPA_PTR_TO_INT (nu->props)); nu->props = pinos_serialize_props_deserialize (conn->in.data, SPA_PTR_TO_INT (nu->props));
} }
static void static void
connection_parse_port_update (PinosConnection *conn, PinosControlCmdPortUpdate *pu) connection_parse_port_update (PinosConnection *conn, PinosMessagePortUpdate *pu)
{ {
void *p; void *p;
unsigned int i; unsigned int i;
memcpy (pu, conn->in.data, sizeof (PinosControlCmdPortUpdate)); memcpy (pu, conn->in.data, sizeof (PinosMessagePortUpdate));
p = conn->in.data; p = conn->in.data;
@ -115,47 +116,47 @@ connection_parse_port_update (PinosConnection *conn, PinosControlCmdPortUpdate *
} }
static void 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) if (cmd->format)
cmd->format = pinos_serialize_format_deserialize (conn->in.data, SPA_PTR_TO_INT (cmd->format)); cmd->format = pinos_serialize_format_deserialize (conn->in.data, SPA_PTR_TO_INT (cmd->format));
} }
static void static void
connection_parse_use_buffers (PinosConnection *conn, PinosControlCmdUseBuffers *cmd) connection_parse_use_buffers (PinosConnection *conn, PinosMessageUseBuffers *cmd)
{ {
void *p; void *p;
p = conn->in.data; p = conn->in.data;
memcpy (cmd, p, sizeof (PinosControlCmdUseBuffers)); memcpy (cmd, p, sizeof (PinosMessageUseBuffers));
if (cmd->buffers) 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 static void
connection_parse_node_event (PinosConnection *conn, PinosControlCmdNodeEvent *cmd) connection_parse_node_event (PinosConnection *conn, PinosMessageNodeEvent *cmd)
{ {
void *p = conn->in.data; void *p = conn->in.data;
memcpy (cmd, p, sizeof (PinosControlCmdNodeEvent)); memcpy (cmd, p, sizeof (PinosMessageNodeEvent));
if (cmd->event) if (cmd->event)
cmd->event = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->event), SpaNodeEvent); cmd->event = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->event), SpaNodeEvent);
} }
static void static void
connection_parse_node_command (PinosConnection *conn, PinosControlCmdNodeCommand *cmd) connection_parse_node_command (PinosConnection *conn, PinosMessageNodeCommand *cmd)
{ {
void *p = conn->in.data; void *p = conn->in.data;
memcpy (cmd, p, sizeof (PinosControlCmdNodeCommand)); memcpy (cmd, p, sizeof (PinosMessageNodeCommand));
if (cmd->command) if (cmd->command)
cmd->command = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->command), SpaNodeCommand); cmd->command = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->command), SpaNodeCommand);
} }
static void static void
connection_parse_port_command (PinosConnection *conn, PinosControlCmdPortCommand *cmd) connection_parse_port_command (PinosConnection *conn, PinosMessagePortCommand *cmd)
{ {
void *p = conn->in.data; void *p = conn->in.data;
memcpy (cmd, p, sizeof (PinosControlCmdPortCommand)); memcpy (cmd, p, sizeof (PinosMessagePortCommand));
if (cmd->command) if (cmd->command)
cmd->command = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->command), SpaNodeCommand); 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) { 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); 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); buf->buffer_data = realloc (buf->buffer_data, buf->buffer_maxsize);
} }
return (uint8_t *) buf->buffer_data + buf->buffer_size; return (uint8_t *) buf->buffer_data + buf->buffer_size;
} }
static void * 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; uint8_t *p;
unsigned int plen; 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 */ /* 1 for cmd, plen for size and size for payload */
p = connection_ensure_size (conn, buf, 1 + plen + size); p = connection_ensure_size (conn, buf, 1 + plen + size);
buf->cmd = cmd; buf->type = type;
buf->offset = buf->buffer_size; buf->offset = buf->buffer_size;
buf->buffer_size += 1 + plen + size; buf->buffer_size += 1 + plen + size;
*p++ = cmd; *p++ = type;
/* write length */ /* write length */
while (plen) { while (plen) {
plen--; plen--;
@ -199,21 +200,21 @@ connection_add_cmd (PinosConnection *conn, PinosControlCmd cmd, size_t size)
} }
static void static void
connection_add_node_update (PinosConnection *conn, PinosControlCmdNodeUpdate *nu) connection_add_node_update (PinosConnection *conn, PinosMessageNodeUpdate *nu)
{ {
size_t len; size_t len;
void *p; void *p;
PinosControlCmdNodeUpdate *d; PinosMessageNodeUpdate *d;
/* calc len */ /* calc len */
len = sizeof (PinosControlCmdNodeUpdate); len = sizeof (PinosMessageNodeUpdate);
len += pinos_serialize_props_get_size (nu->props); len += pinos_serialize_props_get_size (nu->props);
p = connection_add_cmd (conn, PINOS_CONTROL_CMD_NODE_UPDATE, len); p = connection_add_message (conn, PINOS_MESSAGE_NODE_UPDATE, len);
memcpy (p, nu, sizeof (PinosControlCmdNodeUpdate)); memcpy (p, nu, sizeof (PinosMessageNodeUpdate));
d = p; d = p;
p = SPA_MEMBER (d, sizeof (PinosControlCmdNodeUpdate), void); p = SPA_MEMBER (d, sizeof (PinosMessageNodeUpdate), void);
if (nu->props) { if (nu->props) {
len = pinos_serialize_props_serialize (p, nu->props); len = pinos_serialize_props_serialize (p, nu->props);
d->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); d->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
@ -223,16 +224,16 @@ connection_add_node_update (PinosConnection *conn, PinosControlCmdNodeUpdate *nu
} }
static void static void
connection_add_port_update (PinosConnection *conn, PinosControlCmdPortUpdate *pu) connection_add_port_update (PinosConnection *conn, PinosMessagePortUpdate *pu)
{ {
size_t len; size_t len;
void *p; void *p;
int i; int i;
SpaFormat **bfa; SpaFormat **bfa;
PinosControlCmdPortUpdate *d; PinosMessagePortUpdate *d;
/* calc len */ /* calc len */
len = sizeof (PinosControlCmdPortUpdate); len = sizeof (PinosMessagePortUpdate);
len += pu->n_possible_formats * sizeof (SpaFormat *); len += pu->n_possible_formats * sizeof (SpaFormat *);
for (i = 0; i < pu->n_possible_formats; i++) { for (i = 0; i < pu->n_possible_formats; i++) {
len += pinos_serialize_format_get_size (pu->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) if (pu->info)
len += pinos_serialize_port_info_get_size (pu->info); len += pinos_serialize_port_info_get_size (pu->info);
p = connection_add_cmd (conn, PINOS_CONTROL_CMD_PORT_UPDATE, len); p = connection_add_message (conn, PINOS_MESSAGE_PORT_UPDATE, len);
memcpy (p, pu, sizeof (PinosControlCmdPortUpdate)); memcpy (p, pu, sizeof (PinosMessagePortUpdate));
d = p; d = p;
p = SPA_MEMBER (d, sizeof (PinosControlCmdPortUpdate), void); p = SPA_MEMBER (d, sizeof (PinosMessagePortUpdate), void);
bfa = p; bfa = p;
if (pu->n_possible_formats) if (pu->n_possible_formats)
d->possible_formats = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); 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 static void
connection_add_set_format (PinosConnection *conn, PinosControlCmdSetFormat *sf) connection_add_set_format (PinosConnection *conn, PinosMessageSetFormat *sf)
{ {
size_t len; size_t len;
void *p; void *p;
/* calculate length */ /* calculate length */
/* port_id + format + mask */ /* port_id + format + mask */
len = sizeof (PinosControlCmdSetFormat) + pinos_serialize_format_get_size (sf->format); len = sizeof (PinosMessageSetFormat) + pinos_serialize_format_get_size (sf->format);
p = connection_add_cmd (conn, PINOS_CONTROL_CMD_SET_FORMAT, len); p = connection_add_message (conn, PINOS_MESSAGE_SET_FORMAT, len);
memcpy (p, sf, sizeof (PinosControlCmdSetFormat)); memcpy (p, sf, sizeof (PinosMessageSetFormat));
sf = p; sf = p;
p = SPA_MEMBER (sf, sizeof (PinosControlCmdSetFormat), void); p = SPA_MEMBER (sf, sizeof (PinosMessageSetFormat), void);
if (sf->format) { if (sf->format) {
len = pinos_serialize_format_serialize (p, sf->format); len = pinos_serialize_format_serialize (p, sf->format);
sf->format = SPA_INT_TO_PTR (SPA_PTRDIFF (p, sf)); sf->format = SPA_INT_TO_PTR (SPA_PTRDIFF (p, sf));
@ -305,21 +306,21 @@ connection_add_set_format (PinosConnection *conn, PinosControlCmdSetFormat *sf)
} }
static void static void
connection_add_use_buffers (PinosConnection *conn, PinosControlCmdUseBuffers *ub) connection_add_use_buffers (PinosConnection *conn, PinosMessageUseBuffers *ub)
{ {
size_t len; size_t len;
int i; int i;
PinosControlCmdUseBuffers *d; PinosMessageUseBuffers *d;
PinosControlMemRef *mr; PinosMessageMemRef *mr;
/* calculate length */ /* calculate length */
len = sizeof (PinosControlCmdUseBuffers); len = sizeof (PinosMessageUseBuffers);
len += ub->n_buffers * sizeof (PinosControlMemRef); len += ub->n_buffers * sizeof (PinosMessageMemRef);
d = connection_add_cmd (conn, PINOS_CONTROL_CMD_USE_BUFFERS, len); d = connection_add_message (conn, PINOS_MESSAGE_USE_BUFFERS, len);
memcpy (d, ub, sizeof (PinosControlCmdUseBuffers)); memcpy (d, ub, sizeof (PinosMessageUseBuffers));
mr = SPA_MEMBER (d, sizeof (PinosControlCmdUseBuffers), void); mr = SPA_MEMBER (d, sizeof (PinosMessageUseBuffers), void);
if (d->n_buffers) if (d->n_buffers)
d->buffers = SPA_INT_TO_PTR (SPA_PTRDIFF (mr, d)); 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; d->buffers = 0;
for (i = 0; i < ub->n_buffers; i++) 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 static void
connection_add_node_event (PinosConnection *conn, PinosControlCmdNodeEvent *ev) connection_add_node_event (PinosConnection *conn, PinosMessageNodeEvent *ev)
{ {
size_t len; size_t len;
void *p; void *p;
PinosControlCmdNodeEvent *d; PinosMessageNodeEvent *d;
/* calculate length */ /* calculate length */
len = sizeof (PinosControlCmdNodeEvent); len = sizeof (PinosMessageNodeEvent);
len += ev->event->size; len += ev->event->size;
p = connection_add_cmd (conn, PINOS_CONTROL_CMD_NODE_EVENT, len); p = connection_add_message (conn, PINOS_MESSAGE_NODE_EVENT, len);
memcpy (p, ev, sizeof (PinosControlCmdNodeEvent)); memcpy (p, ev, sizeof (PinosMessageNodeEvent));
d = p; 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)); d->event = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
memcpy (p, ev->event, ev->event->size); memcpy (p, ev->event, ev->event->size);
} }
static void static void
connection_add_node_command (PinosConnection *conn, PinosControlCmdNodeCommand *cm) connection_add_node_command (PinosConnection *conn, PinosMessageNodeCommand *cm)
{ {
size_t len; size_t len;
void *p; void *p;
PinosControlCmdNodeCommand *d; PinosMessageNodeCommand *d;
/* calculate length */ /* calculate length */
len = sizeof (PinosControlCmdNodeCommand); len = sizeof (PinosMessageNodeCommand);
len += cm->command->size; len += cm->command->size;
p = connection_add_cmd (conn, PINOS_CONTROL_CMD_NODE_COMMAND, len); p = connection_add_message (conn, PINOS_MESSAGE_NODE_COMMAND, len);
memcpy (p, cm, sizeof (PinosControlCmdNodeCommand)); memcpy (p, cm, sizeof (PinosMessageNodeCommand));
d = p; 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)); d->command = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
memcpy (p, cm->command, cm->command->size); memcpy (p, cm->command, cm->command->size);
} }
static void static void
connection_add_port_command (PinosConnection *conn, PinosControlCmdPortCommand *cm) connection_add_port_command (PinosConnection *conn, PinosMessagePortCommand *cm)
{ {
size_t len; size_t len;
void *p; void *p;
PinosControlCmdPortCommand *d; PinosMessagePortCommand *d;
/* calculate length */ /* calculate length */
len = sizeof (PinosControlCmdPortCommand); len = sizeof (PinosMessagePortCommand);
len += cm->command->size; len += cm->command->size;
p = connection_add_cmd (conn, PINOS_CONTROL_CMD_PORT_COMMAND, len); p = connection_add_message (conn, PINOS_MESSAGE_PORT_COMMAND, len);
memcpy (p, cm, sizeof (PinosControlCmdPortCommand)); memcpy (p, cm, sizeof (PinosMessagePortCommand));
d = p; 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)); d->command = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
memcpy (p, cm->command, cm->command->size); memcpy (p, cm->command, cm->command->size);
} }
static gboolean static bool
refill_buffer (PinosConnection *conn, ConnectionBuffer *buf) refill_buffer (PinosConnection *conn, ConnectionBuffer *buf)
{ {
ssize_t len; ssize_t len;
@ -422,7 +423,7 @@ refill_buffer (PinosConnection *conn, ConnectionBuffer *buf)
} }
if (len < 4) if (len < 4)
return FALSE; return false;
buf->buffer_size += len; 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); 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)); 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 */ /* ERRORS */
recv_error: recv_error:
{ {
g_warning ("could not recvmsg on fd %d: %s", conn->fd, strerror (errno)); pinos_log_error ("could not recvmsg on fd %d: %s", conn->fd, strerror (errno));
return FALSE; return false;
} }
} }
@ -458,7 +459,7 @@ clear_buffer (ConnectionBuffer *buf)
} }
} }
buf->n_fds = 0; buf->n_fds = 0;
buf->cmd = PINOS_CONTROL_CMD_INVALID; buf->type = PINOS_MESSAGE_INVALID;
buf->offset = 0; buf->offset = 0;
buf->size = 0; buf->size = 0;
buf->buffer_size = 0; buf->buffer_size = 0;
@ -494,16 +495,16 @@ pinos_connection_free (PinosConnection *conn)
* *
* Move to the next packet in @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) pinos_connection_has_next (PinosConnection *conn)
{ {
size_t len, size, skip; size_t len, size, skip;
uint8_t *data; uint8_t *data;
ConnectionBuffer *buf; ConnectionBuffer *buf;
g_return_val_if_fail (conn != NULL, FALSE); spa_return_val_if_fail (conn != NULL, false);
buf = &conn->in; buf = &conn->in;
@ -523,13 +524,13 @@ again:
if (buf->offset >= size) { if (buf->offset >= size) {
clear_buffer (buf); clear_buffer (buf);
buf->update = true; buf->update = true;
return FALSE; return false;
} }
data += buf->offset; data += buf->offset;
size -= buf->offset; size -= buf->offset;
buf->cmd = *data; buf->type = *data;
data++; data++;
size--; size--;
@ -542,97 +543,97 @@ again:
buf->data = data + skip; buf->data = data + skip;
buf->offset += 1 + skip; buf->offset += 1 + skip;
return TRUE; return true;
} }
PinosControlCmd PinosMessageType
pinos_connection_get_cmd (PinosConnection *conn) 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 bool
pinos_connection_parse_cmd (PinosConnection *conn, pinos_connection_parse_message (PinosConnection *conn,
gpointer command) 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 */ /* C -> S */
case PINOS_CONTROL_CMD_NODE_UPDATE: case PINOS_MESSAGE_NODE_UPDATE:
connection_parse_node_update (conn, command); connection_parse_node_update (conn, message);
break; break;
case PINOS_CONTROL_CMD_PORT_UPDATE: case PINOS_MESSAGE_PORT_UPDATE:
connection_parse_port_update (conn, command); connection_parse_port_update (conn, message);
break; break;
case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: case PINOS_MESSAGE_PORT_STATUS_CHANGE:
g_warning ("implement iter of %d", conn->in.cmd); pinos_log_warn ("implement iter of %d", conn->in.type);
break; break;
case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: case PINOS_MESSAGE_NODE_STATE_CHANGE:
if (conn->in.size < sizeof (PinosControlCmdNodeStateChange)) if (conn->in.size < sizeof (PinosMessageNodeStateChange))
return FALSE; return false;
memcpy (command, conn->in.data, sizeof (PinosControlCmdNodeStateChange)); memcpy (message, conn->in.data, sizeof (PinosMessageNodeStateChange));
break; break;
/* S -> C */ /* S -> C */
case PINOS_CONTROL_CMD_ADD_PORT: case PINOS_MESSAGE_ADD_PORT:
if (conn->in.size < sizeof (PinosControlCmdAddPort)) if (conn->in.size < sizeof (PinosMessageAddPort))
return FALSE; return false;
memcpy (command, conn->in.data, sizeof (PinosControlCmdAddPort)); memcpy (message, conn->in.data, sizeof (PinosMessageAddPort));
break; break;
case PINOS_CONTROL_CMD_REMOVE_PORT: case PINOS_MESSAGE_REMOVE_PORT:
if (conn->in.size < sizeof (PinosControlCmdRemovePort)) if (conn->in.size < sizeof (PinosMessageRemovePort))
return FALSE; return false;
memcpy (command, conn->in.data, sizeof (PinosControlCmdRemovePort)); memcpy (message, conn->in.data, sizeof (PinosMessageRemovePort));
break; break;
case PINOS_CONTROL_CMD_SET_FORMAT: case PINOS_MESSAGE_SET_FORMAT:
connection_parse_set_format (conn, command); connection_parse_set_format (conn, message);
break; break;
case PINOS_CONTROL_CMD_SET_PROPERTY: case PINOS_MESSAGE_SET_PROPERTY:
g_warning ("implement iter of %d", conn->in.cmd); pinos_log_warn ("implement iter of %d", conn->in.type);
break; break;
/* bidirectional */ /* bidirectional */
case PINOS_CONTROL_CMD_ADD_MEM: case PINOS_MESSAGE_ADD_MEM:
if (conn->in.size < sizeof (PinosControlCmdAddMem)) if (conn->in.size < sizeof (PinosMessageAddMem))
return FALSE; return false;
memcpy (command, conn->in.data, sizeof (PinosControlCmdAddMem)); memcpy (message, conn->in.data, sizeof (PinosMessageAddMem));
break; break;
case PINOS_CONTROL_CMD_USE_BUFFERS: case PINOS_MESSAGE_USE_BUFFERS:
connection_parse_use_buffers (conn, command); connection_parse_use_buffers (conn, message);
break; break;
case PINOS_CONTROL_CMD_PROCESS_BUFFER: case PINOS_MESSAGE_PROCESS_BUFFER:
if (conn->in.size < sizeof (PinosControlCmdProcessBuffer)) if (conn->in.size < sizeof (PinosMessageProcessBuffer))
return FALSE; return false;
memcpy (command, conn->in.data, sizeof (PinosControlCmdProcessBuffer)); memcpy (message, conn->in.data, sizeof (PinosMessageProcessBuffer));
break; break;
case PINOS_CONTROL_CMD_NODE_EVENT: case PINOS_MESSAGE_NODE_EVENT:
connection_parse_node_event (conn, command); connection_parse_node_event (conn, message);
break; break;
case PINOS_CONTROL_CMD_NODE_COMMAND: case PINOS_MESSAGE_NODE_COMMAND:
connection_parse_node_command (conn, command); connection_parse_node_command (conn, message);
break; break;
case PINOS_CONTROL_CMD_PORT_COMMAND: case PINOS_MESSAGE_PORT_COMMAND:
connection_parse_port_command (conn, command); connection_parse_port_command (conn, message);
break; break;
case PINOS_CONTROL_CMD_INVALID: case PINOS_MESSAGE_INVALID:
return FALSE; return false;
} }
return TRUE; return true;
} }
/** /**
@ -648,13 +649,13 @@ pinos_connection_parse_cmd (PinosConnection *conn,
*/ */
int int
pinos_connection_get_fd (PinosConnection *conn, pinos_connection_get_fd (PinosConnection *conn,
guint index, unsigned int index,
gboolean close) bool close)
{ {
int fd; int fd;
g_return_val_if_fail (conn != NULL, -1); spa_return_val_if_fail (conn != NULL, -1);
g_return_val_if_fail (index < conn->in.n_fds, -1); spa_return_val_if_fail (index < conn->in.n_fds, -1);
fd = conn->in.fds[index]; fd = conn->in.fds[index];
if (fd < 0) if (fd < 0)
@ -677,11 +678,11 @@ pinos_connection_get_fd (PinosConnection *conn,
int int
pinos_connection_add_fd (PinosConnection *conn, pinos_connection_add_fd (PinosConnection *conn,
int fd, int fd,
gboolean close) bool close)
{ {
int index, i; 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++) { for (i = 0; i < conn->out.n_fds; i++) {
if (conn->out.fds[i] == fd || conn->out.fds[i] == -fd) 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 * @conn: a #PinosConnection
* @cmd: a #PinosControlCmd * @type: a #PinosMessageType
* @command: a command * @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 bool
pinos_connection_add_cmd (PinosConnection *conn, pinos_connection_add_message (PinosConnection *conn,
PinosControlCmd cmd, PinosMessageType type,
gpointer command) void *message)
{ {
void *p; void *p;
g_return_val_if_fail (conn != NULL, FALSE); spa_return_val_if_fail (conn != NULL, false);
g_return_val_if_fail (command != NULL, FALSE); spa_return_val_if_fail (message != NULL, false);
switch (cmd) { switch (type) {
/* C -> S */ /* C -> S */
case PINOS_CONTROL_CMD_NODE_UPDATE: case PINOS_MESSAGE_NODE_UPDATE:
connection_add_node_update (conn, command); connection_add_node_update (conn, message);
break; break;
case PINOS_CONTROL_CMD_PORT_UPDATE: case PINOS_MESSAGE_PORT_UPDATE:
connection_add_port_update (conn, command); connection_add_port_update (conn, message);
break; break;
case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: case PINOS_MESSAGE_PORT_STATUS_CHANGE:
p = connection_add_cmd (conn, cmd, 0); p = connection_add_message (conn, type, 0);
break; break;
case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: case PINOS_MESSAGE_NODE_STATE_CHANGE:
p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdNodeStateChange)); p = connection_add_message (conn, type, sizeof (PinosMessageNodeStateChange));
memcpy (p, command, sizeof (PinosControlCmdNodeStateChange)); memcpy (p, message, sizeof (PinosMessageNodeStateChange));
break; break;
/* S -> C */ /* S -> C */
case PINOS_CONTROL_CMD_ADD_PORT: case PINOS_MESSAGE_ADD_PORT:
p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdAddPort)); p = connection_add_message (conn, type, sizeof (PinosMessageAddPort));
memcpy (p, command, sizeof (PinosControlCmdAddPort)); memcpy (p, message, sizeof (PinosMessageAddPort));
break; break;
case PINOS_CONTROL_CMD_REMOVE_PORT: case PINOS_MESSAGE_REMOVE_PORT:
p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdRemovePort)); p = connection_add_message (conn, type, sizeof (PinosMessageRemovePort));
memcpy (p, command, sizeof (PinosControlCmdRemovePort)); memcpy (p, message, sizeof (PinosMessageRemovePort));
break; break;
case PINOS_CONTROL_CMD_SET_FORMAT: case PINOS_MESSAGE_SET_FORMAT:
connection_add_set_format (conn, command); connection_add_set_format (conn, message);
break; break;
case PINOS_CONTROL_CMD_SET_PROPERTY: case PINOS_MESSAGE_SET_PROPERTY:
g_warning ("implement builder of %d", cmd); pinos_log_warn ("implement builder of %d", type);
break; break;
/* bidirectional */ /* bidirectional */
case PINOS_CONTROL_CMD_ADD_MEM: case PINOS_MESSAGE_ADD_MEM:
p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdAddMem)); p = connection_add_message (conn, type, sizeof (PinosMessageAddMem));
memcpy (p, command, sizeof (PinosControlCmdAddMem)); memcpy (p, message, sizeof (PinosMessageAddMem));
break; break;
case PINOS_CONTROL_CMD_USE_BUFFERS: case PINOS_MESSAGE_USE_BUFFERS:
connection_add_use_buffers (conn, command); connection_add_use_buffers (conn, message);
break; break;
case PINOS_CONTROL_CMD_PROCESS_BUFFER: case PINOS_MESSAGE_PROCESS_BUFFER:
p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdProcessBuffer)); p = connection_add_message (conn, type, sizeof (PinosMessageProcessBuffer));
memcpy (p, command, sizeof (PinosControlCmdProcessBuffer)); memcpy (p, message, sizeof (PinosMessageProcessBuffer));
break; break;
case PINOS_CONTROL_CMD_NODE_EVENT: case PINOS_MESSAGE_NODE_EVENT:
connection_add_node_event (conn, command); connection_add_node_event (conn, message);
break; break;
case PINOS_CONTROL_CMD_NODE_COMMAND: case PINOS_MESSAGE_NODE_COMMAND:
connection_add_node_command (conn, command); connection_add_node_command (conn, message);
break; break;
case PINOS_CONTROL_CMD_PORT_COMMAND: case PINOS_MESSAGE_PORT_COMMAND:
connection_add_port_command (conn, command); connection_add_port_command (conn, message);
break; break;
case PINOS_CONTROL_CMD_INVALID: case PINOS_MESSAGE_INVALID:
return FALSE; return false;
} }
return TRUE; return true;
} }
gboolean bool
pinos_connection_flush (PinosConnection *conn) pinos_connection_flush (PinosConnection *conn)
{ {
ssize_t len; ssize_t len;
@ -797,12 +798,12 @@ pinos_connection_flush (PinosConnection *conn)
int *cm, i, fds_len; int *cm, i, fds_len;
ConnectionBuffer *buf; ConnectionBuffer *buf;
g_return_val_if_fail (conn != NULL, FALSE); spa_return_val_if_fail (conn != NULL, false);
buf = &conn->out; buf = &conn->out;
if (buf->buffer_size == 0) if (buf->buffer_size == 0)
return TRUE; return true;
fds_len = buf->n_fds * sizeof (int); fds_len = buf->n_fds * sizeof (int);
@ -840,26 +841,26 @@ pinos_connection_flush (PinosConnection *conn)
buf->buffer_size -= len; buf->buffer_size -= len;
buf->n_fds = 0; 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 */ /* ERRORS */
send_error: send_error:
{ {
g_warning ("could not sendmsg: %s", strerror (errno)); pinos_log_error ("could not sendmsg: %s", strerror (errno));
return FALSE; return false;
} }
} }
gboolean bool
pinos_connection_clear (PinosConnection *conn) 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->out);
clear_buffer (&conn->in); clear_buffer (&conn->in);
conn->in.update = true; conn->in.update = true;
return TRUE; return true;
} }

View file

@ -17,12 +17,12 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef __PINOS_CONTROL_H__ #ifndef __PINOS_CONNECTION_H__
#define __PINOS_CONTROL_H__ #define __PINOS_CONNECTION_H__
#include <glib-object.h> #ifdef __cplusplus
extern "C" {
G_BEGIN_DECLS #endif
#include <spa/defs.h> #include <spa/defs.h>
#include <spa/props.h> #include <spa/props.h>
@ -33,113 +33,116 @@ G_BEGIN_DECLS
typedef struct _PinosConnection PinosConnection; typedef struct _PinosConnection PinosConnection;
typedef enum { typedef enum {
PINOS_CONTROL_CMD_INVALID = 0, PINOS_MESSAGE_INVALID = 0,
/* client to server */ /* client to server */
PINOS_CONTROL_CMD_NODE_UPDATE = 1, PINOS_MESSAGE_NODE_UPDATE = 1,
PINOS_CONTROL_CMD_PORT_UPDATE = 2, PINOS_MESSAGE_PORT_UPDATE = 2,
PINOS_CONTROL_CMD_NODE_STATE_CHANGE = 3, 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 */ /* server to client */
PINOS_CONTROL_CMD_ADD_PORT = 32, PINOS_MESSAGE_ADD_PORT = 32,
PINOS_CONTROL_CMD_REMOVE_PORT = 33, PINOS_MESSAGE_REMOVE_PORT = 33,
PINOS_CONTROL_CMD_SET_FORMAT = 34, PINOS_MESSAGE_SET_FORMAT = 34,
PINOS_CONTROL_CMD_SET_PROPERTY = 35, PINOS_MESSAGE_SET_PROPERTY = 35,
PINOS_CONTROL_CMD_NODE_COMMAND = 36, PINOS_MESSAGE_NODE_COMMAND = 36,
PINOS_CONTROL_CMD_PORT_COMMAND = 37, PINOS_MESSAGE_PORT_COMMAND = 37,
/* both */ /* both */
PINOS_CONTROL_CMD_ADD_MEM = 64, PINOS_MESSAGE_ADD_MEM = 64,
PINOS_CONTROL_CMD_USE_BUFFERS = 66, PINOS_MESSAGE_USE_BUFFERS = 66,
PINOS_CONTROL_CMD_PROCESS_BUFFER = 67, PINOS_MESSAGE_PROCESS_BUFFER = 67,
PINOS_CONTROL_CMD_NODE_EVENT = 68, } PinosMessageType;
} PinosControlCmd;
/* PINOS_CONTROL_CMD_NODE_UPDATE */ /* PINOS_MESSAGE_NODE_UPDATE */
typedef struct { typedef struct {
#define PINOS_CONTROL_CMD_NODE_UPDATE_MAX_INPUTS (1 << 0) #define PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS (1 << 0)
#define PINOS_CONTROL_CMD_NODE_UPDATE_MAX_OUTPUTS (1 << 1) #define PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS (1 << 1)
#define PINOS_CONTROL_CMD_NODE_UPDATE_PROPS (1 << 2) #define PINOS_MESSAGE_NODE_UPDATE_PROPS (1 << 2)
uint32_t change_mask; uint32_t change_mask;
unsigned int max_input_ports; unsigned int max_input_ports;
unsigned int max_output_ports; unsigned int max_output_ports;
const SpaProps *props; const SpaProps *props;
} PinosControlCmdNodeUpdate; } PinosMessageNodeUpdate;
/* PINOS_CONTROL_CMD_PORT_UPDATE */ /* PINOS_MESSAGE_PORT_UPDATE */
typedef struct { typedef struct {
SpaDirection direction; SpaDirection direction;
uint32_t port_id; uint32_t port_id;
#define PINOS_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS (1 << 0) #define PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS (1 << 0)
#define PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT (1 << 1) #define PINOS_MESSAGE_PORT_UPDATE_FORMAT (1 << 1)
#define PINOS_CONTROL_CMD_PORT_UPDATE_PROPS (1 << 2) #define PINOS_MESSAGE_PORT_UPDATE_PROPS (1 << 2)
#define PINOS_CONTROL_CMD_PORT_UPDATE_INFO (1 << 3) #define PINOS_MESSAGE_PORT_UPDATE_INFO (1 << 3)
uint32_t change_mask; uint32_t change_mask;
unsigned int n_possible_formats; unsigned int n_possible_formats;
SpaFormat **possible_formats; SpaFormat **possible_formats;
SpaFormat *format; SpaFormat *format;
const SpaProps *props; const SpaProps *props;
const SpaPortInfo *info; const SpaPortInfo *info;
} PinosControlCmdPortUpdate; } PinosMessagePortUpdate;
/* PINOS_CONTROL_CMD_PORT_STATUS_CHANGE */ /* PINOS_MESSAGE_NODE_STATE_CHANGE */
/* PINOS_CONTROL_CMD_NODE_STATE_CHANGE */
typedef struct { typedef struct {
SpaNodeState state; 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 { typedef struct {
uint32_t seq; uint32_t seq;
SpaDirection direction; SpaDirection direction;
uint32_t port_id; uint32_t port_id;
} PinosControlCmdAddPort; } PinosMessageAddPort;
/* PINOS_CONTROL_CMD_REMOVE_PORT */ /* PINOS_MESSAGE_REMOVE_PORT */
typedef struct { typedef struct {
uint32_t seq; uint32_t seq;
SpaDirection direction; SpaDirection direction;
uint32_t port_id; uint32_t port_id;
} PinosControlCmdRemovePort; } PinosMessageRemovePort;
/* PINOS_CONTROL_CMD_SET_FORMAT */ /* PINOS_MESSAGE_SET_FORMAT */
typedef struct { typedef struct {
uint32_t seq; uint32_t seq;
SpaDirection direction; SpaDirection direction;
uint32_t port_id; uint32_t port_id;
SpaPortFormatFlags flags; SpaPortFormatFlags flags;
SpaFormat *format; SpaFormat *format;
} PinosControlCmdSetFormat; } PinosMessageSetFormat;
/* PINOS_CONTROL_CMD_SET_PROPERTY */ /* PINOS_MESSAGE_SET_PROPERTY */
typedef struct { typedef struct {
uint32_t seq; uint32_t seq;
SpaDirection direction;
uint32_t port_id;
uint32_t id; uint32_t id;
size_t size; size_t size;
void *value; void *value;
} PinosControlCmdSetProperty; } PinosMessageSetProperty;
/* PINOS_CONTROL_CMD_NODE_COMMAND */ /* PINOS_MESSAGE_NODE_COMMAND */
typedef struct { typedef struct {
uint32_t seq; uint32_t seq;
SpaNodeCommand *command; SpaNodeCommand *command;
} PinosControlCmdNodeCommand; } PinosMessageNodeCommand;
/* PINOS_CONTROL_CMD_PORT_COMMAND */ /* PINOS_MESSAGE_PORT_COMMAND */
typedef struct { typedef struct {
uint32_t port_id; uint32_t port_id;
SpaNodeCommand *command; SpaNodeCommand *command;
} PinosControlCmdPortCommand; } PinosMessagePortCommand;
/* PINOS_CONTROL_CMD_ADD_MEM */ /* PINOS_MESSAGE_ADD_MEM */
typedef struct { typedef struct {
SpaDirection direction; SpaDirection direction;
uint32_t port_id; uint32_t port_id;
@ -149,57 +152,53 @@ typedef struct {
uint32_t flags; uint32_t flags;
off_t offset; off_t offset;
size_t size; size_t size;
} PinosControlCmdAddMem; } PinosMessageAddMem;
typedef struct { typedef struct {
uint32_t mem_id; uint32_t mem_id;
off_t offset; off_t offset;
size_t size; size_t size;
} PinosControlMemRef; } PinosMessageMemRef;
/* PINOS_CONTROL_CMD_USE_BUFFERS */ /* PINOS_MESSAGE_USE_BUFFERS */
typedef struct { typedef struct {
uint32_t seq; uint32_t seq;
SpaDirection direction; SpaDirection direction;
uint32_t port_id; uint32_t port_id;
unsigned int n_buffers; unsigned int n_buffers;
PinosControlMemRef *buffers; PinosMessageMemRef *buffers;
} PinosControlCmdUseBuffers; } PinosMessageUseBuffers;
/* PINOS_CONTROL_CMD_PROCESS_BUFFER */ /* PINOS_MESSAGE_PROCESS_BUFFER */
typedef struct { typedef struct {
SpaDirection direction; SpaDirection direction;
uint32_t port_id; uint32_t port_id;
uint32_t buffer_id; uint32_t buffer_id;
} PinosControlCmdProcessBuffer; } PinosMessageProcessBuffer;
/* PINOS_CONTROL_CMD_NODE_EVENT */
typedef struct {
SpaNodeEvent *event;
} PinosControlCmdNodeEvent;
PinosConnection * pinos_connection_new (int fd); PinosConnection * pinos_connection_new (int fd);
void pinos_connection_free (PinosConnection *conn); void pinos_connection_free (PinosConnection *conn);
gboolean pinos_connection_has_next (PinosConnection *conn); bool pinos_connection_has_next (PinosConnection *conn);
PinosControlCmd pinos_connection_get_cmd (PinosConnection *conn); PinosMessageType pinos_connection_get_type (PinosConnection *conn);
gboolean pinos_connection_parse_cmd (PinosConnection *conn, bool pinos_connection_parse_message (PinosConnection *conn,
gpointer command); void *msg);
int pinos_connection_get_fd (PinosConnection *conn, int pinos_connection_get_fd (PinosConnection *conn,
guint index, unsigned int index,
gboolean close); bool close);
int pinos_connection_add_fd (PinosConnection *conn, int pinos_connection_add_fd (PinosConnection *conn,
int fd, int fd,
gboolean close); bool close);
gboolean pinos_connection_add_cmd (PinosConnection *conn, bool pinos_connection_add_message (PinosConnection *conn,
PinosControlCmd cmd, PinosMessageType type,
gpointer command); void *msg);
gboolean pinos_connection_flush (PinosConnection *conn); bool pinos_connection_flush (PinosConnection *conn);
gboolean pinos_connection_clear (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); PinosContext *context = PINOS_CONTEXT (object);
PinosContextPrivate *priv = context->priv; PinosContextPrivate *priv = context->priv;
g_debug ("free context %p", context); pinos_log_debug ("free context %p", context);
if (priv->id) if (priv->id)
g_bus_unwatch_name(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); 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; 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 = [ pinos_headers = [
'array.h',
'context.h', 'context.h',
'format.h', 'format.h',
'introspect.h', 'introspect.h',
'log.h',
'map.h',
'pinos.h', 'pinos.h',
'properties.h', 'properties.h',
'ringbuffer.h', 'ringbuffer.h',
@ -16,6 +19,8 @@ pinos_sources = [
'context.c', 'context.c',
'format.c', 'format.c',
'introspect.c', 'introspect.c',
'log.c',
'mapper.c',
'properties.c', 'properties.c',
'serialize.c', 'serialize.c',
'stream.c', 'stream.c',

View file

@ -25,11 +25,13 @@ extern const char g_log_domain_pinos[];
#include <pinos/client/context.h> #include <pinos/client/context.h>
#include <pinos/client/enumtypes.h> #include <pinos/client/enumtypes.h>
#include <pinos/client/introspect.h> #include <pinos/client/introspect.h>
#include <pinos/client/log.h>
#include <pinos/client/thread-mainloop.h> #include <pinos/client/thread-mainloop.h>
#include <pinos/client/properties.h> #include <pinos/client/properties.h>
#include <pinos/client/ringbuffer.h> #include <pinos/client/ringbuffer.h>
#include <pinos/client/stream.h> #include <pinos/client/stream.h>
#include <pinos/client/subscribe.h> #include <pinos/client/subscribe.h>
#include <spa/include/spa/id-map.h>
#define PINOS_DBUS_SERVICE "org.pinos" #define PINOS_DBUS_SERVICE "org.pinos"
#define PINOS_DBUS_OBJECT_PREFIX "/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); PinosDirection pinos_direction_reverse (PinosDirection direction);
SpaIDMap * pinos_id_map_get_default (void);
#endif /* __PINOS_H__ */ #endif /* __PINOS_H__ */

View file

@ -20,9 +20,9 @@
#ifndef __PINOS_SERIALIZE_H__ #ifndef __PINOS_SERIALIZE_H__
#define __PINOS_SERIALIZE_H__ #define __PINOS_SERIALIZE_H__
#include <glib-object.h> #ifdef __cplusplus
extern "C" {
G_BEGIN_DECLS #endif
#include <spa/include/spa/buffer.h> #include <spa/include/spa/buffer.h>
#include <spa/include/spa/format.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_deserialize (void *src, off_t offset);
SpaProps * pinos_serialize_props_copy_into (void *dest, const SpaProps *props); SpaProps * pinos_serialize_props_copy_into (void *dest, const SpaProps *props);
G_END_DECLS #ifdef __cplusplus
}
#endif
#endif /* __PINOS_SERIALIZE_H__ */ #endif /* __PINOS_SERIALIZE_H__ */

View file

@ -22,7 +22,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <errno.h> #include <errno.h>
#include "spa/include/spa/debug.h" #include "spa/lib/debug.h"
#include <gio/gio.h> #include <gio/gio.h>
#include <gio/gunixfdlist.h> #include <gio/gunixfdlist.h>
@ -50,7 +50,6 @@ typedef struct {
uint32_t flags; uint32_t flags;
void *ptr; void *ptr;
size_t size; size_t size;
bool cleanup;
} MemId; } MemId;
typedef struct { typedef struct {
@ -100,8 +99,8 @@ struct _PinosStreamPrivate
GSource *timeout_source; GSource *timeout_source;
GArray *mem_ids; PinosArray mem_ids;
GArray *buffer_ids; PinosArray buffer_ids;
gboolean in_order; gboolean in_order;
gint64 last_ticks; gint64 last_ticks;
@ -139,15 +138,13 @@ static void
clear_buffers (PinosStream *stream) clear_buffers (PinosStream *stream)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
guint i; BufferId *bid;
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) {
g_signal_emit (stream, signals[SIGNAL_REMOVE_BUFFER], 0, bid->id); g_signal_emit (stream, signals[SIGNAL_REMOVE_BUFFER], 0, bid->id);
bid->buf = NULL; bid->buf = NULL;
} }
g_array_set_size (priv->buffer_ids, 0); priv->buffer_ids.size = 0;
priv->in_order = TRUE; priv->in_order = TRUE;
} }
@ -263,7 +260,7 @@ on_node_info (PinosContext *c,
PinosStream *stream = PINOS_STREAM (user_data); PinosStream *stream = PINOS_STREAM (user_data);
if (info->state == PINOS_NODE_STATE_ERROR) { 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, stream_set_state (stream,
PINOS_STREAM_STATE_ERROR, PINOS_STREAM_STATE_ERROR,
g_error_new (PINOS_ERROR, g_error_new (PINOS_ERROR,
@ -278,7 +275,7 @@ info_ready (GObject *o, GAsyncResult *res, gpointer user_data)
GError *error = NULL; GError *error = NULL;
if (!pinos_context_info_finish (o, res, &error)) { 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); g_clear_error (&error);
} }
} }
@ -341,7 +338,7 @@ pinos_stream_finalize (GObject * object)
PinosStream *stream = PINOS_STREAM (object); PinosStream *stream = PINOS_STREAM (object);
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
g_debug ("free stream %p", stream); pinos_log_debug ("free stream %p", stream);
g_clear_object (&priv->node); g_clear_object (&priv->node);
@ -353,6 +350,9 @@ pinos_stream_finalize (GObject * object)
g_free (priv->path); g_free (priv->path);
g_clear_error (&priv->error); g_clear_error (&priv->error);
pinos_array_clear (&priv->buffer_ids);
pinos_array_clear (&priv->mem_ids);
if (priv->properties) if (priv->properties)
pinos_properties_free (priv->properties); pinos_properties_free (priv->properties);
g_signal_handler_disconnect (priv->context->priv->subscribe, priv->id); 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); 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->state = PINOS_STREAM_STATE_UNCONNECTED;
priv->node_state = SPA_NODE_STATE_INIT; priv->node_state = SPA_NODE_STATE_INIT;
priv->mem_ids = g_array_sized_new (FALSE, FALSE, sizeof (MemId), 64); pinos_array_init (&priv->mem_ids);
priv->buffer_ids = g_array_sized_new (FALSE, FALSE, sizeof (BufferId), 64); 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; priv->pending_seq = SPA_ID_INVALID;
} }
@ -614,26 +616,26 @@ static void
add_node_update (PinosStream *stream, uint32_t change_mask) add_node_update (PinosStream *stream, uint32_t change_mask)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosControlCmdNodeUpdate nu = { 0, }; PinosMessageNodeUpdate nu = { 0, };
nu.change_mask = change_mask; 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; 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.max_output_ports = priv->direction == SPA_DIRECTION_OUTPUT ? 1 : 0;
nu.props = NULL; 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 static void
add_state_change (PinosStream *stream, SpaNodeState state) add_state_change (PinosStream *stream, SpaNodeState state)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosControlCmdNodeStateChange sc; PinosMessageNodeStateChange sc;
if (priv->node_state != state) { if (priv->node_state != state) {
sc.state = 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) add_port_update (PinosStream *stream, uint32_t change_mask)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosControlCmdPortUpdate pu = { 0, };; PinosMessagePortUpdate pu = { 0, };;
pu.direction = priv->direction; pu.direction = priv->direction;
pu.port_id = priv->port_id; pu.port_id = priv->port_id;
pu.change_mask = change_mask; 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.n_possible_formats = priv->possible_formats->len;
pu.possible_formats = (SpaFormat **)priv->possible_formats->pdata; 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.format = priv->format;
} }
pu.props = NULL; 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; 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 static void
send_need_input (PinosStream *stream, uint32_t port_id) send_need_input (PinosStream *stream, uint32_t port_id)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosControlCmdNodeEvent cne; PinosMessageNodeEvent cne;
SpaNodeEventNeedInput ni; SpaNodeEventNeedInput ni;
cne.event = &ni.event; cne.event = &ni.event;
ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT; ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT;
ni.event.size = sizeof (ni); ni.event.size = sizeof (ni);
ni.port_id = port_id; 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)) 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 static void
add_request_clock_update (PinosStream *stream) add_request_clock_update (PinosStream *stream)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosControlCmdNodeEvent cne; PinosMessageNodeEvent cne;
SpaNodeEventRequestClockUpdate rcu; SpaNodeEventRequestClockUpdate rcu;
cne.event = &rcu.event; 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.update_mask = SPA_NODE_EVENT_REQUEST_CLOCK_UPDATE_TIME;
rcu.timestamp = 0; rcu.timestamp = 0;
rcu.offset = 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 static void
@ -699,7 +701,7 @@ add_async_complete (PinosStream *stream,
SpaResult res) SpaResult res)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosControlCmdNodeEvent cne; PinosMessageNodeEvent cne;
SpaNodeEventAsyncComplete ac; SpaNodeEventAsyncComplete ac;
cne.event = &ac.event; cne.event = &ac.event;
@ -707,14 +709,14 @@ add_async_complete (PinosStream *stream,
ac.event.size = sizeof (ac); ac.event.size = sizeof (ac);
ac.seq = seq; ac.seq = seq;
ac.res = res; 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 static void
send_reuse_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id) send_reuse_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosControlCmdNodeEvent cne; PinosMessageNodeEvent cne;
SpaNodeEventReuseBuffer rb; SpaNodeEventReuseBuffer rb;
cne.event = &rb.event; 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.event.size = sizeof (rb);
rb.port_id = port_id; rb.port_id = port_id;
rb.buffer_id = buffer_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)) 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 static void
send_process_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id) send_process_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosControlCmdProcessBuffer pb; PinosMessageProcessBuffer pb;
PinosControlCmdNodeEvent cne; PinosMessageNodeEvent cne;
SpaNodeEventHaveOutput ho; SpaNodeEventHaveOutput ho;
pb.direction = priv->direction; pb.direction = priv->direction;
pb.port_id = port_id; pb.port_id = port_id;
pb.buffer_id = buffer_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; cne.event = &ho.event;
ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT; ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
ho.event.size = sizeof (ho); ho.event.size = sizeof (ho);
ho.port_id = port_id; 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)) 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 static void
@ -756,27 +758,26 @@ do_node_init (PinosStream *stream)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
add_node_update (stream, PINOS_CONTROL_CMD_NODE_UPDATE_MAX_INPUTS | add_node_update (stream, PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS |
PINOS_CONTROL_CMD_NODE_UPDATE_MAX_OUTPUTS); PINOS_MESSAGE_NODE_UPDATE_MAX_OUTPUTS);
priv->port_info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS; priv->port_info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
add_port_update (stream, PINOS_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS | add_port_update (stream, PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS |
PINOS_CONTROL_CMD_PORT_UPDATE_INFO); PINOS_MESSAGE_PORT_UPDATE_INFO);
add_state_change (stream, SPA_NODE_STATE_CONFIGURE); add_state_change (stream, SPA_NODE_STATE_CONFIGURE);
if (!pinos_connection_flush (priv->conn)) 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 * static MemId *
find_mem (PinosStream *stream, uint32_t id) find_mem (PinosStream *stream, uint32_t id)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
guint i; MemId *mid;
for (i = 0; i < priv->mem_ids->len; i++) { pinos_array_for_each (mid, &priv->mem_ids) {
MemId *mid = &g_array_index (priv->mem_ids, MemId, i);
if (mid->id == id) if (mid->id == id)
return mid; return mid;
} }
@ -787,13 +788,13 @@ static BufferId *
find_buffer (PinosStream *stream, uint32_t id) find_buffer (PinosStream *stream, uint32_t id)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
guint i;
if (priv->in_order && id < priv->buffer_ids->len) { if (priv->in_order && pinos_array_check_index (&priv->buffer_ids, id, BufferId)) {
return &g_array_index (priv->buffer_ids, BufferId, id); return pinos_array_get_unchecked (&priv->buffer_ids, id, BufferId);
} else { } else {
for (i = 0; i < priv->buffer_ids->len; i++) { BufferId *bid;
BufferId *bid = &g_array_index (priv->buffer_ids, BufferId, i);
pinos_array_for_each (bid, &priv->buffer_ids) {
if (bid->id == id) if (bid->id == id)
return bid; return bid;
} }
@ -815,7 +816,7 @@ handle_node_event (PinosStream *stream,
case SPA_NODE_EVENT_TYPE_BUFFERING: case SPA_NODE_EVENT_TYPE_BUFFERING:
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH: case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE: 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; break;
} }
return TRUE; return TRUE;
@ -834,12 +835,12 @@ handle_rtnode_event (PinosStream *stream,
case SPA_NODE_EVENT_TYPE_BUFFERING: case SPA_NODE_EVENT_TYPE_BUFFERING:
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH: case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE: 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; break;
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT: case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
case SPA_NODE_EVENT_TYPE_NEED_INPUT: 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; break;
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER: case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
@ -874,25 +875,25 @@ handle_node_command (PinosStream *stream,
break; break;
case SPA_NODE_COMMAND_PAUSE: 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_state_change (stream, SPA_NODE_STATE_PAUSED);
add_async_complete (stream, seq, SPA_RESULT_OK); add_async_complete (stream, seq, SPA_RESULT_OK);
if (!pinos_connection_flush (priv->conn)) 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); stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL);
break; break;
} }
case SPA_NODE_COMMAND_START: 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_state_change (stream, SPA_NODE_STATE_STREAMING);
add_async_complete (stream, seq, SPA_RESULT_OK); add_async_complete (stream, seq, SPA_RESULT_OK);
if (!pinos_connection_flush (priv->conn)) 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) if (priv->direction == SPA_DIRECTION_INPUT)
send_need_input (stream, priv->port_id); 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_DRAIN:
case SPA_NODE_COMMAND_MARKER: 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); add_async_complete (stream, seq, SPA_RESULT_NOT_IMPLEMENTED);
if (!pinos_connection_flush (priv->conn)) if (!pinos_connection_flush (priv->conn))
g_warning ("stream %p: error writing connection", stream); pinos_log_warn ("stream %p: error writing connection", stream);
break; break;
} }
case SPA_NODE_COMMAND_CLOCK_UPDATE: case SPA_NODE_COMMAND_CLOCK_UPDATE:
@ -936,28 +937,28 @@ parse_connection (PinosStream *stream)
PinosConnection *conn = priv->conn; PinosConnection *conn = priv->conn;
while (pinos_connection_has_next (conn)) { while (pinos_connection_has_next (conn)) {
PinosControlCmd cmd = pinos_connection_get_cmd (conn); PinosMessageType type = pinos_connection_get_type (conn);
switch (cmd) { switch (type) {
case PINOS_CONTROL_CMD_NODE_UPDATE: case PINOS_MESSAGE_NODE_UPDATE:
case PINOS_CONTROL_CMD_PORT_UPDATE: case PINOS_MESSAGE_PORT_UPDATE:
case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: case PINOS_MESSAGE_PORT_STATUS_CHANGE:
case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: case PINOS_MESSAGE_NODE_STATE_CHANGE:
case PINOS_CONTROL_CMD_PROCESS_BUFFER: case PINOS_MESSAGE_PROCESS_BUFFER:
g_warning ("got unexpected command %d", cmd); pinos_log_warn ("got unexpected message %d", type);
break; break;
case PINOS_CONTROL_CMD_ADD_PORT: case PINOS_MESSAGE_ADD_PORT:
case PINOS_CONTROL_CMD_REMOVE_PORT: case PINOS_MESSAGE_REMOVE_PORT:
g_warning ("add/remove port not supported"); pinos_log_warn ("add/remove port not supported");
break; break;
case PINOS_CONTROL_CMD_SET_FORMAT: case PINOS_MESSAGE_SET_FORMAT:
{ {
PinosControlCmdSetFormat p; PinosMessageSetFormat p;
gpointer mem; gpointer mem;
if (!pinos_connection_parse_cmd (conn, &p)) if (!pinos_connection_parse_message (conn, &p))
break; break;
if (priv->format) if (priv->format)
@ -970,17 +971,17 @@ parse_connection (PinosStream *stream)
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL); stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
break; break;
} }
case PINOS_CONTROL_CMD_SET_PROPERTY: case PINOS_MESSAGE_SET_PROPERTY:
g_warning ("set property not implemented"); pinos_log_warn ("set property not implemented");
break; break;
case PINOS_CONTROL_CMD_ADD_MEM: case PINOS_MESSAGE_ADD_MEM:
{ {
PinosControlCmdAddMem p; PinosMessageAddMem p;
int fd; int fd;
MemId mid, *m; MemId *m;
if (!pinos_connection_parse_cmd (conn, &p)) if (!pinos_connection_parse_message (conn, &p))
break; break;
fd = pinos_connection_get_fd (conn, p.fd_index, false); 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); m = find_mem (stream, p.mem_id);
if (m) { if (m) {
g_debug ("update mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size); pinos_log_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;
} else { } else {
mid.id = p.mem_id; m = pinos_array_add (&priv->mem_ids, sizeof (MemId));
mid.fd = fd; pinos_log_debug ("add mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size);
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->id = p.mem_id;
m->fd = fd;
m->flags = p.flags;
m->ptr = NULL;
m->size = p.size;
break; break;
} }
case PINOS_CONTROL_CMD_USE_BUFFERS: case PINOS_MESSAGE_USE_BUFFERS:
{ {
PinosControlCmdUseBuffers p; PinosMessageUseBuffers p;
BufferId bid; BufferId *bid;
unsigned int i, j; unsigned int i, j, len;
SpaBuffer *b; SpaBuffer *b;
if (!pinos_connection_parse_cmd (conn, &p)) if (!pinos_connection_parse_message (conn, &p))
break; break;
/* clear previous buffers */ /* clear previous buffers */
@ -1024,7 +1018,7 @@ parse_connection (PinosStream *stream)
for (i = 0; i < p.n_buffers; i++) { for (i = 0; i < p.n_buffers; i++) {
MemId *mid = find_mem (stream, p.buffers[i].mem_id); MemId *mid = find_mem (stream, p.buffers[i].mem_id);
if (mid == NULL) { if (mid == NULL) {
g_warning ("unknown memory id %u", mid->id); pinos_log_warn ("unknown memory id %u", mid->id);
continue; continue;
} }
@ -1032,18 +1026,20 @@ parse_connection (PinosStream *stream)
mid->ptr = mmap (NULL, mid->size, PROT_READ | PROT_WRITE, MAP_SHARED, mid->fd, 0); mid->ptr = mmap (NULL, mid->size, PROT_READ | PROT_WRITE, MAP_SHARED, mid->fd, 0);
if (mid->ptr == MAP_FAILED) { if (mid->ptr == MAP_FAILED) {
mid->ptr = NULL; 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; 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; size_t size;
unsigned int i; unsigned int i;
SpaMeta *m; SpaMeta *m;
b = bid.buf_ptr; b = bid->buf_ptr;
size = sizeof (SpaBuffer); size = sizeof (SpaBuffer);
m = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta); m = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta);
for (i = 0; i < b->n_metas; i++) for (i = 0; i < b->n_metas; i++)
@ -1051,24 +1047,28 @@ parse_connection (PinosStream *stream)
for (i = 0; i < b->n_datas; i++) for (i = 0; i < b->n_datas; i++)
size += sizeof (SpaData); size += sizeof (SpaData);
b = bid.buf = g_memdup (bid.buf_ptr, size); b = bid->buf = g_memdup (bid->buf_ptr, size);
if (b->metas) if (b->metas)
b->metas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta); b->metas = SPA_MEMBER (b, SPA_PTR_TO_INT (b->metas), SpaMeta);
if (b->datas) { 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); 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++) { for (j = 0; j < b->n_metas; j++) {
SpaMeta *m = &b->metas[j]; SpaMeta *m = &b->metas[j];
if (m->data) 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++) { for (j = 0; j < b->n_datas; j++) {
@ -1081,28 +1081,23 @@ parse_connection (PinosStream *stream)
d->type = SPA_DATA_TYPE_MEMFD; d->type = SPA_DATA_TYPE_MEMFD;
d->data = NULL; d->data = NULL;
d->fd = bmid->fd; 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; break;
} }
case SPA_DATA_TYPE_MEMPTR: 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; 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; break;
} }
default: default:
g_warning ("unknown buffer data type %d", d->type); pinos_log_warn ("unknown buffer data type %d", d->type);
break; break;
} }
} }
if (bid.id != priv->buffer_ids->len) { g_signal_emit (stream, signals[SIGNAL_ADD_BUFFER], 0, bid->id);
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);
} }
if (p.n_buffers) { if (p.n_buffers) {
@ -1113,7 +1108,7 @@ parse_connection (PinosStream *stream)
add_async_complete (stream, p.seq, SPA_RESULT_OK); add_async_complete (stream, p.seq, SPA_RESULT_OK);
if (!pinos_connection_flush (conn)) 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) if (p.n_buffers)
stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL); 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); stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
break; 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; break;
handle_node_event (stream, p.event); handle_node_event (stream, p.event);
break; 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; break;
handle_node_command (stream, p.seq, p.command); handle_node_command (stream, p.seq, p.command);
break; 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;
break; break;
} }
case PINOS_CONTROL_CMD_INVALID: case PINOS_MESSAGE_INVALID:
g_warning ("unhandled command %d", cmd); pinos_log_warn ("unhandled message %d", type);
break; break;
} }
} }
@ -1165,34 +1160,34 @@ parse_rtconnection (PinosStream *stream)
PinosConnection *conn = priv->rtconn; PinosConnection *conn = priv->rtconn;
while (pinos_connection_has_next (conn)) { while (pinos_connection_has_next (conn)) {
PinosControlCmd cmd = pinos_connection_get_cmd (conn); PinosMessageType type = pinos_connection_get_type (conn);
switch (cmd) { switch (type) {
case PINOS_CONTROL_CMD_INVALID: case PINOS_MESSAGE_INVALID:
case PINOS_CONTROL_CMD_NODE_UPDATE: case PINOS_MESSAGE_NODE_UPDATE:
case PINOS_CONTROL_CMD_PORT_UPDATE: case PINOS_MESSAGE_PORT_UPDATE:
case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: case PINOS_MESSAGE_PORT_STATUS_CHANGE:
case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: case PINOS_MESSAGE_NODE_STATE_CHANGE:
case PINOS_CONTROL_CMD_ADD_PORT: case PINOS_MESSAGE_ADD_PORT:
case PINOS_CONTROL_CMD_REMOVE_PORT: case PINOS_MESSAGE_REMOVE_PORT:
case PINOS_CONTROL_CMD_SET_FORMAT: case PINOS_MESSAGE_SET_FORMAT:
case PINOS_CONTROL_CMD_SET_PROPERTY: case PINOS_MESSAGE_SET_PROPERTY:
case PINOS_CONTROL_CMD_ADD_MEM: case PINOS_MESSAGE_ADD_MEM:
case PINOS_CONTROL_CMD_USE_BUFFERS: case PINOS_MESSAGE_USE_BUFFERS:
case PINOS_CONTROL_CMD_NODE_COMMAND: case PINOS_MESSAGE_NODE_COMMAND:
g_warning ("got unexpected command %d", cmd); pinos_log_warn ("got unexpected command %d", type);
break; break;
case PINOS_CONTROL_CMD_PROCESS_BUFFER: case PINOS_MESSAGE_PROCESS_BUFFER:
{ {
PinosControlCmdProcessBuffer p; PinosMessageProcessBuffer p;
guint i; guint i;
BufferId *bid; BufferId *bid;
if (priv->direction != SPA_DIRECTION_INPUT) if (priv->direction != SPA_DIRECTION_INPUT)
break; break;
if (!pinos_connection_parse_cmd (conn, &p)) if (!pinos_connection_parse_message (conn, &p))
break; break;
if ((bid = find_buffer (stream, p.buffer_id))) { if ((bid = find_buffer (stream, p.buffer_id))) {
@ -1205,17 +1200,17 @@ parse_rtconnection (PinosStream *stream)
} }
break; 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; break;
handle_rtnode_event (stream, p.event); handle_rtnode_event (stream, p.event);
break; break;
} }
case PINOS_CONTROL_CMD_PORT_COMMAND: case PINOS_MESSAGE_PORT_COMMAND:
{ {
break; break;
} }
@ -1240,7 +1235,7 @@ on_socket_condition (GSocket *socket,
} }
case G_IO_OUT: case G_IO_OUT:
g_warning ("can do IO\n"); pinos_log_warn ("can do IO\n");
break; break;
default: default:
@ -1264,7 +1259,7 @@ on_rtsocket_condition (GSocket *socket,
} }
case G_IO_OUT: case G_IO_OUT:
g_warning ("can do IO\n"); pinos_log_warn ("can do IO\n");
break; break;
default: default:
@ -1282,7 +1277,7 @@ on_timeout (gpointer user_data)
add_request_clock_update (stream); add_request_clock_update (stream);
if (!pinos_connection_flush (priv->conn)) 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; return G_SOURCE_CONTINUE;
} }
@ -1321,7 +1316,7 @@ handle_socket (PinosStream *stream, gint fd, gint rtfd)
/* ERRORS */ /* ERRORS */
socket_failed: 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); stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error);
return; return;
} }
@ -1368,7 +1363,7 @@ on_node_proxy (GObject *source_object,
node_failed: 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); stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error);
g_object_unref (stream); g_object_unref (stream);
return; return;
@ -1425,12 +1420,12 @@ on_node_created (GObject *source_object,
/* ERRORS */ /* ERRORS */
create_failed: create_failed:
{ {
g_warning ("failed to connect: %s", error->message); pinos_log_warn ("failed to connect: %s", error->message);
goto exit_error; goto exit_error;
} }
fd_failed: 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); g_object_unref (fd_list);
goto exit_error; goto exit_error;
} }
@ -1479,12 +1474,12 @@ on_node_registered (GObject *source_object,
/* ERRORS */ /* ERRORS */
create_failed: create_failed:
{ {
g_warning ("failed to connect: %s", error->message); pinos_log_warn ("failed to connect: %s", error->message);
goto exit_error; goto exit_error;
} }
fd_failed: 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); g_object_unref (fd_list);
goto exit_error; goto exit_error;
} }
@ -1635,8 +1630,8 @@ pinos_stream_finish_format (PinosStream *stream,
priv->port_info.n_params = n_params; priv->port_info.n_params = n_params;
if (SPA_RESULT_IS_OK (res)) { if (SPA_RESULT_IS_OK (res)) {
add_port_update (stream, PINOS_CONTROL_CMD_PORT_UPDATE_INFO | add_port_update (stream, PINOS_MESSAGE_PORT_UPDATE_INFO |
PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT); PINOS_MESSAGE_PORT_UPDATE_FORMAT);
if (priv->format) { if (priv->format) {
add_state_change (stream, SPA_NODE_STATE_READY); add_state_change (stream, SPA_NODE_STATE_READY);
} else { } else {
@ -1652,7 +1647,7 @@ pinos_stream_finish_format (PinosStream *stream,
priv->pending_seq = SPA_ID_INVALID; priv->pending_seq = SPA_ID_INVALID;
if (!pinos_connection_flush (priv->conn)) 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; return TRUE;
} }
@ -1752,7 +1747,7 @@ on_node_removed (GObject *source_object,
/* ERRORS */ /* ERRORS */
proxy_failed: 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); stream_set_state (stream, PINOS_STREAM_STATE_ERROR, error);
g_object_unref (stream); g_object_unref (stream);
return; return;
@ -1841,14 +1836,13 @@ guint
pinos_stream_get_empty_buffer (PinosStream *stream) pinos_stream_get_empty_buffer (PinosStream *stream)
{ {
PinosStreamPrivate *priv; PinosStreamPrivate *priv;
guint i; BufferId *bid;
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE); g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
priv = stream->priv; priv = stream->priv;
g_return_val_if_fail (priv->direction == SPA_DIRECTION_OUTPUT, FALSE); g_return_val_if_fail (priv->direction == SPA_DIRECTION_OUTPUT, FALSE);
for (i = 0; i < priv->buffer_ids->len; i++) { pinos_array_for_each (bid, &priv->buffer_ids) {
BufferId *bid = &g_array_index (priv->buffer_ids, BufferId, i);
if (!bid->used) if (!bid->used)
return bid->id; return bid->id;
} }

View file

@ -196,7 +196,7 @@ on_proxy_created (GObject *source_object,
data->proxy = g_dbus_proxy_new_finish (res, &error); data->proxy = g_dbus_proxy_new_finish (res, &error);
if (data->proxy == NULL) { if (data->proxy == NULL) {
priv->objects = g_list_remove (priv->objects, data); 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); subscription_set_state (subscribe, PINOS_SUBSCRIPTION_STATE_ERROR);
priv->error = error; priv->error = error;
return; return;
@ -365,7 +365,7 @@ on_managed_objects_ready (GObject *source_object,
objects = g_dbus_proxy_call_finish (priv->manager_proxy, res, &error); objects = g_dbus_proxy_call_finish (priv->manager_proxy, res, &error);
if (objects == NULL) { 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); subscription_set_state (subscribe, PINOS_SUBSCRIPTION_STATE_ERROR);
priv->error = error; priv->error = error;
return; return;
@ -464,7 +464,7 @@ on_manager_proxy_ready (GObject *source_object,
/* ERRORS */ /* ERRORS */
manager_error: 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); subscription_set_state (subscribe, PINOS_SUBSCRIPTION_STATE_ERROR);
priv->error = error; priv->error = error;
g_object_unref (subscribe); g_object_unref (subscribe);

View file

@ -110,7 +110,7 @@ pinos_thread_main_loop_constructed (GObject * object)
PinosThreadMainLoopPrivate *priv = loop->priv; PinosThreadMainLoopPrivate *priv = loop->priv;
priv->mainloop = g_main_loop_new (priv->maincontext, FALSE); 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); 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_set_poll_func (priv->maincontext, do_poll);
g_main_context_push_thread_default (priv->maincontext); 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_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_pop_thread_default (priv->maincontext);
g_main_context_set_poll_func (priv->maincontext, priv->poll_func); g_main_context_set_poll_func (priv->maincontext, priv->poll_func);

View file

@ -135,7 +135,7 @@ pinos_daemon_config_load_file (PinosDaemonConfig * config,
g_return_val_if_fail (config != NULL, FALSE); g_return_val_if_fail (config != NULL, FALSE);
g_return_val_if_fail (filename != NULL && *filename != '\0', 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)) { if (!g_file_get_contents (filename, &data, NULL, err)) {
return FALSE; return FALSE;
@ -175,7 +175,7 @@ pinos_daemon_config_load (PinosDaemonConfig * config,
filename = g_getenv ("PINOS_CONFIG_FILE"); filename = g_getenv ("PINOS_CONFIG_FILE");
if (filename != NULL && *filename != '\0') { 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 { } else {
filename = DEFAULT_CONFIG_FILE; filename = DEFAULT_CONFIG_FILE;
} }
@ -206,7 +206,7 @@ pinos_daemon_config_run_commands (PinosDaemonConfig * config,
for (walk = config->commands; walk != NULL; walk = walk->next) { for (walk = config->commands; walk != NULL; walk = walk->next) {
PinosCommand *command = (PinosCommand *)walk->data; PinosCommand *command = (PinosCommand *)walk->data;
if (!pinos_command_run (command, daemon, &err)) { 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); pinos_command_get_name (command), err->message);
g_clear_error (&err); g_clear_error (&err);
ret = FALSE; ret = FALSE;

View file

@ -105,9 +105,10 @@ do_start (GstBufferPool * pool)
guint size; guint size;
guint min_buffers; guint min_buffers;
guint max_buffers; guint max_buffers;
SpaAllocParam *port_params[2]; SpaAllocParam *port_params[3];
SpaAllocParamMetaEnable param_meta_enable;
SpaAllocParamBuffers param_buffers; SpaAllocParamBuffers param_buffers;
SpaAllocParamMetaEnable param_meta_enable;
SpaAllocParamMetaEnableRingbuffer param_meta_enable_rb;
config = gst_buffer_pool_get_config (pool); config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers, &max_buffers); 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.type = SPA_ALLOC_PARAM_TYPE_META_ENABLE;
param_meta_enable.param.size = sizeof (SpaAllocParamMetaEnable); param_meta_enable.param.size = sizeof (SpaAllocParamMetaEnable);
param_meta_enable.type = SPA_META_TYPE_HEADER; param_meta_enable.type = SPA_META_TYPE_HEADER;
port_params[2] = &param_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); pinos_stream_finish_format (p->stream, SPA_RESULT_OK, port_params, 2);

View file

@ -31,6 +31,8 @@
#include <spa/include/spa/node.h> #include <spa/include/spa/node.h>
#include <spa/include/spa/monitor.h> #include <spa/include/spa/monitor.h>
#include <pinos/client/log.h>
#include "spa-alsa-monitor.h" #include "spa-alsa-monitor.h"
#define PINOS_SPA_ALSA_MONITOR_GET_PRIVATE(obj) \ #define PINOS_SPA_ALSA_MONITOR_GET_PRIVATE(obj) \
@ -109,7 +111,7 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
void *node_iface, *clock_iface; void *node_iface, *clock_iface;
PinosProperties *props = NULL; 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); handle = calloc (1, item->factory->size);
if ((res = spa_handle_factory_init (item->factory, if ((res = spa_handle_factory_init (item->factory,
@ -125,7 +127,7 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
return; return;
} }
if ((res = spa_handle_get_interface (handle, priv->uri.clock, &clock_iface)) < 0) { 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; clock_iface = NULL;
} }
@ -157,7 +159,7 @@ remove_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
PinosSpaALSAMonitorPrivate *priv = this->priv; PinosSpaALSAMonitorPrivate *priv = this->priv;
PinosNode *node; 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); node = g_hash_table_lookup (priv->nodes, item->id);
if (node) { if (node) {
@ -188,7 +190,7 @@ on_monitor_event (SpaMonitor *monitor,
case SPA_MONITOR_EVENT_TYPE_CHANGED: case SPA_MONITOR_EVENT_TYPE_CHANGED:
{ {
SpaMonitorItem *item = (SpaMonitorItem *) event; 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; break;
} }
default: default:
@ -204,7 +206,7 @@ monitor_constructed (GObject * object)
SpaResult res; SpaResult res;
void *state = NULL; 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); 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_monitor_enum_items (priv->monitor, &item, &state)) < 0) {
if (res != SPA_RESULT_ENUM_END) 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; break;
} }
add_item (this, item); add_item (this, item);
@ -278,7 +280,7 @@ monitor_finalize (GObject * object)
PinosSpaALSAMonitor *this = PINOS_SPA_ALSA_MONITOR (object); PinosSpaALSAMonitor *this = PINOS_SPA_ALSA_MONITOR (object);
PinosSpaALSAMonitorPrivate *priv = this->priv; PinosSpaALSAMonitorPrivate *priv = this->priv;
g_debug ("spa-monitor %p: dispose", this); pinos_log_debug ("spa-monitor %p: dispose", this);
spa_handle_clear (priv->handle); spa_handle_clear (priv->handle);
g_free (priv->handle); g_free (priv->handle);
g_hash_table_unref (priv->nodes); g_hash_table_unref (priv->nodes);

View file

@ -100,10 +100,10 @@ setup_node (PinosSpaAudioTestSrc *this)
SpaPropValue value; SpaPropValue value;
if ((res = spa_node_get_props (node->node, &props)) < 0) 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) 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 #endif
} }
@ -149,7 +149,7 @@ src_finalize (GObject * object)
PinosSpaAudioTestSrc *src = PINOS_SPA_AUDIOTESTSRC (object); PinosSpaAudioTestSrc *src = PINOS_SPA_AUDIOTESTSRC (object);
PinosSpaAudioTestSrcPrivate *priv = src->priv; PinosSpaAudioTestSrcPrivate *priv = src->priv;
g_debug ("audiotestsrc %p: dispose", src); pinos_log_debug ("audiotestsrc %p: dispose", src);
spa_handle_clear (priv->handle); spa_handle_clear (priv->handle);
g_free (priv->handle); g_free (priv->handle);

View file

@ -26,10 +26,9 @@
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <gio/gio.h>
#include <spa/include/spa/node.h> #include <spa/include/spa/node.h>
#include <spa/include/spa/monitor.h> #include <spa/include/spa/monitor.h>
#include <pinos/client/log.h>
#include "spa-v4l2-monitor.h" #include "spa-v4l2-monitor.h"
@ -110,7 +109,7 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
void *clock_iface; void *clock_iface;
PinosProperties *props = NULL; 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); handle = calloc (1, item->factory->size);
if ((res = spa_handle_factory_init (item->factory, if ((res = spa_handle_factory_init (item->factory,
@ -158,7 +157,7 @@ remove_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
PinosSpaV4l2MonitorPrivate *priv = this->priv; PinosSpaV4l2MonitorPrivate *priv = this->priv;
PinosNode *node; 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); node = g_hash_table_lookup (priv->nodes, item->id);
if (node) { if (node) {
@ -189,7 +188,7 @@ on_monitor_event (SpaMonitor *monitor,
case SPA_MONITOR_EVENT_TYPE_CHANGED: case SPA_MONITOR_EVENT_TYPE_CHANGED:
{ {
SpaMonitorItem *item = (SpaMonitorItem *) event; 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; break;
} }
default: default:
@ -205,7 +204,7 @@ monitor_constructed (GObject * object)
SpaResult res; SpaResult res;
void *state = NULL; 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); 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_monitor_enum_items (priv->monitor, &item, &state)) < 0) {
if (res != SPA_RESULT_ENUM_END) 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; break;
} }
add_item (this, item); add_item (this, item);
@ -279,7 +278,7 @@ monitor_finalize (GObject * object)
PinosSpaV4l2Monitor *this = PINOS_SPA_V4L2_MONITOR (object); PinosSpaV4l2Monitor *this = PINOS_SPA_V4L2_MONITOR (object);
PinosSpaV4l2MonitorPrivate *priv = this->priv; PinosSpaV4l2MonitorPrivate *priv = this->priv;
g_debug ("spa-monitor %p: dispose", this); pinos_log_debug ("spa-monitor %p: dispose", this);
spa_handle_clear (priv->handle); spa_handle_clear (priv->handle);
g_free (priv->handle); g_free (priv->handle);
g_hash_table_unref (priv->nodes); g_hash_table_unref (priv->nodes);

View file

@ -164,7 +164,7 @@ static SpaResult
clear_buffers (SpaProxy *this, SpaProxyPort *port) clear_buffers (SpaProxy *this, SpaProxyPort *port)
{ {
if (port->n_buffers) { 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); munmap (port->buffer_mem_ptr, port->buffer_mem_size);
close (port->buffer_mem_fd); 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_DRAIN:
case SPA_NODE_COMMAND_MARKER: case SPA_NODE_COMMAND_MARKER:
{ {
PinosControlCmdNodeCommand cnc; PinosMessageNodeCommand cnc;
/* send start */ /* send start */
cnc.seq = this->seq++; cnc.seq = this->seq++;
cnc.command = command; 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)) { 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; res = SPA_RESULT_ERROR;
} else } else
res = SPA_RESULT_RETURN_ASYNC (cnc.seq); res = SPA_RESULT_RETURN_ASYNC (cnc.seq);
@ -228,14 +228,14 @@ spa_proxy_node_send_command (SpaNode *node,
case SPA_NODE_COMMAND_CLOCK_UPDATE: case SPA_NODE_COMMAND_CLOCK_UPDATE:
{ {
PinosControlCmdNodeCommand cnc; PinosMessageNodeCommand cnc;
/* send start */ /* send start */
cnc.command = command; 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)) { 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; res = SPA_RESULT_ERROR;
} }
break; break;
@ -319,7 +319,7 @@ spa_proxy_node_get_port_ids (SpaNode *node,
static void static void
do_update_port (SpaProxy *this, do_update_port (SpaProxy *this,
PinosControlCmdPortUpdate *pu) PinosMessagePortUpdate *pu)
{ {
SpaProxyPort *port; SpaProxyPort *port;
unsigned int i; unsigned int i;
@ -331,7 +331,7 @@ do_update_port (SpaProxy *this,
port = &this->out_ports[pu->port_id]; 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++) for (i = 0; i < port->n_formats; i++)
free (port->formats[i]); free (port->formats[i]);
port->n_formats = pu->n_possible_formats; 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]); 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) if (port->format)
free (port->format); free (port->format);
size = pinos_serialize_format_get_size (pu->format); size = pinos_serialize_format_get_size (pu->format);
port->format = pinos_serialize_format_copy_into (malloc (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) if (port->info)
free (port->info); free (port->info);
size = pinos_serialize_port_info_get_size (pu->info); size = pinos_serialize_port_info_get_size (pu->info);
@ -359,7 +359,7 @@ do_update_port (SpaProxy *this,
} }
if (!port->valid) { 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->format = NULL;
port->valid = true; port->valid = true;
@ -376,12 +376,12 @@ clear_port (SpaProxy *this,
SpaDirection direction, SpaDirection direction,
uint32_t port_id) uint32_t port_id)
{ {
PinosControlCmdPortUpdate pu; PinosMessagePortUpdate pu;
pu.change_mask = PINOS_CONTROL_CMD_PORT_UPDATE_POSSIBLE_FORMATS | pu.change_mask = PINOS_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS |
PINOS_CONTROL_CMD_PORT_UPDATE_FORMAT | PINOS_MESSAGE_PORT_UPDATE_FORMAT |
PINOS_CONTROL_CMD_PORT_UPDATE_PROPS | PINOS_MESSAGE_PORT_UPDATE_PROPS |
PINOS_CONTROL_CMD_PORT_UPDATE_INFO; PINOS_MESSAGE_PORT_UPDATE_INFO;
pu.direction = direction; pu.direction = direction;
pu.port_id = port_id; pu.port_id = port_id;
pu.n_possible_formats = 0; pu.n_possible_formats = 0;
@ -400,7 +400,7 @@ do_uninit_port (SpaProxy *this,
{ {
SpaProxyPort *port; 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) { if (direction == SPA_DIRECTION_INPUT) {
port = &this->in_ports[port_id]; port = &this->in_ports[port_id];
this->n_inputs--; this->n_inputs--;
@ -495,7 +495,7 @@ spa_proxy_node_port_set_format (SpaNode *node,
const SpaFormat *format) const SpaFormat *format)
{ {
SpaProxy *this; SpaProxy *this;
PinosControlCmdSetFormat sf; PinosMessageSetFormat sf;
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -510,10 +510,10 @@ spa_proxy_node_port_set_format (SpaNode *node,
sf.port_id = port_id; sf.port_id = port_id;
sf.flags = flags; sf.flags = flags;
sf.format = (SpaFormat *) format; 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)) 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); return SPA_RESULT_RETURN_ASYNC (sf.seq);
} }
@ -624,17 +624,17 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
SpaProxy *this; SpaProxy *this;
SpaProxyPort *port; SpaProxyPort *port;
unsigned int i, j; unsigned int i, j;
PinosControlCmdAddMem am; PinosMessageAddMem am;
PinosControlCmdUseBuffers ub; PinosMessageUseBuffers ub;
size_t size, n_mem; size_t size, n_mem;
PinosControlMemRef *memref; PinosMessageMemRef *memref;
void *p; void *p;
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaProxy, node); 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)) if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
@ -680,7 +680,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
am.flags = d->flags; am.flags = d->flags;
am.offset = d->offset; am.offset = d->offset;
am.size = d->maxsize; 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].type = SPA_DATA_TYPE_ID;
b->buffer.datas[j].data = SPA_UINT32_TO_PTR (n_mem); b->buffer.datas[j].data = SPA_UINT32_TO_PTR (n_mem);
@ -693,7 +693,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
default: default:
b->buffer.datas[j].type = SPA_DATA_TYPE_INVALID; b->buffer.datas[j].type = SPA_DATA_TYPE_INVALID;
b->buffer.datas[j].data = 0; 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; 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); port->buffer_mem_fd = memfd_create ("spa-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
if (ftruncate (port->buffer_mem_fd, size) < 0) { 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); close (port->buffer_mem_fd);
return SPA_RESULT_ERROR; 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; unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
if (fcntl (port->buffer_mem_fd, F_ADD_SEALS, seals) == -1) { 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 #endif
@ -752,9 +752,9 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
am.flags = 0; am.flags = 0;
am.offset = 0; am.offset = 0;
am.size = size; 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++) { for (i = 0; i < n_buffers; i++) {
memref[i].mem_id = port->buffer_mem_id; memref[i].mem_id = port->buffer_mem_id;
memref[i].offset = port->buffers[i].offset; 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.port_id = port_id;
ub.n_buffers = n_buffers; ub.n_buffers = n_buffers;
ub.buffers = memref; 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)) 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); 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++) { for (i = 0; i < b->outbuf->n_datas; i++) {
b->outbuf->datas[i].size = b->buffer.datas[i].size; b->outbuf->datas[i].size = b->buffer.datas[i].size;
if (b->outbuf->datas[i].type == SPA_DATA_TYPE_MEMPTR) { 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); 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++) { for (i = 0; i < b->outbuf->n_datas; i++) {
b->buffer.datas[i].size = b->outbuf->datas[i].size; b->buffer.datas[i].size = b->outbuf->datas[i].size;
if (b->datas[i].type == SPA_DATA_TYPE_MEMPTR) { 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); 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; SpaProxyPort *port;
unsigned int i; unsigned int i;
bool have_error = false; bool have_error = false;
PinosControlCmdProcessBuffer pb; PinosMessageProcessBuffer pb;
if (node == NULL || n_info == 0 || info == NULL) if (node == NULL || n_info == 0 || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -864,7 +864,7 @@ spa_proxy_node_port_push_input (SpaNode *node,
for (i = 0; i < n_info; i++) { for (i = 0; i < n_info; i++) {
if (!CHECK_IN_PORT (this, SPA_DIRECTION_INPUT, info[i].port_id)) { 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; info[i].status = SPA_RESULT_INVALID_PORT;
have_error = true; have_error = true;
continue; continue;
@ -890,7 +890,7 @@ spa_proxy_node_port_push_input (SpaNode *node,
pb.direction = SPA_DIRECTION_INPUT; pb.direction = SPA_DIRECTION_INPUT;
pb.port_id = info[i].port_id; pb.port_id = info[i].port_id;
pb.buffer_id = info[i].buffer_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; info[i].status = SPA_RESULT_OK;
} }
@ -899,7 +899,7 @@ spa_proxy_node_port_push_input (SpaNode *node,
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
if (!pinos_connection_flush (this->rtconn)) 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; return SPA_RESULT_OK;
} }
@ -923,7 +923,7 @@ spa_proxy_node_port_pull_output (SpaNode *node,
ProxyBuffer *b; ProxyBuffer *b;
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, info[i].port_id)) { 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; info[i].status = SPA_RESULT_INVALID_PORT;
have_error = true; have_error = true;
continue; continue;
@ -960,7 +960,7 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
uint32_t buffer_id) uint32_t buffer_id)
{ {
SpaProxy *this; SpaProxy *this;
PinosControlCmdNodeEvent cne; PinosMessageNodeEvent cne;
SpaNodeEventReuseBuffer rb; SpaNodeEventReuseBuffer rb;
if (node == NULL) if (node == NULL)
@ -977,10 +977,10 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
rb.event.size = sizeof (rb); rb.event.size = sizeof (rb);
rb.port_id = port_id; rb.port_id = port_id;
rb.buffer_id = buffer_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)) 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; 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_DRAIN:
case SPA_NODE_COMMAND_MARKER: case SPA_NODE_COMMAND_MARKER:
{ {
PinosControlCmdPortCommand cpc; PinosMessagePortCommand cpc;
cpc.port_id = port_id; cpc.port_id = port_id;
cpc.command = command; 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)) { 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; res = SPA_RESULT_ERROR;
} }
break; break;
} }
default: 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; res = SPA_RESULT_NOT_IMPLEMENTED;
break; break;
} }
@ -1059,45 +1059,45 @@ parse_connection (SpaProxy *this)
PinosConnection *conn = this->conn; PinosConnection *conn = this->conn;
while (pinos_connection_has_next (conn)) { while (pinos_connection_has_next (conn)) {
PinosControlCmd cmd = pinos_connection_get_cmd (conn); PinosMessageType type = pinos_connection_get_type (conn);
switch (cmd) { switch (type) {
case PINOS_CONTROL_CMD_INVALID: case PINOS_MESSAGE_INVALID:
case PINOS_CONTROL_CMD_ADD_PORT: case PINOS_MESSAGE_ADD_PORT:
case PINOS_CONTROL_CMD_REMOVE_PORT: case PINOS_MESSAGE_REMOVE_PORT:
case PINOS_CONTROL_CMD_SET_FORMAT: case PINOS_MESSAGE_SET_FORMAT:
case PINOS_CONTROL_CMD_SET_PROPERTY: case PINOS_MESSAGE_SET_PROPERTY:
case PINOS_CONTROL_CMD_NODE_COMMAND: case PINOS_MESSAGE_NODE_COMMAND:
case PINOS_CONTROL_CMD_PORT_COMMAND: case PINOS_MESSAGE_PORT_COMMAND:
case PINOS_CONTROL_CMD_PROCESS_BUFFER: case PINOS_MESSAGE_PROCESS_BUFFER:
spa_log_error (this->log, "proxy %p: got unexpected command %d\n", this, cmd); spa_log_error (this->log, "proxy %p: got unexpected command %d", this, type);
break; 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; 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; 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; 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); this->max_inputs, this->max_outputs);
break; break;
} }
case PINOS_CONTROL_CMD_PORT_UPDATE: case PINOS_MESSAGE_PORT_UPDATE:
{ {
PinosControlCmdPortUpdate pu; PinosMessagePortUpdate pu;
bool remove; bool remove;
spa_log_info (this->log, "proxy %p: got port update %d\n", this, cmd); spa_log_info (this->log, "proxy %p: got port update %d", this, type);
if (!pinos_connection_parse_cmd (conn, &pu)) if (!pinos_connection_parse_message (conn, &pu))
break; break;
if (!CHECK_PORT_ID (this, pu.direction, pu.port_id)) if (!CHECK_PORT_ID (this, pu.direction, pu.port_id))
@ -1113,21 +1113,21 @@ parse_connection (SpaProxy *this)
break; 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; break;
} }
case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: case PINOS_MESSAGE_NODE_STATE_CHANGE:
{ {
PinosControlCmdNodeStateChange sc; PinosMessageNodeStateChange sc;
SpaNodeState old = this->node.state; SpaNodeState old = this->node.state;
if (!pinos_connection_parse_cmd (conn, &sc)) if (!pinos_connection_parse_message (conn, &sc))
break; 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; this->node.state = sc.state;
if (old == SPA_NODE_STATE_INIT) if (old == SPA_NODE_STATE_INIT)
send_async_complete (this, 0, SPA_RESULT_OK); send_async_complete (this, 0, SPA_RESULT_OK);
@ -1135,16 +1135,16 @@ parse_connection (SpaProxy *this)
break; break;
} }
case PINOS_CONTROL_CMD_ADD_MEM: case PINOS_MESSAGE_ADD_MEM:
break; break;
case PINOS_CONTROL_CMD_USE_BUFFERS: case PINOS_MESSAGE_USE_BUFFERS:
break; 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; break;
handle_node_event (this, cne.event); handle_node_event (this, cne.event);
@ -1162,63 +1162,63 @@ parse_rtconnection (SpaProxy *this)
PinosConnection *conn = this->rtconn; PinosConnection *conn = this->rtconn;
while (pinos_connection_has_next (conn)) { while (pinos_connection_has_next (conn)) {
PinosControlCmd cmd = pinos_connection_get_cmd (conn); PinosMessageType type = pinos_connection_get_type (conn);
switch (cmd) { switch (type) {
case PINOS_CONTROL_CMD_INVALID: case PINOS_MESSAGE_INVALID:
case PINOS_CONTROL_CMD_NODE_UPDATE: case PINOS_MESSAGE_NODE_UPDATE:
case PINOS_CONTROL_CMD_PORT_UPDATE: case PINOS_MESSAGE_PORT_UPDATE:
case PINOS_CONTROL_CMD_NODE_STATE_CHANGE: case PINOS_MESSAGE_NODE_STATE_CHANGE:
case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE: case PINOS_MESSAGE_PORT_STATUS_CHANGE:
case PINOS_CONTROL_CMD_ADD_PORT: case PINOS_MESSAGE_ADD_PORT:
case PINOS_CONTROL_CMD_REMOVE_PORT: case PINOS_MESSAGE_REMOVE_PORT:
case PINOS_CONTROL_CMD_SET_FORMAT: case PINOS_MESSAGE_SET_FORMAT:
case PINOS_CONTROL_CMD_SET_PROPERTY: case PINOS_MESSAGE_SET_PROPERTY:
case PINOS_CONTROL_CMD_NODE_COMMAND: case PINOS_MESSAGE_NODE_COMMAND:
case PINOS_CONTROL_CMD_ADD_MEM: case PINOS_MESSAGE_ADD_MEM:
case PINOS_CONTROL_CMD_USE_BUFFERS: case PINOS_MESSAGE_USE_BUFFERS:
spa_log_error (this->log, "proxy %p: got unexpected connection %d\n", this, cmd); spa_log_error (this->log, "proxy %p: got unexpected message %d", this, type);
break; break;
case PINOS_CONTROL_CMD_PROCESS_BUFFER: case PINOS_MESSAGE_PROCESS_BUFFER:
{ {
PinosControlCmdProcessBuffer cmd; PinosMessageProcessBuffer msg;
SpaProxyPort *port; SpaProxyPort *port;
ProxyBuffer *b; ProxyBuffer *b;
if (!pinos_connection_parse_cmd (conn, &cmd)) if (!pinos_connection_parse_message (conn, &msg))
break; break;
if (!CHECK_PORT (this, cmd.direction, cmd.port_id)) if (!CHECK_PORT (this, msg.direction, msg.port_id))
break; 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; 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; b->next = NULL;
SPA_QUEUE_PUSH_TAIL (&port->ready, ProxyBuffer, next, b); SPA_QUEUE_PUSH_TAIL (&port->ready, ProxyBuffer, next, b);
break; 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; break;
handle_node_event (this, cne.event); handle_node_event (this, cne.event);
break; 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;
break; break;
@ -1387,7 +1387,7 @@ pinos_client_node_dispose (GObject * object)
PinosClientNode *this = PINOS_CLIENT_NODE (object); PinosClientNode *this = PINOS_CLIENT_NODE (object);
PinosClientNodePrivate *priv = this->priv; PinosClientNodePrivate *priv = this->priv;
g_debug ("client-node %p: dispose", this); pinos_log_debug ("client-node %p: dispose", this);
proxy_clear (priv->proxy); proxy_clear (priv->proxy);
@ -1400,7 +1400,7 @@ pinos_client_node_finalize (GObject * object)
PinosClientNode *this = PINOS_CLIENT_NODE (object); PinosClientNode *this = PINOS_CLIENT_NODE (object);
PinosClientNodePrivate *priv = this->priv; 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[0]);
g_clear_object (&priv->sockets[1]); g_clear_object (&priv->sockets[1]);
@ -1416,7 +1416,7 @@ pinos_client_node_constructed (GObject * object)
PinosClientNode *this = PINOS_CLIENT_NODE (object); PinosClientNode *this = PINOS_CLIENT_NODE (object);
PinosClientNodePrivate *priv = this->priv; 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); 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); node->priv = PINOS_CLIENT_NODE_GET_PRIVATE (node);
g_debug ("client-node %p: new", node); pinos_log_debug ("client-node %p: new", node);
} }
/** /**

View file

@ -70,7 +70,7 @@ client_name_appeared_handler (GDBusConnection *connection,
{ {
PinosClient *client = user_data; 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); g_signal_emit (client, signals[SIGNAL_APPEARED], 0, NULL);
} }
@ -83,7 +83,7 @@ client_name_vanished_handler (GDBusConnection *connection,
PinosClient *client = user_data; PinosClient *client = user_data;
PinosClientPrivate *priv = client->priv; 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_signal_emit (client, signals[SIGNAL_VANISHED], 0, NULL);
g_bus_unwatch_name (priv->id); 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)); priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
g_object_unref (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 static void
@ -195,8 +197,9 @@ client_unregister_object (PinosClient *client)
PinosClientPrivate *priv = client->priv; PinosClientPrivate *priv = client->priv;
PinosDaemon *daemon = priv->daemon; 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_daemon_unexport (daemon, priv->object_path);
pinos_map_remove (&daemon->registry.clients, client->id);
} }
static void static void
@ -206,7 +209,7 @@ pinos_client_dispose (GObject * object)
PinosClientPrivate *priv = client->priv; PinosClientPrivate *priv = client->priv;
GList *copy; GList *copy;
g_debug ("client %p: dispose", client); pinos_log_debug ("client %p: dispose", client);
copy = g_list_copy (priv->objects); copy = g_list_copy (priv->objects);
g_list_free_full (copy, g_object_unref); g_list_free_full (copy, g_object_unref);
g_list_free (priv->objects); g_list_free (priv->objects);
@ -222,7 +225,7 @@ pinos_client_finalize (GObject * object)
PinosClient *client = PINOS_CLIENT (object); PinosClient *client = PINOS_CLIENT (object);
PinosClientPrivate *priv = client->priv; 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->daemon);
g_clear_object (&priv->iface); g_clear_object (&priv->iface);
g_free (priv->sender); g_free (priv->sender);
@ -238,7 +241,7 @@ pinos_client_constructed (GObject * object)
{ {
PinosClient *client = PINOS_CLIENT (object); PinosClient *client = PINOS_CLIENT (object);
g_debug ("client %p: constructed", client); pinos_log_debug ("client %p: constructed", client);
client_watch_name (client); client_watch_name (client);
client_register_object (client); client_register_object (client);
@ -335,7 +338,7 @@ pinos_client_init (PinosClient * client)
PinosClientPrivate *priv = client->priv = PINOS_CLIENT_GET_PRIVATE (client); PinosClientPrivate *priv = client->priv = PINOS_CLIENT_GET_PRIVATE (client);
priv->iface = pinos_client1_skeleton_new (); 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_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); g_signal_emit (client, signals[SIGNAL_REMOVE], 0, NULL);
} }

View file

@ -47,6 +47,8 @@ typedef struct _PinosClientPrivate PinosClientPrivate;
struct _PinosClient { struct _PinosClient {
GObject object; GObject object;
uint32_t id;
PinosClientPrivate *priv; PinosClientPrivate *priv;
}; };

View file

@ -26,6 +26,7 @@
#include "config.h" #include "config.h"
#include "pinos/client/pinos.h" #include "pinos/client/pinos.h"
#include "pinos/client/log.h"
#include "pinos/server/daemon.h" #include "pinos/server/daemon.h"
#include "pinos/server/node.h" #include "pinos/server/node.h"
@ -50,8 +51,6 @@ struct _PinosDaemonPrivate
gchar *object_path; gchar *object_path;
GList *nodes;
GHashTable *clients; GHashTable *clients;
PinosDataLoop *data_loop; PinosDataLoop *data_loop;
PinosMainLoop *main_loop; PinosMainLoop *main_loop;
@ -61,7 +60,6 @@ struct _PinosDaemonPrivate
GHashTable *node_factories; GHashTable *node_factories;
SpaSupport support[4]; SpaSupport support[4];
SpaLog log;
}; };
enum enum
@ -80,7 +78,7 @@ handle_client_appeared (PinosClient *client, gpointer user_data)
PinosDaemon *daemon = user_data; PinosDaemon *daemon = user_data;
PinosDaemonPrivate *priv = daemon->priv; 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); 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; PinosDaemon *daemon = user_data;
PinosDaemonPrivate *priv = daemon->priv; 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)); 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) { if (client == NULL && create) {
client = pinos_client_new (daemon, sender, NULL); 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, g_signal_connect (client,
"appeared", "appeared",
(GCallback) handle_client_appeared, (GCallback) handle_client_appeared,
@ -126,7 +124,7 @@ handle_remove_node (PinosNode *node,
{ {
PinosClient *client = user_data; 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)); 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); sender = g_dbus_method_invocation_get_sender (invocation);
client = sender_get_client (daemon, sender, TRUE); 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); props = pinos_properties_from_variant (arg_properties);
@ -158,7 +156,6 @@ handle_create_node (PinosDaemon1 *interface,
goto no_factory; goto no_factory;
node = pinos_node_factory_create_node (factory, node = pinos_node_factory_create_node (factory,
daemon,
client, client,
arg_name, arg_name,
props); props);
@ -175,7 +172,7 @@ handle_create_node (PinosDaemon1 *interface,
client); client);
object_path = pinos_node_get_object_path (node); 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_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)", object_path)); g_variant_new ("(o)", object_path));
g_object_unref (node); g_object_unref (node);
@ -185,14 +182,14 @@ handle_create_node (PinosDaemon1 *interface,
/* ERRORS */ /* ERRORS */
no_factory: 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, g_dbus_method_invocation_return_dbus_error (invocation,
"org.pinos.Error", "can't find factory"); "org.pinos.Error", "can't find factory");
return TRUE; return TRUE;
} }
no_node: 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, g_dbus_method_invocation_return_dbus_error (invocation,
"org.pinos.Error", "can't create node"); "org.pinos.Error", "can't create node");
return TRUE; return TRUE;
@ -205,7 +202,7 @@ on_link_port_unlinked (PinosLink *link,
PinosPort *port, PinosPort *port,
PinosDaemon *this) 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) if (port->direction == PINOS_DIRECTION_OUTPUT && link->input)
try_link_port (link->input->node, link->input, this); try_link_port (link->input->node, link->input, this);
@ -224,7 +221,7 @@ on_link_state_notify (GObject *obj,
switch (state) { switch (state) {
case PINOS_LINK_STATE_ERROR: 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) if (link->input && link->input->node)
pinos_node_report_error (link->input->node, g_error_copy (error)); 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: 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 #if 0
g_set_error (&error, g_set_error (&error,
@ -348,7 +345,7 @@ on_node_state_change (PinosNode *node,
PinosNodeState state, PinosNodeState state,
PinosDaemon *this) 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 (old),
pinos_node_state_as_string (state)); pinos_node_state_as_string (state));
@ -362,7 +359,7 @@ on_node_added (PinosDaemon *daemon, PinosNode *node)
PinosNodeState state; PinosNodeState state;
PinosDaemonPrivate *priv = daemon->priv; 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); g_object_set (node, "data-loop", priv->data_loop, NULL);
@ -377,7 +374,7 @@ on_node_added (PinosDaemon *daemon, PinosNode *node)
static void static void
on_node_removed (PinosDaemon *daemon, PinosNode *node) 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); 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); sender = g_dbus_method_invocation_get_sender (invocation);
client = sender_get_client (daemon, sender, TRUE); 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); props = pinos_properties_from_variant (arg_properties);
node = pinos_client_node_new (daemon, node = pinos_client_node_new (daemon,
@ -421,7 +418,7 @@ handle_create_client_node (PinosDaemon1 *interface,
pinos_client_add_object (client, G_OBJECT (node)); pinos_client_add_object (client, G_OBJECT (node));
object_path = pinos_node_get_object_path (PINOS_NODE (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); g_object_unref (node);
fdlist = g_unix_fd_list_new (); fdlist = g_unix_fd_list_new ();
@ -438,7 +435,7 @@ handle_create_client_node (PinosDaemon1 *interface,
no_socket: 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); g_object_unref (node);
goto exit_error; goto exit_error;
} }
@ -470,7 +467,7 @@ handle_register_client_node (PinosDaemon1 *interface,
sender = g_dbus_method_invocation_get_sender (invocation); sender = g_dbus_method_invocation_get_sender (invocation);
client = sender_get_client (daemon, sender, TRUE); 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); props = pinos_properties_from_variant (arg_properties);
node = pinos_dbus_client_node_new (daemon, node = pinos_dbus_client_node_new (daemon,
@ -498,7 +495,7 @@ handle_register_client_node (PinosDaemon1 *interface,
no_socket: 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); g_object_unref (node);
goto exit_error; goto exit_error;
} }
@ -606,7 +603,7 @@ pinos_daemon_start (PinosDaemon *daemon)
priv = daemon->priv; priv = daemon->priv;
g_return_if_fail (priv->id == 0); 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, priv->id = g_bus_own_name (G_BUS_TYPE_SESSION,
PINOS_DBUS_SERVICE, PINOS_DBUS_SERVICE,
@ -631,7 +628,7 @@ pinos_daemon_stop (PinosDaemon *daemon)
g_return_if_fail (PINOS_IS_DAEMON (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) { if (priv->id != 0) {
g_bus_unown_name (priv->id); g_bus_unown_name (priv->id);
@ -688,13 +685,9 @@ void
pinos_daemon_add_node (PinosDaemon *daemon, pinos_daemon_add_node (PinosDaemon *daemon,
PinosNode *node) PinosNode *node)
{ {
PinosDaemonPrivate *priv;
g_return_if_fail (PINOS_IS_DAEMON (daemon)); g_return_if_fail (PINOS_IS_DAEMON (daemon));
g_return_if_fail (PINOS_IS_NODE (node)); g_return_if_fail (PINOS_IS_NODE (node));
priv = daemon->priv;
priv->nodes = g_list_prepend (priv->nodes, node);
on_node_added (daemon, node); on_node_added (daemon, node);
} }
@ -709,14 +702,10 @@ void
pinos_daemon_remove_node (PinosDaemon *daemon, pinos_daemon_remove_node (PinosDaemon *daemon,
PinosNode *node) PinosNode *node)
{ {
PinosDaemonPrivate *priv;
g_return_if_fail (PINOS_IS_DAEMON (daemon)); g_return_if_fail (PINOS_IS_DAEMON (daemon));
g_return_if_fail (PINOS_IS_NODE (node)); g_return_if_fail (PINOS_IS_NODE (node));
priv = daemon->priv;
on_node_removed (daemon, node); 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, GPtrArray *format_filters,
GError **error) GError **error)
{ {
PinosDaemonPrivate *priv;
PinosPort *best = NULL; PinosPort *best = NULL;
GList *nodes;
gboolean have_name; gboolean have_name;
guint i;
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL); g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
priv = daemon->priv;
have_name = name ? strlen (name) > 0 : FALSE; 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)) { for (i = 0; i < pinos_map_get_size (&daemon->registry.nodes); i++) {
PinosNode *n = nodes->data; 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; 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 (have_name) {
if (g_str_has_suffix (pinos_node_get_object_path (n), 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)); best = pinos_node_get_free_port (n, pinos_direction_reverse (other_port->direction));
if (best) if (best)
@ -839,7 +826,7 @@ pinos_daemon_constructed (GObject * object)
PinosDaemon *daemon = PINOS_DAEMON_CAST (object); PinosDaemon *daemon = PINOS_DAEMON_CAST (object);
PinosDaemonPrivate *priv = daemon->priv; 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_user_name (priv->iface, g_get_user_name ());
pinos_daemon1_set_host_name (priv->iface, g_get_host_name ()); pinos_daemon1_set_host_name (priv->iface, g_get_host_name ());
pinos_daemon1_set_version (priv->iface, PACKAGE_VERSION); pinos_daemon1_set_version (priv->iface, PACKAGE_VERSION);
@ -855,7 +842,7 @@ pinos_daemon_dispose (GObject * object)
{ {
PinosDaemon *daemon = PINOS_DAEMON_CAST (object); PinosDaemon *daemon = PINOS_DAEMON_CAST (object);
g_debug ("daemon %p: dispose", object); pinos_log_debug ("daemon %p: dispose", object);
pinos_daemon_stop (daemon); pinos_daemon_stop (daemon);
@ -868,7 +855,7 @@ pinos_daemon_finalize (GObject * object)
PinosDaemon *daemon = PINOS_DAEMON_CAST (object); PinosDaemon *daemon = PINOS_DAEMON_CAST (object);
PinosDaemonPrivate *priv = daemon->priv; 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->server_manager);
g_clear_object (&priv->iface); g_clear_object (&priv->iface);
g_clear_object (&priv->data_loop); g_clear_object (&priv->data_loop);
@ -922,55 +909,19 @@ 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 static void
pinos_daemon_init (PinosDaemon * daemon) pinos_daemon_init (PinosDaemon * daemon)
{ {
PinosDaemonPrivate *priv = daemon->priv = PINOS_DAEMON_GET_PRIVATE (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 (); 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-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-create-client-node", (GCallback) handle_create_client_node, daemon);
g_signal_connect (priv->iface, "handle-register-client-node", (GCallback) handle_register_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->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->clients = g_hash_table_new (g_str_hash, g_str_equal);
priv->node_factories = g_hash_table_new_full (g_str_hash, priv->node_factories = g_hash_table_new_full (g_str_hash,
@ -979,17 +930,10 @@ pinos_daemon_init (PinosDaemon * daemon)
g_object_unref); g_object_unref);
daemon->main_loop = pinos_main_loop_new (g_main_context_get_thread_default ()); daemon->main_loop = pinos_main_loop_new (g_main_context_get_thread_default ());
priv->data_loop = pinos_data_loop_new(); priv->data_loop = pinos_data_loop_new();
priv->log.size = sizeof (SpaLog); daemon->map = pinos_id_map_get_default();
priv->log.info = NULL; daemon->log = pinos_log_get();
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;
priv->support[0].uri = SPA_ID_MAP_URI; priv->support[0].uri = SPA_ID_MAP_URI;
priv->support[0].data = daemon->map; priv->support[0].data = daemon->map;

View file

@ -44,6 +44,7 @@ typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
#include <pinos/server/node-factory.h> #include <pinos/server/node-factory.h>
#include <pinos/server/main-loop.h> #include <pinos/server/main-loop.h>
#include <pinos/client/properties.h> #include <pinos/client/properties.h>
#include <pinos/server/registry.h>
/** /**
* PinosDaemon: * PinosDaemon:
@ -61,6 +62,8 @@ struct _PinosDaemon {
SpaSupport *support; SpaSupport *support;
unsigned int n_support; unsigned int n_support;
PinosRegistry registry;
PinosDaemonPrivate *priv; PinosDaemonPrivate *priv;
}; };

View file

@ -27,9 +27,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <gio/gio.h>
#include "spa/include/spa/ringbuffer.h" #include "spa/include/spa/ringbuffer.h"
#include "pinos/client/log.h"
#include "pinos/client/rtkit.h" #include "pinos/client/rtkit.h"
#include "pinos/server/data-loop.h" #include "pinos/server/data-loop.h"
@ -63,7 +62,7 @@ struct _PinosDataLoopPrivate
uint32_t counter; uint32_t counter;
uint32_t seq; uint32_t seq;
gboolean running; bool running;
pthread_t thread; pthread_t thread;
}; };
@ -97,31 +96,31 @@ make_realtime (PinosDataLoop *this)
sp.sched_priority = rtprio; sp.sched_priority = rtprio;
if (pthread_setschedparam (pthread_self(), SCHED_RR|SCHED_RESET_ON_FORK, &sp) == 0) { 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; return;
} }
system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
rl.rlim_cur = rl.rlim_max = rttime; rl.rlim_cur = rl.rlim_max = rttime;
if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0) 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) { if (rttime >= 0) {
r = getrlimit (RLIMIT_RTTIME, &rl); r = getrlimit (RLIMIT_RTTIME, &rl);
if (r >= 0 && (long long) rl.rlim_max > rttime) { 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; rl.rlim_cur = rl.rlim_max = rttime;
if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0) 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)) { 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); g_clear_error (&error);
} else { } else {
g_debug ("thread made realtime"); pinos_log_debug ("thread made realtime");
} }
g_object_unref (system_bus); g_object_unref (system_bus);
} }
@ -136,7 +135,7 @@ loop (void *user_data)
make_realtime (this); make_realtime (this);
g_debug ("data-loop %p: enter thread", this); pinos_log_debug ("data-loop %p: enter thread", this);
while (priv->running) { while (priv->running) {
SpaPollNotifyData ndata; SpaPollNotifyData ndata;
unsigned int n_idle = 0; unsigned int n_idle = 0;
@ -196,7 +195,7 @@ loop (void *user_data)
break; break;
} }
if (r == 0) { 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; continue;
} }
@ -206,7 +205,7 @@ loop (void *user_data)
size_t offset; size_t offset;
if (read (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t)) 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) { while (spa_ringbuffer_get_read_offset (&priv->buffer, &offset) > 0) {
InvokeItem *item = SPA_MEMBER (priv->buffer_data, offset, InvokeItem); 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; return NULL;
} }
@ -244,7 +243,7 @@ wakeup_thread (PinosDataLoop *this)
uint64_t u = 1; uint64_t u = 1;
if (write (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t)) 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 static void
@ -256,14 +255,14 @@ start_thread (PinosDataLoop *this)
if (!priv->running) { if (!priv->running) {
priv->running = true; priv->running = true;
if ((err = pthread_create (&priv->thread, NULL, loop, this)) != 0) { 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; priv->running = false;
} }
} }
} }
static void static void
stop_thread (PinosDataLoop *this, gboolean in_thread) stop_thread (PinosDataLoop *this, bool in_thread)
{ {
PinosDataLoopPrivate *priv = this->priv; PinosDataLoopPrivate *priv = this->priv;
@ -282,7 +281,7 @@ do_add_item (SpaPoll *poll,
{ {
PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll); PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
PinosDataLoopPrivate *priv = this->priv; 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; item->id = ++priv->counter;
priv->poll[priv->n_poll] = *item; priv->poll[priv->n_poll] = *item;
@ -304,7 +303,7 @@ do_update_item (SpaPoll *poll,
{ {
PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll); PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
PinosDataLoopPrivate *priv = this->priv; 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; unsigned int i;
for (i = 0; i < priv->n_poll; 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); PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
PinosDataLoopPrivate *priv = this->priv; 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; unsigned int i;
for (i = 0; i < priv->n_poll; 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); PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
PinosDataLoopPrivate *priv = this->priv; 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]; SpaRingbufferArea areas[2];
InvokeItem *item; InvokeItem *item;
SpaResult res; SpaResult res;
@ -365,7 +364,7 @@ do_invoke (SpaPoll *poll,
} else { } else {
spa_ringbuffer_get_write_areas (&priv->buffer, areas); spa_ringbuffer_get_write_areas (&priv->buffer, areas);
if (areas[0].len < sizeof (InvokeItem)) { if (areas[0].len < sizeof (InvokeItem)) {
g_warning ("queue full"); pinos_log_warn ("queue full");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
item = SPA_MEMBER (priv->buffer_data, areas[0].offset, InvokeItem); 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); PinosDataLoop *this = PINOS_DATA_LOOP (obj);
PinosDataLoopPrivate *priv = this->priv; 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); 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); 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); stop_thread (this, FALSE);
G_OBJECT_CLASS (pinos_data_loop_parent_class)->dispose (obj); 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); 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); 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); 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.size = sizeof (SpaPoll);
this->poll.info = NULL; this->poll.info = NULL;
@ -476,7 +475,7 @@ pinos_data_loop_new (void)
return g_object_new (PINOS_TYPE_DATA_LOOP, NULL); return g_object_new (PINOS_TYPE_DATA_LOOP, NULL);
} }
gboolean bool
pinos_data_loop_in_thread (PinosDataLoop *loop) pinos_data_loop_in_thread (PinosDataLoop *loop)
{ {
return pthread_equal (loop->priv->thread, pthread_self()); return pthread_equal (loop->priv->thread, pthread_self());

View file

@ -67,7 +67,7 @@ GType pinos_data_loop_get_type (void);
PinosDataLoop * pinos_data_loop_new (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 G_END_DECLS

View file

@ -27,6 +27,8 @@
#include <poll.h> #include <poll.h>
#include <sys/eventfd.h> #include <sys/eventfd.h>
#include "spa/lib/props.h"
#include "pinos/client/pinos.h" #include "pinos/client/pinos.h"
#include "pinos/client/enumtypes.h" #include "pinos/client/enumtypes.h"
#include "pinos/client/private.h" #include "pinos/client/private.h"

View file

@ -22,7 +22,7 @@
#include <gio/gio.h> #include <gio/gio.h>
#include <spa/include/spa/video/format.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/pinos.h"
#include "pinos/client/enumtypes.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)); priv->object_path = pinos_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel));
g_object_unref (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 static void
@ -189,8 +191,9 @@ link_unregister_object (PinosLink *this)
{ {
PinosLinkPrivate *priv = this->priv; 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_daemon_unexport (priv->daemon, priv->object_path);
pinos_map_remove (&priv->daemon->registry.links, this->id);
} }
static void static void
@ -200,7 +203,7 @@ pinos_link_update_state (PinosLink *link, PinosLinkState state)
if (state != priv->state) { if (state != priv->state) {
g_clear_error (&priv->error); 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 (priv->state),
pinos_link_state_as_string (state)); pinos_link_state_as_string (state));
priv->state = state; priv->state = state;
@ -216,7 +219,7 @@ pinos_link_report_error (PinosLink *link, GError *error)
g_clear_error (&priv->error); g_clear_error (&priv->error);
priv->error = error; priv->error = error;
priv->state = PINOS_LINK_STATE_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"); 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 */ /* both ports need a format */
if (in_state == SPA_NODE_STATE_CONFIGURE && out_state == SPA_NODE_STATE_CONFIGURE) { 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: again:
if ((res = spa_node_port_enum_formats (this->input->node->node, if ((res = spa_node_port_enum_formats (this->input->node->node,
SPA_DIRECTION_INPUT, SPA_DIRECTION_INPUT,
@ -251,7 +254,7 @@ again:
goto error; goto error;
} }
} }
g_debug ("Try filter:"); pinos_log_debug ("Try filter:");
spa_debug_format (filter); spa_debug_format (filter);
if ((res = spa_node_port_enum_formats (this->output->node->node, if ((res = spa_node_port_enum_formats (this->output->node->node,
@ -270,7 +273,7 @@ again:
"error output enum formats: %d", res); "error output enum formats: %d", res);
goto error; goto error;
} }
g_debug ("Got filtered:"); pinos_log_debug ("Got filtered:");
spa_debug_format (format); spa_debug_format (format);
spa_format_fixate (format); spa_format_fixate (format);
} else if (in_state == SPA_NODE_STATE_CONFIGURE && out_state > SPA_NODE_STATE_CONFIGURE) { } else if (in_state == SPA_NODE_STATE_CONFIGURE && out_state > SPA_NODE_STATE_CONFIGURE) {
@ -300,11 +303,11 @@ again:
} else } else
return SPA_RESULT_OK; 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); spa_debug_format (format);
if (out_state == SPA_NODE_STATE_CONFIGURE) { 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, if ((res = spa_node_port_set_format (this->output->node->node,
SPA_DIRECTION_OUTPUT, SPA_DIRECTION_OUTPUT,
this->output->port, this->output->port,
@ -317,7 +320,7 @@ again:
goto error; goto error;
} }
} else if (in_state == SPA_NODE_STATE_CONFIGURE) { } 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, if ((res = spa_node_port_set_format (this->input->node->node,
SPA_DIRECTION_INPUT, SPA_DIRECTION_INPUT,
this->input->port, this->input->port,
@ -351,6 +354,20 @@ find_param (const SpaPortInfo *info, SpaAllocParamType type)
return NULL; 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 static SpaResult
do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state) 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); 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 */ /* find out what's possible */
if ((res = spa_node_port_get_info (this->output->node->node, if ((res = spa_node_port_get_info (this->output->node->node,
SPA_DIRECTION_OUTPUT, SPA_DIRECTION_OUTPUT,
@ -394,7 +411,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
out_flags = oinfo->flags; out_flags = oinfo->flags;
if (out_flags & SPA_PORT_INFO_FLAG_LIVE) { 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->output->node->live = true;
this->input->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) { if (priv->buffers == NULL) {
SpaAllocParamBuffers *in_alloc, *out_alloc; SpaAllocParamBuffers *in_alloc, *out_alloc;
guint max_buffers = MAX_BUFFERS; SpaAllocParamMetaEnableRingbuffer *in_me, *out_me;
size_t minsize = 0, stride = 0; guint max_buffers;
size_t minsize, stride, blocks;
max_buffers = MAX_BUFFERS; in_me = find_meta_enable (iinfo, SPA_META_TYPE_RINGBUFFER);
in_alloc = find_param (iinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS); out_me = find_meta_enable (oinfo, SPA_META_TYPE_RINGBUFFER);
if (in_alloc) { if (in_me && out_me) {
max_buffers = in_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (in_alloc->max_buffers, max_buffers); max_buffers = 1;
minsize = SPA_MAX (minsize, in_alloc->minsize); minsize = SPA_MAX (out_me->minsize, in_me->minsize);
stride = SPA_MAX (stride, in_alloc->stride); stride = SPA_MAX (out_me->stride, in_me->stride);
} blocks = SPA_MAX (1, SPA_MAX (out_me->blocks, in_me->blocks));
out_alloc = find_param (oinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS); } else {
if (out_alloc) { max_buffers = MAX_BUFFERS;
max_buffers = out_alloc->max_buffers == 0 ? max_buffers : SPA_MIN (out_alloc->max_buffers, max_buffers); minsize = stride = 0;
minsize = SPA_MAX (minsize, out_alloc->minsize); blocks = 1;
stride = SPA_MAX (stride, out_alloc->stride); 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) || 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->n_buffers = this->output->n_buffers;
priv->buffers = this->output->buffers; priv->buffers = this->output->buffers;
priv->allocated = FALSE; 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 { } else {
guint i, j; guint i, j;
size_t hdr_size, buf_size, arr_size; 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); 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; priv->n_buffers = max_buffers;
pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD | 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].type = pme->type;
b->metas[mi].data = pd; b->metas[mi].data = pd;
b->metas[mi].size = spa_meta_type_get_size (pme->type); 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); pd = SPA_MEMBER (pd, b->metas[mi].size, void);
mi++; mi++;
} }
@ -543,7 +583,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
d->data = NULL; 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; priv->allocated = TRUE;
} }
@ -564,7 +604,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
this->output->allocated = TRUE; this->output->allocated = TRUE;
this->output->buffer_mem = priv->buffer_mem; this->output->buffer_mem = priv->buffer_mem;
priv->allocated = FALSE; 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) { } else if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
if ((res = spa_node_port_alloc_buffers (this->input->node->node, if ((res = spa_node_port_alloc_buffers (this->input->node->node,
SPA_DIRECTION_INPUT, SPA_DIRECTION_INPUT,
@ -582,12 +622,12 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
this->input->allocated = TRUE; this->input->allocated = TRUE;
this->input->buffer_mem = priv->buffer_mem; this->input->buffer_mem = priv->buffer_mem;
priv->allocated = FALSE; 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) { 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, if ((res = spa_node_port_use_buffers (this->input->node->node,
SPA_DIRECTION_INPUT, SPA_DIRECTION_INPUT,
this->input->port, this->input->port,
@ -604,7 +644,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
this->input->allocated = FALSE; this->input->allocated = FALSE;
} }
else if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) { 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, if ((res = spa_node_port_use_buffers (this->output->node->node,
SPA_DIRECTION_OUTPUT, SPA_DIRECTION_OUTPUT,
this->output->port, this->output->port,
@ -673,7 +713,7 @@ check_states (PinosLink *this,
PinosLinkPrivate *priv = this->priv; PinosLinkPrivate *priv = this->priv;
if (res != SPA_RESULT_OK) { if (res != SPA_RESULT_OK) {
g_warning ("link %p: error: %d", this, res); pinos_log_warn ("link %p: error: %d", this, res);
return res; return res;
} }
@ -684,7 +724,7 @@ again:
in_state = this->input->node->node->state; in_state = this->input->node->node->state;
out_state = this->output->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) if ((res = do_negotiate (this, in_state, out_state)) != SPA_RESULT_OK)
goto exit; goto exit;
@ -714,7 +754,7 @@ on_async_complete_notify (PinosNode *node,
PinosLink *this) PinosLink *this)
{ {
PinosLinkPrivate *priv = this->priv; 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); 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->buffers = NULL;
priv->n_buffers = 0; 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); pinos_port_clear_buffers (other);
} }
@ -814,7 +854,7 @@ pinos_link_constructed (GObject * object)
G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object); G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object);
on_property_notify (G_OBJECT (this), NULL, this); 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->output->node, this->output->port,
this->input->node, this->input->port); this->input->node, this->input->port);
link_register_object (this); link_register_object (this);
@ -826,7 +866,7 @@ pinos_link_dispose (GObject * object)
PinosLink *this = PINOS_LINK (object); PinosLink *this = PINOS_LINK (object);
PinosLinkPrivate *priv = this->priv; PinosLinkPrivate *priv = this->priv;
g_debug ("link %p: dispose", this); pinos_log_debug ("link %p: dispose", this);
if (this->input && this->input->node) if (this->input && this->input->node)
g_signal_handlers_disconnect_by_data (this->input->node, this); g_signal_handlers_disconnect_by_data (this->input->node, this);
@ -853,7 +893,7 @@ pinos_link_finalize (GObject * object)
PinosLink *this = PINOS_LINK (object); PinosLink *this = PINOS_LINK (object);
PinosLinkPrivate *priv = this->priv; 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->daemon);
g_clear_object (&priv->iface); g_clear_object (&priv->iface);
g_free (priv->object_path); g_free (priv->object_path);
@ -963,7 +1003,7 @@ pinos_link_init (PinosLink * this)
PinosLinkPrivate *priv = this->priv = PINOS_LINK_GET_PRIVATE (this); PinosLinkPrivate *priv = this->priv = PINOS_LINK_GET_PRIVATE (this);
priv->iface = pinos_link1_skeleton_new (); 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; priv->state = PINOS_LINK_STATE_INIT;
} }
@ -976,7 +1016,7 @@ pinos_link_init (PinosLink * this)
void void
pinos_link_remove (PinosLink *this) 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); g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
} }

View file

@ -50,6 +50,8 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate;
struct _PinosLink { struct _PinosLink {
GObject object; GObject object;
uint32_t id;
PinosPort *output; PinosPort *output;
PinosPort *input; PinosPort *input;

View file

@ -27,6 +27,7 @@
#include "spa/include/spa/queue.h" #include "spa/include/spa/queue.h"
#include "spa/include/spa/ringbuffer.h" #include "spa/include/spa/ringbuffer.h"
#include "pinos/client/log.h"
#include "pinos/server/main-loop.h" #include "pinos/server/main-loop.h"
#define PINOS_MAIN_LOOP_GET_PRIVATE(loop) \ #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 ()); item->id = g_source_attach (source, g_main_context_get_thread_default ());
g_source_unref (source); 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; return SPA_RESULT_OK;
} }
@ -139,7 +140,7 @@ static SpaResult
do_update_item (SpaPoll *poll, do_update_item (SpaPoll *poll,
SpaPollItem *item) SpaPollItem *item)
{ {
g_debug ("update main poll %d", item->id); pinos_log_debug ("update main poll %d", item->id);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -149,7 +150,7 @@ do_remove_item (SpaPoll *poll,
{ {
GSource *source; 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); source = g_main_context_find_source_by_id (g_main_context_get_thread_default (), item->id);
g_source_destroy (source); g_source_destroy (source);
@ -167,7 +168,7 @@ main_loop_dispatch (SpaPollNotifyData *data)
InvokeItem *item; InvokeItem *item;
if (read (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t)) 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) { while (spa_ringbuffer_get_read_offset (&priv->buffer, &offset) > 0) {
item = SPA_MEMBER (priv->buffer_data, offset, InvokeItem); item = SPA_MEMBER (priv->buffer_data, offset, InvokeItem);
@ -199,7 +200,7 @@ do_invoke (SpaPoll *poll,
} else { } else {
spa_ringbuffer_get_write_areas (&priv->buffer, areas); spa_ringbuffer_get_write_areas (&priv->buffer, areas);
if (areas[0].len < sizeof (InvokeItem)) { if (areas[0].len < sizeof (InvokeItem)) {
g_warning ("queue full"); pinos_log_warn ("queue full");
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
} }
item = SPA_MEMBER (priv->buffer_data, areas[0].offset, InvokeItem); 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); spa_ringbuffer_write_advance (&priv->buffer, item->item_size);
if (write (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t)) 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); res = SPA_RESULT_RETURN_ASYNC (seq);
} }
@ -276,7 +277,7 @@ pinos_main_loop_constructed (GObject * obj)
PinosMainLoop *this = PINOS_MAIN_LOOP (obj); PinosMainLoop *this = PINOS_MAIN_LOOP (obj);
PinosMainLoopPrivate *priv = this->priv; 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->loop = g_main_loop_new (priv->context, FALSE);
priv->fds[0].fd = eventfd (0, 0); priv->fds[0].fd = eventfd (0, 0);
@ -301,7 +302,7 @@ pinos_main_loop_dispose (GObject * obj)
{ {
PinosMainLoop *this = PINOS_MAIN_LOOP (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); 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); PinosMainLoop *this = PINOS_MAIN_LOOP (obj);
PinosMainLoopPrivate *priv = this->priv; 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); 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); 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.size = sizeof (SpaPoll);
this->poll.info = NULL; this->poll.info = NULL;
@ -400,7 +401,7 @@ process_work_queue (PinosMainLoop *this)
prev->next = next; prev->next = next;
if (item->func) { 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); item->func (item->obj, item->data, item->res, item->id);
} }
if (item->notify) if (item->notify)
@ -445,12 +446,12 @@ pinos_main_loop_defer (PinosMainLoop *loop,
if (SPA_RESULT_IS_ASYNC (res)) { if (SPA_RESULT_IS_ASYNC (res)) {
item->seq = SPA_RESULT_ASYNC_SEQ (res); item->seq = SPA_RESULT_ASYNC_SEQ (res);
item->res = 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 { } else {
item->seq = SPA_ID_INVALID; item->seq = SPA_ID_INVALID;
item->res = res; item->res = res;
have_work = TRUE; 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); 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) { for (item = priv->work.head; item; item = item->next) {
if ((id == 0 || item->id == id) && (obj == NULL || item->obj == obj)) { 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->seq = SPA_ID_INVALID;
item->func = NULL; item->func = NULL;
have_work = TRUE; have_work = TRUE;
@ -499,14 +500,14 @@ pinos_main_loop_defer_complete (PinosMainLoop *loop,
for (item = priv->work.head; item; item = item->next) { for (item = priv->work.head; item; item = item->next) {
if (item->obj == obj && item->seq == seq) { 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->seq = SPA_ID_INVALID;
item->res = res; item->res = res;
have_work = TRUE; have_work = TRUE;
} }
} }
if (!have_work) 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) if (priv->work_id == 0 && have_work)
priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop); priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);

View file

@ -10,6 +10,7 @@ pinoscore_headers = [
'module.h', 'module.h',
'node.h', 'node.h',
'node-factory.h', 'node-factory.h',
'registry.h',
'utils.h', 'utils.h',
] ]
@ -25,6 +26,7 @@ pinoscore_sources = [
'module.c', 'module.c',
'node.c', 'node.c',
'node-factory.c', 'node-factory.c',
'registry.c',
'utils.c', 'utils.c',
] ]

View file

@ -180,7 +180,7 @@ find_module (const gchar * path, const gchar *name)
dir = g_dir_open (path, 0, &err); dir = g_dir_open (path, 0, &err);
if (dir == NULL) { 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); g_error_free (err);
return NULL; return NULL;
} }
@ -241,7 +241,7 @@ pinos_module_load (PinosDaemon * daemon,
gchar **l; gchar **l;
gint i; 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); l = g_strsplit (module_dir, G_SEARCHPATH_SEPARATOR_S, 0);
for (i = 0; l[i] != NULL; i++) { for (i = 0; l[i] != NULL; i++) {
@ -251,7 +251,7 @@ pinos_module_load (PinosDaemon * daemon,
} }
g_strfreev (l); g_strfreev (l);
} else { } else {
g_debug ("moduledir set to: %s", MODULEDIR); pinos_log_debug ("moduledir set to: %s", MODULEDIR);
filename = find_module (MODULEDIR, name); filename = find_module (MODULEDIR, name);
} }
@ -262,7 +262,7 @@ pinos_module_load (PinosDaemon * daemon,
return NULL; 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); gmodule = g_module_open (filename, G_MODULE_BIND_LOCAL);
g_free (filename); g_free (filename);
@ -295,7 +295,7 @@ pinos_module_load (PinosDaemon * daemon,
return NULL; return NULL;
} }
g_debug ("loaded module: %s", module->name); pinos_log_debug ("loaded module: %s", module->name);
return module; return module;
} }

View file

@ -25,6 +25,8 @@
struct _PinosNodeFactoryPrivate struct _PinosNodeFactoryPrivate
{ {
PinosDaemon *daemon;
gchar *name; gchar *name;
}; };
@ -33,6 +35,7 @@ G_DEFINE_ABSTRACT_TYPE (PinosNodeFactory, pinos_node_factory, G_TYPE_OBJECT);
enum enum
{ {
PROP_0, PROP_0,
PROP_DAEMON,
PROP_NAME, PROP_NAME,
}; };
@ -46,6 +49,10 @@ pinos_node_factory_get_property (GObject *_object,
PinosNodeFactoryPrivate *priv = factory->priv; PinosNodeFactoryPrivate *priv = factory->priv;
switch (prop_id) { switch (prop_id) {
case PROP_DAEMON:
g_value_set_object (value, priv->daemon);
break;
case PROP_NAME: case PROP_NAME:
g_value_set_string (value, priv->name); g_value_set_string (value, priv->name);
break; break;
@ -66,6 +73,10 @@ pinos_node_factory_set_property (GObject *_object,
PinosNodeFactoryPrivate *priv = factory->priv; PinosNodeFactoryPrivate *priv = factory->priv;
switch (prop_id) { switch (prop_id) {
case PROP_DAEMON:
priv->daemon = g_value_dup_object (value);
break;
case PROP_NAME: case PROP_NAME:
priv->name = g_value_dup_string (value); priv->name = g_value_dup_string (value);
break; break;
@ -80,9 +91,12 @@ static void
pinos_node_factory_constructed (GObject * obj) pinos_node_factory_constructed (GObject * obj)
{ {
PinosNodeFactory *factory = PINOS_NODE_FACTORY (obj); PinosNodeFactory *factory = PINOS_NODE_FACTORY (obj);
PinosNodeFactoryPrivate *priv = factory->priv;
g_debug ("node factory %p: constructed", factory); 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); G_OBJECT_CLASS (pinos_node_factory_parent_class)->constructed (obj);
} }
@ -93,6 +107,7 @@ pinos_node_factory_finalize (GObject * obj)
PinosNodeFactoryPrivate *priv = factory->priv; PinosNodeFactoryPrivate *priv = factory->priv;
g_debug ("node factory %p: finalize", factory); g_debug ("node factory %p: finalize", factory);
pinos_map_remove (&priv->daemon->registry.node_factories, factory->id);
g_free (priv->name); g_free (priv->name);
@ -111,6 +126,16 @@ pinos_node_factory_class_init (PinosNodeFactoryClass * klass)
gobject_class->set_property = pinos_node_factory_set_property; gobject_class->set_property = pinos_node_factory_set_property;
gobject_class->get_property = pinos_node_factory_get_property; 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, g_object_class_install_property (gobject_class,
PROP_NAME, PROP_NAME,
g_param_spec_string ("name", g_param_spec_string ("name",
@ -152,7 +177,6 @@ pinos_node_factory_get_name (PinosNodeFactory *factory)
/** /**
* pinos_node_factory_create_node: * pinos_node_factory_create_node:
* @factory: A #PinosNodeFactory * @factory: A #PinosNodeFactory
* @daemon: a #PinosDaemon
* @client: the owner client * @client: the owner client
* @name: node name * @name: node name
* @props: #PinosProperties for the node * @props: #PinosProperties for the node
@ -163,7 +187,6 @@ pinos_node_factory_get_name (PinosNodeFactory *factory)
*/ */
PinosNode * PinosNode *
pinos_node_factory_create_node (PinosNodeFactory *factory, pinos_node_factory_create_node (PinosNodeFactory *factory,
PinosDaemon *daemon,
PinosClient *client, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *props) PinosProperties *props)
@ -177,5 +200,5 @@ pinos_node_factory_create_node (PinosNodeFactory *factory,
return NULL; return NULL;
g_debug ("node factory %p: create node", factory); 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);
} }

View file

@ -48,6 +48,8 @@ typedef struct _PinosNodeFactoryPrivate PinosNodeFactoryPrivate;
struct _PinosNodeFactory { struct _PinosNodeFactory {
GObject object; GObject object;
uint32_t id;
PinosNodeFactoryPrivate *priv; PinosNodeFactoryPrivate *priv;
}; };
@ -71,7 +73,6 @@ struct _PinosNodeFactoryClass {
GType pinos_node_factory_get_type (void); GType pinos_node_factory_get_type (void);
PinosNode * pinos_node_factory_create_node (PinosNodeFactory *factory, PinosNode * pinos_node_factory_create_node (PinosNodeFactory *factory,
PinosDaemon *daemon,
PinosClient *client, PinosClient *client,
const gchar *name, const gchar *name,
PinosProperties *props); PinosProperties *props);

View file

@ -144,7 +144,7 @@ update_port_ids (PinosNode *node, gboolean create)
max_output_ports, max_output_ports,
output_port_ids); 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); n_input_ports, max_input_ports, n_output_ports, max_output_ports);
i = 0; i = 0;
@ -157,7 +157,7 @@ update_port_ids (PinosNode *node, gboolean create)
ports = g_list_next (ports); ports = g_list_next (ports);
} else if ((p && i < n_input_ports && input_port_ids[i] < p->port) || i < n_input_ports) { } else if ((p && i < n_input_ports && input_port_ids[i] < p->port) || i < n_input_ports) {
PinosPort *np; 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]); np = new_pinos_port (node, PINOS_DIRECTION_INPUT, input_port_ids[i]);
priv->input_ports = g_list_insert_before (priv->input_ports, ports, np); priv->input_ports = g_list_insert_before (priv->input_ports, ports, np);
@ -167,7 +167,7 @@ update_port_ids (PinosNode *node, gboolean create)
i++; i++;
} else if (p) { } else if (p) {
GList *next; 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); next = g_list_next (ports);
priv->input_ports = g_list_delete_link (priv->input_ports, 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); ports = g_list_next (ports);
} else if ((p && i < n_output_ports && output_port_ids[i] < p->port) || i < n_output_ports) { } else if ((p && i < n_output_ports && output_port_ids[i] < p->port) || i < n_output_ports) {
PinosPort *np; 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]); np = new_pinos_port (node, PINOS_DIRECTION_OUTPUT, output_port_ids[i]);
priv->output_ports = g_list_insert_before (priv->output_ports, ports, np); priv->output_ports = g_list_insert_before (priv->output_ports, ports, np);
@ -201,7 +201,7 @@ update_port_ids (PinosNode *node, gboolean create)
i++; i++;
} else if (p) { } else if (p) {
GList *next; 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); next = g_list_next (ports);
priv->output_ports = g_list_delete_link (priv->output_ports, ports); priv->output_ports = g_list_delete_link (priv->output_ports, ports);
@ -231,12 +231,12 @@ pause_node (PinosNode *this)
SpaResult res; SpaResult res;
SpaNodeCommand cmd; SpaNodeCommand cmd;
g_debug ("node %p: pause node", this); pinos_log_debug ("node %p: pause node", this);
cmd.type = SPA_NODE_COMMAND_PAUSE; cmd.type = SPA_NODE_COMMAND_PAUSE;
cmd.size = sizeof (cmd); cmd.size = sizeof (cmd);
if ((res = spa_node_send_command (this->node, &cmd)) < 0) 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; return res;
} }
@ -247,12 +247,12 @@ start_node (PinosNode *this)
SpaResult res; SpaResult res;
SpaNodeCommand cmd; SpaNodeCommand cmd;
g_debug ("node %p: start node", this); pinos_log_debug ("node %p: start node", this);
cmd.type = SPA_NODE_COMMAND_START; cmd.type = SPA_NODE_COMMAND_START;
cmd.size = sizeof (cmd); cmd.size = sizeof (cmd);
if ((res = spa_node_send_command (this->node, &cmd)) < 0) 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; return res;
} }
@ -264,12 +264,12 @@ suspend_node (PinosNode *this)
SpaResult res = SPA_RESULT_OK; SpaResult res = SPA_RESULT_OK;
GList *walk; 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)) { for (walk = priv->input_ports; walk; walk = g_list_next (walk)) {
PinosPort *p = walk->data; PinosPort *p = walk->data;
if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_INPUT, p->port, 0, NULL)) < 0) 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->buffers = NULL;
p->n_buffers = 0; p->n_buffers = 0;
if (p->allocated) if (p->allocated)
@ -279,7 +279,7 @@ suspend_node (PinosNode *this)
for (walk = priv->output_ports; walk; walk = g_list_next (walk)) { for (walk = priv->output_ports; walk; walk = g_list_next (walk)) {
PinosPort *p = walk->data; PinosPort *p = walk->data;
if ((res = spa_node_port_set_format (this->node, SPA_DIRECTION_OUTPUT, p->port, 0, NULL)) < 0) 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->buffers = NULL;
p->n_buffers = 0; p->n_buffers = 0;
if (p->allocated) if (p->allocated)
@ -314,7 +314,7 @@ send_clock_update (PinosNode *this)
cu.state = SPA_CLOCK_STATE_RUNNING; cu.state = SPA_CLOCK_STATE_RUNNING;
if ((res = spa_node_send_command (this->node, &cu.command)) < 0) 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 static SpaResult
@ -341,7 +341,7 @@ do_read_link (SpaPoll *poll,
iinfo[0].flags = SPA_PORT_INPUT_FLAG_NONE; iinfo[0].flags = SPA_PORT_INPUT_FLAG_NONE;
if ((res = spa_node_port_push_input (link->input->node->node, 1, iinfo)) < 0) 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); spa_ringbuffer_read_advance (&link->ringbuffer, 1);
link->in_ready--; link->in_ready--;
@ -367,7 +367,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
{ {
SpaNodeEventAsyncComplete *ac = (SpaNodeEventAsyncComplete *) event; 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)) 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); g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res);
break; break;
@ -405,7 +405,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
oinfo[0].port_id = ho->port_id; oinfo[0].port_id = ho->port_id;
if ((res = spa_node_port_pull_output (node, 1, oinfo)) < 0) { 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; break;
} }
@ -434,7 +434,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
} }
if (!pushed) { if (!pushed) {
if ((res = spa_node_port_reuse_buffer (node, oinfo[0].port_id, oinfo[0].buffer_id)) < 0) 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; 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, if ((res = spa_node_port_reuse_buffer (link->output->node->node,
link->output->port, link->output->port,
rb->buffer_id)) < 0) 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; break;
} }
@ -470,7 +470,7 @@ handle_remove (PinosNode1 *interface,
{ {
PinosNode *this = user_data; PinosNode *this = user_data;
g_debug ("node %p: remove", this); pinos_log_debug ("node %p: remove", this);
pinos_node_remove (this); pinos_node_remove (this);
g_dbus_method_invocation_return_value (invocation, g_dbus_method_invocation_return_value (invocation,
@ -554,7 +554,7 @@ pinos_node_set_property (GObject *_object,
if (priv->data_loop) { if (priv->data_loop) {
if ((res = spa_node_set_event_callback (this->node, on_node_event, this)) < 0) 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; break;
} }
@ -599,7 +599,9 @@ node_register_object (PinosNode *this)
priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel)); priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
g_object_unref (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); pinos_daemon_add_node (daemon, this);
return; return;
@ -610,10 +612,11 @@ node_unregister_object (PinosNode *this)
{ {
PinosNodePrivate *priv = this->priv; 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); pinos_daemon_unexport (priv->daemon, priv->object_path);
g_clear_pointer (&priv->object_path, g_free); g_clear_pointer (&priv->object_path, g_free);
pinos_daemon_remove_node (priv->daemon, this); pinos_daemon_remove_node (priv->daemon, this);
pinos_map_remove (&priv->daemon->registry.nodes, this->id);
} }
static void static void
@ -645,7 +648,7 @@ init_complete (PinosNode *this)
PinosNodePrivate *priv = this->priv; PinosNodePrivate *priv = this->priv;
update_port_ids (this, FALSE); update_port_ids (this, FALSE);
g_debug ("node %p: init completed", this); pinos_log_debug ("node %p: init completed", this);
priv->async_init = FALSE; priv->async_init = FALSE;
on_property_notify (G_OBJECT (this), NULL, this); on_property_notify (G_OBJECT (this), NULL, this);
pinos_node_update_state (this, PINOS_NODE_STATE_SUSPENDED); pinos_node_update_state (this, PINOS_NODE_STATE_SUSPENDED);
@ -657,7 +660,7 @@ pinos_node_constructed (GObject * obj)
PinosNode *this = PINOS_NODE (obj); PinosNode *this = PINOS_NODE (obj);
PinosNodePrivate *priv = this->priv; PinosNodePrivate *priv = this->priv;
g_debug ("node %p: constructed", this); pinos_log_debug ("node %p: constructed", this);
priv->main_loop = priv->daemon->main_loop; priv->main_loop = priv->daemon->main_loop;
@ -696,7 +699,7 @@ pinos_node_dispose (GObject * obj)
PinosNode *node = PINOS_NODE (obj); PinosNode *node = PINOS_NODE (obj);
PinosNodePrivate *priv = node->priv; 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); pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
node_unregister_object (node); node_unregister_object (node);
@ -712,7 +715,7 @@ pinos_node_finalize (GObject * obj)
PinosNode *node = PINOS_NODE (obj); PinosNode *node = PINOS_NODE (obj);
PinosNodePrivate *priv = node->priv; 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->daemon);
g_clear_object (&priv->iface); g_clear_object (&priv->iface);
g_clear_object (&priv->data_loop); g_clear_object (&priv->data_loop);
@ -871,7 +874,7 @@ pinos_node_init (PinosNode * node)
{ {
PinosNodePrivate *priv = node->priv = PINOS_NODE_GET_PRIVATE (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 (); priv->iface = pinos_node1_skeleton_new ();
g_signal_connect (priv->iface, "handle-remove", g_signal_connect (priv->iface, "handle-remove",
(GCallback) handle_remove, (GCallback) handle_remove,
@ -1009,7 +1012,7 @@ pinos_node_remove (PinosNode *node)
if (node->flags & PINOS_NODE_FLAG_REMOVING) if (node->flags & PINOS_NODE_FLAG_REMOVING)
return; return;
g_debug ("node %p: remove", node); pinos_log_debug ("node %p: remove", node);
node->flags |= PINOS_NODE_FLAG_REMOVING; node->flags |= PINOS_NODE_FLAG_REMOVING;
g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL); g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL);
} }
@ -1046,7 +1049,7 @@ pinos_node_get_free_port (PinosNode *node,
} }
free_port = 0; 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)) { for (walk = ports; walk; walk = g_list_next (walk)) {
PinosPort *p = walk->data; PinosPort *p = walk->data;
@ -1140,7 +1143,7 @@ pinos_port_link (PinosPort *output_port,
priv = output_node->priv; priv = output_node->priv;
input_node = input_port->node; 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) if (output_node == input_node)
goto same_node; goto same_node;
@ -1156,7 +1159,7 @@ pinos_port_link (PinosPort *output_port,
input_node->live = output_node->live; input_node->live = output_node->live;
if (output_node->clock) if (output_node->clock)
input_node->clock = 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, link = g_object_new (PINOS_TYPE_LINK,
"daemon", priv->daemon, "daemon", priv->daemon,
@ -1231,7 +1234,7 @@ do_remove_link_done (SpaPoll *poll,
PinosNodePrivate *priv = this->priv; PinosNodePrivate *priv = this->priv;
PinosLink *link = ((PinosLink**)data)[0]; 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 (port->direction == PINOS_DIRECTION_OUTPUT) {
if (g_ptr_array_remove_fast (port->links, link)) if (g_ptr_array_remove_fast (port->links, link))
priv->n_used_output_links--; priv->n_used_output_links--;
@ -1248,7 +1251,7 @@ do_remove_link_done (SpaPoll *poll,
} }
if (!port->allocated) { 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, spa_node_port_use_buffers (port->node->node,
port->direction, port->direction,
port->port, port->port,
@ -1302,7 +1305,7 @@ pinos_port_unlink (PinosPort *port, PinosLink *link)
{ {
SpaResult res; 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 (link);
g_object_ref (port->node); g_object_ref (port->node);
@ -1328,7 +1331,7 @@ do_clear_buffers_done (SpaPoll *poll,
PinosNodePrivate *priv = this->priv; PinosNodePrivate *priv = this->priv;
SpaResult res; 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, res = spa_node_port_use_buffers (port->node->node,
port->direction, port->direction,
@ -1372,7 +1375,7 @@ pinos_port_clear_buffers (PinosPort *port)
{ {
SpaResult res; 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, res = spa_poll_invoke (&port->node->priv->data_loop->poll,
do_clear_buffers, do_clear_buffers,
port->node->priv->seq++, port->node->priv->seq++,
@ -1457,7 +1460,7 @@ pinos_node_set_state (PinosNode *node,
remove_idle_timeout (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) { switch (state) {
case PINOS_NODE_STATE_CREATING: case PINOS_NODE_STATE_CREATING:
@ -1515,7 +1518,7 @@ pinos_node_update_state (PinosNode *node,
old = priv->state; old = priv->state;
if (old != 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 (old),
pinos_node_state_as_string (state)); pinos_node_state_as_string (state));
priv->state = state; priv->state = state;
@ -1546,7 +1549,7 @@ pinos_node_report_error (PinosNode *node,
remove_idle_timeout (node); remove_idle_timeout (node);
priv->error = error; priv->error = error;
priv->state = PINOS_NODE_STATE_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); pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_ERROR);
g_signal_emit (node, signals[SIGNAL_STATE_CHANGE], 0, old, priv->state); g_signal_emit (node, signals[SIGNAL_STATE_CHANGE], 0, old, priv->state);
} }
@ -1557,7 +1560,7 @@ idle_timeout (PinosNode *node)
PinosNodePrivate *priv = node->priv; PinosNodePrivate *priv = node->priv;
priv->idle_timeout = 0; 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); pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
@ -1578,7 +1581,7 @@ pinos_node_report_idle (PinosNode *node)
g_return_if_fail (PINOS_IS_NODE (node)); g_return_if_fail (PINOS_IS_NODE (node));
priv = node->priv; 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); pinos_node_set_state (node, PINOS_NODE_STATE_IDLE);
priv->idle_timeout = g_timeout_add_seconds (3, 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_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); pinos_node_set_state (node, PINOS_NODE_STATE_RUNNING);
} }

View file

@ -44,6 +44,7 @@ typedef enum {
#include <pinos/server/utils.h> #include <pinos/server/utils.h>
struct _PinosPort { struct _PinosPort {
uint32_t id;
PinosNode *node; PinosNode *node;
PinosDirection direction; PinosDirection direction;
uint32_t port; uint32_t port;
@ -71,6 +72,8 @@ struct _PinosPort {
struct _PinosNode { struct _PinosNode {
GObject object; GObject object;
uint32_t id;
PinosNodeFlags flags; PinosNodeFlags flags;
SpaNode *node; SpaNode *node;

36
pinos/server/registry.c Normal file
View file

@ -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 (&reg->clients, 64);
pinos_map_init (&reg->nodes, 128);
pinos_map_init (&reg->ports, 512);
pinos_map_init (&reg->links, 256);
pinos_map_init (&reg->modules, 128);
pinos_map_init (&reg->monitors, 64);
}

57
pinos/server/registry.h Normal file
View file

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

View file

@ -28,6 +28,7 @@
#include "memfd-wrappers.h" #include "memfd-wrappers.h"
#include <pinos/client/log.h>
#include <pinos/server/utils.h> #include <pinos/server/utils.h>
#undef USE_MEMFD #undef USE_MEMFD
@ -47,21 +48,21 @@ pinos_memblock_alloc (PinosMemblockFlags flags,
#ifdef USE_MEMFD #ifdef USE_MEMFD
mem->fd = memfd_create ("pinos-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING); mem->fd = memfd_create ("pinos-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
if (mem->fd == -1) { 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; return FALSE;
} }
#else #else
char filename[] = "/dev/shm/spa-tmpfile.XXXXXX"; char filename[] = "/dev/shm/spa-tmpfile.XXXXXX";
mem->fd = mkostemp (filename, O_CLOEXEC); mem->fd = mkostemp (filename, O_CLOEXEC);
if (mem->fd == -1) { 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; return FALSE;
} }
unlink (filename); unlink (filename);
#endif #endif
if (ftruncate (mem->fd, size) < 0) { 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); close (mem->fd);
return FALSE; return FALSE;
} }
@ -69,7 +70,7 @@ pinos_memblock_alloc (PinosMemblockFlags flags,
if (flags & PINOS_MEMBLOCK_FLAG_SEAL) { if (flags & PINOS_MEMBLOCK_FLAG_SEAL) {
unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL; unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
if (fcntl (mem->fd, F_ADD_SEALS, seals) == -1) { 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 #endif

View file

@ -64,6 +64,7 @@ typedef enum {
#include <spa/defs.h> #include <spa/defs.h>
#include <spa/port.h> #include <spa/port.h>
#include <spa/ringbuffer.h>
/** /**
* SpaBufferFlags: * SpaBufferFlags:
@ -112,16 +113,10 @@ typedef struct {
/** /**
* SpaMetaRingbuffer: * SpaMetaRingbuffer:
* @readindex: * @ringbuffer:
* @writeindex:
* @size:
* @size_mask:
*/ */
typedef struct { typedef struct {
volatile int readindex; SpaRingbuffer ringbuffer;
volatile int writeindex;
int size;
int size_mask;
} SpaMetaRingbuffer; } SpaMetaRingbuffer;
/** /**

View file

@ -57,8 +57,6 @@ struct _SpaIDMap {
#define spa_id_map_get_id(n,...) (n)->get_id((n),__VA_ARGS__) #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__) #define spa_id_map_get_uri(n,...) (n)->get_uri((n),__VA_ARGS__)
SpaIDMap * spa_id_map_get_default (void);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

View file

@ -70,6 +70,15 @@ typedef struct {
SpaMetaType type; SpaMetaType type;
} SpaAllocParamMetaEnable; } SpaAllocParamMetaEnable;
typedef struct {
SpaAllocParam param;
SpaMetaType type;
size_t minsize;
size_t stride;
size_t blocks;
uint32_t align;
} SpaAllocParamMetaEnableRingbuffer;
typedef struct { typedef struct {
SpaAllocParam param; SpaAllocParam param;
unsigned int padding_top; unsigned int padding_top;

View file

@ -197,44 +197,6 @@ spa_props_index_for_name (const SpaProps *props, const char *name)
return SPA_IDX_INVALID; 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 #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

View file

@ -24,6 +24,7 @@
#include <spa/audio/raw.h> #include <spa/audio/raw.h>
#include <spa/audio/format.h> #include <spa/audio/format.h>
#include <lib/props.h>
static const uint32_t format_values[] = { static const uint32_t format_values[] = {
SPA_AUDIO_FORMAT_S8, SPA_AUDIO_FORMAT_S8,

View file

@ -19,9 +19,8 @@
#include <stdio.h> #include <stdio.h>
#include "spa/debug.h" #include "debug.h"
#include "spa/props.h" #include "props.h"
#include "spa/format.h"
struct meta_type_name { struct meta_type_name {
const char *name; const char *name;
@ -83,6 +82,19 @@ spa_debug_port_info (const SpaPortInfo *info)
SpaAllocParamMetaEnable *p = (SpaAllocParamMetaEnable *)param; SpaAllocParamMetaEnable *p = (SpaAllocParamMetaEnable *)param;
fprintf (stderr, " SpaAllocParamMetaEnable:\n"); fprintf (stderr, " SpaAllocParamMetaEnable:\n");
fprintf (stderr, " type: \t%d (%s)\n", p->type, META_TYPE_NAME(p->type)); 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; break;
} }
case SPA_ALLOC_PARAM_TYPE_VIDEO_PADDING: case SPA_ALLOC_PARAM_TYPE_VIDEO_PADDING:
@ -153,10 +165,11 @@ spa_debug_buffer (const SpaBuffer *buffer)
{ {
SpaMetaRingbuffer *h = m->data; SpaMetaRingbuffer *h = m->data;
fprintf (stderr, " SpaMetaRingbuffer:\n"); fprintf (stderr, " SpaMetaRingbuffer:\n");
fprintf (stderr, " readindex: %d\n", h->readindex); fprintf (stderr, " readindex: %zd\n", h->ringbuffer.readindex);
fprintf (stderr, " writeindex: %d\n", h->writeindex); fprintf (stderr, " writeindex: %zd\n", h->ringbuffer.writeindex);
fprintf (stderr, " size: %d\n", h->size); fprintf (stderr, " size: %zd\n", h->ringbuffer.size);
fprintf (stderr, " size_mask: %d\n", h->size_mask); fprintf (stderr, " mask: %zd\n", h->ringbuffer.mask);
fprintf (stderr, " mask2: %zd\n", h->ringbuffer.mask2);
break; break;
} }
default: default:

View file

@ -17,8 +17,8 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef __SPA_DEBUG_H__ #ifndef __SPA_LIBDEBUG_H__
#define __SPA_DEBUG_H__ #define __SPA_LIBDEBUG_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -43,4 +43,4 @@ SpaResult spa_debug_dict (const SpaDict *dict);
#endif #endif
#endif /* __SPA_DEBUG_H__ */ #endif /* __SPA_LIBDEBUG_H__ */

View file

@ -36,7 +36,8 @@
#include <spa/props.h> #include <spa/props.h>
#include <spa/queue.h> #include <spa/queue.h>
#include <spa/ringbuffer.h> #include <spa/ringbuffer.h>
#include <spa/debug.h>
#include <lib/debug.h>
#define MAX_URIS 4096 #define MAX_URIS 4096

35
spa/lib/mapper.h Normal file
View file

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

View file

@ -6,7 +6,7 @@ spalib_sources = ['audio-raw.c',
spalib = shared_library('spa-lib', spalib = shared_library('spa-lib',
spalib_sources, spalib_sources,
include_directories : spa_inc, include_directories : [ spa_inc, spa_libinc ],
install : true) install : true)
spalib_dep = declare_dependency(link_with : spalib, spalib_dep = declare_dependency(link_with : spalib,

71
spa/lib/props.h Normal file
View file

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

View file

@ -25,6 +25,8 @@
#include <spa/video/raw.h> #include <spa/video/raw.h>
#include <spa/video/format.h> #include <spa/video/format.h>
#include "props.h"
static const uint32_t format_values[] = { static const uint32_t format_values[] = {
SPA_VIDEO_FORMAT_UNKNOWN, SPA_VIDEO_FORMAT_UNKNOWN,
SPA_VIDEO_FORMAT_ENCODED, SPA_VIDEO_FORMAT_ENCODED,

View file

@ -17,6 +17,7 @@ dl_lib = cc.find_library('dl', required : true)
pthread_lib = cc.find_library('pthread', required : true) pthread_lib = cc.find_library('pthread', required : true)
spa_inc = include_directories('include') spa_inc = include_directories('include')
spa_libinc = include_directories('.')
subdir('include') subdir('include')
subdir('lib') subdir('lib')

View file

@ -31,7 +31,7 @@
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/poll.h> #include <spa/poll.h>
#include <spa/monitor.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_sink_factory;
extern const SpaHandleFactory spa_alsa_source_factory; extern const SpaHandleFactory spa_alsa_source_factory;
@ -100,7 +100,7 @@ path_get_card_id (const char *path)
return e + 5; 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 static int
fill_item (SpaALSAMonitor *this, ALSAItem *item, struct udev_device *udevice) 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_RESAMPLE |
SND_PCM_NO_AUTO_CHANNELS | SND_PCM_NO_AUTO_CHANNELS |
SND_PCM_NO_AUTO_FORMAT)) < 0) { 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, if ((err = snd_pcm_open (&hndl,
device, device,
SND_PCM_STREAM_CAPTURE, 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_RESAMPLE |
SND_PCM_NO_AUTO_CHANNELS | SND_PCM_NO_AUTO_CHANNELS |
SND_PCM_NO_AUTO_FORMAT)) < 0) { 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; return -1;
} else { } else {
item->item.factory = &spa_alsa_source_factory; item->item.factory = &spa_alsa_source_factory;

View file

@ -23,6 +23,7 @@
#include <spa/node.h> #include <spa/node.h>
#include <spa/audio/format.h> #include <spa/audio/format.h>
#include <lib/props.h>
#include "alsa-utils.h" #include "alsa-utils.h"
@ -47,7 +48,7 @@ reset_alsa_sink_props (SpaALSAProps *props)
static void static void
update_state (SpaALSASink *this, SpaNodeState state) 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; this->node.state = state;
} }
@ -367,6 +368,7 @@ spa_alsa_clear_buffers (SpaALSASink *this)
if (this->n_buffers > 0) { if (this->n_buffers > 0) {
SPA_QUEUE_INIT (&this->ready); SPA_QUEUE_INIT (&this->ready);
this->n_buffers = 0; this->n_buffers = 0;
this->ringbuffer = NULL;
} }
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -390,7 +392,7 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
if (format == NULL) { 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_pause (this, false);
spa_alsa_clear_buffers (this); spa_alsa_clear_buffers (this);
spa_alsa_close (this); spa_alsa_close (this);
@ -409,7 +411,7 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
SPA_PORT_INFO_FLAG_LIVE; SPA_PORT_INFO_FLAG_LIVE;
this->info.maxbuffering = this->buffer_frames * this->frame_size; this->info.maxbuffering = this->buffer_frames * this->frame_size;
this->info.latency = (this->period_frames * SPA_NSEC_PER_SEC) / this->rate; 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->info.params = this->params;
this->params[0] = &this->param_buffers.param; this->params[0] = &this->param_buffers.param;
this->param_buffers.param.type = SPA_ALLOC_PARAM_TYPE_BUFFERS; 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.type = SPA_ALLOC_PARAM_TYPE_META_ENABLE;
this->param_meta.param.size = sizeof (this->param_meta); this->param_meta.param.size = sizeof (this->param_meta);
this->param_meta.type = SPA_META_TYPE_HEADER; 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->info.extra = NULL;
this->have_format = true; this->have_format = true;
@ -512,7 +522,7 @@ spa_alsa_sink_node_port_use_buffers (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaALSASink, 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) if (!this->have_format)
return SPA_RESULT_NO_FORMAT; return SPA_RESULT_NO_FORMAT;
@ -530,13 +540,16 @@ spa_alsa_sink_node_port_use_buffers (SpaNode *node,
b->outstanding = true; b->outstanding = true;
b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER); 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) { switch (buffers[i]->datas[0].type) {
case SPA_DATA_TYPE_MEMFD: case SPA_DATA_TYPE_MEMFD:
case SPA_DATA_TYPE_DMABUF: case SPA_DATA_TYPE_DMABUF:
case SPA_DATA_TYPE_MEMPTR: case SPA_DATA_TYPE_MEMPTR:
if (buffers[i]->datas[0].data == NULL) { 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; continue;
} }
break; break;
@ -637,9 +650,14 @@ spa_alsa_sink_node_port_push_input (SpaNode *node,
have_error = true; have_error = true;
continue; 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->outstanding = false;
b->next = NULL;
SPA_QUEUE_PUSH_TAIL (&this->ready, SpaALSABuffer, next, b);
info[i].status = SPA_RESULT_OK; info[i].status = SPA_RESULT_OK;
} }
if (have_error) if (have_error)

View file

@ -24,6 +24,7 @@
#include <spa/node.h> #include <spa/node.h>
#include <spa/queue.h> #include <spa/queue.h>
#include <spa/audio/format.h> #include <spa/audio/format.h>
#include <lib/props.h>
#include "alsa-utils.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_DMABUF:
case SPA_DATA_TYPE_MEMPTR: case SPA_DATA_TYPE_MEMPTR:
if (buffers[i]->datas[0].data == NULL) { 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; continue;
} }
break; break;
@ -697,7 +698,7 @@ spa_alsa_source_node_port_pull_output (SpaNode *node,
info[i].buffer_id = b->outbuf->id; info[i].buffer_id = b->outbuf->id;
info[i].status = SPA_RESULT_OK; 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) if (have_error)
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
@ -727,7 +728,7 @@ spa_alsa_source_node_port_reuse_buffer (SpaNode *node,
if (buffer_id >= this->n_buffers) if (buffer_id >= this->n_buffers)
return SPA_RESULT_INVALID_BUFFER_ID; 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); recycle_buffer (this, buffer_id);
return SPA_RESULT_OK; return SPA_RESULT_OK;

View file

@ -7,9 +7,10 @@
#include <sys/time.h> #include <sys/time.h>
#include <math.h> #include <math.h>
#include <lib/debug.h>
#include "alsa-utils.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); 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"); 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, CHECK (snd_pcm_open (&state->hndl,
props->device, props->device,
state->stream, state->stream,
@ -59,7 +60,7 @@ spa_alsa_close (SpaALSAState *state)
spa_poll_remove_item (state->data_loop, &state->poll); 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"); CHECK (snd_pcm_close (state->hndl), "close failed");
state->opened = false; state->opened = false;
@ -147,14 +148,14 @@ spa_alsa_set_format (SpaALSAState *state, SpaFormatAudio *fmt, SpaPortFormatFlag
/* set the sample format */ /* set the sample format */
format = spa_alsa_format_to_alsa (info->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"); CHECK (snd_pcm_hw_params_set_format (hndl, params, format), "set_format");
/* set the count of channels */ /* set the count of channels */
rchannels = info->channels; rchannels = info->channels;
CHECK (snd_pcm_hw_params_set_channels_near (hndl, params, &rchannels), "set_channels"); CHECK (snd_pcm_hw_params_set_channels_near (hndl, params, &rchannels), "set_channels");
if (rchannels != info->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) if (flags & SPA_PORT_FORMAT_FLAG_NEAREST)
info->channels = rchannels; info->channels = rchannels;
else else
@ -165,7 +166,7 @@ spa_alsa_set_format (SpaALSAState *state, SpaFormatAudio *fmt, SpaPortFormatFlag
rrate = info->rate; rrate = info->rate;
CHECK (snd_pcm_hw_params_set_rate_near (hndl, params, &rrate, 0), "set_rate_near"); CHECK (snd_pcm_hw_params_set_rate_near (hndl, params, &rrate, 0), "set_rate_near");
if (rrate != info->rate) { 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) if (flags & SPA_PORT_FORMAT_FLAG_NEAREST)
info->rate = rrate; info->rate = rrate;
else 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"); CHECK (snd_pcm_hw_params_get_period_size (params, &size, &dir), "get_period_size");
state->period_frames = 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 */ /* write the parameters to device */
CHECK (snd_pcm_hw_params (hndl, params), "set_hw_params"); 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"); 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: */ /* start the transfer */
/* (buffer_frames / avail_min) * avail_min */ CHECK (snd_pcm_sw_params_set_start_threshold (hndl, params, 0U), "set_start_threshold");
CHECK (snd_pcm_sw_params_set_start_threshold (hndl, params, CHECK (snd_pcm_sw_params_set_stop_threshold (hndl, params,
(state->buffer_frames / state->period_frames) * state->period_frames), "set_start_threshold"); (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 */ /* 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) */ /* 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); snd_pcm_status_alloca (&status);
if ((err = snd_pcm_status (hndl, status)) < 0) { 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) { 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) { 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) { 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) 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; 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 static int
mmap_write (SpaALSAState *state) mmap_write (SpaALSAState *state)
{ {
@ -270,71 +368,42 @@ mmap_write (SpaALSAState *state)
snd_pcm_sframes_t avail; snd_pcm_sframes_t avail;
snd_pcm_uframes_t offset, frames, size; snd_pcm_uframes_t offset, frames, size;
const snd_pcm_channel_area_t *my_areas; const snd_pcm_channel_area_t *my_areas;
SpaNodeEventNeedInput ni;
SpaALSABuffer *b;
snd_pcm_status_t *status; snd_pcm_status_t *status;
SpaNodeEventNeedInput ni;
snd_pcm_status_alloca (&status); snd_pcm_status_alloca (&status);
if ((err = snd_pcm_status (hndl, status)) < 0) { 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; return -1;
} }
avail = snd_pcm_status_get_avail (status); 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; size = avail;
while (size > 0) { while (size > 0) {
frames = size; frames = size;
if ((err = snd_pcm_mmap_begin (hndl, &my_areas, &offset, &frames)) < 0) { 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; return -1;
} }
ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT; if (state->ringbuffer)
ni.event.size = sizeof (ni); frames = pull_frames_ringbuffer (state, my_areas, offset, frames);
ni.port_id = 0; else
state->event_cb (&state->node, &ni.event, state->user_data); frames = pull_frames_queue (state, my_areas, offset, frames);
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 ((err = snd_pcm_mmap_commit (hndl, offset, frames)) < 0) { 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) if (err != -EPIPE && err != -ESTRPIPE)
return -1; return -1;
} }
spa_log_debug (state->log, "write %zd/%zd/%zd %u", frames, size, avail, state->ready.length);
size -= frames; size -= frames;
} }
return 0; return 0;
@ -358,7 +427,7 @@ mmap_read (SpaALSAState *state)
snd_pcm_status_alloca(&status); snd_pcm_status_alloca(&status);
if ((err = snd_pcm_status (hndl, status)) < 0) { 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; return err;
} }
@ -371,7 +440,7 @@ mmap_read (SpaALSAState *state)
SPA_QUEUE_POP_HEAD (&state->free, SpaALSABuffer, next, b); SPA_QUEUE_POP_HEAD (&state->free, SpaALSABuffer, next, b);
if (b == NULL) { if (b == NULL) {
spa_log_warn (state->log, "no more buffers\n"); spa_log_warn (state->log, "no more buffers");
} else { } else {
dest = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void); dest = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void);
destsize = b->outbuf->datas[0].size; destsize = b->outbuf->datas[0].size;
@ -390,7 +459,7 @@ mmap_read (SpaALSAState *state)
while (size > 0) { while (size > 0) {
frames = size; frames = size;
if ((err = snd_pcm_mmap_begin (hndl, &my_areas, &offset, &frames)) < 0) { 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; return -1;
} }
@ -404,13 +473,12 @@ mmap_read (SpaALSAState *state)
} }
if ((err = snd_pcm_mmap_commit (hndl, offset, frames)) < 0) { 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; return -1;
} }
size -= frames; size -= frames;
} }
if (b) { if (b) {
SpaNodeEventHaveOutput ho; SpaNodeEventHaveOutput ho;
SpaData *d; SpaData *d;
@ -443,7 +511,7 @@ alsa_on_fd_events (SpaPollNotifyData *data)
&revents); &revents);
if (revents & POLLERR) { if (revents & POLLERR) {
if ((err = xrun_recovery (state, hndl, err)) < 0) { 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; return -1;
} }
} }
@ -476,16 +544,16 @@ spa_alsa_start (SpaALSAState *state, bool xrun_recover)
snd_pcm_dump (state->hndl, state->output); snd_pcm_dump (state->hndl, state->output);
if ((err = snd_pcm_prepare (state->hndl)) < 0) { 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; return SPA_RESULT_ERROR;
} }
if ((state->poll.n_fds = snd_pcm_poll_descriptors_count (state->hndl)) <= 0) { 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; return SPA_RESULT_ERROR;
} }
if ((err = snd_pcm_poll_descriptors (state->hndl, (struct pollfd *)state->fds, state->poll.n_fds)) < 0) { 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; return SPA_RESULT_ERROR;
} }
@ -499,7 +567,7 @@ spa_alsa_start (SpaALSAState *state, bool xrun_recover)
} }
if ((err = snd_pcm_start (state->hndl)) < 0) { 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; return SPA_RESULT_ERROR;
} }
@ -522,7 +590,7 @@ spa_alsa_pause (SpaALSAState *state, bool xrun_recover)
} }
if ((err = snd_pcm_drop (state->hndl)) < 0) 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; state->started = false;

View file

@ -32,6 +32,7 @@ extern "C" {
#include <spa/log.h> #include <spa/log.h>
#include <spa/queue.h> #include <spa/queue.h>
#include <spa/node.h> #include <spa/node.h>
#include <spa/ringbuffer.h>
#include <spa/audio/format.h> #include <spa/audio/format.h>
typedef struct _SpaALSAState SpaALSAState; typedef struct _SpaALSAState SpaALSAState;
@ -52,6 +53,7 @@ typedef struct {
struct _SpaALSABuffer { struct _SpaALSABuffer {
SpaBuffer *outbuf; SpaBuffer *outbuf;
SpaMetaHeader *h; SpaMetaHeader *h;
SpaMetaRingbuffer *rb;
bool outstanding; bool outstanding;
SpaALSABuffer *next; SpaALSABuffer *next;
}; };
@ -96,13 +98,16 @@ struct _SpaALSAState {
size_t frame_size; size_t frame_size;
SpaPortInfo info; SpaPortInfo info;
SpaAllocParam *params[2]; SpaAllocParam *params[3];
SpaAllocParamBuffers param_buffers; SpaAllocParamBuffers param_buffers;
SpaAllocParamMetaEnable param_meta; SpaAllocParamMetaEnable param_meta;
SpaAllocParamMetaEnableRingbuffer param_meta_rb;
SpaPortStatus status; SpaPortStatus status;
SpaALSABuffer buffers[MAX_BUFFERS]; SpaALSABuffer buffers[MAX_BUFFERS];
unsigned int n_buffers; unsigned int n_buffers;
bool use_ringbuffer;
SpaALSABuffer *ringbuffer;
SpaQueue free; SpaQueue free;
SpaQueue ready; SpaQueue ready;

View file

@ -6,7 +6,7 @@ spa_alsa_sources = ['alsa.c',
spa_alsa = shared_library('spa-alsa', spa_alsa = shared_library('spa-alsa',
spa_alsa_sources, spa_alsa_sources,
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc],
dependencies : [ alsa_dep, libudev_dep ], dependencies : [ alsa_dep, libudev_dep ],
link_with : spalib, link_with : spalib,
install : true, install : true,

View file

@ -24,6 +24,7 @@
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/node.h> #include <spa/node.h>
#include <spa/audio/format.h> #include <spa/audio/format.h>
#include <lib/props.h>
#define MAX_PORTS 128 #define MAX_PORTS 128
@ -700,7 +701,7 @@ spa_audiomixer_node_port_pull_output (SpaNode *node,
for (i = 0; i < n_info; i++) { for (i = 0; i < n_info; i++) {
if ((info[i].status = mix_data (this, &info[i])) < 0) { 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; have_error = true;
continue; continue;
} }

View file

@ -2,7 +2,7 @@ audiomixer_sources = ['audiomixer.c', 'plugin.c']
audiomixerlib = shared_library('spa-audiomixer', audiomixerlib = shared_library('spa-audiomixer',
audiomixer_sources, audiomixer_sources,
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc],
link_with : spalib, link_with : spalib,
install : true, install : true,
install_dir : '@0@/spa'.format(get_option('libdir'))) install_dir : '@0@/spa'.format(get_option('libdir')))

View file

@ -29,6 +29,7 @@
#include <spa/node.h> #include <spa/node.h>
#include <spa/queue.h> #include <spa/queue.h>
#include <spa/audio/format.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 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) #define BYTES_TO_SAMPLES(this,b) ((b)/(this)->bpf)
@ -526,7 +527,7 @@ static SpaResult
clear_buffers (SpaAudioTestSrc *this) clear_buffers (SpaAudioTestSrc *this)
{ {
if (this->n_buffers > 0) { 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; this->n_buffers = 0;
SPA_QUEUE_INIT (&this->empty); SPA_QUEUE_INIT (&this->empty);
SPA_QUEUE_INIT (&this->ready); 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_MEMFD:
case SPA_DATA_TYPE_DMABUF: case SPA_DATA_TYPE_DMABUF:
if (d[0].data == NULL) { 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; continue;
} }
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void); b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);

View file

@ -2,7 +2,7 @@ audiotestsrc_sources = ['audiotestsrc.c', 'plugin.c']
audiotestsrclib = shared_library('spa-audiotestsrc', audiotestsrclib = shared_library('spa-audiotestsrc',
audiotestsrc_sources, audiotestsrc_sources,
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc],
link_with : spalib, link_with : spalib,
install : true, install : true,
install_dir : '@0@/spa'.format(get_option('libdir'))) install_dir : '@0@/spa'.format(get_option('libdir')))

View file

@ -26,6 +26,7 @@
#include <spa/log.h> #include <spa/log.h>
#include <spa/node.h> #include <spa/node.h>
#include <spa/video/format.h> #include <spa/video/format.h>
#include <lib/props.h>
typedef struct _SpaFFMpegDec SpaFFMpegDec; typedef struct _SpaFFMpegDec SpaFFMpegDec;

View file

@ -26,6 +26,7 @@
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/node.h> #include <spa/node.h>
#include <spa/video/format.h> #include <spa/video/format.h>
#include <lib/props.h>
typedef struct _SpaFFMpegEnc SpaFFMpegEnc; typedef struct _SpaFFMpegEnc SpaFFMpegEnc;

View file

@ -4,7 +4,7 @@ ffmpeg_sources = ['ffmpeg.c',
ffmpeglib = shared_library('spa-ffmpeg', ffmpeglib = shared_library('spa-ffmpeg',
ffmpeg_sources, ffmpeg_sources,
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc],
dependencies : [ avcodec_dep, avformat_dep ], dependencies : [ avcodec_dep, avformat_dep ],
link_with : spalib, link_with : spalib,
install : true, install : true,

View file

@ -4,7 +4,7 @@ v4l2_sources = ['v4l2.c',
v4l2lib = shared_library('spa-v4l2', v4l2lib = shared_library('spa-v4l2',
v4l2_sources, v4l2_sources,
include_directories : spa_inc, include_directories : [ spa_inc, spa_libinc ],
dependencies : [ v4l2_dep, libudev_dep ], dependencies : [ v4l2_dep, libudev_dep ],
link_with : spalib, link_with : spalib,
install : true, install : true,

View file

@ -30,7 +30,7 @@
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/poll.h> #include <spa/poll.h>
#include <spa/monitor.h> #include <spa/monitor.h>
#include <spa/debug.h> #include <lib/debug.h>
extern const SpaHandleFactory spa_v4l2_source_factory; extern const SpaHandleFactory spa_v4l2_source_factory;

View file

@ -26,10 +26,11 @@
#include <spa/node.h> #include <spa/node.h>
#include <spa/video/format.h> #include <spa/video/format.h>
#include <spa/debug.h>
#include <spa/queue.h> #include <spa/queue.h>
#include <spa/log.h> #include <spa/log.h>
#include <spa/id-map.h> #include <spa/id-map.h>
#include <lib/debug.h>
#include <lib/props.h>
typedef struct _SpaV4l2Source SpaV4l2Source; typedef struct _SpaV4l2Source SpaV4l2Source;
@ -150,7 +151,7 @@ struct _SpaV4l2Source {
static void static void
update_state (SpaV4l2Source *this, SpaNodeState state) 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; this->node.state = state;
} }
#include "v4l2-utils.c" #include "v4l2-utils.c"

View file

@ -34,27 +34,27 @@ spa_v4l2_open (SpaV4l2Source *this)
return 0; return 0;
if (props->props.unset_mask & 1) { 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; 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) { 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)); props->device, errno, strerror (errno));
return -1; return -1;
} }
if (!S_ISCHR (st.st_mode)) { 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; return -1;
} }
state->fd = open (props->device, O_RDWR | O_NONBLOCK, 0); state->fd = open (props->device, O_RDWR | O_NONBLOCK, 0);
if (state->fd == -1) { 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)); props->device, errno, strerror (errno));
return -1; return -1;
} }
@ -65,7 +65,7 @@ spa_v4l2_open (SpaV4l2Source *this)
} }
if ((state->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) { 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; return -1;
} }
@ -120,7 +120,7 @@ spa_v4l2_clear_buffers (SpaV4l2Source *this)
b = &state->buffers[i]; b = &state->buffers[i];
if (b->outstanding) { 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); spa_v4l2_buffer_recycle (this, i);
} }
if (b->allocated) { if (b->allocated) {
@ -156,7 +156,7 @@ spa_v4l2_close (SpaV4l2Source *this)
if (state->n_buffers > 0) if (state->n_buffers > 0)
return 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); 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, f->format,
0); 0);
if (info == NULL) { 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); f->fmt.media_subtype, f->format);
return -1; 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.numerator = f->framerate.denom;
streamparm.parm.capture.timeperframe.denominator = f->framerate.num; 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, fmt.fmt.pix.width, fmt.fmt.pix.height,
streamparm.parm.capture.timeperframe.numerator, streamparm.parm.capture.timeperframe.numerator,
streamparm.parm.capture.timeperframe.denominator); 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) if (xioctl (state->fd, VIDIOC_S_PARM, &streamparm) < 0)
perror ("VIDIOC_S_PARM"); 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, fmt.fmt.pix.width, fmt.fmt.pix.height,
streamparm.parm.capture.timeperframe.numerator, streamparm.parm.capture.timeperframe.numerator,
streamparm.parm.capture.timeperframe.denominator); 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; state->memtype = V4L2_MEMORY_DMABUF;
break; break;
default: 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; return SPA_RESULT_ERROR;
} }
} }
@ -946,9 +946,9 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
perror ("VIDIOC_REQBUFS"); perror ("VIDIOC_REQBUFS");
return SPA_RESULT_ERROR; 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) { 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; return SPA_RESULT_ERROR;
} }
@ -961,10 +961,10 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
b->allocated = false; b->allocated = false;
b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER); 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) { 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; continue;
} }
d = buffers[i]->datas; 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_MEMPTR:
case SPA_DATA_TYPE_MEMFD: case SPA_DATA_TYPE_MEMFD:
if (d[0].data == NULL) { 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; continue;
} }
b->v4l2_buffer.m.userptr = (unsigned long) SPA_MEMBER (d[0].data, d[0].offset, void *); 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; 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; *n_buffers = reqbuf.count;
if (reqbuf.count < 2) { 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; return SPA_RESULT_ERROR;
} }
if (state->export_buf) 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++) { for (i = 0; i < reqbuf.count; i++) {
V4l2Buffer *b; V4l2Buffer *b;
SpaData *d; SpaData *d;
if (buffers[i]->n_datas < 1) { 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; return SPA_RESULT_ERROR;
} }

View file

@ -2,7 +2,7 @@ videotestsrc_sources = ['videotestsrc.c', 'plugin.c']
videotestsrclib = shared_library('spa-videotestsrc', videotestsrclib = shared_library('spa-videotestsrc',
videotestsrc_sources, videotestsrc_sources,
include_directories : spa_inc, include_directories : [ spa_inc, spa_libinc],
dependencies : threads_dep, dependencies : threads_dep,
link_with : spalib, link_with : spalib,
install : true, install : true,

View file

@ -30,6 +30,7 @@
#include <spa/node.h> #include <spa/node.h>
#include <spa/queue.h> #include <spa/queue.h>
#include <spa/video/format.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) / \ #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)) (this->current_format.info.raw.framerate.denom))
@ -474,7 +475,7 @@ static SpaResult
clear_buffers (SpaVideoTestSrc *this) clear_buffers (SpaVideoTestSrc *this)
{ {
if (this->n_buffers > 0) { 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; this->n_buffers = 0;
SPA_QUEUE_INIT (&this->empty); SPA_QUEUE_INIT (&this->empty);
SPA_QUEUE_INIT (&this->ready); 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_MEMFD:
case SPA_DATA_TYPE_DMABUF: case SPA_DATA_TYPE_DMABUF:
if (d[0].data == NULL) { 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; continue;
} }
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void); b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);

View file

@ -2,7 +2,7 @@ volume_sources = ['volume.c', 'plugin.c']
volumelib = shared_library('spa-volume', volumelib = shared_library('spa-volume',
volume_sources, volume_sources,
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc],
link_with : spalib, link_with : spalib,
install : true, install : true,
install_dir : '@0@/spa'.format(get_option('libdir'))) install_dir : '@0@/spa'.format(get_option('libdir')))

View file

@ -24,6 +24,7 @@
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/node.h> #include <spa/node.h>
#include <spa/audio/format.h> #include <spa/audio/format.h>
#include <lib/props.h>
typedef struct _SpaVolume SpaVolume; typedef struct _SpaVolume SpaVolume;

View file

@ -3,7 +3,7 @@ xv_sources = ['xv.c',
xvlib = shared_library('spa-xv', xvlib = shared_library('spa-xv',
xv_sources, xv_sources,
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc],
dependencies : xv_dep, dependencies : xv_dep,
link_with : spalib, link_with : spalib,
install : true, install : true,

View file

@ -28,6 +28,7 @@
#include <spa/log.h> #include <spa/log.h>
#include <spa/node.h> #include <spa/node.h>
#include <spa/video/format.h> #include <spa/video/format.h>
#include <lib/props.h>
typedef struct _SpaXvSink SpaXvSink; typedef struct _SpaXvSink SpaXvSink;

View file

@ -1,11 +1,11 @@
executable('test-mixer', 'test-mixer.c', executable('test-mixer', 'test-mixer.c',
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc ],
dependencies : [dl_lib, pthread_lib], dependencies : [dl_lib, pthread_lib],
link_with : spalib, link_with : spalib,
install : false) install : false)
executable('test-v4l2', 'test-v4l2.c', executable('test-v4l2', 'test-v4l2.c',
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc ],
dependencies : [dl_lib, sdl_dep, pthread_lib], dependencies : [dl_lib, sdl_dep, pthread_lib],
link_with : spalib, link_with : spalib,
install : false) install : false)

View file

@ -30,6 +30,8 @@
#include <spa/log.h> #include <spa/log.h>
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/audio/format.h> #include <spa/audio/format.h>
#include <lib/mapper.h>
#include <lib/props.h>
typedef struct { typedef struct {
uint32_t node; uint32_t node;

View file

@ -31,8 +31,10 @@
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/log.h> #include <spa/log.h>
#include <spa/node.h> #include <spa/node.h>
#include <spa/debug.h>
#include <spa/video/format.h> #include <spa/video/format.h>
#include <lib/debug.h>
#include <lib/props.h>
#include <lib/mapper.h>
#define MAX_BUFFERS 8 #define MAX_BUFFERS 8

View file

@ -1,11 +1,11 @@
executable('spa-inspect', 'spa-inspect.c', executable('spa-inspect', 'spa-inspect.c',
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc],
dependencies : [dl_lib], dependencies : [dl_lib],
link_with : spalib, link_with : spalib,
install : true) install : true)
executable('spa-monitor', 'spa-monitor.c', executable('spa-monitor', 'spa-monitor.c',
include_directories : spa_inc, include_directories : [spa_inc, spa_libinc],
dependencies : [dl_lib], dependencies : [dl_lib],
link_with : spalib, link_with : spalib,
install : true) install : true)

View file

@ -26,7 +26,8 @@
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/log.h> #include <spa/log.h>
#include <spa/node.h> #include <spa/node.h>
#include <spa/debug.h> #include <lib/debug.h>
#include <lib/mapper.h>
typedef struct { typedef struct {
uint32_t node; uint32_t node;

View file

@ -29,7 +29,8 @@
#include <spa/id-map.h> #include <spa/id-map.h>
#include <spa/monitor.h> #include <spa/monitor.h>
#include <spa/poll.h> #include <spa/poll.h>
#include <spa/debug.h> #include <lib/debug.h>
#include <lib/mapper.h>
typedef struct { typedef struct {
uint32_t monitor; uint32_t monitor;