diff options
| author | liamwhite <liamwhite@users.noreply.github.com> | 2022-07-23 15:20:39 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-23 15:20:39 -0400 |
| commit | 97729fd8e9c2f8cabc626ab03a666c9428e01c5e (patch) | |
| tree | f6a2f3b6c71b51a646d1502c01a4f6be92a3ed26 /src/audio_core/renderer/system_manager.h | |
| parent | 6c4e48dac40d5a9b7b9a8077d14b814df6032fd4 (diff) | |
| parent | 458da8a94877677f086f06cdeecf959ec4283a33 (diff) | |
Merge pull request #8545 from Kelebek1/Audio
Project Andio
Diffstat (limited to 'src/audio_core/renderer/system_manager.h')
| -rw-r--r-- | src/audio_core/renderer/system_manager.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/audio_core/renderer/system_manager.h b/src/audio_core/renderer/system_manager.h new file mode 100644 index 000000000..1291e9e0e --- /dev/null +++ b/src/audio_core/renderer/system_manager.h @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <list> +#include <memory> +#include <mutex> +#include <optional> +#include <thread> + +#include "audio_core/renderer/system.h" + +namespace Core { +namespace Timing { +struct EventType; +} +class System; +} // namespace Core + +namespace AudioCore::AudioRenderer { +namespace ADSP { +class ADSP; +class AudioRenderer_Mailbox; +} // namespace ADSP + +/** + * Manages all audio renderers, responsible for triggering command list generation and signalling + * the ADSP. + */ +class SystemManager { +public: + explicit SystemManager(Core::System& core); + ~SystemManager(); + + /** + * Initialize the system manager, called when any system is registered. + * + * @return True if sucessfully initialized, otherwise false. + */ + bool InitializeUnsafe(); + + /** + * Stop the system manager. + */ + void Stop(); + + /** + * Add an audio render system to the manager. + * The manager does not own the system, so do not free it without calling Remove. + * + * @param system - The system to add. + * @return True if succesfully added, otherwise false. + */ + bool Add(System& system); + + /** + * Remove an audio render system from the manager. + * + * @param system - The system to remove. + * @return True if succesfully removed, otherwise false. + */ + bool Remove(System& system); + +private: + /** + * Main thread responsible for command generation. + */ + void ThreadFunc(); + + /** + * Signalling core timing thread to run ThreadFunc. + */ + std::optional<std::chrono::nanoseconds> ThreadFunc2(s64 time); + + /** + * Callback from core timing when pausing, used to detect shutdowns and stop ThreadFunc. + * + * @param paused - Are we pausing or resuming? + */ + void PauseCallback(bool paused); + + enum class StreamState { + Filling, + Steady, + Draining, + }; + + /// Core system + Core::System& core; + /// List of pointers to managed systems + std::list<System*> systems{}; + /// Main worker thread for generating command lists + std::jthread thread; + /// Mutex for the systems + std::mutex mutex1{}; + /// Mutex for adding/removing systems + std::mutex mutex2{}; + /// Is the system manager thread active? + std::atomic<bool> active{}; + /// Reference to the ADSP for communication + ADSP::ADSP& adsp; + /// AudioRenderer mailbox for communication + ADSP::AudioRenderer_Mailbox* mailbox{}; + /// Core timing event to signal main thread + std::shared_ptr<Core::Timing::EventType> thread_event; + /// Atomic for main thread to wait on + std::atomic<bool> update{}; + /// Current state of the streams + StreamState state{StreamState::Filling}; +}; + +} // namespace AudioCore::AudioRenderer |
