summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibAudio
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2022-02-20 01:44:18 -0700
committerLinus Groh <mail@linusgroh.de>2022-02-20 19:04:59 +0000
commitb92df530d3ab329f6a17531a13392decf1dcc6cf (patch)
treee9d8649ef3d97c721ad2de09d3dab7f761779856 /Userland/Libraries/LibAudio
parentfb179bc2893b9f98844dc672390a53b219a79f26 (diff)
downloadserenity-b92df530d3ab329f6a17531a13392decf1dcc6cf.zip
LibAudio: Simplify empty Audio::Buffer state to be truly empty
The old FIXME asserting that Core::AnonymousBuffer cannot be invalid or zero-sized is no longer accurate. Add a default constructor for Audio::Buffer that has all invalid state instead of going to the OS to allocate a 1 sample buffer for the "no more samples" states in the WAV and FLAC plugins.
Diffstat (limited to 'Userland/Libraries/LibAudio')
-rw-r--r--Userland/Libraries/LibAudio/Buffer.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/Userland/Libraries/LibAudio/Buffer.h b/Userland/Libraries/LibAudio/Buffer.h
index 0856d77450..f1dcf64df8 100644
--- a/Userland/Libraries/LibAudio/Buffer.h
+++ b/Userland/Libraries/LibAudio/Buffer.h
@@ -86,7 +86,7 @@ public:
static NonnullRefPtr<Buffer> create_empty()
{
// If we can't allocate an empty buffer, things are in a very bad state.
- return MUST(adopt_nonnull_ref_or_enomem(new (nothrow) Buffer(FixedArray<Sample>())));
+ return MUST(adopt_nonnull_ref_or_enomem(new (nothrow) Buffer));
}
Sample const* samples() const { return (const Sample*)data(); }
@@ -99,9 +99,7 @@ public:
private:
template<ArrayLike<Sample> ArrayT>
explicit Buffer(ArrayT&& samples)
- // FIXME: AnonymousBuffers can't be empty, so even for empty buffers we create a buffer of size 1 here,
- // although the sample count is set to 0 to mark this.
- : m_buffer(Core::AnonymousBuffer::create_with_size(max(samples.size(), 1) * sizeof(Sample)).release_value())
+ : m_buffer(Core::AnonymousBuffer::create_with_size(samples.size() * sizeof(Sample)).release_value())
, m_id(allocate_id())
, m_sample_count(samples.size())
{
@@ -115,11 +113,14 @@ private:
{
}
+ // Empty Buffer representation, to avoid tiny anonymous buffers in EOF states
+ Buffer() = default;
+
static i32 allocate_id();
Core::AnonymousBuffer m_buffer;
- const i32 m_id;
- const int m_sample_count;
+ const i32 m_id { -1 };
+ const int m_sample_count { 0 };
};
// This only works for double resamplers, and therefore cannot be part of the class