diff options
Diffstat (limited to 'src/audio_core')
| -rw-r--r-- | src/audio_core/sink/sink_details.cpp | 34 | ||||
| -rw-r--r-- | src/audio_core/sink/sink_details.h | 8 |
2 files changed, 23 insertions, 19 deletions
diff --git a/src/audio_core/sink/sink_details.cpp b/src/audio_core/sink/sink_details.cpp index 39ea6d91b..027bfa517 100644 --- a/src/audio_core/sink/sink_details.cpp +++ b/src/audio_core/sink/sink_details.cpp | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #endif | 15 | #endif |
| 16 | #include "audio_core/sink/null_sink.h" | 16 | #include "audio_core/sink/null_sink.h" |
| 17 | #include "common/logging/log.h" | 17 | #include "common/logging/log.h" |
| 18 | #include "common/settings_enums.h" | ||
| 18 | 19 | ||
| 19 | namespace AudioCore::Sink { | 20 | namespace AudioCore::Sink { |
| 20 | namespace { | 21 | namespace { |
| @@ -24,7 +25,7 @@ struct SinkDetails { | |||
| 24 | using LatencyFn = u32 (*)(); | 25 | using LatencyFn = u32 (*)(); |
| 25 | 26 | ||
| 26 | /// Name for this sink. | 27 | /// Name for this sink. |
| 27 | std::string_view id; | 28 | Settings::AudioEngine id; |
| 28 | /// A method to call to construct an instance of this type of sink. | 29 | /// A method to call to construct an instance of this type of sink. |
| 29 | FactoryFn factory; | 30 | FactoryFn factory; |
| 30 | /// A method to call to list available devices. | 31 | /// A method to call to list available devices. |
| @@ -37,7 +38,7 @@ struct SinkDetails { | |||
| 37 | constexpr SinkDetails sink_details[] = { | 38 | constexpr SinkDetails sink_details[] = { |
| 38 | #ifdef HAVE_CUBEB | 39 | #ifdef HAVE_CUBEB |
| 39 | SinkDetails{ | 40 | SinkDetails{ |
| 40 | "cubeb", | 41 | Settings::AudioEngine::Cubeb, |
| 41 | [](std::string_view device_id) -> std::unique_ptr<Sink> { | 42 | [](std::string_view device_id) -> std::unique_ptr<Sink> { |
| 42 | return std::make_unique<CubebSink>(device_id); | 43 | return std::make_unique<CubebSink>(device_id); |
| 43 | }, | 44 | }, |
| @@ -47,7 +48,7 @@ constexpr SinkDetails sink_details[] = { | |||
| 47 | #endif | 48 | #endif |
| 48 | #ifdef HAVE_SDL2 | 49 | #ifdef HAVE_SDL2 |
| 49 | SinkDetails{ | 50 | SinkDetails{ |
| 50 | "sdl2", | 51 | Settings::AudioEngine::Sdl2, |
| 51 | [](std::string_view device_id) -> std::unique_ptr<Sink> { | 52 | [](std::string_view device_id) -> std::unique_ptr<Sink> { |
| 52 | return std::make_unique<SDLSink>(device_id); | 53 | return std::make_unique<SDLSink>(device_id); |
| 53 | }, | 54 | }, |
| @@ -55,46 +56,47 @@ constexpr SinkDetails sink_details[] = { | |||
| 55 | &GetSDLLatency, | 56 | &GetSDLLatency, |
| 56 | }, | 57 | }, |
| 57 | #endif | 58 | #endif |
| 58 | SinkDetails{"null", | 59 | SinkDetails{Settings::AudioEngine::Null, |
| 59 | [](std::string_view device_id) -> std::unique_ptr<Sink> { | 60 | [](std::string_view device_id) -> std::unique_ptr<Sink> { |
| 60 | return std::make_unique<NullSink>(device_id); | 61 | return std::make_unique<NullSink>(device_id); |
| 61 | }, | 62 | }, |
| 62 | [](bool capture) { return std::vector<std::string>{"null"}; }, []() { return 0u; }}, | 63 | [](bool capture) { return std::vector<std::string>{"null"}; }, []() { return 0u; }}, |
| 63 | }; | 64 | }; |
| 64 | 65 | ||
| 65 | const SinkDetails& GetOutputSinkDetails(std::string_view sink_id) { | 66 | const SinkDetails& GetOutputSinkDetails(Settings::AudioEngine sink_id) { |
| 66 | const auto find_backend{[](std::string_view id) { | 67 | const auto find_backend{[](Settings::AudioEngine id) { |
| 67 | return std::find_if(std::begin(sink_details), std::end(sink_details), | 68 | return std::find_if(std::begin(sink_details), std::end(sink_details), |
| 68 | [&id](const auto& sink_detail) { return sink_detail.id == id; }); | 69 | [&id](const auto& sink_detail) { return sink_detail.id == id; }); |
| 69 | }}; | 70 | }}; |
| 70 | 71 | ||
| 71 | auto iter = find_backend(sink_id); | 72 | auto iter = find_backend(sink_id); |
| 72 | 73 | ||
| 73 | if (sink_id == "auto") { | 74 | if (sink_id == Settings::AudioEngine::Auto) { |
| 74 | // Auto-select a backend. Prefer CubeB, but it may report a large minimum latency which | 75 | // Auto-select a backend. Prefer CubeB, but it may report a large minimum latency which |
| 75 | // causes audio issues, in that case go with SDL. | 76 | // causes audio issues, in that case go with SDL. |
| 76 | #if defined(HAVE_CUBEB) && defined(HAVE_SDL2) | 77 | #if defined(HAVE_CUBEB) && defined(HAVE_SDL2) |
| 77 | iter = find_backend("cubeb"); | 78 | iter = find_backend(Settings::AudioEngine::Cubeb); |
| 78 | if (iter->latency() > TargetSampleCount * 3) { | 79 | if (iter->latency() > TargetSampleCount * 3) { |
| 79 | iter = find_backend("sdl2"); | 80 | iter = find_backend(Settings::AudioEngine::Sdl2); |
| 80 | } | 81 | } |
| 81 | #else | 82 | #else |
| 82 | iter = std::begin(sink_details); | 83 | iter = std::begin(sink_details); |
| 83 | #endif | 84 | #endif |
| 84 | LOG_INFO(Service_Audio, "Auto-selecting the {} backend", iter->id); | 85 | LOG_INFO(Service_Audio, "Auto-selecting the {} backend", |
| 86 | Settings::CanonicalizeEnum(iter->id)); | ||
| 85 | } | 87 | } |
| 86 | 88 | ||
| 87 | if (iter == std::end(sink_details)) { | 89 | if (iter == std::end(sink_details)) { |
| 88 | LOG_ERROR(Audio, "Invalid sink_id {}", sink_id); | 90 | LOG_ERROR(Audio, "Invalid sink_id {}", Settings::CanonicalizeEnum(sink_id)); |
| 89 | iter = find_backend("null"); | 91 | iter = find_backend(Settings::AudioEngine::Null); |
| 90 | } | 92 | } |
| 91 | 93 | ||
| 92 | return *iter; | 94 | return *iter; |
| 93 | } | 95 | } |
| 94 | } // Anonymous namespace | 96 | } // Anonymous namespace |
| 95 | 97 | ||
| 96 | std::vector<std::string_view> GetSinkIDs() { | 98 | std::vector<Settings::AudioEngine> GetSinkIDs() { |
| 97 | std::vector<std::string_view> sink_ids(std::size(sink_details)); | 99 | std::vector<Settings::AudioEngine> sink_ids(std::size(sink_details)); |
| 98 | 100 | ||
| 99 | std::transform(std::begin(sink_details), std::end(sink_details), std::begin(sink_ids), | 101 | std::transform(std::begin(sink_details), std::end(sink_details), std::begin(sink_ids), |
| 100 | [](const auto& sink) { return sink.id; }); | 102 | [](const auto& sink) { return sink.id; }); |
| @@ -102,11 +104,11 @@ std::vector<std::string_view> GetSinkIDs() { | |||
| 102 | return sink_ids; | 104 | return sink_ids; |
| 103 | } | 105 | } |
| 104 | 106 | ||
| 105 | std::vector<std::string> GetDeviceListForSink(std::string_view sink_id, bool capture) { | 107 | std::vector<std::string> GetDeviceListForSink(Settings::AudioEngine sink_id, bool capture) { |
| 106 | return GetOutputSinkDetails(sink_id).list_devices(capture); | 108 | return GetOutputSinkDetails(sink_id).list_devices(capture); |
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | std::unique_ptr<Sink> CreateSinkFromID(std::string_view sink_id, std::string_view device_id) { | 111 | std::unique_ptr<Sink> CreateSinkFromID(Settings::AudioEngine sink_id, std::string_view device_id) { |
| 110 | return GetOutputSinkDetails(sink_id).factory(device_id); | 112 | return GetOutputSinkDetails(sink_id).factory(device_id); |
| 111 | } | 113 | } |
| 112 | 114 | ||
diff --git a/src/audio_core/sink/sink_details.h b/src/audio_core/sink/sink_details.h index e75932898..c8498842b 100644 --- a/src/audio_core/sink/sink_details.h +++ b/src/audio_core/sink/sink_details.h | |||
| @@ -3,9 +3,11 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <memory> | ||
| 6 | #include <string> | 7 | #include <string> |
| 7 | #include <string_view> | 8 | #include <string_view> |
| 8 | #include <vector> | 9 | #include <vector> |
| 10 | #include "common/settings_enums.h" | ||
| 9 | 11 | ||
| 10 | namespace AudioCore { | 12 | namespace AudioCore { |
| 11 | class AudioManager; | 13 | class AudioManager; |
| @@ -19,7 +21,7 @@ class Sink; | |||
| 19 | * | 21 | * |
| 20 | * @return Vector of available sink names. | 22 | * @return Vector of available sink names. |
| 21 | */ | 23 | */ |
| 22 | std::vector<std::string_view> GetSinkIDs(); | 24 | std::vector<Settings::AudioEngine> GetSinkIDs(); |
| 23 | 25 | ||
| 24 | /** | 26 | /** |
| 25 | * Gets the list of devices for a particular sink identified by the given ID. | 27 | * Gets the list of devices for a particular sink identified by the given ID. |
| @@ -28,7 +30,7 @@ std::vector<std::string_view> GetSinkIDs(); | |||
| 28 | * @param capture - Get capture (input) devices, or output devices? | 30 | * @param capture - Get capture (input) devices, or output devices? |
| 29 | * @return Vector of device names. | 31 | * @return Vector of device names. |
| 30 | */ | 32 | */ |
| 31 | std::vector<std::string> GetDeviceListForSink(std::string_view sink_id, bool capture); | 33 | std::vector<std::string> GetDeviceListForSink(Settings::AudioEngine sink_id, bool capture); |
| 32 | 34 | ||
| 33 | /** | 35 | /** |
| 34 | * Creates an audio sink identified by the given device ID. | 36 | * Creates an audio sink identified by the given device ID. |
| @@ -37,7 +39,7 @@ std::vector<std::string> GetDeviceListForSink(std::string_view sink_id, bool cap | |||
| 37 | * @param device_id - Name of the device to create. | 39 | * @param device_id - Name of the device to create. |
| 38 | * @return Pointer to the created sink. | 40 | * @return Pointer to the created sink. |
| 39 | */ | 41 | */ |
| 40 | std::unique_ptr<Sink> CreateSinkFromID(std::string_view sink_id, std::string_view device_id); | 42 | std::unique_ptr<Sink> CreateSinkFromID(Settings::AudioEngine sink_id, std::string_view device_id); |
| 41 | 43 | ||
| 42 | } // namespace Sink | 44 | } // namespace Sink |
| 43 | } // namespace AudioCore | 45 | } // namespace AudioCore |