aboutsummaryrefslogtreecommitdiff
path: root/src/audio_core/sink_details.cpp
blob: 961e040b3cd6a6a5dbf8bff25bba393a4d4dc12b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "audio_core/null_sink.h"
#include "audio_core/sink_details.h"
#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"

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
#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},
#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"}; }},
};
} // Anonymous namespace

std::vector<SinkDetails> ListSinks() {
    return {sink_details.begin(), sink_details.end()};
}

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;
}

} // namespace AudioCore