mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +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.
52 lines
1.6 KiB
C++
52 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <AudioServer/AudioClientEndpoint.h>
|
|
#include <AudioServer/AudioServerEndpoint.h>
|
|
#include <LibAudio/Queue.h>
|
|
#include <LibCore/EventLoop.h>
|
|
#include <LibIPC/ConnectionFromClient.h>
|
|
|
|
namespace AudioServer {
|
|
|
|
class ClientAudioStream;
|
|
class Mixer;
|
|
|
|
class ConnectionFromClient final : public IPC::ConnectionFromClient<AudioClientEndpoint, AudioServerEndpoint> {
|
|
C_OBJECT(ConnectionFromClient)
|
|
public:
|
|
~ConnectionFromClient() override = default;
|
|
|
|
void did_change_client_volume(Badge<ClientAudioStream>, double volume);
|
|
|
|
virtual void die() override;
|
|
|
|
static void for_each(Function<void(ConnectionFromClient&)>);
|
|
|
|
private:
|
|
explicit ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>, int client_id, Mixer& mixer);
|
|
|
|
virtual Messages::AudioServer::GetSelfVolumeResponse get_self_volume() override;
|
|
virtual void set_self_volume(double) override;
|
|
virtual void set_buffer(Audio::AudioQueue const&) override;
|
|
virtual void clear_buffer() override;
|
|
virtual void start_playback() override;
|
|
virtual void pause_playback() override;
|
|
virtual Messages::AudioServer::IsSelfMutedResponse is_self_muted() override;
|
|
virtual void set_self_muted(bool) override;
|
|
virtual Messages::AudioServer::GetSelfSampleRateResponse get_self_sample_rate() override;
|
|
virtual void set_self_sample_rate(u32 sample_rate) override;
|
|
|
|
Mixer& m_mixer;
|
|
RefPtr<ClientAudioStream> m_queue;
|
|
Optional<u32> m_saved_sample_rate {};
|
|
};
|
|
|
|
}
|