2013-10-28 12:30:57 -07:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-11-26 23:06:49 -08:00
|
|
|
#include <thread>
|
|
|
|
|
2013-10-28 12:30:57 -07:00
|
|
|
#include "alMain.h"
|
2017-02-18 16:55:48 -08:00
|
|
|
#include "alu.h"
|
2013-10-28 12:30:57 -07:00
|
|
|
|
|
|
|
#include "backends/base.h"
|
|
|
|
|
|
|
|
|
2018-11-13 19:45:26 -08:00
|
|
|
ClockLatency GetClockLatency(ALCdevice *device)
|
|
|
|
{
|
2018-12-29 02:16:16 -08:00
|
|
|
BackendBase *backend{device->Backend.get()};
|
2018-12-28 22:56:20 -08:00
|
|
|
ClockLatency ret{backend->getClockLatency()};
|
2018-11-22 14:32:48 -08:00
|
|
|
ret.Latency += device->FixedLatency;
|
2018-11-13 19:45:26 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-28 22:56:20 -08:00
|
|
|
/* BackendBase method implementations. */
|
|
|
|
BackendBase::BackendBase(ALCdevice *device) noexcept : mDevice{device}
|
2018-12-27 13:40:43 -08:00
|
|
|
{ }
|
2013-10-28 12:30:57 -07:00
|
|
|
|
2018-12-28 22:56:20 -08:00
|
|
|
BackendBase::~BackendBase()
|
2018-12-27 13:40:43 -08:00
|
|
|
{ }
|
2013-10-28 12:30:57 -07:00
|
|
|
|
2018-12-28 22:56:20 -08:00
|
|
|
ALCboolean BackendBase::reset()
|
|
|
|
{ return ALC_FALSE; }
|
2013-10-29 15:07:13 -07:00
|
|
|
|
2018-12-28 22:56:20 -08:00
|
|
|
ALCenum BackendBase::captureSamples(void* UNUSED(buffer), ALCuint UNUSED(samples))
|
|
|
|
{ return ALC_INVALID_DEVICE; }
|
2013-10-29 15:07:13 -07:00
|
|
|
|
2018-12-28 22:56:20 -08:00
|
|
|
ALCuint BackendBase::availableSamples()
|
|
|
|
{ return 0; }
|
2013-10-29 15:07:13 -07:00
|
|
|
|
2018-12-28 22:56:20 -08:00
|
|
|
ClockLatency BackendBase::getClockLatency()
|
2013-10-28 12:30:57 -07:00
|
|
|
{
|
2016-05-28 00:43:14 -07:00
|
|
|
ClockLatency ret;
|
|
|
|
|
2018-12-28 22:56:20 -08:00
|
|
|
ALuint refcount;
|
2017-02-28 03:50:42 -08:00
|
|
|
do {
|
2018-12-28 22:56:20 -08:00
|
|
|
while(((refcount=mDevice->MixCount.load(std::memory_order_acquire))&1))
|
2018-11-26 23:06:49 -08:00
|
|
|
std::this_thread::yield();
|
2018-12-28 22:56:20 -08:00
|
|
|
ret.ClockTime = GetDeviceClockTime(mDevice);
|
2018-11-19 05:04:17 -08:00
|
|
|
std::atomic_thread_fence(std::memory_order_acquire);
|
2018-12-28 22:56:20 -08:00
|
|
|
} while(refcount != mDevice->MixCount.load(std::memory_order_relaxed));
|
2017-02-28 03:50:42 -08:00
|
|
|
|
2017-02-18 16:55:48 -08:00
|
|
|
/* NOTE: The device will generally have about all but one periods filled at
|
|
|
|
* any given time during playback. Without a more accurate measurement from
|
|
|
|
* the output, this is an okay approximation.
|
|
|
|
*/
|
2018-12-28 22:56:20 -08:00
|
|
|
ret.Latency = std::chrono::seconds{mDevice->UpdateSize*maxi(mDevice->NumUpdates-1, 0)};
|
|
|
|
ret.Latency /= mDevice->Frequency;
|
2016-05-28 00:43:14 -07:00
|
|
|
|
|
|
|
return ret;
|
2013-10-28 12:30:57 -07:00
|
|
|
}
|