context: support foreign mainloop_api

Detect if the mainloop_api is one of ours and use the loop directly in
that case. Otherwise, make a new loop and add the fd to the foreign
mainloop_api. Make sure we clean up as well.

Fixes #345
This commit is contained in:
Wim Taymans 2020-10-22 12:24:49 +02:00
parent 7782352e8d
commit 55b4042512
3 changed files with 51 additions and 5 deletions

View file

@ -272,6 +272,8 @@ pa_mainloop *pa_mainloop_new(void)
loop->api = api;
loop->api.userdata = loop->loop;
pw_log_debug("%p: %p fd:%d", loop, loop->loop, loop->fd);
return loop;
no_loop:
@ -279,9 +281,15 @@ pa_mainloop *pa_mainloop_new(void)
return NULL;
}
bool pa_mainloop_api_is_pipewire(pa_mainloop_api *api)
{
return api && api->io_new == api_io_new;
}
SPA_EXPORT
void pa_mainloop_free(pa_mainloop* m)
{
pw_log_debug("%p", m);
pw_loop_destroy(m->loop);
free(m);
}