79 lines
1.8 KiB
C
Raw Normal View History

2018-12-25 11:09:41 -08:00
#ifndef ALC_BACKENDS_BASE_H
#define ALC_BACKENDS_BASE_H
2013-10-27 16:37:40 -07:00
2018-12-29 02:16:16 -08:00
#include <memory>
#include <chrono>
#include <string>
#include <mutex>
2018-12-25 11:09:41 -08:00
#include "alMain.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;
2013-10-27 16:37:40 -07:00
virtual ALCenum captureSamples(void *buffer, ALCuint samples);
virtual ALCuint availableSamples();
2013-10-27 16:37:40 -07:00
virtual ClockLatency getClockLatency();
2013-10-27 16:37:40 -07:00
virtual void lock() { mMutex.lock(); }
virtual void unlock() { mMutex.unlock(); }
2013-10-27 16:37:40 -07:00
ALCdevice *mDevice;
2013-10-27 16:37:40 -07:00
std::recursive_mutex mMutex;
BackendBase(ALCdevice *device) noexcept;
virtual ~BackendBase();
2013-10-27 16:37:40 -07:00
};
2018-12-29 02:16:16 -08:00
using BackendPtr = std::unique_ptr<BackendBase>;
using BackendUniqueLock = std::unique_lock<BackendBase>;
using BackendLockGuard = std::lock_guard<BackendBase>;
2013-10-27 16:37:40 -07:00
2018-12-29 01:38:26 -08:00
enum class BackendType {
Playback,
Capture
};
2013-10-28 07:27:35 -07:00
enum class DevProbe {
Playback,
Capture
};
2013-10-28 07:27:35 -07:00
struct BackendFactory {
virtual bool init() = 0;
2018-12-29 01:38:26 -08:00
virtual bool querySupport(BackendType type) = 0;
virtual void probe(DevProbe type, std::string *outnames) = 0;
2018-12-29 02:16:16 -08:00
virtual BackendPtr createBackend(ALCdevice *device, BackendType type) = 0;
};
2018-12-25 11:09:41 -08:00
#endif /* ALC_BACKENDS_BASE_H */