mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:37:35 +00:00
Ladybird+LibWeb+WebContent: Create a platform plugin for playing audio
This creates (and installs upon WebContent startup) a platform plugin to play audio data. On Serenity, we use AudioServer to play audio over IPC. Unfortunately, AudioServer is currently coupled with Serenity's audio devices, and thus cannot be used in Ladybird on Lagom. Instead, we use a Qt audio device to play the audio, which requires the Qt multimedia package. While we use Qt to play the audio, note that we can still use LibAudio to decode the audio data and retrieve samples - we simply send Qt the raw PCM signals.
This commit is contained in:
parent
ee48d7514f
commit
a34e369252
15 changed files with 317 additions and 9 deletions
59
Userland/Services/WebContent/AudioCodecPluginSerenity.cpp
Normal file
59
Userland/Services/WebContent/AudioCodecPluginSerenity.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibAudio/ConnectionToServer.h>
|
||||
#include <WebContent/AudioCodecPluginSerenity.h>
|
||||
|
||||
namespace WebContent {
|
||||
|
||||
ErrorOr<NonnullOwnPtr<AudioCodecPluginSerenity>> AudioCodecPluginSerenity::create()
|
||||
{
|
||||
auto connection = TRY(Audio::ConnectionToServer::try_create());
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) AudioCodecPluginSerenity(move(connection)));
|
||||
}
|
||||
|
||||
AudioCodecPluginSerenity::AudioCodecPluginSerenity(NonnullRefPtr<Audio::ConnectionToServer> connection)
|
||||
: m_connection(move(connection))
|
||||
{
|
||||
}
|
||||
|
||||
AudioCodecPluginSerenity::~AudioCodecPluginSerenity() = default;
|
||||
|
||||
size_t AudioCodecPluginSerenity::device_sample_rate()
|
||||
{
|
||||
if (!m_device_sample_rate.has_value())
|
||||
m_device_sample_rate = m_connection->get_sample_rate();
|
||||
return *m_device_sample_rate;
|
||||
}
|
||||
|
||||
void AudioCodecPluginSerenity::enqueue_samples(FixedArray<Audio::Sample> samples)
|
||||
{
|
||||
m_connection->async_enqueue(move(samples)).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
||||
size_t AudioCodecPluginSerenity::remaining_samples() const
|
||||
{
|
||||
return m_connection->remaining_samples();
|
||||
}
|
||||
|
||||
void AudioCodecPluginSerenity::resume_playback()
|
||||
{
|
||||
m_connection->async_start_playback();
|
||||
}
|
||||
|
||||
void AudioCodecPluginSerenity::pause_playback()
|
||||
{
|
||||
m_connection->async_start_playback();
|
||||
}
|
||||
|
||||
void AudioCodecPluginSerenity::playback_ended()
|
||||
{
|
||||
m_connection->async_pause_playback();
|
||||
m_connection->clear_client_buffer();
|
||||
m_connection->async_clear_buffer();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue