sink_details.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include <memory>
  6. #include <vector>
  7. #include "audio_core/null_sink.h"
  8. #include "audio_core/sink_details.h"
  9. #ifdef HAVE_SDL2
  10. #include "audio_core/sdl2_sink.h"
  11. #endif
  12. #include "common/logging/log.h"
  13. namespace AudioCore {
  14. // g_sink_details is ordered in terms of desirability, with the best choice at the top.
  15. const std::vector<SinkDetails> g_sink_details = {
  16. #ifdef HAVE_SDL2
  17. {"sdl2", []() { return std::make_unique<SDL2Sink>(); }},
  18. #endif
  19. {"null", []() { return std::make_unique<NullSink>(); }},
  20. };
  21. const SinkDetails& GetSinkDetails(std::string sink_id) {
  22. auto iter =
  23. std::find_if(g_sink_details.begin(), g_sink_details.end(),
  24. [sink_id](const auto& sink_detail) { return sink_detail.id == sink_id; });
  25. if (sink_id == "auto" || iter == g_sink_details.end()) {
  26. if (sink_id != "auto") {
  27. LOG_ERROR(Audio, "AudioCore::SelectSink given invalid sink_id %s", sink_id.c_str());
  28. }
  29. // Auto-select.
  30. // g_sink_details is ordered in terms of desirability, with the best choice at the front.
  31. iter = g_sink_details.begin();
  32. }
  33. return *iter;
  34. }
  35. } // namespace AudioCore