From 3ed25005c74a9d4ccf6e3487814e5d47de31633f Mon Sep 17 00:00:00 2001 From: lizzie Date: Fri, 23 Jan 2026 22:03:20 +0000 Subject: [PATCH] [audio] remove recursive_mutex, replace with std::mutex<> Signed-off-by: lizzie --- src/audio_core/audio_in_manager.h | 2 +- src/audio_core/audio_out_manager.h | 2 +- src/audio_core/device/audio_buffers.h | 4 +- src/audio_core/device/device_session.cpp | 4 - src/audio_core/device/device_session.h | 4 +- src/audio_core/in/audio_in.cpp | 13 +-- src/audio_core/in/audio_in.h | 115 +++++++---------------- src/audio_core/out/audio_out.h | 114 +++++++--------------- 8 files changed, 84 insertions(+), 174 deletions(-) diff --git a/src/audio_core/audio_in_manager.h b/src/audio_core/audio_in_manager.h index 2179990e0d..700d96c181 100644 --- a/src/audio_core/audio_in_manager.h +++ b/src/audio_core/audio_in_manager.h @@ -85,7 +85,7 @@ public: /// Whether the sessions have been started bool sessions_started{}; /// Protect state due to audio manager callback - std::recursive_mutex mutex{}; + std::mutex mutex{}; }; } // namespace AudioCore::AudioIn diff --git a/src/audio_core/audio_out_manager.h b/src/audio_core/audio_out_manager.h index c3e445d5d3..f2f4faf50a 100644 --- a/src/audio_core/audio_out_manager.h +++ b/src/audio_core/audio_out_manager.h @@ -82,7 +82,7 @@ public: /// Whether the sessions have been started bool sessions_started{}; /// Protect state due to audio manager callback - std::recursive_mutex mutex{}; + std::mutex mutex{}; }; } // namespace AudioCore::AudioOut diff --git a/src/audio_core/device/audio_buffers.h b/src/audio_core/device/audio_buffers.h index 34a396e2dc..4add6fd182 100644 --- a/src/audio_core/device/audio_buffers.h +++ b/src/audio_core/device/audio_buffers.h @@ -33,7 +33,7 @@ constexpr s32 BufferAppendLimit = 4; template class AudioBuffers { public: - explicit AudioBuffers(size_t limit) : append_limit{static_cast(limit)} {} + explicit AudioBuffers(size_t limit) : append_limit{u32(limit)} {} /** * Append a new audio buffer to the ring. @@ -308,7 +308,7 @@ public: private: /// Buffer lock - mutable std::recursive_mutex lock{}; + mutable std::mutex lock{}; /// The audio buffers std::array buffers{}; /// Current released index diff --git a/src/audio_core/device/device_session.cpp b/src/audio_core/device/device_session.cpp index 2a1ae1bb3f..b8045b3043 100644 --- a/src/audio_core/device/device_session.cpp +++ b/src/audio_core/device/device_session.cpp @@ -123,10 +123,6 @@ void DeviceSession::SetVolume(f32 volume) const { } } -u64 DeviceSession::GetPlayedSampleCount() const { - return played_sample_count; -} - std::optional DeviceSession::ThreadFunc() { played_sample_count = stream->GetExpectedPlayedSampleCount(); if (type == Sink::StreamType::Out) { diff --git a/src/audio_core/device/device_session.h b/src/audio_core/device/device_session.h index f3fae26175..5f59735804 100644 --- a/src/audio_core/device/device_session.h +++ b/src/audio_core/device/device_session.h @@ -112,7 +112,9 @@ public: * * @return Samples played by this session. */ - u64 GetPlayedSampleCount() const; + u64 GetPlayedSampleCount() const noexcept { + return played_sample_count; + } /* * CoreTiming callback to increment played_sample_count over time. diff --git a/src/audio_core/in/audio_in.cpp b/src/audio_core/in/audio_in.cpp index df8c44d1f2..e52678ce09 100644 --- a/src/audio_core/in/audio_in.cpp +++ b/src/audio_core/in/audio_in.cpp @@ -8,15 +8,18 @@ namespace AudioCore::AudioIn { In::In(Core::System& system_, Manager& manager_, Kernel::KEvent* event_, size_t session_id_) - : manager{manager_}, parent_mutex{manager.mutex}, event{event_}, system{system_, event, - session_id_} {} + : manager{manager_} + , parent_mutex{manager.mutex} + , event{event_} + , system{system_, event, session_id_} +{} void In::Free() { std::scoped_lock l{parent_mutex}; manager.ReleaseSessionId(system.GetSessionId()); } -System& In::GetSystem() { +System& In::GetSystem() noexcept { return system; } @@ -42,10 +45,8 @@ Result In::StopSystem() { Result In::AppendBuffer(const AudioInBuffer& buffer, u64 tag) { std::scoped_lock l{parent_mutex}; - - if (system.AppendBuffer(buffer, tag)) { + if (system.AppendBuffer(buffer, tag)) return ResultSuccess; - } return Service::Audio::ResultBufferCountReached; } diff --git a/src/audio_core/in/audio_in.h b/src/audio_core/in/audio_in.h index 092ab72369..f983d836e6 100644 --- a/src/audio_core/in/audio_in.h +++ b/src/audio_core/in/audio_in.h @@ -19,125 +19,80 @@ class KReadableEvent; namespace AudioCore::AudioIn { class Manager; -/** - * Interface between the service and audio in system. Mainly responsible for forwarding service - * calls to the system. - */ +/// @brief Interface between the service and audio in system. Mainly responsible for forwarding service +/// calls to the system. class In { public: explicit In(Core::System& system, Manager& manager, Kernel::KEvent* event, size_t session_id); - /** - * Free this audio in from the audio in manager. - */ + /// @brief Free this audio in from the audio in manager. void Free(); - /** - * Get this audio in's system. - */ - System& GetSystem(); + /// @brief Get this audio in's system. + System& GetSystem() noexcept; - /** - * Get the current state. - * - * @return Started or Stopped. - */ + /// @brief Get the current state. + /// @return Started or Stopped. AudioIn::State GetState(); - /** - * Start the system - * - * @return Result code - */ + /// @brief Start the system + /// @return Result code Result StartSystem(); - /** - * Start the system's device session. - */ + /// @brief Start the system's device session. void StartSession(); - /** - * Stop the system. - * - * @return Result code - */ + /// @brief Stop the system. + /// @return Result code Result StopSystem(); - /** - * Append a new buffer to the system, the buffer event will be signalled when it is filled. - * - * @param buffer - The new buffer to append. - * @param tag - Unique tag for this buffer. - * @return Result code. - */ + /// @brief Append a new buffer to the system, the buffer event will be signalled when it is filled. + /// @param buffer - The new buffer to append. + /// @param tag - Unique tag for this buffer. + /// @return Result code. Result AppendBuffer(const AudioInBuffer& buffer, u64 tag); - /** - * Release all completed buffers, and register any appended. - */ + /// @brief Release all completed buffers, and register any appended. void ReleaseAndRegisterBuffers(); - /** - * Flush all buffers. - */ + /// @brief Flush all buffers. bool FlushAudioInBuffers(); - /** - * Get all of the currently released buffers. - * - * @param tags - Output container for the buffer tags which were released. - * @return The number of buffers released. - */ + /// @brief Get all of the currently released buffers. + /// @param tags - Output container for the buffer tags which were released. + /// @return The number of buffers released. u32 GetReleasedBuffers(std::span tags); - /** - * Get the buffer event for this audio in, this event will be signalled when a buffer is filled. - * - * @return The buffer event. - */ + /// @brief Get the buffer event for this audio in, this event will be signalled when a buffer is filled. + /// @return The buffer event. Kernel::KReadableEvent& GetBufferEvent(); - /** - * Get the current system volume. - * - * @return The current volume. - */ + /// @brief Get the current system volume. + /// @return The current volume. f32 GetVolume() const; - /** - * Set the system volume. - * - * @param volume - The volume to set. - */ + /// @brief Set the system volume. + /// @param volume - The volume to set. void SetVolume(f32 volume); - /** - * Check if a buffer is in the system. - * - * @param tag - The tag to search for. - * @return True if the buffer is in the system, otherwise false. - */ + /// @brief Check if a buffer is in the system. + /// @param tag - The tag to search for. + /// @return True if the buffer is in the system, otherwise false. bool ContainsAudioBuffer(u64 tag) const; - /** - * Get the maximum number of buffers. - * - * @return The maximum number of buffers. - */ + /// @brief Get the maximum number of buffers. + /// @return The maximum number of buffers. u32 GetBufferCount() const; - /** - * Get the total played sample count for this audio in. - * - * @return The played sample count. - */ + /// @brief Get the total played sample count for this audio in. + /// @return The played sample count. u64 GetPlayedSampleCount() const; private: /// The AudioIn::Manager this audio in is registered with Manager& manager; /// Manager's mutex - std::recursive_mutex& parent_mutex; + std::mutex& parent_mutex; /// Buffer event, signalled when buffers are ready to be released Kernel::KEvent* event; /// Main audio in system diff --git a/src/audio_core/out/audio_out.h b/src/audio_core/out/audio_out.h index 946f345c61..a906e5e944 100644 --- a/src/audio_core/out/audio_out.h +++ b/src/audio_core/out/audio_out.h @@ -19,125 +19,81 @@ class KReadableEvent; namespace AudioCore::AudioOut { class Manager; -/** - * Interface between the service and audio out system. Mainly responsible for forwarding service - * calls to the system. - */ +/// @brief Interface between the service and audio out system. Mainly responsible for forwarding service +/// calls to the system. class Out { public: explicit Out(Core::System& system, Manager& manager, Kernel::KEvent* event, size_t session_id); - /** - * Free this audio out from the audio out manager. - */ + /// @brief Free this audio out from the audio out manager. void Free(); - /** - * Get this audio out's system. - */ + /// @brief Get this audio out's system. System& GetSystem(); - /** - * Get the current state. - * - * @return Started or Stopped. - */ + /// @brief Get the current state. + /// @return Started or Stopped. AudioOut::State GetState(); - /** - * Start the system - * - * @return Result code - */ + /// @brief Start the system + /// @return Result code Result StartSystem(); - /** - * Start the system's device session. - */ + /// @brief Start the system's device session. void StartSession(); - /** - * Stop the system. - * - * @return Result code - */ + /// @brief Stop the system. + /// @return Result code Result StopSystem(); - /** - * Append a new buffer to the system, the buffer event will be signalled when it is filled. - * - * @param buffer - The new buffer to append. - * @param tag - Unique tag for this buffer. - * @return Result code. - */ + /// @brief Append a new buffer to the system, the buffer event will be signalled when it is filled. + /// @param buffer - The new buffer to append. + /// @param tag - Unique tag for this buffer. + /// @return Result code. Result AppendBuffer(const AudioOutBuffer& buffer, u64 tag); - /** - * Release all completed buffers, and register any appended. - */ + /// @brief Release all completed buffers, and register any appended. void ReleaseAndRegisterBuffers(); - /** - * Flush all buffers. - */ + /// @brief Flush all buffers. bool FlushAudioOutBuffers(); - /** - * Get all of the currently released buffers. - * - * @param tags - Output container for the buffer tags which were released. - * @return The number of buffers released. - */ + /// @brief Get all of the currently released buffers. + /// @param tags - Output container for the buffer tags which were released. + /// @return The number of buffers released. u32 GetReleasedBuffers(std::span tags); - /** - * Get the buffer event for this audio out, this event will be signalled when a buffer is - * filled. - * @return The buffer event. - */ + /// @brief Get the buffer event for this audio out, this event will be signalled when a buffer is + /// filled. + /// @return The buffer event. Kernel::KReadableEvent& GetBufferEvent(); - /** - * Get the current system volume. - * - * @return The current volume. - */ + /// @brief Get the current system volume. + /// @return The current volume. f32 GetVolume() const; - /** - * Set the system volume. - * - * @param volume - The volume to set. - */ + /// @brief Set the system volume. + /// @param volume - The volume to set. void SetVolume(f32 volume); - /** - * Check if a buffer is in the system. - * - * @param tag - The tag to search for. - * @return True if the buffer is in the system, otherwise false. - */ + /// @brief Check if a buffer is in the system. + /// @param tag - The tag to search for. + /// @return True if the buffer is in the system, otherwise false. bool ContainsAudioBuffer(u64 tag) const; - /** - * Get the maximum number of buffers. - * - * @return The maximum number of buffers. - */ + /// @brief Get the maximum number of buffers. + /// @return The maximum number of buffers. u32 GetBufferCount() const; - /** - * Get the total played sample count for this audio out. - * - * @return The played sample count. - */ + /// @brief Get the total played sample count for this audio out. + /// @return The played sample count. u64 GetPlayedSampleCount() const; private: /// The AudioOut::Manager this audio out is registered with Manager& manager; /// Manager's mutex - std::recursive_mutex& parent_mutex; + std::mutex& parent_mutex; /// Buffer event, signalled when buffers are ready to be released Kernel::KEvent* event; /// Main audio out system