summaryrefslogtreecommitdiffstats
path: root/src/audio_core/sink/cubeb_sink.cpp
diff options
context:
space:
mode:
authorKelebek1 <eeeedddccc@hotmail.co.uk>2023-08-23 08:14:40 +0200
committerKelebek1 <eeeedddccc@hotmail.co.uk>2023-08-23 09:33:26 +0200
commit39c8ddcda281e5f5b125c78b55741e39a50ff254 (patch)
treeca88e6666c76d755015945c1f5f228edb47287ef /src/audio_core/sink/cubeb_sink.cpp
parentMerge pull request #11302 from vonchenplus/vulkan_macos (diff)
downloadyuzu-39c8ddcda281e5f5b125c78b55741e39a50ff254.tar
yuzu-39c8ddcda281e5f5b125c78b55741e39a50ff254.tar.gz
yuzu-39c8ddcda281e5f5b125c78b55741e39a50ff254.tar.bz2
yuzu-39c8ddcda281e5f5b125c78b55741e39a50ff254.tar.lz
yuzu-39c8ddcda281e5f5b125c78b55741e39a50ff254.tar.xz
yuzu-39c8ddcda281e5f5b125c78b55741e39a50ff254.tar.zst
yuzu-39c8ddcda281e5f5b125c78b55741e39a50ff254.zip
Diffstat (limited to 'src/audio_core/sink/cubeb_sink.cpp')
-rw-r--r--src/audio_core/sink/cubeb_sink.cpp52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/audio_core/sink/cubeb_sink.cpp b/src/audio_core/sink/cubeb_sink.cpp
index 9a0801888..04d98a865 100644
--- a/src/audio_core/sink/cubeb_sink.cpp
+++ b/src/audio_core/sink/cubeb_sink.cpp
@@ -8,6 +8,7 @@
#include "audio_core/sink/cubeb_sink.h"
#include "audio_core/sink/sink_stream.h"
#include "common/logging/log.h"
+#include "common/scope_exit.h"
#include "core/core.h"
#ifdef _WIN32
@@ -332,25 +333,38 @@ std::vector<std::string> ListCubebSinkDevices(bool capture) {
return device_list;
}
-u32 GetCubebLatency() {
- cubeb* ctx;
+namespace {
+static long TmpDataCallback(cubeb_stream*, void*, const void*, void*, long) {
+ return TargetSampleCount;
+}
+static void TmpStateCallback(cubeb_stream*, void*, cubeb_state) {}
+} // namespace
+
+bool IsCubebSuitable() {
+#if !defined(HAVE_CUBEB)
+ return false;
+#else
+ cubeb* ctx{nullptr};
#ifdef _WIN32
auto com_init_result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
#endif
+ // Init cubeb
if (cubeb_init(&ctx, "yuzu Latency Getter", nullptr) != CUBEB_OK) {
- LOG_CRITICAL(Audio_Sink, "cubeb_init failed");
- // Return a large latency so we choose SDL instead.
- return 10000u;
+ LOG_ERROR(Audio_Sink, "Cubeb failed to init, it is not suitable.");
+ return false;
}
+ SCOPE_EXIT({ cubeb_destroy(ctx); });
+
#ifdef _WIN32
if (SUCCEEDED(com_init_result)) {
CoUninitialize();
}
#endif
+ // Test min latency
cubeb_stream_params params{};
params.rate = TargetSampleRate;
params.channels = 2;
@@ -361,12 +375,32 @@ u32 GetCubebLatency() {
u32 latency{0};
const auto latency_error = cubeb_get_min_latency(ctx, &params, &latency);
if (latency_error != CUBEB_OK) {
- LOG_CRITICAL(Audio_Sink, "Error getting minimum latency, error: {}", latency_error);
- latency = TargetSampleCount * 2;
+ LOG_ERROR(Audio_Sink, "Cubeb could not get min latency, it is not suitable.");
+ return false;
}
latency = std::max(latency, TargetSampleCount * 2);
- cubeb_destroy(ctx);
- return latency;
+
+ if (latency > TargetSampleCount * 3) {
+ LOG_ERROR(Audio_Sink, "Cubeb latency is too high, it is not suitable.");
+ return false;
+ }
+
+ // Test opening a device with standard parameters
+ cubeb_devid output_device{0};
+ cubeb_devid input_device{0};
+ std::string name{"Yuzu test"};
+ cubeb_stream* stream{nullptr};
+
+ if (cubeb_stream_init(ctx, &stream, name.c_str(), input_device, nullptr, output_device, &params,
+ latency, &TmpDataCallback, &TmpStateCallback, nullptr) != CUBEB_OK) {
+ LOG_CRITICAL(Audio_Sink, "Cubeb could not open a device, it is not suitable.");
+ return false;
+ }
+
+ cubeb_stream_stop(stream);
+ cubeb_stream_destroy(stream);
+ return true;
+#endif
}
} // namespace AudioCore::Sink