Lime3DS/src/audio_core/sink_details.cpp

77 lines
2.5 KiB
C++
Raw Normal View History

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.
#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"
#include "audio_core/sink_details.h"
2016-04-27 04:57:29 -05:00
#ifdef HAVE_SDL2
#include "audio_core/sdl2_sink.h"
#endif
#ifdef HAVE_CUBEB
#include "audio_core/cubeb_sink.h"
#endif
#ifdef HAVE_OPENAL
#include "audio_core/openal_sink.h"
#endif
#include "common/logging/log.h"
2016-04-27 04:57:29 -05:00
2016-04-28 08:28:59 -05:00
namespace AudioCore {
namespace {
// sink_details is ordered in terms of desirability, with the best choice at the top.
constexpr std::array sink_details = {
#ifdef HAVE_CUBEB
SinkDetails{SinkType::Cubeb, "Cubeb",
[](std::string_view device_id) -> std::unique_ptr<Sink> {
return std::make_unique<CubebSink>(device_id);
},
&ListCubebSinkDevices},
#endif
#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
SinkDetails{SinkType::SDL2, "SDL2",
[](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
SinkDetails{SinkType::Null, "None",
[](std::string_view device_id) -> std::unique_ptr<Sink> {
return std::make_unique<NullSink>(device_id);
},
[] { return std::vector<std::string>{"None"}; }},
2016-04-28 08:28:59 -05:00
};
} // Anonymous namespace
std::vector<SinkDetails> ListSinks() {
return {sink_details.begin(), sink_details.end()};
}
2016-04-28 08:28:59 -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; });
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);
}
// Auto-select.
// sink_details is ordered in terms of desirability, with the best choice at the front.
iter = sink_details.begin();
}
return *iter;
}
2016-04-28 08:28:59 -05:00
} // namespace AudioCore