base.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "config.h"
  2. #include <stdlib.h>
  3. #include "alMain.h"
  4. #include "alu.h"
  5. #include "backends/base.h"
  6. extern inline ALuint64 GetDeviceClockTime(ALCdevice *device);
  7. extern inline void ALCdevice_Lock(ALCdevice *device);
  8. extern inline void ALCdevice_Unlock(ALCdevice *device);
  9. /* Base ALCbackend method implementations. */
  10. void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
  11. {
  12. int ret = almtx_init(&self->mMutex, almtx_recursive);
  13. assert(ret == althrd_success);
  14. self->mDevice = device;
  15. }
  16. void ALCbackend_Destruct(ALCbackend *self)
  17. {
  18. almtx_destroy(&self->mMutex);
  19. }
  20. ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self))
  21. {
  22. return ALC_FALSE;
  23. }
  24. ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
  25. {
  26. return ALC_INVALID_DEVICE;
  27. }
  28. ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self))
  29. {
  30. return 0;
  31. }
  32. ClockLatency ALCbackend_getClockLatency(ALCbackend *self)
  33. {
  34. ALCdevice *device = self->mDevice;
  35. ALuint refcount;
  36. ClockLatency ret;
  37. do {
  38. while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
  39. althrd_yield();
  40. ret.ClockTime = GetDeviceClockTime(device);
  41. ATOMIC_THREAD_FENCE(almemory_order_acquire);
  42. } while(refcount != ATOMIC_LOAD(&device->MixCount, almemory_order_relaxed));
  43. /* NOTE: The device will generally have about all but one periods filled at
  44. * any given time during playback. Without a more accurate measurement from
  45. * the output, this is an okay approximation.
  46. */
  47. ret.Latency = device->UpdateSize * DEVICE_CLOCK_RES / device->Frequency *
  48. maxu(device->NumUpdates-1, 1);
  49. return ret;
  50. }
  51. void ALCbackend_lock(ALCbackend *self)
  52. {
  53. int ret = almtx_lock(&self->mMutex);
  54. assert(ret == althrd_success);
  55. }
  56. void ALCbackend_unlock(ALCbackend *self)
  57. {
  58. int ret = almtx_unlock(&self->mMutex);
  59. assert(ret == althrd_success);
  60. }
  61. /* Base ALCbackendFactory method implementations. */
  62. void ALCbackendFactory_deinit(ALCbackendFactory* UNUSED(self))
  63. {
  64. }