Rework transport protocol

Use a more simple tranport protocol for the realtime data. Use a piece
of shared memory and a socket where we use a 1byte read/write to trigger
remote actions. Also use a ringbuffer for events.
This commit is contained in:
Wim Taymans 2016-11-07 10:24:13 +01:00
parent 7e46f9e3ad
commit b774b99db5
22 changed files with 797 additions and 364 deletions

View file

@ -26,8 +26,6 @@ extern "C" {
typedef struct _PinosArray PinosArray; typedef struct _PinosArray PinosArray;
#include <string.h>
#include <spa/defs.h> #include <spa/defs.h>
struct _PinosArray { struct _PinosArray {
@ -52,7 +50,8 @@ struct _PinosArray {
static inline void static inline void
pinos_array_init (PinosArray *arr) pinos_array_init (PinosArray *arr)
{ {
memset (arr, 0, sizeof (PinosArray)); arr->data = NULL;
arr->size = arr->alloc = 0;
} }
static inline void static inline void

View file

@ -630,6 +630,12 @@ pinos_connection_parse_message (PinosConnection *conn,
connection_parse_port_command (conn, message); connection_parse_port_command (conn, message);
break; break;
case PINOS_MESSAGE_TRANSPORT_UPDATE:
if (conn->in.size < sizeof (PinosMessageTransportUpdate))
return false;
memcpy (message, conn->in.data, sizeof (PinosMessageTransportUpdate));
break;
case PINOS_MESSAGE_INVALID: case PINOS_MESSAGE_INVALID:
return false; return false;
} }
@ -781,6 +787,11 @@ pinos_connection_add_message (PinosConnection *conn,
connection_add_port_command (conn, message); connection_add_port_command (conn, message);
break; break;
case PINOS_MESSAGE_TRANSPORT_UPDATE:
p = connection_add_message (conn, type, sizeof (PinosMessageTransportUpdate));
memcpy (p, message, sizeof (PinosMessageTransportUpdate));
break;
case PINOS_MESSAGE_INVALID: case PINOS_MESSAGE_INVALID:
return false; return false;
} }

View file

@ -43,18 +43,21 @@ typedef enum {
PINOS_MESSAGE_NODE_EVENT = 5, PINOS_MESSAGE_NODE_EVENT = 5,
/* server to client */ /* server to client */
PINOS_MESSAGE_ADD_PORT = 32, PINOS_MESSAGE_TRANSPORT_UPDATE = 32,
PINOS_MESSAGE_REMOVE_PORT = 33,
PINOS_MESSAGE_SET_FORMAT = 34, PINOS_MESSAGE_ADD_PORT = 33,
PINOS_MESSAGE_SET_PROPERTY = 35, PINOS_MESSAGE_REMOVE_PORT = 34,
PINOS_MESSAGE_NODE_COMMAND = 36, PINOS_MESSAGE_SET_FORMAT = 35,
PINOS_MESSAGE_PORT_COMMAND = 37, PINOS_MESSAGE_SET_PROPERTY = 36,
PINOS_MESSAGE_NODE_COMMAND = 37,
PINOS_MESSAGE_PORT_COMMAND = 38,
/* both */ /* both */
PINOS_MESSAGE_ADD_MEM = 64, PINOS_MESSAGE_ADD_MEM = 64,
PINOS_MESSAGE_USE_BUFFERS = 66, PINOS_MESSAGE_USE_BUFFERS = 66,
PINOS_MESSAGE_PROCESS_BUFFER = 67, PINOS_MESSAGE_PROCESS_BUFFER = 67,
} PinosMessageType; } PinosMessageType;
@ -142,6 +145,13 @@ typedef struct {
SpaNodeCommand *command; SpaNodeCommand *command;
} PinosMessagePortCommand; } PinosMessagePortCommand;
/* PINOS_MESSAGE_TRANSPORT_UPDATE */
typedef struct {
unsigned int memfd_index;
off_t offset;
size_t size;
} PinosMessageTransportUpdate;
/* PINOS_MESSAGE_ADD_MEM */ /* PINOS_MESSAGE_ADD_MEM */
typedef struct { typedef struct {
SpaDirection direction; SpaDirection direction;

View file

@ -21,6 +21,8 @@
#include <pinos/client/log.h> #include <pinos/client/log.h>
SpaLogLevel pinos_log_level = SPA_LOG_LEVEL_DEBUG;
static void static void
do_logv (SpaLog *log, do_logv (SpaLog *log,
SpaLogLevel level, SpaLogLevel level,

View file

@ -26,6 +26,8 @@
extern "C" { extern "C" {
#endif #endif
extern SpaLogLevel pinos_log_level;
SpaLog * pinos_log_get (void); SpaLog * pinos_log_get (void);
@ -43,21 +45,27 @@ void pinos_log_logv (SpaLogLevel level,
#if __STDC_VERSION__ >= 199901L #if __STDC_VERSION__ >= 199901L
#define pinos_log_error(...) pinos_log_log(SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__) #define pinos_log_logc(lev,...) \
#define pinos_log_warn(...) pinos_log_log(SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__) if (SPA_UNLIKELY (lev >= pinos_log_level)) \
#define pinos_log_info(...) pinos_log_log(SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__) pinos_log_log(lev,__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__) #define pinos_log_error(...) pinos_log_logc(SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define pinos_log_warn(...) pinos_log_logc(SPA_LOG_LEVEL_WARN,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define pinos_log_info(...) pinos_log_logc(SPA_LOG_LEVEL_INFO,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define pinos_log_debug(...) pinos_log_logc(SPA_LOG_LEVEL_DEBUG,__FILE__,__LINE__,__func__,__VA_ARGS__)
#define pinos_log_trace(...) pinos_log_logc(SPA_LOG_LEVEL_TRACE,__FILE__,__LINE__,__func__,__VA_ARGS__)
#else #else
#define PINOS_LOG_FUNC(name,lev) \ #define PINOS_LOG_FUNC(name,lev) \
static inline void pinos_log_##name (const char *format, ...) \ static inline void pinos_log_##name (const char *format, ...) \
{ \ { \
va_list varargs; \ if (lev >= pinos_log_level) { \
va_start (varargs, format); \ va_list varargs; \
pinos_log_logv (lev,__FILE__,__LINE__,__func__,format,varargs); \ va_start (varargs, format); \
va_end (varargs); \ pinos_log_logv (lev,__FILE__,__LINE__,__func__,format,varargs); \
va_end (varargs); \
} \
} }
PINOS_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR) PINOS_LOG_FUNC(error, SPA_LOG_LEVEL_ERROR)
PINOS_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN) PINOS_LOG_FUNC(warn, SPA_LOG_LEVEL_WARN)

View file

@ -25,21 +25,59 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/syscall.h>
#include "memfd-wrappers.h"
#include <pinos/client/log.h> #include <pinos/client/log.h>
#include <pinos/server/utils.h> #include <pinos/client/mem.h>
/*
* No glibc wrappers exist for memfd_create(2), so provide our own.
*
* Also define memfd fcntl sealing macros. While they are already
* defined in the kernel header file <linux/fcntl.h>, that file as
* a whole conflicts with the original glibc header <fnctl.h>.
*/
static inline int memfd_create(const char *name, unsigned int flags) {
return syscall(SYS_memfd_create, name, flags);
}
/* memfd_create(2) flags */
#ifndef MFD_CLOEXEC
#define MFD_CLOEXEC 0x0001U
#endif
#ifndef MFD_ALLOW_SEALING
#define MFD_ALLOW_SEALING 0x0002U
#endif
/* fcntl() seals-related flags */
#ifndef F_LINUX_SPECIFIC_BASE
#define F_LINUX_SPECIFIC_BASE 1024
#endif
#ifndef F_ADD_SEALS
#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
#define F_SEAL_GROW 0x0004 /* prevent file from growing */
#define F_SEAL_WRITE 0x0008 /* prevent writes */
#endif
#undef USE_MEMFD #undef USE_MEMFD
gboolean SpaResult
pinos_memblock_alloc (PinosMemblockFlags flags, pinos_memblock_alloc (PinosMemblockFlags flags,
gsize size, size_t size,
PinosMemblock *mem) PinosMemblock *mem)
{ {
g_return_val_if_fail (mem != NULL, FALSE); if (mem == NULL || size == 0)
g_return_val_if_fail (size > 0, FALSE); return SPA_RESULT_INVALID_ARGUMENTS;
mem->flags = flags; mem->flags = flags;
mem->size = size; mem->size = size;
@ -49,14 +87,14 @@ pinos_memblock_alloc (PinosMemblockFlags flags,
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) {
pinos_log_error ("Failed to create memfd: %s\n", strerror (errno)); pinos_log_error ("Failed to create memfd: %s\n", strerror (errno));
return FALSE; return SPA_RESULT_ERROR;
} }
#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) {
pinos_log_error ("Failed to create temporary file: %s\n", strerror (errno)); pinos_log_error ("Failed to create temporary file: %s\n", strerror (errno));
return FALSE; return SPA_RESULT_ERROR;
} }
unlink (filename); unlink (filename);
#endif #endif
@ -64,7 +102,7 @@ pinos_memblock_alloc (PinosMemblockFlags flags,
if (ftruncate (mem->fd, size) < 0) { if (ftruncate (mem->fd, size) < 0) {
pinos_log_warn ("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 SPA_RESULT_ERROR;
} }
#ifdef USE_MEMFD #ifdef USE_MEMFD
if (flags & PINOS_MEMBLOCK_FLAG_SEAL) { if (flags & PINOS_MEMBLOCK_FLAG_SEAL) {
@ -87,16 +125,17 @@ pinos_memblock_alloc (PinosMemblockFlags flags,
mem->ptr = NULL; mem->ptr = NULL;
} }
} else { } else {
mem->ptr = g_malloc (size); mem->ptr = malloc (size);
mem->fd = -1; mem->fd = -1;
} }
return TRUE; return SPA_RESULT_OK;
} }
void void
pinos_memblock_free (PinosMemblock *mem) pinos_memblock_free (PinosMemblock *mem)
{ {
g_return_if_fail (mem != NULL); if (mem == NULL)
return;
if (mem->flags & PINOS_MEMBLOCK_FLAG_WITH_FD) { if (mem->flags & PINOS_MEMBLOCK_FLAG_WITH_FD) {
if (mem->ptr) if (mem->ptr)
@ -104,7 +143,7 @@ pinos_memblock_free (PinosMemblock *mem)
if (mem->fd != -1) if (mem->fd != -1)
close (mem->fd); close (mem->fd);
} else { } else {
g_free (mem->ptr); free (mem->ptr);
} }
mem->ptr = NULL; mem->ptr = NULL;
mem->fd = -1; mem->fd = -1;

View file

@ -17,12 +17,14 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef __PINOS_UTILS_H__ #ifndef __PINOS_MEM_H__
#define __PINOS_UTILS_H__ #define __PINOS_MEM_H__
#include <glib-object.h> #include <spa/defs.h>
G_BEGIN_DECLS #ifdef __cplusplus
extern "C" {
#endif
typedef struct _PinosMemblock PinosMemblock; typedef struct _PinosMemblock PinosMemblock;
@ -39,15 +41,17 @@ typedef enum {
struct _PinosMemblock { struct _PinosMemblock {
PinosMemblockFlags flags; PinosMemblockFlags flags;
int fd; int fd;
gpointer *ptr; void *ptr;
gsize size; size_t size;
}; };
gboolean pinos_memblock_alloc (PinosMemblockFlags flags, SpaResult pinos_memblock_alloc (PinosMemblockFlags flags,
gsize size, size_t size,
PinosMemblock *mem); PinosMemblock *mem);
void pinos_memblock_free (PinosMemblock *mem); void pinos_memblock_free (PinosMemblock *mem);
G_END_DECLS #ifdef __cplusplus
}
#endif
#endif /* __PINOS_UTILS_H__ */ #endif /* __PINOS_MEM_H__ */

View file

@ -0,0 +1,59 @@
/* 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 <sys/syscall.h>
#include <fcntl.h>
/*
* No glibc wrappers exist for memfd_create(2), so provide our own.
*
* Also define memfd fcntl sealing macros. While they are already
* defined in the kernel header file <linux/fcntl.h>, that file as
* a whole conflicts with the original glibc header <fnctl.h>.
*/
static inline int memfd_create(const char *name, unsigned int flags) {
return syscall(SYS_memfd_create, name, flags);
}
/* memfd_create(2) flags */
#ifndef MFD_CLOEXEC
#define MFD_CLOEXEC 0x0001U
#endif
#ifndef MFD_ALLOW_SEALING
#define MFD_ALLOW_SEALING 0x0002U
#endif
/* fcntl() seals-related flags */
#ifndef F_LINUX_SPECIFIC_BASE
#define F_LINUX_SPECIFIC_BASE 1024
#endif
#ifndef F_ADD_SEALS
#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
#define F_SEAL_GROW 0x0004 /* prevent file from growing */
#define F_SEAL_WRITE 0x0008 /* prevent writes */
#endif

View file

@ -5,6 +5,7 @@ pinos_headers = [
'introspect.h', 'introspect.h',
'log.h', 'log.h',
'map.h', 'map.h',
'mem.h',
'pinos.h', 'pinos.h',
'properties.h', 'properties.h',
'ringbuffer.h', 'ringbuffer.h',
@ -12,6 +13,7 @@ pinos_headers = [
'stream.h', 'stream.h',
'subscribe.h', 'subscribe.h',
'thread-mainloop.h', 'thread-mainloop.h',
'transport.h',
] ]
pinos_sources = [ pinos_sources = [
@ -21,6 +23,7 @@ pinos_sources = [
'introspect.c', 'introspect.c',
'log.c', 'log.c',
'mapper.c', 'mapper.c',
'mem.c',
'properties.c', 'properties.c',
'serialize.c', 'serialize.c',
'stream.c', 'stream.c',
@ -29,6 +32,7 @@ pinos_sources = [
'rtkit.c', 'rtkit.c',
'subscribe.c', 'subscribe.c',
'thread-mainloop.c', 'thread-mainloop.c',
'transport.c',
gdbus_target, gdbus_target,
] ]

View file

@ -26,11 +26,13 @@ extern const char g_log_domain_pinos[];
#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/log.h>
#include <pinos/client/mem.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> #include <spa/include/spa/id-map.h>
#define PINOS_DBUS_SERVICE "org.pinos" #define PINOS_DBUS_SERVICE "org.pinos"

View file

@ -38,6 +38,7 @@
#include "pinos/client/format.h" #include "pinos/client/format.h"
#include "pinos/client/private.h" #include "pinos/client/private.h"
#include "pinos/client/serialize.h" #include "pinos/client/serialize.h"
#include "pinos/client/transport.h"
#define MAX_BUFFER_SIZE 4096 #define MAX_BUFFER_SIZE 4096
#define MAX_FDS 32 #define MAX_FDS 32
@ -90,12 +91,13 @@ struct _PinosStreamPrivate
GSocket *socket; GSocket *socket;
GSource *socket_source; GSource *socket_source;
int fd; int fd;
GSocket *rtsocket; GSocket *rtsocket;
GSource *rtsocket_source; GSource *rtsocket_source;
int rtfd; int rtfd;
PinosConnection *conn; PinosConnection *conn;
PinosConnection *rtconn; PinosTransport *trans;
GSource *timeout_source; GSource *timeout_source;
@ -662,21 +664,11 @@ add_port_update (PinosStream *stream, uint32_t change_mask)
pinos_connection_add_message (priv->conn, PINOS_MESSAGE_PORT_UPDATE, &pu); pinos_connection_add_message (priv->conn, PINOS_MESSAGE_PORT_UPDATE, &pu);
} }
static void static inline void
send_need_input (PinosStream *stream, uint32_t port_id) send_need_input (PinosStream *stream)
{ {
PinosStreamPrivate *priv = stream->priv; PinosStreamPrivate *priv = stream->priv;
PinosMessageNodeEvent cne; pinos_transport_write_cmd (priv->trans, PINOS_TRANSPORT_CMD_NEED_DATA);
SpaNodeEventNeedInput ni;
cne.event = &ni.event;
ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT;
ni.event.size = sizeof (ni);
ni.port_id = port_id;
pinos_connection_add_message (priv->rtconn, PINOS_MESSAGE_NODE_EVENT, &cne);
if (!pinos_connection_flush (priv->rtconn))
pinos_log_warn ("stream %p: error writing connection", stream);
} }
static void static void
@ -712,47 +704,6 @@ add_async_complete (PinosStream *stream,
pinos_connection_add_message (priv->conn, PINOS_MESSAGE_NODE_EVENT, &cne); pinos_connection_add_message (priv->conn, PINOS_MESSAGE_NODE_EVENT, &cne);
} }
static void
send_reuse_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id)
{
PinosStreamPrivate *priv = stream->priv;
PinosMessageNodeEvent cne;
SpaNodeEventReuseBuffer rb;
cne.event = &rb.event;
rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
rb.event.size = sizeof (rb);
rb.port_id = port_id;
rb.buffer_id = buffer_id;
pinos_connection_add_message (priv->rtconn, PINOS_MESSAGE_NODE_EVENT, &cne);
if (!pinos_connection_flush (priv->rtconn))
pinos_log_warn ("stream %p: error writing connection", stream);
}
static void
send_process_buffer (PinosStream *stream, uint32_t port_id, uint32_t buffer_id)
{
PinosStreamPrivate *priv = stream->priv;
PinosMessageProcessBuffer pb;
PinosMessageNodeEvent cne;
SpaNodeEventHaveOutput ho;
pb.direction = priv->direction;
pb.port_id = port_id;
pb.buffer_id = buffer_id;
pinos_connection_add_message (priv->rtconn, PINOS_MESSAGE_PROCESS_BUFFER, &pb);
cne.event = &ho.event;
ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
ho.event.size = sizeof (ho);
ho.port_id = port_id;
pinos_connection_add_message (priv->rtconn, PINOS_MESSAGE_NODE_EVENT, &cne);
if (!pinos_connection_flush (priv->rtconn))
pinos_log_warn ("stream %p: error writing connection", stream);
}
static void static void
do_node_init (PinosStream *stream) do_node_init (PinosStream *stream)
{ {
@ -822,47 +773,6 @@ handle_node_event (PinosStream *stream,
return TRUE; return TRUE;
} }
static gboolean
handle_rtnode_event (PinosStream *stream,
SpaNodeEvent *event)
{
PinosStreamPrivate *priv = stream->priv;
switch (event->type) {
case SPA_NODE_EVENT_TYPE_INVALID:
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
case SPA_NODE_EVENT_TYPE_ERROR:
case SPA_NODE_EVENT_TYPE_BUFFERING:
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE:
pinos_log_warn ("unexpected node event %d", event->type);
break;
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
pinos_log_warn ("unhandled node event %d", event->type);
break;
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
{
SpaNodeEventReuseBuffer *p = (SpaNodeEventReuseBuffer *) event;
BufferId *bid;
if (p->port_id != priv->port_id)
break;
if (priv->direction != SPA_DIRECTION_OUTPUT)
break;
if ((bid = find_buffer (stream, p->buffer_id))) {
bid->used = FALSE;
g_signal_emit (stream, signals[SIGNAL_NEW_BUFFER], 0, p->buffer_id);
}
break;
}
}
return TRUE;
}
static gboolean static gboolean
handle_node_command (PinosStream *stream, handle_node_command (PinosStream *stream,
uint32_t seq, uint32_t seq,
@ -896,7 +806,7 @@ handle_node_command (PinosStream *stream,
pinos_log_warn ("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);
stream_set_state (stream, PINOS_STREAM_STATE_STREAMING, NULL); stream_set_state (stream, PINOS_STREAM_STATE_STREAMING, NULL);
break; break;
@ -1145,6 +1055,29 @@ parse_connection (PinosStream *stream)
break; break;
} }
case PINOS_MESSAGE_TRANSPORT_UPDATE:
{
PinosMessageTransportUpdate p;
PinosTransportInfo info;
if (!pinos_connection_parse_message (conn, &p))
break;
info.memfd = pinos_connection_get_fd (conn, p.memfd_index, false);
if (info.memfd == -1)
break;
info.offset = p.offset;
info.size = p.size;
info.fd = priv->rtfd;
pinos_log_debug ("transport update %d %p", priv->rtfd, priv->trans);
if (priv->trans)
pinos_transport_free (priv->trans);
priv->trans = pinos_transport_new_from_info (&info);
break;
}
case PINOS_MESSAGE_INVALID: case PINOS_MESSAGE_INVALID:
pinos_log_warn ("unhandled message %d", type); pinos_log_warn ("unhandled message %d", type);
break; break;
@ -1153,73 +1086,6 @@ parse_connection (PinosStream *stream)
return TRUE; return TRUE;
} }
static gboolean
parse_rtconnection (PinosStream *stream)
{
PinosStreamPrivate *priv = stream->priv;
PinosConnection *conn = priv->rtconn;
while (pinos_connection_has_next (conn)) {
PinosMessageType type = pinos_connection_get_type (conn);
switch (type) {
case PINOS_MESSAGE_INVALID:
case PINOS_MESSAGE_NODE_UPDATE:
case PINOS_MESSAGE_PORT_UPDATE:
case PINOS_MESSAGE_PORT_STATUS_CHANGE:
case PINOS_MESSAGE_NODE_STATE_CHANGE:
case PINOS_MESSAGE_ADD_PORT:
case PINOS_MESSAGE_REMOVE_PORT:
case PINOS_MESSAGE_SET_FORMAT:
case PINOS_MESSAGE_SET_PROPERTY:
case PINOS_MESSAGE_ADD_MEM:
case PINOS_MESSAGE_USE_BUFFERS:
case PINOS_MESSAGE_NODE_COMMAND:
pinos_log_warn ("got unexpected command %d", type);
break;
case PINOS_MESSAGE_PROCESS_BUFFER:
{
PinosMessageProcessBuffer p;
guint i;
BufferId *bid;
if (priv->direction != SPA_DIRECTION_INPUT)
break;
if (!pinos_connection_parse_message (conn, &p))
break;
if ((bid = find_buffer (stream, p.buffer_id))) {
for (i = 0; i < bid->buf->n_datas; i++) {
bid->buf->datas[i].size = bid->datas[i].size;
}
g_signal_emit (stream, signals[SIGNAL_NEW_BUFFER], 0, p.buffer_id);
send_need_input (stream, priv->port_id);
}
break;
}
case PINOS_MESSAGE_NODE_EVENT:
{
PinosMessageNodeEvent p;
if (!pinos_connection_parse_message (conn, &p))
break;
handle_rtnode_event (stream, p.event);
break;
}
case PINOS_MESSAGE_PORT_COMMAND:
{
break;
}
}
}
return TRUE;
}
static gboolean static gboolean
on_socket_condition (GSocket *socket, on_socket_condition (GSocket *socket,
GIOCondition condition, GIOCondition condition,
@ -1244,22 +1110,95 @@ on_socket_condition (GSocket *socket,
return TRUE; return TRUE;
} }
static gboolean
handle_rtnode_event (PinosStream *stream,
SpaNodeEvent *event)
{
PinosStreamPrivate *priv = stream->priv;
switch (event->type) {
case SPA_NODE_EVENT_TYPE_INVALID:
case SPA_NODE_EVENT_TYPE_ASYNC_COMPLETE:
case SPA_NODE_EVENT_TYPE_ERROR:
case SPA_NODE_EVENT_TYPE_BUFFERING:
case SPA_NODE_EVENT_TYPE_REQUEST_REFRESH:
case SPA_NODE_EVENT_TYPE_REQUEST_CLOCK_UPDATE:
pinos_log_warn ("unexpected node event %d", event->type);
break;
case SPA_NODE_EVENT_TYPE_HAVE_OUTPUT:
case SPA_NODE_EVENT_TYPE_NEED_INPUT:
pinos_log_warn ("unhandled node event %d", event->type);
break;
case SPA_NODE_EVENT_TYPE_REUSE_BUFFER:
{
SpaNodeEventReuseBuffer *p = (SpaNodeEventReuseBuffer *) event;
BufferId *bid;
if (p->port_id != priv->port_id)
break;
if (priv->direction != SPA_DIRECTION_OUTPUT)
break;
if ((bid = find_buffer (stream, p->buffer_id))) {
bid->used = FALSE;
g_signal_emit (stream, signals[SIGNAL_NEW_BUFFER], 0, p->buffer_id);
}
break;
}
}
return TRUE;
}
static gboolean static gboolean
on_rtsocket_condition (GSocket *socket, on_rtsocket_condition (GSocket *socket,
GIOCondition condition, GIOCondition condition,
gpointer user_data) gpointer user_data)
{ {
PinosStream *stream = user_data; PinosStream *stream = user_data;
PinosStreamPrivate *priv = stream->priv;
switch (condition) { switch (condition) {
case G_IO_IN: case G_IO_IN:
{ {
parse_rtconnection (stream); uint8_t cmd;
int i;
pinos_transport_read_cmd (priv->trans, &cmd);
if (cmd & PINOS_TRANSPORT_CMD_HAVE_DATA) {
BufferId *bid;
for (i = 0; i < priv->trans->area->n_input_info; i++) {
SpaPortInputInfo *info = &priv->trans->input_info[i];
if (info->buffer_id == SPA_ID_INVALID)
continue;
if ((bid = find_buffer (stream, info->buffer_id))) {
for (i = 0; i < bid->buf->n_datas; i++) {
bid->buf->datas[i].size = bid->datas[i].size;
}
g_signal_emit (stream, signals[SIGNAL_NEW_BUFFER], 0, bid->id);
}
info->buffer_id = SPA_ID_INVALID;
}
send_need_input (stream);
}
if (cmd & PINOS_TRANSPORT_CMD_HAVE_EVENT) {
SpaNodeEvent event;
while (pinos_transport_next_event (priv->trans, &event) == SPA_RESULT_OK) {
SpaNodeEvent *ev = alloca (event.size);
pinos_transport_parse_event (priv->trans, ev);
handle_rtnode_event (stream, ev);
}
}
break; break;
} }
case G_IO_OUT: case G_IO_OUT:
pinos_log_warn ("can do IO\n"); pinos_log_warn ("can do IO");
break; break;
default: default:
@ -1305,7 +1244,8 @@ handle_socket (PinosStream *stream, gint fd, gint rtfd)
priv->rtsocket_source = g_socket_create_source (priv->rtsocket, G_IO_IN, NULL); priv->rtsocket_source = g_socket_create_source (priv->rtsocket, G_IO_IN, NULL);
g_source_set_callback (priv->rtsocket_source, (GSourceFunc) on_rtsocket_condition, stream, NULL); g_source_set_callback (priv->rtsocket_source, (GSourceFunc) on_rtsocket_condition, stream, NULL);
g_source_attach (priv->rtsocket_source, priv->context->priv->context); g_source_attach (priv->rtsocket_source, priv->context->priv->context);
priv->rtconn = pinos_connection_new (priv->rtfd);
pinos_log_debug ("sockets %d %d", priv->fd, priv->rtfd);
priv->timeout_source = g_timeout_source_new (100); priv->timeout_source = g_timeout_source_new (100);
g_source_set_callback (priv->timeout_source, (GSourceFunc) on_timeout, stream, NULL); g_source_set_callback (priv->timeout_source, (GSourceFunc) on_timeout, stream, NULL);
@ -1863,13 +1803,19 @@ pinos_stream_recycle_buffer (PinosStream *stream,
guint id) guint id)
{ {
PinosStreamPrivate *priv; PinosStreamPrivate *priv;
SpaNodeEventReuseBuffer rb;
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE); g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
g_return_val_if_fail (id != SPA_ID_INVALID, FALSE); g_return_val_if_fail (id != SPA_ID_INVALID, FALSE);
priv = stream->priv; priv = stream->priv;
g_return_val_if_fail (priv->direction == SPA_DIRECTION_INPUT, FALSE); g_return_val_if_fail (priv->direction == SPA_DIRECTION_INPUT, FALSE);
send_reuse_buffer (stream, priv->port_id, id); rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
rb.event.size = sizeof (rb);
rb.port_id = priv->port_id;
rb.buffer_id = id;
pinos_transport_add_event (priv->trans, &rb.event);
pinos_transport_write_cmd (priv->trans, PINOS_TRANSPORT_CMD_HAVE_EVENT);
return TRUE; return TRUE;
} }
@ -1929,7 +1875,9 @@ pinos_stream_send_buffer (PinosStream *stream,
for (i = 0; i < bid->buf->n_datas; i++) { for (i = 0; i < bid->buf->n_datas; i++) {
bid->datas[i].size = bid->buf->datas[i].size; bid->datas[i].size = bid->buf->datas[i].size;
} }
send_process_buffer (stream, priv->port_id, id); priv->trans->output_info[0].buffer_id = id;
priv->trans->output_info[0].status = SPA_RESULT_OK;
pinos_transport_write_cmd (priv->trans, PINOS_TRANSPORT_CMD_HAVE_DATA);
return TRUE; return TRUE;
} else { } else {
return FALSE; return FALSE;

251
pinos/client/transport.c Normal file
View file

@ -0,0 +1,251 @@
/* 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 <unistd.h>
#include <sys/mman.h>
#include <pinos/client/transport.h>
#define INPUT_BUFFER_SIZE (1<<12)
#define OUTPUT_BUFFER_SIZE (1<<12)
#define CMD_NONE 0
#define CMD_PROCESS_DATA (1<<0)
#define CMD_PROCESS_EVENTS (1<<1)
#define CMD_PROCESS_SYNC (1<<2)
typedef struct {
PinosTransport trans;
PinosMemblock mem;
size_t offset;
SpaRingbufferArea areas[2];
SpaNodeEvent current;
} PinosTransportImpl;
static size_t
transport_area_get_size (PinosTransportArea *area)
{
size_t size;
size = sizeof (PinosTransportArea);
size += area->max_input_info * sizeof (SpaPortInputInfo);
size += area->max_output_info * sizeof (SpaPortOutputInfo);
size += sizeof (SpaRingbuffer);
size += INPUT_BUFFER_SIZE;
size += sizeof (SpaRingbuffer);
size += OUTPUT_BUFFER_SIZE;
return size;
}
static void
transport_setup_area (void *p, PinosTransport *trans)
{
PinosTransportArea *a;
trans->area = a = p;
p = SPA_MEMBER (p, sizeof (PinosTransportArea), SpaPortInputInfo);
trans->input_info = p;
p = SPA_MEMBER (p, a->max_input_info * sizeof (SpaPortInputInfo), void);
trans->output_info = p;
p = SPA_MEMBER (p, a->max_output_info * sizeof (SpaPortOutputInfo), void);
trans->input_buffer = p;
spa_ringbuffer_init (trans->input_buffer, INPUT_BUFFER_SIZE);
p = SPA_MEMBER (p, sizeof (SpaRingbuffer), void);
trans->input_data = p;
p = SPA_MEMBER (p, INPUT_BUFFER_SIZE, void);
trans->output_buffer = p;
spa_ringbuffer_init (trans->output_buffer, OUTPUT_BUFFER_SIZE);
p = SPA_MEMBER (p, sizeof (SpaRingbuffer), void);
trans->output_data = p;
p = SPA_MEMBER (p, OUTPUT_BUFFER_SIZE, void);
}
PinosTransport *
pinos_transport_new (unsigned int max_input_info,
unsigned int max_output_info,
int fd)
{
PinosTransportImpl *impl;
PinosTransport *trans;
PinosTransportArea area;
area.max_input_info = max_input_info;
area.n_input_info = 0;
area.max_output_info = max_output_info;
area.n_output_info = 0;
impl = calloc (1, sizeof (PinosTransportImpl));
impl->offset = 0;
trans = &impl->trans;
trans->fd = fd;
pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD |
PINOS_MEMBLOCK_FLAG_MAP_READWRITE |
PINOS_MEMBLOCK_FLAG_SEAL,
transport_area_get_size (&area),
&impl->mem);
memcpy (impl->mem.ptr, &area, sizeof (PinosTransportArea));
transport_setup_area (impl->mem.ptr, trans);
return trans;
}
PinosTransport *
pinos_transport_new_from_info (PinosTransportInfo *info)
{
PinosTransportImpl *impl;
PinosTransport *trans;
void *tmp;
if (info == NULL)
return NULL;
impl = calloc (1, sizeof (PinosTransportImpl));
trans = &impl->trans;
trans->fd = info->fd;
impl->mem.flags = PINOS_MEMBLOCK_FLAG_MAP_READWRITE |
PINOS_MEMBLOCK_FLAG_WITH_FD;
impl->mem.fd = info->memfd;
impl->mem.size = info->size;
impl->mem.ptr = mmap (NULL, info->size, PROT_READ | PROT_WRITE, MAP_SHARED, info->memfd, info->offset);
impl->offset = info->offset;
transport_setup_area (impl->mem.ptr, trans);
tmp = trans->output_buffer;
trans->output_buffer = trans->input_buffer;
trans->input_buffer = tmp;
tmp = trans->output_data;
trans->output_data = trans->input_data;
trans->input_data = tmp;
return trans;
}
void
pinos_transport_free (PinosTransport *trans)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
if (impl == NULL)
return;
pinos_memblock_free (&impl->mem);
if (trans->fd != -1)
close (trans->fd);
free (impl);
}
SpaResult
pinos_transport_get_info (PinosTransport *trans,
PinosTransportInfo *info)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
if (impl == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
info->memfd = impl->mem.fd;
info->offset = impl->offset;
info->size = impl->mem.size;
info->fd = trans->fd;
return SPA_RESULT_OK;
}
SpaResult
pinos_transport_add_event (PinosTransport *trans,
SpaNodeEvent *event)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
SpaRingbufferArea areas[2];
size_t avail;
if (impl == NULL || event == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
avail = spa_ringbuffer_get_write_areas (trans->output_buffer, areas);
if (avail < event->size)
return SPA_RESULT_ERROR;
spa_ringbuffer_write_data (trans->output_buffer,
trans->output_data,
areas,
event,
event->size);
spa_ringbuffer_write_advance (trans->output_buffer, event->size);
return SPA_RESULT_OK;
}
SpaResult
pinos_transport_next_event (PinosTransport *trans,
SpaNodeEvent *event)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
size_t avail;
if (impl == NULL || event == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
avail = spa_ringbuffer_get_read_areas (trans->input_buffer, impl->areas);
if (avail < sizeof (SpaNodeEvent))
return SPA_RESULT_ENUM_END;
spa_ringbuffer_read_data (trans->input_buffer,
trans->input_data,
impl->areas,
&impl->current,
sizeof (SpaNodeEvent));
*event = impl->current;
return SPA_RESULT_OK;
}
SpaResult
pinos_transport_parse_event (PinosTransport *trans,
void *event)
{
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
if (impl == NULL || event == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
spa_ringbuffer_read_data (trans->input_buffer,
trans->input_data,
impl->areas,
event,
impl->current.size);
spa_ringbuffer_read_advance (trans->input_buffer, impl->current.size);
return SPA_RESULT_OK;
}

115
pinos/client/transport.h Normal file
View file

@ -0,0 +1,115 @@
/* 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_TRANSPORT_H__
#define __PINOS_TRANSPORT_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _PinosTransport PinosTransport;
typedef struct _PinosTransportArea PinosTransportArea;
#include <string.h>
#include <spa/defs.h>
#include <spa/port.h>
#include <spa/node.h>
#include <pinos/client/connection.h>
#include <pinos/client/mem.h>
#define PINOS_TRANSPORT_CMD_NONE 0
#define PINOS_TRANSPORT_CMD_NEED_DATA (1<<0)
#define PINOS_TRANSPORT_CMD_HAVE_DATA (1<<1)
#define PINOS_TRANSPORT_CMD_HAVE_EVENT (1<<2)
#define PINOS_TRANSPORT_CMD_SYNC (1<<3)
typedef struct {
int memfd;
off_t offset;
size_t size;
int fd;
} PinosTransportInfo;
struct _PinosTransportArea {
unsigned int max_input_info;
unsigned int n_input_info;
unsigned int max_output_info;
unsigned int n_output_info;
};
struct _PinosTransport {
PinosTransportArea *area;
SpaPortInputInfo *input_info;
SpaPortOutputInfo *output_info;
void *input_data;
SpaRingbuffer *input_buffer;
void *output_data;
SpaRingbuffer *output_buffer;
int fd;
};
PinosTransport * pinos_transport_new (unsigned int max_input_info,
unsigned int max_output_info,
int fd);
PinosTransport * pinos_transport_new_from_info (PinosTransportInfo *info);
void pinos_transport_free (PinosTransport *trans);
SpaResult pinos_transport_get_info (PinosTransport *trans,
PinosTransportInfo *info);
SpaResult pinos_transport_add_event (PinosTransport *trans,
SpaNodeEvent *event);
SpaResult pinos_transport_next_event (PinosTransport *trans,
SpaNodeEvent *event);
SpaResult pinos_transport_parse_event (PinosTransport *trans,
void *event);
static inline void
pinos_transport_write_cmd (PinosTransport *trans,
uint8_t cmd)
{
write (trans->fd, &cmd, 1);
}
static inline void
pinos_transport_read_cmd (PinosTransport *trans,
uint8_t *cmd)
{
read (trans->fd, cmd, 1);
}
static inline void
pinos_transport_sync_cmd (PinosTransport *trans,
uint8_t out_cmd,
uint8_t *in_cmd)
{
write (trans->fd, &out_cmd, 1);
read (trans->fd, in_cmd, 1);
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __PINOS_TRANSPORT_H__ */

View file

@ -34,6 +34,7 @@
#include "pinos/client/private.h" #include "pinos/client/private.h"
#include "pinos/client/connection.h" #include "pinos/client/connection.h"
#include "pinos/client/serialize.h" #include "pinos/client/serialize.h"
#include "pinos/client/transport.h"
#include "pinos/server/daemon.h" #include "pinos/server/daemon.h"
#include "pinos/server/client-node.h" #include "pinos/server/client-node.h"
@ -110,7 +111,6 @@ struct _SpaProxy
SpaPollFd rtfds[1]; SpaPollFd rtfds[1];
SpaPollItem rtpoll; SpaPollItem rtpoll;
PinosConnection *rtconn;
unsigned int max_inputs; unsigned int max_inputs;
unsigned int n_inputs; unsigned int n_inputs;
@ -119,6 +119,8 @@ struct _SpaProxy
SpaProxyPort in_ports[MAX_INPUTS]; SpaProxyPort in_ports[MAX_INPUTS];
SpaProxyPort out_ports[MAX_OUTPUTS]; SpaProxyPort out_ports[MAX_OUTPUTS];
PinosTransport *trans;
uint32_t seq; uint32_t seq;
}; };
@ -852,10 +854,8 @@ spa_proxy_node_port_push_input (SpaNode *node,
SpaPortInputInfo *info) SpaPortInputInfo *info)
{ {
SpaProxy *this; SpaProxy *this;
SpaProxyPort *port;
unsigned int i; unsigned int i;
bool have_error = false; bool have_error = false;
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;
@ -863,13 +863,16 @@ spa_proxy_node_port_push_input (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaProxy, node); this = SPA_CONTAINER_OF (node, SpaProxy, 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)) { SpaProxyPort *port;
spa_log_warn (this->log, "invalid port %d", info[i].port_id); uint32_t port_id = info[i].port_id;
if (!CHECK_IN_PORT (this, SPA_DIRECTION_INPUT, port_id)) {
spa_log_warn (this->log, "invalid port %d", port_id);
info[i].status = SPA_RESULT_INVALID_PORT; info[i].status = SPA_RESULT_INVALID_PORT;
have_error = true; have_error = true;
continue; continue;
} }
port = &this->in_ports[info[i].port_id]; port = &this->in_ports[port_id];
if (!port->format) { if (!port->format) {
info[i].status = SPA_RESULT_NO_FORMAT; info[i].status = SPA_RESULT_NO_FORMAT;
@ -877,29 +880,19 @@ spa_proxy_node_port_push_input (SpaNode *node,
continue; continue;
} }
if (!CHECK_PORT_BUFFER (this, info[i].buffer_id, port)) { if (!CHECK_PORT_BUFFER (this, info[i].buffer_id, port)) {
if (port->n_buffers == 0) info[i].status = SPA_RESULT_INVALID_BUFFER_ID;
info[i].status = SPA_RESULT_NO_BUFFERS;
else
info[i].status = SPA_RESULT_INVALID_BUFFER_ID;
have_error = true; have_error = true;
continue; continue;
} }
copy_meta_out (this, port, info[i].buffer_id); copy_meta_out (this, port, info[i].buffer_id);
this->trans->input_info[i] = *info;
pb.direction = SPA_DIRECTION_INPUT;
pb.port_id = info[i].port_id;
pb.buffer_id = info[i].buffer_id;
pinos_connection_add_message (this->rtconn, PINOS_MESSAGE_PROCESS_BUFFER, &pb);
info[i].status = SPA_RESULT_OK;
} }
this->trans->area->n_input_info = n_info;
if (have_error) if (have_error)
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
if (!pinos_connection_flush (this->rtconn)) pinos_transport_write_cmd (this->trans, PINOS_TRANSPORT_CMD_HAVE_DATA);
spa_log_error (this->log, "proxy %p: error writing connection", this);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -910,7 +903,6 @@ spa_proxy_node_port_pull_output (SpaNode *node,
SpaPortOutputInfo *info) SpaPortOutputInfo *info)
{ {
SpaProxy *this; SpaProxy *this;
SpaProxyPort *port;
unsigned int i; unsigned int i;
bool have_error = false; bool have_error = false;
@ -920,33 +912,28 @@ spa_proxy_node_port_pull_output (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaProxy, node); this = SPA_CONTAINER_OF (node, SpaProxy, node);
for (i = 0; i < n_info; i++) { for (i = 0; i < n_info; i++) {
ProxyBuffer *b; SpaProxyPort *port;
uint32_t port_id = info[i].port_id;
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, info[i].port_id)) { if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, 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;
} }
port = &this->out_ports[port_id];
port = &this->out_ports[info[i].port_id]; info[i] = this->trans->output_info[port_id];
if (!port->format) { if (!CHECK_PORT_BUFFER (this, info[i].buffer_id, port)) {
info[i].status = SPA_RESULT_NO_FORMAT; info[i].status = SPA_RESULT_INVALID_BUFFER_ID;
have_error = true; have_error = true;
continue; continue;
} }
SPA_QUEUE_POP_HEAD (&port->ready, ProxyBuffer, next, b); copy_meta_in (this, port, info[i].buffer_id);
if (b == NULL) {
info[i].status = SPA_RESULT_UNEXPECTED;
have_error = true;
continue;
}
b->outstanding = true;
info[i].buffer_id = b->outbuf->id; if (info[i].status != SPA_RESULT_OK)
info[i].status = SPA_RESULT_OK; have_error = true;
} }
if (have_error) if (have_error)
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
@ -960,7 +947,6 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
uint32_t buffer_id) uint32_t buffer_id)
{ {
SpaProxy *this; SpaProxy *this;
PinosMessageNodeEvent cne;
SpaNodeEventReuseBuffer rb; SpaNodeEventReuseBuffer rb;
if (node == NULL) if (node == NULL)
@ -971,16 +957,12 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, port_id)) if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
/* send start */
cne.event = &rb.event;
rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER; rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER;
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_message (this->rtconn, PINOS_MESSAGE_NODE_EVENT, &cne); pinos_transport_add_event (this->trans, &rb.event);
pinos_transport_write_cmd (this->trans, PINOS_TRANSPORT_CMD_HAVE_EVENT);
if (!pinos_connection_flush (this->rtconn))
spa_log_error (this->log, "proxy %p: error writing connection", this);
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -1008,19 +990,7 @@ spa_proxy_node_port_send_command (SpaNode *node,
case SPA_NODE_COMMAND_FLUSH: case SPA_NODE_COMMAND_FLUSH:
case SPA_NODE_COMMAND_DRAIN: case SPA_NODE_COMMAND_DRAIN:
case SPA_NODE_COMMAND_MARKER: case SPA_NODE_COMMAND_MARKER:
{
PinosMessagePortCommand cpc;
cpc.port_id = port_id;
cpc.command = command;
pinos_connection_add_message (this->rtconn, PINOS_MESSAGE_PORT_COMMAND, &cpc);
if (!pinos_connection_flush (this->rtconn)) {
spa_log_error (this->log, "proxy %p: error writing connection", this);
res = SPA_RESULT_ERROR;
}
break; break;
}
default: default:
spa_log_warn (this->log, "unhandled command %d", command->type); spa_log_warn (this->log, "unhandled command %d", command->type);
@ -1070,12 +1040,15 @@ parse_connection (SpaProxy *this)
case PINOS_MESSAGE_NODE_COMMAND: case PINOS_MESSAGE_NODE_COMMAND:
case PINOS_MESSAGE_PORT_COMMAND: case PINOS_MESSAGE_PORT_COMMAND:
case PINOS_MESSAGE_PROCESS_BUFFER: case PINOS_MESSAGE_PROCESS_BUFFER:
case PINOS_MESSAGE_TRANSPORT_UPDATE:
spa_log_error (this->log, "proxy %p: got unexpected command %d", this, type); spa_log_error (this->log, "proxy %p: got unexpected command %d", this, type);
break; break;
case PINOS_MESSAGE_NODE_UPDATE: case PINOS_MESSAGE_NODE_UPDATE:
{ {
PinosMessageNodeUpdate nu; PinosMessageNodeUpdate nu;
PinosTransportInfo info;
PinosMessageTransportUpdate tu;
if (!pinos_connection_parse_message (conn, &nu)) if (!pinos_connection_parse_message (conn, &nu))
break; break;
@ -1088,6 +1061,19 @@ parse_connection (SpaProxy *this)
spa_log_info (this->log, "proxy %p: got node update %d, max_in %u, max_out %u", this, type, 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);
this->trans = pinos_transport_new (this->max_inputs,
this->max_outputs,
this->rtfds[0].fd);
pinos_transport_get_info (this->trans, &info);
tu.memfd_index = pinos_connection_add_fd (conn, info.memfd, false);
tu.offset = info.offset;
tu.size = info.size;
pinos_connection_add_message (conn, PINOS_MESSAGE_TRANSPORT_UPDATE, &tu);
if (!pinos_connection_flush (conn))
spa_log_error (this->log, "proxy %p: error writing connection", this);
break; break;
} }
@ -1156,79 +1142,6 @@ parse_connection (SpaProxy *this)
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static SpaResult
parse_rtconnection (SpaProxy *this)
{
PinosConnection *conn = this->rtconn;
while (pinos_connection_has_next (conn)) {
PinosMessageType type = pinos_connection_get_type (conn);
switch (type) {
case PINOS_MESSAGE_INVALID:
case PINOS_MESSAGE_NODE_UPDATE:
case PINOS_MESSAGE_PORT_UPDATE:
case PINOS_MESSAGE_NODE_STATE_CHANGE:
case PINOS_MESSAGE_PORT_STATUS_CHANGE:
case PINOS_MESSAGE_ADD_PORT:
case PINOS_MESSAGE_REMOVE_PORT:
case PINOS_MESSAGE_SET_FORMAT:
case PINOS_MESSAGE_SET_PROPERTY:
case PINOS_MESSAGE_NODE_COMMAND:
case PINOS_MESSAGE_ADD_MEM:
case PINOS_MESSAGE_USE_BUFFERS:
spa_log_error (this->log, "proxy %p: got unexpected message %d", this, type);
break;
case PINOS_MESSAGE_PROCESS_BUFFER:
{
PinosMessageProcessBuffer msg;
SpaProxyPort *port;
ProxyBuffer *b;
if (!pinos_connection_parse_message (conn, &msg))
break;
if (!CHECK_PORT (this, msg.direction, msg.port_id))
break;
port = msg.direction == SPA_DIRECTION_INPUT ? &this->in_ports[msg.port_id] : &this->out_ports[msg.port_id];
if (!CHECK_PORT_BUFFER (this, msg.buffer_id, port))
break;
copy_meta_in (this, port, msg.buffer_id);
b = &port->buffers[msg.buffer_id];
b->next = NULL;
SPA_QUEUE_PUSH_TAIL (&port->ready, ProxyBuffer, next, b);
break;
}
case PINOS_MESSAGE_NODE_EVENT:
{
PinosMessageNodeEvent cne;
if (!pinos_connection_parse_message (conn, &cne))
break;
handle_node_event (this, cne.event);
break;
}
case PINOS_MESSAGE_PORT_COMMAND:
{
PinosMessagePortCommand cm;
if (!pinos_connection_parse_message (conn, &cm))
break;
break;
}
}
}
return SPA_RESULT_OK;
}
static int static int
proxy_on_fd_events (SpaPollNotifyData *data) proxy_on_fd_events (SpaPollNotifyData *data)
{ {
@ -1246,7 +1159,32 @@ proxy_on_rtfd_events (SpaPollNotifyData *data)
SpaProxy *this = data->user_data; SpaProxy *this = data->user_data;
if (data->fds[0].revents & POLLIN) { if (data->fds[0].revents & POLLIN) {
parse_rtconnection (this); uint8_t cmd;
pinos_transport_read_cmd (this->trans, &cmd);
if (cmd & PINOS_TRANSPORT_CMD_HAVE_EVENT) {
SpaNodeEvent event;
while (pinos_transport_next_event (this->trans, &event) == SPA_RESULT_OK) {
SpaNodeEvent *ev = alloca (event.size);
pinos_transport_parse_event (this->trans, ev);
this->event_cb (&this->node, ev, this->user_data);
}
}
if (cmd & PINOS_TRANSPORT_CMD_HAVE_DATA) {
SpaNodeEventHaveOutput ho;
ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
ho.event.size = sizeof (ho);
ho.port_id = 0;
this->event_cb (&this->node, &ho.event, this->user_data);
}
if (cmd & PINOS_TRANSPORT_CMD_NEED_DATA) {
SpaNodeEventNeedInput ni;
ni.event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT;
ni.event.size = sizeof (ni);
ni.port_id = 0;
this->event_cb (&this->node, &ni.event, this->user_data);
}
} }
return 0; return 0;
} }
@ -1504,7 +1442,7 @@ pinos_client_node_get_socket_pair (PinosClientNode *this,
if (priv->sockets[1] == NULL) { if (priv->sockets[1] == NULL) {
int fd[2]; int fd[2];
if (socketpair (AF_UNIX, SOCK_STREAM, 0, fd) != 0) if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, fd) != 0)
goto no_sockets; goto no_sockets;
priv->sockets[0] = g_socket_new_from_fd (fd[0], error); priv->sockets[0] = g_socket_new_from_fd (fd[0], error);
@ -1574,7 +1512,6 @@ pinos_client_node_get_rtsocket_pair (PinosClientNode *this,
goto create_failed; goto create_failed;
priv->proxy->rtfds[0].fd = g_socket_get_fd (priv->rtsockets[0]); priv->proxy->rtfds[0].fd = g_socket_get_fd (priv->rtsockets[0]);
priv->proxy->rtconn = pinos_connection_new (priv->proxy->rtfds[0].fd);
spa_poll_add_item (priv->proxy->data_loop, &priv->proxy->rtpoll); spa_poll_add_item (priv->proxy->data_loop, &priv->proxy->rtpoll);
} }

View file

@ -28,7 +28,6 @@
#include "pinos/client/enumtypes.h" #include "pinos/client/enumtypes.h"
#include "pinos/server/link.h" #include "pinos/server/link.h"
#include "pinos/server/utils.h"
#include "pinos/dbus/org-pinos.h" #include "pinos/dbus/org-pinos.h"

View file

@ -28,11 +28,13 @@ typedef struct _PinosLink PinosLink;
typedef struct _PinosLinkClass PinosLinkClass; typedef struct _PinosLinkClass PinosLinkClass;
typedef struct _PinosLinkPrivate PinosLinkPrivate; typedef struct _PinosLinkPrivate PinosLinkPrivate;
#include <pinos/server/daemon.h>
#include <pinos/server/utils.h>
#include <pinos/server/main-loop.h>
#include <spa/include/spa/ringbuffer.h> #include <spa/include/spa/ringbuffer.h>
#include <pinos/client/mem.h>
#include <pinos/server/daemon.h>
#include <pinos/server/main-loop.h>
#define PINOS_TYPE_LINK (pinos_link_get_type ()) #define PINOS_TYPE_LINK (pinos_link_get_type ())
#define PINOS_IS_LINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_LINK)) #define PINOS_IS_LINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_LINK))
#define PINOS_IS_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_LINK)) #define PINOS_IS_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_LINK))

View file

@ -11,7 +11,6 @@ pinoscore_headers = [
'node.h', 'node.h',
'node-factory.h', 'node-factory.h',
'registry.h', 'registry.h',
'utils.h',
] ]
pinoscore_sources = [ pinoscore_sources = [
@ -27,7 +26,6 @@ pinoscore_sources = [
'node.c', 'node.c',
'node-factory.c', 'node-factory.c',
'registry.c', 'registry.c',
'utils.c',
] ]
libpinoscore_c_args = [ libpinoscore_c_args = [

View file

@ -222,7 +222,6 @@ update_port_ids (PinosNode *node, gboolean create)
node->have_inputs = priv->n_input_ports > 0; node->have_inputs = priv->n_input_ports > 0;
node->have_outputs = priv->n_output_ports > 0; node->have_outputs = priv->n_output_ports > 0;
} }
static SpaResult static SpaResult

View file

@ -38,10 +38,11 @@ typedef enum {
#include <spa/include/spa/node.h> #include <spa/include/spa/node.h>
#include <pinos/client/introspect.h> #include <pinos/client/introspect.h>
#include <pinos/client/mem.h>
#include <pinos/server/daemon.h> #include <pinos/server/daemon.h>
#include <pinos/server/link.h> #include <pinos/server/link.h>
#include <pinos/server/client.h> #include <pinos/server/client.h>
#include <pinos/server/utils.h>
struct _PinosPort { struct _PinosPort {
uint32_t id; uint32_t id;

View file

@ -29,6 +29,8 @@ typedef struct _SpaRingbuffer SpaRingbuffer;
#define SPA_RINGBUFFER_URI "http://spaplug.in/ns/ringbuffer" #define SPA_RINGBUFFER_URI "http://spaplug.in/ns/ringbuffer"
#define SPA_RINGBUFFER_PREFIX SPA_RINGBUFFER_URI "#" #define SPA_RINGBUFFER_PREFIX SPA_RINGBUFFER_URI "#"
#include <string.h>
#include <spa/defs.h> #include <spa/defs.h>
#include <spa/barrier.h> #include <spa/barrier.h>
@ -115,7 +117,7 @@ spa_ringbuffer_get_read_offset (SpaRingbuffer *rbuf,
* Fill @areas with pointers to read from. The total amount of * Fill @areas with pointers to read from. The total amount of
* bytes that can be read can be obtained by summing the areas len fields. * bytes that can be read can be obtained by summing the areas len fields.
*/ */
static inline void static inline size_t
spa_ringbuffer_get_read_areas (SpaRingbuffer *rbuf, spa_ringbuffer_get_read_areas (SpaRingbuffer *rbuf,
SpaRingbufferArea areas[2]) SpaRingbufferArea areas[2])
{ {
@ -134,6 +136,22 @@ spa_ringbuffer_get_read_areas (SpaRingbuffer *rbuf,
areas[0].len = avail; areas[0].len = avail;
areas[1].len = 0; areas[1].len = 0;
} }
return avail;
}
static inline void
spa_ringbuffer_read_data (SpaRingbuffer *rbuf,
void *buffer,
SpaRingbufferArea areas[2],
void *data,
size_t size)
{
if (SPA_LIKELY (size < areas[0].len))
memcpy (data, buffer + areas[0].offset, size);
else {
memcpy (data, buffer + areas[0].offset, areas[0].len);
memcpy (data + areas[0].len, buffer, size - areas[0].len);
}
} }
/** /**
@ -173,7 +191,7 @@ spa_ringbuffer_get_write_offset (SpaRingbuffer *rbuf,
* Fill @areas with pointers to write to. The total amount of * Fill @areas with pointers to write to. The total amount of
* bytes that can be written can be obtained by summing the areas len fields. * bytes that can be written can be obtained by summing the areas len fields.
*/ */
static inline void static inline size_t
spa_ringbuffer_get_write_areas (SpaRingbuffer *rbuf, spa_ringbuffer_get_write_areas (SpaRingbuffer *rbuf,
SpaRingbufferArea areas[2]) SpaRingbufferArea areas[2])
{ {
@ -192,6 +210,22 @@ spa_ringbuffer_get_write_areas (SpaRingbuffer *rbuf,
areas[0].len = avail; areas[0].len = avail;
areas[1].len = 0; areas[1].len = 0;
} }
return avail;
}
static inline void
spa_ringbuffer_write_data (SpaRingbuffer *rbuf,
void *buffer,
SpaRingbufferArea areas[2],
void *data,
size_t size)
{
if (SPA_LIKELY (size < areas[0].len))
memcpy (buffer + areas[0].offset, data, size);
else {
memcpy (buffer + areas[0].offset, data, areas[0].len);
memcpy (buffer, data + areas[0].len, size - areas[0].len);
}
} }
/** /**
@ -210,6 +244,7 @@ spa_ringbuffer_write_advance (SpaRingbuffer *rbuf,
rbuf->writeindex = (rbuf->writeindex + len) & rbuf->mask2; rbuf->writeindex = (rbuf->writeindex + len) & rbuf->mask2;
} }
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

View file

@ -698,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", b->outbuf->id); spa_log_trace (this->log, "pull buffer %u", b->outbuf->id);
} }
if (have_error) if (have_error)
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;
@ -728,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", buffer_id); spa_log_trace (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

@ -221,14 +221,20 @@ set_swparams (SpaALSAState *state)
CHECK (snd_pcm_sw_params_set_silence_threshold (hndl, params, 0U), "set_silence_threshold"); CHECK (snd_pcm_sw_params_set_silence_threshold (hndl, params, 0U), "set_silence_threshold");
#if 1
/* 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) */
CHECK (snd_pcm_sw_params_set_avail_min (hndl, params, CHECK (snd_pcm_sw_params_set_avail_min (hndl, params,
props->period_event ? state->buffer_frames : state->period_frames), "set_avail_min"); props->period_event ? state->buffer_frames : state->period_frames), "set_avail_min");
/* enable period events when requested */ /* enable period events when requested */
if (props->period_event) { if (props->period_event) {
CHECK (snd_pcm_sw_params_set_period_event (hndl, params, 1), "set_period_event"); CHECK (snd_pcm_sw_params_set_period_event (hndl, params, 1), "set_period_event");
} }
#else
CHECK (snd_pcm_sw_params_set_avail_min (hndl, params, 0), "set_avail_min");
#endif
/* write the parameters to the playback device */ /* write the parameters to the playback device */
CHECK (snd_pcm_sw_params (hndl, params), "sw_params"); CHECK (snd_pcm_sw_params (hndl, params), "sw_params");
@ -328,8 +334,7 @@ pull_frames_ringbuffer (SpaALSAState *state,
src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void); 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); dst = SPA_MEMBER (my_areas[0].addr, offset * state->frame_size, uint8_t);
spa_ringbuffer_get_read_areas (&b->rb->ringbuffer, areas); avail = spa_ringbuffer_get_read_areas (&b->rb->ringbuffer, areas);
avail = areas[0].len + areas[1].len;
size = SPA_MIN (avail, frames * state->frame_size); size = SPA_MIN (avail, frames * state->frame_size);
spa_log_debug (state->log, "%zd %zd %zd %zd %zd %zd", spa_log_debug (state->log, "%zd %zd %zd %zd %zd %zd",
@ -337,13 +342,11 @@ pull_frames_ringbuffer (SpaALSAState *state,
areas[1].offset, areas[1].len, offset, size); areas[1].offset, areas[1].len, offset, size);
if (size > 0) { if (size > 0) {
areas[0].len = SPA_MIN (areas[0].len, size); spa_ringbuffer_read_data (&b->rb->ringbuffer,
areas[1].len = SPA_MIN (areas[1].len, size - areas[0].len); src,
areas,
memcpy (dst, src + areas[0].offset, areas[0].len); dst,
if (areas[1].len) size);
memcpy (dst + areas[0].len, src + areas[1].offset, areas[1].len);
spa_ringbuffer_read_advance (&b->rb->ringbuffer, size); spa_ringbuffer_read_advance (&b->rb->ringbuffer, size);
frames = size / state->frame_size; frames = size / state->frame_size;
} else { } else {
@ -371,6 +374,7 @@ mmap_write (SpaALSAState *state)
snd_pcm_status_t *status; snd_pcm_status_t *status;
SpaNodeEventNeedInput ni; SpaNodeEventNeedInput ni;
#if 0
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) {
@ -379,6 +383,12 @@ mmap_write (SpaALSAState *state)
} }
avail = snd_pcm_status_get_avail (status); avail = snd_pcm_status_get_avail (status);
#else
if ((avail = snd_pcm_avail_update (hndl)) < 0) {
spa_log_error (state->log, "snd_pcm_avail_update error: %s", snd_strerror (avail));
return -1;
}
#endif
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);
@ -403,7 +413,6 @@ mmap_write (SpaALSAState *state)
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;
@ -552,6 +561,7 @@ spa_alsa_start (SpaALSAState *state, bool xrun_recover)
spa_log_error (state->log, "Invalid poll descriptors count %d", 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", snd_strerror(err)); spa_log_error (state->log, "snd_pcm_poll_descriptors: %s", snd_strerror(err));
return SPA_RESULT_ERROR; return SPA_RESULT_ERROR;