Torque3D/Engine/lib/openal-soft/alc/backends/base.h

120 lines
2.9 KiB
C
Raw Normal View History

#ifndef ALC_BACKENDS_BASE_H
#define ALC_BACKENDS_BASE_H
2016-10-22 09:22:33 +10:00
#include <chrono>
#include <cstdarg>
2024-06-30 14:35:57 -05:00
#include <cstddef>
#include <memory>
#include <ratio>
#include <string>
2024-06-30 14:35:57 -05:00
#include <string_view>
#include <vector>
2016-10-22 09:22:33 +10:00
#include "core/device.h"
#include "core/except.h"
2024-06-30 14:35:57 -05:00
#include "alc/events.h"
2016-10-22 09:22:33 +10:00
using uint = unsigned int;
2016-10-22 09:22:33 +10:00
struct ClockLatency {
std::chrono::nanoseconds ClockTime;
std::chrono::nanoseconds Latency;
};
2016-10-22 09:22:33 +10:00
struct BackendBase {
2024-06-30 14:35:57 -05:00
virtual void open(std::string_view name) = 0;
2016-10-22 09:22:33 +10:00
virtual bool reset();
virtual void start() = 0;
virtual void stop() = 0;
2016-10-22 09:22:33 +10:00
2024-06-30 14:35:57 -05:00
virtual void captureSamples(std::byte *buffer, uint samples);
virtual uint availableSamples();
2016-10-22 09:22:33 +10:00
virtual ClockLatency getClockLatency();
2016-10-22 09:22:33 +10:00
DeviceBase *const mDevice;
2016-10-22 09:22:33 +10:00
2024-06-30 14:35:57 -05:00
BackendBase() = delete;
BackendBase(const BackendBase&) = delete;
BackendBase(BackendBase&&) = delete;
BackendBase(DeviceBase *device) noexcept : mDevice{device} { }
virtual ~BackendBase() = default;
2016-10-22 09:22:33 +10:00
2024-06-30 14:35:57 -05:00
void operator=(const BackendBase&) = delete;
void operator=(BackendBase&&) = delete;
protected:
/** Sets the default channel order used by most non-WaveFormatEx-based APIs. */
2024-06-30 14:35:57 -05:00
void setDefaultChannelOrder() const;
/** Sets the default channel order used by WaveFormatEx. */
2024-06-30 14:35:57 -05:00
void setDefaultWFXChannelOrder() const;
};
using BackendPtr = std::unique_ptr<BackendBase>;
2016-10-22 09:22:33 +10:00
enum class BackendType {
Playback,
Capture
};
2016-10-22 09:22:33 +10:00
/* Helper to get the device latency from the backend, including any fixed
* latency from post-processing.
*/
inline ClockLatency GetClockLatency(DeviceBase *device, BackendBase *backend)
{
ClockLatency ret{backend->getClockLatency()};
ret.Latency += device->FixedLatency;
return ret;
}
2016-10-22 09:22:33 +10:00
struct BackendFactory {
2024-06-30 14:35:57 -05:00
BackendFactory() = default;
BackendFactory(const BackendFactory&) = delete;
BackendFactory(BackendFactory&&) = delete;
virtual ~BackendFactory() = default;
2016-10-22 09:22:33 +10:00
2024-06-30 14:35:57 -05:00
void operator=(const BackendFactory&) = delete;
void operator=(BackendFactory&&) = delete;
2016-10-22 09:22:33 +10:00
2024-06-30 14:35:57 -05:00
virtual auto init() -> bool = 0;
2016-10-22 09:22:33 +10:00
2024-06-30 14:35:57 -05:00
virtual auto querySupport(BackendType type) -> bool = 0;
2016-10-22 09:22:33 +10:00
2024-06-30 14:35:57 -05:00
virtual auto queryEventSupport(alc::EventType, BackendType) -> alc::EventSupport
{ return alc::EventSupport::NoSupport; }
virtual auto enumerate(BackendType type) -> std::vector<std::string> = 0;
virtual auto createBackend(DeviceBase *device, BackendType type) -> BackendPtr = 0;
};
2016-10-22 09:22:33 +10:00
namespace al {
2016-10-22 09:22:33 +10:00
enum class backend_error {
NoDevice,
DeviceError,
OutOfMemory
2016-10-22 09:22:33 +10:00
};
class backend_exception final : public base_exception {
backend_error mErrorCode;
public:
2024-06-30 14:35:57 -05:00
#ifdef __MINGW32__
[[gnu::format(__MINGW_PRINTF_FORMAT, 3, 4)]]
#else
[[gnu::format(printf, 3, 4)]]
#endif
backend_exception(backend_error code, const char *msg, ...);
~backend_exception() override;
2024-06-30 14:35:57 -05:00
[[nodiscard]] auto errorCode() const noexcept -> backend_error { return mErrorCode; }
};
2016-10-22 09:22:33 +10:00
} // namespace al
2016-10-22 09:22:33 +10:00
#endif /* ALC_BACKENDS_BASE_H */