base.c 2.1 KB

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