diff --git a/Userland/Services/WebContent/AudioCodecPluginSerenity.cpp b/Userland/Services/WebContent/AudioCodecPluginSerenity.cpp deleted file mode 100644 index cb5867050e..0000000000 --- a/Userland/Services/WebContent/AudioCodecPluginSerenity.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2023, Tim Flynn - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include - -namespace WebContent { - -// These constants and this implementation is based heavily on SoundPlayer::PlaybackManager. -static constexpr u32 UPDATE_RATE_MS = 50; -static constexpr u32 BUFFER_SIZE_MS = 100; -static constexpr size_t ALWAYS_ENQUEUED_BUFFER_COUNT = 5; - -ErrorOr> AudioCodecPluginSerenity::create(NonnullRefPtr loader) -{ - auto connection = TRY(Audio::ConnectionToServer::try_create()); - return adopt_nonnull_own_or_enomem(new (nothrow) AudioCodecPluginSerenity(move(connection), move(loader))); -} - -AudioCodecPluginSerenity::AudioCodecPluginSerenity(NonnullRefPtr connection, NonnullRefPtr loader) - : m_connection(move(connection)) - , m_loader(move(loader)) - , m_sample_timer(Web::Platform::Timer::create_repeating(UPDATE_RATE_MS, [this]() { - if (play_next_samples().is_error()) { - // FIXME: Propagate the error to the HTMLMediaElement. - } else { - if (on_playback_position_updated) - on_playback_position_updated(m_position); - } - })) -{ - auto duration = static_cast(m_loader->total_samples()) / static_cast(m_loader->sample_rate()); - m_duration = Duration::from_milliseconds(static_cast(duration * 1000.0)); - - m_samples_to_load_per_buffer = static_cast(BUFFER_SIZE_MS / 1000.0 * static_cast(m_loader->sample_rate())); - - m_connection->set_self_sample_rate(m_loader->sample_rate()); -} - -AudioCodecPluginSerenity::~AudioCodecPluginSerenity() = default; - -ErrorOr AudioCodecPluginSerenity::play_next_samples() -{ - while (m_connection->remaining_samples() < m_samples_to_load_per_buffer * ALWAYS_ENQUEUED_BUFFER_COUNT) { - bool all_samples_loaded = m_loader->loaded_samples() >= m_loader->total_samples(); - bool audio_server_done = m_connection->remaining_samples() == 0; - - if (all_samples_loaded && audio_server_done) { - pause_playback(); - - m_connection->clear_client_buffer(); - m_connection->async_clear_buffer(); - (void)m_loader->reset(); - - m_position = m_duration; - break; - } - - auto samples = TRY(read_samples_from_loader(m_loader, m_samples_to_load_per_buffer)); - TRY(m_connection->async_enqueue(move(samples))); - - m_position = current_loader_position(m_loader); - } - - return {}; -} - -void AudioCodecPluginSerenity::resume_playback() -{ - m_connection->async_start_playback(); - m_sample_timer->start(); -} - -void AudioCodecPluginSerenity::pause_playback() -{ - m_connection->async_pause_playback(); - m_sample_timer->stop(); -} - -void AudioCodecPluginSerenity::set_volume(double volume) -{ - m_connection->async_set_self_volume(volume); -} - -void AudioCodecPluginSerenity::seek(double position) -{ - m_position = set_loader_position(m_loader, position, m_duration); - - m_connection->clear_client_buffer(); - m_connection->async_clear_buffer(); - - if (on_playback_position_updated) - on_playback_position_updated(m_position); -} - -Duration AudioCodecPluginSerenity::duration() -{ - return m_duration; -} - -} diff --git a/Userland/Services/WebContent/AudioCodecPluginSerenity.h b/Userland/Services/WebContent/AudioCodecPluginSerenity.h deleted file mode 100644 index 2423f40d6c..0000000000 --- a/Userland/Services/WebContent/AudioCodecPluginSerenity.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023, Tim Flynn - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace WebContent { - -class AudioCodecPluginSerenity final : public Web::Platform::AudioCodecPlugin { -public: - static ErrorOr> create(NonnullRefPtr); - virtual ~AudioCodecPluginSerenity() override; - - virtual void resume_playback() override; - virtual void pause_playback() override; - virtual void set_volume(double) override; - virtual void seek(double) override; - - virtual Duration duration() override; - -private: - AudioCodecPluginSerenity(NonnullRefPtr, NonnullRefPtr); - - ErrorOr play_next_samples(); - - NonnullRefPtr m_connection; - NonnullRefPtr m_loader; - NonnullRefPtr m_sample_timer; - - Duration m_duration; - Duration m_position; - - size_t m_samples_to_load_per_buffer { 0 }; -}; - -} diff --git a/Userland/Services/WebContent/CMakeLists.txt b/Userland/Services/WebContent/CMakeLists.txt index 6980a21fc8..88095dc73b 100644 --- a/Userland/Services/WebContent/CMakeLists.txt +++ b/Userland/Services/WebContent/CMakeLists.txt @@ -11,7 +11,6 @@ compile_ipc(WebDriverClient.ipc WebDriverClientEndpoint.h) compile_ipc(WebDriverServer.ipc WebDriverServerEndpoint.h) set(SOURCES - AudioCodecPluginSerenity.cpp ConnectionFromClient.cpp ConsoleGlobalEnvironmentExtensions.cpp ImageCodecPluginSerenity.cpp diff --git a/Userland/Services/WebContent/main.cpp b/Userland/Services/WebContent/main.cpp index 91a7b1d5c2..4de66d6d67 100644 --- a/Userland/Services/WebContent/main.cpp +++ b/Userland/Services/WebContent/main.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "AudioCodecPluginSerenity.h" #include "ImageCodecPluginSerenity.h" #include #include @@ -16,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +48,7 @@ ErrorOr serenity_main(Main::Arguments) Web::Platform::FontPlugin::install(*new Web::Platform::FontPluginSerenity); Web::Platform::AudioCodecPlugin::install_creation_hook([](auto loader) { - return WebContent::AudioCodecPluginSerenity::create(move(loader)); + return Web::Platform::AudioCodecPluginAgnostic::create(move(loader)); }); Web::WebSockets::WebSocketClientManager::initialize(TRY(WebView::WebSocketClientManagerAdapter::try_create()));