mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	Work on main loop
Make a main-loop object with associated helper functions to handle async methods. rtloop -> data_loop Handle async results a lot better. Remove REMOVE_MEM command. We don't need it. Handle stream memory updates better.
This commit is contained in:
		
							parent
							
								
									98dbb6424d
								
							
						
					
					
						commit
						8fac22afdb
					
				
					 26 changed files with 926 additions and 583 deletions
				
			
		| 
						 | 
					@ -421,7 +421,7 @@ 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\n", conn, conn->fd, len, buf->n_fds);
 | 
					  PINOS_DEBUG_CONTROL ("connection %p: %d read %zd bytes and %d fds", conn, conn->fd, len, buf->n_fds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -594,12 +594,6 @@ pinos_connection_parse_cmd (PinosConnection *conn,
 | 
				
			||||||
      memcpy (command, conn->in.data, sizeof (PinosControlCmdAddMem));
 | 
					      memcpy (command, conn->in.data, sizeof (PinosControlCmdAddMem));
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case PINOS_CONTROL_CMD_REMOVE_MEM:
 | 
					 | 
				
			||||||
      if (conn->in.size < sizeof (PinosControlCmdRemoveMem))
 | 
					 | 
				
			||||||
        return FALSE;
 | 
					 | 
				
			||||||
      memcpy (command, conn->in.data, sizeof (PinosControlCmdRemoveMem));
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
					    case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
				
			||||||
      connection_parse_use_buffers (conn, command);
 | 
					      connection_parse_use_buffers (conn, command);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
| 
						 | 
					@ -748,11 +742,6 @@ pinos_connection_add_cmd (PinosConnection *conn,
 | 
				
			||||||
      memcpy (p, command, sizeof (PinosControlCmdAddMem));
 | 
					      memcpy (p, command, sizeof (PinosControlCmdAddMem));
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case PINOS_CONTROL_CMD_REMOVE_MEM:
 | 
					 | 
				
			||||||
      p = connection_add_cmd (conn, cmd, sizeof (PinosControlCmdRemoveMem));
 | 
					 | 
				
			||||||
      memcpy (p, command, sizeof (PinosControlCmdRemoveMem));
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
					    case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
				
			||||||
      connection_add_use_buffers (conn, command);
 | 
					      connection_add_use_buffers (conn, command);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
| 
						 | 
					@ -830,7 +819,7 @@ 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\n", conn, conn->fd, len, buf->n_fds);
 | 
					  PINOS_DEBUG_CONTROL ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,8 +52,6 @@ typedef enum {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* both */
 | 
					  /* both */
 | 
				
			||||||
  PINOS_CONTROL_CMD_ADD_MEM                  = 64,
 | 
					  PINOS_CONTROL_CMD_ADD_MEM                  = 64,
 | 
				
			||||||
  PINOS_CONTROL_CMD_REMOVE_MEM               = 65,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  PINOS_CONTROL_CMD_USE_BUFFERS              = 66,
 | 
					  PINOS_CONTROL_CMD_USE_BUFFERS              = 66,
 | 
				
			||||||
  PINOS_CONTROL_CMD_PROCESS_BUFFER           = 67,
 | 
					  PINOS_CONTROL_CMD_PROCESS_BUFFER           = 67,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -146,13 +144,6 @@ typedef struct {
 | 
				
			||||||
  size_t       size;
 | 
					  size_t       size;
 | 
				
			||||||
} PinosControlCmdAddMem;
 | 
					} PinosControlCmdAddMem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* PINOS_CONTROL_CMD_REMOVE_MEM */
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
  SpaDirection direction;
 | 
					 | 
				
			||||||
  uint32_t     port_id;
 | 
					 | 
				
			||||||
  uint32_t     mem_id;
 | 
					 | 
				
			||||||
} PinosControlCmdRemoveMem;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  uint32_t    mem_id;
 | 
					  uint32_t    mem_id;
 | 
				
			||||||
  off_t       offset;
 | 
					  off_t       offset;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,12 +2,12 @@ pinos_headers = [
 | 
				
			||||||
  'context.h',
 | 
					  'context.h',
 | 
				
			||||||
  'format.h',
 | 
					  'format.h',
 | 
				
			||||||
  'introspect.h',
 | 
					  'introspect.h',
 | 
				
			||||||
  'mainloop.h',
 | 
					 | 
				
			||||||
  'pinos.h',
 | 
					  'pinos.h',
 | 
				
			||||||
  'properties.h',
 | 
					  'properties.h',
 | 
				
			||||||
  'stream.h',
 | 
					  'stream.h',
 | 
				
			||||||
  'ringbuffer.h',
 | 
					  'ringbuffer.h',
 | 
				
			||||||
  'subscribe.h',
 | 
					  'subscribe.h',
 | 
				
			||||||
 | 
					  'thread-mainloop.h',
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pinos_sources = [
 | 
					pinos_sources = [
 | 
				
			||||||
| 
						 | 
					@ -15,13 +15,13 @@ pinos_sources = [
 | 
				
			||||||
  'context.c',
 | 
					  'context.c',
 | 
				
			||||||
  'format.c',
 | 
					  'format.c',
 | 
				
			||||||
  'introspect.c',
 | 
					  'introspect.c',
 | 
				
			||||||
  'mainloop.c',
 | 
					 | 
				
			||||||
  'properties.c',
 | 
					  'properties.c',
 | 
				
			||||||
  'serialize.c',
 | 
					  'serialize.c',
 | 
				
			||||||
  'stream.c',
 | 
					  'stream.c',
 | 
				
			||||||
  'pinos.c',
 | 
					  'pinos.c',
 | 
				
			||||||
  'ringbuffer.c',
 | 
					  'ringbuffer.c',
 | 
				
			||||||
  'subscribe.c',
 | 
					  'subscribe.c',
 | 
				
			||||||
 | 
					  'thread-mainloop.c',
 | 
				
			||||||
  gdbus_target,
 | 
					  gdbus_target,
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,7 @@ 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/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>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -992,7 +992,7 @@ parse_connection (PinosStream *stream)
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        PinosControlCmdAddMem p;
 | 
					        PinosControlCmdAddMem p;
 | 
				
			||||||
        int fd;
 | 
					        int fd;
 | 
				
			||||||
        MemId mid;
 | 
					        MemId mid, *m;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!pinos_connection_parse_cmd (conn, &p))
 | 
					        if (!pinos_connection_parse_cmd (conn, &p))
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
| 
						 | 
					@ -1001,27 +1001,25 @@ parse_connection (PinosStream *stream)
 | 
				
			||||||
        if (fd == -1)
 | 
					        if (fd == -1)
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mid.id = p.mem_id;
 | 
					        m = find_mem (stream, p.mem_id);
 | 
				
			||||||
        mid.fd = fd;
 | 
					        if (m) {
 | 
				
			||||||
        mid.flags = p.flags;
 | 
					          g_debug ("update mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size);
 | 
				
			||||||
        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);
 | 
					          m->id = p.mem_id;
 | 
				
			||||||
        g_array_append_val (priv->mem_ids, mid);
 | 
					          m->fd = fd;
 | 
				
			||||||
        break;
 | 
					          m->flags = p.flags;
 | 
				
			||||||
      }
 | 
					          m->ptr = NULL;
 | 
				
			||||||
      case PINOS_CONTROL_CMD_REMOVE_MEM:
 | 
					          m->size = p.size;
 | 
				
			||||||
      {
 | 
					        } else {
 | 
				
			||||||
        PinosControlCmdRemoveMem p;
 | 
					          mid.id = p.mem_id;
 | 
				
			||||||
        MemId *mid;
 | 
					          mid.fd = fd;
 | 
				
			||||||
 | 
					          mid.flags = p.flags;
 | 
				
			||||||
 | 
					          mid.ptr = NULL;
 | 
				
			||||||
 | 
					          mid.size = p.size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!pinos_connection_parse_cmd (conn, &p))
 | 
					          g_debug ("add mem %u, fd %d, flags %d, size %zd", p.mem_id, fd, p.flags, p.size);
 | 
				
			||||||
          break;
 | 
					          g_array_append_val (priv->mem_ids, mid);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        g_debug ("stream %p: remove mem %d", stream, p.mem_id);
 | 
					 | 
				
			||||||
        if ((mid = find_mem (stream, p.mem_id)))
 | 
					 | 
				
			||||||
          mid->cleanup = true;
 | 
					 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
					      case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
				
			||||||
| 
						 | 
					@ -1181,7 +1179,6 @@ parse_rtconnection (PinosStream *stream)
 | 
				
			||||||
      case PINOS_CONTROL_CMD_SET_FORMAT:
 | 
					      case PINOS_CONTROL_CMD_SET_FORMAT:
 | 
				
			||||||
      case PINOS_CONTROL_CMD_SET_PROPERTY:
 | 
					      case PINOS_CONTROL_CMD_SET_PROPERTY:
 | 
				
			||||||
      case PINOS_CONTROL_CMD_ADD_MEM:
 | 
					      case PINOS_CONTROL_CMD_ADD_MEM:
 | 
				
			||||||
      case PINOS_CONTROL_CMD_REMOVE_MEM:
 | 
					 | 
				
			||||||
      case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
					      case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
				
			||||||
      case PINOS_CONTROL_CMD_NODE_COMMAND:
 | 
					      case PINOS_CONTROL_CMD_NODE_COMMAND:
 | 
				
			||||||
        g_warning ("got unexpected connection %d", cmd);
 | 
					        g_warning ("got unexpected connection %d", cmd);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,9 +18,9 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "pinos.h"
 | 
					#include "pinos.h"
 | 
				
			||||||
#include "mainloop.h"
 | 
					#include "thread-mainloop.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct _PinosMainLoopPrivate
 | 
					struct _PinosThreadMainLoopPrivate
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GMainContext *maincontext;
 | 
					  GMainContext *maincontext;
 | 
				
			||||||
  GMainLoop *mainloop;
 | 
					  GMainLoop *mainloop;
 | 
				
			||||||
| 
						 | 
					@ -38,10 +38,10 @@ struct _PinosMainLoopPrivate
 | 
				
			||||||
  gint n_waiting_for_accept;
 | 
					  gint n_waiting_for_accept;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define PINOS_MAIN_LOOP_GET_PRIVATE(obj)  \
 | 
					#define PINOS_THREAD_MAIN_LOOP_GET_PRIVATE(obj)  \
 | 
				
			||||||
   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_MAIN_LOOP, PinosMainLoopPrivate))
 | 
					   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_THREAD_MAIN_LOOP, PinosThreadMainLoopPrivate))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_DEFINE_TYPE (PinosMainLoop, pinos_main_loop, G_TYPE_OBJECT);
 | 
					G_DEFINE_TYPE (PinosThreadMainLoop, pinos_thread_main_loop, G_TYPE_OBJECT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum
 | 
					enum
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -52,13 +52,13 @@ enum
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_main_loop_get_property (GObject    *_object,
 | 
					pinos_thread_main_loop_get_property (GObject    *_object,
 | 
				
			||||||
                              guint       prop_id,
 | 
					                              guint       prop_id,
 | 
				
			||||||
                              GValue     *value,
 | 
					                              GValue     *value,
 | 
				
			||||||
                              GParamSpec *pspec)
 | 
					                              GParamSpec *pspec)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoop *loop = PINOS_MAIN_LOOP (_object);
 | 
					  PinosThreadMainLoop *loop = PINOS_THREAD_MAIN_LOOP (_object);
 | 
				
			||||||
  PinosMainLoopPrivate *priv = loop->priv;
 | 
					  PinosThreadMainLoopPrivate *priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  switch (prop_id) {
 | 
					  switch (prop_id) {
 | 
				
			||||||
    case PROP_MAIN_CONTEXT:
 | 
					    case PROP_MAIN_CONTEXT:
 | 
				
			||||||
| 
						 | 
					@ -80,13 +80,13 @@ pinos_main_loop_get_property (GObject    *_object,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_main_loop_set_property (GObject      *_object,
 | 
					pinos_thread_main_loop_set_property (GObject      *_object,
 | 
				
			||||||
                           guint         prop_id,
 | 
					                           guint         prop_id,
 | 
				
			||||||
                           const GValue *value,
 | 
					                           const GValue *value,
 | 
				
			||||||
                           GParamSpec   *pspec)
 | 
					                           GParamSpec   *pspec)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoop *loop = PINOS_MAIN_LOOP (_object);
 | 
					  PinosThreadMainLoop *loop = PINOS_THREAD_MAIN_LOOP (_object);
 | 
				
			||||||
  PinosMainLoopPrivate *priv = loop->priv;
 | 
					  PinosThreadMainLoopPrivate *priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  switch (prop_id) {
 | 
					  switch (prop_id) {
 | 
				
			||||||
    case PROP_MAIN_CONTEXT:
 | 
					    case PROP_MAIN_CONTEXT:
 | 
				
			||||||
| 
						 | 
					@ -104,22 +104,22 @@ pinos_main_loop_set_property (GObject      *_object,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_main_loop_constructed (GObject * object)
 | 
					pinos_thread_main_loop_constructed (GObject * object)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoop *loop = PINOS_MAIN_LOOP (object);
 | 
					  PinosThreadMainLoop *loop = PINOS_THREAD_MAIN_LOOP (object);
 | 
				
			||||||
  PinosMainLoopPrivate *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 ("mainloop %p: contructed %p %p", loop, priv->maincontext, priv->mainloop);
 | 
					  g_debug ("thread-mainloop %p: contructed %p %p", loop, priv->maincontext, priv->mainloop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  G_OBJECT_CLASS (pinos_main_loop_parent_class)->constructed (object);
 | 
					  G_OBJECT_CLASS (pinos_thread_main_loop_parent_class)->constructed (object);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_main_loop_finalize (GObject * object)
 | 
					pinos_thread_main_loop_finalize (GObject * object)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoop *loop = PINOS_MAIN_LOOP (object);
 | 
					  PinosThreadMainLoop *loop = PINOS_THREAD_MAIN_LOOP (object);
 | 
				
			||||||
  PinosMainLoopPrivate *priv = loop->priv;
 | 
					  PinosThreadMainLoopPrivate *priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (priv->maincontext)
 | 
					  if (priv->maincontext)
 | 
				
			||||||
    g_main_context_unref (priv->maincontext);
 | 
					    g_main_context_unref (priv->maincontext);
 | 
				
			||||||
| 
						 | 
					@ -130,23 +130,23 @@ pinos_main_loop_finalize (GObject * object)
 | 
				
			||||||
  g_cond_clear (&priv->cond);
 | 
					  g_cond_clear (&priv->cond);
 | 
				
			||||||
  g_cond_clear (&priv->accept_cond);
 | 
					  g_cond_clear (&priv->accept_cond);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  G_OBJECT_CLASS (pinos_main_loop_parent_class)->finalize (object);
 | 
					  G_OBJECT_CLASS (pinos_thread_main_loop_parent_class)->finalize (object);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_main_loop_class_init (PinosMainLoopClass * klass)
 | 
					pinos_thread_main_loop_class_init (PinosThreadMainLoopClass * klass)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 | 
					  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_type_class_add_private (klass, sizeof (PinosMainLoopPrivate));
 | 
					  g_type_class_add_private (klass, sizeof (PinosThreadMainLoopPrivate));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  gobject_class->constructed = pinos_main_loop_constructed;
 | 
					  gobject_class->constructed = pinos_thread_main_loop_constructed;
 | 
				
			||||||
  gobject_class->finalize = pinos_main_loop_finalize;
 | 
					  gobject_class->finalize = pinos_thread_main_loop_finalize;
 | 
				
			||||||
  gobject_class->set_property = pinos_main_loop_set_property;
 | 
					  gobject_class->set_property = pinos_thread_main_loop_set_property;
 | 
				
			||||||
  gobject_class->get_property = pinos_main_loop_get_property;
 | 
					  gobject_class->get_property = pinos_thread_main_loop_get_property;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * PinosMainLoop:main-context
 | 
					   * PinosThreadMainLoop:main-context
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * The GMainContext of the loop.
 | 
					   * The GMainContext of the loop.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
| 
						 | 
					@ -160,7 +160,7 @@ pinos_main_loop_class_init (PinosMainLoopClass * klass)
 | 
				
			||||||
                                                       G_PARAM_CONSTRUCT_ONLY |
 | 
					                                                       G_PARAM_CONSTRUCT_ONLY |
 | 
				
			||||||
                                                       G_PARAM_STATIC_STRINGS));
 | 
					                                                       G_PARAM_STATIC_STRINGS));
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * PinosMainLoop:name
 | 
					   * PinosThreadMainLoop:name
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * The name of the loop as specified at construction time.
 | 
					   * The name of the loop as specified at construction time.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
| 
						 | 
					@ -174,7 +174,7 @@ pinos_main_loop_class_init (PinosMainLoopClass * klass)
 | 
				
			||||||
                                                        G_PARAM_CONSTRUCT_ONLY |
 | 
					                                                        G_PARAM_CONSTRUCT_ONLY |
 | 
				
			||||||
                                                        G_PARAM_STATIC_STRINGS));
 | 
					                                                        G_PARAM_STATIC_STRINGS));
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * PinosMainLoop:main-loop
 | 
					   * PinosThreadMainLoop:main-loop
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * The GMainLoop of the loop.
 | 
					   * The GMainLoop of the loop.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
| 
						 | 
					@ -189,9 +189,9 @@ pinos_main_loop_class_init (PinosMainLoopClass * klass)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_main_loop_init (PinosMainLoop * loop)
 | 
					pinos_thread_main_loop_init (PinosThreadMainLoop * loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv = loop->priv = PINOS_MAIN_LOOP_GET_PRIVATE (loop);
 | 
					  PinosThreadMainLoopPrivate *priv = loop->priv = PINOS_THREAD_MAIN_LOOP_GET_PRIVATE (loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_mutex_init (&priv->lock);
 | 
					  g_mutex_init (&priv->lock);
 | 
				
			||||||
  g_cond_init (&priv->cond);
 | 
					  g_cond_init (&priv->cond);
 | 
				
			||||||
| 
						 | 
					@ -199,21 +199,21 @@ pinos_main_loop_init (PinosMainLoop * loop)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_new:
 | 
					 * pinos_thread_main_loop_new:
 | 
				
			||||||
 * @context: a #GMainContext
 | 
					 * @context: a #GMainContext
 | 
				
			||||||
 * @name: a thread name
 | 
					 * @name: a thread name
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Make a new #PinosMainLoop that will run a mainloop on @context in
 | 
					 * Make a new #PinosThreadMainLoop that will run a mainloop on @context in
 | 
				
			||||||
 * a thread with @name.
 | 
					 * a thread with @name.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Returns: a #PinosMainLoop
 | 
					 * Returns: a #PinosThreadMainLoop
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
PinosMainLoop *
 | 
					PinosThreadMainLoop *
 | 
				
			||||||
pinos_main_loop_new (GMainContext * context, const gchar *name)
 | 
					pinos_thread_main_loop_new (GMainContext * context, const gchar *name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoop *loop;
 | 
					  PinosThreadMainLoop *loop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  loop = g_object_new (PINOS_TYPE_MAIN_LOOP,
 | 
					  loop = g_object_new (PINOS_TYPE_THREAD_MAIN_LOOP,
 | 
				
			||||||
                       "main-context", context,
 | 
					                       "main-context", context,
 | 
				
			||||||
                       "name", name,
 | 
					                       "name", name,
 | 
				
			||||||
                       NULL);
 | 
					                       NULL);
 | 
				
			||||||
| 
						 | 
					@ -221,8 +221,8 @@ pinos_main_loop_new (GMainContext * context, const gchar *name)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_get_impl:
 | 
					 * pinos_thread_main_loop_get_impl:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Get the #GMainLoop used by @loop.
 | 
					 * Get the #GMainLoop used by @loop.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -230,11 +230,11 @@ pinos_main_loop_new (GMainContext * context, const gchar *name)
 | 
				
			||||||
 *          @loop is valid.
 | 
					 *          @loop is valid.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
GMainLoop *
 | 
					GMainLoop *
 | 
				
			||||||
pinos_main_loop_get_impl (PinosMainLoop *loop)
 | 
					pinos_thread_main_loop_get_impl (PinosThreadMainLoop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), NULL);
 | 
					  g_return_val_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  priv = loop->priv;
 | 
					  priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -247,8 +247,8 @@ static gint
 | 
				
			||||||
do_poll (GPollFD *ufds, guint nfsd, gint timeout_)
 | 
					do_poll (GPollFD *ufds, guint nfsd, gint timeout_)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  gint res;
 | 
					  gint res;
 | 
				
			||||||
  PinosMainLoop *loop = g_private_get (&loop_key);
 | 
					  PinosThreadMainLoop *loop = g_private_get (&loop_key);
 | 
				
			||||||
  PinosMainLoopPrivate *priv = loop->priv;
 | 
					  PinosThreadMainLoopPrivate *priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_mutex_unlock (&priv->lock);
 | 
					  g_mutex_unlock (&priv->lock);
 | 
				
			||||||
  res = priv->poll_func (ufds, nfsd, timeout_);
 | 
					  res = priv->poll_func (ufds, nfsd, timeout_);
 | 
				
			||||||
| 
						 | 
					@ -258,9 +258,9 @@ do_poll (GPollFD *ufds, guint nfsd, gint timeout_)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gpointer
 | 
					static gpointer
 | 
				
			||||||
handle_mainloop (PinosMainLoop *loop)
 | 
					handle_mainloop (PinosThreadMainLoop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv = loop->priv;
 | 
					  PinosThreadMainLoopPrivate *priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_mutex_lock (&priv->lock);
 | 
					  g_mutex_lock (&priv->lock);
 | 
				
			||||||
  g_private_set (&loop_key, loop);
 | 
					  g_private_set (&loop_key, loop);
 | 
				
			||||||
| 
						 | 
					@ -269,9 +269,9 @@ handle_mainloop (PinosMainLoop *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 ("mainloop %p: run mainloop %p context %p", loop, priv->mainloop, priv->maincontext);
 | 
					  g_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 ("mainloop %p: done", loop);
 | 
					  g_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);
 | 
				
			||||||
| 
						 | 
					@ -283,8 +283,8 @@ handle_mainloop (PinosMainLoop *loop)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_start:
 | 
					 * pinos_thread_main_loop_start:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 * @error: am optional #GError
 | 
					 * @error: am optional #GError
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Start the thread to handle @loop.
 | 
					 * Start the thread to handle @loop.
 | 
				
			||||||
| 
						 | 
					@ -293,11 +293,11 @@ handle_mainloop (PinosMainLoop *loop)
 | 
				
			||||||
 *          and @error will contain more information.
 | 
					 *          and @error will contain more information.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
gboolean
 | 
					gboolean
 | 
				
			||||||
pinos_main_loop_start (PinosMainLoop *loop, GError **error)
 | 
					pinos_thread_main_loop_start (PinosThreadMainLoop *loop, GError **error)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), FALSE);
 | 
					  g_return_val_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop), FALSE);
 | 
				
			||||||
  priv = loop->priv;
 | 
					  priv = loop->priv;
 | 
				
			||||||
  g_return_val_if_fail (priv->thread == NULL, FALSE);
 | 
					  g_return_val_if_fail (priv->thread == NULL, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -307,21 +307,21 @@ pinos_main_loop_start (PinosMainLoop *loop, GError **error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_stop:
 | 
					 * pinos_thread_main_loop_stop:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Quit the main loop and stop its thread.
 | 
					 * Quit the main loop and stop its thread.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
pinos_main_loop_stop (PinosMainLoop *loop)
 | 
					pinos_thread_main_loop_stop (PinosThreadMainLoop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
 | 
					  g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
 | 
				
			||||||
  priv = loop->priv;
 | 
					  priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_if_fail (priv->thread != NULL);
 | 
					  g_return_if_fail (priv->thread != NULL);
 | 
				
			||||||
  g_return_if_fail (!pinos_main_loop_in_thread (loop));
 | 
					  g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_mutex_lock (&priv->lock);
 | 
					  g_mutex_lock (&priv->lock);
 | 
				
			||||||
  g_main_loop_quit (priv->mainloop);
 | 
					  g_main_loop_quit (priv->mainloop);
 | 
				
			||||||
| 
						 | 
					@ -332,54 +332,54 @@ pinos_main_loop_stop (PinosMainLoop *loop)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_lock:
 | 
					 * pinos_thread_main_loop_lock:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Lock the mutex associated with @loop.
 | 
					 * Lock the mutex associated with @loop.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
pinos_main_loop_lock (PinosMainLoop *loop)
 | 
					pinos_thread_main_loop_lock (PinosThreadMainLoop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
 | 
					  g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
 | 
				
			||||||
  priv = loop->priv;
 | 
					  priv = loop->priv;
 | 
				
			||||||
  g_return_if_fail (!pinos_main_loop_in_thread (loop));
 | 
					  g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_mutex_lock (&priv->lock);
 | 
					  g_mutex_lock (&priv->lock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_unlock:
 | 
					 * pinos_thread_main_loop_unlock:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Unlock the mutex associated with @loop.
 | 
					 * Unlock the mutex associated with @loop.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
pinos_main_loop_unlock (PinosMainLoop *loop)
 | 
					pinos_thread_main_loop_unlock (PinosThreadMainLoop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
 | 
					  g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
 | 
				
			||||||
  priv = loop->priv;
 | 
					  priv = loop->priv;
 | 
				
			||||||
  g_return_if_fail (!pinos_main_loop_in_thread (loop));
 | 
					  g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_mutex_unlock (&priv->lock);
 | 
					  g_mutex_unlock (&priv->lock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_signal:
 | 
					 * pinos_thread_main_loop_signal:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Signal the main thread of @loop. If @wait_for_accept is %TRUE,
 | 
					 * Signal the main thread of @loop. If @wait_for_accept is %TRUE,
 | 
				
			||||||
 * this function waits until pinos_main_loop_accept() is called.
 | 
					 * this function waits until pinos_thread_main_loop_accept() is called.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
pinos_main_loop_signal (PinosMainLoop *loop, gboolean wait_for_accept)
 | 
					pinos_thread_main_loop_signal (PinosThreadMainLoop *loop, gboolean wait_for_accept)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
 | 
					  g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
 | 
				
			||||||
  priv = loop->priv;
 | 
					  priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (priv->n_waiting > 0)
 | 
					  if (priv->n_waiting > 0)
 | 
				
			||||||
| 
						 | 
					@ -394,19 +394,19 @@ pinos_main_loop_signal (PinosMainLoop *loop, gboolean wait_for_accept)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_wait:
 | 
					 * pinos_thread_main_loop_wait:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Wait for the loop thread to call pinos_main_loop_signal().
 | 
					 * Wait for the loop thread to call pinos_thread_main_loop_signal().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
pinos_main_loop_wait (PinosMainLoop *loop)
 | 
					pinos_thread_main_loop_wait (PinosThreadMainLoop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
 | 
					  g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
 | 
				
			||||||
  priv = loop->priv;
 | 
					  priv = loop->priv;
 | 
				
			||||||
  g_return_if_fail (!pinos_main_loop_in_thread (loop));
 | 
					  g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  priv->n_waiting ++;
 | 
					  priv->n_waiting ++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -417,19 +417,19 @@ pinos_main_loop_wait (PinosMainLoop *loop)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_accept:
 | 
					 * pinos_thread_main_loop_accept:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Signal the loop thread waiting for accept with pinos_main_loop_signal().
 | 
					 * Signal the loop thread waiting for accept with pinos_thread_main_loop_signal().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
pinos_main_loop_accept (PinosMainLoop *loop)
 | 
					pinos_thread_main_loop_accept (PinosThreadMainLoop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
 | 
					  g_return_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop));
 | 
				
			||||||
  priv = loop->priv;
 | 
					  priv = loop->priv;
 | 
				
			||||||
  g_return_if_fail (!pinos_main_loop_in_thread (loop));
 | 
					  g_return_if_fail (!pinos_thread_main_loop_in_thread (loop));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_assert (priv->n_waiting_for_accept > 0);
 | 
					  g_assert (priv->n_waiting_for_accept > 0);
 | 
				
			||||||
  priv->n_waiting_for_accept--;
 | 
					  priv->n_waiting_for_accept--;
 | 
				
			||||||
| 
						 | 
					@ -438,17 +438,17 @@ pinos_main_loop_accept (PinosMainLoop *loop)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_main_loop_in_thread:
 | 
					 * pinos_thread_main_loop_in_thread:
 | 
				
			||||||
 * @loop: a #PinosMainLoop
 | 
					 * @loop: a #PinosThreadMainLoop
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Check if we are inside the thread of @loop.
 | 
					 * Check if we are inside the thread of @loop.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Returns: %TRUE when called inside the thread of @loop.
 | 
					 * Returns: %TRUE when called inside the thread of @loop.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
gboolean
 | 
					gboolean
 | 
				
			||||||
pinos_main_loop_in_thread (PinosMainLoop *loop)
 | 
					pinos_thread_main_loop_in_thread (PinosThreadMainLoop *loop)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), FALSE);
 | 
					  g_return_val_if_fail (PINOS_IS_THREAD_MAIN_LOOP (loop), FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return g_thread_self() == loop->priv->thread;
 | 
					  return g_thread_self() == loop->priv->thread;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										84
									
								
								pinos/client/thread-mainloop.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								pinos/client/thread-mainloop.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,84 @@
 | 
				
			||||||
 | 
					/* 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_THREAD_MAIN_LOOP_H__
 | 
				
			||||||
 | 
					#define __PINOS_THREAD_MAIN_LOOP_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <glib-object.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_BEGIN_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PINOS_TYPE_THREAD_MAIN_LOOP                 (pinos_thread_main_loop_get_type ())
 | 
				
			||||||
 | 
					#define PINOS_IS_THREAD_MAIN_LOOP(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_THREAD_MAIN_LOOP))
 | 
				
			||||||
 | 
					#define PINOS_IS_THREAD_MAIN_LOOP_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_THREAD_MAIN_LOOP))
 | 
				
			||||||
 | 
					#define PINOS_THREAD_MAIN_LOOP_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_THREAD_MAIN_LOOP, PinosThreadMainLoopClass))
 | 
				
			||||||
 | 
					#define PINOS_THREAD_MAIN_LOOP(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_THREAD_MAIN_LOOP, PinosThreadMainLoop))
 | 
				
			||||||
 | 
					#define PINOS_THREAD_MAIN_LOOP_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_THREAD_MAIN_LOOP, PinosThreadMainLoopClass))
 | 
				
			||||||
 | 
					#define PINOS_THREAD_MAIN_LOOP_CAST(obj)            ((PinosThreadMainLoop*)(obj))
 | 
				
			||||||
 | 
					#define PINOS_THREAD_MAIN_LOOP_CLASS_CAST(klass)    ((PinosThreadMainLoopClass*)(klass))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct _PinosThreadMainLoop PinosThreadMainLoop;
 | 
				
			||||||
 | 
					typedef struct _PinosThreadMainLoopClass PinosThreadMainLoopClass;
 | 
				
			||||||
 | 
					typedef struct _PinosThreadMainLoopPrivate PinosThreadMainLoopPrivate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * PinosThreadMainLoop:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Pinos main loop object class.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct _PinosThreadMainLoop {
 | 
				
			||||||
 | 
					  GObject object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  PinosThreadMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * PinosThreadMainLoopClass:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Pinos main loop object class.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct _PinosThreadMainLoopClass {
 | 
				
			||||||
 | 
					  GObjectClass parent_class;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* normal GObject stuff */
 | 
				
			||||||
 | 
					GType                  pinos_thread_main_loop_get_type        (void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PinosThreadMainLoop *  pinos_thread_main_loop_new             (GMainContext * context,
 | 
				
			||||||
 | 
					                                                               const gchar   *name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GMainLoop *            pinos_thread_main_loop_get_impl        (PinosThreadMainLoop *loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gboolean               pinos_thread_main_loop_start           (PinosThreadMainLoop *loop, GError **error);
 | 
				
			||||||
 | 
					void                   pinos_thread_main_loop_stop            (PinosThreadMainLoop *loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void                   pinos_thread_main_loop_lock            (PinosThreadMainLoop *loop);
 | 
				
			||||||
 | 
					void                   pinos_thread_main_loop_unlock          (PinosThreadMainLoop *loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void                   pinos_thread_main_loop_wait            (PinosThreadMainLoop *loop);
 | 
				
			||||||
 | 
					void                   pinos_thread_main_loop_signal          (PinosThreadMainLoop *loop, gboolean wait_for_accept);
 | 
				
			||||||
 | 
					void                   pinos_thread_main_loop_accept          (PinosThreadMainLoop *loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gboolean               pinos_thread_main_loop_in_thread       (PinosThreadMainLoop *loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_END_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* __PINOS_THREAD_MAIN_LOOP_H__ */
 | 
				
			||||||
| 
						 | 
					@ -451,7 +451,7 @@ context_state_notify (GObject    *gobject,
 | 
				
			||||||
            pinos_context_get_error (context)->message);
 | 
					            pinos_context_get_error (context)->message);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_signal (self->loop, FALSE);
 | 
					  pinos_thread_main_loop_signal (self->loop, FALSE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gboolean
 | 
					static gboolean
 | 
				
			||||||
| 
						 | 
					@ -465,23 +465,23 @@ gst_pinos_device_provider_start (GstDeviceProvider * provider)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  c = g_main_context_new ();
 | 
					  c = g_main_context_new ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!(self->loop = pinos_main_loop_new (c, "pinos-device-monitor"))) {
 | 
					  if (!(self->loop = pinos_thread_main_loop_new (c, "pinos-device-monitor"))) {
 | 
				
			||||||
    GST_ERROR_OBJECT (self, "Could not create pinos mainloop");
 | 
					    GST_ERROR_OBJECT (self, "Could not create pinos mainloop");
 | 
				
			||||||
    goto failed;
 | 
					    goto failed;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!pinos_main_loop_start (self->loop, &error)) {
 | 
					  if (!pinos_thread_main_loop_start (self->loop, &error)) {
 | 
				
			||||||
    GST_ERROR_OBJECT (self, "Could not start pinos mainloop: %s", error->message);
 | 
					    GST_ERROR_OBJECT (self, "Could not start pinos mainloop: %s", error->message);
 | 
				
			||||||
    g_clear_object (&self->loop);
 | 
					    g_clear_object (&self->loop);
 | 
				
			||||||
    goto failed;
 | 
					    goto failed;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (self->loop);
 | 
					  pinos_thread_main_loop_lock (self->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!(self->context = pinos_context_new (c, self->client_name, NULL))) {
 | 
					  if (!(self->context = pinos_context_new (c, self->client_name, NULL))) {
 | 
				
			||||||
    GST_ERROR_OBJECT (self, "Failed to create context");
 | 
					    GST_ERROR_OBJECT (self, "Failed to create context");
 | 
				
			||||||
    pinos_main_loop_unlock (self->loop);
 | 
					    pinos_thread_main_loop_unlock (self->loop);
 | 
				
			||||||
    pinos_main_loop_stop (self->loop);
 | 
					    pinos_thread_main_loop_stop (self->loop);
 | 
				
			||||||
    g_clear_object (&self->loop);
 | 
					    g_clear_object (&self->loop);
 | 
				
			||||||
    goto failed;
 | 
					    goto failed;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -515,7 +515,7 @@ gst_pinos_device_provider_start (GstDeviceProvider * provider)
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Wait until something happens */
 | 
					    /* Wait until something happens */
 | 
				
			||||||
    pinos_main_loop_wait (self->loop);
 | 
					    pinos_thread_main_loop_wait (self->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  GST_DEBUG_OBJECT (self, "connected");
 | 
					  GST_DEBUG_OBJECT (self, "connected");
 | 
				
			||||||
  pinos_context_get_daemon_info (self->context,
 | 
					  pinos_context_get_daemon_info (self->context,
 | 
				
			||||||
| 
						 | 
					@ -524,7 +524,7 @@ gst_pinos_device_provider_start (GstDeviceProvider * provider)
 | 
				
			||||||
                                 NULL,
 | 
					                                 NULL,
 | 
				
			||||||
                                 NULL,
 | 
					                                 NULL,
 | 
				
			||||||
                                 self);
 | 
					                                 self);
 | 
				
			||||||
  pinos_main_loop_unlock (self->loop);
 | 
					  pinos_thread_main_loop_unlock (self->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_main_context_unref (c);
 | 
					  g_main_context_unref (c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -537,8 +537,8 @@ failed:
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
not_running:
 | 
					not_running:
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    pinos_main_loop_unlock (self->loop);
 | 
					    pinos_thread_main_loop_unlock (self->loop);
 | 
				
			||||||
    pinos_main_loop_stop (self->loop);
 | 
					    pinos_thread_main_loop_stop (self->loop);
 | 
				
			||||||
    g_clear_object (&self->context);
 | 
					    g_clear_object (&self->context);
 | 
				
			||||||
    g_clear_object (&self->loop);
 | 
					    g_clear_object (&self->loop);
 | 
				
			||||||
    return TRUE;
 | 
					    return TRUE;
 | 
				
			||||||
| 
						 | 
					@ -554,7 +554,7 @@ gst_pinos_device_provider_stop (GstDeviceProvider * provider)
 | 
				
			||||||
    pinos_context_disconnect (self->context);
 | 
					    pinos_context_disconnect (self->context);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (self->loop) {
 | 
					  if (self->loop) {
 | 
				
			||||||
    pinos_main_loop_stop (self->loop);
 | 
					    pinos_thread_main_loop_stop (self->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  g_clear_object (&self->context);
 | 
					  g_clear_object (&self->context);
 | 
				
			||||||
  g_clear_object (&self->loop);
 | 
					  g_clear_object (&self->loop);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -82,7 +82,7 @@ struct _GstPinosDeviceProvider {
 | 
				
			||||||
  gchar *client_name;
 | 
					  gchar *client_name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  GMainContext *maincontext;
 | 
					  GMainContext *maincontext;
 | 
				
			||||||
  PinosMainLoop *loop;
 | 
					  PinosThreadMainLoop *loop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosContext *context;
 | 
					  PinosContext *context;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -415,7 +415,7 @@ on_add_buffer (GObject    *gobject,
 | 
				
			||||||
  gst_pinos_pool_add_buffer (pinossink->pool, buf);
 | 
					  gst_pinos_pool_add_buffer (pinossink->pool, buf);
 | 
				
			||||||
  g_hash_table_insert (pinossink->buf_ids, GINT_TO_POINTER (id), buf);
 | 
					  g_hash_table_insert (pinossink->buf_ids, GINT_TO_POINTER (id), buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_signal (pinossink->loop, FALSE);
 | 
					  pinos_thread_main_loop_signal (pinossink->loop, FALSE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -450,7 +450,7 @@ on_new_buffer (GObject    *gobject,
 | 
				
			||||||
  buf = g_hash_table_lookup (pinossink->buf_ids, GINT_TO_POINTER (id));
 | 
					  buf = g_hash_table_lookup (pinossink->buf_ids, GINT_TO_POINTER (id));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (buf) {
 | 
					  if (buf) {
 | 
				
			||||||
    pinos_main_loop_signal (pinossink->loop, FALSE);
 | 
					    pinos_thread_main_loop_signal (pinossink->loop, FALSE);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -479,7 +479,7 @@ on_stream_notify (GObject    *gobject,
 | 
				
			||||||
            pinos_stream_get_error (stream)->message), (NULL));
 | 
					            pinos_stream_get_error (stream)->message), (NULL));
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_signal (pinossink->loop, FALSE);
 | 
					  pinos_thread_main_loop_signal (pinossink->loop, FALSE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -528,7 +528,7 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  possible = gst_caps_to_format_all (caps);
 | 
					  possible = gst_caps_to_format_all (caps);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossink->loop);
 | 
					  pinos_thread_main_loop_lock (pinossink->loop);
 | 
				
			||||||
  state = pinos_stream_get_state (pinossink->stream);
 | 
					  state = pinos_stream_get_state (pinossink->stream);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (state == PINOS_STREAM_STATE_ERROR)
 | 
					  if (state == PINOS_STREAM_STATE_ERROR)
 | 
				
			||||||
| 
						 | 
					@ -556,7 +556,7 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
 | 
				
			||||||
      if (state == PINOS_STREAM_STATE_ERROR)
 | 
					      if (state == PINOS_STREAM_STATE_ERROR)
 | 
				
			||||||
        goto start_error;
 | 
					        goto start_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      pinos_main_loop_wait (pinossink->loop);
 | 
					      pinos_thread_main_loop_wait (pinossink->loop);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  res = TRUE;
 | 
					  res = TRUE;
 | 
				
			||||||
| 
						 | 
					@ -574,11 +574,11 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
 | 
				
			||||||
      if (state == PINOS_STREAM_STATE_ERROR)
 | 
					      if (state == PINOS_STREAM_STATE_ERROR)
 | 
				
			||||||
        goto start_error;
 | 
					        goto start_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      pinos_main_loop_wait (pinossink->loop);
 | 
					      pinos_thread_main_loop_wait (pinossink->loop);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  pinos_main_loop_unlock (pinossink->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinossink->negotiated = res;
 | 
					  pinossink->negotiated = res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -587,7 +587,7 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
 | 
				
			||||||
start_error:
 | 
					start_error:
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    GST_ERROR ("could not start stream");
 | 
					    GST_ERROR ("could not start stream");
 | 
				
			||||||
    pinos_main_loop_unlock (pinossink->loop);
 | 
					    pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
    g_ptr_array_unref (possible);
 | 
					    g_ptr_array_unref (possible);
 | 
				
			||||||
    return FALSE;
 | 
					    return FALSE;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -606,7 +606,7 @@ gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
 | 
				
			||||||
  if (!pinossink->negotiated)
 | 
					  if (!pinossink->negotiated)
 | 
				
			||||||
    goto not_negotiated;
 | 
					    goto not_negotiated;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossink->loop);
 | 
					  pinos_thread_main_loop_lock (pinossink->loop);
 | 
				
			||||||
  if (pinos_stream_get_state (pinossink->stream) != PINOS_STREAM_STATE_STREAMING)
 | 
					  if (pinos_stream_get_state (pinossink->stream) != PINOS_STREAM_STATE_STREAMING)
 | 
				
			||||||
    goto done;
 | 
					    goto done;
 | 
				
			||||||
//    goto streaming_error;
 | 
					//    goto streaming_error;
 | 
				
			||||||
| 
						 | 
					@ -639,7 +639,7 @@ gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
 | 
				
			||||||
    g_warning ("can't send buffer");
 | 
					    g_warning ("can't send buffer");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
done:
 | 
					done:
 | 
				
			||||||
  pinos_main_loop_unlock (pinossink->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return GST_FLOW_OK;
 | 
					  return GST_FLOW_OK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -649,7 +649,7 @@ not_negotiated:
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
//streaming_error:
 | 
					//streaming_error:
 | 
				
			||||||
//  {
 | 
					//  {
 | 
				
			||||||
//    pinos_main_loop_unlock (pinossink->loop);
 | 
					//    pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
//    return GST_FLOW_ERROR;
 | 
					//    return GST_FLOW_ERROR;
 | 
				
			||||||
//  }
 | 
					//  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -683,7 +683,7 @@ gst_pinos_sink_start (GstBaseSink * basesink)
 | 
				
			||||||
    props = NULL;
 | 
					    props = NULL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossink->loop);
 | 
					  pinos_thread_main_loop_lock (pinossink->loop);
 | 
				
			||||||
  pinossink->stream = pinos_stream_new (pinossink->ctx, pinossink->client_name, props);
 | 
					  pinossink->stream = pinos_stream_new (pinossink->ctx, pinossink->client_name, props);
 | 
				
			||||||
  pinossink->pool->stream = pinossink->stream;
 | 
					  pinossink->pool->stream = pinossink->stream;
 | 
				
			||||||
  g_signal_connect (pinossink->stream, "notify::state", (GCallback) on_stream_notify, pinossink);
 | 
					  g_signal_connect (pinossink->stream, "notify::state", (GCallback) on_stream_notify, pinossink);
 | 
				
			||||||
| 
						 | 
					@ -691,7 +691,7 @@ gst_pinos_sink_start (GstBaseSink * basesink)
 | 
				
			||||||
  g_signal_connect (pinossink->stream, "add-buffer", (GCallback) on_add_buffer, pinossink);
 | 
					  g_signal_connect (pinossink->stream, "add-buffer", (GCallback) on_add_buffer, pinossink);
 | 
				
			||||||
  g_signal_connect (pinossink->stream, "remove-buffer", (GCallback) on_remove_buffer, pinossink);
 | 
					  g_signal_connect (pinossink->stream, "remove-buffer", (GCallback) on_remove_buffer, pinossink);
 | 
				
			||||||
  g_signal_connect (pinossink->stream, "new-buffer", (GCallback) on_new_buffer, pinossink);
 | 
					  g_signal_connect (pinossink->stream, "new-buffer", (GCallback) on_new_buffer, pinossink);
 | 
				
			||||||
  pinos_main_loop_unlock (pinossink->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -701,14 +701,14 @@ gst_pinos_sink_stop (GstBaseSink * basesink)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GstPinosSink *pinossink = GST_PINOS_SINK (basesink);
 | 
					  GstPinosSink *pinossink = GST_PINOS_SINK (basesink);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossink->loop);
 | 
					  pinos_thread_main_loop_lock (pinossink->loop);
 | 
				
			||||||
  if (pinossink->stream) {
 | 
					  if (pinossink->stream) {
 | 
				
			||||||
    pinos_stream_stop (pinossink->stream);
 | 
					    pinos_stream_stop (pinossink->stream);
 | 
				
			||||||
    pinos_stream_disconnect (pinossink->stream);
 | 
					    pinos_stream_disconnect (pinossink->stream);
 | 
				
			||||||
    g_clear_object (&pinossink->stream);
 | 
					    g_clear_object (&pinossink->stream);
 | 
				
			||||||
    pinossink->pool->stream = NULL;
 | 
					    pinossink->pool->stream = NULL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_unlock (pinossink->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinossink->negotiated = FALSE;
 | 
					  pinossink->negotiated = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -738,7 +738,7 @@ on_context_notify (GObject    *gobject,
 | 
				
			||||||
            pinos_context_get_error (pinossink->ctx)->message), (NULL));
 | 
					            pinos_context_get_error (pinossink->ctx)->message), (NULL));
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_signal (pinossink->loop, FALSE);
 | 
					  pinos_thread_main_loop_signal (pinossink->loop, FALSE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gboolean
 | 
					static gboolean
 | 
				
			||||||
| 
						 | 
					@ -749,11 +749,11 @@ gst_pinos_sink_open (GstPinosSink * pinossink)
 | 
				
			||||||
  pinossink->context = g_main_context_new ();
 | 
					  pinossink->context = g_main_context_new ();
 | 
				
			||||||
  GST_DEBUG ("context %p", pinossink->context);
 | 
					  GST_DEBUG ("context %p", pinossink->context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinossink->loop = pinos_main_loop_new (pinossink->context, "pinos-sink-loop");
 | 
					  pinossink->loop = pinos_thread_main_loop_new (pinossink->context, "pinos-sink-loop");
 | 
				
			||||||
  if (!pinos_main_loop_start (pinossink->loop, &error))
 | 
					  if (!pinos_thread_main_loop_start (pinossink->loop, &error))
 | 
				
			||||||
    goto mainloop_error;
 | 
					    goto mainloop_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossink->loop);
 | 
					  pinos_thread_main_loop_lock (pinossink->loop);
 | 
				
			||||||
  pinossink->ctx = pinos_context_new (pinossink->context, g_get_application_name (), NULL);
 | 
					  pinossink->ctx = pinos_context_new (pinossink->context, g_get_application_name (), NULL);
 | 
				
			||||||
  g_signal_connect (pinossink->ctx, "notify::state", (GCallback) on_context_notify, pinossink);
 | 
					  g_signal_connect (pinossink->ctx, "notify::state", (GCallback) on_context_notify, pinossink);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -768,9 +768,9 @@ gst_pinos_sink_open (GstPinosSink * pinossink)
 | 
				
			||||||
    if (state == PINOS_CONTEXT_STATE_ERROR)
 | 
					    if (state == PINOS_CONTEXT_STATE_ERROR)
 | 
				
			||||||
      goto connect_error;
 | 
					      goto connect_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pinos_main_loop_wait (pinossink->loop);
 | 
					    pinos_thread_main_loop_wait (pinossink->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_unlock (pinossink->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -783,7 +783,7 @@ mainloop_error:
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
connect_error:
 | 
					connect_error:
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    pinos_main_loop_unlock (pinossink->loop);
 | 
					    pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
    return FALSE;
 | 
					    return FALSE;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -791,7 +791,7 @@ connect_error:
 | 
				
			||||||
static gboolean
 | 
					static gboolean
 | 
				
			||||||
gst_pinos_sink_close (GstPinosSink * pinossink)
 | 
					gst_pinos_sink_close (GstPinosSink * pinossink)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  pinos_main_loop_lock (pinossink->loop);
 | 
					  pinos_thread_main_loop_lock (pinossink->loop);
 | 
				
			||||||
  if (pinossink->stream) {
 | 
					  if (pinossink->stream) {
 | 
				
			||||||
    pinos_stream_disconnect (pinossink->stream);
 | 
					    pinos_stream_disconnect (pinossink->stream);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -807,12 +807,12 @@ gst_pinos_sink_close (GstPinosSink * pinossink)
 | 
				
			||||||
      if (state == PINOS_CONTEXT_STATE_ERROR)
 | 
					      if (state == PINOS_CONTEXT_STATE_ERROR)
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      pinos_main_loop_wait (pinossink->loop);
 | 
					      pinos_thread_main_loop_wait (pinossink->loop);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_unlock (pinossink->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossink->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_stop (pinossink->loop);
 | 
					  pinos_thread_main_loop_stop (pinossink->loop);
 | 
				
			||||||
  g_clear_object (&pinossink->loop);
 | 
					  g_clear_object (&pinossink->loop);
 | 
				
			||||||
  g_clear_object (&pinossink->stream);
 | 
					  g_clear_object (&pinossink->stream);
 | 
				
			||||||
  g_clear_object (&pinossink->ctx);
 | 
					  g_clear_object (&pinossink->ctx);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,7 +78,7 @@ struct _GstPinosSink {
 | 
				
			||||||
  gboolean negotiated;
 | 
					  gboolean negotiated;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  GMainContext *context;
 | 
					  GMainContext *context;
 | 
				
			||||||
  PinosMainLoop *loop;
 | 
					  PinosThreadMainLoop *loop;
 | 
				
			||||||
  PinosContext *ctx;
 | 
					  PinosContext *ctx;
 | 
				
			||||||
  PinosStream *stream;
 | 
					  PinosStream *stream;
 | 
				
			||||||
  GstAllocator *allocator;
 | 
					  GstAllocator *allocator;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -479,7 +479,7 @@ on_new_buffer (GObject    *gobject,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    g_queue_push_tail (&pinossrc->queue, buf);
 | 
					    g_queue_push_tail (&pinossrc->queue, buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pinos_main_loop_signal (pinossrc->loop, FALSE);
 | 
					    pinos_thread_main_loop_signal (pinossrc->loop, FALSE);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return;
 | 
					  return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -507,7 +507,7 @@ on_stream_notify (GObject    *gobject,
 | 
				
			||||||
            pinos_stream_get_error (pinossrc->stream)->message), (NULL));
 | 
					            pinos_stream_get_error (pinossrc->stream)->message), (NULL));
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_signal (pinossrc->loop, FALSE);
 | 
					  pinos_thread_main_loop_signal (pinossrc->loop, FALSE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -536,7 +536,7 @@ gst_pinos_src_stream_start (GstPinosSrc *pinossrc)
 | 
				
			||||||
  gboolean res;
 | 
					  gboolean res;
 | 
				
			||||||
  PinosProperties *props;
 | 
					  PinosProperties *props;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  res = pinos_stream_start (pinossrc->stream);
 | 
					  res = pinos_stream_start (pinossrc->stream);
 | 
				
			||||||
  while (TRUE) {
 | 
					  while (TRUE) {
 | 
				
			||||||
    PinosStreamState state = pinos_stream_get_state (pinossrc->stream);
 | 
					    PinosStreamState state = pinos_stream_get_state (pinossrc->stream);
 | 
				
			||||||
| 
						 | 
					@ -547,26 +547,26 @@ gst_pinos_src_stream_start (GstPinosSrc *pinossrc)
 | 
				
			||||||
    if (state == PINOS_STREAM_STATE_ERROR)
 | 
					    if (state == PINOS_STREAM_STATE_ERROR)
 | 
				
			||||||
      goto start_error;
 | 
					      goto start_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pinos_main_loop_wait (pinossrc->loop);
 | 
					    pinos_thread_main_loop_wait (pinossrc->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_object_get (pinossrc->stream, "properties", &props, NULL);
 | 
					  g_object_get (pinossrc->stream, "properties", &props, NULL);
 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  parse_stream_properties (pinossrc, props);
 | 
					  parse_stream_properties (pinossrc, props);
 | 
				
			||||||
  pinos_properties_free (props);
 | 
					  pinos_properties_free (props);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  pinossrc->started = TRUE;
 | 
					  pinossrc->started = TRUE;
 | 
				
			||||||
  pinos_main_loop_signal (pinossrc->loop, FALSE);
 | 
					  pinos_thread_main_loop_signal (pinossrc->loop, FALSE);
 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return res;
 | 
					  return res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
start_error:
 | 
					start_error:
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    GST_DEBUG_OBJECT (pinossrc, "error starting stream");
 | 
					    GST_DEBUG_OBJECT (pinossrc, "error starting stream");
 | 
				
			||||||
    pinos_main_loop_unlock (pinossrc->loop);
 | 
					    pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
    return FALSE;
 | 
					    return FALSE;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -576,7 +576,7 @@ wait_negotiated (GstPinosSrc *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosStreamState state;
 | 
					  PinosStreamState state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (this->loop);
 | 
					  pinos_thread_main_loop_lock (this->loop);
 | 
				
			||||||
  while (TRUE) {
 | 
					  while (TRUE) {
 | 
				
			||||||
    state = pinos_stream_get_state (this->stream);
 | 
					    state = pinos_stream_get_state (this->stream);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -586,9 +586,9 @@ wait_negotiated (GstPinosSrc *this)
 | 
				
			||||||
    if (this->started)
 | 
					    if (this->started)
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pinos_main_loop_wait (this->loop);
 | 
					    pinos_thread_main_loop_wait (this->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_unlock (this->loop);
 | 
					  pinos_thread_main_loop_unlock (this->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return state;
 | 
					  return state;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -633,7 +633,7 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc)
 | 
				
			||||||
  possible = gst_caps_to_format_all (caps);
 | 
					  possible = gst_caps_to_format_all (caps);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* first disconnect */
 | 
					  /* first disconnect */
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  if (pinos_stream_get_state (pinossrc->stream) != PINOS_STREAM_STATE_UNCONNECTED) {
 | 
					  if (pinos_stream_get_state (pinossrc->stream) != PINOS_STREAM_STATE_UNCONNECTED) {
 | 
				
			||||||
    GST_DEBUG_OBJECT (basesrc, "disconnect capture");
 | 
					    GST_DEBUG_OBJECT (basesrc, "disconnect capture");
 | 
				
			||||||
    pinos_stream_disconnect (pinossrc->stream);
 | 
					    pinos_stream_disconnect (pinossrc->stream);
 | 
				
			||||||
| 
						 | 
					@ -648,7 +648,7 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc)
 | 
				
			||||||
        goto connect_error;
 | 
					        goto connect_error;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      pinos_main_loop_wait (pinossrc->loop);
 | 
					      pinos_thread_main_loop_wait (pinossrc->loop);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -669,9 +669,9 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc)
 | 
				
			||||||
    if (state == PINOS_STREAM_STATE_ERROR)
 | 
					    if (state == PINOS_STREAM_STATE_ERROR)
 | 
				
			||||||
      goto connect_error;
 | 
					      goto connect_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pinos_main_loop_wait (pinossrc->loop);
 | 
					    pinos_thread_main_loop_wait (pinossrc->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  result = gst_pinos_src_stream_start (pinossrc);
 | 
					  result = gst_pinos_src_stream_start (pinossrc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -706,7 +706,7 @@ no_common_caps:
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
connect_error:
 | 
					connect_error:
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    pinos_main_loop_unlock (pinossrc->loop);
 | 
					    pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
    return FALSE;
 | 
					    return FALSE;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -747,11 +747,11 @@ gst_pinos_src_unlock (GstBaseSrc * basesrc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GstPinosSrc *pinossrc = GST_PINOS_SRC (basesrc);
 | 
					  GstPinosSrc *pinossrc = GST_PINOS_SRC (basesrc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  GST_DEBUG_OBJECT (pinossrc, "setting flushing");
 | 
					  GST_DEBUG_OBJECT (pinossrc, "setting flushing");
 | 
				
			||||||
  pinossrc->flushing = TRUE;
 | 
					  pinossrc->flushing = TRUE;
 | 
				
			||||||
  pinos_main_loop_signal (pinossrc->loop, FALSE);
 | 
					  pinos_thread_main_loop_signal (pinossrc->loop, FALSE);
 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -761,10 +761,10 @@ gst_pinos_src_unlock_stop (GstBaseSrc * basesrc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GstPinosSrc *pinossrc = GST_PINOS_SRC (basesrc);
 | 
					  GstPinosSrc *pinossrc = GST_PINOS_SRC (basesrc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  GST_DEBUG_OBJECT (pinossrc, "unsetting flushing");
 | 
					  GST_DEBUG_OBJECT (pinossrc, "unsetting flushing");
 | 
				
			||||||
  pinossrc->flushing = FALSE;
 | 
					  pinossrc->flushing = FALSE;
 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -850,7 +850,7 @@ gst_pinos_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
 | 
				
			||||||
  if (!pinossrc->negotiated)
 | 
					  if (!pinossrc->negotiated)
 | 
				
			||||||
    goto not_negotiated;
 | 
					    goto not_negotiated;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  while (TRUE) {
 | 
					  while (TRUE) {
 | 
				
			||||||
    PinosStreamState state;
 | 
					    PinosStreamState state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -868,9 +868,9 @@ gst_pinos_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
 | 
				
			||||||
    if (*buffer != NULL)
 | 
					    if (*buffer != NULL)
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pinos_main_loop_wait (pinossrc->loop);
 | 
					    pinos_thread_main_loop_wait (pinossrc->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (pinossrc->is_live)
 | 
					  if (pinossrc->is_live)
 | 
				
			||||||
    base_time = GST_ELEMENT_CAST (psrc)->base_time;
 | 
					    base_time = GST_ELEMENT_CAST (psrc)->base_time;
 | 
				
			||||||
| 
						 | 
					@ -901,12 +901,12 @@ not_negotiated:
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
streaming_error:
 | 
					streaming_error:
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    pinos_main_loop_unlock (pinossrc->loop);
 | 
					    pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
    return GST_FLOW_ERROR;
 | 
					    return GST_FLOW_ERROR;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
streaming_stopped:
 | 
					streaming_stopped:
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    pinos_main_loop_unlock (pinossrc->loop);
 | 
					    pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
    return GST_FLOW_FLUSHING;
 | 
					    return GST_FLOW_FLUSHING;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -931,9 +931,9 @@ gst_pinos_src_stop (GstBaseSrc * basesrc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinossrc = GST_PINOS_SRC (basesrc);
 | 
					  pinossrc = GST_PINOS_SRC (basesrc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  clear_queue (pinossrc);
 | 
					  clear_queue (pinossrc);
 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -959,7 +959,7 @@ on_context_notify (GObject    *gobject,
 | 
				
			||||||
            pinos_context_get_error (pinossrc->ctx)->message), (NULL));
 | 
					            pinos_context_get_error (pinossrc->ctx)->message), (NULL));
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  pinos_main_loop_signal (pinossrc->loop, FALSE);
 | 
					  pinos_thread_main_loop_signal (pinossrc->loop, FALSE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gboolean
 | 
					static gboolean
 | 
				
			||||||
| 
						 | 
					@ -985,11 +985,11 @@ gst_pinos_src_open (GstPinosSrc * pinossrc)
 | 
				
			||||||
  pinossrc->context = g_main_context_new ();
 | 
					  pinossrc->context = g_main_context_new ();
 | 
				
			||||||
  GST_DEBUG ("context %p", pinossrc->context);
 | 
					  GST_DEBUG ("context %p", pinossrc->context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinossrc->loop = pinos_main_loop_new (pinossrc->context, "pinos-main-loop");
 | 
					  pinossrc->loop = pinos_thread_main_loop_new (pinossrc->context, "pinos-main-loop");
 | 
				
			||||||
  if (!pinos_main_loop_start (pinossrc->loop, &error))
 | 
					  if (!pinos_thread_main_loop_start (pinossrc->loop, &error))
 | 
				
			||||||
    goto mainloop_failed;
 | 
					    goto mainloop_failed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  pinossrc->ctx = pinos_context_new (pinossrc->context, g_get_application_name (), NULL);
 | 
					  pinossrc->ctx = pinos_context_new (pinossrc->context, g_get_application_name (), NULL);
 | 
				
			||||||
  g_signal_connect (pinossrc->ctx, "notify::state", (GCallback) on_context_notify, pinossrc);
 | 
					  g_signal_connect (pinossrc->ctx, "notify::state", (GCallback) on_context_notify, pinossrc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1004,7 +1004,7 @@ gst_pinos_src_open (GstPinosSrc * pinossrc)
 | 
				
			||||||
    if (state == PINOS_CONTEXT_STATE_ERROR)
 | 
					    if (state == PINOS_CONTEXT_STATE_ERROR)
 | 
				
			||||||
      goto connect_error;
 | 
					      goto connect_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pinos_main_loop_wait (pinossrc->loop);
 | 
					    pinos_thread_main_loop_wait (pinossrc->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (pinossrc->properties) {
 | 
					  if (pinossrc->properties) {
 | 
				
			||||||
| 
						 | 
					@ -1021,7 +1021,7 @@ gst_pinos_src_open (GstPinosSrc * pinossrc)
 | 
				
			||||||
  g_signal_connect (pinossrc->stream, "remove-buffer", (GCallback) on_remove_buffer, pinossrc);
 | 
					  g_signal_connect (pinossrc->stream, "remove-buffer", (GCallback) on_remove_buffer, pinossrc);
 | 
				
			||||||
  g_signal_connect (pinossrc->stream, "new-buffer", (GCallback) on_new_buffer, pinossrc);
 | 
					  g_signal_connect (pinossrc->stream, "new-buffer", (GCallback) on_new_buffer, pinossrc);
 | 
				
			||||||
  pinossrc->clock = gst_pinos_clock_new (pinossrc->stream);
 | 
					  pinossrc->clock = gst_pinos_clock_new (pinossrc->stream);
 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1034,7 +1034,7 @@ mainloop_failed:
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
connect_error:
 | 
					connect_error:
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    pinos_main_loop_unlock (pinossrc->loop);
 | 
					    pinos_thread_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
    return FALSE;
 | 
					    return FALSE;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1042,7 +1042,7 @@ connect_error:
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
gst_pinos_src_close (GstPinosSrc * pinossrc)
 | 
					gst_pinos_src_close (GstPinosSrc * pinossrc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  pinos_main_loop_stop (pinossrc->loop);
 | 
					  pinos_thread_main_loop_stop (pinossrc->loop);
 | 
				
			||||||
  g_clear_object (&pinossrc->loop);
 | 
					  g_clear_object (&pinossrc->loop);
 | 
				
			||||||
  g_clear_object (&pinossrc->ctx);
 | 
					  g_clear_object (&pinossrc->ctx);
 | 
				
			||||||
  g_main_context_unref (pinossrc->context);
 | 
					  g_main_context_unref (pinossrc->context);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,7 +64,7 @@ struct _GstPinosSrc {
 | 
				
			||||||
  GstClockTime max_latency;
 | 
					  GstClockTime max_latency;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  GMainContext *context;
 | 
					  GMainContext *context;
 | 
				
			||||||
  PinosMainLoop *loop;
 | 
					  PinosThreadMainLoop *loop;
 | 
				
			||||||
  PinosContext *ctx;
 | 
					  PinosContext *ctx;
 | 
				
			||||||
  PinosStream *stream;
 | 
					  PinosStream *stream;
 | 
				
			||||||
  GstAllocator *fd_allocator;
 | 
					  GstAllocator *fd_allocator;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1111,8 +1111,6 @@ parse_connection (SpaProxy   *this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      case PINOS_CONTROL_CMD_ADD_MEM:
 | 
					      case PINOS_CONTROL_CMD_ADD_MEM:
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      case PINOS_CONTROL_CMD_REMOVE_MEM:
 | 
					 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
      case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
					      case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1152,7 +1150,6 @@ parse_rtconnection (SpaProxy   *this)
 | 
				
			||||||
      case PINOS_CONTROL_CMD_SET_PROPERTY:
 | 
					      case PINOS_CONTROL_CMD_SET_PROPERTY:
 | 
				
			||||||
      case PINOS_CONTROL_CMD_NODE_COMMAND:
 | 
					      case PINOS_CONTROL_CMD_NODE_COMMAND:
 | 
				
			||||||
      case PINOS_CONTROL_CMD_ADD_MEM:
 | 
					      case PINOS_CONTROL_CMD_ADD_MEM:
 | 
				
			||||||
      case PINOS_CONTROL_CMD_REMOVE_MEM:
 | 
					 | 
				
			||||||
      case PINOS_CONTROL_CMD_USE_BUFFERS:
 | 
					      case PINOS_CONTROL_CMD_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 connection %d\n", this, cmd);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,8 @@
 | 
				
			||||||
#include "pinos/server/dbus-client-node.h"
 | 
					#include "pinos/server/dbus-client-node.h"
 | 
				
			||||||
#include "pinos/server/client.h"
 | 
					#include "pinos/server/client.h"
 | 
				
			||||||
#include "pinos/server/link.h"
 | 
					#include "pinos/server/link.h"
 | 
				
			||||||
#include "pinos/server/rt-loop.h"
 | 
					#include "pinos/server/data-loop.h"
 | 
				
			||||||
 | 
					#include "pinos/server/main-loop.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "pinos/dbus/org-pinos.h"
 | 
					#include "pinos/dbus/org-pinos.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,7 +53,8 @@ struct _PinosDaemonPrivate
 | 
				
			||||||
  GList *nodes;
 | 
					  GList *nodes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  GHashTable *clients;
 | 
					  GHashTable *clients;
 | 
				
			||||||
  PinosRTLoop *loop;
 | 
					  PinosDataLoop *data_loop;
 | 
				
			||||||
 | 
					  PinosMainLoop *main_loop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosProperties *properties;
 | 
					  PinosProperties *properties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,7 +62,6 @@ struct _PinosDaemonPrivate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  SpaSupport support[4];
 | 
					  SpaSupport support[4];
 | 
				
			||||||
  SpaLog log;
 | 
					  SpaLog log;
 | 
				
			||||||
  SpaPoll main_loop;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum
 | 
					enum
 | 
				
			||||||
| 
						 | 
					@ -71,6 +72,7 @@ enum
 | 
				
			||||||
  PROP_OBJECT_PATH,
 | 
					  PROP_OBJECT_PATH,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
handle_client_appeared (PinosClient *client, gpointer user_data)
 | 
					handle_client_appeared (PinosClient *client, gpointer user_data)
 | 
				
			||||||
| 
						 | 
					@ -197,27 +199,30 @@ no_node:
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_node_remove_signal (PinosNode   *node,
 | 
					on_node_remove_signal (PinosNode   *node,
 | 
				
			||||||
                       PinosDaemon *daemon)
 | 
					                       PinosDaemon *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  g_debug ("daemon %p: node %p remove", daemon, node);
 | 
					  g_debug ("daemon %p: node %p remove", this, node);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_link_input_unlinked (PinosLink   *link,
 | 
					on_link_input_unlinked (PinosLink   *link,
 | 
				
			||||||
                        PinosPort   *port,
 | 
					                        PinosPort   *port,
 | 
				
			||||||
                        PinosDaemon *daemon)
 | 
					                        PinosDaemon *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  g_debug ("daemon %p: link %p: input unlinked", daemon, link);
 | 
					  g_debug ("daemon %p: link %p: input unlinked", this, link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_link_output_unlinked (PinosLink   *link,
 | 
					on_link_output_unlinked (PinosLink   *link,
 | 
				
			||||||
                         PinosPort   *port,
 | 
					                         PinosPort   *port,
 | 
				
			||||||
                         PinosDaemon *daemon)
 | 
					                         PinosDaemon *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  g_debug ("daemon %p: link %p: output unlinked", daemon, link);
 | 
					  g_debug ("daemon %p: link %p: output unlinked", this, link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  try_link_port (link->input->node, link->input, this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -245,6 +250,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);
 | 
					      g_debug ("daemon %p: link %p: unlinked", daemon, link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if 0
 | 
				
			||||||
      g_set_error (&error,
 | 
					      g_set_error (&error,
 | 
				
			||||||
                   PINOS_ERROR,
 | 
					                   PINOS_ERROR,
 | 
				
			||||||
                   PINOS_ERROR_NODE_LINK,
 | 
					                   PINOS_ERROR_NODE_LINK,
 | 
				
			||||||
| 
						 | 
					@ -254,6 +260,7 @@ on_link_state_notify (GObject     *obj,
 | 
				
			||||||
        pinos_node_report_error (link->input->node, g_error_copy (error));
 | 
					        pinos_node_report_error (link->input->node, g_error_copy (error));
 | 
				
			||||||
      if (link->output && link->output->node)
 | 
					      if (link->output && link->output->node)
 | 
				
			||||||
        pinos_node_report_error (link->output->node, g_error_copy (error));
 | 
					        pinos_node_report_error (link->output->node, g_error_copy (error));
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case PINOS_LINK_STATE_INIT:
 | 
					    case PINOS_LINK_STATE_INIT:
 | 
				
			||||||
| 
						 | 
					@ -266,14 +273,13 @@ on_link_state_notify (GObject     *obj,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
 | 
					try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosClient *client;
 | 
					  PinosClient *client;
 | 
				
			||||||
  PinosProperties *props;
 | 
					  PinosProperties *props;
 | 
				
			||||||
  const gchar *path;
 | 
					  const gchar *path;
 | 
				
			||||||
  GError *error = NULL;
 | 
					  GError *error = NULL;
 | 
				
			||||||
  PinosLink *link;
 | 
					  PinosLink *link;
 | 
				
			||||||
  PinosDirection direction = port->direction;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  props = pinos_node_get_properties (node);
 | 
					  props = pinos_node_get_properties (node);
 | 
				
			||||||
  if (props == NULL)
 | 
					  if (props == NULL)
 | 
				
			||||||
| 
						 | 
					@ -285,16 +291,15 @@ on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
 | 
				
			||||||
    PinosPort *target;
 | 
					    PinosPort *target;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    target = pinos_daemon_find_port (this,
 | 
					    target = pinos_daemon_find_port (this,
 | 
				
			||||||
                                     pinos_direction_reverse (direction),
 | 
					                                     port,
 | 
				
			||||||
                                     path,
 | 
					                                     path,
 | 
				
			||||||
                                     NULL,
 | 
					                                     NULL,
 | 
				
			||||||
                                     0,
 | 
					 | 
				
			||||||
                                     NULL,
 | 
					                                     NULL,
 | 
				
			||||||
                                     &error);
 | 
					                                     &error);
 | 
				
			||||||
    if (target == NULL)
 | 
					    if (target == NULL)
 | 
				
			||||||
      goto error;
 | 
					      goto error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (direction == PINOS_DIRECTION_OUTPUT)
 | 
					    if (port->direction == PINOS_DIRECTION_OUTPUT)
 | 
				
			||||||
      link = pinos_node_link (node, port, target, NULL, NULL, &error);
 | 
					      link = pinos_node_link (node, port, target, NULL, NULL, &error);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      link = pinos_node_link (target->node, target, port, NULL, NULL, &error);
 | 
					      link = pinos_node_link (target->node, target, port, NULL, NULL, &error);
 | 
				
			||||||
| 
						 | 
					@ -306,10 +311,10 @@ on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
 | 
				
			||||||
    if (client)
 | 
					    if (client)
 | 
				
			||||||
      pinos_client_add_object (client, G_OBJECT (link));
 | 
					      pinos_client_add_object (client, G_OBJECT (link));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_signal_connect (target->node, "remove", (GCallback) on_node_remove_signal, daemon);
 | 
					    g_signal_connect (target->node, "remove", (GCallback) on_node_remove_signal, this);
 | 
				
			||||||
    g_signal_connect (link, "input-unlinked", (GCallback) on_link_input_unlinked, daemon);
 | 
					    g_signal_connect (link, "input-unlinked", (GCallback) on_link_input_unlinked, this);
 | 
				
			||||||
    g_signal_connect (link, "output-unlinked", (GCallback) on_link_output_unlinked, daemon);
 | 
					    g_signal_connect (link, "output-unlinked", (GCallback) on_link_output_unlinked, this);
 | 
				
			||||||
    g_signal_connect (link, "notify::state", (GCallback) on_link_state_notify, daemon);
 | 
					    g_signal_connect (link, "notify::state", (GCallback) on_link_state_notify, this);
 | 
				
			||||||
    pinos_link_activate (link);
 | 
					    pinos_link_activate (link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_object_unref (link);
 | 
					    g_object_unref (link);
 | 
				
			||||||
| 
						 | 
					@ -324,26 +329,32 @@ error:
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_port_removed (PinosNode *node, PinosPort *port, PinosDaemon *daemon)
 | 
					on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  try_link_port (node, port, this);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					on_port_removed (PinosNode *node, PinosPort *port, PinosDaemon *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_node_created (PinosNode      *node,
 | 
					on_node_created (PinosNode      *node,
 | 
				
			||||||
                 PinosDaemon    *daemon)
 | 
					                 PinosDaemon    *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GList *ports, *walk;
 | 
					  GList *ports, *walk;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ports = pinos_node_get_ports (node, PINOS_DIRECTION_INPUT);
 | 
					  ports = pinos_node_get_ports (node, PINOS_DIRECTION_INPUT);
 | 
				
			||||||
  for (walk = ports; walk; walk = g_list_next (walk))
 | 
					  for (walk = ports; walk; walk = g_list_next (walk))
 | 
				
			||||||
    on_port_added (node, walk->data, daemon);
 | 
					    on_port_added (node, walk->data, this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ports = pinos_node_get_ports (node, PINOS_DIRECTION_OUTPUT);
 | 
					  ports = pinos_node_get_ports (node, PINOS_DIRECTION_OUTPUT);
 | 
				
			||||||
  for (walk = ports; walk; walk = g_list_next (walk))
 | 
					  for (walk = ports; walk; walk = g_list_next (walk))
 | 
				
			||||||
    on_port_added (node, walk->data, daemon);
 | 
					    on_port_added (node, walk->data, this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_signal_connect (node, "port-added", (GCallback) on_port_added, daemon);
 | 
					  g_signal_connect (node, "port-added", (GCallback) on_port_added, this);
 | 
				
			||||||
  g_signal_connect (node, "port-removed", (GCallback) on_port_removed, daemon);
 | 
					  g_signal_connect (node, "port-removed", (GCallback) on_port_removed, this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -351,14 +362,14 @@ static void
 | 
				
			||||||
on_node_state_change (PinosNode      *node,
 | 
					on_node_state_change (PinosNode      *node,
 | 
				
			||||||
                      PinosNodeState  old,
 | 
					                      PinosNodeState  old,
 | 
				
			||||||
                      PinosNodeState  state,
 | 
					                      PinosNodeState  state,
 | 
				
			||||||
                      PinosDaemon    *daemon)
 | 
					                      PinosDaemon    *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  g_debug ("daemon %p: node %p state change %s -> %s", daemon, node,
 | 
					  g_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));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (old == PINOS_NODE_STATE_CREATING && state == PINOS_NODE_STATE_SUSPENDED)
 | 
					  if (old == PINOS_NODE_STATE_CREATING && state == PINOS_NODE_STATE_SUSPENDED)
 | 
				
			||||||
    on_node_created (node, daemon);
 | 
					    on_node_created (node, this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -369,7 +380,7 @@ on_node_added (PinosDaemon *daemon, PinosNode *node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("daemon %p: node %p added", daemon, node);
 | 
					  g_debug ("daemon %p: node %p added", daemon, node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_object_set (node, "rt-loop", priv->loop, NULL);
 | 
					  g_object_set (node, "data-loop", priv->data_loop, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_signal_connect (node, "state-change", (GCallback) on_node_state_change, daemon);
 | 
					  g_signal_connect (node, "state-change", (GCallback) on_node_state_change, daemon);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -727,6 +738,7 @@ pinos_daemon_remove_node (PinosDaemon *daemon,
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_daemon_find_port:
 | 
					 * pinos_daemon_find_port:
 | 
				
			||||||
 * @daemon: a #PinosDaemon
 | 
					 * @daemon: a #PinosDaemon
 | 
				
			||||||
 | 
					 * @other_port: a port to be compatible with
 | 
				
			||||||
 * @name: a port name
 | 
					 * @name: a port name
 | 
				
			||||||
 * @props: port properties
 | 
					 * @props: port properties
 | 
				
			||||||
 * @format_filter: a format filter
 | 
					 * @format_filter: a format filter
 | 
				
			||||||
| 
						 | 
					@ -738,11 +750,10 @@ pinos_daemon_remove_node (PinosDaemon *daemon,
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
PinosPort *
 | 
					PinosPort *
 | 
				
			||||||
pinos_daemon_find_port (PinosDaemon     *daemon,
 | 
					pinos_daemon_find_port (PinosDaemon     *daemon,
 | 
				
			||||||
                        PinosDirection   direction,
 | 
					                        PinosPort       *other_port,
 | 
				
			||||||
                        const gchar     *name,
 | 
					                        const gchar     *name,
 | 
				
			||||||
                        PinosProperties *props,
 | 
					                        PinosProperties *props,
 | 
				
			||||||
                        unsigned int     n_format_filters,
 | 
					                        GPtrArray       *format_filters,
 | 
				
			||||||
                        SpaFormat      **format_filters,
 | 
					 | 
				
			||||||
                        GError         **error)
 | 
					                        GError         **error)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosDaemonPrivate *priv;
 | 
					  PinosDaemonPrivate *priv;
 | 
				
			||||||
| 
						 | 
					@ -766,7 +777,7 @@ pinos_daemon_find_port (PinosDaemon     *daemon,
 | 
				
			||||||
      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);
 | 
					        g_debug ("name \"%s\" matches node %p", name, n);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        best = pinos_node_get_free_port (n, direction);
 | 
					        best = pinos_node_get_free_port (n, pinos_direction_reverse (other_port->direction));
 | 
				
			||||||
        if (best)
 | 
					        if (best)
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -873,7 +884,7 @@ pinos_daemon_finalize (GObject * object)
 | 
				
			||||||
  g_debug ("daemon %p: finalize", object);
 | 
					  g_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->loop);
 | 
					  g_clear_object (&priv->data_loop);
 | 
				
			||||||
  g_hash_table_unref (priv->clients);
 | 
					  g_hash_table_unref (priv->clients);
 | 
				
			||||||
  g_hash_table_unref (priv->node_factories);
 | 
					  g_hash_table_unref (priv->node_factories);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -962,74 +973,6 @@ do_log (SpaLog        *log,
 | 
				
			||||||
  va_end (args);
 | 
					  va_end (args);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
  PinosDaemonPrivate *priv;
 | 
					 | 
				
			||||||
  SpaPollItem item;
 | 
					 | 
				
			||||||
} PollData;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static gboolean
 | 
					 | 
				
			||||||
poll_event (GIOChannel *source,
 | 
					 | 
				
			||||||
            GIOCondition condition,
 | 
					 | 
				
			||||||
            gpointer user_data)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  PollData *data = user_data;
 | 
					 | 
				
			||||||
  SpaPollNotifyData d;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  d.user_data = data->item.user_data;
 | 
					 | 
				
			||||||
  d.fds = data->item.fds;
 | 
					 | 
				
			||||||
  d.fds[0].revents = condition;
 | 
					 | 
				
			||||||
  d.n_fds = data->item.n_fds;
 | 
					 | 
				
			||||||
  data->item.after_cb (&d);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return TRUE;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static SpaResult
 | 
					 | 
				
			||||||
do_add_item (SpaPoll     *poll,
 | 
					 | 
				
			||||||
             SpaPollItem *item)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  PinosDaemonPrivate *priv = SPA_CONTAINER_OF (poll, PinosDaemonPrivate, main_loop);
 | 
					 | 
				
			||||||
  GIOChannel *channel;
 | 
					 | 
				
			||||||
  GSource *source;
 | 
					 | 
				
			||||||
  PollData data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  channel = g_io_channel_unix_new (item->fds[0].fd);
 | 
					 | 
				
			||||||
  source = g_io_create_watch (channel, G_IO_IN);
 | 
					 | 
				
			||||||
  g_io_channel_unref (channel);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  data.priv = priv;
 | 
					 | 
				
			||||||
  data.item = *item;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  g_source_set_callback (source, (GSourceFunc) poll_event, g_slice_dup (PollData, &data) , NULL);
 | 
					 | 
				
			||||||
  item->id = g_source_attach (source, g_main_context_get_thread_default ());
 | 
					 | 
				
			||||||
  g_source_unref (source);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  g_debug ("added main poll %d", item->id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return SPA_RESULT_OK;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static SpaResult
 | 
					 | 
				
			||||||
do_update_item (SpaPoll     *poll,
 | 
					 | 
				
			||||||
                SpaPollItem *item)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  g_debug ("update main poll %d", item->id);
 | 
					 | 
				
			||||||
  return SPA_RESULT_OK;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static SpaResult
 | 
					 | 
				
			||||||
do_remove_item (SpaPoll     *poll,
 | 
					 | 
				
			||||||
                SpaPollItem *item)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  GSource *source;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  g_debug ("remove main poll %d", item->id);
 | 
					 | 
				
			||||||
  source = g_main_context_find_source_by_id (g_main_context_get_thread_default (), item->id);
 | 
					 | 
				
			||||||
  g_source_destroy (source);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return SPA_RESULT_OK;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_daemon_init (PinosDaemon * daemon)
 | 
					pinos_daemon_init (PinosDaemon * daemon)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -1047,13 +990,9 @@ pinos_daemon_init (PinosDaemon * daemon)
 | 
				
			||||||
                                                g_str_equal,
 | 
					                                                g_str_equal,
 | 
				
			||||||
                                                g_free,
 | 
					                                                g_free,
 | 
				
			||||||
                                                g_object_unref);
 | 
					                                                g_object_unref);
 | 
				
			||||||
  priv->loop = pinos_rtloop_new();
 | 
					  daemon->main_loop = pinos_main_loop_new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  priv->main_loop.size = sizeof (SpaPoll);
 | 
					  priv->data_loop = pinos_data_loop_new();
 | 
				
			||||||
  priv->main_loop.info = NULL;
 | 
					 | 
				
			||||||
  priv->main_loop.add_item = do_add_item;
 | 
					 | 
				
			||||||
  priv->main_loop.update_item = do_update_item;
 | 
					 | 
				
			||||||
  priv->main_loop.remove_item = do_remove_item;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  priv->log.size = sizeof (SpaLog);
 | 
					  priv->log.size = sizeof (SpaLog);
 | 
				
			||||||
  priv->log.info = NULL;
 | 
					  priv->log.info = NULL;
 | 
				
			||||||
| 
						 | 
					@ -1069,9 +1008,9 @@ pinos_daemon_init (PinosDaemon * daemon)
 | 
				
			||||||
  priv->support[1].uri = SPA_LOG_URI;
 | 
					  priv->support[1].uri = SPA_LOG_URI;
 | 
				
			||||||
  priv->support[1].data = daemon->log;
 | 
					  priv->support[1].data = daemon->log;
 | 
				
			||||||
  priv->support[2].uri = SPA_POLL__DataLoop;
 | 
					  priv->support[2].uri = SPA_POLL__DataLoop;
 | 
				
			||||||
  priv->support[2].data = &priv->loop->poll;
 | 
					  priv->support[2].data = &priv->data_loop->poll;
 | 
				
			||||||
  priv->support[3].uri = SPA_POLL__MainLoop;
 | 
					  priv->support[3].uri = SPA_POLL__MainLoop;
 | 
				
			||||||
  priv->support[3].data = &priv->main_loop;
 | 
					  priv->support[3].data = &daemon->main_loop->poll;
 | 
				
			||||||
  daemon->support = priv->support;
 | 
					  daemon->support = priv->support;
 | 
				
			||||||
  daemon->n_support = 4;
 | 
					  daemon->n_support = 4;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,6 +42,7 @@ typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
 | 
				
			||||||
#include <spa/include/spa/id-map.h>
 | 
					#include <spa/include/spa/id-map.h>
 | 
				
			||||||
#include <pinos/server/node.h>
 | 
					#include <pinos/server/node.h>
 | 
				
			||||||
#include <pinos/server/node-factory.h>
 | 
					#include <pinos/server/node-factory.h>
 | 
				
			||||||
 | 
					#include <pinos/server/main-loop.h>
 | 
				
			||||||
#include <pinos/client/properties.h>
 | 
					#include <pinos/client/properties.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -55,6 +56,8 @@ struct _PinosDaemon {
 | 
				
			||||||
  SpaIDMap *map;
 | 
					  SpaIDMap *map;
 | 
				
			||||||
  SpaLog *log;
 | 
					  SpaLog *log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  PinosMainLoop *main_loop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  SpaSupport *support;
 | 
					  SpaSupport *support;
 | 
				
			||||||
  unsigned int n_support;
 | 
					  unsigned int n_support;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -86,11 +89,10 @@ void              pinos_daemon_add_node          (PinosDaemon *daemon, PinosNode
 | 
				
			||||||
void              pinos_daemon_remove_node       (PinosDaemon *daemon, PinosNode *node);
 | 
					void              pinos_daemon_remove_node       (PinosDaemon *daemon, PinosNode *node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PinosPort *       pinos_daemon_find_port         (PinosDaemon     *daemon,
 | 
					PinosPort *       pinos_daemon_find_port         (PinosDaemon     *daemon,
 | 
				
			||||||
                                                  PinosDirection   direction,
 | 
					                                                  PinosPort       *other_port,
 | 
				
			||||||
                                                  const gchar     *name,
 | 
					                                                  const gchar     *name,
 | 
				
			||||||
                                                  PinosProperties *props,
 | 
					                                                  PinosProperties *props,
 | 
				
			||||||
                                                  unsigned int     n_format_filters,
 | 
					                                                  GPtrArray       *format_filter,
 | 
				
			||||||
                                                  SpaFormat      **format_filters,
 | 
					 | 
				
			||||||
                                                  GError         **error);
 | 
					                                                  GError         **error);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void              pinos_daemon_add_node_factory  (PinosDaemon *daemon,
 | 
					void              pinos_daemon_add_node_factory  (PinosDaemon *daemon,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,12 +26,12 @@
 | 
				
			||||||
#include <gio/gio.h>
 | 
					#include <gio/gio.h>
 | 
				
			||||||
#include <gio/gunixfdlist.h>
 | 
					#include <gio/gunixfdlist.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "pinos/server/rt-loop.h"
 | 
					#include "pinos/server/data-loop.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define PINOS_RTLOOP_GET_PRIVATE(loop)  \
 | 
					#define PINOS_DATA_LOOP_GET_PRIVATE(loop)  \
 | 
				
			||||||
   (G_TYPE_INSTANCE_GET_PRIVATE ((loop), PINOS_TYPE_RTLOOP, PinosRTLoopPrivate))
 | 
					   (G_TYPE_INSTANCE_GET_PRIVATE ((loop), PINOS_TYPE_DATA_LOOP, PinosDataLoopPrivate))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct _PinosRTLoopPrivate
 | 
					struct _PinosDataLoopPrivate
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  unsigned int n_poll;
 | 
					  unsigned int n_poll;
 | 
				
			||||||
  SpaPollItem poll[16];
 | 
					  SpaPollItem poll[16];
 | 
				
			||||||
| 
						 | 
					@ -45,7 +45,7 @@ struct _PinosRTLoopPrivate
 | 
				
			||||||
  pthread_t thread;
 | 
					  pthread_t thread;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_DEFINE_TYPE (PinosRTLoop, pinos_rtloop, G_TYPE_OBJECT);
 | 
					G_DEFINE_TYPE (PinosDataLoop, pinos_data_loop, G_TYPE_OBJECT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum
 | 
					enum
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -60,11 +60,11 @@ enum
 | 
				
			||||||
static void *
 | 
					static void *
 | 
				
			||||||
loop (void *user_data)
 | 
					loop (void *user_data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoop *this = user_data;
 | 
					  PinosDataLoop *this = user_data;
 | 
				
			||||||
  PinosRTLoopPrivate *priv = this->priv;
 | 
					  PinosDataLoopPrivate *priv = this->priv;
 | 
				
			||||||
  unsigned int i, j;
 | 
					  unsigned int i, j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("rt-loop %p: enter thread", this);
 | 
					  g_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;
 | 
				
			||||||
| 
						 | 
					@ -87,7 +87,7 @@ loop (void *user_data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* rebuild */
 | 
					    /* rebuild */
 | 
				
			||||||
    if (priv->rebuild_fds) {
 | 
					    if (priv->rebuild_fds) {
 | 
				
			||||||
      g_debug ("rt-loop %p: rebuild fds", this);
 | 
					      g_debug ("data-loop %p: rebuild fds", this);
 | 
				
			||||||
      priv->n_fds = 1;
 | 
					      priv->n_fds = 1;
 | 
				
			||||||
      for (i = 0; i < priv->n_poll; i++) {
 | 
					      for (i = 0; i < priv->n_poll; i++) {
 | 
				
			||||||
        SpaPollItem *p = &priv->poll[i];
 | 
					        SpaPollItem *p = &priv->poll[i];
 | 
				
			||||||
| 
						 | 
					@ -122,7 +122,7 @@ loop (void *user_data)
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (r == 0) {
 | 
					    if (r == 0) {
 | 
				
			||||||
      g_debug ("rt-loop %p: select timeout", this);
 | 
					      g_debug ("data-loop %p: select timeout", this);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,7 +130,7 @@ loop (void *user_data)
 | 
				
			||||||
    if (priv->fds[0].revents & POLLIN) {
 | 
					    if (priv->fds[0].revents & POLLIN) {
 | 
				
			||||||
      uint64_t u;
 | 
					      uint64_t u;
 | 
				
			||||||
      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 ("rt-loop %p: failed to read fd", strerror (errno));
 | 
					        g_warning ("data-loop %p: failed to read fd", strerror (errno));
 | 
				
			||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -146,40 +146,40 @@ loop (void *user_data)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  g_debug ("rt-loop %p: leave thread", this);
 | 
					  g_debug ("data-loop %p: leave thread", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return NULL;
 | 
					  return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
wakeup_thread (PinosRTLoop *this)
 | 
					wakeup_thread (PinosDataLoop *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoopPrivate *priv = this->priv;
 | 
					  PinosDataLoopPrivate *priv = this->priv;
 | 
				
			||||||
  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 ("rt-loop %p: failed to write fd", strerror (errno));
 | 
					    g_warning ("data-loop %p: failed to write fd", strerror (errno));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
start_thread (PinosRTLoop *this)
 | 
					start_thread (PinosDataLoop *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoopPrivate *priv = this->priv;
 | 
					  PinosDataLoopPrivate *priv = this->priv;
 | 
				
			||||||
  int err;
 | 
					  int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  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 ("rt-loop %p: can't create thread", strerror (err));
 | 
					      g_warning ("data-loop %p: can't create thread", strerror (err));
 | 
				
			||||||
      priv->running = false;
 | 
					      priv->running = false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
stop_thread (PinosRTLoop *this, gboolean in_thread)
 | 
					stop_thread (PinosDataLoop *this, gboolean in_thread)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoopPrivate *priv = this->priv;
 | 
					  PinosDataLoopPrivate *priv = this->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (priv->running) {
 | 
					  if (priv->running) {
 | 
				
			||||||
    priv->running = false;
 | 
					    priv->running = false;
 | 
				
			||||||
| 
						 | 
					@ -194,12 +194,12 @@ static SpaResult
 | 
				
			||||||
do_add_item (SpaPoll         *poll,
 | 
					do_add_item (SpaPoll         *poll,
 | 
				
			||||||
             SpaPollItem     *item)
 | 
					             SpaPollItem     *item)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoop *this = SPA_CONTAINER_OF (poll, PinosRTLoop, poll);
 | 
					  PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
 | 
				
			||||||
  PinosRTLoopPrivate *priv = this->priv;
 | 
					  PinosDataLoopPrivate *priv = this->priv;
 | 
				
			||||||
  gboolean in_thread = pthread_equal (priv->thread, pthread_self());
 | 
					  gboolean in_thread = pthread_equal (priv->thread, pthread_self());
 | 
				
			||||||
  unsigned int i;
 | 
					  unsigned int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("rt-loop %p: %d: add pollid %d, n_poll %d, n_fds %d", this, in_thread, item->id, priv->n_poll, item->n_fds);
 | 
					  g_debug ("data-loop %p: %d: add pollid %d, n_poll %d, n_fds %d", this, in_thread, item->id, priv->n_poll, item->n_fds);
 | 
				
			||||||
  priv->poll[priv->n_poll] = *item;
 | 
					  priv->poll[priv->n_poll] = *item;
 | 
				
			||||||
  priv->n_poll++;
 | 
					  priv->n_poll++;
 | 
				
			||||||
  if (item->n_fds)
 | 
					  if (item->n_fds)
 | 
				
			||||||
| 
						 | 
					@ -221,8 +221,8 @@ static SpaResult
 | 
				
			||||||
do_update_item (SpaPoll         *poll,
 | 
					do_update_item (SpaPoll         *poll,
 | 
				
			||||||
                SpaPollItem     *item)
 | 
					                SpaPollItem     *item)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoop *this = SPA_CONTAINER_OF (poll, PinosRTLoop, poll);
 | 
					  PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
 | 
				
			||||||
  PinosRTLoopPrivate *priv = this->priv;
 | 
					  PinosDataLoopPrivate *priv = this->priv;
 | 
				
			||||||
  gboolean in_thread = pthread_equal (priv->thread, pthread_self());
 | 
					  gboolean in_thread = pthread_equal (priv->thread, pthread_self());
 | 
				
			||||||
  unsigned int i;
 | 
					  unsigned int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -243,12 +243,12 @@ static SpaResult
 | 
				
			||||||
do_remove_item (SpaPoll         *poll,
 | 
					do_remove_item (SpaPoll         *poll,
 | 
				
			||||||
                SpaPollItem     *item)
 | 
					                SpaPollItem     *item)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoop *this = SPA_CONTAINER_OF (poll, PinosRTLoop, poll);
 | 
					  PinosDataLoop *this = SPA_CONTAINER_OF (poll, PinosDataLoop, poll);
 | 
				
			||||||
  PinosRTLoopPrivate *priv = this->priv;
 | 
					  PinosDataLoopPrivate *priv = this->priv;
 | 
				
			||||||
  gboolean in_thread = pthread_equal (priv->thread, pthread_self());
 | 
					  gboolean in_thread = pthread_equal (priv->thread, pthread_self());
 | 
				
			||||||
  unsigned int i;
 | 
					  unsigned int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("rt-loop %p: remove poll %d %d", this, item->n_fds, priv->n_poll);
 | 
					  g_debug ("data-loop %p: remove poll %d %d", this, item->n_fds, priv->n_poll);
 | 
				
			||||||
  for (i = 0; i < priv->n_poll; i++) {
 | 
					  for (i = 0; i < priv->n_poll; i++) {
 | 
				
			||||||
    if (priv->poll[i].id == item->id && priv->poll[i].user_data == item->user_data) {
 | 
					    if (priv->poll[i].id == item->id && priv->poll[i].user_data == item->user_data) {
 | 
				
			||||||
      priv->n_poll--;
 | 
					      priv->n_poll--;
 | 
				
			||||||
| 
						 | 
					@ -273,14 +273,14 @@ do_remove_item (SpaPoll         *poll,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_rtloop_constructed (GObject * obj)
 | 
					pinos_data_loop_constructed (GObject * obj)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoop *this = PINOS_RTLOOP (obj);
 | 
					  PinosDataLoop *this = PINOS_DATA_LOOP (obj);
 | 
				
			||||||
  PinosRTLoopPrivate *priv = this->priv;
 | 
					  PinosDataLoopPrivate *priv = this->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("rt-loop %p: constructed", this);
 | 
					  g_debug ("data-loop %p: constructed", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  G_OBJECT_CLASS (pinos_rtloop_parent_class)->constructed (obj);
 | 
					  G_OBJECT_CLASS (pinos_data_loop_parent_class)->constructed (obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  priv->fds[0].fd = eventfd (0, 0);
 | 
					  priv->fds[0].fd = eventfd (0, 0);
 | 
				
			||||||
  priv->fds[0].events = POLLIN | POLLPRI | POLLERR;
 | 
					  priv->fds[0].events = POLLIN | POLLPRI | POLLERR;
 | 
				
			||||||
| 
						 | 
					@ -289,44 +289,44 @@ pinos_rtloop_constructed (GObject * obj)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_rtloop_dispose (GObject * obj)
 | 
					pinos_data_loop_dispose (GObject * obj)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoop *this = PINOS_RTLOOP (obj);
 | 
					  PinosDataLoop *this = PINOS_DATA_LOOP (obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("rt-loop %p: dispose", this);
 | 
					  g_debug ("data-loop %p: dispose", this);
 | 
				
			||||||
  stop_thread (this, FALSE);
 | 
					  stop_thread (this, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  G_OBJECT_CLASS (pinos_rtloop_parent_class)->dispose (obj);
 | 
					  G_OBJECT_CLASS (pinos_data_loop_parent_class)->dispose (obj);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_rtloop_finalize (GObject * obj)
 | 
					pinos_data_loop_finalize (GObject * obj)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosRTLoop *this = PINOS_RTLOOP (obj);
 | 
					  PinosDataLoop *this = PINOS_DATA_LOOP (obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("rt-loop %p: finalize", this);
 | 
					  g_debug ("data-loop %p: finalize", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  G_OBJECT_CLASS (pinos_rtloop_parent_class)->finalize (obj);
 | 
					  G_OBJECT_CLASS (pinos_data_loop_parent_class)->finalize (obj);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_rtloop_class_init (PinosRTLoopClass * klass)
 | 
					pinos_data_loop_class_init (PinosDataLoopClass * klass)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 | 
					  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_type_class_add_private (klass, sizeof (PinosRTLoopPrivate));
 | 
					  g_type_class_add_private (klass, sizeof (PinosDataLoopPrivate));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  gobject_class->constructed = pinos_rtloop_constructed;
 | 
					  gobject_class->constructed = pinos_data_loop_constructed;
 | 
				
			||||||
  gobject_class->dispose = pinos_rtloop_dispose;
 | 
					  gobject_class->dispose = pinos_data_loop_dispose;
 | 
				
			||||||
  gobject_class->finalize = pinos_rtloop_finalize;
 | 
					  gobject_class->finalize = pinos_data_loop_finalize;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
pinos_rtloop_init (PinosRTLoop * this)
 | 
					pinos_data_loop_init (PinosDataLoop * this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  this->priv = PINOS_RTLOOP_GET_PRIVATE (this);
 | 
					  this->priv = PINOS_DATA_LOOP_GET_PRIVATE (this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("rt-loop %p: new", this);
 | 
					  g_debug ("data-loop %p: new", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this->poll.size = sizeof (SpaPoll);
 | 
					  this->poll.size = sizeof (SpaPoll);
 | 
				
			||||||
  this->poll.info = NULL;
 | 
					  this->poll.info = NULL;
 | 
				
			||||||
| 
						 | 
					@ -336,14 +336,14 @@ pinos_rtloop_init (PinosRTLoop * this)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * pinos_rtloop_new:
 | 
					 * pinos_data_loop_new:
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Create a new #PinosRTLoop.
 | 
					 * Create a new #PinosDataLoop.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Returns: a new #PinosRTLoop
 | 
					 * Returns: a new #PinosDataLoop
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
PinosRTLoop *
 | 
					PinosDataLoop *
 | 
				
			||||||
pinos_rtloop_new (void)
 | 
					pinos_data_loop_new (void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  return g_object_new (PINOS_TYPE_RTLOOP, NULL);
 | 
					  return g_object_new (PINOS_TYPE_DATA_LOOP, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										71
									
								
								pinos/server/data-loop.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								pinos/server/data-loop.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,71 @@
 | 
				
			||||||
 | 
					/* Pinos
 | 
				
			||||||
 | 
					 * 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_DATA_LOOP_H__
 | 
				
			||||||
 | 
					#define __PINOS_DATA_LOOP_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <glib-object.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_BEGIN_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <spa/include/spa/poll.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct _PinosDataLoop PinosDataLoop;
 | 
				
			||||||
 | 
					typedef struct _PinosDataLoopClass PinosDataLoopClass;
 | 
				
			||||||
 | 
					typedef struct _PinosDataLoopPrivate PinosDataLoopPrivate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PINOS_TYPE_DATA_LOOP                 (pinos_data_loop_get_type ())
 | 
				
			||||||
 | 
					#define PINOS_IS_DATA_LOOP(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_DATA_LOOP))
 | 
				
			||||||
 | 
					#define PINOS_IS_DATA_LOOP_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_DATA_LOOP))
 | 
				
			||||||
 | 
					#define PINOS_DATA_LOOP_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_DATA_LOOP, PinosDataLoopClass))
 | 
				
			||||||
 | 
					#define PINOS_DATA_LOOP(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_DATA_LOOP, PinosDataLoop))
 | 
				
			||||||
 | 
					#define PINOS_DATA_LOOP_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_DATA_LOOP, PinosDataLoopClass))
 | 
				
			||||||
 | 
					#define PINOS_DATA_LOOP_CAST(obj)            ((PinosDataLoop*)(obj))
 | 
				
			||||||
 | 
					#define PINOS_DATA_LOOP_CLASS_CAST(klass)    ((PinosDataLoopClass*)(klass))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * PinosDataLoop:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Pinos rt-loop class.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct _PinosDataLoop {
 | 
				
			||||||
 | 
					  GObject object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  SpaPoll poll;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  PinosDataLoopPrivate *priv;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * PinosDataLoopClass:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Pinos rt-loop class.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct _PinosDataLoopClass {
 | 
				
			||||||
 | 
					  GObjectClass parent_class;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* normal GObject stuff */
 | 
				
			||||||
 | 
					GType               pinos_data_loop_get_type                (void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PinosDataLoop *     pinos_data_loop_new                     (void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_END_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* __PINOS_DATA_LOOP_H__ */
 | 
				
			||||||
| 
						 | 
					@ -46,11 +46,11 @@ struct _PinosLinkPrivate
 | 
				
			||||||
  GPtrArray *format_filter;
 | 
					  GPtrArray *format_filter;
 | 
				
			||||||
  PinosProperties *properties;
 | 
					  PinosProperties *properties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  PinosMainLoop *main_loop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosLinkState state;
 | 
					  PinosLinkState state;
 | 
				
			||||||
  GError *error;
 | 
					  GError *error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  uint32_t async_busy;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  gboolean allocated;
 | 
					  gboolean allocated;
 | 
				
			||||||
  PinosMemblock buffer_mem;
 | 
					  PinosMemblock buffer_mem;
 | 
				
			||||||
  SpaBuffer **buffers;
 | 
					  SpaBuffer **buffers;
 | 
				
			||||||
| 
						 | 
					@ -656,29 +656,24 @@ do_start (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (in_state == SPA_NODE_STATE_PAUSED) {
 | 
					    if (in_state == SPA_NODE_STATE_PAUSED) {
 | 
				
			||||||
      pinos_node_set_state (this->input->node, PINOS_NODE_STATE_RUNNING);
 | 
					      pinos_node_set_state (this->input->node, PINOS_NODE_STATE_RUNNING);
 | 
				
			||||||
      if (pinos_node_get_state (this->input->node) != PINOS_NODE_STATE_RUNNING)
 | 
					 | 
				
			||||||
        res = SPA_RESULT_RETURN_ASYNC (0);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (out_state == SPA_NODE_STATE_PAUSED) {
 | 
					    if (out_state == SPA_NODE_STATE_PAUSED) {
 | 
				
			||||||
      pinos_node_set_state (this->output->node, PINOS_NODE_STATE_RUNNING);
 | 
					      pinos_node_set_state (this->output->node, PINOS_NODE_STATE_RUNNING);
 | 
				
			||||||
      if (pinos_node_get_state (this->output->node) != PINOS_NODE_STATE_RUNNING)
 | 
					 | 
				
			||||||
        res = SPA_RESULT_RETURN_ASYNC (0);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return res;
 | 
					  return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static SpaResult
 | 
					static SpaResult
 | 
				
			||||||
check_states (PinosLink *this)
 | 
					check_states (PinosLink *this, SpaResult res)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosLinkPrivate *priv = this->priv;
 | 
					 | 
				
			||||||
  SpaResult res;
 | 
					 | 
				
			||||||
  SpaNodeState in_state, out_state;
 | 
					  SpaNodeState in_state, out_state;
 | 
				
			||||||
 | 
					  PinosLinkPrivate *priv = this->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
again:
 | 
					again:
 | 
				
			||||||
   if (priv->async_busy != SPA_ID_INVALID)
 | 
					  if (this->input == NULL || this->output == NULL)
 | 
				
			||||||
     return SPA_RESULT_OK;
 | 
					    return SPA_RESULT_OK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  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;
 | 
				
			||||||
| 
						 | 
					@ -702,30 +697,19 @@ again:
 | 
				
			||||||
  return SPA_RESULT_OK;
 | 
					  return SPA_RESULT_OK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exit:
 | 
					exit:
 | 
				
			||||||
  if (SPA_RESULT_IS_ASYNC (res)) {
 | 
					  pinos_main_loop_defer (priv->main_loop, this, res, (PinosDeferFunc) check_states, this, NULL);
 | 
				
			||||||
    priv->async_busy = SPA_RESULT_ASYNC_SEQ (res);
 | 
					 | 
				
			||||||
    g_debug ("link %p: waiting for async complete %d", this, priv->async_busy);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  return res;
 | 
					  return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gboolean
 | 
					 | 
				
			||||||
do_check_states (PinosLink *this)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  PinosLinkPrivate *priv = this->priv;
 | 
					 | 
				
			||||||
  priv->async_busy = SPA_ID_INVALID;
 | 
					 | 
				
			||||||
  check_states (this);
 | 
					 | 
				
			||||||
  return G_SOURCE_REMOVE;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_async_complete_notify (PinosNode  *node,
 | 
					on_async_complete_notify (PinosNode  *node,
 | 
				
			||||||
                          guint       seq,
 | 
					                          guint       seq,
 | 
				
			||||||
                          guint       res,
 | 
					                          guint       res,
 | 
				
			||||||
                          PinosLink  *this)
 | 
					                          PinosLink  *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					  PinosLinkPrivate *priv = this->priv;
 | 
				
			||||||
  g_debug ("link %p: node %p async complete %d %d", this, node, seq, res);
 | 
					  g_debug ("link %p: node %p async complete %d %d", this, node, seq, res);
 | 
				
			||||||
  g_idle_add ((GSourceFunc) do_check_states, this);
 | 
					  pinos_main_loop_defer_complete (priv->main_loop, this, seq, res);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -756,28 +740,75 @@ on_property_notify (GObject    *obj,
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					  PinosLink *link;
 | 
				
			||||||
 | 
					  PinosPort *port;
 | 
				
			||||||
 | 
					} UnlinkedData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					on_input_unlinked (UnlinkedData *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  g_signal_emit (data->link, signals[SIGNAL_INPUT_UNLINKED], 0, data->port);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					on_output_unlinked (UnlinkedData *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  g_signal_emit (data->link, signals[SIGNAL_OUTPUT_UNLINKED], 0, data->port);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_node_remove (PinosNode *node, PinosLink *this)
 | 
					on_node_remove (PinosNode *node, PinosLink *this)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosLinkPrivate *priv = this->priv;
 | 
					  PinosLinkPrivate *priv = this->priv;
 | 
				
			||||||
 | 
					  SpaResult res = SPA_RESULT_OK;
 | 
				
			||||||
 | 
					  UnlinkedData data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  data.link = this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_signal_handlers_disconnect_by_data (node, this);
 | 
					  g_signal_handlers_disconnect_by_data (node, this);
 | 
				
			||||||
  if (node == this->input->node) {
 | 
					  if (node == this->input->node) {
 | 
				
			||||||
    if (this->input->allocated) {
 | 
					    if (this->input->allocated) {
 | 
				
			||||||
      priv->buffers = NULL;
 | 
					      priv->buffers = NULL;
 | 
				
			||||||
      priv->n_buffers = 0;
 | 
					      priv->n_buffers = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if ((res = spa_node_port_use_buffers (this->output->node->node,
 | 
				
			||||||
 | 
					                                            SPA_DIRECTION_OUTPUT,
 | 
				
			||||||
 | 
					                                            this->output->port,
 | 
				
			||||||
 | 
					                                            priv->buffers,
 | 
				
			||||||
 | 
					                                            priv->n_buffers)) < 0) {
 | 
				
			||||||
 | 
					        g_warning ("link %p: failed to clear output buffers: %d", this, res);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    data.port = this->input;
 | 
				
			||||||
    this->input = NULL;
 | 
					    this->input = NULL;
 | 
				
			||||||
    g_object_notify (G_OBJECT (this), "input-port");
 | 
					    pinos_main_loop_defer (priv->main_loop,
 | 
				
			||||||
    g_signal_emit (this, signals[SIGNAL_INPUT_UNLINKED], 0, node);
 | 
					                           this,
 | 
				
			||||||
 | 
					                           res,
 | 
				
			||||||
 | 
					                           (PinosDeferFunc) on_input_unlinked,
 | 
				
			||||||
 | 
					                           g_memdup (&data, sizeof (UnlinkedData)),
 | 
				
			||||||
 | 
					                           g_free);
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    if (this->output->allocated) {
 | 
					    if (this->output->allocated) {
 | 
				
			||||||
      priv->buffers = NULL;
 | 
					      priv->buffers = NULL;
 | 
				
			||||||
      priv->n_buffers = 0;
 | 
					      priv->n_buffers = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if ((res = spa_node_port_use_buffers (this->input->node->node,
 | 
				
			||||||
 | 
					                                            SPA_DIRECTION_INPUT,
 | 
				
			||||||
 | 
					                                            this->input->port,
 | 
				
			||||||
 | 
					                                            priv->buffers,
 | 
				
			||||||
 | 
					                                            priv->n_buffers)) < 0) {
 | 
				
			||||||
 | 
					        g_warning ("link %p: failed to clear input buffers: %d", this, res);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    data.port = this->output;
 | 
				
			||||||
    this->output = NULL;
 | 
					    this->output = NULL;
 | 
				
			||||||
    g_object_notify (G_OBJECT (this), "output-port");
 | 
					    pinos_main_loop_defer (priv->main_loop,
 | 
				
			||||||
    g_signal_emit (this, signals[SIGNAL_OUTPUT_UNLINKED], 0, node);
 | 
					                           this,
 | 
				
			||||||
 | 
					                           res,
 | 
				
			||||||
 | 
					                           (PinosDeferFunc) on_output_unlinked,
 | 
				
			||||||
 | 
					                           g_memdup (&data, sizeof (UnlinkedData)),
 | 
				
			||||||
 | 
					                           g_free);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (this->input == NULL || this->output == NULL)
 | 
					  if (this->input == NULL || this->output == NULL)
 | 
				
			||||||
| 
						 | 
					@ -788,6 +819,9 @@ static void
 | 
				
			||||||
pinos_link_constructed (GObject * object)
 | 
					pinos_link_constructed (GObject * object)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosLink *this = PINOS_LINK (object);
 | 
					  PinosLink *this = PINOS_LINK (object);
 | 
				
			||||||
 | 
					  PinosLinkPrivate *priv = this->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  priv->main_loop = priv->daemon->main_loop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_signal_connect (this->input->node, "remove", (GCallback) on_node_remove, this);
 | 
					  g_signal_connect (this->input->node, "remove", (GCallback) on_node_remove, this);
 | 
				
			||||||
  g_signal_connect (this->output->node, "remove", (GCallback) on_node_remove, this);
 | 
					  g_signal_connect (this->output->node, "remove", (GCallback) on_node_remove, this);
 | 
				
			||||||
| 
						 | 
					@ -1031,7 +1065,7 @@ pinos_link_activate (PinosLink *this)
 | 
				
			||||||
  g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
 | 
					  g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  spa_ringbuffer_init (&this->ringbuffer, SPA_N_ELEMENTS (this->queue));
 | 
					  spa_ringbuffer_init (&this->ringbuffer, SPA_N_ELEMENTS (this->queue));
 | 
				
			||||||
  check_states (this);
 | 
					  check_states (this, SPA_RESULT_OK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,7 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <pinos/server/daemon.h>
 | 
					#include <pinos/server/daemon.h>
 | 
				
			||||||
#include <pinos/server/utils.h>
 | 
					#include <pinos/server/utils.h>
 | 
				
			||||||
 | 
					#include <pinos/server/main-loop.h>
 | 
				
			||||||
#include <spa/include/spa/ringbuffer.h>
 | 
					#include <spa/include/spa/ringbuffer.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define PINOS_TYPE_LINK             (pinos_link_get_type ())
 | 
					#define PINOS_TYPE_LINK             (pinos_link_get_type ())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										313
									
								
								pinos/server/main-loop.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										313
									
								
								pinos/server/main-loop.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,313 @@
 | 
				
			||||||
 | 
					/* Pinos
 | 
				
			||||||
 | 
					 * 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 <string.h>
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <gio/gio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "pinos/server/main-loop.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PINOS_MAIN_LOOP_GET_PRIVATE(loop)  \
 | 
				
			||||||
 | 
					   (G_TYPE_INSTANCE_GET_PRIVATE ((loop), PINOS_TYPE_MAIN_LOOP, PinosMainLoopPrivate))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct _PinosMainLoopPrivate
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  gulong counter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  GQueue work;
 | 
				
			||||||
 | 
					  gulong work_id;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_DEFINE_TYPE (PinosMainLoop, pinos_main_loop, G_TYPE_OBJECT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PROP_0,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  LAST_SIGNAL
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					  PinosMainLoop *loop;
 | 
				
			||||||
 | 
					  SpaPollItem item;
 | 
				
			||||||
 | 
					} PollData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static gboolean
 | 
				
			||||||
 | 
					poll_event (GIOChannel *source,
 | 
				
			||||||
 | 
					            GIOCondition condition,
 | 
				
			||||||
 | 
					            gpointer user_data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PollData *data = user_data;
 | 
				
			||||||
 | 
					  SpaPollNotifyData d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  d.user_data = data->item.user_data;
 | 
				
			||||||
 | 
					  d.fds = data->item.fds;
 | 
				
			||||||
 | 
					  d.fds[0].revents = condition;
 | 
				
			||||||
 | 
					  d.n_fds = data->item.n_fds;
 | 
				
			||||||
 | 
					  data->item.after_cb (&d);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return TRUE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static SpaResult
 | 
				
			||||||
 | 
					do_add_item (SpaPoll     *poll,
 | 
				
			||||||
 | 
					             SpaPollItem *item)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PinosMainLoop *this = SPA_CONTAINER_OF (poll, PinosMainLoop, poll);
 | 
				
			||||||
 | 
					  GIOChannel *channel;
 | 
				
			||||||
 | 
					  GSource *source;
 | 
				
			||||||
 | 
					  PollData data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  channel = g_io_channel_unix_new (item->fds[0].fd);
 | 
				
			||||||
 | 
					  source = g_io_create_watch (channel, G_IO_IN);
 | 
				
			||||||
 | 
					  g_io_channel_unref (channel);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  data.loop = this;
 | 
				
			||||||
 | 
					  data.item = *item;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_source_set_callback (source, (GSourceFunc) poll_event, g_slice_dup (PollData, &data) , NULL);
 | 
				
			||||||
 | 
					  item->id = g_source_attach (source, g_main_context_get_thread_default ());
 | 
				
			||||||
 | 
					  g_source_unref (source);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_debug ("added main poll %d", item->id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return SPA_RESULT_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static SpaResult
 | 
				
			||||||
 | 
					do_update_item (SpaPoll     *poll,
 | 
				
			||||||
 | 
					                SpaPollItem *item)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  g_debug ("update main poll %d", item->id);
 | 
				
			||||||
 | 
					  return SPA_RESULT_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static SpaResult
 | 
				
			||||||
 | 
					do_remove_item (SpaPoll     *poll,
 | 
				
			||||||
 | 
					                SpaPollItem *item)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GSource *source;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_debug ("remove main poll %d", item->id);
 | 
				
			||||||
 | 
					  source = g_main_context_find_source_by_id (g_main_context_get_thread_default (), item->id);
 | 
				
			||||||
 | 
					  g_source_destroy (source);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return SPA_RESULT_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					pinos_main_loop_constructed (GObject * obj)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PinosMainLoop *this = PINOS_MAIN_LOOP (obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_debug ("main-loop %p: constructed", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  G_OBJECT_CLASS (pinos_main_loop_parent_class)->constructed (obj);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					pinos_main_loop_dispose (GObject * obj)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PinosMainLoop *this = PINOS_MAIN_LOOP (obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_debug ("main-loop %p: dispose", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  G_OBJECT_CLASS (pinos_main_loop_parent_class)->dispose (obj);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					pinos_main_loop_finalize (GObject * obj)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PinosMainLoop *this = PINOS_MAIN_LOOP (obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_debug ("main-loop %p: finalize", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  G_OBJECT_CLASS (pinos_main_loop_parent_class)->finalize (obj);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					pinos_main_loop_class_init (PinosMainLoopClass * klass)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_type_class_add_private (klass, sizeof (PinosMainLoopPrivate));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  gobject_class->constructed = pinos_main_loop_constructed;
 | 
				
			||||||
 | 
					  gobject_class->dispose = pinos_main_loop_dispose;
 | 
				
			||||||
 | 
					  gobject_class->finalize = pinos_main_loop_finalize;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					pinos_main_loop_init (PinosMainLoop * this)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PinosMainLoopPrivate *priv = this->priv = PINOS_MAIN_LOOP_GET_PRIVATE (this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_debug ("main-loop %p: new", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  this->poll.size = sizeof (SpaPoll);
 | 
				
			||||||
 | 
					  this->poll.info = NULL;
 | 
				
			||||||
 | 
					  this->poll.add_item = do_add_item;
 | 
				
			||||||
 | 
					  this->poll.update_item = do_update_item;
 | 
				
			||||||
 | 
					  this->poll.remove_item = do_remove_item;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_queue_init (&priv->work);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * pinos_main_loop_new:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Create a new #PinosMainLoop.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Returns: a new #PinosMainLoop
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					PinosMainLoop *
 | 
				
			||||||
 | 
					pinos_main_loop_new (void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  return g_object_new (PINOS_TYPE_MAIN_LOOP, NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					  gulong          id;
 | 
				
			||||||
 | 
					  gpointer        obj;
 | 
				
			||||||
 | 
					  uint32_t        seq;
 | 
				
			||||||
 | 
					  SpaResult       res;
 | 
				
			||||||
 | 
					  PinosDeferFunc  func;
 | 
				
			||||||
 | 
					  gpointer       *data;
 | 
				
			||||||
 | 
					  GDestroyNotify  notify;
 | 
				
			||||||
 | 
					} WorkItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static gboolean
 | 
				
			||||||
 | 
					process_work_queue (PinosMainLoop *this)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PinosMainLoopPrivate *priv = this->priv;
 | 
				
			||||||
 | 
					  GList *walk, *next;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (walk = priv->work.head; walk; walk = next) {
 | 
				
			||||||
 | 
					    WorkItem *item = walk->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    next = g_list_next (walk);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    g_debug ("main-loop %p: peek work queue item %p seq %d", this, item, item ? item->seq : -1);
 | 
				
			||||||
 | 
					    if (item->seq != SPA_ID_INVALID)
 | 
				
			||||||
 | 
					      continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    g_debug ("main-loop %p: process work item %p", this, item);
 | 
				
			||||||
 | 
					    if (item->func)
 | 
				
			||||||
 | 
					      item->func (item->data, item->res, item->id);
 | 
				
			||||||
 | 
					    if (item->notify)
 | 
				
			||||||
 | 
					      item->notify (item->data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    g_queue_delete_link (&priv->work, walk);
 | 
				
			||||||
 | 
					    g_slice_free (WorkItem, item);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  priv->work_id = 0;
 | 
				
			||||||
 | 
					  return FALSE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gulong
 | 
				
			||||||
 | 
					pinos_main_loop_defer (PinosMainLoop  *loop,
 | 
				
			||||||
 | 
					                       gpointer        obj,
 | 
				
			||||||
 | 
					                       SpaResult       res,
 | 
				
			||||||
 | 
					                       PinosDeferFunc  func,
 | 
				
			||||||
 | 
					                       gpointer        data,
 | 
				
			||||||
 | 
					                       GDestroyNotify  notify)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  PinosMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					  WorkItem *item;
 | 
				
			||||||
 | 
					  gboolean have_work = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), 0);
 | 
				
			||||||
 | 
					  priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  item = g_slice_new (WorkItem);
 | 
				
			||||||
 | 
					  item->id = ++priv->counter;
 | 
				
			||||||
 | 
					  item->obj = obj;
 | 
				
			||||||
 | 
					  item->func = func;
 | 
				
			||||||
 | 
					  item->data = data;
 | 
				
			||||||
 | 
					  item->notify = notify;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (SPA_RESULT_IS_ASYNC (res)) {
 | 
				
			||||||
 | 
					    item->seq = SPA_RESULT_ASYNC_SEQ (res);
 | 
				
			||||||
 | 
					    item->res = res;
 | 
				
			||||||
 | 
					    g_debug ("main-loop %p: defer async %d for object %p", loop, item->seq, obj);
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    item->seq = SPA_ID_INVALID;
 | 
				
			||||||
 | 
					    item->res = res;
 | 
				
			||||||
 | 
					    have_work = TRUE;
 | 
				
			||||||
 | 
					    g_debug ("main-loop %p: defer object %p", loop, obj);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  g_queue_push_tail (&priv->work, item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (priv->work_id == 0 && have_work)
 | 
				
			||||||
 | 
					    priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return item->id;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					pinos_main_loop_defer_cancel (PinosMainLoop  *loop,
 | 
				
			||||||
 | 
					                              gulong          id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GList *walk;
 | 
				
			||||||
 | 
					  PinosMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
 | 
				
			||||||
 | 
					  priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (walk = priv->work.head; walk; walk = g_list_next (walk)) {
 | 
				
			||||||
 | 
					    WorkItem *i = walk->data;
 | 
				
			||||||
 | 
					    if (i->id == id) {
 | 
				
			||||||
 | 
					      i->func = NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					pinos_main_loop_defer_complete (PinosMainLoop  *loop,
 | 
				
			||||||
 | 
					                                gpointer        obj,
 | 
				
			||||||
 | 
					                                uint32_t        seq,
 | 
				
			||||||
 | 
					                                SpaResult       res)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GList *walk;
 | 
				
			||||||
 | 
					  PinosMainLoopPrivate *priv;
 | 
				
			||||||
 | 
					  gboolean have_work = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
 | 
				
			||||||
 | 
					  priv = loop->priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_debug ("main-loop %p: async complete %d %d for object %p", loop, seq, res, obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (walk = priv->work.head; walk; walk = g_list_next (walk)) {
 | 
				
			||||||
 | 
					    WorkItem *i = walk->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (i->obj == obj && i->seq == seq) {
 | 
				
			||||||
 | 
					      g_debug ("main-loop %p: found defered %d for object %p", loop, seq, obj);
 | 
				
			||||||
 | 
					      i->seq = SPA_ID_INVALID;
 | 
				
			||||||
 | 
					      i->res = res;
 | 
				
			||||||
 | 
					      have_work = TRUE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (priv->work_id == 0 && have_work)
 | 
				
			||||||
 | 
					    priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
/* Pinos
 | 
					/* Pinos
 | 
				
			||||||
 * Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
 | 
					 * Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This library is free software; you can redistribute it and/or
 | 
					 * This library is free software; you can redistribute it and/or
 | 
				
			||||||
 * modify it under the terms of the GNU Library General Public
 | 
					 * modify it under the terms of the GNU Library General Public
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,12 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_BEGIN_DECLS
 | 
					G_BEGIN_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <spa/include/spa/poll.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct _PinosMainLoop PinosMainLoop;
 | 
				
			||||||
 | 
					typedef struct _PinosMainLoopClass PinosMainLoopClass;
 | 
				
			||||||
 | 
					typedef struct _PinosMainLoopPrivate PinosMainLoopPrivate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define PINOS_TYPE_MAIN_LOOP                 (pinos_main_loop_get_type ())
 | 
					#define PINOS_TYPE_MAIN_LOOP                 (pinos_main_loop_get_type ())
 | 
				
			||||||
#define PINOS_IS_MAIN_LOOP(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_MAIN_LOOP))
 | 
					#define PINOS_IS_MAIN_LOOP(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_MAIN_LOOP))
 | 
				
			||||||
#define PINOS_IS_MAIN_LOOP_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_MAIN_LOOP))
 | 
					#define PINOS_IS_MAIN_LOOP_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_MAIN_LOOP))
 | 
				
			||||||
| 
						 | 
					@ -33,51 +39,50 @@ G_BEGIN_DECLS
 | 
				
			||||||
#define PINOS_MAIN_LOOP_CAST(obj)            ((PinosMainLoop*)(obj))
 | 
					#define PINOS_MAIN_LOOP_CAST(obj)            ((PinosMainLoop*)(obj))
 | 
				
			||||||
#define PINOS_MAIN_LOOP_CLASS_CAST(klass)    ((PinosMainLoopClass*)(klass))
 | 
					#define PINOS_MAIN_LOOP_CLASS_CAST(klass)    ((PinosMainLoopClass*)(klass))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct _PinosMainLoop PinosMainLoop;
 | 
					 | 
				
			||||||
typedef struct _PinosMainLoopClass PinosMainLoopClass;
 | 
					 | 
				
			||||||
typedef struct _PinosMainLoopPrivate PinosMainLoopPrivate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * PinosMainLoop:
 | 
					 * PinosMainLoop:
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Pinos main loop object class.
 | 
					 * Pinos rt-loop class.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct _PinosMainLoop {
 | 
					struct _PinosMainLoop {
 | 
				
			||||||
  GObject object;
 | 
					  GObject object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  SpaPoll poll;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosMainLoopPrivate *priv;
 | 
					  PinosMainLoopPrivate *priv;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * PinosMainLoopClass:
 | 
					 * PinosMainLoopClass:
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Pinos main loop object class.
 | 
					 * Pinos rt-loop class.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct _PinosMainLoopClass {
 | 
					struct _PinosMainLoopClass {
 | 
				
			||||||
  GObjectClass parent_class;
 | 
					  GObjectClass parent_class;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef void (*PinosDeferFunc) (gpointer       data,
 | 
				
			||||||
 | 
					                                SpaResult      res,
 | 
				
			||||||
 | 
					                                gulong         id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* normal GObject stuff */
 | 
					/* normal GObject stuff */
 | 
				
			||||||
GType            pinos_main_loop_get_type        (void);
 | 
					GType               pinos_main_loop_get_type                (void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PinosMainLoop *  pinos_main_loop_new             (GMainContext * context,
 | 
					PinosMainLoop *     pinos_main_loop_new                     (void);
 | 
				
			||||||
                                                  const gchar   *name);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
GMainLoop *      pinos_main_loop_get_impl        (PinosMainLoop *loop);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
gboolean         pinos_main_loop_start           (PinosMainLoop *loop, GError **error);
 | 
					 | 
				
			||||||
void             pinos_main_loop_stop            (PinosMainLoop *loop);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void             pinos_main_loop_lock            (PinosMainLoop *loop);
 | 
					 | 
				
			||||||
void             pinos_main_loop_unlock          (PinosMainLoop *loop);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void             pinos_main_loop_wait            (PinosMainLoop *loop);
 | 
					 | 
				
			||||||
void             pinos_main_loop_signal          (PinosMainLoop *loop, gboolean wait_for_accept);
 | 
					 | 
				
			||||||
void             pinos_main_loop_accept          (PinosMainLoop *loop);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
gboolean         pinos_main_loop_in_thread       (PinosMainLoop *loop);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gulong              pinos_main_loop_defer                   (PinosMainLoop  *loop,
 | 
				
			||||||
 | 
					                                                             gpointer        obj,
 | 
				
			||||||
 | 
					                                                             SpaResult       res,
 | 
				
			||||||
 | 
					                                                             PinosDeferFunc  func,
 | 
				
			||||||
 | 
					                                                             gpointer        data,
 | 
				
			||||||
 | 
					                                                             GDestroyNotify  notify);
 | 
				
			||||||
 | 
					void                pinos_main_loop_defer_cancel            (PinosMainLoop  *loop,
 | 
				
			||||||
 | 
					                                                             gulong          id);
 | 
				
			||||||
 | 
					void                pinos_main_loop_defer_complete          (PinosMainLoop  *loop,
 | 
				
			||||||
 | 
					                                                             gpointer        obj,
 | 
				
			||||||
 | 
					                                                             uint32_t        seq,
 | 
				
			||||||
 | 
					                                                             SpaResult       res);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_END_DECLS
 | 
					G_END_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,12 +3,13 @@ pinoscore_headers = [
 | 
				
			||||||
  'client-node.h',
 | 
					  'client-node.h',
 | 
				
			||||||
  'command.h',
 | 
					  'command.h',
 | 
				
			||||||
  'daemon.h',
 | 
					  'daemon.h',
 | 
				
			||||||
 | 
					  'data-loop.h',
 | 
				
			||||||
  'dbus-client-node.h',
 | 
					  'dbus-client-node.h',
 | 
				
			||||||
  'link.h',
 | 
					  'link.h',
 | 
				
			||||||
 | 
					  'main-loop.h',
 | 
				
			||||||
  'module.h',
 | 
					  'module.h',
 | 
				
			||||||
  'node.h',
 | 
					  'node.h',
 | 
				
			||||||
  'node-factory.h',
 | 
					  'node-factory.h',
 | 
				
			||||||
  'rt-loop.h',
 | 
					 | 
				
			||||||
  'utils.h',
 | 
					  'utils.h',
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,12 +18,13 @@ pinoscore_sources = [
 | 
				
			||||||
  'client-node.c',
 | 
					  'client-node.c',
 | 
				
			||||||
  'command.c',
 | 
					  'command.c',
 | 
				
			||||||
  'daemon.c',
 | 
					  'daemon.c',
 | 
				
			||||||
 | 
					  'data-loop.c',
 | 
				
			||||||
  'dbus-client-node.c',
 | 
					  'dbus-client-node.c',
 | 
				
			||||||
  'link.c',
 | 
					  'link.c',
 | 
				
			||||||
 | 
					  'main-loop.c',
 | 
				
			||||||
  'module.c',
 | 
					  'module.c',
 | 
				
			||||||
  'node.c',
 | 
					  'node.c',
 | 
				
			||||||
  'node-factory.c',
 | 
					  'node-factory.c',
 | 
				
			||||||
  'rt-loop.c',
 | 
					 | 
				
			||||||
  'utils.c',
 | 
					  'utils.c',
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,8 @@
 | 
				
			||||||
#include "pinos/client/enumtypes.h"
 | 
					#include "pinos/client/enumtypes.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "pinos/server/node.h"
 | 
					#include "pinos/server/node.h"
 | 
				
			||||||
#include "pinos/server/rt-loop.h"
 | 
					#include "pinos/server/data-loop.h"
 | 
				
			||||||
 | 
					#include "pinos/server/main-loop.h"
 | 
				
			||||||
#include "pinos/server/daemon.h"
 | 
					#include "pinos/server/daemon.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "pinos/dbus/org-pinos.h"
 | 
					#include "pinos/dbus/org-pinos.h"
 | 
				
			||||||
| 
						 | 
					@ -89,11 +90,8 @@ struct _PinosNodePrivate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosProperties *properties;
 | 
					  PinosProperties *properties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PinosRTLoop *loop;
 | 
					  PinosDataLoop *data_loop;
 | 
				
			||||||
 | 
					  PinosMainLoop *main_loop;
 | 
				
			||||||
  SpaNodeEventAsyncComplete ac;
 | 
					 | 
				
			||||||
  uint32_t pending_state_seq;
 | 
					 | 
				
			||||||
  PinosNodeState pending_state;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_DEFINE_TYPE (PinosNode, pinos_node, G_TYPE_OBJECT);
 | 
					G_DEFINE_TYPE (PinosNode, pinos_node, G_TYPE_OBJECT);
 | 
				
			||||||
| 
						 | 
					@ -103,7 +101,7 @@ enum
 | 
				
			||||||
  PROP_0,
 | 
					  PROP_0,
 | 
				
			||||||
  PROP_DAEMON,
 | 
					  PROP_DAEMON,
 | 
				
			||||||
  PROP_CLIENT,
 | 
					  PROP_CLIENT,
 | 
				
			||||||
  PROP_RTLOOP,
 | 
					  PROP_DATA_LOOP,
 | 
				
			||||||
  PROP_OBJECT_PATH,
 | 
					  PROP_OBJECT_PATH,
 | 
				
			||||||
  PROP_NAME,
 | 
					  PROP_NAME,
 | 
				
			||||||
  PROP_PROPERTIES,
 | 
					  PROP_PROPERTIES,
 | 
				
			||||||
| 
						 | 
					@ -330,12 +328,24 @@ send_clock_update (PinosNode *this)
 | 
				
			||||||
    g_debug ("got error %d", res);
 | 
					    g_debug ("got error %d", res);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					  PinosNode *node;
 | 
				
			||||||
 | 
					  PinosNodeState state;
 | 
				
			||||||
 | 
					} StateData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					on_state_complete (StateData *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  pinos_node_update_state (data->node, data->state);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gboolean
 | 
					static gboolean
 | 
				
			||||||
node_set_state (PinosNode       *this,
 | 
					node_set_state (PinosNode       *this,
 | 
				
			||||||
                PinosNodeState   state)
 | 
					                PinosNodeState   state)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PinosNodePrivate *priv = this->priv;
 | 
					  PinosNodePrivate *priv = this->priv;
 | 
				
			||||||
  SpaResult res = SPA_RESULT_OK;
 | 
					  SpaResult res = SPA_RESULT_OK;
 | 
				
			||||||
 | 
					  StateData data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("node %p: set state %s", this, pinos_node_state_as_string (state));
 | 
					  g_debug ("node %p: set state %s", this, pinos_node_state_as_string (state));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -365,12 +375,15 @@ node_set_state (PinosNode       *this,
 | 
				
			||||||
  if (SPA_RESULT_IS_ERROR (res))
 | 
					  if (SPA_RESULT_IS_ERROR (res))
 | 
				
			||||||
    return FALSE;
 | 
					    return FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (SPA_RESULT_IS_ASYNC (res)) {
 | 
					  data.node = this;
 | 
				
			||||||
    priv->pending_state_seq = SPA_RESULT_ASYNC_SEQ (res);
 | 
					  data.state = state;
 | 
				
			||||||
    priv->pending_state = state;
 | 
					
 | 
				
			||||||
  } else {
 | 
					  pinos_main_loop_defer (priv->main_loop,
 | 
				
			||||||
    pinos_node_update_state (this, state);
 | 
					                         this,
 | 
				
			||||||
  }
 | 
					                         res,
 | 
				
			||||||
 | 
					                         (PinosDeferFunc) on_state_complete,
 | 
				
			||||||
 | 
					                         g_memdup (&data, sizeof (StateData)),
 | 
				
			||||||
 | 
					                         g_free);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -387,7 +400,7 @@ do_read_link (PinosNode *this, PinosLink *link)
 | 
				
			||||||
  if (areas[0].len > 0) {
 | 
					  if (areas[0].len > 0) {
 | 
				
			||||||
    SpaPortInputInfo iinfo[1];
 | 
					    SpaPortInputInfo iinfo[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (link->in_ready <= 0)
 | 
					    if (link->in_ready <= 0 || link->input == NULL)
 | 
				
			||||||
      return FALSE;
 | 
					      return FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    link->in_ready--;
 | 
					    link->in_ready--;
 | 
				
			||||||
| 
						 | 
					@ -406,24 +419,6 @@ do_read_link (PinosNode *this, PinosLink *link)
 | 
				
			||||||
  return pushed;
 | 
					  return pushed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					 | 
				
			||||||
do_handle_async_complete (PinosNode *this)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  PinosNodePrivate *priv = this->priv;
 | 
					 | 
				
			||||||
  SpaNodeEventAsyncComplete *ac = &priv->ac;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  g_debug ("node %p: async complete %u %d", this, ac->seq, ac->res);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (priv->async_init) {
 | 
					 | 
				
			||||||
    init_complete (this);
 | 
					 | 
				
			||||||
    priv->async_init = FALSE;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if (priv->pending_state_seq == ac->seq) {
 | 
					 | 
				
			||||||
    pinos_node_update_state (this, priv->pending_state);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
 | 
					on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -443,10 +438,9 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      SpaNodeEventAsyncComplete *ac = event->data;
 | 
					      SpaNodeEventAsyncComplete *ac = event->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      priv->ac = *ac;
 | 
					      g_debug ("node %p: async complete event %d %d", this, ac->seq, ac->res);
 | 
				
			||||||
      g_main_context_invoke (NULL,
 | 
					      pinos_main_loop_defer_complete (priv->main_loop, this, ac->seq, ac->res);
 | 
				
			||||||
                            (GSourceFunc) do_handle_async_complete,
 | 
					      g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res);
 | 
				
			||||||
                            this);
 | 
					 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -518,6 +512,9 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
 | 
				
			||||||
      for (i = 0; i < p->links->len; i++) {
 | 
					      for (i = 0; i < p->links->len; i++) {
 | 
				
			||||||
        PinosLink *link = g_ptr_array_index (p->links, i);
 | 
					        PinosLink *link = g_ptr_array_index (p->links, i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (link->output == NULL)
 | 
				
			||||||
 | 
					          continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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)
 | 
				
			||||||
| 
						 | 
					@ -564,8 +561,8 @@ pinos_node_get_property (GObject    *_object,
 | 
				
			||||||
      g_value_set_object (value, priv->client);
 | 
					      g_value_set_object (value, priv->client);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case PROP_RTLOOP:
 | 
					    case PROP_DATA_LOOP:
 | 
				
			||||||
      g_value_set_object (value, priv->loop);
 | 
					      g_value_set_object (value, priv->data_loop);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case PROP_OBJECT_PATH:
 | 
					    case PROP_OBJECT_PATH:
 | 
				
			||||||
| 
						 | 
					@ -612,15 +609,15 @@ pinos_node_set_property (GObject      *_object,
 | 
				
			||||||
      priv->client = g_value_get_object (value);
 | 
					      priv->client = g_value_get_object (value);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case PROP_RTLOOP:
 | 
					    case PROP_DATA_LOOP:
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      SpaResult res;
 | 
					      SpaResult res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (priv->loop)
 | 
					      if (priv->data_loop)
 | 
				
			||||||
        g_object_unref (priv->loop);
 | 
					        g_object_unref (priv->data_loop);
 | 
				
			||||||
      priv->loop = g_value_dup_object (value);
 | 
					      priv->data_loop = g_value_dup_object (value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (priv->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);
 | 
					         g_warning ("node %p: error setting callback", this);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -640,13 +637,6 @@ pinos_node_set_property (GObject      *_object,
 | 
				
			||||||
    case PROP_NODE:
 | 
					    case PROP_NODE:
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      this->node = g_value_get_pointer (value);
 | 
					      this->node = g_value_get_pointer (value);
 | 
				
			||||||
#if 0
 | 
					 | 
				
			||||||
      void *iface;
 | 
					 | 
				
			||||||
      if (this->node->handle->get_interface (this->node->handle,
 | 
					 | 
				
			||||||
                                             spa_id_map_get_id (priv->daemon->map, SPA_CLOCK_URI),
 | 
					 | 
				
			||||||
                                             &iface) >= 0)
 | 
					 | 
				
			||||||
        this->clock = iface;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    case PROP_CLOCK:
 | 
					    case PROP_CLOCK:
 | 
				
			||||||
| 
						 | 
					@ -734,6 +724,8 @@ pinos_node_constructed (GObject * obj)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_debug ("node %p: constructed", this);
 | 
					  g_debug ("node %p: constructed", this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  priv->main_loop = priv->daemon->main_loop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
 | 
					  g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
 | 
				
			||||||
  G_OBJECT_CLASS (pinos_node_parent_class)->constructed (obj);
 | 
					  G_OBJECT_CLASS (pinos_node_parent_class)->constructed (obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -753,6 +745,12 @@ pinos_node_constructed (GObject * obj)
 | 
				
			||||||
    init_complete (this);
 | 
					    init_complete (this);
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    priv->async_init = TRUE;
 | 
					    priv->async_init = TRUE;
 | 
				
			||||||
 | 
					    pinos_main_loop_defer (priv->main_loop,
 | 
				
			||||||
 | 
					                           this,
 | 
				
			||||||
 | 
					                           SPA_RESULT_RETURN_ASYNC (0),
 | 
				
			||||||
 | 
					                           (PinosDeferFunc) init_complete,
 | 
				
			||||||
 | 
					                           this,
 | 
				
			||||||
 | 
					                           NULL);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  node_register_object (this);
 | 
					  node_register_object (this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -780,7 +778,7 @@ pinos_node_finalize (GObject * obj)
 | 
				
			||||||
  g_debug ("node %p: finalize", node);
 | 
					  g_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->loop);
 | 
					  g_clear_object (&priv->data_loop);
 | 
				
			||||||
  g_free (priv->name);
 | 
					  g_free (priv->name);
 | 
				
			||||||
  g_clear_error (&priv->error);
 | 
					  g_clear_error (&priv->error);
 | 
				
			||||||
  if (priv->properties)
 | 
					  if (priv->properties)
 | 
				
			||||||
| 
						 | 
					@ -869,11 +867,11 @@ pinos_node_class_init (PinosNodeClass * klass)
 | 
				
			||||||
                                                         G_PARAM_CONSTRUCT_ONLY |
 | 
					                                                         G_PARAM_CONSTRUCT_ONLY |
 | 
				
			||||||
                                                         G_PARAM_STATIC_STRINGS));
 | 
					                                                         G_PARAM_STATIC_STRINGS));
 | 
				
			||||||
  g_object_class_install_property (gobject_class,
 | 
					  g_object_class_install_property (gobject_class,
 | 
				
			||||||
                                   PROP_RTLOOP,
 | 
					                                   PROP_DATA_LOOP,
 | 
				
			||||||
                                   g_param_spec_object ("rt-loop",
 | 
					                                   g_param_spec_object ("data-loop",
 | 
				
			||||||
                                                        "RTLoop",
 | 
					                                                        "Data Loop",
 | 
				
			||||||
                                                        "The RTLoop",
 | 
					                                                        "The Data Loop",
 | 
				
			||||||
                                                        PINOS_TYPE_RTLOOP,
 | 
					                                                        PINOS_TYPE_DATA_LOOP,
 | 
				
			||||||
                                                        G_PARAM_READWRITE |
 | 
					                                                        G_PARAM_READWRITE |
 | 
				
			||||||
                                                        G_PARAM_CONSTRUCT |
 | 
					                                                        G_PARAM_CONSTRUCT |
 | 
				
			||||||
                                                        G_PARAM_STATIC_STRINGS));
 | 
					                                                        G_PARAM_STATIC_STRINGS));
 | 
				
			||||||
| 
						 | 
					@ -945,7 +943,6 @@ pinos_node_init (PinosNode * node)
 | 
				
			||||||
                                 (GCallback) handle_remove,
 | 
					                                 (GCallback) handle_remove,
 | 
				
			||||||
                                 node);
 | 
					                                 node);
 | 
				
			||||||
  priv->state = PINOS_NODE_STATE_CREATING;
 | 
					  priv->state = PINOS_NODE_STATE_CREATING;
 | 
				
			||||||
  priv->pending_state_seq = SPA_ID_INVALID;
 | 
					 | 
				
			||||||
  pinos_node1_set_state (priv->iface, priv->state);
 | 
					  pinos_node1_set_state (priv->iface, priv->state);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,79 +0,0 @@
 | 
				
			||||||
/* Pinos
 | 
					 | 
				
			||||||
 * 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_RTLOOP_H__
 | 
					 | 
				
			||||||
#define __PINOS_RTLOOP_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <glib-object.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
G_BEGIN_DECLS
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <spa/include/spa/poll.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct _PinosRTLoop PinosRTLoop;
 | 
					 | 
				
			||||||
typedef struct _PinosRTLoopClass PinosRTLoopClass;
 | 
					 | 
				
			||||||
typedef struct _PinosRTLoopPrivate PinosRTLoopPrivate;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define PINOS_TYPE_RTLOOP                 (pinos_rtloop_get_type ())
 | 
					 | 
				
			||||||
#define PINOS_IS_RTLOOP(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_RTLOOP))
 | 
					 | 
				
			||||||
#define PINOS_IS_RTLOOP_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_RTLOOP))
 | 
					 | 
				
			||||||
#define PINOS_RTLOOP_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_RTLOOP, PinosRTLoopClass))
 | 
					 | 
				
			||||||
#define PINOS_RTLOOP(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_RTLOOP, PinosRTLoop))
 | 
					 | 
				
			||||||
#define PINOS_RTLOOP_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_RTLOOP, PinosRTLoopClass))
 | 
					 | 
				
			||||||
#define PINOS_RTLOOP_CAST(obj)            ((PinosRTLoop*)(obj))
 | 
					 | 
				
			||||||
#define PINOS_RTLOOP_CLASS_CAST(klass)    ((PinosRTLoopClass*)(klass))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * PinosRTLoop:
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Pinos rt-loop class.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct _PinosRTLoop {
 | 
					 | 
				
			||||||
  GObject object;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  SpaPoll poll;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  PinosRTLoopPrivate *priv;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * PinosRTLoopClass:
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Pinos rt-loop class.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct _PinosRTLoopClass {
 | 
					 | 
				
			||||||
  GObjectClass parent_class;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* normal GObject stuff */
 | 
					 | 
				
			||||||
GType               pinos_rtloop_get_type                (void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
PinosRTLoop *       pinos_rtloop_new                     (void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
gboolean            pinos_rtloop_add_poll                (PinosRTLoop *loop,
 | 
					 | 
				
			||||||
                                                          SpaPollItem *item);
 | 
					 | 
				
			||||||
gboolean            pinos_rtloop_update_poll             (PinosRTLoop *loop,
 | 
					 | 
				
			||||||
                                                          SpaPollItem *item);
 | 
					 | 
				
			||||||
gboolean            pinos_rtloop_remove_poll             (PinosRTLoop *loop,
 | 
					 | 
				
			||||||
                                                          SpaPollItem *item);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
G_END_DECLS
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __PINOS_RTLOOP_H__ */
 | 
					 | 
				
			||||||
| 
						 | 
					@ -39,12 +39,12 @@ typedef struct _SpaNode SpaNode;
 | 
				
			||||||
 * @SPA_NODE_STATE_ERROR: the node is in error
 | 
					 * @SPA_NODE_STATE_ERROR: the node is in error
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
typedef enum {
 | 
					typedef enum {
 | 
				
			||||||
  SPA_NODE_STATE_INIT,
 | 
					  SPA_NODE_STATE_ERROR       = -1,
 | 
				
			||||||
 | 
					  SPA_NODE_STATE_INIT        = 0,
 | 
				
			||||||
  SPA_NODE_STATE_CONFIGURE,
 | 
					  SPA_NODE_STATE_CONFIGURE,
 | 
				
			||||||
  SPA_NODE_STATE_READY,
 | 
					  SPA_NODE_STATE_READY,
 | 
				
			||||||
  SPA_NODE_STATE_PAUSED,
 | 
					  SPA_NODE_STATE_PAUSED,
 | 
				
			||||||
  SPA_NODE_STATE_STREAMING,
 | 
					  SPA_NODE_STATE_STREAMING,
 | 
				
			||||||
  SPA_NODE_STATE_ERROR
 | 
					 | 
				
			||||||
} SpaNodeState;
 | 
					} SpaNodeState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue