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
;
39 BackendBase() = delete;
40 BackendBase(const BackendBase
&) = delete;
41 BackendBase(BackendBase
&&) = delete;
42 BackendBase(DeviceBase
*device
) noexcept
: mDevice
{device
} { }
43 virtual ~BackendBase() = default;
45 void operator=(const BackendBase
&) = delete;
46 void operator=(BackendBase
&&) = delete;
49 /** Sets the default channel order used by most non-WaveFormatEx-based APIs. */
50 void setDefaultChannelOrder() const;
51 /** Sets the default channel order used by WaveFormatEx. */
52 void setDefaultWFXChannelOrder() const;
54 using BackendPtr
= std::unique_ptr
<BackendBase
>;
56 enum class BackendType
{
62 /* Helper to get the device latency from the backend, including any fixed
63 * latency from post-processing.
65 inline ClockLatency
GetClockLatency(DeviceBase
*device
, BackendBase
*backend
)
67 ClockLatency ret
{backend
->getClockLatency()};
68 ret
.Latency
+= device
->FixedLatency
;
73 struct BackendFactory
{
74 BackendFactory() = default;
75 BackendFactory(const BackendFactory
&) = delete;
76 BackendFactory(BackendFactory
&&) = delete;
77 virtual ~BackendFactory() = default;
79 void operator=(const BackendFactory
&) = delete;
80 void operator=(BackendFactory
&&) = delete;
82 virtual auto init() -> bool = 0;
84 virtual auto querySupport(BackendType type
) -> bool = 0;
86 virtual auto queryEventSupport(alc::EventType
, BackendType
) -> alc::EventSupport
87 { return alc::EventSupport::NoSupport
; }
89 virtual auto enumerate(BackendType type
) -> std::vector
<std::string
> = 0;
91 virtual auto createBackend(DeviceBase
*device
, BackendType type
) -> BackendPtr
= 0;
96 enum class backend_error
{
102 class backend_exception final
: public base_exception
{
103 backend_error mErrorCode
;
107 [[gnu::format(__MINGW_PRINTF_FORMAT
, 3, 4)]]
109 [[gnu::format(printf
, 3, 4)]]
111 backend_exception(backend_error code
, const char *msg
, ...);
112 ~backend_exception() override
;
114 [[nodiscard
]] auto errorCode() const noexcept
-> backend_error
{ return mErrorCode
; }
119 #endif /* ALC_BACKENDS_BASE_H */