mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-08 13:30:08 -05:00
node: improve callbacks
Make separate callbacks for events and RT notifications.
This commit is contained in:
parent
fb0919b8b7
commit
3b33e3d362
32 changed files with 557 additions and 481 deletions
|
|
@ -217,52 +217,61 @@ make_node (AppData *data, SpaNode **node, const char *lib, const char *name, boo
|
|||
|
||||
static void
|
||||
on_sink_event (SpaNode *node, SpaEvent *event, void *user_data)
|
||||
{
|
||||
printf ("got event %d\n", SPA_EVENT_TYPE (event));
|
||||
}
|
||||
|
||||
static void
|
||||
on_sink_need_input (SpaNode *node, void *user_data)
|
||||
{
|
||||
AppData *data = user_data;
|
||||
SpaResult res;
|
||||
|
||||
if (SPA_EVENT_TYPE (event) == data->type.event_node.NeedInput) {
|
||||
|
||||
res = spa_node_process_output (data->mix);
|
||||
|
||||
if (res == SPA_RESULT_NEED_BUFFER) {
|
||||
|
||||
if (data->source1_mix_io[0].status == SPA_RESULT_NEED_BUFFER) {
|
||||
res = spa_node_process_output (data->source1);
|
||||
if (res != SPA_RESULT_HAVE_BUFFER)
|
||||
printf ("got process_output error from source1 %d\n", res);
|
||||
}
|
||||
|
||||
if (data->source2_mix_io[0].status == SPA_RESULT_NEED_BUFFER) {
|
||||
res = spa_node_process_output (data->source2);
|
||||
if (res != SPA_RESULT_HAVE_BUFFER)
|
||||
printf ("got process_output error from source2 %d\n", res);
|
||||
}
|
||||
|
||||
res = spa_node_process_input (data->mix);
|
||||
if (res == SPA_RESULT_HAVE_BUFFER)
|
||||
goto push;
|
||||
else
|
||||
printf ("got process_input error from mixer %d\n", res);
|
||||
|
||||
} else if (res == SPA_RESULT_HAVE_BUFFER) {
|
||||
push:
|
||||
if ((res = spa_node_process_input (data->sink)) < 0)
|
||||
printf ("got process_input error from sink %d\n", res);
|
||||
} else {
|
||||
printf ("got process_output error from mixer %d\n", res);
|
||||
res = spa_node_process_output (data->mix);
|
||||
if (res == SPA_RESULT_NEED_BUFFER) {
|
||||
if (data->source1_mix_io[0].status == SPA_RESULT_NEED_BUFFER) {
|
||||
res = spa_node_process_output (data->source1);
|
||||
if (res != SPA_RESULT_HAVE_BUFFER)
|
||||
printf ("got process_output error from source1 %d\n", res);
|
||||
}
|
||||
}
|
||||
else if (SPA_EVENT_TYPE (event) == data->type.event_node.ReuseBuffer) {
|
||||
SpaEventNodeReuseBuffer *rb = (SpaEventNodeReuseBuffer *) event;
|
||||
|
||||
data->mix_sink_io[0].buffer_id = rb->body.buffer_id.value;
|
||||
}
|
||||
else {
|
||||
printf ("got event %d\n", SPA_EVENT_TYPE (event));
|
||||
if (data->source2_mix_io[0].status == SPA_RESULT_NEED_BUFFER) {
|
||||
res = spa_node_process_output (data->source2);
|
||||
if (res != SPA_RESULT_HAVE_BUFFER)
|
||||
printf ("got process_output error from source2 %d\n", res);
|
||||
}
|
||||
|
||||
res = spa_node_process_input (data->mix);
|
||||
if (res == SPA_RESULT_HAVE_BUFFER)
|
||||
goto push;
|
||||
else
|
||||
printf ("got process_input error from mixer %d\n", res);
|
||||
|
||||
} else if (res == SPA_RESULT_HAVE_BUFFER) {
|
||||
push:
|
||||
if ((res = spa_node_process_input (data->sink)) < 0)
|
||||
printf ("got process_input error from sink %d\n", res);
|
||||
} else {
|
||||
printf ("got process_output error from mixer %d\n", res);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_sink_reuse_buffer (SpaNode *node, uint32_t port_id, uint32_t buffer_id, void *user_data)
|
||||
{
|
||||
AppData *data = user_data;
|
||||
|
||||
data->mix_sink_io[0].buffer_id = buffer_id;
|
||||
}
|
||||
|
||||
static const SpaNodeCallbacks sink_callbacks =
|
||||
{
|
||||
&on_sink_event,
|
||||
&on_sink_need_input,
|
||||
NULL,
|
||||
&on_sink_reuse_buffer
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
do_add_source (SpaLoop *loop,
|
||||
SpaSource *source)
|
||||
|
|
@ -313,7 +322,7 @@ make_nodes (AppData *data, const char *device)
|
|||
printf ("can't create alsa-sink: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
spa_node_set_event_callback (data->sink, on_sink_event, data);
|
||||
spa_node_set_callbacks (data->sink, &sink_callbacks, sizeof (sink_callbacks), data);
|
||||
|
||||
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
||||
spa_pod_builder_props (&b, &f[0], data->type.props,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue