Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/libremidi/backends/pipewire/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ struct pipewire_context

// Add a manual 1ms event loop iteration at the end of
// ctor to ensure synchronous clients will still see the ports
pw_loop_enter(this->lp);
pw_loop_iterate(this->lp, 1);
pw_loop_leave(this->lp);
}

void initialize_observation()
Expand Down
26 changes: 20 additions & 6 deletions include/libremidi/backends/pipewire/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,18 @@ struct pipewire_helpers
{
// Note: called from a std::jthread.
assert(this->global_context);
auto lp = this->global_context->lp;
if (!lp)
return;

if (int fd = this->global_context->get_fd(); fd != -1)
{
fds[0] = {.fd = fd, .events = POLLIN, .revents = 0};
current_state = poll_state::in_poll;

// pw_loop_iterate requires the loop to be entered first.
pw_loop_enter(lp);

for (;;)
{
if (int err = poll(fds, 2, -1); err < 0)
Expand All @@ -174,13 +181,10 @@ struct pipewire_helpers
// Check pipewire fd:
if (fds[0].revents & POLLIN)
{
if (auto lp = this->global_context->lp)
int result = pw_loop_iterate(lp, 0);
if (result < 0)
{
int result = pw_loop_iterate(lp, 0);
if (result < 0)
{
LIBREMIDI_LOG(spa_strerror(result));
}
LIBREMIDI_LOG(spa_strerror(result));
}
fds[0].revents = 0;
}
Expand All @@ -191,6 +195,8 @@ struct pipewire_helpers
break;
}
}

pw_loop_leave(lp);
}
current_state = poll_state::not_in_poll;
}
Expand Down Expand Up @@ -347,7 +353,11 @@ struct pipewire_helpers
{
// Wait for the pipewire server to send us back our node's info
for (int i = 0; i < 1000; i++)
{
this->filter->synchronize_node();
if (this->filter->filter_node_id() != 4294967295)
break;
}

auto this_node = this->filter->filter_node_id();
auto& midi = this->global_context->current_graph.software_midi;
Expand Down Expand Up @@ -380,7 +390,11 @@ struct pipewire_helpers
{
// Wait for the pipewire server to send us back our node's info
for (int i = 0; i < 1000; i++)
{
this->filter->synchronize_node();
if (this->filter->filter_node_id() != 4294967295)
break;
}

auto this_node = this->filter->filter_node_id();
auto& midi = this->global_context->current_graph.software_midi;
Expand Down
Loading