mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-16 16:12:53 +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.
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FixedArray.h>
|
|
#include <AK/Function.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <LibAudio/Forward.h>
|
|
|
|
namespace Web::Platform {
|
|
|
|
class AudioCodecPlugin {
|
|
public:
|
|
using AudioCodecPluginCreator = Function<ErrorOr<NonnullOwnPtr<AudioCodecPlugin>>(NonnullRefPtr<Audio::Loader>)>;
|
|
|
|
static void install_creation_hook(AudioCodecPluginCreator);
|
|
static ErrorOr<NonnullOwnPtr<AudioCodecPlugin>> create(NonnullRefPtr<Audio::Loader>);
|
|
|
|
virtual ~AudioCodecPlugin();
|
|
|
|
static ErrorOr<FixedArray<Audio::Sample>> read_samples_from_loader(Audio::Loader&, size_t samples_to_load, size_t device_sample_rate);
|
|
static Duration current_loader_position(Audio::Loader const&, size_t device_sample_rate);
|
|
|
|
virtual void resume_playback() = 0;
|
|
virtual void pause_playback() = 0;
|
|
virtual void set_volume(double) = 0;
|
|
virtual void seek(double) = 0;
|
|
|
|
virtual Duration duration() = 0;
|
|
|
|
Function<void(Duration)> on_playback_position_updated;
|
|
|
|
protected:
|
|
AudioCodecPlugin();
|
|
};
|
|
|
|
}
|