mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:07:34 +00:00
LibAudio: Create a playback class with a PulseAudio implementation
This adds an abstract `Audio::PlaybackStream` class to allow cross- platform audio playback to be done in an opaque manner by applications in both Serenity and Lagom. Currently, the only supported audio API is PulseAudio, but a Serenity implementation should be added shortly as well.
This commit is contained in:
parent
fe672989a9
commit
bc4d4f0f95
9 changed files with 1041 additions and 0 deletions
39
Userland/Libraries/LibAudio/PlaybackStream.cpp
Normal file
39
Userland/Libraries/LibAudio/PlaybackStream.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Gregory Bertilson <zaggy1024@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "PlaybackStream.h"
|
||||
|
||||
#include <LibCore/ThreadedPromise.h>
|
||||
|
||||
#if defined(HAVE_PULSEAUDIO)
|
||||
# include <LibAudio/PlaybackStreamPulseAudio.h>
|
||||
#endif
|
||||
|
||||
namespace Audio {
|
||||
|
||||
#define TRY_OR_REJECT_AND_STOP(expression, promise) \
|
||||
({ \
|
||||
auto&& __temporary_result = (expression); \
|
||||
if (__temporary_result.is_error()) [[unlikely]] { \
|
||||
(promise)->reject(__temporary_result.release_error()); \
|
||||
return 1; \
|
||||
} \
|
||||
__temporary_result.release_value(); \
|
||||
})
|
||||
|
||||
ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStream::create(OutputState initial_output_state, u32 sample_rate, u8 channels, u32 target_latency_ms, AudioDataRequestCallback&& data_request_callback)
|
||||
{
|
||||
VERIFY(data_request_callback);
|
||||
// Create the platform-specific implementation for this stream.
|
||||
#if defined(HAVE_PULSEAUDIO)
|
||||
return PlaybackStreamPulseAudio::create(initial_output_state, sample_rate, channels, target_latency_ms, move(data_request_callback));
|
||||
#else
|
||||
(void)initial_output_state, (void)sample_rate, (void)channels, (void)target_latency_ms;
|
||||
return Error::from_string_literal("Audio output is not available for this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue