mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 15:27:34 +00:00
Ladybird+LibWeb+WebConent: Drive audio in Ladybird off the main thread
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.
This commit is contained in:
parent
0fd35b4dd8
commit
1c4dd0caad
10 changed files with 383 additions and 205 deletions
|
@ -8,37 +8,35 @@
|
|||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <LibAudio/Forward.h>
|
||||
#include <LibWeb/Platform/AudioCodecPlugin.h>
|
||||
|
||||
class QAudioSink;
|
||||
class QIODevice;
|
||||
class QMediaDevices;
|
||||
#include <QObject>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
class AudioCodecPluginLadybird final : public Web::Platform::AudioCodecPlugin {
|
||||
class AudioThread;
|
||||
|
||||
class AudioCodecPluginLadybird final
|
||||
: public QObject
|
||||
, public Web::Platform::AudioCodecPlugin {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullOwnPtr<AudioCodecPluginLadybird>> create();
|
||||
static ErrorOr<NonnullOwnPtr<AudioCodecPluginLadybird>> create(NonnullRefPtr<Audio::Loader>);
|
||||
virtual ~AudioCodecPluginLadybird() override;
|
||||
|
||||
virtual size_t device_sample_rate() override;
|
||||
|
||||
virtual void enqueue_samples(FixedArray<Audio::Sample>) override;
|
||||
virtual size_t remaining_samples() const override;
|
||||
|
||||
virtual void resume_playback() override;
|
||||
virtual void pause_playback() override;
|
||||
virtual void playback_ended() override;
|
||||
|
||||
virtual void set_volume(double) override;
|
||||
virtual void seek(double) override;
|
||||
|
||||
virtual Duration duration() override;
|
||||
|
||||
private:
|
||||
AudioCodecPluginLadybird(NonnullOwnPtr<QMediaDevices>, NonnullOwnPtr<QAudioSink>);
|
||||
explicit AudioCodecPluginLadybird(NonnullOwnPtr<AudioThread>);
|
||||
|
||||
NonnullOwnPtr<QMediaDevices> m_devices;
|
||||
NonnullOwnPtr<QAudioSink> m_audio_output;
|
||||
QIODevice* m_io_device { nullptr };
|
||||
NonnullOwnPtr<AudioThread> m_audio_thread;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue