diff options
| author | 2022-12-16 16:01:35 +0000 | |
|---|---|---|
| committer | 2022-12-16 16:07:24 +0000 | |
| commit | 6a56f42f5d94e2be405a736a74b86ffe3ab1b37b (patch) | |
| tree | f110ff43899da31442d31c219c36f2b8a20ef974 | |
| parent | Merge pull request #9431 from liamwhite/sixty-five-oh-two (diff) | |
| download | yuzu-6a56f42f5d94e2be405a736a74b86ffe3ab1b37b.tar.gz yuzu-6a56f42f5d94e2be405a736a74b86ffe3ab1b37b.tar.xz yuzu-6a56f42f5d94e2be405a736a74b86ffe3ab1b37b.zip | |
Signal buffer event on audio in/out system stop, and force remove all registered audio buffers
| -rw-r--r-- | src/audio_core/device/audio_buffers.h | 8 | ||||
| -rw-r--r-- | src/audio_core/device/device_session.cpp | 6 | ||||
| -rw-r--r-- | src/audio_core/device/device_session.h | 5 | ||||
| -rw-r--r-- | src/audio_core/in/audio_in_system.cpp | 7 | ||||
| -rw-r--r-- | src/audio_core/out/audio_out_system.cpp | 7 |
5 files changed, 26 insertions, 7 deletions
diff --git a/src/audio_core/device/audio_buffers.h b/src/audio_core/device/audio_buffers.h index 3dae1a3b7..15082f6c6 100644 --- a/src/audio_core/device/audio_buffers.h +++ b/src/audio_core/device/audio_buffers.h | |||
| @@ -91,9 +91,10 @@ public: | |||
| 91 | * @param core_timing - The CoreTiming instance | 91 | * @param core_timing - The CoreTiming instance |
| 92 | * @param session - The device session | 92 | * @param session - The device session |
| 93 | * | 93 | * |
| 94 | * @return Is the buffer was released. | 94 | * @return If any buffer was released. |
| 95 | */ | 95 | */ |
| 96 | bool ReleaseBuffers(const Core::Timing::CoreTiming& core_timing, const DeviceSession& session) { | 96 | bool ReleaseBuffers(const Core::Timing::CoreTiming& core_timing, const DeviceSession& session, |
| 97 | bool force) { | ||
| 97 | std::scoped_lock l{lock}; | 98 | std::scoped_lock l{lock}; |
| 98 | bool buffer_released{false}; | 99 | bool buffer_released{false}; |
| 99 | while (registered_count > 0) { | 100 | while (registered_count > 0) { |
| @@ -103,7 +104,8 @@ public: | |||
| 103 | } | 104 | } |
| 104 | 105 | ||
| 105 | // Check with the backend if this buffer can be released yet. | 106 | // Check with the backend if this buffer can be released yet. |
| 106 | if (!session.IsBufferConsumed(buffers[index])) { | 107 | // If we're shutting down, we don't care if it's been played or not. |
| 108 | if (!force && !session.IsBufferConsumed(buffers[index])) { | ||
| 107 | break; | 109 | break; |
| 108 | } | 110 | } |
| 109 | 111 | ||
diff --git a/src/audio_core/device/device_session.cpp b/src/audio_core/device/device_session.cpp index 995060414..5a327a606 100644 --- a/src/audio_core/device/device_session.cpp +++ b/src/audio_core/device/device_session.cpp | |||
| @@ -73,6 +73,12 @@ void DeviceSession::Stop() { | |||
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | void DeviceSession::ClearBuffers() { | ||
| 77 | if (stream) { | ||
| 78 | stream->ClearQueue(); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 76 | void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) const { | 82 | void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) const { |
| 77 | for (const auto& buffer : buffers) { | 83 | for (const auto& buffer : buffers) { |
| 78 | Sink::SinkBuffer new_buffer{ | 84 | Sink::SinkBuffer new_buffer{ |
diff --git a/src/audio_core/device/device_session.h b/src/audio_core/device/device_session.h index 74f4dc085..75f766c68 100644 --- a/src/audio_core/device/device_session.h +++ b/src/audio_core/device/device_session.h | |||
| @@ -91,6 +91,11 @@ public: | |||
| 91 | void Stop(); | 91 | void Stop(); |
| 92 | 92 | ||
| 93 | /** | 93 | /** |
| 94 | * Clear out the underlying audio buffers in the backend stream. | ||
| 95 | */ | ||
| 96 | void ClearBuffers(); | ||
| 97 | |||
| 98 | /** | ||
| 94 | * Set this device session's volume. | 99 | * Set this device session's volume. |
| 95 | * | 100 | * |
| 96 | * @param volume - New volume for this session. | 101 | * @param volume - New volume for this session. |
diff --git a/src/audio_core/in/audio_in_system.cpp b/src/audio_core/in/audio_in_system.cpp index 4324cafd8..934ef8c1c 100644 --- a/src/audio_core/in/audio_in_system.cpp +++ b/src/audio_core/in/audio_in_system.cpp | |||
| @@ -23,7 +23,6 @@ System::~System() { | |||
| 23 | void System::Finalize() { | 23 | void System::Finalize() { |
| 24 | Stop(); | 24 | Stop(); |
| 25 | session->Finalize(); | 25 | session->Finalize(); |
| 26 | buffer_event->Signal(); | ||
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | void System::StartSession() { | 28 | void System::StartSession() { |
| @@ -102,6 +101,10 @@ Result System::Stop() { | |||
| 102 | if (state == State::Started) { | 101 | if (state == State::Started) { |
| 103 | session->Stop(); | 102 | session->Stop(); |
| 104 | session->SetVolume(0.0f); | 103 | session->SetVolume(0.0f); |
| 104 | session->ClearBuffers(); | ||
| 105 | if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) { | ||
| 106 | buffer_event->Signal(); | ||
| 107 | } | ||
| 105 | state = State::Stopped; | 108 | state = State::Stopped; |
| 106 | } | 109 | } |
| 107 | 110 | ||
| @@ -138,7 +141,7 @@ void System::RegisterBuffers() { | |||
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | void System::ReleaseBuffers() { | 143 | void System::ReleaseBuffers() { |
| 141 | bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session)}; | 144 | bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)}; |
| 142 | 145 | ||
| 143 | if (signal) { | 146 | if (signal) { |
| 144 | // Signal if any buffer was released, or if none are registered, we need more. | 147 | // Signal if any buffer was released, or if none are registered, we need more. |
diff --git a/src/audio_core/out/audio_out_system.cpp b/src/audio_core/out/audio_out_system.cpp index a66208ed9..e096a1dac 100644 --- a/src/audio_core/out/audio_out_system.cpp +++ b/src/audio_core/out/audio_out_system.cpp | |||
| @@ -24,7 +24,6 @@ System::~System() { | |||
| 24 | void System::Finalize() { | 24 | void System::Finalize() { |
| 25 | Stop(); | 25 | Stop(); |
| 26 | session->Finalize(); | 26 | session->Finalize(); |
| 27 | buffer_event->Signal(); | ||
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | std::string_view System::GetDefaultOutputDeviceName() const { | 29 | std::string_view System::GetDefaultOutputDeviceName() const { |
| @@ -102,6 +101,10 @@ Result System::Stop() { | |||
| 102 | if (state == State::Started) { | 101 | if (state == State::Started) { |
| 103 | session->Stop(); | 102 | session->Stop(); |
| 104 | session->SetVolume(0.0f); | 103 | session->SetVolume(0.0f); |
| 104 | session->ClearBuffers(); | ||
| 105 | if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) { | ||
| 106 | buffer_event->Signal(); | ||
| 107 | } | ||
| 105 | state = State::Stopped; | 108 | state = State::Stopped; |
| 106 | } | 109 | } |
| 107 | 110 | ||
| @@ -138,7 +141,7 @@ void System::RegisterBuffers() { | |||
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | void System::ReleaseBuffers() { | 143 | void System::ReleaseBuffers() { |
| 141 | bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session)}; | 144 | bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)}; |
| 142 | if (signal) { | 145 | if (signal) { |
| 143 | // Signal if any buffer was released, or if none are registered, we need more. | 146 | // Signal if any buffer was released, or if none are registered, we need more. |
| 144 | buffer_event->Signal(); | 147 | buffer_event->Signal(); |