audio_in_manager.h 2.4 KB

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