From 86b7693f985c77bafca4f935ce6722cbd4ce61f5 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 14 Sep 2026 11:30:41 -0700 Subject: [PATCH] GS/GSCapture: Flush stale GSCapture audio buffer during state load --- pcsx2/GS/GSCapture.cpp | 17 ++++++++++++++--- pcsx2/GS/GSCapture.h | 2 +- pcsx2/VMManager.cpp | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pcsx2/GS/GSCapture.cpp b/pcsx2/GS/GSCapture.cpp index d143f9e8db..2392fd2651 100644 --- a/pcsx2/GS/GSCapture.cpp +++ b/pcsx2/GS/GSCapture.cpp @@ -169,6 +169,7 @@ namespace GSCapture static bool ReceivePackets(AVCodecContext* codec_context, AVStream* stream, AVPacket* packet); static bool ProcessAudioPackets(s64 video_pts); static void InternalEndCapture(std::unique_lock& lock); + static void InternalFlush(bool flush_audio_only); static CodecList GetCodecListForContainer(const char* container, AVMediaType type); static std::mutex s_lock; @@ -1463,14 +1464,14 @@ std::string GSCapture::GetNextCaptureFileName() return ret; } -void GSCapture::Flush() +void GSCapture::InternalFlush(bool flush_audio_only) { std::unique_lock lock(s_lock); if (s_encoding_error) return; - - ProcessAllInFlightFrames(lock); + if (!flush_audio_only) + ProcessAllInFlightFrames(lock); if (IsCapturingAudio()) { @@ -1485,6 +1486,16 @@ void GSCapture::Flush() } } +void GSCapture::Flush() +{ + InternalFlush(false); +} + +void GSCapture::FlushAudioOnly() +{ + InternalFlush(true); +} + GSCapture::CodecList GSCapture::GetCodecListForContainer(const char* container, AVMediaType type) { CodecList ret; diff --git a/pcsx2/GS/GSCapture.h b/pcsx2/GS/GSCapture.h index 504497a350..81176a5f70 100644 --- a/pcsx2/GS/GSCapture.h +++ b/pcsx2/GS/GSCapture.h @@ -32,7 +32,7 @@ namespace GSCapture GSVector2i GetSize(); std::string GetNextCaptureFileName(); void Flush(); - + void FlushAudioOnly(); using CodecName = std::pair; // shortname,longname using CodecList = std::vector; CodecList GetVideoCodecList(const char* container); diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index d1550360da..1193e80e1f 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -14,6 +14,7 @@ #include "GS.h" #include "GS/Renderers/HW/GSTextureReplacements.h" #include "GSDumpReplayer.h" +#include "GS/GSCapture.h" #include "GameDatabase.h" #include "GameList.h" #include "Host.h" @@ -1910,7 +1911,7 @@ bool VMManager::DoLoadState(const char* filename, Error* error) Error::SetString(error, TRANSLATE_STR("VMManager", "Cannot load state while replaying a GS dump.")); return false; } - + GSCapture::FlushAudioOnly(); Host::OnSaveStateLoading(filename); if (!SaveState_UnzipFromDisk(filename, error))