From 49f9a055dc348d296cc8431059e2cb9c9110c069 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 21 Dec 2021 11:46:42 -0800 Subject: [PATCH] libobs: Fix destruction order for destruction task queue Destruction of the task queue should probably happen after the audio and video threads have been destroyed and all audio/video processing has stopped. --- libobs/obs-internal.h | 4 ++-- libobs/obs-source.c | 2 +- libobs/obs.c | 19 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 68ccd09a6..f95c30e26 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -364,8 +364,6 @@ struct obs_core_data { DARRAY(struct draw_callback) draw_callbacks; DARRAY(struct tick_callback) tick_callbacks; - os_task_queue_t *destruction_task_thread; - struct obs_view main_view; long long unnamed_index; @@ -439,6 +437,8 @@ struct obs_core { struct obs_core_data data; struct obs_core_hotkeys hotkeys; + os_task_queue_t *destruction_task_thread; + obs_task_handler_t ui_task_handler; }; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index d2f95c6d5..3c9bf64d5 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -635,7 +635,7 @@ void obs_source_destroy(struct obs_source *source) obs_context_data_remove(&source->context); /* defer source destroy */ - os_task_queue_queue_task(obs->data.destruction_task_thread, + os_task_queue_queue_task(obs->destruction_task_thread, (os_task_t)obs_source_destroy_defer, source); } diff --git a/libobs/obs.c b/libobs/obs.c index 5fc83dcac..fe325fca6 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -649,10 +649,6 @@ static bool obs_init_data(void) if (pthread_mutex_init_recursive(&obs->data.draw_callbacks_mutex) != 0) goto fail; - data->destruction_task_thread = os_task_queue_create(); - if (!data->destruction_task_thread) - goto fail; - if (!obs_view_init(&data->main_view)) goto fail; @@ -710,7 +706,6 @@ static void obs_free_data(void) pthread_mutex_destroy(&data->encoders_mutex); pthread_mutex_destroy(&data->services_mutex); pthread_mutex_destroy(&data->draw_callbacks_mutex); - os_task_queue_destroy(data->destruction_task_thread); da_free(data->draw_callbacks); da_free(data->tick_callbacks); obs_data_release(data->private_data); @@ -875,6 +870,10 @@ static bool obs_init(const char *locale, const char *module_config_path, if (!obs_init_hotkeys()) return false; + obs->destruction_task_thread = os_task_queue_create(); + if (!obs->destruction_task_thread) + return false; + if (module_config_path) obs->module_config_path = bstrdup(module_config_path); obs->locale = bstrdup(locale); @@ -1047,6 +1046,7 @@ void obs_shutdown(void) obs_free_data(); obs_free_audio(); obs_free_video(); + os_task_queue_destroy(obs->destruction_task_thread); obs_free_hotkeys(); obs_free_graphics(); proc_handler_destroy(obs->procs); @@ -2563,7 +2563,7 @@ bool obs_in_task_thread(enum obs_task_type type) else if (type == OBS_TASK_UI) return is_ui_thread; else if (type == OBS_TASK_DESTROY) - return os_task_queue_inside(obs->data.destruction_task_thread); + return os_task_queue_inside(obs->destruction_task_thread); assert(false); return false; @@ -2612,9 +2612,8 @@ void obs_queue_task(enum obs_task_type type, obs_task_t task, void *param, } else if (type == OBS_TASK_DESTROY) { os_task_t os_task = (os_task_t)task; - os_task_queue_queue_task( - obs->data.destruction_task_thread, os_task, - param); + os_task_queue_queue_task(obs->destruction_task_thread, + os_task, param); } } } @@ -2635,7 +2634,7 @@ bool obs_wait_for_destroy_queue(void) os_event_destroy(info.event); /* wait for destroy task queue */ - return os_task_queue_wait(obs->data.destruction_task_thread); + return os_task_queue_wait(obs->destruction_task_thread); } static void set_ui_thread(void *unused)