aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends/base.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-07-28 18:56:04 -0700
committerChris Robinson <[email protected]>2019-07-28 18:56:04 -0700
commitcb3e96e75640730b9391f0d2d922eecd9ee2ce79 (patch)
tree23520551bddb2a80354e44da47f54201fdc084f0 /alc/backends/base.h
parent93e60919c8f387c36c267ca9faa1ac653254aea6 (diff)
Rename Alc to alc
Diffstat (limited to 'alc/backends/base.h')
-rw-r--r--alc/backends/base.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/alc/backends/base.h b/alc/backends/base.h
new file mode 100644
index 00000000..437e31d9
--- /dev/null
+++ b/alc/backends/base.h
@@ -0,0 +1,78 @@
+#ifndef ALC_BACKENDS_BASE_H
+#define ALC_BACKENDS_BASE_H
+
+#include <memory>
+#include <chrono>
+#include <string>
+#include <mutex>
+
+#include "alcmain.h"
+
+
+struct ClockLatency {
+ std::chrono::nanoseconds ClockTime;
+ std::chrono::nanoseconds Latency;
+};
+
+/* Helper to get the current clock time from the device's ClockBase, and
+ * SamplesDone converted from the sample rate.
+ */
+inline std::chrono::nanoseconds GetDeviceClockTime(ALCdevice *device)
+{
+ using std::chrono::seconds;
+ using std::chrono::nanoseconds;
+
+ auto ns = nanoseconds{seconds{device->SamplesDone}} / device->Frequency;
+ return device->ClockBase + ns;
+}
+
+ClockLatency GetClockLatency(ALCdevice *device);
+
+struct BackendBase {
+ virtual ALCenum open(const ALCchar *name) = 0;
+
+ virtual ALCboolean reset();
+ virtual ALCboolean start() = 0;
+ virtual void stop() = 0;
+
+ virtual ALCenum captureSamples(void *buffer, ALCuint samples);
+ virtual ALCuint availableSamples();
+
+ virtual ClockLatency getClockLatency();
+
+ virtual void lock() { mMutex.lock(); }
+ virtual void unlock() { mMutex.unlock(); }
+
+ ALCdevice *mDevice;
+
+ std::recursive_mutex mMutex;
+
+ BackendBase(ALCdevice *device) noexcept;
+ virtual ~BackendBase();
+};
+using BackendPtr = std::unique_ptr<BackendBase>;
+using BackendUniqueLock = std::unique_lock<BackendBase>;
+using BackendLockGuard = std::lock_guard<BackendBase>;
+
+enum class BackendType {
+ Playback,
+ Capture
+};
+
+enum class DevProbe {
+ Playback,
+ Capture
+};
+
+
+struct BackendFactory {
+ virtual bool init() = 0;
+
+ virtual bool querySupport(BackendType type) = 0;
+
+ virtual void probe(DevProbe type, std::string *outnames) = 0;
+
+ virtual BackendPtr createBackend(ALCdevice *device, BackendType type) = 0;
+};
+
+#endif /* ALC_BACKENDS_BASE_H */