1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:57:35 +00:00

LibWeb/Ladybird: Use the abstract audio output in a new audio plugin

The implementation of this plugin is meant to eventually replace all
current audio plugins in Ladybird. The benefits over the current Qt-
based audio playback plugin in Ladybird are:

- Low latency: With direct access to PulseAudio, we can ask for a
specific latency to output to allow minimal delay when pausing or
seeking a stream.
- Accurate timestamps: The Qt audio playback API does not expose audio
time properly. When we have access directly to PulseAudio APIs, we can
enable their timing interpolation to get an accurate monotonically-
increasing timestamp of the playing audio.
- Resiliency: With more control over how the underlying audio API is
called, we have the power to fix most bugs we might encounter. The
PulseAudio wrappers already avoid some bugs that occur with QAudioSink
when running through WSLg.
This commit is contained in:
Zaggy1024 2023-07-04 05:02:19 -05:00 committed by Andrew Kaster
parent bc4d4f0f95
commit ad440f9e9a
5 changed files with 225 additions and 0 deletions

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2023, Gregory Bertilson <zaggy1024@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibAudio/PlaybackStream.h>
#include <LibWeb/Platform/AudioCodecPlugin.h>
namespace Web::Platform {
class AudioCodecPluginAgnostic final : public AudioCodecPlugin {
public:
static ErrorOr<NonnullOwnPtr<AudioCodecPluginAgnostic>> create(NonnullRefPtr<Audio::Loader> const&);
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:
explicit AudioCodecPluginAgnostic(NonnullRefPtr<Audio::Loader> loader, Duration, NonnullRefPtr<Core::Timer> update_timer);
void update_timestamp();
NonnullRefPtr<Audio::Loader> m_loader;
RefPtr<Audio::PlaybackStream> m_output { nullptr };
Duration m_duration { Duration::zero() };
Duration m_last_resume_in_media_time { Duration::zero() };
Duration m_last_resume_in_device_time { Duration::zero() };
Duration m_last_good_device_time { Duration::zero() };
Core::EventLoop& m_main_thread_event_loop;
NonnullRefPtr<Core::Timer> m_update_timer;
bool m_paused { true };
};
}