audio_out_manager.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * @oaram names - Output container to write names to.
  50. * @return Number of names written.
  51. */
  52. u32 GetAudioOutDeviceNames(
  53. std::vector<AudioRenderer::AudioDevice::AudioDeviceName>& names) const;
  54. /// Core system
  55. Core::System& system;
  56. /// Array of session ids
  57. std::array<size_t, MaxOutSessions> session_ids{};
  58. /// Array of resource user ids
  59. std::array<size_t, MaxOutSessions> applet_resource_user_ids{};
  60. /// Pointer to each open session
  61. std::array<std::shared_ptr<Out>, MaxOutSessions> sessions{};
  62. /// The number of free sessions
  63. size_t num_free_sessions{};
  64. /// The next session id to be taken
  65. size_t next_session_id{};
  66. /// The next session id to be freed
  67. size_t free_session_id{};
  68. /// Whether this is linked to the audio manager
  69. bool linked_to_manager{};
  70. /// Whether the sessions have been started
  71. bool sessions_started{};
  72. /// Protect state due to audio manager callback
  73. std::recursive_mutex mutex{};
  74. };
  75. } // namespace AudioCore::AudioOut