audio_out_manager.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <mutex>
  6. #include "audio_core/renderer/audio_device.h"
  7. namespace Core {
  8. class System;
  9. }
  10. namespace AudioCore::AudioOut {
  11. class Out;
  12. constexpr size_t MaxOutSessions = 12;
  13. /**
  14. * Manages all audio out sessions.
  15. */
  16. class Manager {
  17. public:
  18. explicit Manager(Core::System& system);
  19. /**
  20. * Acquire a free session id for opening a new audio out.
  21. *
  22. * @param session_id - Output session_id.
  23. * @return Result code.
  24. */
  25. Result AcquireSessionId(size_t& session_id);
  26. /**
  27. * Release a session id on close.
  28. *
  29. * @param session_id - Session id to free.
  30. */
  31. void ReleaseSessionId(size_t session_id);
  32. /**
  33. * Link this manager to the main audio manager.
  34. *
  35. * @return Result code.
  36. */
  37. Result LinkToManager();
  38. /**
  39. * Start the audio out manager.
  40. */
  41. void Start();
  42. /**
  43. * Callback function, called by the audio manager when the audio out event is signalled.
  44. */
  45. void BufferReleaseAndRegister();
  46. /**
  47. * Get a list of audio out device names.
  48. *
  49. * @param names - Output container to write names to.
  50. * @return Number of names written.
  51. */
  52. u32 GetAudioOutDeviceNames(std::vector<Renderer::AudioDevice::AudioDeviceName>& names) const;
  53. /// Core system
  54. Core::System& system;
  55. /// Array of session ids
  56. std::array<size_t, MaxOutSessions> session_ids{};
  57. /// Array of resource user ids
  58. std::array<size_t, MaxOutSessions> applet_resource_user_ids{};
  59. /// Pointer to each open session
  60. std::array<std::shared_ptr<Out>, MaxOutSessions> sessions{};
  61. /// The number of free sessions
  62. size_t num_free_sessions{};
  63. /// The next session id to be taken
  64. size_t next_session_id{};
  65. /// The next session id to be freed
  66. size_t free_session_id{};
  67. /// Whether this is linked to the audio manager
  68. bool linked_to_manager{};
  69. /// Whether the sessions have been started
  70. bool sessions_started{};
  71. /// Protect state due to audio manager callback
  72. std::recursive_mutex mutex{};
  73. };
  74. } // namespace AudioCore::AudioOut