PlaybackStream.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2023, Gregory Bertilson <zaggy1024@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "PlaybackStream.h"
  7. #include <LibCore/ThreadedPromise.h>
  8. #if defined(HAVE_PULSEAUDIO)
  9. # include <LibAudio/PlaybackStreamPulseAudio.h>
  10. #endif
  11. namespace Audio {
  12. #define TRY_OR_REJECT_AND_STOP(expression, promise) \
  13. ({ \
  14. auto&& __temporary_result = (expression); \
  15. if (__temporary_result.is_error()) [[unlikely]] { \
  16. (promise)->reject(__temporary_result.release_error()); \
  17. return 1; \
  18. } \
  19. __temporary_result.release_value(); \
  20. })
  21. ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStream::create(OutputState initial_output_state, u32 sample_rate, u8 channels, u32 target_latency_ms, AudioDataRequestCallback&& data_request_callback)
  22. {
  23. VERIFY(data_request_callback);
  24. // Create the platform-specific implementation for this stream.
  25. #if defined(HAVE_PULSEAUDIO)
  26. return PlaybackStreamPulseAudio::create(initial_output_state, sample_rate, channels, target_latency_ms, move(data_request_callback));
  27. #else
  28. (void)initial_output_state, (void)sample_rate, (void)channels, (void)target_latency_ms;
  29. return Error::from_string_literal("Audio output is not available for this platform");
  30. #endif
  31. }
  32. }