2016-04-28 08:28:59 -05:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-01-25 21:33:26 -06:00
|
|
|
#include <algorithm>
|
2016-04-28 08:28:59 -05:00
|
|
|
#include <memory>
|
2017-12-20 12:44:32 -06:00
|
|
|
#include <string>
|
2016-04-28 08:28:59 -05:00
|
|
|
#include <vector>
|
|
|
|
#include "audio_core/null_sink.h"
|
2016-09-21 01:52:38 -05:00
|
|
|
#include "audio_core/sink_details.h"
|
2016-04-27 04:57:29 -05:00
|
|
|
#ifdef HAVE_SDL2
|
|
|
|
#include "audio_core/sdl2_sink.h"
|
|
|
|
#endif
|
2018-05-25 00:58:53 -05:00
|
|
|
#ifdef HAVE_CUBEB
|
2018-05-25 00:50:37 -05:00
|
|
|
#include "audio_core/cubeb_sink.h"
|
2018-05-25 00:58:53 -05:00
|
|
|
#endif
|
2023-05-01 14:17:45 -05:00
|
|
|
#ifdef HAVE_OPENAL
|
|
|
|
#include "audio_core/openal_sink.h"
|
|
|
|
#endif
|
2017-01-25 21:33:26 -06:00
|
|
|
#include "common/logging/log.h"
|
2016-04-27 04:57:29 -05:00
|
|
|
|
2016-04-28 08:28:59 -05:00
|
|
|
namespace AudioCore {
|
2018-12-13 15:23:31 -06:00
|
|
|
namespace {
|
|
|
|
// sink_details is ordered in terms of desirability, with the best choice at the top.
|
2023-05-01 14:17:45 -05:00
|
|
|
constexpr std::array sink_details = {
|
2018-05-25 00:58:53 -05:00
|
|
|
#ifdef HAVE_CUBEB
|
2023-05-01 14:17:45 -05:00
|
|
|
SinkDetails{SinkType::Cubeb, "Cubeb",
|
2018-12-13 15:23:31 -06:00
|
|
|
[](std::string_view device_id) -> std::unique_ptr<Sink> {
|
|
|
|
return std::make_unique<CubebSink>(device_id);
|
|
|
|
},
|
|
|
|
&ListCubebSinkDevices},
|
2018-05-25 00:58:53 -05:00
|
|
|
#endif
|
2023-05-01 14:17:45 -05:00
|
|
|
#ifdef HAVE_OPENAL
|
|
|
|
SinkDetails{SinkType::OpenAL, "OpenAL",
|
|
|
|
[](std::string_view device_id) -> std::unique_ptr<Sink> {
|
|
|
|
return std::make_unique<OpenALSink>(std::string(device_id));
|
|
|
|
},
|
|
|
|
&ListOpenALSinkDevices},
|
|
|
|
#endif
|
2016-04-27 04:57:29 -05:00
|
|
|
#ifdef HAVE_SDL2
|
2023-05-01 14:17:45 -05:00
|
|
|
SinkDetails{SinkType::SDL2, "SDL2",
|
2018-12-13 15:23:31 -06:00
|
|
|
[](std::string_view device_id) -> std::unique_ptr<Sink> {
|
|
|
|
return std::make_unique<SDL2Sink>(std::string(device_id));
|
|
|
|
},
|
|
|
|
&ListSDL2SinkDevices},
|
2016-04-27 04:57:29 -05:00
|
|
|
#endif
|
2023-05-01 14:17:45 -05:00
|
|
|
SinkDetails{SinkType::Null, "None",
|
2018-12-13 15:23:31 -06:00
|
|
|
[](std::string_view device_id) -> std::unique_ptr<Sink> {
|
|
|
|
return std::make_unique<NullSink>(device_id);
|
|
|
|
},
|
2023-05-01 14:17:45 -05:00
|
|
|
[] { return std::vector<std::string>{"None"}; }},
|
2016-04-28 08:28:59 -05:00
|
|
|
};
|
2023-12-22 13:38:06 -06:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
|
std::vector<SinkDetails> ListSinks() {
|
|
|
|
return {sink_details.begin(), sink_details.end()};
|
|
|
|
}
|
2016-04-28 08:28:59 -05:00
|
|
|
|
2023-05-01 14:17:45 -05:00
|
|
|
const SinkDetails& GetSinkDetails(SinkType sink_type) {
|
|
|
|
auto iter = std::find_if(
|
|
|
|
sink_details.begin(), sink_details.end(),
|
|
|
|
[sink_type](const auto& sink_detail) { return sink_detail.type == sink_type; });
|
2017-01-25 21:33:26 -06:00
|
|
|
|
2023-05-01 14:17:45 -05:00
|
|
|
if (sink_type == SinkType::Auto || iter == sink_details.end()) {
|
|
|
|
if (sink_type != SinkType::Auto) {
|
|
|
|
LOG_ERROR(Audio, "AudioCore::GetSinkDetails given invalid sink_type {}", sink_type);
|
2017-01-25 21:33:26 -06:00
|
|
|
}
|
|
|
|
// Auto-select.
|
2018-12-13 15:23:31 -06:00
|
|
|
// sink_details is ordered in terms of desirability, with the best choice at the front.
|
2023-05-01 14:17:45 -05:00
|
|
|
iter = sink_details.begin();
|
2017-01-25 21:33:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return *iter;
|
|
|
|
}
|
|
|
|
|
2016-04-28 08:28:59 -05:00
|
|
|
} // namespace AudioCore
|