sink_details.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 yuzu 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 <string>
  7. #include <vector>
  8. #include "audio_core/null_sink.h"
  9. #include "audio_core/sink_details.h"
  10. #ifdef HAVE_CUBEB
  11. #include "audio_core/cubeb_sink.h"
  12. #endif
  13. #include "common/logging/log.h"
  14. namespace AudioCore {
  15. // g_sink_details is ordered in terms of desirability, with the best choice at the top.
  16. const std::vector<SinkDetails> g_sink_details = {
  17. #ifdef HAVE_CUBEB
  18. SinkDetails{"cubeb", &std::make_unique<CubebSink, std::string>, &ListCubebSinkDevices},
  19. #endif
  20. SinkDetails{"null", &std::make_unique<NullSink, std::string>,
  21. [] { return std::vector<std::string>{"null"}; }},
  22. };
  23. const SinkDetails& GetSinkDetails(std::string_view sink_id) {
  24. auto iter =
  25. std::find_if(g_sink_details.begin(), g_sink_details.end(),
  26. [sink_id](const auto& sink_detail) { return sink_detail.id == sink_id; });
  27. if (sink_id == "auto" || iter == g_sink_details.end()) {
  28. if (sink_id != "auto") {
  29. LOG_ERROR(Audio, "AudioCore::SelectSink given invalid sink_id {}", sink_id);
  30. }
  31. // Auto-select.
  32. // g_sink_details is ordered in terms of desirability, with the best choice at the front.
  33. iter = g_sink_details.begin();
  34. }
  35. return *iter;
  36. }
  37. } // namespace AudioCore