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:
Timothy Flynn 2024-12-23 13:32:27 -05:00 committed by Andreas Kling
parent 4d866f22a4
commit dfa727a4d4
Notes: github-actions[bot] 2024-12-25 11:01:55 +00:00
4 changed files with 18 additions and 24 deletions

View file

@ -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
}
}

View file

@ -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 {};

View file

@ -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()>)

View file

@ -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);