[audio] remove recursive_mutex, replace with std::mutex<>

Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie 2026-01-23 22:03:20 +00:00
parent 29fad5a89e
commit 3ed25005c7
8 changed files with 84 additions and 174 deletions

View File

@ -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

View File

@ -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

View File

@ -33,7 +33,7 @@ constexpr s32 BufferAppendLimit = 4;
template <size_t N>
class AudioBuffers {
public:
explicit AudioBuffers(size_t limit) : append_limit{static_cast<u32>(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<AudioBuffer, N> buffers{};
/// Current released index

View File

@ -123,10 +123,6 @@ void DeviceSession::SetVolume(f32 volume) const {
}
}
u64 DeviceSession::GetPlayedSampleCount() const {
return played_sample_count;
}
std::optional<std::chrono::nanoseconds> DeviceSession::ThreadFunc() {
played_sample_count = stream->GetExpectedPlayedSampleCount();
if (type == Sink::StreamType::Out) {

View File

@ -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.

View File

@ -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;
}

View File

@ -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<u64> 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

View File

@ -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<u64> 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