summaryrefslogtreecommitdiffstats
path: root/drivers/wasapi
diff options
context:
space:
mode:
authorLalit Shankar Chowdhury <lalitshankarch@gmail.com>2024-09-18 00:03:48 +0530
committerLalit Shankar Chowdhury <lalitshankarch@gmail.com>2024-09-18 00:03:48 +0530
commit0e23c5fc9f64fb8e15d7362dfd7d7db2844e4dd7 (patch)
treee4928444ab640f6cb8286b9d411781be70026b5c /drivers/wasapi
parent6681f2563b99e14929a8acb27f4908fece398ef1 (diff)
downloadredot-engine-0e23c5fc9f64fb8e15d7362dfd7d7db2844e4dd7.tar.gz
Fix `AudioStreamMicrophone` crash on scene-reload
Diffstat (limited to 'drivers/wasapi')
-rw-r--r--drivers/wasapi/audio_driver_wasapi.cpp19
-rw-r--r--drivers/wasapi/audio_driver_wasapi.h9
2 files changed, 17 insertions, 11 deletions
diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp
index a349a66f75..4e7c9695a5 100644
--- a/drivers/wasapi/audio_driver_wasapi.cpp
+++ b/drivers/wasapi/audio_driver_wasapi.cpp
@@ -39,6 +39,9 @@
#include <functiondiscoverykeys.h>
+#include <wrl/client.h>
+using Microsoft::WRL::ComPtr;
+
// Define IAudioClient3 if not already defined by MinGW headers
#if defined __MINGW32__ || defined __MINGW64__
@@ -107,6 +110,12 @@ const IID IID_IAudioClient3 = __uuidof(IAudioClient3);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
+#define SAFE_RELEASE(memory) \
+ if ((memory) != nullptr) { \
+ (memory)->Release(); \
+ (memory) = nullptr; \
+ }
+
#define REFTIMES_PER_SEC 10000000
#define REFTIMES_PER_MILLISEC 10000
@@ -302,7 +311,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_i
audioProps.bIsOffload = FALSE;
audioProps.eCategory = AudioCategory_GameEffects;
- hr = ((IAudioClient3 *)p_device->audio_client.Get())->SetClientProperties(&audioProps);
+ hr = ((IAudioClient3 *)p_device->audio_client)->SetClientProperties(&audioProps);
ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: SetClientProperties failed with error 0x" + String::num_uint64(hr, 16) + ".");
}
@@ -385,7 +394,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_i
}
} else {
- IAudioClient3 *device_audio_client_3 = (IAudioClient3 *)p_device->audio_client.Get();
+ IAudioClient3 *device_audio_client_3 = (IAudioClient3 *)p_device->audio_client;
// AUDCLNT_STREAMFLAGS_RATEADJUST is an invalid flag with IAudioClient3, therefore we have to use
// the closest supported mix rate supported by the audio driver.
@@ -516,9 +525,9 @@ Error AudioDriverWASAPI::audio_device_finish(AudioDeviceWASAPI *p_device) {
p_device->active.clear();
}
- p_device->audio_client.Reset();
- p_device->render_client.Reset();
- p_device->capture_client.Reset();
+ SAFE_RELEASE(p_device->audio_client)
+ SAFE_RELEASE(p_device->render_client)
+ SAFE_RELEASE(p_device->capture_client)
return OK;
}
diff --git a/drivers/wasapi/audio_driver_wasapi.h b/drivers/wasapi/audio_driver_wasapi.h
index d73cbf4a8a..367c30607a 100644
--- a/drivers/wasapi/audio_driver_wasapi.h
+++ b/drivers/wasapi/audio_driver_wasapi.h
@@ -40,18 +40,15 @@
#include <audioclient.h>
#include <mmdeviceapi.h>
-#include <wrl/client.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-using Microsoft::WRL::ComPtr;
-
class AudioDriverWASAPI : public AudioDriver {
class AudioDeviceWASAPI {
public:
- ComPtr<IAudioClient> audio_client = nullptr;
- ComPtr<IAudioRenderClient> render_client = nullptr; // Output
- ComPtr<IAudioCaptureClient> capture_client = nullptr; // Input
+ IAudioClient *audio_client = nullptr;
+ IAudioRenderClient *render_client = nullptr; // Output
+ IAudioCaptureClient *capture_client = nullptr; // Input
SafeFlag active;
WORD format_tag = 0;