🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.8 KiB

  1. #ifndef ALC_BACKENDS_BASE_H
  2. #define ALC_BACKENDS_BASE_H
  3. #include <memory>
  4. #include <chrono>
  5. #include <string>
  6. #include <mutex>
  7. #include "alMain.h"
  8. struct ClockLatency {
  9. std::chrono::nanoseconds ClockTime;
  10. std::chrono::nanoseconds Latency;
  11. };
  12. /* Helper to get the current clock time from the device's ClockBase, and
  13. * SamplesDone converted from the sample rate.
  14. */
  15. inline std::chrono::nanoseconds GetDeviceClockTime(ALCdevice *device)
  16. {
  17. using std::chrono::seconds;
  18. using std::chrono::nanoseconds;
  19. auto ns = nanoseconds{seconds{device->SamplesDone}} / device->Frequency;
  20. return device->ClockBase + ns;
  21. }
  22. ClockLatency GetClockLatency(ALCdevice *device);
  23. struct BackendBase {
  24. virtual ALCenum open(const ALCchar *name) = 0;
  25. virtual ALCboolean reset();
  26. virtual ALCboolean start() = 0;
  27. virtual void stop() = 0;
  28. virtual ALCenum captureSamples(void *buffer, ALCuint samples);
  29. virtual ALCuint availableSamples();
  30. virtual ClockLatency getClockLatency();
  31. virtual void lock() { mMutex.lock(); }
  32. virtual void unlock() { mMutex.unlock(); }
  33. ALCdevice *mDevice;
  34. std::recursive_mutex mMutex;
  35. BackendBase(ALCdevice *device) noexcept;
  36. virtual ~BackendBase();
  37. };
  38. using BackendPtr = std::unique_ptr<BackendBase>;
  39. using BackendUniqueLock = std::unique_lock<BackendBase>;
  40. using BackendLockGuard = std::lock_guard<BackendBase>;
  41. enum class BackendType {
  42. Playback,
  43. Capture
  44. };
  45. enum class DevProbe {
  46. Playback,
  47. Capture
  48. };
  49. struct BackendFactory {
  50. virtual bool init() = 0;
  51. virtual bool querySupport(BackendType type) = 0;
  52. virtual void probe(DevProbe type, std::string *outnames) = 0;
  53. virtual BackendPtr createBackend(ALCdevice *device, BackendType type) = 0;
  54. };
  55. #endif /* ALC_BACKENDS_BASE_H */