mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
This commit implements the functionality to play back audio through PlaybackManager. To decode the audio data, AudioDataProviders are created for each track in the provided media data. These providers will fill their audio block queue, then sit idle until their corresponding tracks are enabled. In order to output the audio, one AudioMixingSink is created which manages a PlaybackStream which requests audio blocks from multiple AudioDataProviders and mixes them into one buffer with sample-perfect precision.
62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2025, Gregory Bertilson <gregory@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FixedArray.h>
|
|
#include <AK/Time.h>
|
|
|
|
namespace Media {
|
|
|
|
class AudioBlock {
|
|
public:
|
|
using Data = FixedArray<float>;
|
|
|
|
u32 sample_rate() const { return m_sample_rate; }
|
|
u8 channel_count() const { return m_channel_count; }
|
|
AK::Duration start_timestamp() const { return m_start_timestamp; }
|
|
Data& data() { return m_data; }
|
|
Data const& data() const { return m_data; }
|
|
|
|
void clear()
|
|
{
|
|
m_sample_rate = 0;
|
|
m_channel_count = 0;
|
|
m_start_timestamp = AK::Duration::zero();
|
|
m_data = Data();
|
|
}
|
|
template<typename Callback>
|
|
void emplace(u32 sample_rate, u8 channel_count, AK::Duration start_timestamp, Callback data_callback)
|
|
{
|
|
VERIFY(sample_rate != 0);
|
|
VERIFY(channel_count != 0);
|
|
VERIFY(m_data.is_empty());
|
|
m_sample_rate = sample_rate;
|
|
m_channel_count = channel_count;
|
|
m_start_timestamp = start_timestamp;
|
|
data_callback(m_data);
|
|
}
|
|
bool is_empty() const
|
|
{
|
|
return m_sample_rate == 0;
|
|
}
|
|
size_t data_count() const
|
|
{
|
|
return data().size();
|
|
}
|
|
size_t sample_count() const
|
|
{
|
|
return data_count() / m_channel_count;
|
|
}
|
|
|
|
private:
|
|
u32 m_sample_rate { 0 };
|
|
u8 m_channel_count { 0 };
|
|
AK::Duration m_start_timestamp;
|
|
Data m_data;
|
|
};
|
|
|
|
}
|