From 55101efdf3b4aefbf8e22e4805eee63c111c034c Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 18 Sep 2023 09:39:46 +0200 Subject: [PATCH] attempt to fix opus crash --- src/CSoundInput.cpp | 2 ++ src/CSoundInput.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/CSoundInput.cpp b/src/CSoundInput.cpp index bf64d86..361d7bc 100644 --- a/src/CSoundInput.cpp +++ b/src/CSoundInput.cpp @@ -15,6 +15,7 @@ CSoundInput::CSoundInput(int _bitRate) : encoder(new COpusEncoder(SAMPLE_RATE, A CSoundInput::~CSoundInput() { + std::unique_lock lock{ inputMutex }; delete encoder; delete opusBuffer; rnnoise_destroy(denoiser); @@ -203,6 +204,7 @@ void CSoundInput::SetNoiseSuppressionEnabled(const bool enabled) BOOL CSoundInput::OnSoundFrame(HRECORD handle, const void* buffer, DWORD length, void* user) { const auto self = static_cast(user); + std::unique_lock lock{ self->inputMutex }; for (int i = 0; i < length; i += (FRAME_SIZE_SAMPLES * sizeof(short))) { diff --git a/src/CSoundInput.h b/src/CSoundInput.h index 69311ce..5cffb5e 100644 --- a/src/CSoundInput.h +++ b/src/CSoundInput.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include "alt-voice.h" #include "ISoundInput.h" @@ -36,6 +37,8 @@ class CSoundInput : public ISoundInput bool recording = false; bool deviceLost = false; bool isDefault = true; + + std::mutex inputMutex; public: CSoundInput(int _bitRate); ~CSoundInput() override;