mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
b4fbd30b70
This change was a long time in the making ever since we obtained sample rate awareness in the system. Now, each client has its own sample rate, accessible via new IPC APIs, and the device sample rate is only accessible via the management interface. AudioServer takes care of resampling client streams into the device sample rate. Therefore, the main improvement introduced with this commit is full responsiveness to sample rate changes; all open audio programs will continue to play at correct speed with the audio resampled to the new device rate. The immediate benefits are manifold: - Gets rid of the legacy hardware sample rate IPC message in the non-managing client - Removes duplicate resampling and sample index rescaling code everywhere - Avoids potential sample index scaling bugs in SoundPlayer (which have happened many times before) and fixes a sample index scaling bug in aplay - Removes several FIXMEs - Reduces amount of sample copying in all applications (especially Piano, where this is critical), improving performance - Reduces number of resampling users, making future API changes (which will need to happen for correct resampling to be implemented) easier I also threw in a simple race condition fix for Piano's audio player loop.
44 lines
1.2 KiB
C++
44 lines
1.2 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);
|
|
static Duration set_loader_position(Audio::Loader&, double position, Duration duration);
|
|
static Duration current_loader_position(Audio::Loader const&);
|
|
|
|
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();
|
|
};
|
|
|
|
}
|