mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:27:35 +00:00
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.
This commit is contained in:
parent
fb179bc289
commit
b92df530d3
1 changed files with 7 additions and 6 deletions
|
@ -86,7 +86,7 @@ public:
|
||||||
static NonnullRefPtr<Buffer> create_empty()
|
static NonnullRefPtr<Buffer> create_empty()
|
||||||
{
|
{
|
||||||
// If we can't allocate an empty buffer, things are in a very bad state.
|
// 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(); }
|
Sample const* samples() const { return (const Sample*)data(); }
|
||||||
|
@ -99,9 +99,7 @@ public:
|
||||||
private:
|
private:
|
||||||
template<ArrayLike<Sample> ArrayT>
|
template<ArrayLike<Sample> ArrayT>
|
||||||
explicit Buffer(ArrayT&& samples)
|
explicit Buffer(ArrayT&& samples)
|
||||||
// FIXME: AnonymousBuffers can't be empty, so even for empty buffers we create a buffer of size 1 here,
|
: m_buffer(Core::AnonymousBuffer::create_with_size(samples.size() * sizeof(Sample)).release_value())
|
||||||
// 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_id(allocate_id())
|
, m_id(allocate_id())
|
||||||
, m_sample_count(samples.size())
|
, 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();
|
static i32 allocate_id();
|
||||||
|
|
||||||
Core::AnonymousBuffer m_buffer;
|
Core::AnonymousBuffer m_buffer;
|
||||||
const i32 m_id;
|
const i32 m_id { -1 };
|
||||||
const int m_sample_count;
|
const int m_sample_count { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
// This only works for double resamplers, and therefore cannot be part of the class
|
// This only works for double resamplers, and therefore cannot be part of the class
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue