audio_render_manager.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <memory>
  6. #include <mutex>
  7. #include "common/polyfill_thread.h"
  8. #include "audio_core/common/common.h"
  9. #include "audio_core/renderer/system_manager.h"
  10. #include "core/hle/service/audio/errors.h"
  11. namespace Core {
  12. class System;
  13. }
  14. namespace AudioCore {
  15. struct AudioRendererParameterInternal;
  16. namespace AudioRenderer {
  17. /**
  18. * Wrapper for the audio system manager, handles service calls.
  19. */
  20. class Manager {
  21. public:
  22. explicit Manager(Core::System& system);
  23. ~Manager();
  24. /**
  25. * Stop the manager.
  26. */
  27. void Stop();
  28. /**
  29. * Get the system manager.
  30. *
  31. * @return The system manager.
  32. */
  33. SystemManager& GetSystemManager();
  34. /**
  35. * Get required size for the audio renderer workbuffer.
  36. *
  37. * @param params - Input parameters with the numbers of voices/mixes/sinks etc.
  38. * @param out_count - Output size of the required workbuffer.
  39. * @return Result code.
  40. */
  41. Result GetWorkBufferSize(const AudioRendererParameterInternal& params, u64& out_count) const;
  42. /**
  43. * Get a new session id.
  44. *
  45. * @return The new session id. -1 if invalid, otherwise 0-MaxRendererSessions.
  46. */
  47. s32 GetSessionId();
  48. /**
  49. * Get the number of currently active sessions.
  50. *
  51. * @return The number of active sessions.
  52. */
  53. u32 GetSessionCount() const;
  54. /**
  55. * Add a renderer system to the manager.
  56. * The system will be regularly called to generate commands for the AudioRenderer.
  57. *
  58. * @param system - The system to add.
  59. * @return True if the system was successfully added, otherwise false.
  60. */
  61. bool AddSystem(System& system);
  62. /**
  63. * Remove a renderer system from the manager.
  64. *
  65. * @param system - The system to remove.
  66. * @return True if the system was successfully removed, otherwise false.
  67. */
  68. bool RemoveSystem(System& system);
  69. /**
  70. * Free a session id when the system wants to shut down.
  71. *
  72. * @param session_id - The session id to free.
  73. */
  74. void ReleaseSessionId(s32 session_id);
  75. private:
  76. /// Core system
  77. Core::System& system;
  78. /// Session ids, -1 when in use
  79. std::array<s32, MaxRendererSessions> session_ids{};
  80. /// Number of active renderers
  81. u32 session_count{};
  82. /// Lock for interacting with the sessions
  83. mutable std::mutex session_lock{};
  84. /// Regularly generates commands from the registered systems for the AudioRenderer
  85. std::unique_ptr<SystemManager> system_manager{};
  86. };
  87. } // namespace AudioRenderer
  88. } // namespace AudioCore