mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-11 13:30:07 -05:00
Work on sink
Remove _remove from properties, we can do the same with set of a NULL value. Add signals to the stream API to manage the buffers. Wrap those buffers in a GstBuffer in the pinossrc and pinossink elements and pool them in a bufferpool. Remove SPA_EVENT_TYPE_PULL_INPUT, we can do the same with NEED_INPUT and by using a ringbuffer. Do more complete allocation of buffers in the link. Use the buffer allocator if none of the nodes can allocate. Follow the node state to trigger negotiation and allocation. Remove offset and size when refering to buffers, we want to always deal with the complete buffer and use a ringbuffer for ranges or change the offset/size in the buffer data when needed. Serialize port_info structures as part of the port_update Print both the enum number and the name when debuging properties or formats.
This commit is contained in:
parent
a03352353f
commit
ca7d08c406
45 changed files with 1614 additions and 570 deletions
|
|
@ -180,8 +180,6 @@ on_received_buffer (PinosPort *port, uint32_t buffer_id, GError **error, gpointe
|
|||
info[0].port_id = port->id;
|
||||
info[0].buffer_id = buffer_id;
|
||||
info[0].flags = SPA_INPUT_FLAG_NONE;
|
||||
info[0].offset = 0;
|
||||
info[0].size = -1;
|
||||
|
||||
if ((res = spa_node_port_push_input (node->node, 1, info)) < 0)
|
||||
g_warning ("client-node %p: error pushing buffer: %d, %d", node, res, info[0].status);
|
||||
|
|
@ -296,6 +294,8 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
|||
{
|
||||
SpaEventStateChange *sc = event->data;
|
||||
|
||||
pinos_node_update_node_state (PINOS_NODE (this), sc->state);
|
||||
|
||||
switch (sc->state) {
|
||||
case SPA_NODE_STATE_CONFIGURE:
|
||||
{
|
||||
|
|
@ -329,6 +329,24 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
|||
stop_thread (this);
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_HAVE_OUTPUT:
|
||||
{
|
||||
PinosPort *port;
|
||||
SpaOutputInfo info[1] = { 0, };
|
||||
SpaResult res;
|
||||
GError *error = NULL;
|
||||
|
||||
if ((res = spa_node_port_pull_output (node, 1, info)) < 0)
|
||||
g_debug ("client-node %p: got pull error %d, %d", this, res, info[0].status);
|
||||
|
||||
port = pinos_node_find_port (PINOS_NODE (this), info[0].port_id);
|
||||
|
||||
if (!pinos_port_send_buffer (port, info[0].buffer_id, &error)) {
|
||||
g_debug ("send failed: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SPA_EVENT_TYPE_REUSE_BUFFER:
|
||||
{
|
||||
PinosPort *port;
|
||||
|
|
|
|||
|
|
@ -56,8 +56,13 @@ struct _PinosLinkPrivate
|
|||
SpaNode *input_node;
|
||||
uint32_t input_port;
|
||||
|
||||
SpaBuffer *buffers[16];
|
||||
unsigned int n_buffers;
|
||||
SpaNodeState input_state;
|
||||
SpaNodeState output_state;
|
||||
|
||||
SpaBuffer *in_buffers[16];
|
||||
unsigned int n_in_buffers;
|
||||
SpaBuffer *out_buffers[16];
|
||||
unsigned int n_out_buffers;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosLink, pinos_link, G_TYPE_OBJECT);
|
||||
|
|
@ -268,8 +273,9 @@ do_allocation (PinosLink *this)
|
|||
PinosLinkPrivate *priv = this->priv;
|
||||
SpaResult res;
|
||||
const SpaPortInfo *iinfo, *oinfo;
|
||||
SpaPortInfoFlags in_flags, out_flags;
|
||||
|
||||
g_debug ("link %p: doing alloc buffers", this);
|
||||
g_debug ("link %p: doing alloc buffers %p %p", this, priv->output_node, priv->input_node);
|
||||
/* find out what's possible */
|
||||
if ((res = spa_node_port_get_info (priv->output_node, priv->output_port, &oinfo)) < 0) {
|
||||
g_warning ("error get port info: %d", res);
|
||||
|
|
@ -280,18 +286,79 @@ do_allocation (PinosLink *this)
|
|||
return res;
|
||||
}
|
||||
|
||||
priv->n_buffers = 16;
|
||||
if ((res = spa_node_port_alloc_buffers (priv->output_node, priv->output_port,
|
||||
iinfo->params, iinfo->n_params,
|
||||
priv->buffers, &priv->n_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
return res;
|
||||
spa_debug_port_info (oinfo);
|
||||
spa_debug_port_info (iinfo);
|
||||
|
||||
priv->n_in_buffers = 16;
|
||||
priv->n_out_buffers = 16;
|
||||
|
||||
if ((oinfo->flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) &&
|
||||
(iinfo->flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS)) {
|
||||
out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
in_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
} else if ((oinfo->flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) &&
|
||||
(iinfo->flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS)) {
|
||||
out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
in_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
} else if ((oinfo->flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) &&
|
||||
(iinfo->flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS)) {
|
||||
out_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
in_flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
|
||||
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);
|
||||
return res;
|
||||
}
|
||||
memcpy (priv->out_buffers, priv->in_buffers, priv->n_in_buffers * sizeof (SpaBuffer*));
|
||||
priv->n_out_buffers = priv->n_in_buffers;
|
||||
} else if ((oinfo->flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) &&
|
||||
(iinfo->flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS)) {
|
||||
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");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if ((res = spa_node_port_use_buffers (priv->input_node, priv->input_port,
|
||||
priv->buffers, priv->n_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
return res;
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
||||
if ((res = spa_node_port_alloc_buffers (priv->input_node, priv->input_port,
|
||||
oinfo->params, oinfo->n_params,
|
||||
priv->in_buffers, &priv->n_in_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
return res;
|
||||
}
|
||||
priv->input->n_buffers = priv->n_in_buffers;
|
||||
priv->input->buffers = priv->in_buffers;
|
||||
}
|
||||
if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
|
||||
if ((res = spa_node_port_alloc_buffers (priv->output_node, priv->output_port,
|
||||
iinfo->params, iinfo->n_params,
|
||||
priv->out_buffers, &priv->n_out_buffers)) < 0) {
|
||||
g_warning ("error alloc buffers: %d", res);
|
||||
return res;
|
||||
}
|
||||
priv->output->n_buffers = priv->n_out_buffers;
|
||||
priv->output->buffers = priv->out_buffers;
|
||||
}
|
||||
if (in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
||||
if ((res = spa_node_port_use_buffers (priv->input_node, priv->input_port,
|
||||
priv->out_buffers, priv->n_out_buffers)) < 0) {
|
||||
g_warning ("error use buffers: %d", res);
|
||||
return res;
|
||||
}
|
||||
priv->input->n_buffers = priv->n_out_buffers;
|
||||
priv->input->buffers = priv->out_buffers;
|
||||
}
|
||||
if (out_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS) {
|
||||
if ((res = spa_node_port_use_buffers (priv->output_node, priv->output_port,
|
||||
priv->in_buffers, priv->n_in_buffers)) < 0) {
|
||||
g_warning ("error use buffers: %d", res);
|
||||
return res;
|
||||
}
|
||||
priv->output->n_buffers = priv->n_in_buffers;
|
||||
priv->output->buffers = priv->in_buffers;
|
||||
}
|
||||
|
||||
priv->allocated = TRUE;
|
||||
|
|
@ -299,13 +366,86 @@ do_allocation (PinosLink *this)
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_start (PinosLink *this)
|
||||
{
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
SpaCommand cmd;
|
||||
SpaResult res;
|
||||
|
||||
cmd.type = SPA_COMMAND_START;
|
||||
if ((res = spa_node_send_command (priv->input_node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
if ((res = spa_node_send_command (priv->output_node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
do_stop (PinosLink *this)
|
||||
{
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
SpaCommand cmd;
|
||||
SpaResult res;
|
||||
|
||||
cmd.type = SPA_COMMAND_STOP;
|
||||
if ((res = spa_node_send_command (priv->input_node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
if ((res = spa_node_send_command (priv->output_node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
check_states (PinosLink *this)
|
||||
{
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
SpaResult res;
|
||||
|
||||
g_debug ("link %p: input %d, output %d", this, priv->input_state, priv->output_state);
|
||||
|
||||
if (priv->input_state == SPA_NODE_STATE_CONFIGURE &&
|
||||
priv->output_state == SPA_NODE_STATE_CONFIGURE &&
|
||||
!priv->negotiated) {
|
||||
if ((res = do_negotiate (this)) < 0)
|
||||
return res;
|
||||
}
|
||||
if (priv->input_state == SPA_NODE_STATE_READY &&
|
||||
priv->output_state == SPA_NODE_STATE_READY &&
|
||||
!priv->allocated) {
|
||||
if ((res = do_allocation (this)) < 0)
|
||||
return res;
|
||||
|
||||
if ((res = do_start (this)) < 0)
|
||||
return res;
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_state_notify (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosLink *this = user_data;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
g_debug ("link %p: node %p state change", this, obj);
|
||||
if (obj == G_OBJECT (priv->input->node))
|
||||
priv->input_state = priv->input->node->node_state;
|
||||
else
|
||||
priv->output_state = priv->output->node->node_state;
|
||||
|
||||
check_states (this);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_activate (PinosPort *port, gpointer user_data)
|
||||
{
|
||||
PinosLink *this = user_data;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
SpaCommand cmd;
|
||||
SpaResult res;
|
||||
|
||||
if (priv->active)
|
||||
return TRUE;
|
||||
|
|
@ -316,18 +456,7 @@ on_activate (PinosPort *port, gpointer user_data)
|
|||
else
|
||||
pinos_port_activate (priv->input);
|
||||
|
||||
if (!priv->negotiated)
|
||||
do_negotiate (this);
|
||||
|
||||
/* negotiate allocation */
|
||||
if (!priv->allocated)
|
||||
do_allocation (this);
|
||||
|
||||
cmd.type = SPA_COMMAND_START;
|
||||
if ((res = spa_node_send_command (priv->input_node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
if ((res = spa_node_send_command (priv->output_node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
check_states (this);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -335,10 +464,8 @@ on_activate (PinosPort *port, gpointer user_data)
|
|||
static gboolean
|
||||
on_deactivate (PinosPort *port, gpointer user_data)
|
||||
{
|
||||
PinosLink *link = user_data;
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
SpaCommand cmd;
|
||||
SpaResult res;
|
||||
PinosLink *this = user_data;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
if (!priv->active)
|
||||
return TRUE;
|
||||
|
|
@ -349,11 +476,7 @@ on_deactivate (PinosPort *port, gpointer user_data)
|
|||
else
|
||||
pinos_port_deactivate (priv->input);
|
||||
|
||||
cmd.type = SPA_COMMAND_STOP;
|
||||
if ((res = spa_node_send_command (priv->input_node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
if ((res = spa_node_send_command (priv->output_node, &cmd)) < 0)
|
||||
g_warning ("got error %d", res);
|
||||
do_stop (this);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -363,8 +486,8 @@ on_property_notify (GObject *obj,
|
|||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosLink *link = user_data;
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
PinosLink *this = user_data;
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output") == 0) {
|
||||
gchar *port = g_strdup_printf ("%s:%d", pinos_node_get_object_path (priv->output->node),
|
||||
|
|
@ -384,32 +507,38 @@ on_property_notify (GObject *obj,
|
|||
static void
|
||||
pinos_link_constructed (GObject * object)
|
||||
{
|
||||
PinosLink *link = PINOS_LINK (object);
|
||||
PinosLinkPrivate *priv = link->priv;
|
||||
PinosLink *this = PINOS_LINK (object);
|
||||
PinosLinkPrivate *priv = this->priv;
|
||||
|
||||
priv->output_id = pinos_port_add_send_cb (priv->output,
|
||||
on_output_buffer,
|
||||
on_output_event,
|
||||
link,
|
||||
this,
|
||||
NULL);
|
||||
priv->input_id = pinos_port_add_send_cb (priv->input,
|
||||
on_input_buffer,
|
||||
on_input_event,
|
||||
link,
|
||||
this,
|
||||
NULL);
|
||||
|
||||
g_signal_connect (priv->input, "activate", (GCallback) on_activate, link);
|
||||
g_signal_connect (priv->input, "deactivate", (GCallback) on_deactivate, link);
|
||||
g_signal_connect (priv->output, "activate", (GCallback) on_activate, link);
|
||||
g_signal_connect (priv->output, "deactivate", (GCallback) on_deactivate, link);
|
||||
priv->input_state = priv->input->node->node_state;
|
||||
priv->output_state = priv->output->node->node_state;
|
||||
|
||||
g_signal_connect (link, "notify", (GCallback) on_property_notify, link);
|
||||
g_signal_connect (priv->input->node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||
g_signal_connect (priv->output->node, "notify::node-state", (GCallback) on_node_state_notify, this);
|
||||
|
||||
g_signal_connect (priv->input, "activate", (GCallback) on_activate, this);
|
||||
g_signal_connect (priv->input, "deactivate", (GCallback) on_deactivate, this);
|
||||
g_signal_connect (priv->output, "activate", (GCallback) on_activate, this);
|
||||
g_signal_connect (priv->output, "deactivate", (GCallback) on_deactivate, this);
|
||||
|
||||
g_signal_connect (this, "notify", (GCallback) on_property_notify, this);
|
||||
|
||||
G_OBJECT_CLASS (pinos_link_parent_class)->constructed (object);
|
||||
|
||||
on_property_notify (G_OBJECT (link), NULL, link);
|
||||
g_debug ("link %p: constructed", link);
|
||||
link_register_object (link);
|
||||
on_property_notify (G_OBJECT (this), NULL, this);
|
||||
g_debug ("link %p: constructed", this);
|
||||
link_register_object (this);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -427,8 +556,8 @@ pinos_link_dispose (GObject * object)
|
|||
pinos_port_deactivate (priv->input);
|
||||
pinos_port_deactivate (priv->output);
|
||||
}
|
||||
g_clear_object (&priv->input);
|
||||
g_clear_object (&priv->output);
|
||||
priv->input = NULL;
|
||||
priv->output = NULL;
|
||||
link_unregister_object (link);
|
||||
|
||||
G_OBJECT_CLASS (pinos_link_parent_class)->dispose (object);
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ enum
|
|||
PROP_STATE,
|
||||
PROP_PROPERTIES,
|
||||
PROP_NODE,
|
||||
PROP_NODE_STATE,
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
@ -266,6 +267,10 @@ pinos_node_get_property (GObject *_object,
|
|||
g_value_set_pointer (value, node->node);
|
||||
break;
|
||||
|
||||
case PROP_NODE_STATE:
|
||||
g_value_set_uint (value, node->node_state);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (node, prop_id, pspec);
|
||||
break;
|
||||
|
|
@ -496,6 +501,17 @@ pinos_node_class_init (PinosNodeClass * klass)
|
|||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_NODE_STATE,
|
||||
g_param_spec_uint ("node-state",
|
||||
"Node State",
|
||||
"The state of the SPA node",
|
||||
0,
|
||||
G_MAXUINT,
|
||||
SPA_NODE_STATE_INIT,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
|
|
@ -954,3 +970,24 @@ pinos_node_report_busy (PinosNode *node)
|
|||
g_debug ("node %p: report busy", node);
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_RUNNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_update_node_state:
|
||||
* @node: a #PinosNode
|
||||
* @state: a #SpaNodeState
|
||||
*
|
||||
* Update the state of a SPA node. This method is used from
|
||||
* inside @node itself.
|
||||
*/
|
||||
void
|
||||
pinos_node_update_node_state (PinosNode *node,
|
||||
SpaNodeState state)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
|
||||
if (node->node_state != state) {
|
||||
g_debug ("node %p: update SPA state to %d", node, state);
|
||||
node->node_state = state;
|
||||
g_object_notify (G_OBJECT (node), "node-state");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ struct _PinosNode {
|
|||
GObject object;
|
||||
|
||||
SpaNode *node;
|
||||
SpaNodeState node_state;
|
||||
|
||||
PinosNodePrivate *priv;
|
||||
};
|
||||
|
|
@ -111,6 +112,8 @@ void pinos_node_report_error (PinosNode *node, GError
|
|||
void pinos_node_report_idle (PinosNode *node);
|
||||
void pinos_node_report_busy (PinosNode *node);
|
||||
|
||||
void pinos_node_update_node_state (PinosNode *node, SpaNodeState state);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_NODE_H__ */
|
||||
|
|
|
|||
|
|
@ -55,6 +55,9 @@ struct _PinosPort {
|
|||
uint32_t id;
|
||||
PinosNode *node;
|
||||
|
||||
SpaBuffer **buffers;
|
||||
guint n_buffers;
|
||||
|
||||
PinosPortPrivate *priv;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue