mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
Handle error cases
Add a link state Add error quark Track the state of node we create and error when it is in error. Handle stream error states when negotiating Make the node error when a link is in error
This commit is contained in:
parent
6497c82a7d
commit
2bf322ee71
15 changed files with 422 additions and 71 deletions
|
|
@ -433,6 +433,26 @@ pinos_direction_as_string (PinosDirection direction)
|
|||
return val == NULL ? "invalid-direction" : val->value_nick;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_link_state_as_string:
|
||||
* @state: a #PinosLinkeState
|
||||
*
|
||||
* Return the string representation of @state.
|
||||
*
|
||||
* Returns: the string representation of @state.
|
||||
*/
|
||||
const gchar *
|
||||
pinos_link_state_as_string (PinosLinkState state)
|
||||
{
|
||||
GEnumValue *val;
|
||||
|
||||
val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_LINK_STATE)),
|
||||
state);
|
||||
|
||||
return val == NULL ? "invalid-state" : val->value_nick;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
link_fill_info (PinosLinkInfo *info, GDBusProxy *proxy)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,6 +64,30 @@ typedef enum {
|
|||
|
||||
const gchar * pinos_direction_as_string (PinosDirection direction);
|
||||
|
||||
/**
|
||||
* PinosLinkState:
|
||||
* @PINOS_LINK_STATE_ERROR: the link is in error
|
||||
* @PINOS_LINK_STATE_UNLINKED: the link is unlinked
|
||||
* @PINOS_LINK_STATE_INIT: the link is initialized
|
||||
* @PINOS_LINK_STATE_NEGOTIATING: the link is negotiating formats
|
||||
* @PINOS_LINK_STATE_ALLOCATING: the link is allocating buffers
|
||||
* @PINOS_LINK_STATE_PAUSED: the link is paused
|
||||
* @PINOS_LINK_STATE_RUNNING: the link is running
|
||||
*
|
||||
* The different link states
|
||||
*/
|
||||
typedef enum {
|
||||
PINOS_LINK_STATE_ERROR = -2,
|
||||
PINOS_LINK_STATE_UNLINKED = -1,
|
||||
PINOS_LINK_STATE_INIT = 0,
|
||||
PINOS_LINK_STATE_NEGOTIATING = 1,
|
||||
PINOS_LINK_STATE_ALLOCATING = 2,
|
||||
PINOS_LINK_STATE_PAUSED = 3,
|
||||
PINOS_LINK_STATE_RUNNING = 4,
|
||||
} PinosLinkState;
|
||||
|
||||
const gchar * pinos_link_state_as_string (PinosLinkState state);
|
||||
|
||||
#include <pinos/client/context.h>
|
||||
#include <pinos/client/properties.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,16 @@
|
|||
#include "pinos/client/pinos.h"
|
||||
#include "spa/include/spa/memory.h"
|
||||
|
||||
GQuark
|
||||
pinos_error_quark (void)
|
||||
{
|
||||
static GQuark quark = 0;
|
||||
if (!quark)
|
||||
quark = g_quark_from_static_string ("pinos-error-quark");
|
||||
return quark;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* pinos_init:
|
||||
* @argc: pointer to argc
|
||||
|
|
|
|||
|
|
@ -36,6 +36,18 @@
|
|||
#define PINOS_DBUS_OBJECT_NODE PINOS_DBUS_OBJECT_PREFIX "/node"
|
||||
#define PINOS_DBUS_OBJECT_LINK PINOS_DBUS_OBJECT_PREFIX "/link"
|
||||
|
||||
typedef enum {
|
||||
PINOS_ERROR_FAILED,
|
||||
PINOS_ERROR_FORMAT_NEGOTIATION,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
PINOS_ERROR_NODE_STATE,
|
||||
PINOS_ERROR_NODE_PORT,
|
||||
PINOS_ERROR_NODE_LINK,
|
||||
} PinosErrorEnum;
|
||||
|
||||
GQuark pinos_error_quark (void);
|
||||
#define PINOS_ERROR pinos_error_quark()
|
||||
|
||||
void pinos_init (int *argc, char **argv[]);
|
||||
|
||||
gchar *pinos_client_name (void);
|
||||
|
|
|
|||
|
|
@ -230,6 +230,34 @@ stream_set_state (PinosStream *stream,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_info (PinosContext *c,
|
||||
const PinosNodeInfo *info,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosStream *stream = PINOS_STREAM (user_data);
|
||||
|
||||
if (info->state == PINOS_NODE_STATE_ERROR) {
|
||||
g_debug ("stream %p: node %s in error", stream, info->node_path);
|
||||
stream_set_state (stream,
|
||||
PINOS_STREAM_STATE_ERROR,
|
||||
g_error_new (PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_STATE,
|
||||
"node is in error"));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
info_ready (GObject *o, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!pinos_context_info_finish (o, res, &error)) {
|
||||
g_printerr ("introspection failure: %s\n", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
subscription_cb (PinosSubscribe *subscribe,
|
||||
PinosSubscriptionEvent event,
|
||||
|
|
@ -250,6 +278,16 @@ subscription_cb (PinosSubscribe *subscribe,
|
|||
G_IO_ERROR_CLOSED,
|
||||
"Node disappeared"));
|
||||
}
|
||||
} else if (event == PINOS_SUBSCRIPTION_EVENT_CHANGE) {
|
||||
if (object == priv->node && !priv->disconnecting) {
|
||||
pinos_context_get_node_info_by_id (priv->context,
|
||||
object,
|
||||
PINOS_NODE_INFO_FLAGS_NONE,
|
||||
on_node_info,
|
||||
NULL,
|
||||
info_ready,
|
||||
stream);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ gst_pinos_src_provide_clock (GstElement * elem)
|
|||
if (!GST_OBJECT_FLAG_IS_SET (pinossrc, GST_ELEMENT_FLAG_PROVIDE_CLOCK))
|
||||
goto clock_disabled;
|
||||
|
||||
if (pinossrc->clock)
|
||||
if (pinossrc->clock && pinossrc->is_live)
|
||||
clock = GST_CLOCK_CAST (gst_object_ref (pinossrc->clock));
|
||||
else
|
||||
clock = NULL;
|
||||
|
|
@ -489,10 +489,6 @@ on_stream_notify (GObject *gobject,
|
|||
|
||||
GST_DEBUG ("got stream state %d", state);
|
||||
|
||||
GST_OBJECT_LOCK (pinossrc);
|
||||
pinossrc->stream_state = state;
|
||||
GST_OBJECT_UNLOCK (pinossrc);
|
||||
|
||||
switch (state) {
|
||||
case PINOS_STREAM_STATE_UNCONNECTED:
|
||||
case PINOS_STREAM_STATE_CONNECTING:
|
||||
|
|
@ -513,16 +509,20 @@ static void
|
|||
parse_stream_properties (GstPinosSrc *pinossrc, PinosProperties *props)
|
||||
{
|
||||
const gchar *var;
|
||||
gboolean is_live;
|
||||
|
||||
GST_OBJECT_LOCK (pinossrc);
|
||||
var = pinos_properties_get (props, "pinos.latency.is-live");
|
||||
pinossrc->is_live = var ? (atoi (var) == 1) : FALSE;
|
||||
gst_base_src_set_live (GST_BASE_SRC (pinossrc), pinossrc->is_live);
|
||||
is_live = pinossrc->is_live = var ? (atoi (var) == 1) : FALSE;
|
||||
|
||||
var = pinos_properties_get (props, "pinos.latency.min");
|
||||
pinossrc->min_latency = var ? (GstClockTime) atoi (var) : 0;
|
||||
|
||||
var = pinos_properties_get (props, "pinos.latency.max");
|
||||
pinossrc->max_latency = var ? (GstClockTime) atoi (var) : GST_CLOCK_TIME_NONE;
|
||||
GST_OBJECT_UNLOCK (pinossrc);
|
||||
|
||||
gst_base_src_set_live (GST_BASE_SRC (pinossrc), is_live);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -561,18 +561,31 @@ gst_pinos_src_stream_start (GstPinosSrc *pinossrc)
|
|||
start_error:
|
||||
{
|
||||
GST_DEBUG_OBJECT (pinossrc, "error starting stream");
|
||||
pinos_main_loop_unlock (pinossrc->loop);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static PinosStreamState
|
||||
wait_negotiated (GstPinosSrc *this)
|
||||
{
|
||||
PinosStreamState state;
|
||||
|
||||
pinos_main_loop_lock (this->loop);
|
||||
while (!this->started) {
|
||||
while (TRUE) {
|
||||
state = pinos_stream_get_state (this->stream);
|
||||
|
||||
if (state == PINOS_STREAM_STATE_ERROR)
|
||||
break;
|
||||
|
||||
if (this->started)
|
||||
break;
|
||||
|
||||
pinos_main_loop_wait (this->loop);
|
||||
}
|
||||
pinos_main_loop_unlock (this->loop);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -794,9 +807,11 @@ gst_pinos_src_query (GstBaseSrc * src, GstQuery * query)
|
|||
|
||||
switch (GST_QUERY_TYPE (query)) {
|
||||
case GST_QUERY_LATENCY:
|
||||
GST_OBJECT_LOCK (pinossrc);
|
||||
pinossrc->min_latency = 10000000;
|
||||
pinossrc->max_latency = GST_CLOCK_TIME_NONE;
|
||||
gst_query_set_latency (query, pinossrc->is_live, pinossrc->min_latency, pinossrc->max_latency);
|
||||
GST_OBJECT_UNLOCK (pinossrc);
|
||||
res = TRUE;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -1010,7 +1025,6 @@ gst_pinos_src_close (GstPinosSrc * pinossrc)
|
|||
g_clear_object (&pinossrc->ctx);
|
||||
g_main_context_unref (pinossrc->context);
|
||||
GST_OBJECT_LOCK (pinossrc);
|
||||
pinossrc->stream_state = PINOS_STREAM_STATE_UNCONNECTED;
|
||||
g_clear_object (&pinossrc->clock);
|
||||
g_clear_object (&pinossrc->stream);
|
||||
GST_OBJECT_UNLOCK (pinossrc);
|
||||
|
|
@ -1047,7 +1061,9 @@ gst_pinos_src_change_state (GstElement * element, GstStateChange transition)
|
|||
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||
wait_negotiated (this);
|
||||
if (wait_negotiated (this) == PINOS_STREAM_STATE_ERROR)
|
||||
goto open_failed;
|
||||
|
||||
if (gst_base_src_is_live (GST_BASE_SRC (element)))
|
||||
ret = GST_STATE_CHANGE_NO_PREROLL;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ struct _GstPinosSrc {
|
|||
PinosMainLoop *loop;
|
||||
PinosContext *ctx;
|
||||
PinosStream *stream;
|
||||
PinosStreamState stream_state;
|
||||
GstAllocator *fd_allocator;
|
||||
GstStructure *properties;
|
||||
|
||||
|
|
|
|||
|
|
@ -404,6 +404,22 @@ pinos_client_remove_object (PinosClient *client,
|
|||
g_object_unref (object);
|
||||
}
|
||||
|
||||
gboolean
|
||||
pinos_client_has_object (PinosClient *client,
|
||||
GObject *object)
|
||||
{
|
||||
PinosClientPrivate *priv;
|
||||
GList *found;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_CLIENT (client), FALSE);
|
||||
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
|
||||
priv = client->priv;
|
||||
|
||||
found = g_list_find (priv->objects, object);
|
||||
|
||||
return found != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_client_get_sender:
|
||||
* @client: a #PinosClient
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ void pinos_client_add_object (PinosClient *client,
|
|||
GObject *object);
|
||||
void pinos_client_remove_object (PinosClient *client,
|
||||
GObject *object);
|
||||
gboolean pinos_client_has_object (PinosClient *client,
|
||||
GObject *object);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -183,6 +183,38 @@ no_node:
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_link_state_notify (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
PinosClient *client)
|
||||
{
|
||||
PinosLink *link = PINOS_LINK (obj);
|
||||
GError *error = NULL;
|
||||
PinosLinkState state;
|
||||
|
||||
state = pinos_link_get_state (link, &error);
|
||||
switch (state) {
|
||||
case PINOS_LINK_STATE_ERROR:
|
||||
g_warning ("link %p: state error: %s", link, error->message);
|
||||
|
||||
if (link->input_node && pinos_client_has_object (client, G_OBJECT (link->input_node))) {
|
||||
pinos_node_report_error (link->input_node, g_error_copy (error));
|
||||
}
|
||||
if (link->output_node && pinos_client_has_object (client, G_OBJECT (link->output_node))) {
|
||||
pinos_node_report_error (link->output_node, g_error_copy (error));
|
||||
}
|
||||
break;
|
||||
case PINOS_LINK_STATE_UNLINKED:
|
||||
break;
|
||||
case PINOS_LINK_STATE_INIT:
|
||||
case PINOS_LINK_STATE_NEGOTIATING:
|
||||
case PINOS_LINK_STATE_ALLOCATING:
|
||||
case PINOS_LINK_STATE_PAUSED:
|
||||
case PINOS_LINK_STATE_RUNNING:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_port_added (PinosNode *node, PinosDirection direction, guint port_id, PinosClient *client)
|
||||
{
|
||||
|
|
@ -209,27 +241,34 @@ on_port_added (PinosNode *node, PinosDirection direction, guint port_id, PinosCl
|
|||
NULL,
|
||||
&error);
|
||||
if (target == NULL) {
|
||||
g_warning ("daemon %p: can't find node target: %s", this, error->message);
|
||||
g_clear_error (&error);
|
||||
pinos_node_report_error (node, error);
|
||||
return;
|
||||
}
|
||||
|
||||
new_port = pinos_node_get_free_port (target, pinos_direction_reverse (direction));
|
||||
if (new_port == SPA_ID_INVALID) {
|
||||
g_warning ("daemon %p: can't get free port", this);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_PORT,
|
||||
"can't get free port from node %s", pinos_node_get_object_path (target));
|
||||
pinos_node_report_error (node, error);
|
||||
return;
|
||||
}
|
||||
if (direction == PINOS_DIRECTION_OUTPUT)
|
||||
link = pinos_node_link (node, port_id, target, new_port, NULL, NULL);
|
||||
link = pinos_node_link (node, port_id, target, new_port, NULL, NULL, &error);
|
||||
else
|
||||
link = pinos_node_link (target, new_port, node, port_id, NULL, NULL);
|
||||
link = pinos_node_link (target, new_port, node, port_id, NULL, NULL, &error);
|
||||
|
||||
if (link == NULL) {
|
||||
g_warning ("daemon %p: can't link nodes", this);
|
||||
pinos_node_report_error (node, error);
|
||||
return;
|
||||
}
|
||||
|
||||
pinos_client_add_object (client, G_OBJECT (link));
|
||||
|
||||
g_signal_connect (link, "notify::state", (GCallback) on_link_state_notify, client);
|
||||
pinos_link_activate (link);
|
||||
|
||||
g_object_unref (link);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ struct _PinosLinkPrivate
|
|||
GPtrArray *format_filter;
|
||||
PinosProperties *properties;
|
||||
|
||||
PinosLinkState state;
|
||||
GError *error;
|
||||
|
||||
SpaBuffer *in_buffers[16];
|
||||
unsigned int n_in_buffers;
|
||||
SpaBuffer *out_buffers[16];
|
||||
|
|
@ -64,6 +67,7 @@ enum
|
|||
PROP_INPUT_PORT,
|
||||
PROP_FORMAT_FILTER,
|
||||
PROP_PROPERTIES,
|
||||
PROP_STATE,
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
@ -124,6 +128,10 @@ pinos_link_get_property (GObject *_object,
|
|||
g_value_set_boxed (value, priv->properties);
|
||||
break;
|
||||
|
||||
case PROP_STATE:
|
||||
g_value_set_enum (value, priv->state);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec);
|
||||
break;
|
||||
|
|
@ -215,12 +223,43 @@ link_unregister_object (PinosLink *this)
|
|||
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_link_update_state (PinosLink *link, PinosLinkState state)
|
||||
{
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
|
||||
if (state != priv->state) {
|
||||
g_clear_error (&priv->error);
|
||||
priv->state = state;
|
||||
g_debug ("link %p: got state %s", link, pinos_link_state_as_string (state));
|
||||
g_object_notify (G_OBJECT (link), "state");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_link_report_error (PinosLink *link, GError *error)
|
||||
{
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
|
||||
g_clear_error (&priv->error);
|
||||
priv->error = error;
|
||||
priv->state = PINOS_LINK_STATE_ERROR;
|
||||
g_debug ("link %p: got error state %s", link, error->message);
|
||||
g_object_notify (G_OBJECT (link), "state");
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
||||
{
|
||||
SpaResult res;
|
||||
SpaFormat *filter = NULL, *format;
|
||||
void *istate = NULL, *ostate = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (in_state != SPA_NODE_STATE_CONFIGURE && out_state != SPA_NODE_STATE_CONFIGURE)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_NEGOTIATING);
|
||||
|
||||
/* both ports need a format */
|
||||
if (in_state == SPA_NODE_STATE_CONFIGURE && out_state == SPA_NODE_STATE_CONFIGURE) {
|
||||
|
|
@ -232,7 +271,10 @@ again:
|
|||
NULL,
|
||||
&istate)) < 0) {
|
||||
if (res == SPA_RESULT_ENUM_END && istate != NULL) {
|
||||
g_warning ("error input enum formats: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_FORMAT_NEGOTIATION,
|
||||
"error input enum formats: %d", res);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
@ -247,21 +289,34 @@ again:
|
|||
ostate = NULL;
|
||||
goto again;
|
||||
}
|
||||
g_warning ("error output enum formats: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_FORMAT_NEGOTIATION,
|
||||
"error output enum formats: %d", res);
|
||||
goto error;
|
||||
}
|
||||
spa_debug_format (format);
|
||||
spa_format_fixate (format);
|
||||
} else if (in_state == SPA_NODE_STATE_CONFIGURE && out_state > SPA_NODE_STATE_CONFIGURE) {
|
||||
/* only input needs format */
|
||||
if ((res = spa_node_port_get_format (this->output_node->node, this->output_port, (const SpaFormat **)&format)) < 0) {
|
||||
g_warning ("error get format output: %d", res);
|
||||
if ((res = spa_node_port_get_format (this->output_node->node,
|
||||
this->output_port,
|
||||
(const SpaFormat **)&format)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_FORMAT_NEGOTIATION,
|
||||
"error get output format: %d", res);
|
||||
goto error;
|
||||
}
|
||||
} else if (out_state == SPA_NODE_STATE_CONFIGURE && in_state > SPA_NODE_STATE_CONFIGURE) {
|
||||
/* only output needs format */
|
||||
if ((res = spa_node_port_get_format (this->input_node->node, this->input_port, (const SpaFormat **)&format)) < 0) {
|
||||
g_warning ("error get format input: %d", res);
|
||||
if ((res = spa_node_port_get_format (this->input_node->node,
|
||||
this->input_port,
|
||||
(const SpaFormat **)&format)) < 0) {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_FORMAT_NEGOTIATION,
|
||||
"error get input format: %d", res);
|
||||
goto error;
|
||||
}
|
||||
} else
|
||||
|
|
@ -273,13 +328,19 @@ again:
|
|||
if (out_state == SPA_NODE_STATE_CONFIGURE) {
|
||||
g_debug ("link %p: doing set format on output", this);
|
||||
if ((res = spa_node_port_set_format (this->output_node->node, this->output_port, 0, format)) < 0) {
|
||||
g_warning ("error set format output: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_FORMAT_NEGOTIATION,
|
||||
"error set output format: %d", res);
|
||||
goto error;
|
||||
}
|
||||
} else if (in_state == SPA_NODE_STATE_CONFIGURE) {
|
||||
g_debug ("link %p: doing set format on input", this);
|
||||
if ((res = spa_node_port_set_format (this->input_node->node, this->input_port, 0, format)) < 0) {
|
||||
g_warning ("error set format input: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_FORMAT_NEGOTIATION,
|
||||
"error set input format: %d", res);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
@ -287,6 +348,7 @@ again:
|
|||
|
||||
error:
|
||||
{
|
||||
pinos_link_report_error (this, error);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
@ -298,18 +360,27 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
SpaResult res;
|
||||
const SpaPortInfo *iinfo, *oinfo;
|
||||
SpaPortInfoFlags in_flags, out_flags;
|
||||
GError *error = NULL;
|
||||
|
||||
if (in_state != SPA_NODE_STATE_READY && out_state != SPA_NODE_STATE_READY)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_ALLOCATING);
|
||||
|
||||
g_debug ("link %p: doing alloc buffers %p %p", this, this->output_node, this->input_node);
|
||||
/* find out what's possible */
|
||||
if ((res = spa_node_port_get_info (this->output_node->node, this->output_port, &oinfo)) < 0) {
|
||||
g_warning ("error get port info: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error get output port info: %d", res);
|
||||
goto error;
|
||||
}
|
||||
if ((res = spa_node_port_get_info (this->input_node->node, this->input_port, &iinfo)) < 0) {
|
||||
g_warning ("error get port info: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error get input port info: %d", res);
|
||||
goto error;
|
||||
}
|
||||
in_flags = iinfo->flags;
|
||||
|
|
@ -333,7 +404,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
if ((res = spa_buffer_alloc (oinfo->params, oinfo->n_params,
|
||||
priv->in_buffers,
|
||||
&priv->n_in_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error buffer alloc: %d", res);
|
||||
goto error;
|
||||
}
|
||||
memcpy (priv->out_buffers, priv->in_buffers, priv->n_in_buffers * sizeof (SpaBuffer*));
|
||||
|
|
@ -344,7 +418,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
in_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
} else {
|
||||
g_warning ("error no common allocation found");
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"no common buffer alloc found");
|
||||
res = SPA_RESULT_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -365,7 +442,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
if ((res = spa_node_port_alloc_buffers (this->input_node->node, this->input_port,
|
||||
oinfo->params, oinfo->n_params,
|
||||
priv->in_buffers, &priv->n_in_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc input buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
g_debug ("allocated in_buffers %p", priv->in_buffers);
|
||||
|
|
@ -375,7 +455,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
if ((res = spa_node_port_alloc_buffers (this->output_node->node, this->output_port,
|
||||
iinfo->params, iinfo->n_params,
|
||||
priv->out_buffers, &priv->n_out_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error alloc output buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
g_debug ("allocated out_buffers %p", priv->out_buffers);
|
||||
|
|
@ -384,7 +467,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
g_debug ("using out_buffers %p", priv->out_buffers);
|
||||
if ((res = spa_node_port_use_buffers (this->input_node->node, this->input_port,
|
||||
priv->out_buffers, priv->n_out_buffers)) < 0) {
|
||||
g_warning ("error use buffers: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error use input buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
@ -392,16 +478,25 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
g_debug ("using in_buffers %p", priv->out_buffers);
|
||||
if ((res = spa_node_port_use_buffers (this->output_node->node, this->output_port,
|
||||
priv->in_buffers, priv->n_in_buffers)) < 0) {
|
||||
g_warning ("error use buffers: %d", res);
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"error use output buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
} else
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
} else {
|
||||
g_set_error (&error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_BUFFER_ALLOCATION,
|
||||
"no common buffer alloc found");
|
||||
goto error;
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
error:
|
||||
{
|
||||
pinos_link_report_error (this, error);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
@ -414,12 +509,16 @@ do_start (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
if (in_state < SPA_NODE_STATE_PAUSED || out_state < SPA_NODE_STATE_PAUSED)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_PAUSED);
|
||||
|
||||
if (in_state == SPA_NODE_STATE_PAUSED)
|
||||
pinos_node_set_state (this->input_node, PINOS_NODE_STATE_RUNNING);
|
||||
|
||||
if (out_state == SPA_NODE_STATE_PAUSED)
|
||||
pinos_node_set_state (this->output_node, PINOS_NODE_STATE_RUNNING);
|
||||
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_RUNNING);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -487,6 +586,8 @@ on_node_remove (PinosNode *node, PinosLink *this)
|
|||
g_clear_object (&this->input_node);
|
||||
else
|
||||
g_clear_object (&this->output_node);
|
||||
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_UNLINKED);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -496,6 +597,7 @@ pinos_link_constructed (GObject * object)
|
|||
|
||||
g_signal_connect (this->input_node, "remove", (GCallback) on_node_remove, this);
|
||||
g_signal_connect (this->output_node, "remove", (GCallback) on_node_remove, this);
|
||||
|
||||
g_signal_connect (this->input_node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||
g_signal_connect (this->output_node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||
|
||||
|
|
@ -508,8 +610,6 @@ pinos_link_constructed (GObject * object)
|
|||
this->output_node, this->output_id, this->output_port,
|
||||
this->input_node, this->input_id, this->input_port);
|
||||
link_register_object (this);
|
||||
|
||||
check_states (this);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -654,11 +754,20 @@ pinos_link_class_init (PinosLinkClass * klass)
|
|||
PROP_PROPERTIES,
|
||||
g_param_spec_boxed ("properties",
|
||||
"Properties",
|
||||
"The properties of the node",
|
||||
"The properties of the link",
|
||||
PINOS_TYPE_PROPERTIES,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_STATE,
|
||||
g_param_spec_enum ("state",
|
||||
"State",
|
||||
"The state of the link",
|
||||
PINOS_TYPE_LINK_STATE,
|
||||
PINOS_LINK_STATE_INIT,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
|
|
@ -679,6 +788,7 @@ pinos_link_init (PinosLink * this)
|
|||
|
||||
priv->iface = pinos_link1_skeleton_new ();
|
||||
g_debug ("link %p: new", this);
|
||||
priv->state = PINOS_LINK_STATE_INIT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -712,3 +822,34 @@ pinos_link_get_object_path (PinosLink *this)
|
|||
|
||||
return priv->object_path;
|
||||
}
|
||||
|
||||
PinosLinkState
|
||||
pinos_link_get_state (PinosLink *this,
|
||||
GError **error)
|
||||
{
|
||||
PinosLinkPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_LINK (this), PINOS_LINK_STATE_ERROR);
|
||||
priv = this->priv;
|
||||
|
||||
if (error)
|
||||
*error = priv->error;
|
||||
|
||||
return priv->state;
|
||||
}
|
||||
|
||||
gboolean
|
||||
pinos_link_activate (PinosLink *this)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_LINK (this), FALSE);
|
||||
|
||||
check_states (this);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
pinos_link_deactivate (PinosLink *this)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,12 @@ PinosProperties * pinos_link_get_properties (PinosLink *link);
|
|||
|
||||
const gchar * pinos_link_get_object_path (PinosLink *link);
|
||||
|
||||
gboolean pinos_link_activate (PinosLink *link);
|
||||
gboolean pinos_link_deactivate (PinosLink *link);
|
||||
|
||||
PinosLinkState pinos_link_get_state (PinosLink *link,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_LINK_H__ */
|
||||
|
|
|
|||
|
|
@ -1206,20 +1206,21 @@ do_remove_link (PinosLink *link, PinosNode *node)
|
|||
/**
|
||||
* pinos_node_link:
|
||||
* @output_node: a #PinosNode
|
||||
* @output_port: a port
|
||||
* @output_id: an output link id
|
||||
* @input_node: a #PinosNode
|
||||
* @input_port: a port
|
||||
* @input_id: an input link id
|
||||
* @format_filter: a format filter
|
||||
* @properties: extra properties
|
||||
* @error: an error or %NULL
|
||||
*
|
||||
* Make a link between @output_node and @input_node on the given ports.
|
||||
* Make a link between @output_node and @input_node with the given ids
|
||||
*
|
||||
* If the ports were already linked, the existing linke will be returned.
|
||||
* If the ports were already linked, the existing links will be returned.
|
||||
*
|
||||
* If the source port was linked to a different destination node or port, it
|
||||
* If the output id was linked to a different input node or id, it
|
||||
* will be relinked.
|
||||
*
|
||||
* Returns: a new #PinosLink
|
||||
* Returns: a new #PinosLink or %NULL and @error is set.
|
||||
*/
|
||||
PinosLink *
|
||||
pinos_node_link (PinosNode *output_node,
|
||||
|
|
@ -1227,7 +1228,8 @@ pinos_node_link (PinosNode *output_node,
|
|||
PinosNode *input_node,
|
||||
guint input_id,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties)
|
||||
PinosProperties *properties,
|
||||
GError **error)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
NodeLink *olink, *ilink;
|
||||
|
|
@ -1240,6 +1242,9 @@ pinos_node_link (PinosNode *output_node,
|
|||
|
||||
g_debug ("node %p: link %u %p:%u", output_node, output_id, input_node, input_id);
|
||||
|
||||
if (output_node == input_node)
|
||||
goto same_node;
|
||||
|
||||
if (output_id >= priv->output_links->len)
|
||||
g_array_set_size (priv->output_links, output_id + 1);
|
||||
if (input_id >= input_node->priv->input_links->len)
|
||||
|
|
@ -1261,13 +1266,13 @@ pinos_node_link (PinosNode *output_node,
|
|||
if (output_port == SPA_ID_INVALID && output_node->priv->n_output_ports > 0)
|
||||
output_port = output_node->priv->output_port_ids[0];
|
||||
else
|
||||
return NULL;
|
||||
goto no_output_ports;
|
||||
|
||||
input_port = get_free_node_port (input_node, PINOS_DIRECTION_INPUT);
|
||||
if (input_port == SPA_ID_INVALID && input_node->priv->n_input_ports > 0)
|
||||
input_port = input_node->priv->input_port_ids[0];
|
||||
else
|
||||
return NULL;
|
||||
goto no_input_ports;
|
||||
|
||||
if (output_node->priv->clock)
|
||||
input_node->priv->clock = output_node->priv->clock;
|
||||
|
|
@ -1296,6 +1301,31 @@ pinos_node_link (PinosNode *output_node,
|
|||
ilink->link = pl;
|
||||
}
|
||||
return pl;
|
||||
|
||||
same_node:
|
||||
{
|
||||
g_set_error (error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_LINK,
|
||||
"can't link a node to itself");
|
||||
return NULL;
|
||||
}
|
||||
no_input_ports:
|
||||
{
|
||||
g_set_error (error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_LINK,
|
||||
"can't get an input port to link to");
|
||||
return NULL;
|
||||
}
|
||||
no_output_ports:
|
||||
{
|
||||
g_set_error (error,
|
||||
PINOS_ERROR,
|
||||
PINOS_ERROR_NODE_LINK,
|
||||
"can't get an output port to link to");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1309,11 +1339,7 @@ pinos_node_link (PinosNode *output_node,
|
|||
GList *
|
||||
pinos_node_get_links (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1405,6 +1431,7 @@ pinos_node_report_error (PinosNode *node,
|
|||
priv->error = error;
|
||||
priv->state = PINOS_NODE_STATE_ERROR;
|
||||
g_debug ("node %p: got error state %s", node, error->message);
|
||||
pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_ERROR);
|
||||
g_object_notify (G_OBJECT (node), "state");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,30 +72,31 @@ struct _PinosNodeClass {
|
|||
/* normal GObject stuff */
|
||||
GType pinos_node_get_type (void);
|
||||
|
||||
PinosNode * pinos_node_new (PinosDaemon *daemon,
|
||||
const gchar *sender,
|
||||
const gchar *name,
|
||||
PinosProperties *properties,
|
||||
SpaNode *node);
|
||||
PinosNode * pinos_node_new (PinosDaemon *daemon,
|
||||
const gchar *sender,
|
||||
const gchar *name,
|
||||
PinosProperties *properties,
|
||||
SpaNode *node);
|
||||
void pinos_node_remove (PinosNode *node);
|
||||
|
||||
const gchar * pinos_node_get_name (PinosNode *node);
|
||||
PinosProperties * pinos_node_get_properties (PinosNode *node);
|
||||
|
||||
PinosDaemon * pinos_node_get_daemon (PinosNode *node);
|
||||
const gchar * pinos_node_get_sender (PinosNode *node);
|
||||
const gchar * pinos_node_get_object_path (PinosNode *node);
|
||||
PinosDaemon * pinos_node_get_daemon (PinosNode *node);
|
||||
const gchar * pinos_node_get_sender (PinosNode *node);
|
||||
const gchar * pinos_node_get_object_path (PinosNode *node);
|
||||
|
||||
guint pinos_node_get_free_port (PinosNode *node,
|
||||
PinosDirection direction);
|
||||
guint pinos_node_get_free_port (PinosNode *node,
|
||||
PinosDirection direction);
|
||||
|
||||
PinosLink * pinos_node_link (PinosNode *output_node,
|
||||
guint output_id,
|
||||
PinosNode *input_node,
|
||||
guint input_id,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties);
|
||||
GList * pinos_node_get_links (PinosNode *node);
|
||||
PinosLink * pinos_node_link (PinosNode *output_node,
|
||||
guint output_id,
|
||||
PinosNode *input_node,
|
||||
guint input_id,
|
||||
GPtrArray *format_filter,
|
||||
PinosProperties *properties,
|
||||
GError **error);
|
||||
GList * pinos_node_get_links (PinosNode *node);
|
||||
|
||||
|
||||
PinosNodeState pinos_node_get_state (PinosNode *node);
|
||||
|
|
|
|||
|
|
@ -408,7 +408,7 @@ static SpaResult
|
|||
clear_buffers (SpaAudioTestSrc *this)
|
||||
{
|
||||
if (this->have_buffers) {
|
||||
fprintf (stderr, "clear buffers");
|
||||
fprintf (stderr, "audiotestsrc %p: clear buffers\n", this);
|
||||
if (this->alloc_mem)
|
||||
spa_memory_unref (&this->alloc_mem->mem);
|
||||
this->alloc_mem = NULL;
|
||||
|
|
@ -577,7 +577,7 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
|
|||
|
||||
mem_ref = &d[0].mem.mem;
|
||||
if (!(mem = spa_memory_find (mem_ref))) {
|
||||
fprintf (stderr, "invalid memory on buffer %p\n", buffers[i]);
|
||||
fprintf (stderr, "audiotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
continue;
|
||||
}
|
||||
b->ptr = SPA_MEMBER (spa_memory_ensure_ptr (mem), d[0].mem.offset, void);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue