From 6ccff434f7e8b0811107a0e688d309110aa9e866 Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Wed, 23 Aug 2023 14:26:07 +0300 Subject: [PATCH] swap thread --- src/transcription-filter.cpp | 4 +++- src/whisper-processing.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/transcription-filter.cpp b/src/transcription-filter.cpp index 5770352..ccf7079 100644 --- a/src/transcription-filter.cpp +++ b/src/transcription-filter.cpp @@ -399,10 +399,12 @@ void *transcription_filter_create(obs_data_t *settings, obs_source_t *filter) obs_log(LOG_INFO, "transcription_filter: start whisper thread"); // start the thread - gf->whisper_thread = std::thread(whisper_loop, gf); + std::thread new_whisper_thread(whisper_loop, gf); + gf->whisper_thread.swap(new_whisper_thread); gf->active = true; + obs_log(LOG_INFO, "transcription_filter: filter created."); return gf; } diff --git a/src/whisper-processing.cpp b/src/whisper-processing.cpp index 69bbfb8..be21906 100644 --- a/src/whisper-processing.cpp +++ b/src/whisper-processing.cpp @@ -297,6 +297,11 @@ void process_audio_from_buffer(struct transcription_filter_data *gf) void whisper_loop(void *data) { + if (data == nullptr) { + obs_log(LOG_ERROR, "whisper_loop: data is null"); + return; + } + struct transcription_filter_data *gf = static_cast(data); const size_t segment_size = gf->frames * sizeof(float);