mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -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
|
|
@ -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