ClientConnection.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibAudio/Buffer.h>
  7. #include <LibAudio/ClientConnection.h>
  8. namespace Audio {
  9. ClientConnection::ClientConnection()
  10. : IPC::ServerConnection<AudioClientEndpoint, AudioServerEndpoint>(*this, "/tmp/portal/audio")
  11. {
  12. }
  13. void ClientConnection::enqueue(const Buffer& buffer)
  14. {
  15. for (;;) {
  16. auto success = enqueue_buffer(buffer.anonymous_buffer(), buffer.id(), buffer.sample_count());
  17. if (success)
  18. break;
  19. // FIXME: We don't know what is a good value for this.
  20. // For now, decrease it to enable better real-time audio.
  21. usleep(10000);
  22. }
  23. }
  24. bool ClientConnection::try_enqueue(const Buffer& buffer)
  25. {
  26. return enqueue_buffer(buffer.anonymous_buffer(), buffer.id(), buffer.sample_count());
  27. }
  28. void ClientConnection::finished_playing_buffer(i32 buffer_id)
  29. {
  30. if (on_finish_playing_buffer)
  31. on_finish_playing_buffer(buffer_id);
  32. }
  33. void ClientConnection::muted_state_changed(bool muted)
  34. {
  35. if (on_muted_state_change)
  36. on_muted_state_change(muted);
  37. }
  38. void ClientConnection::main_mix_volume_changed(i32 volume)
  39. {
  40. if (on_main_mix_volume_change)
  41. on_main_mix_volume_change(volume);
  42. }
  43. }