From 0a3d44ac5330e25a132a9a1146b82df2ff998f7a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 21 Apr 2021 12:12:30 +0200 Subject: [PATCH] context: add method to get a work_queue Make a method to get a work-queue from the context. There is one work-queue to use and the context will allocate it when requested and free when destroyed. The work queue is handy to delay execution of some logic for later, either in the next iteration of the main-loop or when an async operation completed. Export some work-queue methods. --- src/pipewire/context.c | 11 +++++++++++ src/pipewire/context.h | 3 +++ src/pipewire/private.h | 9 +++++---- src/pipewire/work-queue.c | 3 +++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/pipewire/context.c b/src/pipewire/context.c index 3105652df..144bedbc2 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -433,6 +433,9 @@ void pw_context_destroy(struct pw_context *context) pw_data_loop_destroy(context->data_loop_impl); + if (context->work_queue) + pw_work_queue_destroy(context->work_queue); + pw_properties_free(context->properties); pw_properties_free(context->conf); @@ -483,6 +486,14 @@ struct pw_loop *pw_context_get_main_loop(struct pw_context *context) return context->main_loop; } +SPA_EXPORT +struct pw_work_queue *pw_context_get_work_queue(struct pw_context *context) +{ + if (context->work_queue == NULL) + context->work_queue = pw_work_queue_new(context->main_loop); + return context->work_queue; +} + SPA_EXPORT const struct pw_properties *pw_context_get_properties(struct pw_context *context) { diff --git a/src/pipewire/context.h b/src/pipewire/context.h index 2add8056c..88c1ac1eb 100644 --- a/src/pipewire/context.h +++ b/src/pipewire/context.h @@ -141,6 +141,9 @@ const struct spa_support *pw_context_get_support(struct pw_context *context, uin /** get the context main loop */ struct pw_loop *pw_context_get_main_loop(struct pw_context *context); +/** Get the work queue from the context: Since 0.3.26 */ +struct pw_work_queue *pw_context_get_work_queue(struct pw_context *context); + /** Iterate the globals of the context. The callback should return * 0 to fetch the next item, any other value stops the iteration and returns * the value. When all callbacks return 0, this function returns 0 when all diff --git a/src/pipewire/private.h b/src/pipewire/private.h index e6b6788aa..0bb667f7c 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -401,10 +401,11 @@ struct pw_context { struct spa_hook_list driver_listener_list; struct spa_hook_list listener_list; - struct pw_loop *main_loop; /**< main loop for control */ - struct pw_loop *data_loop; /**< data loop for data passing */ - struct pw_data_loop *data_loop_impl; - struct spa_system *data_system; /**< data system for data passing */ + struct pw_loop *main_loop; /**< main loop for control */ + struct pw_loop *data_loop; /**< data loop for data passing */ + struct pw_data_loop *data_loop_impl; + struct spa_system *data_system; /**< data system for data passing */ + struct pw_work_queue *work_queue; /**< work queue */ struct spa_support support[16]; /**< support for spa plugins */ uint32_t n_support; /**< number of support items */ diff --git a/src/pipewire/work-queue.c b/src/pipewire/work-queue.c index cf3cb6d2d..8e02a058d 100644 --- a/src/pipewire/work-queue.c +++ b/src/pipewire/work-queue.c @@ -160,6 +160,7 @@ void pw_work_queue_destroy(struct pw_work_queue *queue) * * \memberof pw_work_queue */ +SPA_EXPORT uint32_t pw_work_queue_add(struct pw_work_queue *queue, void *obj, int res, pw_work_func_t func, void *data) { @@ -215,6 +216,7 @@ pw_work_queue_add(struct pw_work_queue *queue, void *obj, int res, pw_work_func_ * * \memberof pw_work_queue */ +SPA_EXPORT int pw_work_queue_cancel(struct pw_work_queue *queue, void *obj, uint32_t id) { bool have_work = false; @@ -246,6 +248,7 @@ int pw_work_queue_cancel(struct pw_work_queue *queue, void *obj, uint32_t id) * * \memberof pw_work_queue */ +SPA_EXPORT int pw_work_queue_complete(struct pw_work_queue *queue, void *obj, uint32_t seq, int res) { struct work_item *item;