summaryrefslogtreecommitdiffstats
path: root/src/audio_core/audio_render_manager.h
blob: bf483719036207b5a55a2124afeb4cf7c99a7533 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <array>
#include <memory>
#include <mutex>

#include "audio_core/common/common.h"
#include "audio_core/renderer/system_manager.h"
#include "core/hle/service/audio/errors.h"

namespace Core {
class System;
}

namespace AudioCore {
struct AudioRendererParameterInternal;

namespace AudioRenderer {
/**
 * Wrapper for the audio system manager, handles service calls.
 */
class Manager {
public:
    explicit Manager(Core::System& system);
    ~Manager();

    /**
     * Stop the manager.
     */
    void Stop();

    /**
     * Get the system manager.
     *
     * @return The system manager.
     */
    SystemManager& GetSystemManager();

    /**
     * Get required size for the audio renderer workbuffer.
     *
     * @param params    - Input parameters with the numbers of voices/mixes/sinks etc.
     * @param out_count - Output size of the required workbuffer.
     * @return Result code.
     */
    Result GetWorkBufferSize(const AudioRendererParameterInternal& params, u64& out_count) const;

    /**
     * Get a new session id.
     *
     * @return The new session id. -1 if invalid, otherwise 0-MaxRendererSessions.
     */
    s32 GetSessionId();

    /**
     * Get the number of currently active sessions.
     *
     * @return The number of active sessions.
     */
    u32 GetSessionCount() const;

    /**
     * Add a renderer system to the manager.
     * The system will be regularly called to generate commands for the AudioRenderer.
     *
     * @param system - The system to add.
     * @return True if the system was successfully added, otherwise false.
     */
    bool AddSystem(System& system);

    /**
     * Remove a renderer system from the manager.
     *
     * @param system - The system to remove.
     * @return True if the system was successfully removed, otherwise false.
     */
    bool RemoveSystem(System& system);

    /**
     * Free a session id when the system wants to shut down.
     *
     * @param session_id - The session id to free.
     */
    void ReleaseSessionId(s32 session_id);

private:
    /// Core system
    Core::System& system;
    /// Session ids, -1 when in use
    std::array<s32, MaxRendererSessions> session_ids{};
    /// Number of active renderers
    u32 session_count{};
    /// Lock for interacting with the sessions
    mutable std::mutex session_lock{};
    /// Regularly generates commands from the registered systems for the AudioRenderer
    std::unique_ptr<SystemManager> system_manager{};
};

} // namespace AudioRenderer
} // namespace AudioCore