73 lines
1.6 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
#include <chrono>
2019-07-29 19:59:48 -07:00
#include <memory>
#include <mutex>
2019-07-29 19:59:48 -07:00
#include <string>
#include "AL/alc.h"
#include "alcmain.h"
#include "albyte.h"
2018-12-25 11:09:41 -08:00
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 void open(const ALCchar *name) = 0;
virtual bool reset();
virtual bool start() = 0;
virtual void stop() = 0;
2013-10-27 16:37:40 -07:00
virtual ALCenum captureSamples(al::byte *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
2020-03-30 00:07:35 -07:00
ALCdevice *const mDevice;
2013-10-27 16:37:40 -07:00
2020-03-30 00:07:35 -07:00
BackendBase(ALCdevice *device) noexcept : mDevice{device} { }
virtual ~BackendBase() = default;
2013-10-27 16:37:40 -07:00
};
2018-12-29 02:16:16 -08:00
using BackendPtr = std::unique_ptr<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
struct BackendFactory {
virtual bool init() = 0;
2018-12-29 01:38:26 -08:00
virtual bool querySupport(BackendType type) = 0;
2020-03-30 16:00:02 -07:00
virtual std::string probe(BackendType type) = 0;
2018-12-29 02:16:16 -08:00
virtual BackendPtr createBackend(ALCdevice *device, BackendType type) = 0;
protected:
virtual ~BackendFactory() = default;
};
2018-12-25 11:09:41 -08:00
#endif /* ALC_BACKENDS_BASE_H */