diff --git a/Core/AVIDump.cpp b/Core/AVIDump.cpp index e118c390db..456698936b 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.c_str(), KernelTimeNow()).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/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 bf22b2d01b..ed9c7c1c76 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" @@ -328,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. @@ -381,11 +384,25 @@ 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.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)); + File::CreateEmptyFile(audio_file_name); + __StartLogAudio(audio_file_name); + } 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.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 - 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); } @@ -443,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/HLE/sceKernelTime.cpp b/Core/HLE/sceKernelTime.cpp index 087e8f115b..a4f2df2a60 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 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 2cbc5ca2fb..15c064d7ce 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 KernelTimeNow(); void __KernelTimeInit(); void __KernelTimeDoState(PointerWrap &p); diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 4b5a4a5426..7c3719f1a0 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -46,6 +46,11 @@ #include "HW/MemoryStick.h" #include "GPU/GPUState.h" +#ifndef MOBILE_DEVICE +#include "Core/AVIDump.h" +#include "Core/HLE/__sceAudio.h" +#endif + namespace SaveState { struct SaveStart @@ -591,6 +596,17 @@ namespace SaveState callbackMessage = sc->T("Loaded State"); callbackResult = true; hasLoadedState = true; +#ifndef MOBILE_DEVICE + if (g_Config.bSaveLoadResetsAVdumping) { + if (g_Config.bDumpFrames) { + AVIDump::Stop(); + AVIDump::Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight); + } + if (g_Config.bDumpAudio) { + WAVDump::Reset(); + } + } +#endif } else if (result == CChunkFileReader::ERROR_BROKEN_STATE) { HandleFailure(); callbackMessage = i18nLoadFailure; @@ -615,6 +631,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) { + AVIDump::Stop(); + AVIDump::Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight); + } + if (g_Config.bDumpAudio) { + WAVDump::Reset(); + } + } +#endif } else if (result == CChunkFileReader::ERROR_BROKEN_STATE) { HandleFailure(); callbackMessage = i18nSaveFailure; 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_; 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"};