blob: 9681fd12192ea75b64338fe4fd6a3b65b4e0c305 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// 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 successfully 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 successfully added, otherwise false.
*/
bool Add(System& system);
/**
* Remove an audio render system from the manager.
*
* @param system - The system to remove.
* @return True if successfully removed, otherwise false.
*/
bool Remove(System& system);
private:
/**
* Main thread responsible for command generation.
*/
void ThreadFunc(std::stop_token stop_token);
/// 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{};
};
} // namespace AudioCore::AudioRenderer
|