
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.
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
/*
|
|
* 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 };
|
|
};
|
|
|
|
}
|