summaryrefslogtreecommitdiff
path: root/src/audio_core/sink_details.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-12-14 21:48:17 -0500
committerGravatar GitHub2018-12-14 21:48:17 -0500
commitb88430c29908a0f0b9cdbce139fac4f9c392eec6 (patch)
tree6554f524db5348ae005504a4dd13954342ca9008 /src/audio_core/sink_details.cpp
parentMerge pull request #1899 from lioncash/state (diff)
parentaudio_core: Make g_sink_details internally linked (diff)
downloadyuzu-b88430c29908a0f0b9cdbce139fac4f9c392eec6.tar.gz
yuzu-b88430c29908a0f0b9cdbce139fac4f9c392eec6.tar.xz
yuzu-b88430c29908a0f0b9cdbce139fac4f9c392eec6.zip
Merge pull request #1902 from lioncash/audio
audio_core: Make g_sink_details internally linked
Diffstat (limited to 'src/audio_core/sink_details.cpp')
-rw-r--r--src/audio_core/sink_details.cpp53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/audio_core/sink_details.cpp b/src/audio_core/sink_details.cpp
index 67cf1f3b2..a848eb1c9 100644
--- a/src/audio_core/sink_details.cpp
+++ b/src/audio_core/sink_details.cpp
@@ -14,31 +14,68 @@
14#include "common/logging/log.h" 14#include "common/logging/log.h"
15 15
16namespace AudioCore { 16namespace AudioCore {
17namespace {
18struct SinkDetails {
19 using FactoryFn = std::unique_ptr<Sink> (*)(std::string_view);
20 using ListDevicesFn = std::vector<std::string> (*)();
17 21
18// g_sink_details is ordered in terms of desirability, with the best choice at the top. 22 /// Name for this sink.
19const std::vector<SinkDetails> g_sink_details = { 23 const char* id;
24 /// A method to call to construct an instance of this type of sink.
25 FactoryFn factory;
26 /// A method to call to list available devices.
27 ListDevicesFn list_devices;
28};
29
30// sink_details is ordered in terms of desirability, with the best choice at the top.
31constexpr SinkDetails sink_details[] = {
20#ifdef HAVE_CUBEB 32#ifdef HAVE_CUBEB
21 SinkDetails{"cubeb", &std::make_unique<CubebSink, std::string>, &ListCubebSinkDevices}, 33 SinkDetails{"cubeb",
34 [](std::string_view device_id) -> std::unique_ptr<Sink> {
35 return std::make_unique<CubebSink>(device_id);
36 },
37 &ListCubebSinkDevices},
22#endif 38#endif
23 SinkDetails{"null", &std::make_unique<NullSink, std::string>, 39 SinkDetails{"null",
40 [](std::string_view device_id) -> std::unique_ptr<Sink> {
41 return std::make_unique<NullSink>(device_id);
42 },
24 [] { return std::vector<std::string>{"null"}; }}, 43 [] { return std::vector<std::string>{"null"}; }},
25}; 44};
26 45
27const SinkDetails& GetSinkDetails(std::string_view sink_id) { 46const SinkDetails& GetSinkDetails(std::string_view sink_id) {
28 auto iter = 47 auto iter =
29 std::find_if(g_sink_details.begin(), g_sink_details.end(), 48 std::find_if(std::begin(sink_details), std::end(sink_details),
30 [sink_id](const auto& sink_detail) { return sink_detail.id == sink_id; }); 49 [sink_id](const auto& sink_detail) { return sink_detail.id == sink_id; });
31 50
32 if (sink_id == "auto" || iter == g_sink_details.end()) { 51 if (sink_id == "auto" || iter == std::end(sink_details)) {
33 if (sink_id != "auto") { 52 if (sink_id != "auto") {
34 LOG_ERROR(Audio, "AudioCore::SelectSink given invalid sink_id {}", sink_id); 53 LOG_ERROR(Audio, "AudioCore::SelectSink given invalid sink_id {}", sink_id);
35 } 54 }
36 // Auto-select. 55 // Auto-select.
37 // g_sink_details is ordered in terms of desirability, with the best choice at the front. 56 // sink_details is ordered in terms of desirability, with the best choice at the front.
38 iter = g_sink_details.begin(); 57 iter = std::begin(sink_details);
39 } 58 }
40 59
41 return *iter; 60 return *iter;
42} 61}
62} // Anonymous namespace
63
64std::vector<const char*> GetSinkIDs() {
65 std::vector<const char*> sink_ids(std::size(sink_details));
66
67 std::transform(std::begin(sink_details), std::end(sink_details), std::begin(sink_ids),
68 [](const auto& sink) { return sink.id; });
69
70 return sink_ids;
71}
72
73std::vector<std::string> GetDeviceListForSink(std::string_view sink_id) {
74 return GetSinkDetails(sink_id).list_devices();
75}
76
77std::unique_ptr<Sink> CreateSinkFromID(std::string_view sink_id, std::string_view device_id) {
78 return GetSinkDetails(sink_id).factory(device_id);
79}
43 80
44} // namespace AudioCore 81} // namespace AudioCore