2022-07-17 00:48:45 +02:00
|
|
|
// 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
|
|
|
|
|
2023-08-31 16:09:15 +02:00
|
|
|
namespace AudioCore::ADSP {
|
2022-07-17 00:48:45 +02:00
|
|
|
class ADSP;
|
2023-08-31 16:09:15 +02:00
|
|
|
namespace AudioRenderer {
|
|
|
|
class AudioRenderer;
|
|
|
|
} // namespace AudioRenderer
|
|
|
|
} // namespace AudioCore::ADSP
|
|
|
|
|
|
|
|
namespace AudioCore::Renderer {
|
2022-07-17 00:48:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2023-03-12 04:10:38 +01:00
|
|
|
* @return True if successfully initialized, otherwise false.
|
2022-07-17 00:48:45 +02:00
|
|
|
*/
|
2023-08-31 16:09:15 +02:00
|
|
|
void InitializeUnsafe();
|
2022-07-17 00:48:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2023-03-12 04:10:38 +01:00
|
|
|
* @return True if successfully added, otherwise false.
|
2022-07-17 00:48:45 +02:00
|
|
|
*/
|
|
|
|
bool Add(System& system);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an audio render system from the manager.
|
|
|
|
*
|
|
|
|
* @param system - The system to remove.
|
2023-03-12 04:10:38 +01:00
|
|
|
* @return True if successfully removed, otherwise false.
|
2022-07-17 00:48:45 +02:00
|
|
|
*/
|
|
|
|
bool Remove(System& system);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Main thread responsible for command generation.
|
|
|
|
*/
|
2023-05-10 18:59:21 +02:00
|
|
|
void ThreadFunc(std::stop_token stop_token);
|
2022-07-17 00:48:45 +02:00
|
|
|
|
|
|
|
/// 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{};
|
2023-08-31 16:09:15 +02:00
|
|
|
/// Reference to the ADSP's AudioRenderer for communication
|
|
|
|
::AudioCore::ADSP::AudioRenderer::AudioRenderer& audio_renderer;
|
2022-07-17 00:48:45 +02:00
|
|
|
};
|
|
|
|
|
2023-08-31 16:09:15 +02:00
|
|
|
} // namespace AudioCore::Renderer
|