From 99ab8dfc997b7012b528729cae460bc6af230238 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Tue, 14 Nov 2017 00:25:49 +0100 Subject: [PATCH 1/5] Use gameID and emulated timestamp for Avi/Wav dump filenames. --- Core/AVIDump.cpp | 14 ++++++++++++-- Core/HLE/__sceAudio.cpp | 11 +++++++++-- Core/HLE/sceKernelTime.cpp | 4 ++++ Core/HLE/sceKernelTime.h | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Core/AVIDump.cpp b/Core/AVIDump.cpp index e118c390db..5809383135 100644 --- a/Core/AVIDump.cpp +++ b/Core/AVIDump.cpp @@ -34,6 +34,10 @@ extern "C" { #include "GPU/Common/GPUDebugInterface.h" +#include "Core/ELF/ParamSFO.h" +#include "Core/HLE/sceKernelTime.h" +#include "StringUtils.h" + #ifdef USE_FFMPEG #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 28, 1) @@ -86,10 +90,16 @@ bool AVIDump::CreateAVI() { #ifdef USE_FFMPEG AVCodec* codec = nullptr; + // Use gameID_EmulatedTimestamp for filename + std::string discID = g_paramSFO.GetDiscID(); + std::string video_file_name = StringFromFormat("%s%s_%d.avi", GetSysDirectory(DIRECTORY_VIDEO).c_str(), discID, returnEmulatedTime()).c_str(); + s_format_context = avformat_alloc_context(); std::stringstream s_file_index_str; - s_file_index_str << s_file_index; - snprintf(s_format_context->filename, sizeof(s_format_context->filename), "%s", (GetSysDirectory(DIRECTORY_VIDEO) + "framedump" + s_file_index_str.str() + ".avi").c_str()); + s_file_index_str << video_file_name; + + snprintf(s_format_context->filename, sizeof(s_format_context->filename), "%s", s_file_index_str.str().c_str()); + INFO_LOG(COMMON, "Recording Video to: %s", s_format_context->filename); // Make sure that the path exists if (!File::Exists(GetSysDirectory(DIRECTORY_VIDEO))) File::CreateDir(GetSysDirectory(DIRECTORY_VIDEO)); diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index bf22b2d01b..1b4fc50ef6 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -35,6 +35,9 @@ #include "Core/System.h" #ifndef MOBILE_DEVICE #include "Core/WaveFile.h" +#include "Core/ELF/ParamSFO.h" +#include "Core/HLE/sceKernelTime.h" +#include "StringUtils.h" #endif #include "Core/HLE/__sceAudio.h" #include "Core/HLE/sceAudio.h" @@ -383,9 +386,13 @@ void __AudioUpdate() { #ifndef MOBILE_DEVICE if (!m_logAudio) { if (g_Config.bDumpAudio) { - std::string audio_file_name = GetSysDirectory(DIRECTORY_AUDIO) + "audiodump.wav"; + // Use gameID_EmulatedTimestamp for filename + std::string discID = g_paramSFO.GetDiscID(); + std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID, returnEmulatedTime()).c_str(); + INFO_LOG(COMMON,"Recording audio to: %s", audio_file_name.c_str()); // Create the path just in case it doesn't exist - File::CreateDir(GetSysDirectory(DIRECTORY_AUDIO)); + if (!File::Exists(GetSysDirectory(DIRECTORY_AUDIO))) + File::CreateDir(GetSysDirectory(DIRECTORY_AUDIO)); File::CreateEmptyFile(audio_file_name); __StartLogAudio(audio_file_name); } diff --git a/Core/HLE/sceKernelTime.cpp b/Core/HLE/sceKernelTime.cpp index 087e8f115b..32265fdf1b 100644 --- a/Core/HLE/sceKernelTime.cpp +++ b/Core/HLE/sceKernelTime.cpp @@ -171,3 +171,7 @@ u32 sceKernelLibcGettimeofday(u32 timeAddr, u32 tzAddr) hleReSchedule("libc timeofday"); return 0; } + +u32 returnEmulatedTime() { + return (u32)start_time + (u32)(CoreTiming::GetGlobalTimeUs() / 1000000ULL); +} \ No newline at end of file diff --git a/Core/HLE/sceKernelTime.h b/Core/HLE/sceKernelTime.h index 2cbc5ca2fb..df81f20663 100644 --- a/Core/HLE/sceKernelTime.h +++ b/Core/HLE/sceKernelTime.h @@ -27,6 +27,7 @@ int sceKernelSysClock2USec(u32 sysclockPtr, u32 highPtr, u32 lowPtr); int sceKernelSysClock2USecWide(u32 lowClock, u32 highClock, u32 lowPtr, u32 highPtr); u64 sceKernelUSec2SysClockWide(u32 usec); u32 sceKernelLibcClock(); +u32 returnEmulatedTime(); void __KernelTimeInit(); void __KernelTimeDoState(PointerWrap &p); From e698414f9bc0c005aeae2bf06911a25cc9603554 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Tue, 14 Nov 2017 05:12:27 +0100 Subject: [PATCH 2/5] Add an option to allow resetting video/audio dump on save/load state. --- Core/Config.cpp | 1 + Core/Config.h | 1 + Core/HLE/__sceAudio.cpp | 16 +++++++++++++++- Core/HLE/__sceAudio.h | 8 +++++++- Core/SaveState.cpp | 30 ++++++++++++++++++++++++++++++ UI/GameSettingsScreen.cpp | 1 + 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 9ddda1a9e9..9e0537ed24 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -360,6 +360,7 @@ static ConfigSetting generalSettings[] = { ConfigSetting("UseFFV1", &g_Config.bUseFFV1, false), ConfigSetting("DumpFrames", &g_Config.bDumpFrames, false), ConfigSetting("DumpAudio", &g_Config.bDumpAudio, false), + ConfigSetting("SaveLoadResetsAVdumping", &g_Config.bSaveLoadResetsAVdumping, false), ConfigSetting("StateSlot", &g_Config.iCurrentStateSlot, 0, true, true), ConfigSetting("RewindFlipFrequency", &g_Config.iRewindFlipFrequency, 0, true, true), diff --git a/Core/Config.h b/Core/Config.h index 6a1d4c2134..ee63af6f30 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -105,6 +105,7 @@ public: bool bUseFFV1; bool bDumpFrames; bool bDumpAudio; + bool bSaveLoadResetsAVdumping; bool bEnableLogging; bool bDumpDecryptedEboot; bool bFullscreenOnDoubleclick; diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index 1b4fc50ef6..c933b9fa9f 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -331,7 +331,7 @@ void __AudioSetOutputFrequency(int freq) { // Mix samples from the various audio channels into a single sample queue. // This single sample queue is where __AudioMix should read from. If the sample queue is full, we should // just sleep the main emulator thread a little. -void __AudioUpdate() { +void __AudioUpdate(bool resetRecording) { // Audio throttle doesn't really work on the PSP since the mixing intervals are so closely tied // to the CPU. Much better to throttle the frame rate on frame display and just throw away audio // if the buffer somehow gets full. @@ -384,6 +384,16 @@ void __AudioUpdate() { if (g_Config.bEnableSound) { resampler.PushSamples(mixBuffer, hwBlockSize); #ifndef MOBILE_DEVICE + if (g_Config.bSaveLoadResetsAVdumping && resetRecording) { + __StopLogAudio(); + std::string discID = g_paramSFO.GetDiscID(); + std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID, returnEmulatedTime()).c_str(); + INFO_LOG(COMMON, "Restarted audio recording to: %s", audio_file_name.c_str()); + if (!File::Exists(GetSysDirectory(DIRECTORY_AUDIO))) + File::CreateDir(GetSysDirectory(DIRECTORY_AUDIO)); + File::CreateEmptyFile(audio_file_name); + __StartLogAudio(audio_file_name); + } if (!m_logAudio) { if (g_Config.bDumpAudio) { // Use gameID_EmulatedTimestamp for filename @@ -450,3 +460,7 @@ void __StopLogAudio() { } } #endif + +void WAVDump::Reset() { + __AudioUpdate(true); +} diff --git a/Core/HLE/__sceAudio.h b/Core/HLE/__sceAudio.h index 87365fb361..39f83d8401 100644 --- a/Core/HLE/__sceAudio.h +++ b/Core/HLE/__sceAudio.h @@ -33,7 +33,7 @@ struct AudioDebugStats { void __AudioInit(); void __AudioDoState(PointerWrap &p); -void __AudioUpdate(); +void __AudioUpdate(bool resetRecording = false); void __AudioShutdown(); void __AudioSetOutputFrequency(int freq); @@ -49,3 +49,9 @@ void __PushExternalAudio(const s32 *audio, int numSamples); // Should not be us // Audio Dumping stuff void __StartLogAudio(const std::string& filename); void __StopLogAudio(); + +class WAVDump +{ +public: + static void Reset(); +}; diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 4b5a4a5426..ebed78f879 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -46,6 +46,14 @@ #include "HW/MemoryStick.h" #include "GPU/GPUState.h" +#ifndef MOBILE_DEVICE +#include "Core/AVIDump.h" +#include "Core/HLE/__sceAudio.h" + +AVIDump video; +WAVDump audio; +#endif + namespace SaveState { struct SaveStart @@ -591,6 +599,17 @@ namespace SaveState callbackMessage = sc->T("Loaded State"); callbackResult = true; hasLoadedState = true; +#ifndef MOBILE_DEVICE + if (g_Config.bSaveLoadResetsAVdumping) { + if (g_Config.bDumpFrames) { + video.Stop(); + video.Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight); + } + if (g_Config.bDumpAudio) { + audio.Reset(); + } + } +#endif } else if (result == CChunkFileReader::ERROR_BROKEN_STATE) { HandleFailure(); callbackMessage = i18nLoadFailure; @@ -615,6 +634,17 @@ namespace SaveState if (result == CChunkFileReader::ERROR_NONE) { callbackMessage = sc->T("Saved State"); callbackResult = true; +#ifndef MOBILE_DEVICE + if (g_Config.bSaveLoadResetsAVdumping) { + if (g_Config.bDumpFrames) { + video.Stop(); + video.Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight); + } + if (g_Config.bDumpAudio) { + audio.Reset(); + } + } +#endif } else if (result == CChunkFileReader::ERROR_BROKEN_STATE) { HandleFailure(); callbackMessage = i18nSaveFailure; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 68cb2d71bf..5e7d7fa2f7 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -781,6 +781,7 @@ void GameSettingsScreen::CreateViews() { systemSettings->Add(new CheckBox(&g_Config.bDumpFrames, sy->T("Record Display"))); systemSettings->Add(new CheckBox(&g_Config.bUseFFV1, sy->T("Use Lossless Video Codec (FFV1)"))); systemSettings->Add(new CheckBox(&g_Config.bDumpAudio, sy->T("Record Audio"))); + systemSettings->Add(new CheckBox(&g_Config.bSaveLoadResetsAVdumping, sy->T("Reset Recording on Save/Load State"))); #endif systemSettings->Add(new CheckBox(&g_Config.bDayLightSavings, sy->T("Day Light Saving"))); static const char *dateFormat[] = { "YYYYMMDD", "MMDDYYYY", "DDMMYYYY"}; From 992748bcde7eeef25ce53c09ac0c24dec199f0cb Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Tue, 14 Nov 2017 05:56:10 +0100 Subject: [PATCH 3/5] Fix linux build. --- Core/AVIDump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/AVIDump.cpp b/Core/AVIDump.cpp index 5809383135..ce02743d02 100644 --- a/Core/AVIDump.cpp +++ b/Core/AVIDump.cpp @@ -92,7 +92,7 @@ bool AVIDump::CreateAVI() { // Use gameID_EmulatedTimestamp for filename std::string discID = g_paramSFO.GetDiscID(); - std::string video_file_name = StringFromFormat("%s%s_%d.avi", GetSysDirectory(DIRECTORY_VIDEO).c_str(), discID, returnEmulatedTime()).c_str(); + std::string video_file_name = StringFromFormat("%s%s_%d.avi", GetSysDirectory(DIRECTORY_VIDEO).c_str(), discID.c_str(), returnEmulatedTime()).c_str(); s_format_context = avformat_alloc_context(); std::stringstream s_file_index_str; From f8f4acc31685327010133b1fd2dda1abd651405a Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Tue, 14 Nov 2017 06:03:52 +0100 Subject: [PATCH 4/5] Blah;p. Buildfix. --- Core/HLE/__sceAudio.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index c933b9fa9f..a6185256cd 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -387,7 +387,7 @@ void __AudioUpdate(bool resetRecording) { if (g_Config.bSaveLoadResetsAVdumping && resetRecording) { __StopLogAudio(); std::string discID = g_paramSFO.GetDiscID(); - std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID, returnEmulatedTime()).c_str(); + std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID.c_str(), returnEmulatedTime()).c_str(); INFO_LOG(COMMON, "Restarted audio recording to: %s", audio_file_name.c_str()); if (!File::Exists(GetSysDirectory(DIRECTORY_AUDIO))) File::CreateDir(GetSysDirectory(DIRECTORY_AUDIO)); @@ -398,7 +398,7 @@ void __AudioUpdate(bool resetRecording) { if (g_Config.bDumpAudio) { // Use gameID_EmulatedTimestamp for filename std::string discID = g_paramSFO.GetDiscID(); - std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID, returnEmulatedTime()).c_str(); + std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID.c_str(), returnEmulatedTime()).c_str(); INFO_LOG(COMMON,"Recording audio to: %s", audio_file_name.c_str()); // Create the path just in case it doesn't exist if (!File::Exists(GetSysDirectory(DIRECTORY_AUDIO))) From 2ff4104ddf2ab185904403b7863fe1fa7f65efda Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Tue, 14 Nov 2017 06:33:49 +0100 Subject: [PATCH 5/5] Requested changes. --- Core/AVIDump.cpp | 2 +- Core/HLE/__sceAudio.cpp | 4 ++-- Core/HLE/sceKernelTime.cpp | 2 +- Core/HLE/sceKernelTime.h | 2 +- Core/SaveState.cpp | 15 ++++++--------- UI/EmuScreen.cpp | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Core/AVIDump.cpp b/Core/AVIDump.cpp index ce02743d02..456698936b 100644 --- a/Core/AVIDump.cpp +++ b/Core/AVIDump.cpp @@ -92,7 +92,7 @@ bool AVIDump::CreateAVI() { // Use gameID_EmulatedTimestamp for filename std::string discID = g_paramSFO.GetDiscID(); - std::string video_file_name = StringFromFormat("%s%s_%d.avi", GetSysDirectory(DIRECTORY_VIDEO).c_str(), discID.c_str(), returnEmulatedTime()).c_str(); + std::string video_file_name = StringFromFormat("%s%s_%d.avi", GetSysDirectory(DIRECTORY_VIDEO).c_str(), discID.c_str(), KernelTimeNow()).c_str(); s_format_context = avformat_alloc_context(); std::stringstream s_file_index_str; diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index a6185256cd..ed9c7c1c76 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -387,7 +387,7 @@ void __AudioUpdate(bool resetRecording) { if (g_Config.bSaveLoadResetsAVdumping && resetRecording) { __StopLogAudio(); std::string discID = g_paramSFO.GetDiscID(); - std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID.c_str(), returnEmulatedTime()).c_str(); + std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID.c_str(), KernelTimeNow()).c_str(); INFO_LOG(COMMON, "Restarted audio recording to: %s", audio_file_name.c_str()); if (!File::Exists(GetSysDirectory(DIRECTORY_AUDIO))) File::CreateDir(GetSysDirectory(DIRECTORY_AUDIO)); @@ -398,7 +398,7 @@ void __AudioUpdate(bool resetRecording) { if (g_Config.bDumpAudio) { // Use gameID_EmulatedTimestamp for filename std::string discID = g_paramSFO.GetDiscID(); - std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID.c_str(), returnEmulatedTime()).c_str(); + std::string audio_file_name = StringFromFormat("%s%s_%d.wav", GetSysDirectory(DIRECTORY_AUDIO).c_str(), discID.c_str(), KernelTimeNow()).c_str(); INFO_LOG(COMMON,"Recording audio to: %s", audio_file_name.c_str()); // Create the path just in case it doesn't exist if (!File::Exists(GetSysDirectory(DIRECTORY_AUDIO))) diff --git a/Core/HLE/sceKernelTime.cpp b/Core/HLE/sceKernelTime.cpp index 32265fdf1b..a4f2df2a60 100644 --- a/Core/HLE/sceKernelTime.cpp +++ b/Core/HLE/sceKernelTime.cpp @@ -172,6 +172,6 @@ u32 sceKernelLibcGettimeofday(u32 timeAddr, u32 tzAddr) return 0; } -u32 returnEmulatedTime() { +u32 KernelTimeNow() { return (u32)start_time + (u32)(CoreTiming::GetGlobalTimeUs() / 1000000ULL); } \ No newline at end of file diff --git a/Core/HLE/sceKernelTime.h b/Core/HLE/sceKernelTime.h index df81f20663..15c064d7ce 100644 --- a/Core/HLE/sceKernelTime.h +++ b/Core/HLE/sceKernelTime.h @@ -27,7 +27,7 @@ int sceKernelSysClock2USec(u32 sysclockPtr, u32 highPtr, u32 lowPtr); int sceKernelSysClock2USecWide(u32 lowClock, u32 highClock, u32 lowPtr, u32 highPtr); u64 sceKernelUSec2SysClockWide(u32 usec); u32 sceKernelLibcClock(); -u32 returnEmulatedTime(); +u32 KernelTimeNow(); void __KernelTimeInit(); void __KernelTimeDoState(PointerWrap &p); diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index ebed78f879..7c3719f1a0 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -49,9 +49,6 @@ #ifndef MOBILE_DEVICE #include "Core/AVIDump.h" #include "Core/HLE/__sceAudio.h" - -AVIDump video; -WAVDump audio; #endif namespace SaveState @@ -602,11 +599,11 @@ namespace SaveState #ifndef MOBILE_DEVICE if (g_Config.bSaveLoadResetsAVdumping) { if (g_Config.bDumpFrames) { - video.Stop(); - video.Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight); + AVIDump::Stop(); + AVIDump::Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight); } if (g_Config.bDumpAudio) { - audio.Reset(); + WAVDump::Reset(); } } #endif @@ -637,11 +634,11 @@ namespace SaveState #ifndef MOBILE_DEVICE if (g_Config.bSaveLoadResetsAVdumping) { if (g_Config.bDumpFrames) { - video.Stop(); - video.Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight); + AVIDump::Stop(); + AVIDump::Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight); } if (g_Config.bDumpAudio) { - audio.Reset(); + WAVDump::Reset(); } } #endif diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index fc089d3c3c..f8d8727899 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -79,7 +79,7 @@ #endif #ifndef MOBILE_DEVICE -AVIDump avi; +static AVIDump avi; #endif static bool frameStep_;