summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2026-11-02 01:34:23 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2026-11-17 13:03:41 -0600
commita906348b9143610d958af908c2a1d4adcb86f810 (patch)
treeb5d1a85d404ae370f113fc5584655f10cde4ab2e /Source/Core
parent2e0a63c918aeec3d3a7ffe08cd41ec3ad45ea0f8 (diff)
CubebUtils: Add functions to get a list of supported backend names and the display name for a backend.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/AudioCommon/CubebUtils.cpp40
-rw-r--r--Source/Core/AudioCommon/CubebUtils.h3
2 files changed, 43 insertions, 0 deletions
diff --git a/Source/Core/AudioCommon/CubebUtils.cpp b/Source/Core/AudioCommon/CubebUtils.cpp
index b86283dcdf..feaa5f2392 100644
--- a/Source/Core/AudioCommon/CubebUtils.cpp
+++ b/Source/Core/AudioCommon/CubebUtils.cpp
@@ -10,6 +10,7 @@
#include "AudioCommon/AudioCommon.h"
#include "Common/Logging/Log.h"
#include "Common/Logging/LogManager.h"
+#include "Common/Projection.h"
#include "Common/StringUtil.h"
#include "Core/Config/MainSettings.h"
@@ -276,6 +277,45 @@ const void* GetOutputDeviceById(std::string_view id)
return device_id;
}
+std::vector<std::string_view> GetBackendNames()
+{
+ // Some tricks to only call `cubeb_get_backend_names` if it exists.
+ return [](auto... args) -> std::vector<std::string_view> {
+ if constexpr (requires { cubeb_get_backend_names(args...); })
+ {
+ const auto names = cubeb_get_backend_names(args...);
+ return {names.names, names.names + names.count};
+ }
+ else
+ { // The included version of Cubeb lacks the `cubeb_get_backend_names` function.
+ return {};
+ }
+ }();
+}
+
+std::string_view GetCubebBackendDisplayName(std::string_view backend_name)
+{
+ static constexpr std::pair<const char*, const char*> name_map[] = {
+ {"pulse", "PulseAudio"},
+ {"pulse-rust", "PulseAudio Rust"},
+ {"jack", "JACK"},
+ {"alsa", "ALSA"},
+ {"audiounit", "AudioUnit"},
+ {"audiounit-rust", "AudioUnit Rust"},
+ {"wasapi", "WASAPI"},
+ {"winmm", "WinMM"},
+ {"sun", "Sun"},
+ {"opensl", "OpenSL"},
+ {"oss", "OSS"},
+ {"aaudio", "AAudio"},
+ {"audiotrack", "AudioTrack"},
+ {"kai", "KAI"},
+ };
+
+ const auto it = std::ranges::find(name_map, backend_name, Common::Projection::First{});
+ return (it != std::end(name_map)) ? it->second : backend_name;
+}
+
CoInitSyncWorker::CoInitSyncWorker([[maybe_unused]] std::string worker_name)
#ifdef _WIN32
: m_work_queue{std::move(worker_name)}
diff --git a/Source/Core/AudioCommon/CubebUtils.h b/Source/Core/AudioCommon/CubebUtils.h
index 1e49b0c8bb..8324241869 100644
--- a/Source/Core/AudioCommon/CubebUtils.h
+++ b/Source/Core/AudioCommon/CubebUtils.h
@@ -24,6 +24,9 @@ const void* GetInputDeviceById(std::string_view id);
std::vector<std::pair<std::string, std::string>> ListOutputDevices();
const void* GetOutputDeviceById(std::string_view id);
+std::vector<std::string_view> GetBackendNames();
+std::string_view GetCubebBackendDisplayName(std::string_view backend_name);
+
// Helper used to handle Windows COM library for cubeb WASAPI backend
class CoInitSyncWorker
{