1 #ifndef ALC_BACKENDS_BASE_H
2 #define ALC_BACKENDS_BASE_H
16 std::chrono::nanoseconds ClockTime
;
17 std::chrono::nanoseconds Latency
;
20 /* Helper to get the current clock time from the device's ClockBase, and
21 * SamplesDone converted from the sample rate.
23 inline std::chrono::nanoseconds
GetDeviceClockTime(ALCdevice
*device
)
25 using std::chrono::seconds
;
26 using std::chrono::nanoseconds
;
28 auto ns
= nanoseconds
{seconds
{device
->SamplesDone
}} / device
->Frequency
;
29 return device
->ClockBase
+ ns
;
32 ClockLatency
GetClockLatency(ALCdevice
*device
);
35 virtual ALCenum
open(const ALCchar
*name
) = 0;
38 virtual bool start() = 0;
39 virtual void stop() = 0;
41 virtual ALCenum
captureSamples(al::byte
*buffer
, ALCuint samples
);
42 virtual ALCuint
availableSamples();
44 virtual ClockLatency
getClockLatency();
46 virtual void lock() { mMutex
.lock(); }
47 virtual void unlock() { mMutex
.unlock(); }
51 std::recursive_mutex mMutex
;
53 BackendBase(ALCdevice
*device
) noexcept
;
54 virtual ~BackendBase();
56 using BackendPtr
= std::unique_ptr
<BackendBase
>;
57 using BackendUniqueLock
= std::unique_lock
<BackendBase
>;
58 using BackendLockGuard
= std::lock_guard
<BackendBase
>;
60 enum class BackendType
{
71 struct BackendFactory
{
72 virtual bool init() = 0;
74 virtual bool querySupport(BackendType type
) = 0;
76 virtual void probe(DevProbe type
, std::string
*outnames
) = 0;
78 virtual BackendPtr
createBackend(ALCdevice
*device
, BackendType type
) = 0;
81 virtual ~BackendFactory() = default;
84 #endif /* ALC_BACKENDS_BASE_H */