1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:07:44 +00:00

AudioServer: Persist audio settings with a config file

AudioServer loads its settings, currently volume and mute state, from a
user config file "Audio.ini". Additionally, the current settings are
stored every ten seconds, if necessary. This allows for persistent audio
settings in between boots.
This commit is contained in:
kleines Filmröllchen 2021-07-25 20:54:09 +02:00 committed by Andreas Kling
parent 47bc72bcf6
commit d1b0143ba5
3 changed files with 58 additions and 4 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -16,6 +17,7 @@
#include <AK/WeakPtr.h>
#include <LibAudio/Buffer.h>
#include <LibCore/File.h>
#include <LibCore/Timer.h>
#include <LibThreading/Mutex.h>
#include <LibThreading/Thread.h>
@ -93,7 +95,7 @@ private:
class Mixer : public Core::Object {
C_OBJECT(Mixer)
public:
Mixer();
Mixer(NonnullRefPtr<Core::ConfigFile> config);
virtual ~Mixer() override;
NonnullRefPtr<BufferQueue> create_queue(ClientConnection&);
@ -105,6 +107,8 @@ public:
void set_muted(bool);
private:
void request_setting_sync();
Vector<NonnullRefPtr<BufferQueue>> m_pending_mixing;
Atomic<bool> m_added_queue { false };
pthread_mutex_t m_pending_mutex;
@ -117,8 +121,15 @@ private:
bool m_muted { false };
int m_main_volume { 100 };
NonnullRefPtr<Core::ConfigFile> m_config;
RefPtr<Core::Timer> m_config_write_timer;
static u8 m_zero_filled_buffer[4096];
void mix();
};
// Interval in ms when the server tries to save its configuration to disk.
constexpr unsigned AUDIO_CONFIG_WRITE_INTERVAL = 2000;
}