mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibMedia: Remove preprocessor chain when initializing audio streams
Instead of having to duplicate the audio stream backend conditions, just define PlaybackStream::create in each audio backend implementation file. We provide a weak definition in PlaybackStream.cpp as the fallback.
This commit is contained in:
parent
4d866f22a4
commit
dfa727a4d4
Notes:
github-actions[bot]
2024-12-25 11:01:55 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/dfa727a4d43 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3027
4 changed files with 18 additions and 24 deletions
|
@ -6,32 +6,11 @@
|
|||
|
||||
#include "PlaybackStream.h"
|
||||
|
||||
#include <AK/Platform.h>
|
||||
|
||||
#if defined(HAVE_PULSEAUDIO)
|
||||
# include "PlaybackStreamPulseAudio.h"
|
||||
#elif defined(AK_OS_MACOS)
|
||||
# include "PlaybackStreamAudioUnit.h"
|
||||
#elif defined(AK_OS_ANDROID)
|
||||
# include "PlaybackStreamOboe.h"
|
||||
#endif
|
||||
|
||||
namespace Audio {
|
||||
|
||||
ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStream::create(OutputState initial_output_state, u32 sample_rate, u8 channels, u32 target_latency_ms, AudioDataRequestCallback&& data_request_callback)
|
||||
ErrorOr<NonnullRefPtr<PlaybackStream>> __attribute__((weak)) PlaybackStream::create(OutputState, u32, u8, u32, AudioDataRequestCallback&&)
|
||||
{
|
||||
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));
|
||||
#elif defined(AK_OS_MACOS)
|
||||
return PlaybackStreamAudioUnit::create(initial_output_state, sample_rate, channels, target_latency_ms, move(data_request_callback));
|
||||
#elif defined(AK_OS_ANDROID)
|
||||
return PlaybackStreamOboe::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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -215,6 +215,11 @@ private:
|
|||
Atomic<i64> m_last_sample_time { 0 };
|
||||
};
|
||||
|
||||
ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStream::create(OutputState initial_output_state, u32 sample_rate, u8 channels, u32 target_latency_ms, AudioDataRequestCallback&& data_request_callback)
|
||||
{
|
||||
return PlaybackStreamAudioUnit::create(initial_output_state, sample_rate, channels, target_latency_ms, move(data_request_callback));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStreamAudioUnit::create(OutputState initial_output_state, u32 sample_rate, u8 channels, u32, AudioDataRequestCallback&& data_request_callback)
|
||||
{
|
||||
AudioStreamBasicDescription description {};
|
||||
|
|
|
@ -80,9 +80,9 @@ private:
|
|||
std::shared_ptr<OboeCallback> m_oboe_callback;
|
||||
};
|
||||
|
||||
PlaybackStreamOboe::PlaybackStreamOboe(NonnullRefPtr<Storage> storage)
|
||||
: m_storage(move(storage))
|
||||
ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStream::create(OutputState initial_output_state, u32 sample_rate, u8 channels, u32 target_latency_ms, AudioDataRequestCallback&& data_request_callback)
|
||||
{
|
||||
return PlaybackStreamOboe::create(initial_output_state, sample_rate, channels, target_latency_ms, move(data_request_callback));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStreamOboe::create(OutputState initial_output_state, u32 sample_rate, u8 channels, u32, AudioDataRequestCallback&& data_request_callback)
|
||||
|
@ -108,6 +108,11 @@ ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStreamOboe::create(OutputState in
|
|||
return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) PlaybackStreamOboe(move(storage))));
|
||||
}
|
||||
|
||||
PlaybackStreamOboe::PlaybackStreamOboe(NonnullRefPtr<Storage> storage)
|
||||
: m_storage(move(storage))
|
||||
{
|
||||
}
|
||||
|
||||
PlaybackStreamOboe::~PlaybackStreamOboe() = default;
|
||||
|
||||
void PlaybackStreamOboe::set_underrun_callback(Function<void()>)
|
||||
|
|
|
@ -21,6 +21,11 @@ namespace Audio {
|
|||
__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)
|
||||
{
|
||||
return PlaybackStreamPulseAudio::create(initial_output_state, sample_rate, channels, target_latency_ms, move(data_request_callback));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<PlaybackStream>> PlaybackStreamPulseAudio::create(OutputState initial_state, u32 sample_rate, u8 channels, u32 target_latency_ms, AudioDataRequestCallback&& data_request_callback)
|
||||
{
|
||||
VERIFY(data_request_callback);
|
||||
|
|
Loading…
Reference in a new issue