Check some float property values for being finite
[openal-soft.git] / alc / backends / base.h
blob0e82bb6b7fab1d6ee07e41b2040ed2e7378c36f9
1 #ifndef ALC_BACKENDS_BASE_H
2 #define ALC_BACKENDS_BASE_H
4 #include <chrono>
5 #include <cstdarg>
6 #include <cstddef>
7 #include <memory>
8 #include <ratio>
9 #include <string>
10 #include <string_view>
11 #include <vector>
13 #include "core/device.h"
14 #include "core/except.h"
15 #include "alc/events.h"
18 using uint = unsigned int;
20 struct ClockLatency {
21 std::chrono::nanoseconds ClockTime;
22 std::chrono::nanoseconds Latency;
25 struct BackendBase {
26 virtual void open(std::string_view name) = 0;
28 virtual bool reset();
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;
49 protected:
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 {
58 Playback,
59 Capture
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;
70 return ret;
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;
95 namespace al {
97 enum class backend_error {
98 NoDevice,
99 DeviceError,
100 OutOfMemory
103 class backend_exception final : public base_exception {
104 backend_error mErrorCode;
106 public:
107 #ifdef __MINGW32__
108 [[gnu::format(__MINGW_PRINTF_FORMAT, 3, 4)]]
109 #else
110 [[gnu::format(printf, 3, 4)]]
111 #endif
112 backend_exception(backend_error code, const char *msg, ...);
113 ~backend_exception() override;
115 [[nodiscard]] auto errorCode() const noexcept -> backend_error { return mErrorCode; }
118 } // namespace al
120 #endif /* ALC_BACKENDS_BASE_H */