mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-01-15 19:35:26 +00:00
cubeb_audio: Make sure COM is initialized on Windows. (#1958)
This commit is contained in:
parent
4b2db61120
commit
f8177902a5
|
@ -34,6 +34,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cubeb* ctx = nullptr;
|
cubeb* ctx = nullptr;
|
||||||
|
#ifdef _WIN32
|
||||||
|
bool owns_com = false;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
class SDLAudioOut final : public AudioOutBackend {
|
class SDLAudioOut final : public AudioOutBackend {
|
||||||
|
|
|
@ -10,9 +10,11 @@
|
||||||
#include "core/libraries/audio/audioout.h"
|
#include "core/libraries/audio/audioout.h"
|
||||||
#include "core/libraries/audio/audioout_backend.h"
|
#include "core/libraries/audio/audioout_backend.h"
|
||||||
|
|
||||||
namespace Libraries::AudioOut {
|
#ifdef _WIN32
|
||||||
|
#include <Objbase.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
constexpr int AUDIO_STREAM_BUFFER_THRESHOLD = 65536; // Define constant for buffer threshold
|
namespace Libraries::AudioOut {
|
||||||
|
|
||||||
class CubebPortBackend : public PortBackend {
|
class CubebPortBackend : public PortBackend {
|
||||||
public:
|
public:
|
||||||
|
@ -143,17 +145,26 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
CubebAudioOut::CubebAudioOut() {
|
CubebAudioOut::CubebAudioOut() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Need to initialize COM for this thread on Windows, in case WASAPI backend is used.
|
||||||
|
owns_com = CoInitializeEx(nullptr, COINIT_MULTITHREADED) == S_OK;
|
||||||
|
#endif
|
||||||
if (const auto ret = cubeb_init(&ctx, "shadPS4", nullptr); ret != CUBEB_OK) {
|
if (const auto ret = cubeb_init(&ctx, "shadPS4", nullptr); ret != CUBEB_OK) {
|
||||||
LOG_CRITICAL(Lib_AudioOut, "Failed to create cubeb context: {}", ret);
|
LOG_CRITICAL(Lib_AudioOut, "Failed to create cubeb context: {}", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CubebAudioOut::~CubebAudioOut() {
|
CubebAudioOut::~CubebAudioOut() {
|
||||||
if (!ctx) {
|
if (ctx) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
cubeb_destroy(ctx);
|
cubeb_destroy(ctx);
|
||||||
ctx = nullptr;
|
ctx = nullptr;
|
||||||
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (owns_com) {
|
||||||
|
CoUninitialize();
|
||||||
|
owns_com = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<PortBackend> CubebAudioOut::Open(PortOut& port) {
|
std::unique_ptr<PortBackend> CubebAudioOut::Open(PortOut& port) {
|
||||||
|
|
Loading…
Reference in a new issue