From cb0e95c928e152d39dc60198ab714f437a2347ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Sun, 20 Feb 2022 13:18:38 +0100 Subject: LibAudio+Everywhere: Rename Audio::Buffer -> Audio::LegacyBuffer With the following change in how we send audio, the old Buffer type is not really needed anymore. However, moving WavLoader to the new system is a bit more involved and out of the scope of this PR. Therefore, we need to keep Buffer around, but to make it clear that it's the old buffer type which will be removed soon, we rename it to LegacyBuffer. Most of the users will be gone after the next commit anyways. --- Userland/Libraries/LibAudio/Buffer.cpp | 8 +++---- Userland/Libraries/LibAudio/Buffer.h | 26 +++++++++++----------- .../Libraries/LibAudio/ConnectionFromClient.cpp | 6 ++--- Userland/Libraries/LibAudio/ConnectionFromClient.h | 8 +++---- Userland/Libraries/LibAudio/FlacLoader.cpp | 4 ++-- Userland/Libraries/LibAudio/Loader.h | 2 +- Userland/Libraries/LibAudio/MP3Loader.cpp | 4 ++-- Userland/Libraries/LibAudio/Resampler.cpp | 4 ++-- Userland/Libraries/LibAudio/Resampler.h | 4 ++-- Userland/Libraries/LibAudio/WavLoader.cpp | 4 ++-- Userland/Libraries/LibAudio/WavLoader.h | 4 ++-- 11 files changed, 37 insertions(+), 37 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibAudio/Buffer.cpp b/Userland/Libraries/LibAudio/Buffer.cpp index 1152a6ade3..b313b500fe 100644 --- a/Userland/Libraries/LibAudio/Buffer.cpp +++ b/Userland/Libraries/LibAudio/Buffer.cpp @@ -13,7 +13,7 @@ namespace Audio { -i32 Buffer::allocate_id() +i32 LegacyBuffer::allocate_id() { static Atomic next_id; return next_id++; @@ -97,13 +97,13 @@ static double read_norm_sample_8(InputMemoryStream& stream) return double(sample) / NumericLimits::max(); } -ErrorOr> Buffer::from_pcm_data(ReadonlyBytes data, int num_channels, PcmSampleFormat sample_format) +ErrorOr> LegacyBuffer::from_pcm_data(ReadonlyBytes data, int num_channels, PcmSampleFormat sample_format) { InputMemoryStream stream { data }; return from_pcm_stream(stream, num_channels, sample_format, data.size() / (pcm_bits_per_sample(sample_format) / 8)); } -ErrorOr> Buffer::from_pcm_stream(InputMemoryStream& stream, int num_channels, PcmSampleFormat sample_format, int num_samples) +ErrorOr> LegacyBuffer::from_pcm_stream(InputMemoryStream& stream, int num_channels, PcmSampleFormat sample_format, int num_samples) { Vector fdata; fdata.ensure_capacity(num_samples); @@ -133,7 +133,7 @@ ErrorOr> Buffer::from_pcm_stream(InputMemoryStream& stream // don't belong. VERIFY(!stream.handle_any_error()); - return Buffer::create_with_samples(move(fdata)); + return LegacyBuffer::create_with_samples(move(fdata)); } } diff --git a/Userland/Libraries/LibAudio/Buffer.h b/Userland/Libraries/LibAudio/Buffer.h index cb05a06219..bf53291f45 100644 --- a/Userland/Libraries/LibAudio/Buffer.h +++ b/Userland/Libraries/LibAudio/Buffer.h @@ -28,23 +28,23 @@ namespace Audio { using namespace AK::Exponentials; // A buffer of audio samples. -class Buffer : public RefCounted { +class LegacyBuffer : public RefCounted { public: - static ErrorOr> from_pcm_data(ReadonlyBytes data, int num_channels, PcmSampleFormat sample_format); - static ErrorOr> from_pcm_stream(InputMemoryStream& stream, int num_channels, PcmSampleFormat sample_format, int num_samples); + static ErrorOr> from_pcm_data(ReadonlyBytes data, int num_channels, PcmSampleFormat sample_format); + static ErrorOr> from_pcm_stream(InputMemoryStream& stream, int num_channels, PcmSampleFormat sample_format, int num_samples); template ArrayT> - static ErrorOr> create_with_samples(ArrayT&& samples) + static ErrorOr> create_with_samples(ArrayT&& samples) { - return adopt_nonnull_ref_or_enomem(new (nothrow) Buffer(move(samples))); + return adopt_nonnull_ref_or_enomem(new (nothrow) LegacyBuffer(move(samples))); } - static ErrorOr> create_with_anonymous_buffer(Core::AnonymousBuffer buffer, i32 buffer_id, int sample_count) + static ErrorOr> create_with_anonymous_buffer(Core::AnonymousBuffer buffer, i32 buffer_id, int sample_count) { - return adopt_nonnull_ref_or_enomem(new (nothrow) Buffer(move(buffer), buffer_id, sample_count)); + return adopt_nonnull_ref_or_enomem(new (nothrow) LegacyBuffer(move(buffer), buffer_id, sample_count)); } - static NonnullRefPtr create_empty() + static NonnullRefPtr 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)); + return MUST(adopt_nonnull_ref_or_enomem(new (nothrow) LegacyBuffer)); } Sample const* samples() const { return (Sample const*)data(); } @@ -64,7 +64,7 @@ public: private: template ArrayT> - explicit Buffer(ArrayT&& samples) + explicit LegacyBuffer(ArrayT&& samples) : m_buffer(Core::AnonymousBuffer::create_with_size(samples.size() * sizeof(Sample)).release_value()) , m_id(allocate_id()) , m_sample_count(samples.size()) @@ -72,7 +72,7 @@ private: memcpy(m_buffer.data(), samples.data(), samples.size() * sizeof(Sample)); } - explicit Buffer(Core::AnonymousBuffer buffer, i32 buffer_id, int sample_count) + explicit LegacyBuffer(Core::AnonymousBuffer buffer, i32 buffer_id, int sample_count) : m_buffer(move(buffer)) , m_id(buffer_id) , m_sample_count(sample_count) @@ -80,7 +80,7 @@ private: } // Empty Buffer representation, to avoid tiny anonymous buffers in EOF states - Buffer() = default; + LegacyBuffer() = default; static i32 allocate_id(); @@ -90,6 +90,6 @@ private: }; // This only works for double resamplers, and therefore cannot be part of the class -ErrorOr> resample_buffer(ResampleHelper& resampler, Buffer const& to_resample); +ErrorOr> resample_buffer(ResampleHelper& resampler, LegacyBuffer const& to_resample); } diff --git a/Userland/Libraries/LibAudio/ConnectionFromClient.cpp b/Userland/Libraries/LibAudio/ConnectionFromClient.cpp index ae5ee7210b..77d747f862 100644 --- a/Userland/Libraries/LibAudio/ConnectionFromClient.cpp +++ b/Userland/Libraries/LibAudio/ConnectionFromClient.cpp @@ -19,7 +19,7 @@ ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr , public AudioClientEndpoint { IPC_CLIENT_CONNECTION(ConnectionFromClient, "/tmp/portal/audio") public: - void enqueue(Buffer const&); - bool try_enqueue(Buffer const&); - void async_enqueue(Buffer const&); + void enqueue(LegacyBuffer const&); + bool try_enqueue(LegacyBuffer const&); + void async_enqueue(LegacyBuffer const&); Function on_finish_playing_buffer; Function on_main_mix_muted_state_change; diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index cce821a5fb..3a504151ab 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -242,7 +242,7 @@ LoaderSamples FlacLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_i { ssize_t remaining_samples = static_cast(m_total_samples - m_loaded_samples); if (remaining_samples <= 0) - return Buffer::create_empty(); + return LegacyBuffer::create_empty(); // FIXME: samples_to_read is calculated wrong, because when seeking not all samples are loaded. size_t samples_to_read = min(max_bytes_to_read_from_input, remaining_samples); @@ -267,7 +267,7 @@ LoaderSamples FlacLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_i } m_loaded_samples += sample_index; - auto maybe_buffer = Buffer::create_with_samples(move(samples)); + auto maybe_buffer = LegacyBuffer::create_with_samples(move(samples)); if (maybe_buffer.is_error()) return LoaderError { LoaderError::Category::Internal, m_loaded_samples, "Couldn't allocate sample buffer" }; return maybe_buffer.release_value(); diff --git a/Userland/Libraries/LibAudio/Loader.h b/Userland/Libraries/LibAudio/Loader.h index bca513c083..4d5b68cdd0 100644 --- a/Userland/Libraries/LibAudio/Loader.h +++ b/Userland/Libraries/LibAudio/Loader.h @@ -22,7 +22,7 @@ namespace Audio { static constexpr StringView no_plugin_error = "No loader plugin available"; -using LoaderSamples = Result, LoaderError>; +using LoaderSamples = Result, LoaderError>; using MaybeLoaderError = Result; class LoaderPlugin { diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp index 60b6ab95a7..ca0199f805 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.cpp +++ b/Userland/Libraries/LibAudio/MP3Loader.cpp @@ -126,7 +126,7 @@ LoaderSamples MP3LoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_in auto maybe_frame = read_next_frame(); if (maybe_frame.is_error()) { if (m_input_stream->unreliable_eof()) { - return Buffer::create_empty(); + return LegacyBuffer::create_empty(); } return maybe_frame.release_error(); } @@ -156,7 +156,7 @@ LoaderSamples MP3LoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_in } m_loaded_samples += samples.size(); - auto maybe_buffer = Buffer::create_with_samples(move(samples)); + auto maybe_buffer = LegacyBuffer::create_with_samples(move(samples)); if (maybe_buffer.is_error()) return LoaderError { LoaderError::Category::Internal, m_loaded_samples, "Couldn't allocate sample buffer" }; return maybe_buffer.release_value(); diff --git a/Userland/Libraries/LibAudio/Resampler.cpp b/Userland/Libraries/LibAudio/Resampler.cpp index 35ed37c536..cfcd4589d1 100644 --- a/Userland/Libraries/LibAudio/Resampler.cpp +++ b/Userland/Libraries/LibAudio/Resampler.cpp @@ -10,7 +10,7 @@ namespace Audio { -ErrorOr> resample_buffer(ResampleHelper& resampler, Buffer const& to_resample) +ErrorOr> resample_buffer(ResampleHelper& resampler, LegacyBuffer const& to_resample) { Vector resampled; resampled.ensure_capacity(to_resample.sample_count() * ceil_div(resampler.source(), resampler.target())); @@ -22,7 +22,7 @@ ErrorOr> resample_buffer(ResampleHelper& resampler resampled.append(sample); } - return Buffer::create_with_samples(move(resampled)); + return LegacyBuffer::create_with_samples(move(resampled)); } } diff --git a/Userland/Libraries/LibAudio/Resampler.h b/Userland/Libraries/LibAudio/Resampler.h index c7c7328df8..2b48dbf888 100644 --- a/Userland/Libraries/LibAudio/Resampler.h +++ b/Userland/Libraries/LibAudio/Resampler.h @@ -84,7 +84,7 @@ private: SampleType m_last_sample_r {}; }; -class Buffer; -ErrorOr> resample_buffer(ResampleHelper& resampler, Buffer const& to_resample); +class LegacyBuffer; +ErrorOr> resample_buffer(ResampleHelper& resampler, LegacyBuffer const& to_resample); } diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp index 6168cf5926..d5fa8ee57e 100644 --- a/Userland/Libraries/LibAudio/WavLoader.cpp +++ b/Userland/Libraries/LibAudio/WavLoader.cpp @@ -53,7 +53,7 @@ LoaderSamples WavLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_in int remaining_samples = m_total_samples - m_loaded_samples; if (remaining_samples <= 0) - return Buffer::create_empty(); + return LegacyBuffer::create_empty(); // One "sample" contains data from all channels. // In the Wave spec, this is also called a block. @@ -78,7 +78,7 @@ LoaderSamples WavLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_in if (m_stream->handle_any_error()) return LoaderError { LoaderError::Category::IO, static_cast(m_loaded_samples), "Stream read error" }; - auto buffer = Buffer::from_pcm_data( + auto buffer = LegacyBuffer::from_pcm_data( sample_data.bytes(), m_num_channels, m_sample_format); diff --git a/Userland/Libraries/LibAudio/WavLoader.h b/Userland/Libraries/LibAudio/WavLoader.h index 50e97b5648..6faf3ccbbc 100644 --- a/Userland/Libraries/LibAudio/WavLoader.h +++ b/Userland/Libraries/LibAudio/WavLoader.h @@ -21,7 +21,7 @@ #include namespace Audio { -class Buffer; +class LegacyBuffer; // defines for handling the WAV header data #define WAVE_FORMAT_PCM 0x0001 // PCM @@ -30,7 +30,7 @@ class Buffer; #define WAVE_FORMAT_MULAW 0x0007 // 8-bit ITU-T G.711 ยต-law #define WAVE_FORMAT_EXTENSIBLE 0xFFFE // Determined by SubFormat -// Parses a WAV file and produces an Audio::Buffer. +// Parses a WAV file and produces an Audio::LegacyBuffer. class WavLoaderPlugin : public LoaderPlugin { public: explicit WavLoaderPlugin(StringView path); -- cgit v1.2.3