mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-23 06:59:58 -05:00
More hacking
Add connection message for PORT_COMMAND Add rtkit support to ask for realtime priority work on stream states and improve negotiation Rework of port linking works, keep separate state for realtime threads and use message passing to update the state. Don't try to link nodes that are removed. Open the device in the ALSA monitor to detect source or sink Implement send_command as async methods on the plugins, use async replies to sync start and stop. Work on alsa sink. Implement async PAUSE/START on v4l2 src. move the STREAMON/OFF calls to the mainloop because they have high latency, add the poll descriptors from the data loop.
This commit is contained in:
parent
984375c0b2
commit
3f4ccaaea2
32 changed files with 1335 additions and 545 deletions
|
|
@ -151,6 +151,15 @@ connection_parse_node_command (PinosConnection *conn, PinosControlCmdNodeCommand
|
|||
cmd->command = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->command), SpaNodeCommand);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_parse_port_command (PinosConnection *conn, PinosControlCmdPortCommand *cmd)
|
||||
{
|
||||
void *p = conn->in.data;
|
||||
memcpy (cmd, p, sizeof (PinosControlCmdPortCommand));
|
||||
if (cmd->command)
|
||||
cmd->command = SPA_MEMBER (p, SPA_PTR_TO_INT (cmd->command), SpaNodeCommand);
|
||||
}
|
||||
|
||||
static void *
|
||||
connection_ensure_size (PinosConnection *conn, ConnectionBuffer *buf, size_t size)
|
||||
{
|
||||
|
|
@ -363,6 +372,27 @@ connection_add_node_command (PinosConnection *conn, PinosControlCmdNodeCommand *
|
|||
memcpy (p, cm->command, cm->command->size);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_add_port_command (PinosConnection *conn, PinosControlCmdPortCommand *cm)
|
||||
{
|
||||
size_t len;
|
||||
void *p;
|
||||
PinosControlCmdPortCommand *d;
|
||||
|
||||
/* calculate length */
|
||||
len = sizeof (PinosControlCmdPortCommand);
|
||||
len += cm->command->size;
|
||||
|
||||
p = connection_add_cmd (conn, PINOS_CONTROL_CMD_PORT_COMMAND, len);
|
||||
memcpy (p, cm, sizeof (PinosControlCmdPortCommand));
|
||||
d = p;
|
||||
|
||||
p = SPA_MEMBER (d, sizeof (PinosControlCmdPortCommand), void);
|
||||
d->command = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
|
||||
|
||||
memcpy (p, cm->command, cm->command->size);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
refill_buffer (PinosConnection *conn, ConnectionBuffer *buf)
|
||||
{
|
||||
|
|
@ -595,6 +625,10 @@ pinos_connection_parse_cmd (PinosConnection *conn,
|
|||
connection_parse_node_command (conn, command);
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_PORT_COMMAND:
|
||||
connection_parse_port_command (conn, command);
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_INVALID:
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -742,6 +776,10 @@ pinos_connection_add_cmd (PinosConnection *conn,
|
|||
connection_add_node_command (conn, command);
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_PORT_COMMAND:
|
||||
connection_add_port_command (conn, command);
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_INVALID:
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ typedef enum {
|
|||
PINOS_CONTROL_CMD_SET_PROPERTY = 35,
|
||||
|
||||
PINOS_CONTROL_CMD_NODE_COMMAND = 36,
|
||||
PINOS_CONTROL_CMD_PORT_COMMAND = 37,
|
||||
|
||||
/* both */
|
||||
PINOS_CONTROL_CMD_ADD_MEM = 64,
|
||||
|
|
@ -132,6 +133,12 @@ typedef struct {
|
|||
SpaNodeCommand *command;
|
||||
} PinosControlCmdNodeCommand;
|
||||
|
||||
/* PINOS_CONTROL_CMD_PORT_COMMAND */
|
||||
typedef struct {
|
||||
uint32_t port_id;
|
||||
SpaNodeCommand *command;
|
||||
} PinosControlCmdPortCommand;
|
||||
|
||||
/* PINOS_CONTROL_CMD_ADD_MEM */
|
||||
typedef struct {
|
||||
SpaDirection direction;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
#include <gio/gio.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <spa/include/spa/defs.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
|
|
@ -59,9 +61,9 @@ const gchar * pinos_node_state_as_string (PinosNodeState state);
|
|||
* The direction of a port
|
||||
*/
|
||||
typedef enum {
|
||||
PINOS_DIRECTION_INVALID = 0,
|
||||
PINOS_DIRECTION_INPUT = 1,
|
||||
PINOS_DIRECTION_OUTPUT = 2
|
||||
PINOS_DIRECTION_INVALID = SPA_DIRECTION_INVALID,
|
||||
PINOS_DIRECTION_INPUT = SPA_DIRECTION_INPUT,
|
||||
PINOS_DIRECTION_OUTPUT = SPA_DIRECTION_OUTPUT
|
||||
} PinosDirection;
|
||||
|
||||
const gchar * pinos_direction_as_string (PinosDirection direction);
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ pinos_headers = [
|
|||
'introspect.h',
|
||||
'pinos.h',
|
||||
'properties.h',
|
||||
'stream.h',
|
||||
'ringbuffer.h',
|
||||
'rtkit.h',
|
||||
'stream.h',
|
||||
'subscribe.h',
|
||||
'thread-mainloop.h',
|
||||
]
|
||||
|
|
@ -20,6 +21,7 @@ pinos_sources = [
|
|||
'stream.c',
|
||||
'pinos.c',
|
||||
'ringbuffer.c',
|
||||
'rtkit.c',
|
||||
'subscribe.c',
|
||||
'thread-mainloop.c',
|
||||
gdbus_target,
|
||||
|
|
|
|||
104
pinos/client/rtkit.c
Normal file
104
pinos/client/rtkit.c
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include "rtkit.h"
|
||||
|
||||
static pid_t _gettid(void) {
|
||||
return (pid_t) syscall(SYS_gettid);
|
||||
}
|
||||
|
||||
gboolean
|
||||
pinos_rtkit_make_realtime (GDBusConnection *system_bus,
|
||||
pid_t thread,
|
||||
gint priority,
|
||||
GError **error)
|
||||
{
|
||||
GVariant *v;
|
||||
|
||||
if (thread == 0)
|
||||
thread = _gettid();
|
||||
|
||||
v = g_dbus_connection_call_sync (system_bus,
|
||||
RTKIT_SERVICE_NAME,
|
||||
RTKIT_OBJECT_PATH,
|
||||
"org.freedesktop.RealtimeKit1",
|
||||
"MakeThreadRealtime",
|
||||
g_variant_new ("(tu)",
|
||||
(guint64) thread,
|
||||
(guint32) priority),
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
error);
|
||||
if (v)
|
||||
g_variant_unref (v);
|
||||
|
||||
return v != NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
pinos_rtkit_make_high_priority (GDBusConnection *system_bus,
|
||||
pid_t thread,
|
||||
gint nice_level,
|
||||
GError **error)
|
||||
{
|
||||
GVariant *v;
|
||||
|
||||
if (thread == 0)
|
||||
thread = _gettid();
|
||||
|
||||
v = g_dbus_connection_call_sync (system_bus,
|
||||
RTKIT_SERVICE_NAME,
|
||||
RTKIT_OBJECT_PATH,
|
||||
"org.freedesktop.RealtimeKit1",
|
||||
"MakeThreadHighPriority",
|
||||
g_variant_new ("(tu)",
|
||||
(guint64) thread,
|
||||
(guint32) nice_level),
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL,
|
||||
error);
|
||||
if (v)
|
||||
g_variant_unref (v);
|
||||
|
||||
return v != NULL;
|
||||
}
|
||||
|
||||
int pinos_rtkit_get_max_realtime_priority (GDBusConnection *system_bus)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pinos_rtkit_get_min_nice_level (GDBusConnection *system_bus, int* min_nice_level)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Return the maximum value of RLIMIT_RTTIME to set before attempting a
|
||||
* realtime request. A negative value is an errno style error code.
|
||||
*/
|
||||
long long rtkit_get_rttime_usec_max (GDBusConnection *system_bus)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
68
pinos/client/rtkit.h
Normal file
68
pinos/client/rtkit.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* 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_RTKIT_H__
|
||||
#define __PINOS_RTKIT_H__
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define RTKIT_SERVICE_NAME "org.freedesktop.RealtimeKit1"
|
||||
#define RTKIT_OBJECT_PATH "/org/freedesktop/RealtimeKit1"
|
||||
|
||||
/* This is mostly equivalent to sched_setparam(thread, SCHED_RR, {
|
||||
* .sched_priority = priority }). 'thread' needs to be a kernel thread
|
||||
* id as returned by gettid(), not a pthread_t! If 'thread' is 0 the
|
||||
* current thread is used.
|
||||
*/
|
||||
gboolean pinos_rtkit_make_realtime (GDBusConnection *system_bus,
|
||||
pid_t thread,
|
||||
gint priority,
|
||||
GError **error);
|
||||
|
||||
|
||||
/* This is mostly equivalent to setpriority(PRIO_PROCESS, thread,
|
||||
* nice_level). 'thread' needs to be a kernel thread id as returned by
|
||||
* gettid(), not a pthread_t! If 'thread' is 0 the current thread is
|
||||
* used. */
|
||||
gboolean pinos_rtkit_make_high_priority (GDBusConnection *system_bus,
|
||||
pid_t thread,
|
||||
gint nice_level,
|
||||
GError **error);
|
||||
|
||||
/* Return the maximum value of realtime priority available. Realtime requests
|
||||
* above this value will fail. A negative value is an errno style error code.
|
||||
*/
|
||||
int pinos_rtkit_get_max_realtime_priority (GDBusConnection *system_bus);
|
||||
|
||||
/* Retreive the minimum value of nice level available. High prio requests
|
||||
* below this value will fail. The returned value is a negative errno
|
||||
* style error code, or 0 on success.*/
|
||||
int pinos_rtkit_get_min_nice_level (GDBusConnection *system_bus, int* min_nice_level);
|
||||
|
||||
/* Return the maximum value of RLIMIT_RTTIME to set before attempting a
|
||||
* realtime request. A negative value is an errno style error code.
|
||||
*/
|
||||
long long rtkit_get_rttime_usec_max (GDBusConnection *system_bus);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_RTKIT_H__ */
|
||||
|
|
@ -874,7 +874,7 @@ handle_node_command (PinosStream *stream,
|
|||
break;
|
||||
case SPA_NODE_COMMAND_PAUSE:
|
||||
{
|
||||
g_debug ("stream %p: pause", stream);
|
||||
g_debug ("stream %p: pause %d", stream, seq);
|
||||
|
||||
add_state_change (stream, SPA_NODE_STATE_PAUSED);
|
||||
add_async_complete (stream, seq, SPA_RESULT_OK);
|
||||
|
|
@ -882,12 +882,12 @@ handle_node_command (PinosStream *stream,
|
|||
if (!pinos_connection_flush (priv->conn))
|
||||
g_warning ("stream %p: error writing connection", stream);
|
||||
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL);
|
||||
break;
|
||||
}
|
||||
case SPA_NODE_COMMAND_START:
|
||||
{
|
||||
g_debug ("stream %p: start", stream);
|
||||
g_debug ("stream %p: start %d", stream, seq);
|
||||
add_state_change (stream, SPA_NODE_STATE_STREAMING);
|
||||
add_async_complete (stream, seq, SPA_RESULT_OK);
|
||||
|
||||
|
|
@ -911,7 +911,6 @@ handle_node_command (PinosStream *stream,
|
|||
g_warning ("stream %p: error writing connection", stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case SPA_NODE_COMMAND_CLOCK_UPDATE:
|
||||
{
|
||||
SpaNodeCommandClockUpdate *cu = (SpaNodeCommandClockUpdate *) command;
|
||||
|
|
@ -945,7 +944,7 @@ parse_connection (PinosStream *stream)
|
|||
case PINOS_CONTROL_CMD_PORT_STATUS_CHANGE:
|
||||
case PINOS_CONTROL_CMD_NODE_STATE_CHANGE:
|
||||
case PINOS_CONTROL_CMD_PROCESS_BUFFER:
|
||||
g_warning ("got unexpected connection %d", cmd);
|
||||
g_warning ("got unexpected command %d", cmd);
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_ADD_PORT:
|
||||
|
|
@ -968,6 +967,7 @@ parse_connection (PinosStream *stream)
|
|||
|
||||
priv->pending_seq = p.seq;
|
||||
g_object_notify (G_OBJECT (stream), "format");
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_SET_PROPERTY:
|
||||
|
|
@ -1114,6 +1114,11 @@ parse_connection (PinosStream *stream)
|
|||
|
||||
if (!pinos_connection_flush (conn))
|
||||
g_warning ("stream %p: error writing connection", stream);
|
||||
|
||||
if (p.n_buffers)
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL);
|
||||
else
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_NODE_EVENT:
|
||||
|
|
@ -1136,7 +1141,15 @@ parse_connection (PinosStream *stream)
|
|||
handle_node_command (stream, p.seq, p.command);
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_PORT_COMMAND:
|
||||
{
|
||||
PinosControlCmdPortCommand p;
|
||||
|
||||
if (!pinos_connection_parse_cmd (conn, &p))
|
||||
break;
|
||||
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_INVALID:
|
||||
g_warning ("unhandled command %d", cmd);
|
||||
break;
|
||||
|
|
@ -1167,7 +1180,7 @@ parse_rtconnection (PinosStream *stream)
|
|||
case PINOS_CONTROL_CMD_ADD_MEM:
|
||||
case PINOS_CONTROL_CMD_USE_BUFFERS:
|
||||
case PINOS_CONTROL_CMD_NODE_COMMAND:
|
||||
g_warning ("got unexpected connection %d", cmd);
|
||||
g_warning ("got unexpected command %d", cmd);
|
||||
break;
|
||||
|
||||
case PINOS_CONTROL_CMD_PROCESS_BUFFER:
|
||||
|
|
@ -1202,6 +1215,10 @@ parse_rtconnection (PinosStream *stream)
|
|||
handle_rtnode_event (stream, p.event);
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_PORT_COMMAND:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1344,7 +1361,7 @@ on_node_proxy (GObject *source_object,
|
|||
|
||||
do_node_init (stream);
|
||||
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_READY, NULL);
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_CONFIGURE, NULL);
|
||||
g_object_unref (stream);
|
||||
|
||||
return;
|
||||
|
|
@ -1664,9 +1681,7 @@ pinos_stream_start (PinosStream *stream)
|
|||
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
||||
|
||||
priv = stream->priv;
|
||||
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_READY, FALSE);
|
||||
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_STARTING, NULL);
|
||||
//g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_PAUSED, FALSE);
|
||||
|
||||
g_main_context_invoke (priv->context->priv->context,
|
||||
(GSourceFunc) do_start,
|
||||
|
|
@ -1709,8 +1724,8 @@ pinos_stream_stop (PinosStream *stream)
|
|||
|
||||
static void
|
||||
on_node_removed (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosStream *stream = user_data;
|
||||
PinosStreamPrivate *priv = stream->priv;
|
||||
|
|
|
|||
|
|
@ -47,9 +47,10 @@ typedef enum {
|
|||
PINOS_STREAM_STATE_ERROR = -1,
|
||||
PINOS_STREAM_STATE_UNCONNECTED = 0,
|
||||
PINOS_STREAM_STATE_CONNECTING = 1,
|
||||
PINOS_STREAM_STATE_READY = 2,
|
||||
PINOS_STREAM_STATE_STARTING = 3,
|
||||
PINOS_STREAM_STATE_STREAMING = 4
|
||||
PINOS_STREAM_STATE_CONFIGURE = 2,
|
||||
PINOS_STREAM_STATE_READY = 3,
|
||||
PINOS_STREAM_STATE_PAUSED = 4,
|
||||
PINOS_STREAM_STATE_STREAMING = 5
|
||||
} PinosStreamState;
|
||||
|
||||
const gchar * pinos_stream_state_as_string (PinosStreamState state);
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ release_buffer (GstBufferPool * pool, GstBuffer *buffer)
|
|||
GST_DEBUG ("release buffer %p", buffer);
|
||||
GST_OBJECT_LOCK (pool);
|
||||
g_queue_push_tail (&p->available, buffer);
|
||||
g_cond_signal (&p->cond);
|
||||
GST_OBJECT_UNLOCK (pool);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -450,6 +450,7 @@ on_new_buffer (GObject *gobject,
|
|||
buf = g_hash_table_lookup (pinossink->buf_ids, GINT_TO_POINTER (id));
|
||||
|
||||
if (buf) {
|
||||
gst_buffer_unref (buf);
|
||||
pinos_thread_main_loop_signal (pinossink->loop, FALSE);
|
||||
}
|
||||
}
|
||||
|
|
@ -469,9 +470,10 @@ on_stream_notify (GObject *gobject,
|
|||
switch (state) {
|
||||
case PINOS_STREAM_STATE_UNCONNECTED:
|
||||
case PINOS_STREAM_STATE_CONNECTING:
|
||||
case PINOS_STREAM_STATE_STARTING:
|
||||
case PINOS_STREAM_STATE_STREAMING:
|
||||
case PINOS_STREAM_STATE_CONFIGURE:
|
||||
case PINOS_STREAM_STATE_READY:
|
||||
case PINOS_STREAM_STATE_PAUSED:
|
||||
case PINOS_STREAM_STATE_STREAMING:
|
||||
break;
|
||||
case PINOS_STREAM_STATE_ERROR:
|
||||
GST_ELEMENT_ERROR (pinossink, RESOURCE, FAILED,
|
||||
|
|
@ -487,6 +489,7 @@ on_format_notify (GObject *gobject,
|
|||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
#if 0
|
||||
GstPinosSink *pinossink = user_data;
|
||||
GstStructure *config;
|
||||
GstCaps *caps;
|
||||
|
|
@ -514,6 +517,7 @@ on_format_notify (GObject *gobject,
|
|||
param_meta_enable.type = SPA_META_TYPE_HEADER;
|
||||
|
||||
pinos_stream_finish_format (pinossink->stream, SPA_RESULT_OK, port_params, 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -634,10 +638,12 @@ gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
|||
d->offset = mem->offset;
|
||||
d->size = mem->size;
|
||||
}
|
||||
gst_buffer_ref (buffer);
|
||||
|
||||
if (!(res = pinos_stream_send_buffer (pinossink->stream, data->id)))
|
||||
g_warning ("can't send buffer");
|
||||
|
||||
|
||||
done:
|
||||
pinos_thread_main_loop_unlock (pinossink->loop);
|
||||
|
||||
|
|
|
|||
|
|
@ -451,38 +451,39 @@ on_new_buffer (GObject *gobject,
|
|||
{
|
||||
GstPinosSrc *pinossrc = user_data;
|
||||
GstBuffer *buf;
|
||||
ProcessMemData *data;
|
||||
SpaMetaHeader *h;
|
||||
guint i;
|
||||
|
||||
GST_LOG_OBJECT (pinossrc, "got new buffer");
|
||||
buf = g_hash_table_lookup (pinossrc->buf_ids, GINT_TO_POINTER (id));
|
||||
|
||||
if (buf) {
|
||||
ProcessMemData *data;
|
||||
SpaMetaHeader *h;
|
||||
guint i;
|
||||
|
||||
data = gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (buf),
|
||||
process_mem_data_quark);
|
||||
h = data->header;
|
||||
if (h) {
|
||||
GST_INFO ("pts %" G_GUINT64_FORMAT ", dts_offset %"G_GUINT64_FORMAT, h->pts, h->dts_offset);
|
||||
|
||||
if (GST_CLOCK_TIME_IS_VALID (h->pts)) {
|
||||
GST_BUFFER_PTS (buf) = h->pts;
|
||||
if (GST_BUFFER_PTS (buf) + h->dts_offset > 0)
|
||||
GST_BUFFER_DTS (buf) = GST_BUFFER_PTS (buf) + h->dts_offset;
|
||||
}
|
||||
GST_BUFFER_OFFSET (buf) = h->seq;
|
||||
}
|
||||
for (i = 0; i < data->buf->n_datas; i++) {
|
||||
SpaData *d = &data->buf->datas[i];
|
||||
GstMemory *mem = gst_buffer_peek_memory (buf, i);
|
||||
mem->offset = d->offset;
|
||||
mem->size = d->size;
|
||||
}
|
||||
g_queue_push_tail (&pinossrc->queue, buf);
|
||||
|
||||
pinos_thread_main_loop_signal (pinossrc->loop, FALSE);
|
||||
if (buf == NULL) {
|
||||
g_warning ("unknown buffer %d", id);
|
||||
return;
|
||||
}
|
||||
|
||||
data = gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (buf),
|
||||
process_mem_data_quark);
|
||||
h = data->header;
|
||||
if (h) {
|
||||
GST_INFO ("pts %" G_GUINT64_FORMAT ", dts_offset %"G_GUINT64_FORMAT, h->pts, h->dts_offset);
|
||||
|
||||
if (GST_CLOCK_TIME_IS_VALID (h->pts)) {
|
||||
GST_BUFFER_PTS (buf) = h->pts;
|
||||
if (GST_BUFFER_PTS (buf) + h->dts_offset > 0)
|
||||
GST_BUFFER_DTS (buf) = GST_BUFFER_PTS (buf) + h->dts_offset;
|
||||
}
|
||||
GST_BUFFER_OFFSET (buf) = h->seq;
|
||||
}
|
||||
for (i = 0; i < data->buf->n_datas; i++) {
|
||||
SpaData *d = &data->buf->datas[i];
|
||||
GstMemory *mem = gst_buffer_peek_memory (buf, i);
|
||||
mem->offset = d->offset;
|
||||
mem->size = d->size;
|
||||
}
|
||||
g_queue_push_tail (&pinossrc->queue, buf);
|
||||
|
||||
pinos_thread_main_loop_signal (pinossrc->loop, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -494,14 +495,15 @@ on_stream_notify (GObject *gobject,
|
|||
GstPinosSrc *pinossrc = user_data;
|
||||
PinosStreamState state = pinos_stream_get_state (pinossrc->stream);
|
||||
|
||||
GST_DEBUG ("got stream state %d", state);
|
||||
GST_DEBUG ("got stream state %s", pinos_stream_state_as_string (state));
|
||||
|
||||
switch (state) {
|
||||
case PINOS_STREAM_STATE_UNCONNECTED:
|
||||
case PINOS_STREAM_STATE_CONNECTING:
|
||||
case PINOS_STREAM_STATE_STARTING:
|
||||
case PINOS_STREAM_STATE_STREAMING:
|
||||
case PINOS_STREAM_STATE_CONFIGURE:
|
||||
case PINOS_STREAM_STATE_READY:
|
||||
case PINOS_STREAM_STATE_PAUSED:
|
||||
case PINOS_STREAM_STATE_STREAMING:
|
||||
break;
|
||||
case PINOS_STREAM_STATE_ERROR:
|
||||
GST_ELEMENT_ERROR (pinossrc, RESOURCE, FAILED,
|
||||
|
|
@ -529,6 +531,8 @@ parse_stream_properties (GstPinosSrc *pinossrc, PinosProperties *props)
|
|||
pinossrc->max_latency = var ? (GstClockTime) atoi (var) : GST_CLOCK_TIME_NONE;
|
||||
GST_OBJECT_UNLOCK (pinossrc);
|
||||
|
||||
GST_DEBUG_OBJECT (pinossrc, "live %d", is_live);
|
||||
|
||||
gst_base_src_set_live (GST_BASE_SRC (pinossrc), is_live);
|
||||
}
|
||||
|
||||
|
|
@ -539,10 +543,12 @@ gst_pinos_src_stream_start (GstPinosSrc *pinossrc)
|
|||
PinosProperties *props;
|
||||
|
||||
pinos_thread_main_loop_lock (pinossrc->loop);
|
||||
GST_DEBUG_OBJECT (pinossrc, "doing stream start");
|
||||
res = pinos_stream_start (pinossrc->stream);
|
||||
while (TRUE) {
|
||||
PinosStreamState state = pinos_stream_get_state (pinossrc->stream);
|
||||
|
||||
GST_DEBUG_OBJECT (pinossrc, "waiting for STREAMING, now %s", pinos_stream_state_as_string (state));
|
||||
if (state == PINOS_STREAM_STATE_STREAMING)
|
||||
break;
|
||||
|
||||
|
|
@ -559,6 +565,7 @@ gst_pinos_src_stream_start (GstPinosSrc *pinossrc)
|
|||
pinos_properties_free (props);
|
||||
|
||||
pinos_thread_main_loop_lock (pinossrc->loop);
|
||||
GST_DEBUG_OBJECT (pinossrc, "signal started");
|
||||
pinossrc->started = TRUE;
|
||||
pinos_thread_main_loop_signal (pinossrc->loop, FALSE);
|
||||
pinos_thread_main_loop_unlock (pinossrc->loop);
|
||||
|
|
@ -582,6 +589,8 @@ wait_negotiated (GstPinosSrc *this)
|
|||
while (TRUE) {
|
||||
state = pinos_stream_get_state (this->stream);
|
||||
|
||||
GST_DEBUG_OBJECT (this, "waiting for started signal, state now %s",
|
||||
pinos_stream_state_as_string (state));
|
||||
if (state == PINOS_STREAM_STATE_ERROR)
|
||||
break;
|
||||
|
||||
|
|
@ -590,6 +599,7 @@ wait_negotiated (GstPinosSrc *this)
|
|||
|
||||
pinos_thread_main_loop_wait (this->loop);
|
||||
}
|
||||
GST_DEBUG_OBJECT (this, "got started signal");
|
||||
pinos_thread_main_loop_unlock (this->loop);
|
||||
|
||||
return state;
|
||||
|
|
@ -642,6 +652,7 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc)
|
|||
while (TRUE) {
|
||||
PinosStreamState state = pinos_stream_get_state (pinossrc->stream);
|
||||
|
||||
GST_DEBUG_OBJECT (basesrc, "waiting for UNCONNECTED, now %s", pinos_stream_state_as_string (state));
|
||||
if (state == PINOS_STREAM_STATE_UNCONNECTED)
|
||||
break;
|
||||
|
||||
|
|
@ -665,7 +676,9 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc)
|
|||
while (TRUE) {
|
||||
PinosStreamState state = pinos_stream_get_state (pinossrc->stream);
|
||||
|
||||
if (state == PINOS_STREAM_STATE_READY)
|
||||
GST_DEBUG_OBJECT (basesrc, "waiting for PAUSED, now %s", pinos_stream_state_as_string (state));
|
||||
if (state == PINOS_STREAM_STATE_PAUSED ||
|
||||
state == PINOS_STREAM_STATE_STREAMING)
|
||||
break;
|
||||
|
||||
if (state == PINOS_STREAM_STATE_ERROR)
|
||||
|
|
@ -726,6 +739,7 @@ on_format_notify (GObject *gobject,
|
|||
g_object_get (gobject, "format", &format, NULL);
|
||||
|
||||
caps = gst_caps_from_format (format);
|
||||
GST_DEBUG_OBJECT (pinossrc, "we got format %" GST_PTR_FORMAT, caps);
|
||||
res = gst_base_src_set_caps (GST_BASE_SRC (pinossrc), caps);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
|
|
@ -738,8 +752,10 @@ on_format_notify (GObject *gobject,
|
|||
param_meta.param.size = sizeof (param_meta);
|
||||
param_meta.type = SPA_META_TYPE_HEADER;
|
||||
|
||||
GST_DEBUG_OBJECT (pinossrc, "doing finish format");
|
||||
pinos_stream_finish_format (pinossrc->stream, SPA_RESULT_OK, params, 1);
|
||||
} else {
|
||||
GST_WARNING_OBJECT (pinossrc, "finish format with error");
|
||||
pinos_stream_finish_format (pinossrc->stream, SPA_RESULT_INVALID_MEDIA_TYPE, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -948,7 +964,7 @@ on_context_notify (GObject *gobject,
|
|||
GstPinosSrc *pinossrc = user_data;
|
||||
PinosContextState state = pinos_context_get_state (pinossrc->ctx);
|
||||
|
||||
GST_DEBUG ("got context state %d", state);
|
||||
GST_DEBUG ("got context state %s", pinos_context_state_as_string (state));
|
||||
|
||||
switch (state) {
|
||||
case PINOS_CONTEXT_STATE_UNCONNECTED:
|
||||
|
|
@ -1000,6 +1016,7 @@ gst_pinos_src_open (GstPinosSrc * pinossrc)
|
|||
while (TRUE) {
|
||||
PinosContextState state = pinos_context_get_state (pinossrc->ctx);
|
||||
|
||||
GST_DEBUG ("waiting for CONNECTED, now %s", pinos_context_state_as_string (state));
|
||||
if (state == PINOS_CONTEXT_STATE_CONNECTED)
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -125,8 +125,8 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
|
|||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.clock, &clock_iface)) < 0) {
|
||||
g_error ("can't get CLOCK interface: %d", res);
|
||||
return;
|
||||
g_debug ("can't get CLOCK interface: %d", res);
|
||||
clock_iface = NULL;
|
||||
}
|
||||
|
||||
if (item->info) {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
#define MAX_INPUTS 64
|
||||
#define MAX_OUTPUTS 64
|
||||
|
||||
#define MAX_BUFFERS 16
|
||||
#define MAX_BUFFERS 64
|
||||
|
||||
#define CHECK_IN_PORT_ID(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) < MAX_INPUTS)
|
||||
#define CHECK_OUT_PORT_ID(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_OUTPUTS)
|
||||
|
|
@ -57,16 +57,20 @@
|
|||
#define CHECK_OUT_PORT(this,d,p) (CHECK_OUT_PORT_ID(this,d,p) && (this)->out_ports[p].valid)
|
||||
#define CHECK_PORT(this,d,p) (CHECK_IN_PORT (this,d,p) || CHECK_OUT_PORT (this,d,p))
|
||||
|
||||
#define CHECK_PORT_BUFFER(this,b,p) (b < p->n_buffers)
|
||||
|
||||
typedef struct _SpaProxy SpaProxy;
|
||||
typedef struct _ProxyBuffer ProxyBuffer;
|
||||
|
||||
struct _ProxyBuffer {
|
||||
SpaBuffer *outbuf;
|
||||
SpaBuffer buffer;
|
||||
SpaMeta metas[4];
|
||||
SpaData datas[4];
|
||||
off_t offset;
|
||||
size_t size;
|
||||
SpaBuffer *outbuf;
|
||||
SpaBuffer buffer;
|
||||
SpaMeta metas[4];
|
||||
SpaData datas[4];
|
||||
off_t offset;
|
||||
size_t size;
|
||||
bool outstanding;
|
||||
ProxyBuffer *next;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -85,7 +89,6 @@ typedef struct {
|
|||
size_t buffer_mem_size;
|
||||
void *buffer_mem_ptr;
|
||||
|
||||
uint32_t buffer_id;
|
||||
SpaQueue ready;
|
||||
} SpaProxyPort;
|
||||
|
||||
|
|
@ -654,7 +657,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
b->buffer.datas = b->datas;
|
||||
b->buffer.metas = b->metas;
|
||||
|
||||
b->size = pinos_serialize_buffer_get_size (buffers[i]);
|
||||
b->size = SPA_ROUND_UP_N (pinos_serialize_buffer_get_size (buffers[i]), 64);
|
||||
b->offset = size;
|
||||
|
||||
for (j = 0; j < buffers[i]->n_metas; j++) {
|
||||
|
|
@ -810,7 +813,7 @@ copy_meta_in (SpaProxy *this, SpaProxyPort *port, uint32_t buffer_id)
|
|||
unsigned int i;
|
||||
|
||||
for (i = 0; i < b->outbuf->n_metas; i++) {
|
||||
SpaMeta *sm = &b->metas[i];
|
||||
SpaMeta *sm = &b->buffer.metas[i];
|
||||
SpaMeta *dm = &b->outbuf->metas[i];
|
||||
memcpy (dm->data, sm->data, dm->size);
|
||||
}
|
||||
|
|
@ -852,7 +855,6 @@ spa_proxy_node_port_push_input (SpaNode *node,
|
|||
SpaProxyPort *port;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
bool have_enough = false;
|
||||
PinosControlCmdProcessBuffer pb;
|
||||
|
||||
if (node == NULL || n_info == 0 || info == NULL)
|
||||
|
|
@ -874,7 +876,7 @@ spa_proxy_node_port_push_input (SpaNode *node,
|
|||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
if (info[i].buffer_id >= port->n_buffers) {
|
||||
if (!CHECK_PORT_BUFFER (this, info[i].buffer_id, port)) {
|
||||
if (port->n_buffers == 0)
|
||||
info[i].status = SPA_RESULT_NO_BUFFERS;
|
||||
else
|
||||
|
|
@ -895,8 +897,6 @@ spa_proxy_node_port_push_input (SpaNode *node,
|
|||
|
||||
if (have_error)
|
||||
return SPA_RESULT_ERROR;
|
||||
if (have_enough)
|
||||
return SPA_RESULT_HAVE_ENOUGH_INPUT;
|
||||
|
||||
if (!pinos_connection_flush (this->rtconn))
|
||||
spa_log_error (this->log, "proxy %p: error writing connection\n", this);
|
||||
|
|
@ -913,7 +913,6 @@ spa_proxy_node_port_pull_output (SpaNode *node,
|
|||
SpaProxyPort *port;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
bool need_more = false;
|
||||
|
||||
if (node == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -921,6 +920,8 @@ spa_proxy_node_port_pull_output (SpaNode *node,
|
|||
this = SPA_CONTAINER_OF (node, SpaProxy, node);
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
ProxyBuffer *b;
|
||||
|
||||
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, info[i].port_id)) {
|
||||
spa_log_warn (this->log, "invalid port %u\n", info[i].port_id);
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
|
|
@ -936,15 +937,19 @@ spa_proxy_node_port_pull_output (SpaNode *node,
|
|||
continue;
|
||||
}
|
||||
|
||||
info[i].buffer_id = port->buffer_id;
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
SPA_QUEUE_POP_HEAD (&port->ready, ProxyBuffer, next, b);
|
||||
if (b == NULL) {
|
||||
info[i].status = SPA_RESULT_UNEXPECTED;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
b->outstanding = true;
|
||||
|
||||
port->buffer_id = SPA_ID_INVALID;
|
||||
info[i].buffer_id = b->outbuf->id;
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
}
|
||||
if (have_error)
|
||||
return SPA_RESULT_ERROR;
|
||||
if (need_more)
|
||||
return SPA_RESULT_NEED_MORE_INPUT;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -987,6 +992,7 @@ spa_proxy_node_port_send_command (SpaNode *node,
|
|||
SpaNodeCommand *command)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaResult res = SPA_RESULT_OK;
|
||||
|
||||
if (node == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -994,11 +1000,34 @@ spa_proxy_node_port_send_command (SpaNode *node,
|
|||
this = SPA_CONTAINER_OF (node, SpaProxy, node);
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_NODE_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
||||
case SPA_NODE_COMMAND_START:
|
||||
case SPA_NODE_COMMAND_PAUSE:
|
||||
case SPA_NODE_COMMAND_FLUSH:
|
||||
case SPA_NODE_COMMAND_DRAIN:
|
||||
case SPA_NODE_COMMAND_MARKER:
|
||||
{
|
||||
PinosControlCmdPortCommand cpc;
|
||||
|
||||
cpc.port_id = port_id;
|
||||
cpc.command = command;
|
||||
pinos_connection_add_cmd (this->rtconn, PINOS_CONTROL_CMD_PORT_COMMAND, &cpc);
|
||||
|
||||
if (!pinos_connection_flush (this->rtconn)) {
|
||||
spa_log_error (this->log, "proxy %p: error writing connection\n", this);
|
||||
res = SPA_RESULT_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
spa_log_warn (this->log, "unhandled command %d\n", command->type);
|
||||
res = SPA_RESULT_NOT_IMPLEMENTED;
|
||||
break;
|
||||
}
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
return res;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -1039,6 +1068,7 @@ parse_connection (SpaProxy *this)
|
|||
case PINOS_CONTROL_CMD_SET_FORMAT:
|
||||
case PINOS_CONTROL_CMD_SET_PROPERTY:
|
||||
case PINOS_CONTROL_CMD_NODE_COMMAND:
|
||||
case PINOS_CONTROL_CMD_PORT_COMMAND:
|
||||
case PINOS_CONTROL_CMD_PROCESS_BUFFER:
|
||||
spa_log_error (this->log, "proxy %p: got unexpected command %d\n", this, cmd);
|
||||
break;
|
||||
|
|
@ -1154,6 +1184,7 @@ parse_rtconnection (SpaProxy *this)
|
|||
{
|
||||
PinosControlCmdProcessBuffer cmd;
|
||||
SpaProxyPort *port;
|
||||
ProxyBuffer *b;
|
||||
|
||||
if (!pinos_connection_parse_cmd (conn, &cmd))
|
||||
break;
|
||||
|
|
@ -1163,12 +1194,14 @@ parse_rtconnection (SpaProxy *this)
|
|||
|
||||
port = cmd.direction == SPA_DIRECTION_INPUT ? &this->in_ports[cmd.port_id] : &this->out_ports[cmd.port_id];
|
||||
|
||||
if (port->buffer_id != SPA_ID_INVALID)
|
||||
spa_log_warn (this->log, "proxy %p: unprocessed buffer: %d\n", this, port->buffer_id);
|
||||
if (!CHECK_PORT_BUFFER (this, cmd.buffer_id, port))
|
||||
break;
|
||||
|
||||
copy_meta_in (this, port, cmd.buffer_id);
|
||||
|
||||
port->buffer_id = cmd.buffer_id;
|
||||
b = &port->buffers[cmd.buffer_id];
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&port->ready, ProxyBuffer, next, b);
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_NODE_EVENT:
|
||||
|
|
@ -1181,6 +1214,15 @@ parse_rtconnection (SpaProxy *this)
|
|||
handle_node_event (this, cne.event);
|
||||
break;
|
||||
}
|
||||
case PINOS_CONTROL_CMD_PORT_COMMAND:
|
||||
{
|
||||
PinosControlCmdPortCommand cm;
|
||||
|
||||
if (!pinos_connection_parse_cmd (conn, &cm))
|
||||
break;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -201,28 +201,14 @@ no_node:
|
|||
|
||||
|
||||
static void
|
||||
on_node_remove_signal (PinosNode *node,
|
||||
on_link_port_unlinked (PinosLink *link,
|
||||
PinosPort *port,
|
||||
PinosDaemon *this)
|
||||
{
|
||||
g_debug ("daemon %p: node %p remove", this, node);
|
||||
}
|
||||
g_debug ("daemon %p: link %p: port %p unlinked", this, link, port);
|
||||
|
||||
static void
|
||||
on_link_input_unlinked (PinosLink *link,
|
||||
PinosPort *port,
|
||||
PinosDaemon *this)
|
||||
{
|
||||
g_debug ("daemon %p: link %p: input unlinked", this, link);
|
||||
}
|
||||
|
||||
static void
|
||||
on_link_output_unlinked (PinosLink *link,
|
||||
PinosPort *port,
|
||||
PinosDaemon *this)
|
||||
{
|
||||
g_debug ("daemon %p: link %p: output unlinked", this, link);
|
||||
|
||||
try_link_port (link->input->node, link->input, this);
|
||||
if (port->direction == PINOS_DIRECTION_OUTPUT && link->input)
|
||||
try_link_port (link->input->node, link->input, this);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -300,9 +286,9 @@ try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this)
|
|||
goto error;
|
||||
|
||||
if (port->direction == PINOS_DIRECTION_OUTPUT)
|
||||
link = pinos_node_link (node, port, target, NULL, NULL, &error);
|
||||
link = pinos_port_link (port, target, NULL, NULL, &error);
|
||||
else
|
||||
link = pinos_node_link (target->node, target, port, NULL, NULL, &error);
|
||||
link = pinos_port_link (target, port, NULL, NULL, &error);
|
||||
|
||||
if (link == NULL)
|
||||
goto error;
|
||||
|
|
@ -311,9 +297,7 @@ try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this)
|
|||
if (client)
|
||||
pinos_client_add_object (client, G_OBJECT (link));
|
||||
|
||||
g_signal_connect (target->node, "remove", (GCallback) on_node_remove_signal, this);
|
||||
g_signal_connect (link, "input-unlinked", (GCallback) on_link_input_unlinked, this);
|
||||
g_signal_connect (link, "output-unlinked", (GCallback) on_link_output_unlinked, this);
|
||||
g_signal_connect (link, "port-unlinked", (GCallback) on_link_port_unlinked, this);
|
||||
g_signal_connect (link, "notify::state", (GCallback) on_link_state_notify, this);
|
||||
pinos_link_activate (link);
|
||||
|
||||
|
|
@ -771,6 +755,9 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
for (nodes = priv->nodes; nodes; nodes = g_list_next (nodes)) {
|
||||
PinosNode *n = nodes->data;
|
||||
|
||||
if (n->flags & PINOS_NODE_FLAG_REMOVING)
|
||||
continue;
|
||||
|
||||
g_debug ("node path \"%s\"", pinos_node_get_object_path (n));
|
||||
|
||||
if (have_name) {
|
||||
|
|
|
|||
|
|
@ -17,15 +17,20 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <limits.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "spa/include/spa/ringbuffer.h"
|
||||
#include "pinos/client/rtkit.h"
|
||||
#include "pinos/server/data-loop.h"
|
||||
|
||||
#define PINOS_DATA_LOOP_GET_PRIVATE(loop) \
|
||||
|
|
@ -60,6 +65,7 @@ struct _PinosDataLoopPrivate
|
|||
|
||||
gboolean running;
|
||||
pthread_t thread;
|
||||
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosDataLoop, pinos_data_loop, G_TYPE_OBJECT);
|
||||
|
|
@ -74,6 +80,52 @@ enum
|
|||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static void
|
||||
make_realtime (PinosDataLoop *this)
|
||||
{
|
||||
struct sched_param sp;
|
||||
GDBusConnection *system_bus;
|
||||
GError *error = NULL;
|
||||
struct rlimit rl;
|
||||
int r, rtprio;
|
||||
long long rttime;
|
||||
|
||||
rtprio = 20;
|
||||
rttime = 20000;
|
||||
|
||||
spa_zero (sp);
|
||||
sp.sched_priority = rtprio;
|
||||
|
||||
if (pthread_setschedparam (pthread_self(), SCHED_RR|SCHED_RESET_ON_FORK, &sp) == 0) {
|
||||
g_debug ("SCHED_OTHER|SCHED_RESET_ON_FORK worked.");
|
||||
return;
|
||||
}
|
||||
system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
|
||||
|
||||
rl.rlim_cur = rl.rlim_max = rttime;
|
||||
if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0)
|
||||
g_debug ("setrlimit() failed: %s", strerror (errno));
|
||||
|
||||
if (rttime >= 0) {
|
||||
r = getrlimit (RLIMIT_RTTIME, &rl);
|
||||
if (r >= 0 && (long long) rl.rlim_max > rttime) {
|
||||
g_debug ("Clamping rlimit-rttime to %lld for RealtimeKit", rttime);
|
||||
rl.rlim_cur = rl.rlim_max = rttime;
|
||||
|
||||
if ((r = setrlimit (RLIMIT_RTTIME, &rl)) < 0)
|
||||
g_debug ("setrlimit() failed: %s", strerror (errno));
|
||||
}
|
||||
}
|
||||
|
||||
if (!pinos_rtkit_make_realtime (system_bus, 0, rtprio, &error)) {
|
||||
g_debug ("could not make thread realtime: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
} else {
|
||||
g_debug ("thread made realtime");
|
||||
}
|
||||
g_object_unref (system_bus);
|
||||
}
|
||||
|
||||
static void *
|
||||
loop (void *user_data)
|
||||
{
|
||||
|
|
@ -82,11 +134,14 @@ loop (void *user_data)
|
|||
SpaPoll *p = &this->poll;
|
||||
unsigned int i, j;
|
||||
|
||||
make_realtime (this);
|
||||
|
||||
g_debug ("data-loop %p: enter thread", this);
|
||||
while (priv->running) {
|
||||
SpaPollNotifyData ndata;
|
||||
unsigned int n_idle = 0;
|
||||
int r;
|
||||
struct timespec ts;
|
||||
|
||||
/* prepare */
|
||||
for (i = 0; i < priv->n_poll; i++) {
|
||||
|
|
@ -161,6 +216,9 @@ loop (void *user_data)
|
|||
continue;
|
||||
}
|
||||
|
||||
// clock_gettime (CLOCK_MONOTONIC, &ts);
|
||||
// fprintf (stderr, "%llu\n", SPA_TIMESPEC_TO_TIME (&ts));
|
||||
|
||||
/* after */
|
||||
for (i = 0; i < priv->n_poll; i++) {
|
||||
SpaPollItem *p = &priv->poll[i];
|
||||
|
|
@ -284,9 +342,6 @@ do_remove_item (SpaPoll *poll,
|
|||
if (!in_thread)
|
||||
wakeup_thread (this);
|
||||
}
|
||||
if (priv->n_poll == 0) {
|
||||
stop_thread (this, in_thread);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,8 +74,7 @@ enum
|
|||
enum
|
||||
{
|
||||
SIGNAL_REMOVE,
|
||||
SIGNAL_INPUT_UNLINKED,
|
||||
SIGNAL_OUTPUT_UNLINKED,
|
||||
SIGNAL_PORT_UNLINKED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
|
|
@ -388,10 +387,14 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
"error get input port info: %d", res);
|
||||
goto error;
|
||||
}
|
||||
spa_debug_port_info (oinfo);
|
||||
spa_debug_port_info (iinfo);
|
||||
|
||||
in_flags = iinfo->flags;
|
||||
out_flags = oinfo->flags;
|
||||
|
||||
if (out_flags & SPA_PORT_INFO_FLAG_LIVE) {
|
||||
g_debug ("setting link as live");
|
||||
this->output->node->live = true;
|
||||
this->input->node->live = true;
|
||||
}
|
||||
|
|
@ -430,9 +433,6 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
} else
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
spa_debug_port_info (oinfo);
|
||||
spa_debug_port_info (iinfo);
|
||||
|
||||
if (priv->buffers == NULL) {
|
||||
SpaAllocParamBuffers *in_alloc, *out_alloc;
|
||||
guint max_buffers = MAX_BUFFERS;
|
||||
|
|
@ -486,7 +486,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
}
|
||||
hdr_size += n_metas * sizeof (SpaMeta);
|
||||
|
||||
buf_size = hdr_size + minsize;
|
||||
buf_size = SPA_ROUND_UP_N (hdr_size + minsize, 64);
|
||||
|
||||
priv->n_buffers = max_buffers;
|
||||
pinos_memblock_alloc (PINOS_MEMBLOCK_FLAG_WITH_FD |
|
||||
|
|
@ -543,7 +543,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
d->data = NULL;
|
||||
}
|
||||
}
|
||||
g_debug ("allocated %d buffers %p", priv->n_buffers, priv->buffers);
|
||||
g_debug ("allocated %d buffers %p %zd", priv->n_buffers, priv->buffers, minsize);
|
||||
priv->allocated = TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -665,11 +665,18 @@ do_start (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
check_states (PinosLink *this, SpaResult res)
|
||||
check_states (PinosLink *this,
|
||||
gpointer user_data,
|
||||
SpaResult res)
|
||||
{
|
||||
SpaNodeState in_state, out_state;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
if (res != SPA_RESULT_OK) {
|
||||
g_warning ("link %p: error: %d", this, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
again:
|
||||
if (this->input == NULL || this->output == NULL)
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -745,15 +752,12 @@ typedef struct {
|
|||
} UnlinkedData;
|
||||
|
||||
static void
|
||||
on_input_unlinked (UnlinkedData *data)
|
||||
on_port_unlinked (PinosPort *port, PinosLink *this, SpaResult res, gulong id)
|
||||
{
|
||||
g_signal_emit (data->link, signals[SIGNAL_INPUT_UNLINKED], 0, data->port);
|
||||
}
|
||||
g_signal_emit (this, signals[SIGNAL_PORT_UNLINKED], 0, port);
|
||||
|
||||
static void
|
||||
on_output_unlinked (UnlinkedData *data)
|
||||
{
|
||||
g_signal_emit (data->link, signals[SIGNAL_OUTPUT_UNLINKED], 0, data->port);
|
||||
if (this->input == NULL || this->output == NULL)
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_UNLINKED);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -761,57 +765,34 @@ on_node_remove (PinosNode *node, PinosLink *this)
|
|||
{
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
SpaResult res = SPA_RESULT_OK;
|
||||
UnlinkedData data;
|
||||
|
||||
data.link = this;
|
||||
PinosPort *port, *other;
|
||||
|
||||
g_signal_handlers_disconnect_by_data (node, this);
|
||||
if (node == this->input->node) {
|
||||
if (this->input->allocated) {
|
||||
priv->buffers = NULL;
|
||||
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;
|
||||
pinos_main_loop_defer (priv->main_loop,
|
||||
this,
|
||||
res,
|
||||
(PinosDeferFunc) on_input_unlinked,
|
||||
g_memdup (&data, sizeof (UnlinkedData)),
|
||||
g_free);
|
||||
} else {
|
||||
if (this->output->allocated) {
|
||||
priv->buffers = NULL;
|
||||
priv->n_buffers = 0;
|
||||
if (this->input && node == this->input->node) {
|
||||
port = this->input;
|
||||
other = this->output;
|
||||
} else if (this->output && node == this->output->node) {
|
||||
port = this->output;
|
||||
other = this->input;
|
||||
} else
|
||||
return;
|
||||
|
||||
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;
|
||||
pinos_main_loop_defer (priv->main_loop,
|
||||
this,
|
||||
res,
|
||||
(PinosDeferFunc) on_output_unlinked,
|
||||
g_memdup (&data, sizeof (UnlinkedData)),
|
||||
g_free);
|
||||
if (port->allocated) {
|
||||
priv->buffers = NULL;
|
||||
priv->n_buffers = 0;
|
||||
|
||||
g_debug ("link %p: clear input allocated buffers on port %p", link, other);
|
||||
pinos_port_clear_buffers (other);
|
||||
}
|
||||
|
||||
if (this->input == NULL || this->output == NULL)
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_UNLINKED);
|
||||
res = pinos_port_unlink (port, this);
|
||||
pinos_main_loop_defer (priv->main_loop,
|
||||
port,
|
||||
res,
|
||||
(PinosDeferFunc) on_port_unlinked,
|
||||
g_object_ref (this),
|
||||
g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -854,28 +835,11 @@ pinos_link_dispose (GObject * object)
|
|||
|
||||
g_signal_emit (this, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
|
||||
if (this->input) {
|
||||
if (!this->input->allocated) {
|
||||
spa_node_port_use_buffers (this->input->node->node,
|
||||
SPA_DIRECTION_INPUT,
|
||||
this->input->port,
|
||||
NULL, 0);
|
||||
this->input->buffers = NULL;
|
||||
this->input->n_buffers = 0;
|
||||
}
|
||||
this->input = NULL;
|
||||
}
|
||||
if (this->output) {
|
||||
if (!this->output->allocated) {
|
||||
spa_node_port_use_buffers (this->output->node->node,
|
||||
SPA_DIRECTION_OUTPUT,
|
||||
this->output->port,
|
||||
NULL, 0);
|
||||
this->output->buffers = NULL;
|
||||
this->output->n_buffers = 0;
|
||||
}
|
||||
this->output = NULL;
|
||||
}
|
||||
if (this->input)
|
||||
pinos_port_unlink (this->input, this);
|
||||
if (this->output)
|
||||
pinos_port_unlink (this->output, this);
|
||||
|
||||
link_unregister_object (this);
|
||||
|
||||
pinos_main_loop_defer_cancel (priv->main_loop, this, 0);
|
||||
|
|
@ -894,9 +858,8 @@ pinos_link_finalize (GObject * object)
|
|||
g_clear_object (&priv->iface);
|
||||
g_free (priv->object_path);
|
||||
|
||||
if (priv->allocated) {
|
||||
if (priv->allocated)
|
||||
pinos_memblock_free (&priv->buffer_mem);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (pinos_link_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
@ -982,17 +945,7 @@ pinos_link_class_init (PinosLinkClass * klass)
|
|||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
signals[SIGNAL_INPUT_UNLINKED] = g_signal_new ("input-unlinked",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
G_TYPE_POINTER);
|
||||
signals[SIGNAL_OUTPUT_UNLINKED] = g_signal_new ("output-unlinked",
|
||||
signals[SIGNAL_PORT_UNLINKED] = g_signal_new ("port-unlinked",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
|
|
@ -1067,7 +1020,7 @@ pinos_link_activate (PinosLink *this)
|
|||
g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
|
||||
|
||||
spa_ringbuffer_init (&this->ringbuffer, SPA_N_ELEMENTS (this->queue));
|
||||
check_states (this, SPA_RESULT_OK);
|
||||
check_states (this, NULL, SPA_RESULT_OK);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ struct _PinosLink {
|
|||
PinosPort *output;
|
||||
PinosPort *input;
|
||||
|
||||
uint32_t queue[16];
|
||||
uint32_t queue[64];
|
||||
SpaRingbuffer ringbuffer;
|
||||
gint in_ready;
|
||||
|
||||
|
|
|
|||
|
|
@ -389,11 +389,9 @@ process_work_queue (PinosMainLoop *this)
|
|||
for (item = priv->work.head, prev = NULL; item; prev = item, item = next) {
|
||||
next = item->next;
|
||||
|
||||
g_debug ("main-loop %p: peek work queue item %p seq %d, prev %p next %p", this, item->obj, item->seq, prev, next);
|
||||
if (item->seq != SPA_ID_INVALID)
|
||||
continue;
|
||||
|
||||
g_debug ("main-loop %p: process work item %p", this, item->obj);
|
||||
if (priv->work.tail == item)
|
||||
priv->work.tail = prev;
|
||||
if (prev == NULL)
|
||||
|
|
@ -401,8 +399,10 @@ process_work_queue (PinosMainLoop *this)
|
|||
else
|
||||
prev->next = next;
|
||||
|
||||
if (item->func)
|
||||
if (item->func) {
|
||||
g_debug ("main-loop %p: process work item %p", this, item->obj);
|
||||
item->func (item->obj, item->data, item->res, item->id);
|
||||
}
|
||||
if (item->notify)
|
||||
item->notify (item->data);
|
||||
|
||||
|
|
@ -484,7 +484,7 @@ pinos_main_loop_defer_cancel (PinosMainLoop *loop,
|
|||
priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
|
||||
}
|
||||
|
||||
void
|
||||
gboolean
|
||||
pinos_main_loop_defer_complete (PinosMainLoop *loop,
|
||||
gpointer obj,
|
||||
uint32_t seq,
|
||||
|
|
@ -494,11 +494,9 @@ pinos_main_loop_defer_complete (PinosMainLoop *loop,
|
|||
PinosMainLoopPrivate *priv;
|
||||
gboolean have_work = FALSE;
|
||||
|
||||
g_return_if_fail (PINOS_IS_MAIN_LOOP (loop));
|
||||
g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), FALSE);
|
||||
priv = loop->priv;
|
||||
|
||||
g_debug ("main-loop %p: async complete %d %d for object %p", loop, seq, res, obj);
|
||||
|
||||
for (item = priv->work.head; item; item = item->next) {
|
||||
if (item->obj == obj && item->seq == seq) {
|
||||
g_debug ("main-loop %p: found defered %d for object %p", loop, seq, obj);
|
||||
|
|
@ -512,6 +510,8 @@ pinos_main_loop_defer_complete (PinosMainLoop *loop,
|
|||
|
||||
if (priv->work_id == 0 && have_work)
|
||||
priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop);
|
||||
|
||||
return have_work;
|
||||
}
|
||||
|
||||
GMainLoop *
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ gulong pinos_main_loop_defer (PinosMainLoop *loo
|
|||
void pinos_main_loop_defer_cancel (PinosMainLoop *loop,
|
||||
gpointer obj,
|
||||
gulong id);
|
||||
void pinos_main_loop_defer_complete (PinosMainLoop *loop,
|
||||
gboolean pinos_main_loop_defer_complete (PinosMainLoop *loop,
|
||||
gpointer obj,
|
||||
uint32_t seq,
|
||||
SpaResult res);
|
||||
|
|
|
|||
|
|
@ -53,18 +53,6 @@ free_node_port (PinosPort *np)
|
|||
g_slice_free (PinosPort, np);
|
||||
}
|
||||
|
||||
static PinosPort *
|
||||
find_node_port (GList *ports, PinosNode *node, uint32_t port)
|
||||
{
|
||||
GList *walk;
|
||||
for (walk = ports; walk; walk = g_list_next (walk)) {
|
||||
PinosPort *np = walk->data;
|
||||
if (np->node == node && np->port == port)
|
||||
return np;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct _PinosNodePrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
|
|
@ -74,6 +62,8 @@ struct _PinosNodePrivate
|
|||
gchar *object_path;
|
||||
gchar *name;
|
||||
|
||||
uint32_t seq;
|
||||
|
||||
gboolean async_init;
|
||||
unsigned int max_input_ports;
|
||||
unsigned int max_output_ports;
|
||||
|
|
@ -340,14 +330,12 @@ do_read_link (SpaPoll *poll,
|
|||
size_t offset;
|
||||
SpaResult res;
|
||||
|
||||
if (spa_ringbuffer_get_read_offset (&link->ringbuffer, &offset) > 0) {
|
||||
if (link->input == NULL)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
while (link->in_ready > 0 && spa_ringbuffer_get_read_offset (&link->ringbuffer, &offset) > 0) {
|
||||
SpaPortInputInfo iinfo[1];
|
||||
|
||||
if (link->in_ready <= 0 || link->input == NULL)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
link->in_ready--;
|
||||
|
||||
iinfo[0].port_id = link->input->port;
|
||||
iinfo[0].buffer_id = link->queue[offset];
|
||||
iinfo[0].flags = SPA_PORT_INPUT_FLAG_NONE;
|
||||
|
|
@ -356,6 +344,7 @@ do_read_link (SpaPoll *poll,
|
|||
g_warning ("node %p: error pushing buffer: %d, %d", this, res, iinfo[0].status);
|
||||
|
||||
spa_ringbuffer_read_advance (&link->ringbuffer, 1);
|
||||
link->in_ready--;
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -379,8 +368,8 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
SpaNodeEventAsyncComplete *ac = (SpaNodeEventAsyncComplete *) event;
|
||||
|
||||
g_debug ("node %p: async complete event %d %d", this, ac->seq, ac->res);
|
||||
pinos_main_loop_defer_complete (priv->main_loop, this, ac->seq, ac->res);
|
||||
g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res);
|
||||
if (!pinos_main_loop_defer_complete (priv->main_loop, this, ac->seq, ac->res))
|
||||
g_signal_emit (this, signals[SIGNAL_ASYNC_COMPLETE], 0, ac->seq, ac->res);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -410,8 +399,8 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
SpaNodeEventHaveOutput *ho = (SpaNodeEventHaveOutput *) event;
|
||||
SpaPortOutputInfo oinfo[1] = { 0, };
|
||||
SpaResult res;
|
||||
gboolean pushed = FALSE;
|
||||
guint i;
|
||||
gboolean pushed = FALSE;
|
||||
|
||||
oinfo[0].port_id = ho->port_id;
|
||||
|
||||
|
|
@ -422,9 +411,12 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
|
||||
for (i = 0; i < priv->rt.links->len; i++) {
|
||||
PinosLink *link = g_ptr_array_index (priv->rt.links, i);
|
||||
PinosPort *output = link->output;
|
||||
PinosPort *input = link->input;
|
||||
size_t offset;
|
||||
|
||||
if (link->output == NULL || link->output->port != ho->port_id)
|
||||
if (output == NULL || input == NULL ||
|
||||
output->node->node != node || output->port != ho->port_id)
|
||||
continue;
|
||||
|
||||
if (spa_ringbuffer_get_write_offset (&link->ringbuffer, &offset) > 0) {
|
||||
|
|
@ -441,7 +433,6 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
}
|
||||
}
|
||||
if (!pushed) {
|
||||
g_debug ("node %p: discarded buffer %u", this, oinfo[0].buffer_id);
|
||||
if ((res = spa_node_port_reuse_buffer (node, oinfo[0].port_id, oinfo[0].buffer_id)) < 0)
|
||||
g_warning ("node %p: error reuse buffer: %d", node, res);
|
||||
}
|
||||
|
|
@ -456,7 +447,7 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
|
|||
for (i = 0; i < priv->rt.links->len; i++) {
|
||||
PinosLink *link = g_ptr_array_index (priv->rt.links, i);
|
||||
|
||||
if (link->input == NULL || link->input->port != rb->port_id)
|
||||
if (link->input == NULL || link->input->port != rb->port_id || link->output == NULL)
|
||||
continue;
|
||||
|
||||
if ((res = spa_node_port_reuse_buffer (link->output->node->node,
|
||||
|
|
@ -1015,7 +1006,11 @@ pinos_node_remove (PinosNode *node)
|
|||
{
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
|
||||
if (node->flags & PINOS_NODE_FLAG_REMOVING)
|
||||
return;
|
||||
|
||||
g_debug ("node %p: remove", node);
|
||||
node->flags |= PINOS_NODE_FLAG_REMOVING;
|
||||
g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
}
|
||||
|
||||
|
|
@ -1071,64 +1066,6 @@ pinos_node_get_free_port (PinosNode *node,
|
|||
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_remove_link (SpaPoll *poll,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data)
|
||||
{
|
||||
PinosNode *this = user_data;
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
PinosLink *link = ((PinosLink**)data)[0];
|
||||
|
||||
g_ptr_array_remove_fast (priv->rt.links, link);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
on_remove_link (PinosLink *link, PinosNode *node)
|
||||
{
|
||||
PinosPort *p;
|
||||
PinosNode *n;
|
||||
|
||||
if (link->output) {
|
||||
n = link->output->node;
|
||||
if ((p = find_node_port (n->priv->output_ports, n, link->output->port)))
|
||||
if (g_ptr_array_remove_fast (p->links, link))
|
||||
n->priv->n_used_output_links--;
|
||||
|
||||
spa_poll_invoke (&n->priv->data_loop->poll,
|
||||
do_remove_link,
|
||||
SPA_ID_INVALID,
|
||||
sizeof (PinosLink *),
|
||||
&link,
|
||||
n);
|
||||
|
||||
if (n->priv->n_used_output_links == 0 &&
|
||||
n->priv->n_used_input_links == 0)
|
||||
pinos_node_report_idle (n);
|
||||
}
|
||||
if (link->input->node) {
|
||||
n = link->input->node;
|
||||
if ((p = find_node_port (n->priv->input_ports, n, link->input->port)))
|
||||
if (g_ptr_array_remove_fast (p->links, link))
|
||||
n->priv->n_used_input_links--;
|
||||
|
||||
spa_poll_invoke (&n->priv->data_loop->poll,
|
||||
do_remove_link,
|
||||
SPA_ID_INVALID,
|
||||
sizeof (PinosLink *),
|
||||
&link,
|
||||
n);
|
||||
|
||||
if (n->priv->n_used_output_links == 0 &&
|
||||
n->priv->n_used_input_links == 0)
|
||||
pinos_node_report_idle (n);
|
||||
}
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_add_link (SpaPoll *poll,
|
||||
|
|
@ -1147,67 +1084,79 @@ do_add_link (SpaPoll *poll,
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static PinosLink *
|
||||
find_link (PinosPort *output_port, PinosPort *input_port)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < output_port->links->len; i++) {
|
||||
PinosLink *pl = g_ptr_array_index (output_port->links, i);
|
||||
if (pl->input == input_port) {
|
||||
return pl;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PinosLink *
|
||||
pinos_port_get_link (PinosPort *output_port,
|
||||
PinosPort *input_port)
|
||||
{
|
||||
g_return_val_if_fail (output_port != NULL, NULL);
|
||||
g_return_val_if_fail (input_port != NULL, NULL);
|
||||
|
||||
return find_link (output_port, input_port);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_link:
|
||||
* @output_node: a #PinosNode
|
||||
* pinos_port_link:
|
||||
* @output_port: an output port
|
||||
* @input_port: an input port
|
||||
* @format_filter: a format filter
|
||||
* @properties: extra properties
|
||||
* @error: an error or %NULL
|
||||
*
|
||||
* Make a link between @output_port and @input_port with the given ids
|
||||
* Make a link between @output_port and @input_port
|
||||
*
|
||||
* If the ports were already linked, the existing links will be returned.
|
||||
*
|
||||
* If the output id was linked to a different input node or id, it
|
||||
* will be relinked.
|
||||
*
|
||||
* Returns: a new #PinosLink or %NULL and @error is set.
|
||||
*/
|
||||
PinosLink *
|
||||
pinos_node_link (PinosNode *output_node,
|
||||
PinosPort *output_port,
|
||||
pinos_port_link (PinosPort *output_port,
|
||||
PinosPort *input_port,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties,
|
||||
GError **error)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
PinosNode *input_node;
|
||||
PinosLink *link = NULL;
|
||||
guint i;
|
||||
PinosNode *input_node, *output_node;
|
||||
PinosLink *link;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (output_node), NULL);
|
||||
g_return_val_if_fail (output_port != NULL, NULL);
|
||||
g_return_val_if_fail (input_port != NULL, NULL);
|
||||
|
||||
output_node = output_port->node;
|
||||
priv = output_node->priv;
|
||||
input_node = input_port->node;
|
||||
|
||||
g_debug ("node %p: link %u %p:%u", output_node, output_port->port, input_node, input_port->port);
|
||||
g_debug ("port link %p:%u -> %p:%u", output_node, output_port->port, input_node, input_port->port);
|
||||
|
||||
if (output_node == input_node)
|
||||
goto same_node;
|
||||
|
||||
for (i = 0; i < output_port->links->len; i++) {
|
||||
PinosLink *pl = g_ptr_array_index (output_port->links, i);
|
||||
if (pl->input->node == input_node && pl->input == input_port) {
|
||||
link = pl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (input_port->links->len > 0)
|
||||
goto was_linked;
|
||||
|
||||
link = find_link (output_port, input_port);
|
||||
|
||||
if (link) {
|
||||
/* FIXME */
|
||||
link->input->node = input_node;
|
||||
link->input = input_port;
|
||||
g_object_ref (link);
|
||||
} else {
|
||||
input_node->live = output_node->live;
|
||||
if (output_node->clock)
|
||||
input_node->clock = output_node->clock;
|
||||
g_debug ("node %p: clock %p", output_node, output_node->clock);
|
||||
g_debug ("node %p: clock %p, live %d", output_node, output_node->clock, output_node->live);
|
||||
|
||||
link = g_object_new (PINOS_TYPE_LINK,
|
||||
"daemon", priv->daemon,
|
||||
|
|
@ -1217,11 +1166,6 @@ pinos_node_link (PinosNode *output_node,
|
|||
"properties", properties,
|
||||
NULL);
|
||||
|
||||
g_signal_connect (link,
|
||||
"remove",
|
||||
(GCallback) on_remove_link,
|
||||
output_node);
|
||||
|
||||
g_ptr_array_add (output_port->links, link);
|
||||
g_ptr_array_add (input_port->links, link);
|
||||
|
||||
|
|
@ -1251,6 +1195,187 @@ same_node:
|
|||
"can't link a node to itself");
|
||||
return NULL;
|
||||
}
|
||||
was_linked:
|
||||
{
|
||||
g_set_error (error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_LINK,
|
||||
"input port was already linked");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
pinos_port_pause (PinosPort *port)
|
||||
{
|
||||
SpaNodeCommand cmd;
|
||||
|
||||
cmd.type = SPA_NODE_COMMAND_PAUSE;
|
||||
cmd.size = sizeof (cmd);
|
||||
return spa_node_port_send_command (port->node->node,
|
||||
port->direction,
|
||||
port->port,
|
||||
&cmd);
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_remove_link_done (SpaPoll *poll,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data)
|
||||
{
|
||||
PinosPort *port = user_data;
|
||||
PinosNode *this = port->node;
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
PinosLink *link = ((PinosLink**)data)[0];
|
||||
|
||||
g_debug ("port %p: finish unlink", port);
|
||||
if (port->direction == PINOS_DIRECTION_OUTPUT) {
|
||||
if (g_ptr_array_remove_fast (port->links, link))
|
||||
priv->n_used_output_links--;
|
||||
link->output = NULL;
|
||||
} else {
|
||||
if (g_ptr_array_remove_fast (port->links, link))
|
||||
priv->n_used_input_links--;
|
||||
link->input = NULL;
|
||||
}
|
||||
|
||||
if (priv->n_used_output_links == 0 &&
|
||||
priv->n_used_input_links == 0) {
|
||||
pinos_node_report_idle (this);
|
||||
}
|
||||
|
||||
if (!port->allocated) {
|
||||
g_debug ("port %p: clear buffers on port", port);
|
||||
spa_node_port_use_buffers (port->node->node,
|
||||
port->direction,
|
||||
port->port,
|
||||
NULL, 0);
|
||||
port->buffers = NULL;
|
||||
port->n_buffers = 0;
|
||||
}
|
||||
|
||||
pinos_main_loop_defer_complete (priv->main_loop,
|
||||
port,
|
||||
seq,
|
||||
SPA_RESULT_OK);
|
||||
g_object_unref (link);
|
||||
g_object_unref (port->node);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_remove_link (SpaPoll *poll,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data)
|
||||
{
|
||||
PinosPort *port = user_data;
|
||||
PinosNode *this = port->node;
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
PinosLink *link = ((PinosLink**)data)[0];
|
||||
SpaResult res;
|
||||
|
||||
pinos_port_pause (port);
|
||||
|
||||
g_ptr_array_remove_fast (priv->rt.links, link);
|
||||
|
||||
res = spa_poll_invoke (&priv->main_loop->poll,
|
||||
do_remove_link_done,
|
||||
seq,
|
||||
sizeof (PinosLink *),
|
||||
&link,
|
||||
port);
|
||||
return res;
|
||||
}
|
||||
|
||||
SpaResult
|
||||
pinos_port_unlink (PinosPort *port, PinosLink *link)
|
||||
{
|
||||
SpaResult res;
|
||||
|
||||
g_debug ("port %p: start unlink %p", port, link);
|
||||
|
||||
g_object_ref (link);
|
||||
g_object_ref (port->node);
|
||||
res = spa_poll_invoke (&port->node->priv->data_loop->poll,
|
||||
do_remove_link,
|
||||
port->node->priv->seq++,
|
||||
sizeof (PinosLink *),
|
||||
&link,
|
||||
port);
|
||||
return res;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_clear_buffers_done (SpaPoll *poll,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data)
|
||||
{
|
||||
PinosPort *port = user_data;
|
||||
PinosNode *this = port->node;
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
SpaResult res;
|
||||
|
||||
g_debug ("port %p: clear buffers finish", port);
|
||||
|
||||
res = spa_node_port_use_buffers (port->node->node,
|
||||
port->direction,
|
||||
port->port,
|
||||
NULL, 0);
|
||||
port->buffers = NULL;
|
||||
port->n_buffers = 0;
|
||||
|
||||
pinos_main_loop_defer_complete (priv->main_loop,
|
||||
port,
|
||||
seq,
|
||||
res);
|
||||
return res;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_clear_buffers (SpaPoll *poll,
|
||||
bool async,
|
||||
uint32_t seq,
|
||||
size_t size,
|
||||
void *data,
|
||||
void *user_data)
|
||||
{
|
||||
PinosPort *port = user_data;
|
||||
PinosNode *this = port->node;
|
||||
PinosNodePrivate *priv = this->priv;
|
||||
SpaResult res;
|
||||
|
||||
pinos_port_pause (port);
|
||||
|
||||
res = spa_poll_invoke (&priv->main_loop->poll,
|
||||
do_clear_buffers_done,
|
||||
seq,
|
||||
0, NULL,
|
||||
port);
|
||||
return res;
|
||||
}
|
||||
|
||||
SpaResult
|
||||
pinos_port_clear_buffers (PinosPort *port)
|
||||
{
|
||||
SpaResult res;
|
||||
|
||||
g_debug ("port %p: clear buffers", port);
|
||||
res = spa_poll_invoke (&port->node->priv->data_loop->poll,
|
||||
do_clear_buffers,
|
||||
port->node->priv->seq++,
|
||||
0, NULL,
|
||||
port);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,6 +29,12 @@ typedef struct _PinosNode PinosNode;
|
|||
typedef struct _PinosNodeClass PinosNodeClass;
|
||||
typedef struct _PinosNodePrivate PinosNodePrivate;
|
||||
|
||||
|
||||
typedef enum {
|
||||
PINOS_NODE_FLAG_NONE = 0,
|
||||
PINOS_NODE_FLAG_REMOVING = (1 << 0),
|
||||
} PinosNodeFlags;
|
||||
|
||||
#include <spa/include/spa/node.h>
|
||||
|
||||
#include <pinos/client/introspect.h>
|
||||
|
|
@ -65,6 +71,8 @@ struct _PinosPort {
|
|||
struct _PinosNode {
|
||||
GObject object;
|
||||
|
||||
PinosNodeFlags flags;
|
||||
|
||||
SpaNode *node;
|
||||
|
||||
bool live;
|
||||
|
|
@ -101,12 +109,6 @@ const gchar * pinos_node_get_object_path (PinosNode *node);
|
|||
PinosPort * pinos_node_get_free_port (PinosNode *node,
|
||||
PinosDirection direction);
|
||||
|
||||
PinosLink * pinos_node_link (PinosNode *output_node,
|
||||
PinosPort *output_port,
|
||||
PinosPort *input_port,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties,
|
||||
GError **error);
|
||||
GList * pinos_node_get_ports (PinosNode *node,
|
||||
PinosDirection direction);
|
||||
|
||||
|
|
@ -118,6 +120,17 @@ void pinos_node_report_error (PinosNode *node, GError
|
|||
void pinos_node_report_idle (PinosNode *node);
|
||||
void pinos_node_report_busy (PinosNode *node);
|
||||
|
||||
PinosLink * pinos_port_link (PinosPort *output_port,
|
||||
PinosPort *input_port,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties,
|
||||
GError **error);
|
||||
SpaResult pinos_port_unlink (PinosPort *port,
|
||||
PinosLink *link);
|
||||
|
||||
SpaResult pinos_port_clear_buffers (PinosPort *port);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_NODE_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue