diff options
author | Wim Taymans <wtaymans@redhat.com> | 2019-09-09 17:17:03 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2019-09-09 17:17:03 +0200 |
commit | 9c9bff8fe915e6e45e4a23b943b0242c69501ef1 (patch) | |
tree | 8a0091e5693a05b166a2fca36205348c39c8470a /src | |
parent | 3340f3cacc056ad51d5a601da94b431c2c108e54 (diff) |
data-loop: add _wait function
Add function to wait for one iteration of the loop. This can be used
by specialized implementations of the data loop, like jack.
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/module-client-node/client-node.c | 6 | ||||
-rw-r--r-- | src/pipewire/data-loop.c | 37 | ||||
-rw-r--r-- | src/pipewire/data-loop.h | 7 |
3 files changed, 45 insertions, 5 deletions
diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index 4d773ea9..f8017c04 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -1254,8 +1254,8 @@ static void node_initialized(void *data) struct spa_system *data_system = impl->node.data_system; size_t size; - impl->fds[0] = spa_system_eventfd_create(data_system, SPA_FD_CLOEXEC); - impl->fds[1] = spa_system_eventfd_create(data_system, SPA_FD_CLOEXEC); + impl->fds[0] = spa_system_eventfd_create(data_system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); + impl->fds[1] = spa_system_eventfd_create(data_system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); impl->other_fds[0] = impl->fds[1]; impl->other_fds[1] = impl->fds[0]; node->data_source.fd = impl->fds[0]; @@ -1537,7 +1537,7 @@ static void node_peer_added(void *data, struct pw_node *peer) pw_log_debug(NAME " %p: can't ensure mem: %m", this); return; } - pw_log_debug(NAME " %p: peer %p %u added %u", &impl->this, peer, + pw_log_debug(NAME " %p: peer %p id:%u added mem_id:%u", &impl->this, peer, peer->info.id, m->id); if (this->resource == NULL) diff --git a/src/pipewire/data-loop.c b/src/pipewire/data-loop.c index 7641c220..50adb327 100644 --- a/src/pipewire/data-loop.c +++ b/src/pipewire/data-loop.c @@ -32,6 +32,29 @@ #define NAME "data-loop" +SPA_EXPORT +int pw_data_loop_wait(struct pw_data_loop *this, int timeout) +{ + int res; + + while (true) { + if (!this->running) + return -ECANCELED; + if ((res = pw_loop_iterate(this->loop, timeout)) < 0) { + if (errno == EINTR) + continue; + } + break; + } + return res; +} + +SPA_EXPORT +void pw_data_loop_exit(struct pw_data_loop *this) +{ + this->running = false; +} + static void *do_loop(void *user_data) { struct pw_data_loop *this = user_data; @@ -41,10 +64,14 @@ static void *do_loop(void *user_data) pw_loop_enter(this->loop); while (this->running) { - if ((res = pw_loop_iterate(this->loop, -1)) < 0) - pw_log_warn(NAME" %p: iterate error %d (%s)", + if ((res = pw_loop_iterate(this->loop, -1)) < 0) { + if (errno == EINTR) + continue; + pw_log_error(NAME" %p: iterate error %d (%s)", this, res, spa_strerror(res)); + } } + pw_log_debug(NAME" %p: leave thread", this); pw_loop_leave(this->loop); @@ -64,6 +91,7 @@ static void do_stop(void *data, uint64_t count) * * \memberof pw_data_loop */ +SPA_EXPORT struct pw_data_loop *pw_data_loop_new(struct pw_properties *properties) { struct pw_data_loop *this; @@ -111,6 +139,7 @@ error_cleanup: * \param loop the data loop to destroy * \memberof pw_data_loop */ +SPA_EXPORT void pw_data_loop_destroy(struct pw_data_loop *loop) { pw_log_debug(NAME" %p: destroy", loop); @@ -124,6 +153,7 @@ void pw_data_loop_destroy(struct pw_data_loop *loop) free(loop); } +SPA_EXPORT void pw_data_loop_add_listener(struct pw_data_loop *loop, struct spa_hook *listener, const struct pw_data_loop_events *events, @@ -146,6 +176,7 @@ pw_data_loop_get_loop(struct pw_data_loop *loop) * * \memberof pw_data_loop */ +SPA_EXPORT int pw_data_loop_start(struct pw_data_loop *loop) { if (!loop->running) { @@ -169,6 +200,7 @@ int pw_data_loop_start(struct pw_data_loop *loop) * * \memberof pw_data_loop */ +SPA_EXPORT int pw_data_loop_stop(struct pw_data_loop *loop) { if (loop->running) { @@ -185,6 +217,7 @@ int pw_data_loop_stop(struct pw_data_loop *loop) * * \memberof pw_data_loop */ +SPA_EXPORT bool pw_data_loop_in_thread(struct pw_data_loop * loop) { return pthread_equal(loop->thread, pthread_self()); diff --git a/src/pipewire/data-loop.h b/src/pipewire/data-loop.h index d01188df..f85b7151 100644 --- a/src/pipewire/data-loop.h +++ b/src/pipewire/data-loop.h @@ -59,6 +59,13 @@ void pw_data_loop_add_listener(struct pw_data_loop *loop, const struct pw_data_loop_events *events, void *data); +/** wait for activity on the loop up to \a timeout milliseconds. + * Should be called from the loop function */ +int pw_data_loop_wait(struct pw_data_loop *loop, int timeout); + +/** make sure the thread will exit. Can be called from a loop callback */ +void pw_data_loop_exit(struct pw_data_loop *loop); + /** Get the loop implementation of this data loop */ struct pw_loop * pw_data_loop_get_loop(struct pw_data_loop *loop); |