2023-08-06 09:59:47 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, Gregory Bertilson <zaggy1024@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/Math.h>
|
|
|
|
#include <AK/MemoryStream.h>
|
|
|
|
#include <AK/WeakPtr.h>
|
|
|
|
#include <LibAudio/PlaybackStream.h>
|
2023-08-03 03:05:47 +03:00
|
|
|
#include <LibCore/EventLoop.h>
|
2023-08-06 09:59:47 +03:00
|
|
|
#include <LibTest/TestSuite.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#if defined(HAVE_PULSEAUDIO)
|
|
|
|
# include <LibAudio/PulseAudioWrappers.h>
|
|
|
|
#endif
|
|
|
|
|
2023-08-03 03:05:47 +03:00
|
|
|
// FIXME: CI doesn't run an AudioServer currently. Creating one in /etc/SystemServer.ini does not
|
|
|
|
// allow this test to pass since CI runs in a Shell that will setsid() if it finds that the
|
|
|
|
// current session ID is 0, and AudioServer's socket address depends on the current sid.
|
|
|
|
// If we can fix that, this test can run on CI.
|
|
|
|
// https://github.com/SerenityOS/serenity/issues/20538
|
|
|
|
#if defined(AK_OS_SERENITY)
|
|
|
|
# define STREAM_TEST BENCHMARK_CASE
|
|
|
|
#else
|
|
|
|
# define STREAM_TEST TEST_CASE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
STREAM_TEST(create_and_destroy_playback_stream)
|
2023-08-06 09:59:47 +03:00
|
|
|
{
|
2023-08-03 03:05:47 +03:00
|
|
|
Core::EventLoop event_loop;
|
|
|
|
|
2023-08-06 09:59:47 +03:00
|
|
|
bool has_implementation = false;
|
2023-09-08 20:16:50 +03:00
|
|
|
#if defined(AK_OS_SERENITY) || defined(HAVE_PULSEAUDIO) || defined(AK_OS_MACOS)
|
2023-08-06 09:59:47 +03:00
|
|
|
has_implementation = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{
|
|
|
|
auto stream_result = Audio::PlaybackStream::create(Audio::OutputState::Playing, 44100, 2, 100, [](Bytes buffer, Audio::PcmSampleFormat format, size_t sample_count) -> ReadonlyBytes {
|
|
|
|
VERIFY(format == Audio::PcmSampleFormat::Float32);
|
|
|
|
FixedMemoryStream writing_stream { buffer };
|
|
|
|
|
|
|
|
for (size_t i = 0; i < sample_count; i++) {
|
|
|
|
MUST(writing_stream.write_value(0.0f));
|
|
|
|
MUST(writing_stream.write_value(0.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer.trim(writing_stream.offset());
|
|
|
|
});
|
|
|
|
EXPECT_EQ(!stream_result.is_error(), has_implementation);
|
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HAVE_PULSEAUDIO)
|
|
|
|
VERIFY(!Audio::PulseAudioContext::weak_instance());
|
|
|
|
#endif
|
|
|
|
}
|