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: [PATCH] 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. --- .../Applications/Piano/AudioPlayerLoop.cpp | 8 +++--- .../SoundPlayer/PlaybackManager.h | 6 ++--- Userland/Applications/SoundPlayer/Player.h | 2 +- .../SoundPlayerWidgetAdvancedView.cpp | 2 +- .../SoundPlayerWidgetAdvancedView.h | 2 +- .../SoundPlayer/VisualizationWidget.h | 2 +- Userland/Libraries/LibAudio/Buffer.cpp | 8 +++--- Userland/Libraries/LibAudio/Buffer.h | 26 +++++++++---------- .../LibAudio/ConnectionFromClient.cpp | 6 ++--- .../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 +-- .../AudioServer/ConnectionFromClient.cpp | 2 +- .../AudioServer/ConnectionFromClient.h | 2 +- Userland/Services/AudioServer/Mixer.cpp | 2 +- Userland/Services/AudioServer/Mixer.h | 6 ++--- 21 files changed, 54 insertions(+), 54 deletions(-) diff --git a/Userland/Applications/Piano/AudioPlayerLoop.cpp b/Userland/Applications/Piano/AudioPlayerLoop.cpp index 387a9f9622..390dd21e0d 100644 --- a/Userland/Applications/Piano/AudioPlayerLoop.cpp +++ b/Userland/Applications/Piano/AudioPlayerLoop.cpp @@ -9,8 +9,8 @@ #include "TrackManager.h" -// Converts Piano-internal data to an Audio::Buffer that AudioServer receives -static NonnullRefPtr music_samples_to_buffer(Array samples) +// Converts Piano-internal data to an Audio::LegacyBuffer that AudioServer receives +static NonnullRefPtr music_samples_to_buffer(Array samples) { Vector frames; frames.ensure_capacity(sample_count); @@ -19,7 +19,7 @@ static NonnullRefPtr music_samples_to_buffer(Array audio_buffer = music_samples_to_buffer(m_buffer); + NonnullRefPtr audio_buffer = music_samples_to_buffer(m_buffer); // FIXME: Handle OOM better. audio_buffer = MUST(Audio::resample_buffer(m_resampler.value(), *audio_buffer)); m_audio_client->async_enqueue(audio_buffer); diff --git a/Userland/Applications/SoundPlayer/PlaybackManager.h b/Userland/Applications/SoundPlayer/PlaybackManager.h index e4fa03eef6..b5c6862064 100644 --- a/Userland/Applications/SoundPlayer/PlaybackManager.h +++ b/Userland/Applications/SoundPlayer/PlaybackManager.h @@ -32,12 +32,12 @@ public: int last_seek() const { return m_last_seek; } bool is_paused() const { return m_paused; } float total_length() const { return m_total_length; } - RefPtr current_buffer() const { return m_current_buffer; } + RefPtr current_buffer() const { return m_current_buffer; } NonnullRefPtr connection() const { return m_connection; } Function on_update; - Function on_load_sample_buffer; + Function on_load_sample_buffer; Function on_finished_playing; private: @@ -56,7 +56,7 @@ private: size_t m_source_buffer_size_bytes { 0 }; RefPtr m_loader { nullptr }; NonnullRefPtr m_connection; - RefPtr m_current_buffer; + RefPtr m_current_buffer; Queue m_enqueued_buffers; Optional> m_resampler; RefPtr m_timer; diff --git a/Userland/Applications/SoundPlayer/Player.h b/Userland/Applications/SoundPlayer/Player.h index 86c199cf9d..6980f62e7e 100644 --- a/Userland/Applications/SoundPlayer/Player.h +++ b/Userland/Applications/SoundPlayer/Player.h @@ -72,7 +72,7 @@ public: virtual void volume_changed(double) = 0; virtual void mute_changed(bool) = 0; virtual void total_samples_changed(int) = 0; - virtual void sound_buffer_played(RefPtr, [[maybe_unused]] int sample_rate, [[maybe_unused]] int samples_played) = 0; + virtual void sound_buffer_played(RefPtr, [[maybe_unused]] int sample_rate, [[maybe_unused]] int samples_played) = 0; protected: void done_initializing() diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp index 0eabca66bd..f01d6c0a31 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp @@ -216,7 +216,7 @@ void SoundPlayerWidgetAdvancedView::total_samples_changed(int total_samples) m_playback_progress_slider->set_page_step(total_samples / 10); } -void SoundPlayerWidgetAdvancedView::sound_buffer_played(RefPtr buffer, int sample_rate, int samples_played) +void SoundPlayerWidgetAdvancedView::sound_buffer_played(RefPtr buffer, int sample_rate, int samples_played) { m_visualization->set_buffer(buffer); m_visualization->set_samplerate(sample_rate); diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h index 628d4a2f72..0701620b49 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h @@ -46,7 +46,7 @@ public: virtual void volume_changed(double) override; virtual void mute_changed(bool) override; virtual void total_samples_changed(int) override; - virtual void sound_buffer_played(RefPtr, int sample_rate, int samples_played) override; + virtual void sound_buffer_played(RefPtr, int sample_rate, int samples_played) override; protected: void keydown_event(GUI::KeyEvent&) override; diff --git a/Userland/Applications/SoundPlayer/VisualizationWidget.h b/Userland/Applications/SoundPlayer/VisualizationWidget.h index e11f233ab9..d38f8f937b 100644 --- a/Userland/Applications/SoundPlayer/VisualizationWidget.h +++ b/Userland/Applications/SoundPlayer/VisualizationWidget.h @@ -18,7 +18,7 @@ class VisualizationWidget : public GUI::Frame { public: virtual void render(GUI::PaintEvent&, FixedArray const& samples) = 0; - void set_buffer(RefPtr buffer) + void set_buffer(RefPtr buffer) { if (buffer.is_null()) return; 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); diff --git a/Userland/Services/AudioServer/ConnectionFromClient.cpp b/Userland/Services/AudioServer/ConnectionFromClient.cpp index d8f97f4bf6..0f4b457561 100644 --- a/Userland/Services/AudioServer/ConnectionFromClient.cpp +++ b/Userland/Services/AudioServer/ConnectionFromClient.cpp @@ -94,7 +94,7 @@ Messages::AudioServer::EnqueueBufferResponse ConnectionFromClient::enqueue_buffe return false; // There's not a big allocation to worry about here. - m_queue->enqueue(MUST(Audio::Buffer::create_with_anonymous_buffer(buffer, buffer_id, sample_count))); + m_queue->enqueue(MUST(Audio::LegacyBuffer::create_with_anonymous_buffer(buffer, buffer_id, sample_count))); return true; } diff --git a/Userland/Services/AudioServer/ConnectionFromClient.h b/Userland/Services/AudioServer/ConnectionFromClient.h index 1886d7859d..e744e75c3d 100644 --- a/Userland/Services/AudioServer/ConnectionFromClient.h +++ b/Userland/Services/AudioServer/ConnectionFromClient.h @@ -12,7 +12,7 @@ #include namespace Audio { -class Buffer; +class LegacyBuffer; } namespace AudioServer { diff --git a/Userland/Services/AudioServer/Mixer.cpp b/Userland/Services/AudioServer/Mixer.cpp index 98525d60ec..cd86c4ee0e 100644 --- a/Userland/Services/AudioServer/Mixer.cpp +++ b/Userland/Services/AudioServer/Mixer.cpp @@ -200,7 +200,7 @@ ClientAudioStream::ClientAudioStream(ConnectionFromClient& client) { } -void ClientAudioStream::enqueue(NonnullRefPtr&& buffer) +void ClientAudioStream::enqueue(NonnullRefPtr&& buffer) { m_remaining_samples += buffer->sample_count(); m_queue.enqueue(move(buffer)); diff --git a/Userland/Services/AudioServer/Mixer.h b/Userland/Services/AudioServer/Mixer.h index c207f687d5..ca24a77050 100644 --- a/Userland/Services/AudioServer/Mixer.h +++ b/Userland/Services/AudioServer/Mixer.h @@ -38,7 +38,7 @@ public: ~ClientAudioStream() = default; bool is_full() const { return m_queue.size() >= 3; } - void enqueue(NonnullRefPtr&&); + void enqueue(NonnullRefPtr&&); bool get_next_sample(Audio::Sample& sample) { @@ -97,8 +97,8 @@ public: void set_muted(bool muted) { m_muted = muted; } private: - RefPtr m_current; - Queue> m_queue; + RefPtr m_current; + Queue> m_queue; int m_position { 0 }; int m_remaining_samples { 0 }; int m_played_samples { 0 };