1 #ifndef ALC_BACKENDS_BASE_H
2 #define ALC_BACKENDS_BASE_H
10 #include <string_view>
13 #include "core/device.h"
14 #include "core/except.h"
15 #include "alc/events.h"
18 using uint
= unsigned int;
21 std::chrono::nanoseconds ClockTime
;
22 std::chrono::nanoseconds Latency
;
26 virtual void open(std::string_view name
) = 0;
29 virtual void start() = 0;
30 virtual void stop() = 0;
32 virtual void captureSamples(std::byte
*buffer
, uint samples
);
33 virtual uint
availableSamples();
35 virtual ClockLatency
getClockLatency();
37 DeviceBase
*const mDevice
;
38 std::string mDeviceName
;
40 BackendBase() = delete;
41 BackendBase(const BackendBase
&) = delete;
42 BackendBase(BackendBase
&&) = delete;
43 BackendBase(DeviceBase
*device
) noexcept
: mDevice
{device
} { }
44 virtual ~BackendBase() = default;
46 void operator=(const BackendBase
&) = delete;
47 void operator=(BackendBase
&&) = delete;
50 /** Sets the default channel order used by most non-WaveFormatEx-based APIs. */
51 void setDefaultChannelOrder() const;
52 /** Sets the default channel order used by WaveFormatEx. */
53 void setDefaultWFXChannelOrder() const;
55 using BackendPtr
= std::unique_ptr
<BackendBase
>;
57 enum class BackendType
{
63 /* Helper to get the device latency from the backend, including any fixed
64 * latency from post-processing.
66 inline ClockLatency
GetClockLatency(DeviceBase
*device
, BackendBase
*backend
)
68 ClockLatency ret
{backend
->getClockLatency()};
69 ret
.Latency
+= device
->FixedLatency
;
74 struct BackendFactory
{
75 BackendFactory() = default;
76 BackendFactory(const BackendFactory
&) = delete;
77 BackendFactory(BackendFactory
&&) = delete;
78 virtual ~BackendFactory() = default;
80 void operator=(const BackendFactory
&) = delete;
81 void operator=(BackendFactory
&&) = delete;
83 virtual auto init() -> bool = 0;
85 virtual auto querySupport(BackendType type
) -> bool = 0;
87 virtual auto queryEventSupport(alc::EventType
, BackendType
) -> alc::EventSupport
88 { return alc::EventSupport::NoSupport
; }
90 virtual auto enumerate(BackendType type
) -> std::vector
<std::string
> = 0;
92 virtual auto createBackend(DeviceBase
*device
, BackendType type
) -> BackendPtr
= 0;
97 enum class backend_error
{
103 class backend_exception final
: public base_exception
{
104 backend_error mErrorCode
;
108 [[gnu::format(__MINGW_PRINTF_FORMAT
, 3, 4)]]
110 [[gnu::format(printf
, 3, 4)]]
112 backend_exception(backend_error code
, const char *msg
, ...);
113 ~backend_exception() override
;
115 [[nodiscard
]] auto errorCode() const noexcept
-> backend_error
{ return mErrorCode
; }
120 #endif /* ALC_BACKENDS_BASE_H */