mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-04-19 02:57:23 +00:00
The main thread in the WebContent process is often busy with layout and running JavaScript. This can cause audio to sound jittery and crack. To avoid this behavior, we now drive audio on a secondary thread. Note: Browser on Serenity uses AudioServer, the connection for which is already handled on a secondary thread within LibAudio. So this only applies to Lagom. Rather than using LibThreading, our hands are tied to QThread for now. Internally, the Qt media objects use a QTimer, which is forbidden from running on a thread that is not a QThread (the debug console is spammed with messages pointing this out). Ideally, in the future AudioServer will be able to run for non-Serenity platforms, and most of this can be aligned with the Serenity implementation.
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/Time.h>
|
|
#include <LibAudio/Forward.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/Platform/AudioCodecPlugin.h>
|
|
|
|
namespace WebContent {
|
|
|
|
class AudioCodecPluginSerenity final : public Web::Platform::AudioCodecPlugin {
|
|
public:
|
|
static ErrorOr<NonnullOwnPtr<AudioCodecPluginSerenity>> create(NonnullRefPtr<Audio::Loader>);
|
|
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<Audio::ConnectionToServer>, NonnullRefPtr<Audio::Loader>);
|
|
|
|
ErrorOr<void> play_next_samples();
|
|
|
|
NonnullRefPtr<Audio::ConnectionToServer> m_connection;
|
|
NonnullRefPtr<Audio::Loader> m_loader;
|
|
NonnullRefPtr<Web::Platform::Timer> m_sample_timer;
|
|
|
|
Duration m_duration;
|
|
Duration m_position;
|
|
|
|
size_t m_device_sample_rate { 0 };
|
|
size_t m_device_samples_per_buffer { 0 };
|
|
size_t m_samples_to_load_per_buffer { 0 };
|
|
};
|
|
|
|
}
|